Merge lp:~karl-qdh/indicator-datetime/calendarmenuitemsignals into lp:indicator-datetime/0.3

Proposed by Karl Lattimer
Status: Merged
Approved by: Ted Gould
Approved revision: 73
Merged at revision: 66
Proposed branch: lp:~karl-qdh/indicator-datetime/calendarmenuitemsignals
Merge into: lp:indicator-datetime/0.3
Diff against target: 364 lines (+121/-69)
2 files modified
src/datetime-service.c (+113/-53)
src/indicator-datetime.c (+8/-16)
To merge this branch: bzr merge lp:~karl-qdh/indicator-datetime/calendarmenuitemsignals
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+53467@code.launchpad.net

Description of the change

Updated code in this branch to fulfil ted's comments

Partially fixes bug #726531

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

  review approve
  merge approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/datetime-service.c'
2--- src/datetime-service.c 2011-03-15 02:43:27 +0000
3+++ src/datetime-service.c 2011-03-15 15:51:45 +0000
4@@ -280,9 +280,6 @@
5 static gboolean
6 month_changed_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, guint timestamp)
7 {
8- // BLOCKED: get type, then get type as string from the variant causes segfault in glib
9- // TODO: * Set some globals so when we-re-run update appointment menu items it gets the right start date
10- // * update appointment menu items
11 start_time_appointments = (time_t)g_variant_get_uint32(variant);
12
13 g_debug("Received month changed with timestamp: %d -> %s",(int)start_time_appointments, ctime(&start_time_appointments));
14@@ -290,6 +287,37 @@
15 return TRUE;
16 }
17
18+static gboolean
19+day_selected_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, guint timestamp)
20+{
21+ start_time_appointments = (time_t)g_variant_get_uint32(variant);
22+
23+ g_debug("Received day-selected with timestamp: %d -> %s",(int)start_time_appointments, ctime(&start_time_appointments));
24+ update_appointment_menu_items(NULL);
25+ return TRUE;
26+}
27+
28+static gboolean
29+day_selected_double_click_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, guint timestamp)
30+{
31+ time_t evotime = (time_t)g_variant_get_uint32(variant);
32+
33+ g_debug("Received day-selected-double-click with timestamp: %d -> %s",(int)evotime, ctime(&evotime));
34+
35+ gchar *ad = isodate_from_time_t(evotime);
36+ gchar *cmd = g_strconcat("evolution calendar:///?startdate=", ad, NULL);
37+
38+ GError * error = NULL;
39+
40+ g_debug("Issuing command '%s'", cmd);
41+ if (!g_spawn_command_line_async(cmd, &error)) {
42+ g_warning("Unable to start %s: %s", (char *)cmd, error->message);
43+ g_error_free(error);
44+ }
45+
46+ return TRUE;
47+}
48+
49 static guint ecaltimer = 0;
50
51 static void
52@@ -365,8 +393,10 @@
53 stop_ecal_timer();
54 }
55
56- // Connect to event::month-changed
57+ // Connect to calendar events
58 g_signal_connect(calendar, "event::month-changed", G_CALLBACK(month_changed_cb), NULL);
59+ g_signal_connect(calendar, "event::day-selected", G_CALLBACK(day_selected_cb), NULL);
60+ g_signal_connect(calendar, "event::day-selected-double-click", G_CALLBACK(day_selected_double_click_cb), NULL);
61 g_free(evo);
62 } else {
63 g_debug("Unable to find calendar app.");
64@@ -543,27 +573,51 @@
65 if (updating_appointments) return TRUE;
66 updating_appointments = TRUE;
67
68- time_t t1, t2;
69+ time_t curtime = 0, t1 = 0, t2 = 0;
70 gchar *ad;
71 GList *l;
72 GSList *g;
73 GError *gerror = NULL;
74 gint i;
75- gint width, height;
76+ gint width = 0, height = 0;
77 ESourceList * sources = NULL;
78-
79- if (start_time_appointments > 0)
80- t1 = start_time_appointments;
81- else
82- time(&t1);
83-
84- /* TODO: 7 days ahead of now, we actually need number_of_days_in_this_month
85- * so we call "mark-day" for all remaining days in this month
86- * N.B. Ideally we want any/all dates which are later than today to be marked.
87- */
88- t2 = t1 + (time_t) (7 * 24 * 60 * 60);
89-
90- // TODO Remove all highlights from the calendar widget
91+
92+ // Get today & work out query times
93+ time(&curtime);
94+ struct tm *today = localtime(&curtime);
95+ const int mday = today->tm_mday;
96+ const int mon = today->tm_mon;
97+ const int year = today->tm_year;
98+
99+ struct tm *start_tm = NULL;
100+ int this_year = today->tm_year + 1900;
101+ int days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
102+ if ((this_year % 400 == 0) || (this_year % 100 > 0 && this_year % 4 == 0)) days[1] = 29;
103+
104+ int highlightdays = days[mon] - mday + 1;
105+ t1 = curtime; // By default the current time is the appointment start time.
106+
107+ if (start_time_appointments > 0) {
108+ start_tm = localtime(&start_time_appointments);
109+ int start_month = start_tm->tm_mon;
110+ int start_year = start_tm->tm_year + 1900;
111+ if ((start_month != mon) || (start_year != this_year)) {
112+ // Set t1 to the start of that month.
113+ struct tm month_start = {0};
114+ month_start.tm_year = start_tm->tm_year;
115+ month_start.tm_mon = start_tm->tm_mon;
116+ month_start.tm_mday = 1;
117+ t1 = mktime(&month_start);
118+ highlightdays = days[mon];
119+ }
120+ }
121+
122+ g_debug("Will highlight %d days from %s", highlightdays, ctime(&t1));
123+
124+ t2 = t1 + (time_t) (highlightdays * 24 * 60 * 60);
125+
126+ // Remove all highlights from the calendar widget
127+ dbusmenu_menuitem_property_set (calendar, CALENDAR_MENUITEM_PROP_CLEAR_MARKS, NULL);
128
129 if (!e_cal_get_sources(&sources, E_CAL_SOURCE_TYPE_EVENT, &gerror)) {
130 g_debug("Failed to get ecal sources\n");
131@@ -588,7 +642,7 @@
132
133 for (s = e_source_group_peek_sources (group); s; s = s->next) {
134 ESource *source = E_SOURCE (s->data);
135- //g_signal_connect (G_OBJECT(source), "changed", G_CALLBACK (update_appointment_menu_items), NULL);
136+ g_signal_connect (G_OBJECT(source), "changed", G_CALLBACK (update_appointment_menu_items), NULL);
137 ECal *ecal = e_cal_new(source, E_CAL_SOURCE_TYPE_EVENT);
138 e_cal_set_auth_func (ecal, (ECalAuthFunc) auth_func, NULL);
139
140@@ -605,7 +659,8 @@
141 g_debug("Number of ECalComponents returned: %d", g_list_length(comp_instances));
142 GList *sorted_comp_instances = g_list_sort(comp_instances, compare_comp_instances);
143 comp_instances = NULL;
144-
145+ g_debug("Components sorted");
146+
147 /* Remove all of the previous appointments */
148 if (appointments != NULL) {
149 g_debug("Freeing old appointments");
150@@ -619,9 +674,7 @@
151 }
152 }
153
154- gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height);
155- // Sometimes these give negative numbers, sometimes large numbers which look like timestamps
156- // is there a buffer overwrite causing it?
157+ gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height);
158 if (width <= 0) width = 12;
159 if (height <= 0) height = 12;
160 if (width > 30) width = 12;
161@@ -646,13 +699,34 @@
162 char right[20];
163 //const gchar *uri;
164 DbusmenuMenuitem * item;
165-
166- g_debug("Start Object %p", ecalcomp);
167-
168- // TODO Mark days
169+
170+ ECalComponentVType vtype = e_cal_component_get_vtype (ecalcomp);
171+ struct tm *due = NULL;
172+ if (vtype == E_CAL_COMPONENT_EVENT) due = localtime(&ci->start);
173+ else if (vtype == E_CAL_COMPONENT_TODO) due = localtime(&ci->end);
174+ else continue;
175+
176+ const int dmday = due->tm_mday;
177+ const int dmon = due->tm_mon;
178+ const int dyear = due->tm_year;
179+
180+ // Mark day
181+ g_debug("Marking date %s", ctime(&ci->start));
182+ dbusmenu_menuitem_property_set_int (calendar, CALENDAR_MENUITEM_PROP_MARK, due->tm_mday);
183+
184+
185+ // If the appointment time is less than the selected date,
186+ // don't create an appointment item for it.
187+ if (vtype == E_CAL_COMPONENT_EVENT) {
188+ if (ci->start < start_time_appointments) continue;
189+ } else if (vtype == E_CAL_COMPONENT_TODO) {
190+ if (ci->end < start_time_appointments) continue;
191+ }
192
193 if (i >= 5) continue;
194 i++;
195+
196+ g_debug("Create menu item");
197
198 item = dbusmenu_menuitem_new();
199 dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_TYPE, APPOINTMENT_MENUITEM_TYPE);
200@@ -668,25 +742,6 @@
201 g_free (summary);
202
203 // Due text
204- ECalComponentVType vtype = e_cal_component_get_vtype (ecalcomp);
205-
206- // Get today
207- time_t curtime = time(NULL);
208- struct tm *today = localtime(&curtime);
209-
210- int mday = today->tm_mday;
211- int mon = today->tm_mon;
212- int year = today->tm_year;
213-
214- struct tm *due;
215- if (vtype == E_CAL_COMPONENT_EVENT) due = localtime(&ci->start);
216- else if (vtype == E_CAL_COMPONENT_TODO) due = localtime(&ci->end);
217- else continue;
218-
219- int dmday = due->tm_mday;
220- int dmon = due->tm_mon;
221- int dyear = due->tm_year;
222-
223 if (apt_output == SETTINGS_TIME_12_HOUR) {
224 if ((mday == dmday) && (mon == dmon) && (year == dyear))
225 strftime(right, 20, _(DEFAULT_TIME_12_FORMAT), due);
226@@ -703,7 +758,6 @@
227 else
228 strftime(right, 20, _(DEFAULT_TIME_FORMAT_WITH_DAY), due);
229 }
230-
231 g_debug("Appointment time: %s, for date %s", right, asctime(due));
232 dbusmenu_menuitem_property_set (item, APPOINTMENT_MENUITEM_PROP_RIGHT, right);
233
234@@ -723,10 +777,9 @@
235 // Draw the correct icon for the appointment type and then tint it using mask fill.
236 // For now we'll create a circle
237 if (color_spec != NULL) {
238- // Fixme causes segfault, but we have colours now yay!
239 GdkColor color;
240 gdk_color_parse (color_spec, &color);
241- g_debug("Creating a cairo surface\n size, %d by %d", width, height);
242+ g_debug("Creating a cairo surface: size, %d by %d", width, height);
243 cairo_surface_t *surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, width, height );
244
245 cairo_t *cr = cairo_create(surface);
246@@ -771,13 +824,13 @@
247
248 dbusmenu_menuitem_property_set_image (item, APPOINTMENT_MENUITEM_PROP_ICON, pixbuf);
249 } else {
250- g_debug("Creating pixbuf from surface failed\n Couldn't create new pixbuf for size, %d by %d", width, height);
251+ g_debug("Creating pixbuf from surface failed");
252 }
253 cairo_surface_destroy (surface);
254 cairo_destroy(cr);
255 }
256 dbusmenu_menuitem_child_add_position (root, item, 2+i);
257- appointments = g_list_append (appointments, item); // Keep track of the items here to make them east to remove
258+ appointments = g_list_append (appointments, item); // Keep track of the items here to make them easy to remove
259 g_debug("Adding appointment: %p", item);
260 }
261
262@@ -785,8 +838,8 @@
263 for (l = sorted_comp_instances; l; l = l->next) {
264 const struct comp_instance *ci = l->data;
265 g_object_unref(ci->comp);
266- g_list_free(sorted_comp_instances);
267 }
268+ g_list_free(sorted_comp_instances);
269
270 updating_appointments = FALSE;
271 g_debug("End of objects");
272@@ -820,6 +873,12 @@
273 check_timezone_sync();
274 }
275
276+static void
277+time_format_changed (void)
278+{
279+ update_appointment_menu_items(NULL);
280+}
281+
282 /* Does the work to build the default menu, really calls out
283 to other functions but this is the core to clean up the
284 main function. */
285@@ -872,6 +931,7 @@
286 g_signal_connect (conf, "changed::" SETTINGS_SHOW_LOCATIONS_S, G_CALLBACK (show_locations_changed), NULL);
287 g_signal_connect (conf, "changed::" SETTINGS_LOCATIONS_S, G_CALLBACK (show_locations_changed), NULL);
288 g_signal_connect (conf, "changed::" SETTINGS_SHOW_EVENTS_S, G_CALLBACK (show_events_changed), NULL);
289+ g_signal_connect (conf, "changed::" SETTINGS_TIME_FORMAT_S, G_CALLBACK (time_format_changed), NULL);
290
291 DbusmenuMenuitem * separator = dbusmenu_menuitem_new();
292 dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR);
293
294=== modified file 'src/indicator-datetime.c'
295--- src/indicator-datetime.c 2011-03-15 02:40:24 +0000
296+++ src/indicator-datetime.c 2011-03-15 15:51:45 +0000
297@@ -813,7 +813,7 @@
298
299 if (self->priv->show_seconds ||
300 (self->priv->time_mode == SETTINGS_TIME_CUSTOM && self->priv->custom_show_seconds)) {
301- self->priv->timer = g_timeout_add_seconds(1, timer_func, self);
302+ self->priv->timer = g_timeout_add_full(G_PRIORITY_HIGH, 865, timer_func, self, NULL);
303 } else {
304 if (datetime == NULL) {
305 datetime = g_date_time_new_now_local();
306@@ -1154,9 +1154,9 @@
307 } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_CLEAR_MARKS)) {
308 ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data));
309 } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_SET_DATE)) {
310- // const gint * array = g_variant_get_fixed_array(value, NULL, sizeof(gint));
311- // TODO: Needs ido branch merged - lp:~karl-qdh/ido/select-activate-set-date
312- // ido_calendar_menu_item_set_date (IDO_CALENDAR_MENU_ITEM (mi_data), array[0], array[1], array[2]);
313+ gsize size = 3;
314+ const gint * array = g_variant_get_fixed_array(value, &size, sizeof(gint));
315+ ido_calendar_menu_item_set_date (IDO_CALENDAR_MENU_ITEM (mi_data), array[0], array[1], array[2]);
316 } else {
317 g_warning("Indicator Item property '%s' unknown", prop);
318 }
319@@ -1257,13 +1257,10 @@
320 guint timestamp = (guint)time(NULL);
321 dbusmenu_menuitem_handle_event(DBUSMENU_MENUITEM(item), "month-changed", variant, timestamp);
322 }
323-
324-// TODO: Needs ido branch merged - lp:~karl-qdh/ido/select-activate-set-date
325-/*
326+
327 static void
328 day_selected_cb (IdoCalendarMenuItem *ido,
329- guint day,
330- gpointer user_data)
331+ gpointer user_data)
332 {
333 guint d,m,y;
334 DbusmenuMenuitem * item = DBUSMENU_MENUITEM (user_data);
335@@ -1281,7 +1278,6 @@
336
337 static void
338 day_selected_double_click_cb (IdoCalendarMenuItem *ido,
339- guint day,
340 gpointer user_data)
341 {
342 guint d,m,y;
343@@ -1297,8 +1293,6 @@
344 guint timestamp = (guint)time(NULL);
345 dbusmenu_menuitem_handle_event(DBUSMENU_MENUITEM(item), "day-selected-double-click", variant, timestamp);
346 }
347-*/
348-
349
350 static gboolean
351 new_calendar_item (DbusmenuMenuitem * newitem,
352@@ -1333,10 +1327,8 @@
353
354 dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(ido), parent);
355 g_signal_connect_after(ido, "month-changed", G_CALLBACK(month_changed_cb), (gpointer)newitem);
356-
357- // TODO: Needs ido branch merged - lp:~karl-qdh/ido/select-activate-set-date
358- /*g_signal_connect_after(ido, "day-selected", G_CALLBACK(day_selected_cb), (gpointer)newitem);
359- g_signal_connect_after(ido, "day-selected-double-click", G_CALLBACK(day_selected_double_click_cb), (gpointer)newitem);*/
360+ g_signal_connect_after(ido, "day-selected", G_CALLBACK(day_selected_cb), (gpointer)newitem);
361+ g_signal_connect_after(ido, "day-selected-double-click", G_CALLBACK(day_selected_double_click_cb), (gpointer)newitem);
362
363 return TRUE;
364 }

Subscribers

People subscribed via source and target branches