Merge lp:~cyphermox/indicator-datetime/revert277 into lp:~indicator-applet-developers/indicator-datetime/trunk.13.10

Proposed by Mathieu Trudel-Lapierre
Status: Merged
Approved by: Ted Gould
Approved revision: 279
Merged at revision: 279
Proposed branch: lp:~cyphermox/indicator-datetime/revert277
Merge into: lp:~indicator-applet-developers/indicator-datetime/trunk.13.10
Diff against target: 1390 lines (+107/-861)
13 files modified
README (+1/-7)
configure.ac (+0/-2)
debian/control (+0/-1)
src/Makefile.am (+0/-2)
src/main.c (+4/-45)
src/planner-eds.c (+70/-179)
src/planner-eds.h (+2/-0)
src/planner-mock.c (+0/-178)
src/planner-mock.h (+0/-58)
src/planner.c (+0/-20)
src/planner.h (+2/-4)
src/service.c (+27/-359)
src/service.h (+1/-6)
To merge this branch: bzr merge lp:~cyphermox/indicator-datetime/revert277
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Ted Gould (community) Approve
Review via email: mp+192258@code.launchpad.net

This proposal supersedes a proposal from 2013-10-22.

Description of the change

Revert revision 277 which appears to be more feature than bugfix applicable for SRU.

To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote : Posted in a previous version of this proposal

Uhm, this is the 14.04 branch. No need to revert anything here.

review: Disapprove
Revision history for this message
Ted Gould (ted) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'README'
--- README 2013-10-09 16:39:36 +0000
+++ README 2013-10-22 22:10:20 +0000
@@ -7,17 +7,11 @@
7 Parameter: None7 Parameter: None
88
9 * "activate-planner"9 * "activate-planner"
10 Description: opens an appointment editor.10 Description: opens up a calendar appointment editor.
11 State: None11 State: None
12 Parameter: int64, a time_t hinting which day/time to show in the planner,12 Parameter: int64, a time_t hinting which day/time to show in the planner,
13 or 0 for the current day13 or 0 for the current day
1414
15 * "activate-appointment"
16 Description: opens an appointment editor to the specified appointment.
17 State: None
18 Parameter: string, an opaque uid to specify which appointment to use.
19 This uid comes from the menuitems' target values.
20
21 * "set-location"15 * "set-location"
22 Description: Set the current location. This will try to set the current16 Description: Set the current location. This will try to set the current
23 timezone to the new location's timezone.17 timezone to the new location's timezone.
2418
=== modified file 'configure.ac'
--- configure.ac 2013-10-16 22:14:11 +0000
+++ configure.ac 2013-10-22 22:10:20 +0000
@@ -51,7 +51,6 @@
51ICAL_REQUIRED_VERSION=0.4851ICAL_REQUIRED_VERSION=0.48
52ECAL_REQUIRED_VERSION=3.552ECAL_REQUIRED_VERSION=3.5
53EDS_REQUIRED_VERSION=3.553EDS_REQUIRED_VERSION=3.5
54LIBNOTIFY_REQUIRED_VERSION=0.7.6
55URL_DISPATCHER_1_REQUIRED_VERSION=154URL_DISPATCHER_1_REQUIRED_VERSION=1
56JSON_GLIB_REQUIRED_VERSION=0.16.255JSON_GLIB_REQUIRED_VERSION=0.16.2
5756
@@ -63,7 +62,6 @@
63 libical >= $ICAL_REQUIRED_VERSION62 libical >= $ICAL_REQUIRED_VERSION
64 libecal-1.2 >= $ECAL_REQUIRED_VERSION63 libecal-1.2 >= $ECAL_REQUIRED_VERSION
65 libedataserver-1.2 >= $EDS_REQUIRED_VERSION64 libedataserver-1.2 >= $EDS_REQUIRED_VERSION
66 libnotify >= $LIBNOTIFY_REQUIRED_VERSION
67 url-dispatcher-1 >= $URL_DISPATCHER_1_REQUIRED_VERSION65 url-dispatcher-1 >= $URL_DISPATCHER_1_REQUIRED_VERSION
68 json-glib-1.0 >= $JSON_GLIB_REQUIRED_VERSION])66 json-glib-1.0 >= $JSON_GLIB_REQUIRED_VERSION])
6967
7068
=== modified file 'debian/control'
--- debian/control 2013-10-16 22:14:11 +0000
+++ debian/control 2013-10-22 22:10:20 +0000
@@ -10,7 +10,6 @@
10 libxorg-gtest-dev,10 libxorg-gtest-dev,
11 libgtest-dev,11 libgtest-dev,
12 libglib2.0-dev (>= 2.35.4),12 libglib2.0-dev (>= 2.35.4),
13 libnotify-dev (>= 0.7.6),
14 libido3-0.1-dev (>= 0.2.90),13 libido3-0.1-dev (>= 0.2.90),
15 libgeoclue-dev (>= 0.12.0),14 libgeoclue-dev (>= 0.12.0),
16 libecal1.2-dev (>= 3.5),15 libecal1.2-dev (>= 3.5),
1716
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2013-10-10 02:31:13 +0000
+++ src/Makefile.am 2013-10-22 22:10:20 +0000
@@ -20,8 +20,6 @@
20libindicator_datetime_service_a_SOURCES = \20libindicator_datetime_service_a_SOURCES = \
21 planner.c \21 planner.c \
22 planner.h \22 planner.h \
23 planner-mock.c \
24 planner-mock.h \
25 planner-eds.c \23 planner-eds.c \
26 planner-eds.h \24 planner-eds.h \
27 service.c \25 service.c \
2826
=== modified file 'src/main.c'
--- src/main.c 2013-10-17 12:23:13 +0000
+++ src/main.c 2013-10-22 22:10:20 +0000
@@ -24,41 +24,25 @@
2424
25#include <glib/gi18n.h>25#include <glib/gi18n.h>
26#include <gio/gio.h>26#include <gio/gio.h>
27#include <libnotify/notify.h>
2827
29#include "planner-eds.h"
30#include "planner-mock.h"
31#include "service.h"28#include "service.h"
3229
33/***30/***
34****31****
35***/32***/
3633
37/* When enabled, new alarms will show up every minute to test snap decisions */
38static gboolean test_alarms = FALSE;
39
40static GOptionEntry entries[] = {
41 { "test-alarms", '\0', 0, G_OPTION_ARG_NONE, &test_alarms, "Test Alarms", NULL },
42 { NULL }
43};
44
45static void34static void
46on_name_lost (gpointer instance G_GNUC_UNUSED, gpointer loop)35on_name_lost (gpointer instance G_GNUC_UNUSED, gpointer loop)
47{36{
48 g_message ("exiting: service couldn't acquire or lost ownership of busname");37 g_message ("exiting: service couldn't acquire or lost ownership of busname");
4938 g_main_loop_quit ((GMainLoop*)loop);
50 if (!test_alarms)
51 g_main_loop_quit ((GMainLoop*)loop);
52}39}
5340
54int41int
55main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED)42main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED)
56{43{
57 GOptionContext * context;44 GMainLoop * loop;
58 GError * error;
59 IndicatorDatetimePlanner * planner;
60 IndicatorDatetimeService * service;45 IndicatorDatetimeService * service;
61 GMainLoop * loop;
6246
63 /* Work around a deadlock in glib's type initialization. It can be47 /* Work around a deadlock in glib's type initialization. It can be
64 * removed when https://bugzilla.gnome.org/show_bug.cgi?id=674885 is48 * removed when https://bugzilla.gnome.org/show_bug.cgi?id=674885 is
@@ -71,40 +55,15 @@
71 bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);55 bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
72 textdomain (GETTEXT_PACKAGE);56 textdomain (GETTEXT_PACKAGE);
7357
74 /* init libnotify */
75 if (!notify_init ("indicator-datetime-service"))
76 g_critical ("libnotify initialization failed");
77
78 /* parse command-line options */
79 context = g_option_context_new (NULL);
80 g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
81 if (!g_option_context_parse (context, &argc, &argv, &error))
82 {
83 g_print("option parsing failed: %s\n", error->message);
84 return EXIT_FAILURE;
85 }
86
87 /* set up the planner */
88 if (test_alarms)
89 {
90 g_message ("Using fake appointment book for testing alarms.");
91 planner = indicator_datetime_planner_mock_new ();
92 }
93 else
94 {
95 planner = indicator_datetime_planner_eds_new ();
96 }
97
98 /* run */58 /* run */
99 service = indicator_datetime_service_new (planner);59 service = indicator_datetime_service_new ();
100 loop = g_main_loop_new (NULL, FALSE);60 loop = g_main_loop_new (NULL, FALSE);
101 g_signal_connect (service, INDICATOR_DATETIME_SERVICE_SIGNAL_NAME_LOST,61 g_signal_connect (service, INDICATOR_DATETIME_SERVICE_SIGNAL_NAME_LOST,
102 G_CALLBACK(on_name_lost), loop);62 G_CALLBACK(on_name_lost), loop);
103 g_main_loop_run (loop);63 g_main_loop_run (loop);
10464
105 /* cleanup */65 /* cleanup */
66 g_clear_object (&service);
106 g_main_loop_unref (loop);67 g_main_loop_unref (loop);
107 g_object_unref (service);
108 g_object_unref (planner);
109 return 0;68 return 0;
110}69}
11170
=== modified file 'src/planner-eds.c'
--- src/planner-eds.c 2013-10-10 02:24:43 +0000
+++ src/planner-eds.c 2013-10-22 22:10:20 +0000
@@ -43,180 +43,78 @@
4343
44/***44/***
45****45****
46**** my_get_appointments() helpers46***/
47****47
48***/48void
4949indicator_datetime_appt_free (struct IndicatorDatetimeAppt * appt)
50/* whole-task data that all the subtasks can see */50{
51struct appointment_task_data51 if (appt != NULL)
52{52 {
53 /* a ref to the planner's cancellable */53 g_date_time_unref (appt->end);
54 GCancellable * cancellable;54 g_date_time_unref (appt->begin);
5555 g_free (appt->color);
56 g_free (appt->summary);
57 g_slice_free (struct IndicatorDatetimeAppt, appt);
58 }
59}
60
61/***
62**** my_get_appointments() helpers
63***/
64
65struct get_appointments_task_data
66{
56 /* how many subtasks are still running on */67 /* how many subtasks are still running on */
57 int subtask_count;68 int subtask_count;
5869
59 /* the list of appointments to be returned */70 /* the list of appointments to be returned */
60 GSList * appointments;71 GSList * appointments;
72
73 /* ensure that recurring events don't get multiple IndicatorDatetimeAppts */
74 GHashTable * added;
61};75};
6276
63static struct appointment_task_data *77static void
64appointment_task_data_new (GCancellable * cancellable)78get_appointments_task_data_free (gpointer gdata)
65{79{
66 struct appointment_task_data * data;80 struct get_appointments_task_data * data = gdata;
6781 g_hash_table_unref (data->added);
68 data = g_slice_new0 (struct appointment_task_data);82 g_slice_free (struct get_appointments_task_data, data);
69 data->cancellable = g_object_ref (cancellable);83}
70 return data;84
71}85static void
7286on_all_subtasks_done (GTask * task)
73static void87{
74appointment_task_data_free (gpointer gdata)88 struct get_appointments_task_data * data = g_task_get_task_data (task);
75{
76 struct appointment_task_data * data = gdata;
77
78 g_object_unref (data->cancellable);
79
80 g_slice_free (struct appointment_task_data, data);
81}
82
83static void
84appointment_task_done (GTask * task)
85{
86 struct appointment_task_data * data = g_task_get_task_data (task);
87
88 g_task_return_pointer (task, data->appointments, NULL);89 g_task_return_pointer (task, data->appointments, NULL);
89 g_object_unref (task);90 g_object_unref (task);
90}91}
9192
92static void93struct get_appointments_subtask_data
93appointment_task_decrement_subtasks (GTask * task)94{
94{95 GTask * task;
95 struct appointment_task_data * data = g_task_get_task_data (task);96
96
97 if (g_atomic_int_dec_and_test (&data->subtask_count))
98 appointment_task_done (task);
99}
100
101static void
102appointment_task_increment_subtasks (GTask * task)
103{
104 struct appointment_task_data * data = g_task_get_task_data (task);
105
106 g_atomic_int_inc (&data->subtask_count);
107}
108
109/**
110*** get-the-appointment's-uri subtasks
111**/
112
113struct appointment_uri_subtask_data
114{
115 /* The parent task */
116 GTask * task;
117
118 /* The appointment whose uri we're looking for.
119 This pointer is owned by the Task and isn't reffed/unreffed by the subtask */
120 struct IndicatorDatetimeAppt * appt;
121};
122
123static void
124appointment_uri_subtask_done (struct appointment_uri_subtask_data * subdata)
125{
126 GTask * task = subdata->task;
127
128 /* free the subtask data */
129 g_slice_free (struct appointment_uri_subtask_data, subdata);
130
131 appointment_task_decrement_subtasks (task);
132}
133
134static struct appointment_uri_subtask_data *
135appointment_uri_subtask_data_new (GTask * task, struct IndicatorDatetimeAppt * appt)
136{
137 struct appointment_uri_subtask_data * subdata;
138
139 appointment_task_increment_subtasks (task);
140
141 subdata = g_slice_new0 (struct appointment_uri_subtask_data);
142 subdata->task = task;
143 subdata->appt = appt;
144 return subdata;
145}
146
147static void
148on_appointment_uris_ready (GObject * client,
149 GAsyncResult * res,
150 gpointer gsubdata)
151{
152 GSList * uris;
153 GError * error;
154 struct appointment_uri_subtask_data * subdata = gsubdata;
155
156 uris = NULL;
157 error = NULL;
158 e_cal_client_get_attachment_uris_finish (E_CAL_CLIENT(client), res, &uris, &error);
159 if (error != NULL)
160 {
161 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
162 g_warning ("Error getting appointment uris: %s", error->message);
163
164 g_error_free (error);
165 }
166 else if (uris != NULL)
167 {
168 struct IndicatorDatetimeAppt * appt = subdata->appt;
169 appt->url = g_strdup (uris->data); /* copy the first URL */
170 g_debug ("found url '%s' for appointment '%s'", appt->url, appt->summary);
171 e_client_util_free_string_slist (uris);
172 }
173
174 appointment_uri_subtask_done (subdata);
175}
176
177/**
178*** enumerate-the-components subtasks
179**/
180
181/* data struct for the enumerate-components subtask */
182struct appointment_component_subtask_data
183{
184 /* The parent task */
185 GTask * task;
186
187 /* The client we're walking through. The subtask owns a ref to this */
188 ECalClient * client;
189
190 /* The appointment's color coding. The subtask owns this string */
191 gchar * color;97 gchar * color;
192};98};
19399
194static void100static void
195on_appointment_component_subtask_done (gpointer gsubdata)101on_subtask_done (gpointer gsubdata)
196{102{
197 struct appointment_component_subtask_data * subdata = gsubdata;103 struct get_appointments_subtask_data * subdata;
198 GTask * task = subdata->task;104 GTask * task;
105 struct get_appointments_task_data * data;
106
107 subdata = gsubdata;
108 task = subdata->task;
199109
200 /* free the subtask data */110 /* free the subtask data */
201 g_free (subdata->color);111 g_free (subdata->color);
202 g_object_unref (subdata->client);112 g_slice_free (struct get_appointments_subtask_data, subdata);
203 g_slice_free (struct appointment_component_subtask_data, subdata);113
204114 /* poke the task */
205 appointment_task_decrement_subtasks (task);115 data = g_task_get_task_data (task);
206}116 if (g_atomic_int_dec_and_test (&data->subtask_count))
207117 on_all_subtasks_done (task);
208static struct appointment_component_subtask_data *
209appointment_component_subtask_data_new (GTask * task, ECalClient * client, const gchar * color)
210{
211 struct appointment_component_subtask_data * subdata;
212
213 appointment_task_increment_subtasks (task);
214
215 subdata = g_slice_new0 (struct appointment_component_subtask_data);
216 subdata->task = task;
217 subdata->client = g_object_ref (client);
218 subdata->color = g_strdup (color);
219 return subdata;
220}118}
221119
222static gboolean120static gboolean
@@ -226,8 +124,8 @@
226 gpointer gsubdata)124 gpointer gsubdata)
227{125{
228 const ECalComponentVType vtype = e_cal_component_get_vtype (component);126 const ECalComponentVType vtype = e_cal_component_get_vtype (component);
229 struct appointment_component_subtask_data * subdata = gsubdata;127 struct get_appointments_subtask_data * subdata = gsubdata;
230 struct appointment_task_data * data = g_task_get_task_data (subdata->task);128 struct get_appointments_task_data * data = g_task_get_task_data (subdata->task);
231129
232 if ((vtype == E_CAL_COMPONENT_EVENT) || (vtype == E_CAL_COMPONENT_TODO))130 if ((vtype == E_CAL_COMPONENT_EVENT) || (vtype == E_CAL_COMPONENT_TODO))
233 {131 {
@@ -238,6 +136,7 @@
238 e_cal_component_get_status (component, &status);136 e_cal_component_get_status (component, &status);
239137
240 if ((uid != NULL) &&138 if ((uid != NULL) &&
139 (!g_hash_table_contains (data->added, uid)) &&
241 (status != ICAL_STATUS_COMPLETED) &&140 (status != ICAL_STATUS_COMPLETED) &&
242 (status != ICAL_STATUS_CANCELLED))141 (status != ICAL_STATUS_CANCELLED))
243 {142 {
@@ -246,7 +145,6 @@
246 GSList * recur_list;145 GSList * recur_list;
247 ECalComponentText text;146 ECalComponentText text;
248 struct IndicatorDatetimeAppt * appt;147 struct IndicatorDatetimeAppt * appt;
249 struct appointment_uri_subtask_data * uri_subdata;
250148
251 appt = g_slice_new0 (struct IndicatorDatetimeAppt);149 appt = g_slice_new0 (struct IndicatorDatetimeAppt);
252150
@@ -271,22 +169,13 @@
271 appt->color = g_strdup (subdata->color);169 appt->color = g_strdup (subdata->color);
272 appt->is_event = vtype == E_CAL_COMPONENT_EVENT;170 appt->is_event = vtype == E_CAL_COMPONENT_EVENT;
273 appt->summary = g_strdup (text.value);171 appt->summary = g_strdup (text.value);
274 appt->uid = g_strdup (uid);
275172
276 alarm_uids = e_cal_component_get_alarm_uids (component);173 alarm_uids = e_cal_component_get_alarm_uids (component);
277 appt->has_alarms = alarm_uids != NULL;174 appt->has_alarms = alarm_uids != NULL;
278 cal_obj_uid_list_free (alarm_uids);175 cal_obj_uid_list_free (alarm_uids);
279176
280 data->appointments = g_slist_prepend (data->appointments, appt);177 data->appointments = g_slist_prepend (data->appointments, appt);
281178 g_hash_table_add (data->added, g_strdup(uid));
282 /* start a new subtask to get the associated URIs */
283 uri_subdata = appointment_uri_subtask_data_new (subdata->task, appt);
284 e_cal_client_get_attachment_uris (subdata->client,
285 uid,
286 NULL,
287 data->cancellable,
288 on_appointment_uris_ready,
289 uri_subdata);
290 }179 }
291 }180 }
292181
@@ -308,6 +197,7 @@
308 priv_t * p;197 priv_t * p;
309 const char * str;198 const char * str;
310 icaltimezone * default_timezone;199 icaltimezone * default_timezone;
200 struct get_appointments_task_data * data;
311 const int64_t begin = g_date_time_to_unix (begin_datetime);201 const int64_t begin = g_date_time_to_unix (begin_datetime);
312 const int64_t end = g_date_time_to_unix (end_datetime);202 const int64_t end = g_date_time_to_unix (end_datetime);
313 GTask * task;203 GTask * task;
@@ -333,18 +223,17 @@
333 *** walk through the sources to build the appointment list223 *** walk through the sources to build the appointment list
334 **/224 **/
335225
226 data = g_slice_new0 (struct get_appointments_task_data);
227 data->added = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
336 task = g_task_new (planner, p->cancellable, callback, user_data);228 task = g_task_new (planner, p->cancellable, callback, user_data);
337 g_task_set_task_data (task,229 g_task_set_task_data (task, data, get_appointments_task_data_free);
338 appointment_task_data_new (p->cancellable),
339 appointment_task_data_free);
340230
341 subtasks_added = FALSE;231 subtasks_added = FALSE;
342 for (l=p->sources; l!=NULL; l=l->next)232 for (l=p->sources; l!=NULL; l=l->next)
343 {233 {
344 ESource * source;234 ESource * source;
345 ECalClient * client;235 ECalClient * client;
346 const char * color;236 struct get_appointments_subtask_data * subdata;
347 struct appointment_component_subtask_data * subdata;
348237
349 source = l->data;238 source = l->data;
350 client = g_object_get_qdata (l->data, source_client_quark());239 client = g_object_get_qdata (l->data, source_client_quark());
@@ -354,9 +243,11 @@
354 if (default_timezone != NULL)243 if (default_timezone != NULL)
355 e_cal_client_set_default_timezone (client, default_timezone);244 e_cal_client_set_default_timezone (client, default_timezone);
356245
357 /* start a new subtask to enumerate all the components in this client. */246 subdata = g_slice_new (struct get_appointments_subtask_data);
358 color = e_source_selectable_get_color (e_source_get_extension (source, E_SOURCE_EXTENSION_CALENDAR));247 subdata->task = task;
359 subdata = appointment_component_subtask_data_new (task, client, color);248 subdata->color = e_source_selectable_dup_color (e_source_get_extension (source, E_SOURCE_EXTENSION_CALENDAR));
249
250 g_atomic_int_inc (&data->subtask_count);
360 subtasks_added = TRUE;251 subtasks_added = TRUE;
361 e_cal_client_generate_instances (client,252 e_cal_client_generate_instances (client,
362 begin,253 begin,
@@ -364,11 +255,11 @@
364 p->cancellable,255 p->cancellable,
365 my_get_appointments_foreach,256 my_get_appointments_foreach,
366 subdata,257 subdata,
367 on_appointment_component_subtask_done);258 on_subtask_done);
368 }259 }
369260
370 if (!subtasks_added)261 if (!subtasks_added)
371 appointment_task_done (task);262 on_all_subtasks_done (task);
372}263}
373264
374static GSList *265static GSList *
@@ -379,7 +270,7 @@
379 return g_task_propagate_pointer (G_TASK(res), error);270 return g_task_propagate_pointer (G_TASK(res), error);
380}271}
381272
382static gboolean273gboolean
383my_is_configured (IndicatorDatetimePlanner * planner)274my_is_configured (IndicatorDatetimePlanner * planner)
384{275{
385 IndicatorDatetimePlannerEds * self;276 IndicatorDatetimePlannerEds * self;
386277
=== modified file 'src/planner-eds.h'
--- src/planner-eds.h 2013-10-10 02:04:31 +0000
+++ src/planner-eds.h 2013-10-22 22:10:20 +0000
@@ -51,6 +51,8 @@
51 IndicatorDatetimePlannerClass parent_class;51 IndicatorDatetimePlannerClass parent_class;
52};52};
5353
54gboolean indicator_datetime_planner_eds_is_usable (void);
55
54IndicatorDatetimePlanner * indicator_datetime_planner_eds_new (void);56IndicatorDatetimePlanner * indicator_datetime_planner_eds_new (void);
5557
56G_END_DECLS58G_END_DECLS
5759
=== removed file 'src/planner-mock.c'
--- src/planner-mock.c 2013-10-10 02:31:13 +0000
+++ src/planner-mock.c 1970-01-01 00:00:00 +0000
@@ -1,178 +0,0 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * Authors:
5 * Charles Kerr <charles.kerr@canonical.com>
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 3, as published
9 * by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranties of
13 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "config.h"
21
22#include "planner-mock.h"
23
24struct _IndicatorDatetimePlannerMockPriv
25{
26 gboolean is_configured;
27};
28
29typedef IndicatorDatetimePlannerMockPriv priv_t;
30
31G_DEFINE_TYPE (IndicatorDatetimePlannerMock,
32 indicator_datetime_planner_mock,
33 INDICATOR_TYPE_DATETIME_PLANNER)
34
35/***
36**** IndicatorDatetimePlanner virtual funcs
37***/
38
39static void
40my_get_appointments (IndicatorDatetimePlanner * planner,
41 GDateTime * begin_datetime,
42 GDateTime * end_datetime G_GNUC_UNUSED,
43 GAsyncReadyCallback callback,
44 gpointer user_data)
45{
46 GTask * task;
47 GSList * appointments;
48 struct IndicatorDatetimeAppt * appt;
49 struct IndicatorDatetimeAppt * prev;
50
51 task = g_task_new (planner, NULL, callback, user_data);
52
53 /**
54 *** Build the appointments list
55 **/
56
57 appointments = NULL;
58
59 /* add a daily appointment that occurs at the beginning of the next minute */
60 appt = g_slice_new0 (struct IndicatorDatetimeAppt);
61 appt->is_daily = TRUE;
62 appt->begin = g_date_time_add_seconds (begin_datetime, 60-g_date_time_get_seconds(begin_datetime));
63 appt->end = g_date_time_add_minutes (appt->begin, 1);
64 appt->color = g_strdup ("#00FF00");
65 appt->is_event = TRUE;
66 appt->summary = g_strdup ("Daily alarm");
67 appt->uid = g_strdup ("this uid isn't very random.");
68 appt->has_alarms = TRUE;
69 appt->url = g_strdup ("alarm:///some-alarm-info-goes-here");
70 appointments = g_slist_prepend (appointments, appt);
71 prev = appt;
72
73 /* and add one for a minute later that has an alarm uri */
74 appt = g_slice_new0 (struct IndicatorDatetimeAppt);
75 appt->is_daily = TRUE;
76 appt->begin = g_date_time_add_minutes (prev->end, 1);
77 appt->end = g_date_time_add_minutes (appt->begin, 1);
78 appt->color = g_strdup ("#0000FF");
79 appt->is_event = TRUE;
80 appt->summary = g_strdup ("Second Daily alarm");
81 appt->uid = g_strdup ("this uid isn't very random either.");
82 appt->has_alarms = FALSE;
83 appointments = g_slist_prepend (appointments, appt);
84
85 /* done */
86 g_task_return_pointer (task, appointments, NULL);
87 g_object_unref (task);
88}
89
90static GSList *
91my_get_appointments_finish (IndicatorDatetimePlanner * self G_GNUC_UNUSED,
92 GAsyncResult * res,
93 GError ** error)
94{
95 return g_task_propagate_pointer (G_TASK(res), error);
96}
97
98static gboolean
99my_is_configured (IndicatorDatetimePlanner * planner)
100{
101 IndicatorDatetimePlannerMock * self;
102 self = INDICATOR_DATETIME_PLANNER_MOCK (planner);
103 return self->priv->is_configured;
104}
105
106static void
107my_activate (IndicatorDatetimePlanner * self G_GNUC_UNUSED)
108{
109 g_message ("%s %s", G_STRLOC, G_STRFUNC);
110}
111
112static void
113my_activate_time (IndicatorDatetimePlanner * self G_GNUC_UNUSED,
114 GDateTime * activate_time)
115{
116 gchar * str = g_date_time_format (activate_time, "%F %T");
117 g_message ("%s %s: %s", G_STRLOC, G_STRFUNC, str);
118 g_free (str);
119}
120
121/***
122**** GObject virtual funcs
123***/
124
125static void
126my_dispose (GObject * o)
127{
128 G_OBJECT_CLASS (indicator_datetime_planner_mock_parent_class)->dispose (o);
129}
130
131/***
132**** Instantiation
133***/
134
135static void
136indicator_datetime_planner_mock_class_init (IndicatorDatetimePlannerMockClass * klass)
137{
138 GObjectClass * object_class;
139 IndicatorDatetimePlannerClass * planner_class;
140
141 object_class = G_OBJECT_CLASS (klass);
142 object_class->dispose = my_dispose;
143
144 planner_class = INDICATOR_DATETIME_PLANNER_CLASS (klass);
145 planner_class->is_configured = my_is_configured;
146 planner_class->activate = my_activate;
147 planner_class->activate_time = my_activate_time;
148 planner_class->get_appointments = my_get_appointments;
149 planner_class->get_appointments_finish = my_get_appointments_finish;
150
151 g_type_class_add_private (klass, sizeof (IndicatorDatetimePlannerMockPriv));
152}
153
154static void
155indicator_datetime_planner_mock_init (IndicatorDatetimePlannerMock * self)
156{
157 priv_t * p;
158
159 p = G_TYPE_INSTANCE_GET_PRIVATE (self,
160 INDICATOR_TYPE_DATETIME_PLANNER_MOCK,
161 IndicatorDatetimePlannerMockPriv);
162
163 p->is_configured = TRUE;
164
165 self->priv = p;
166}
167
168/***
169**** Public
170***/
171
172IndicatorDatetimePlanner *
173indicator_datetime_planner_mock_new (void)
174{
175 gpointer o = g_object_new (INDICATOR_TYPE_DATETIME_PLANNER_MOCK, NULL);
176
177 return INDICATOR_DATETIME_PLANNER (o);
178}
1790
=== removed file 'src/planner-mock.h'
--- src/planner-mock.h 2013-10-10 02:31:13 +0000
+++ src/planner-mock.h 1970-01-01 00:00:00 +0000
@@ -1,58 +0,0 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * Authors:
5 * Charles Kerr <charles.kerr@canonical.com>
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 3, as published
9 * by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranties of
13 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef __INDICATOR_DATETIME_PLANNER_MOCK__H__
21#define __INDICATOR_DATETIME_PLANNER_MOCK__H__
22
23#include "planner.h" /* parent class */
24
25G_BEGIN_DECLS
26
27#define INDICATOR_TYPE_DATETIME_PLANNER_MOCK (indicator_datetime_planner_mock_get_type())
28#define INDICATOR_DATETIME_PLANNER_MOCK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_DATETIME_PLANNER_MOCK, IndicatorDatetimePlannerMock))
29#define INDICATOR_DATETIME_PLANNER_MOCK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_DATETIME_PLANNER_MOCK, IndicatorDatetimePlannerMockClass))
30#define INDICATOR_IS_DATETIME_PLANNER_MOCK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_DATETIME_PLANNER_MOCK))
31
32typedef struct _IndicatorDatetimePlannerMock IndicatorDatetimePlannerMock;
33typedef struct _IndicatorDatetimePlannerMockPriv IndicatorDatetimePlannerMockPriv;
34typedef struct _IndicatorDatetimePlannerMockClass IndicatorDatetimePlannerMockClass;
35
36GType indicator_datetime_planner_mock_get_type (void);
37
38/**
39 * An IndicatorDatetimePlanner which uses Evolution Data Server
40 * to get its list of appointments.
41 */
42struct _IndicatorDatetimePlannerMock
43{
44 /*< private >*/
45 IndicatorDatetimePlanner parent;
46 IndicatorDatetimePlannerMockPriv * priv;
47};
48
49struct _IndicatorDatetimePlannerMockClass
50{
51 IndicatorDatetimePlannerClass parent_class;
52};
53
54IndicatorDatetimePlanner * indicator_datetime_planner_mock_new (void);
55
56G_END_DECLS
57
58#endif /* __INDICATOR_DATETIME_PLANNER_MOCK__H__ */
590
=== modified file 'src/planner.c'
--- src/planner.c 2013-10-10 02:06:35 +0000
+++ src/planner.c 2013-10-22 22:10:20 +0000
@@ -259,23 +259,3 @@
259259
260 return self->priv->timezone;260 return self->priv->timezone;
261}261}
262
263/***
264****
265***/
266
267void
268indicator_datetime_appt_free (struct IndicatorDatetimeAppt * appt)
269{
270 if (appt != NULL)
271 {
272 g_date_time_unref (appt->end);
273 g_date_time_unref (appt->begin);
274 g_free (appt->color);
275 g_free (appt->summary);
276 g_free (appt->url);
277 g_free (appt->uid);
278 g_slice_free (struct IndicatorDatetimeAppt, appt);
279 }
280}
281
282262
=== modified file 'src/planner.h'
--- src/planner.h 2013-10-09 13:21:16 +0000
+++ src/planner.h 2013-10-22 22:10:20 +0000
@@ -40,10 +40,8 @@
4040
41struct IndicatorDatetimeAppt41struct IndicatorDatetimeAppt
42{42{
43 gchar * color;43 char * color;
44 gchar * summary;44 char * summary;
45 gchar * url;
46 gchar * uid;
47 GDateTime * begin;45 GDateTime * begin;
48 GDateTime * end;46 GDateTime * end;
49 gboolean is_event;47 gboolean is_event;
5048
=== modified file 'src/service.c'
--- src/service.c 2013-10-17 03:39:12 +0000
+++ src/service.c 2013-10-22 22:10:20 +0000
@@ -24,11 +24,11 @@
2424
25#include <glib/gi18n.h>25#include <glib/gi18n.h>
26#include <gio/gio.h>26#include <gio/gio.h>
27#include <libnotify/notify.h>
28#include <json-glib/json-glib.h>27#include <json-glib/json-glib.h>
29#include <url-dispatcher.h>28#include <url-dispatcher.h>
3029
31#include "dbus-shared.h"30#include "dbus-shared.h"
31#include "planner-eds.h"
32#include "timezone-file.h"32#include "timezone-file.h"
33#include "timezone-geoclue.h"33#include "timezone-geoclue.h"
34#include "service.h"34#include "service.h"
@@ -53,15 +53,6 @@
5353
54enum54enum
55{55{
56 PROP_0,
57 PROP_PLANNER,
58 PROP_LAST
59};
60
61static GParamSpec * properties[PROP_LAST] = { 0 };
62
63enum
64{
65 SECTION_HEADER = (1<<0),56 SECTION_HEADER = (1<<0),
66 SECTION_CALENDAR = (1<<1),57 SECTION_CALENDAR = (1<<1),
67 SECTION_APPOINTMENTS = (1<<2),58 SECTION_APPOINTMENTS = (1<<2),
@@ -128,7 +119,6 @@
128119
129 guint header_timer;120 guint header_timer;
130 guint timezone_timer;121 guint timezone_timer;
131 guint alarm_timer;
132122
133 /* Which year/month to show in the calendar,123 /* Which year/month to show in the calendar,
134 and which day should get the cursor.124 and which day should get the cursor.
@@ -398,197 +388,6 @@
398 g_date_time_unref (now);388 g_date_time_unref (now);
399}389}
400390
401/***
402**** ALARMS
403***/
404
405static void set_alarm_timer (IndicatorDatetimeService * self);
406
407static gboolean
408appointment_has_alarm_url (const struct IndicatorDatetimeAppt * appt)
409{
410 return (appt->has_alarms) &&
411 (appt->url != NULL) &&
412 (g_str_has_prefix (appt->url, "alarm:///"));
413}
414
415static gboolean
416datetimes_have_the_same_minute (GDateTime * a G_GNUC_UNUSED, GDateTime * b G_GNUC_UNUSED)
417{
418 int ay, am, ad;
419 int by, bm, bd;
420
421 g_date_time_get_ymd (a, &ay, &am, &ad);
422 g_date_time_get_ymd (b, &by, &bm, &bd);
423
424 return (ay == by) &&
425 (am == bm) &&
426 (ad == bd) &&
427 (g_date_time_get_hour (a) == g_date_time_get_hour (b)) &&
428 (g_date_time_get_minute (a) == g_date_time_get_minute (b));
429}
430
431static void
432dispatch_alarm_url (const struct IndicatorDatetimeAppt * appt)
433{
434 gchar * str;
435
436 g_return_if_fail (appt != NULL);
437 g_return_if_fail (appointment_has_alarm_url (appt));
438
439 str = g_date_time_format (appt->begin, "%F %T");
440 g_debug ("dispatching url \"%s\" for appointment \"%s\", which begins at %s",
441 appt->url, appt->summary, str);
442 g_free (str);
443
444 url_dispatch_send (appt->url, NULL, NULL);
445}
446
447static void
448on_snap_decided (NotifyNotification * notification G_GNUC_UNUSED,
449 char * action,
450 gpointer gurl)
451{
452 g_debug ("%s: %s", G_STRFUNC, action);
453
454 if (!g_strcmp0 (action, "show"))
455 {
456 const gchar * url = gurl;
457 g_debug ("dispatching url '%s'", url);
458 url_dispatch_send (url, NULL, NULL);
459 }
460}
461
462static void
463show_snap_decision_for_alarm (const struct IndicatorDatetimeAppt * appt)
464{
465 gchar * title;
466 const gchar * body;
467 const gchar * icon_name;
468 NotifyNotification * nn;
469 GError * error;
470
471 title = g_date_time_format (appt->begin,
472 get_terse_time_format_string (appt->begin));
473 body = appt->summary;
474 icon_name = ALARM_CLOCK_ICON_NAME;
475 g_debug ("creating a snap decision with title '%s', body '%s', icon '%s'",
476 title, body, icon_name);
477
478 nn = notify_notification_new (title, body, icon_name);
479 notify_notification_set_hint_string (nn,
480 "x-canonical-snap-decisions",
481 "true");
482 notify_notification_set_hint_string (nn,
483 "x-canonical-private-button-tint",
484 "true");
485 notify_notification_add_action (nn, "show", _("Show"),
486 on_snap_decided, g_strdup(appt->url), g_free);
487 notify_notification_add_action (nn, "dismiss", _("Dismiss"),
488 on_snap_decided, NULL, NULL);
489
490 error = NULL;
491 notify_notification_show (nn, &error);
492 if (error != NULL)
493 {
494 g_warning ("Unable to show alarm '%s' popup: %s", body, error->message);
495 g_error_free (error);
496 dispatch_alarm_url (appt);
497 }
498
499 g_free (title);
500}
501
502static void update_appointment_lists (IndicatorDatetimeService * self);
503
504static gboolean
505on_alarm_timer (gpointer gself)
506{
507 IndicatorDatetimeService * self = INDICATOR_DATETIME_SERVICE (gself);
508 GDateTime * now;
509 GSList * l;
510
511 /* If there are any alarms at the current time, show a snap decision */
512 now = indicator_datetime_service_get_localtime (self);
513 for (l=self->priv->upcoming_appointments; l!=NULL; l=l->next)
514 {
515 const struct IndicatorDatetimeAppt * appt = l->data;
516
517 if (appointment_has_alarm_url (appt))
518 if (datetimes_have_the_same_minute (now, appt->begin))
519 show_snap_decision_for_alarm (appt);
520 }
521 g_date_time_unref (now);
522
523 /* rebuild the alarm list asynchronously.
524 set_upcoming_appointments() will update the alarm timer when this
525 async call is done, so no need to restart the timer here... */
526 update_appointment_lists (self);
527
528 return G_SOURCE_REMOVE;
529}
530
531/* if there are upcoming alarms, set the alarm timer to the nearest one.
532 otherwise, unset the alarm timer. */
533static void
534set_alarm_timer (IndicatorDatetimeService * self)
535{
536 priv_t * p;
537 GDateTime * now;
538 GDateTime * alarm_time;
539 GSList * l;
540
541 p = self->priv;
542 indicator_clear_timer (&p->alarm_timer);
543
544 now = indicator_datetime_service_get_localtime (self);
545
546 /* find the time of the next alarm on our calendar */
547 alarm_time = NULL;
548 for (l=p->upcoming_appointments; l!=NULL; l=l->next)
549 {
550 const struct IndicatorDatetimeAppt * appt = l->data;
551
552 if (appointment_has_alarm_url (appt))
553 if (g_date_time_compare (appt->begin, now) > 0)
554 if (!alarm_time || g_date_time_compare (alarm_time, appt->begin) > 0)
555 alarm_time = appt->begin;
556 }
557
558 /* if there's an upcoming alarm, set a timer to wake up at that time */
559 if (alarm_time != NULL)
560 {
561 GTimeSpan interval_msec;
562 gchar * str;
563 GDateTime * then;
564
565 interval_msec = g_date_time_difference (alarm_time, now);
566 interval_msec += G_USEC_PER_SEC; /* fire a moment after alarm_time */
567 interval_msec /= 1000; /* convert from usec to msec */
568
569 str = g_date_time_format (alarm_time, "%F %T");
570 g_debug ("%s is the next alarm time", str);
571 g_free (str);
572 then = g_date_time_add_seconds (now, interval_msec/1000);
573 str = g_date_time_format (then, "%F %T");
574 g_debug ("%s is when we'll wake up for it", str);
575 g_free (str);
576 g_date_time_unref (then);
577
578 p->alarm_timer = g_timeout_add_full (G_PRIORITY_HIGH,
579 (guint) interval_msec,
580 on_alarm_timer,
581 self,
582 NULL);
583 }
584
585 g_date_time_unref (now);
586}
587
588/***
589****
590***/
591
592static void391static void
593update_internal_timezone (IndicatorDatetimeService * self)392update_internal_timezone (IndicatorDatetimeService * self)
594{393{
@@ -944,36 +743,23 @@
944}743}
945744
946static void745static void
947add_appointments (IndicatorDatetimeService * self, GMenu * menu, gboolean phone)746add_appointments (IndicatorDatetimeService * self, GMenu * menu, gboolean terse)
948{747{
949 const int MAX_APPTS = 5;748 const int MAX_APPTS = 5;
950 GDateTime * now;749 GDateTime * now = indicator_datetime_service_get_localtime (self);
951 GHashTable * added;
952 GSList * appts;750 GSList * appts;
953 GSList * l;751 GSList * l;
954 int i;752 int i;
955753
956 now = indicator_datetime_service_get_localtime (self);
957
958 added = g_hash_table_new (g_str_hash, g_str_equal);
959
960 /* build appointment menuitems */754 /* build appointment menuitems */
961 appts = self->priv->upcoming_appointments;755 appts = self->priv->upcoming_appointments;
962 for (l=appts, i=0; l!=NULL && i<MAX_APPTS; l=l->next, i++)756 for (l=appts, i=0; l!=NULL && i<MAX_APPTS; l=l->next, i++)
963 {757 {
964 struct IndicatorDatetimeAppt * appt = l->data;758 struct IndicatorDatetimeAppt * appt = l->data;
965 char * fmt;759 char * fmt = get_appointment_time_format (appt, now, self->priv->settings, terse);
966 gint64 unix_time;760 const gint64 unix_time = g_date_time_to_unix (appt->begin);
967 GMenuItem * menu_item;761 GMenuItem * menu_item;
968762
969 if (g_hash_table_contains (added, appt->uid))
970 continue;
971
972 g_hash_table_add (added, appt->uid);
973
974 fmt = get_appointment_time_format (appt, now, self->priv->settings, phone);
975 unix_time = g_date_time_to_unix (appt->begin);
976
977 menu_item = g_menu_item_new (appt->summary, NULL);763 menu_item = g_menu_item_new (appt->summary, NULL);
978764
979 if (appt->has_alarms)765 if (appt->has_alarms)
@@ -990,22 +776,15 @@
990 g_menu_item_set_attribute (menu_item, "x-canonical-type",776 g_menu_item_set_attribute (menu_item, "x-canonical-type",
991 "s", appt->has_alarms ? "com.canonical.indicator.alarm"777 "s", appt->has_alarms ? "com.canonical.indicator.alarm"
992 : "com.canonical.indicator.appointment");778 : "com.canonical.indicator.appointment");
993779 g_menu_item_set_action_and_target_value (menu_item,
994 if (phone)780 "indicator.activate-planner",
995 g_menu_item_set_action_and_target_value (menu_item,781 g_variant_new_int64 (unix_time));
996 "indicator.activate-appointment",
997 g_variant_new_string (appt->uid));
998 else
999 g_menu_item_set_action_and_target_value (menu_item,
1000 "indicator.activate-planner",
1001 g_variant_new_int64 (unix_time));
1002 g_menu_append_item (menu, menu_item);782 g_menu_append_item (menu, menu_item);
1003 g_object_unref (menu_item);783 g_object_unref (menu_item);
1004 g_free (fmt);784 g_free (fmt);
1005 }785 }
1006786
1007 /* cleanup */787 /* cleanup */
1008 g_hash_table_unref (added);
1009 g_date_time_unref (now);788 g_date_time_unref (now);
1010}789}
1011790
@@ -1584,34 +1363,6 @@
1584}1363}
15851364
1586static void1365static void
1587on_activate_appointment (GSimpleAction * a G_GNUC_UNUSED,
1588 GVariant * param,
1589 gpointer gself)
1590{
1591 priv_t * p = INDICATOR_DATETIME_SERVICE(gself)->priv;
1592 const gchar * uid = g_variant_get_string (param, NULL);
1593
1594 if (uid != NULL)
1595 {
1596 const struct IndicatorDatetimeAppt * appt;
1597 GSList * l;
1598
1599 /* find the appointment that matches that uid */
1600 for (l=p->upcoming_appointments, appt=NULL; l && !appt; l=l->next)
1601 {
1602 const struct IndicatorDatetimeAppt * tmp = l->data;
1603 if (!g_strcmp0 (uid, tmp->uid))
1604 appt = tmp;
1605 }
1606
1607 /* if that appointment's an alarm, dispatch its url */
1608 g_debug ("%s: uri '%s'; matching appt is %p", G_STRFUNC, uid, appt);
1609 if (appt && appointment_has_alarm_url (appt))
1610 dispatch_alarm_url (appt);
1611 }
1612}
1613
1614static void
1615on_phone_clock_activated (GSimpleAction * a G_GNUC_UNUSED,1366on_phone_clock_activated (GSimpleAction * a G_GNUC_UNUSED,
1616 GVariant * param G_GNUC_UNUSED,1367 GVariant * param G_GNUC_UNUSED,
1617 gpointer gself G_GNUC_UNUSED)1368 gpointer gself G_GNUC_UNUSED)
@@ -1675,7 +1426,6 @@
1675 { "activate-phone-settings", on_phone_settings_activated },1426 { "activate-phone-settings", on_phone_settings_activated },
1676 { "activate-phone-clock-app", on_phone_clock_activated },1427 { "activate-phone-clock-app", on_phone_clock_activated },
1677 { "activate-planner", on_activate_planner, "x", NULL },1428 { "activate-planner", on_activate_planner, "x", NULL },
1678 { "activate-appointment", on_activate_appointment, "s", NULL },
1679 { "set-location", on_set_location, "s" }1429 { "set-location", on_set_location, "s" }
1680 };1430 };
16811431
@@ -1906,10 +1656,6 @@
19061656
1907 /* sync the menus/actions */1657 /* sync the menus/actions */
1908 rebuild_appointments_section_soon (self);1658 rebuild_appointments_section_soon (self);
1909
1910 /* alarm timer is keyed off of the next alarm time,
1911 so it needs to be rebuilt when the appointment list changes */
1912 set_alarm_timer (self);
1913}1659}
19141660
1915static void1661static void
@@ -2079,45 +1825,6 @@
2079***/1825***/
20801826
2081static void1827static void
2082my_get_property (GObject * o,
2083 guint property_id,
2084 GValue * value,
2085 GParamSpec * pspec)
2086{
2087 IndicatorDatetimeService * self = INDICATOR_DATETIME_SERVICE (o);
2088
2089 switch (property_id)
2090 {
2091 case PROP_PLANNER:
2092 g_value_set_object (value, self->priv->planner);
2093 break;
2094
2095 default:
2096 G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec);
2097 }
2098}
2099
2100static void
2101my_set_property (GObject * o,
2102 guint property_id,
2103 const GValue * value,
2104 GParamSpec * pspec)
2105{
2106 IndicatorDatetimeService * self = INDICATOR_DATETIME_SERVICE (o);
2107
2108 switch (property_id)
2109 {
2110 case PROP_PLANNER:
2111 indicator_datetime_service_set_planner (self, g_value_get_object (value));
2112 break;
2113
2114 default:
2115 G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec);
2116 }
2117}
2118
2119
2120static void
2121my_dispose (GObject * o)1828my_dispose (GObject * o)
2122{1829{
2123 int i;1830 int i;
@@ -2140,7 +1847,13 @@
21401847
2141 set_detect_location_enabled (self, FALSE);1848 set_detect_location_enabled (self, FALSE);
21421849
2143 indicator_datetime_service_set_planner (self, NULL);1850 if (p->planner != NULL)
1851 {
1852 g_signal_handlers_disconnect_by_data (p->planner, self);
1853 g_clear_object (&p->planner);
1854 }
1855 g_clear_pointer (&p->upcoming_appointments, indicator_datetime_planner_free_appointments);
1856 g_clear_pointer (&p->calendar_appointments, indicator_datetime_planner_free_appointments);
21441857
2145 if (p->login1_manager != NULL)1858 if (p->login1_manager != NULL)
2146 {1859 {
@@ -2152,7 +1865,6 @@
2152 indicator_clear_timer (&p->rebuild_id);1865 indicator_clear_timer (&p->rebuild_id);
2153 indicator_clear_timer (&p->timezone_timer);1866 indicator_clear_timer (&p->timezone_timer);
2154 indicator_clear_timer (&p->header_timer);1867 indicator_clear_timer (&p->header_timer);
2155 indicator_clear_timer (&p->alarm_timer);
21561868
2157 if (p->settings != NULL)1869 if (p->settings != NULL)
2158 {1870 {
@@ -2243,6 +1955,16 @@
2243 p->cancellable = g_cancellable_new ();1955 p->cancellable = g_cancellable_new ();
22441956
2245 /***1957 /***
1958 **** Create the planner and listen for changes
1959 ***/
1960
1961 p->planner = indicator_datetime_planner_eds_new ();
1962
1963 g_signal_connect_swapped (p->planner, "appointments-changed",
1964 G_CALLBACK(update_appointment_lists), self);
1965
1966
1967 /***
2246 **** Create the settings object and listen for changes1968 **** Create the settings object and listen for changes
2247 ***/1969 ***/
22481970
@@ -2311,8 +2033,6 @@
23112033
2312 on_local_time_jumped (self);2034 on_local_time_jumped (self);
23132035
2314 set_alarm_timer (self);
2315
2316 for (i=0; i<N_PROFILES; ++i)2036 for (i=0; i<N_PROFILES; ++i)
2317 create_menu (self, i);2037 create_menu (self, i);
23182038
@@ -2323,12 +2043,9 @@
2323indicator_datetime_service_class_init (IndicatorDatetimeServiceClass * klass)2043indicator_datetime_service_class_init (IndicatorDatetimeServiceClass * klass)
2324{2044{
2325 GObjectClass * object_class = G_OBJECT_CLASS (klass);2045 GObjectClass * object_class = G_OBJECT_CLASS (klass);
2326 const GParamFlags flags = G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS;
23272046
2328 object_class->dispose = my_dispose;2047 object_class->dispose = my_dispose;
2329 object_class->finalize = my_finalize;2048 object_class->finalize = my_finalize;
2330 object_class->get_property = my_get_property;
2331 object_class->set_property = my_set_property;
23322049
2333 g_type_class_add_private (klass, sizeof (IndicatorDatetimeServicePrivate));2050 g_type_class_add_private (klass, sizeof (IndicatorDatetimeServicePrivate));
23342051
@@ -2340,18 +2057,6 @@
2340 NULL, NULL,2057 NULL, NULL,
2341 g_cclosure_marshal_VOID__VOID,2058 g_cclosure_marshal_VOID__VOID,
2342 G_TYPE_NONE, 0);2059 G_TYPE_NONE, 0);
2343
2344 /* install properties */
2345
2346 properties[PROP_0] = NULL;
2347
2348 properties[PROP_PLANNER] = g_param_spec_object ("planner",
2349 "Planner",
2350 "The appointment provider",
2351 INDICATOR_TYPE_DATETIME_PLANNER,
2352 flags);
2353
2354 g_object_class_install_properties (object_class, PROP_LAST, properties);
2355}2060}
23562061
2357/***2062/***
@@ -2359,11 +2064,9 @@
2359***/2064***/
23602065
2361IndicatorDatetimeService *2066IndicatorDatetimeService *
2362indicator_datetime_service_new (IndicatorDatetimePlanner * planner)2067indicator_datetime_service_new (void)
2363{2068{
2364 GObject * o = g_object_new (INDICATOR_TYPE_DATETIME_SERVICE,2069 GObject * o = g_object_new (INDICATOR_TYPE_DATETIME_SERVICE, NULL);
2365 "planner", planner,
2366 NULL);
23672070
2368 return INDICATOR_DATETIME_SERVICE (o);2071 return INDICATOR_DATETIME_SERVICE (o);
2369}2072}
@@ -2399,38 +2102,3 @@
2399 if (dirty)2102 if (dirty)
2400 update_appointment_lists (self);2103 update_appointment_lists (self);
2401}2104}
2402
2403void
2404indicator_datetime_service_set_planner (IndicatorDatetimeService * self,
2405 IndicatorDatetimePlanner * planner)
2406{
2407 priv_t * p;
2408
2409 g_return_if_fail (INDICATOR_IS_DATETIME_SERVICE (self));
2410 g_return_if_fail (INDICATOR_IS_DATETIME_PLANNER (planner));
2411
2412 p = self->priv;
2413
2414 /* clear the old planner & appointments */
2415
2416 if (p->planner != NULL)
2417 {
2418 g_signal_handlers_disconnect_by_data (p->planner, self);
2419 g_clear_object (&p->planner);
2420 }
2421
2422 g_clear_pointer (&p->upcoming_appointments, indicator_datetime_planner_free_appointments);
2423 g_clear_pointer (&p->calendar_appointments, indicator_datetime_planner_free_appointments);
2424
2425 /* set the new planner & begin fetching appointments from it */
2426
2427 if (planner != NULL)
2428 {
2429 p->planner = g_object_ref (planner);
2430
2431 g_signal_connect_swapped (p->planner, "appointments-changed",
2432 G_CALLBACK(update_appointment_lists), self);
2433
2434 update_appointment_lists (self);
2435 }
2436}
24372105
=== modified file 'src/service.h'
--- src/service.h 2013-10-10 02:02:17 +0000
+++ src/service.h 2013-10-22 22:10:20 +0000
@@ -22,7 +22,6 @@
2222
23#include <glib.h>23#include <glib.h>
24#include <glib-object.h>24#include <glib-object.h>
25#include "planner.h"
2625
27G_BEGIN_DECLS26G_BEGIN_DECLS
2827
@@ -63,17 +62,13 @@
6362
64GType indicator_datetime_service_get_type (void);63GType indicator_datetime_service_get_type (void);
6564
66IndicatorDatetimeService * indicator_datetime_service_new (IndicatorDatetimePlanner * planner);65IndicatorDatetimeService * indicator_datetime_service_new (void);
6766
68GDateTime * indicator_datetime_service_get_localtime (IndicatorDatetimeService * service);67GDateTime * indicator_datetime_service_get_localtime (IndicatorDatetimeService * service);
6968
70void indicator_datetime_service_set_calendar_date (IndicatorDatetimeService * self,69void indicator_datetime_service_set_calendar_date (IndicatorDatetimeService * self,
71 GDateTime * date);70 GDateTime * date);
7271
73void indicator_datetime_service_set_planner (IndicatorDatetimeService * self,
74 IndicatorDatetimePlanner * planner);
75
76
7772
78G_END_DECLS73G_END_DECLS
7974

Subscribers

People subscribed via source and target branches