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
=== modified file 'src/datetime-service.c'
--- src/datetime-service.c 2011-03-15 02:43:27 +0000
+++ src/datetime-service.c 2011-03-15 15:51:45 +0000
@@ -280,9 +280,6 @@
280static gboolean280static gboolean
281month_changed_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, guint timestamp)281month_changed_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, guint timestamp)
282{282{
283 // BLOCKED: get type, then get type as string from the variant causes segfault in glib
284 // TODO: * Set some globals so when we-re-run update appointment menu items it gets the right start date
285 // * update appointment menu items
286 start_time_appointments = (time_t)g_variant_get_uint32(variant);283 start_time_appointments = (time_t)g_variant_get_uint32(variant);
287 284
288 g_debug("Received month changed with timestamp: %d -> %s",(int)start_time_appointments, ctime(&start_time_appointments)); 285 g_debug("Received month changed with timestamp: %d -> %s",(int)start_time_appointments, ctime(&start_time_appointments));
@@ -290,6 +287,37 @@
290 return TRUE;287 return TRUE;
291}288}
292289
290static gboolean
291day_selected_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, guint timestamp)
292{
293 start_time_appointments = (time_t)g_variant_get_uint32(variant);
294
295 g_debug("Received day-selected with timestamp: %d -> %s",(int)start_time_appointments, ctime(&start_time_appointments));
296 update_appointment_menu_items(NULL);
297 return TRUE;
298}
299
300static gboolean
301day_selected_double_click_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, guint timestamp)
302{
303 time_t evotime = (time_t)g_variant_get_uint32(variant);
304
305 g_debug("Received day-selected-double-click with timestamp: %d -> %s",(int)evotime, ctime(&evotime));
306
307 gchar *ad = isodate_from_time_t(evotime);
308 gchar *cmd = g_strconcat("evolution calendar:///?startdate=", ad, NULL);
309
310 GError * error = NULL;
311
312 g_debug("Issuing command '%s'", cmd);
313 if (!g_spawn_command_line_async(cmd, &error)) {
314 g_warning("Unable to start %s: %s", (char *)cmd, error->message);
315 g_error_free(error);
316 }
317
318 return TRUE;
319}
320
293static guint ecaltimer = 0;321static guint ecaltimer = 0;
294322
295static void323static void
@@ -365,8 +393,10 @@
365 stop_ecal_timer();393 stop_ecal_timer();
366 }394 }
367 395
368 // Connect to event::month-changed 396 // Connect to calendar events
369 g_signal_connect(calendar, "event::month-changed", G_CALLBACK(month_changed_cb), NULL);397 g_signal_connect(calendar, "event::month-changed", G_CALLBACK(month_changed_cb), NULL);
398 g_signal_connect(calendar, "event::day-selected", G_CALLBACK(day_selected_cb), NULL);
399 g_signal_connect(calendar, "event::day-selected-double-click", G_CALLBACK(day_selected_double_click_cb), NULL);
370 g_free(evo);400 g_free(evo);
371 } else {401 } else {
372 g_debug("Unable to find calendar app.");402 g_debug("Unable to find calendar app.");
@@ -543,27 +573,51 @@
543 if (updating_appointments) return TRUE;573 if (updating_appointments) return TRUE;
544 updating_appointments = TRUE;574 updating_appointments = TRUE;
545 575
546 time_t t1, t2;576 time_t curtime = 0, t1 = 0, t2 = 0;
547 gchar *ad;577 gchar *ad;
548 GList *l;578 GList *l;
549 GSList *g;579 GSList *g;
550 GError *gerror = NULL;580 GError *gerror = NULL;
551 gint i;581 gint i;
552 gint width, height;582 gint width = 0, height = 0;
553 ESourceList * sources = NULL;583 ESourceList * sources = NULL;
554 584
555 if (start_time_appointments > 0)585 // Get today & work out query times
556 t1 = start_time_appointments;586 time(&curtime);
557 else587 struct tm *today = localtime(&curtime);
558 time(&t1);588 const int mday = today->tm_mday;
559589 const int mon = today->tm_mon;
560 /* TODO: 7 days ahead of now, we actually need number_of_days_in_this_month 590 const int year = today->tm_year;
561 * so we call "mark-day" for all remaining days in this month591
562 * N.B. Ideally we want any/all dates which are later than today to be marked.592 struct tm *start_tm = NULL;
563 */593 int this_year = today->tm_year + 1900;
564 t2 = t1 + (time_t) (7 * 24 * 60 * 60); 594 int days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
565 595 if ((this_year % 400 == 0) || (this_year % 100 > 0 && this_year % 4 == 0)) days[1] = 29;
566 // TODO Remove all highlights from the calendar widget596
597 int highlightdays = days[mon] - mday + 1;
598 t1 = curtime; // By default the current time is the appointment start time.
599
600 if (start_time_appointments > 0) {
601 start_tm = localtime(&start_time_appointments);
602 int start_month = start_tm->tm_mon;
603 int start_year = start_tm->tm_year + 1900;
604 if ((start_month != mon) || (start_year != this_year)) {
605 // Set t1 to the start of that month.
606 struct tm month_start = {0};
607 month_start.tm_year = start_tm->tm_year;
608 month_start.tm_mon = start_tm->tm_mon;
609 month_start.tm_mday = 1;
610 t1 = mktime(&month_start);
611 highlightdays = days[mon];
612 }
613 }
614
615 g_debug("Will highlight %d days from %s", highlightdays, ctime(&t1));
616
617 t2 = t1 + (time_t) (highlightdays * 24 * 60 * 60);
618
619 // Remove all highlights from the calendar widget
620 dbusmenu_menuitem_property_set (calendar, CALENDAR_MENUITEM_PROP_CLEAR_MARKS, NULL);
567 621
568 if (!e_cal_get_sources(&sources, E_CAL_SOURCE_TYPE_EVENT, &gerror)) {622 if (!e_cal_get_sources(&sources, E_CAL_SOURCE_TYPE_EVENT, &gerror)) {
569 g_debug("Failed to get ecal sources\n");623 g_debug("Failed to get ecal sources\n");
@@ -588,7 +642,7 @@
588 642
589 for (s = e_source_group_peek_sources (group); s; s = s->next) {643 for (s = e_source_group_peek_sources (group); s; s = s->next) {
590 ESource *source = E_SOURCE (s->data);644 ESource *source = E_SOURCE (s->data);
591 //g_signal_connect (G_OBJECT(source), "changed", G_CALLBACK (update_appointment_menu_items), NULL);645 g_signal_connect (G_OBJECT(source), "changed", G_CALLBACK (update_appointment_menu_items), NULL);
592 ECal *ecal = e_cal_new(source, E_CAL_SOURCE_TYPE_EVENT);646 ECal *ecal = e_cal_new(source, E_CAL_SOURCE_TYPE_EVENT);
593 e_cal_set_auth_func (ecal, (ECalAuthFunc) auth_func, NULL);647 e_cal_set_auth_func (ecal, (ECalAuthFunc) auth_func, NULL);
594 648
@@ -605,7 +659,8 @@
605 g_debug("Number of ECalComponents returned: %d", g_list_length(comp_instances));659 g_debug("Number of ECalComponents returned: %d", g_list_length(comp_instances));
606 GList *sorted_comp_instances = g_list_sort(comp_instances, compare_comp_instances);660 GList *sorted_comp_instances = g_list_sort(comp_instances, compare_comp_instances);
607 comp_instances = NULL;661 comp_instances = NULL;
608662 g_debug("Components sorted");
663
609 /* Remove all of the previous appointments */664 /* Remove all of the previous appointments */
610 if (appointments != NULL) {665 if (appointments != NULL) {
611 g_debug("Freeing old appointments");666 g_debug("Freeing old appointments");
@@ -619,9 +674,7 @@
619 }674 }
620 }675 }
621676
622 gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); 677 gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height);
623 // Sometimes these give negative numbers, sometimes large numbers which look like timestamps
624 // is there a buffer overwrite causing it?
625 if (width <= 0) width = 12;678 if (width <= 0) width = 12;
626 if (height <= 0) height = 12;679 if (height <= 0) height = 12;
627 if (width > 30) width = 12;680 if (width > 30) width = 12;
@@ -646,13 +699,34 @@
646 char right[20];699 char right[20];
647 //const gchar *uri;700 //const gchar *uri;
648 DbusmenuMenuitem * item;701 DbusmenuMenuitem * item;
649702
650 g_debug("Start Object %p", ecalcomp);703 ECalComponentVType vtype = e_cal_component_get_vtype (ecalcomp);
651 704 struct tm *due = NULL;
652 // TODO Mark days705 if (vtype == E_CAL_COMPONENT_EVENT) due = localtime(&ci->start);
706 else if (vtype == E_CAL_COMPONENT_TODO) due = localtime(&ci->end);
707 else continue;
708
709 const int dmday = due->tm_mday;
710 const int dmon = due->tm_mon;
711 const int dyear = due->tm_year;
712
713 // Mark day
714 g_debug("Marking date %s", ctime(&ci->start));
715 dbusmenu_menuitem_property_set_int (calendar, CALENDAR_MENUITEM_PROP_MARK, due->tm_mday);
716
717
718 // If the appointment time is less than the selected date,
719 // don't create an appointment item for it.
720 if (vtype == E_CAL_COMPONENT_EVENT) {
721 if (ci->start < start_time_appointments) continue;
722 } else if (vtype == E_CAL_COMPONENT_TODO) {
723 if (ci->end < start_time_appointments) continue;
724 }
653 725
654 if (i >= 5) continue;726 if (i >= 5) continue;
655 i++;727 i++;
728
729 g_debug("Create menu item");
656 730
657 item = dbusmenu_menuitem_new();731 item = dbusmenu_menuitem_new();
658 dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_TYPE, APPOINTMENT_MENUITEM_TYPE);732 dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_TYPE, APPOINTMENT_MENUITEM_TYPE);
@@ -668,25 +742,6 @@
668 g_free (summary);742 g_free (summary);
669743
670 // Due text744 // Due text
671 ECalComponentVType vtype = e_cal_component_get_vtype (ecalcomp);
672
673 // Get today
674 time_t curtime = time(NULL);
675 struct tm *today = localtime(&curtime);
676
677 int mday = today->tm_mday;
678 int mon = today->tm_mon;
679 int year = today->tm_year;
680
681 struct tm *due;
682 if (vtype == E_CAL_COMPONENT_EVENT) due = localtime(&ci->start);
683 else if (vtype == E_CAL_COMPONENT_TODO) due = localtime(&ci->end);
684 else continue;
685
686 int dmday = due->tm_mday;
687 int dmon = due->tm_mon;
688 int dyear = due->tm_year;
689
690 if (apt_output == SETTINGS_TIME_12_HOUR) {745 if (apt_output == SETTINGS_TIME_12_HOUR) {
691 if ((mday == dmday) && (mon == dmon) && (year == dyear))746 if ((mday == dmday) && (mon == dmon) && (year == dyear))
692 strftime(right, 20, _(DEFAULT_TIME_12_FORMAT), due);747 strftime(right, 20, _(DEFAULT_TIME_12_FORMAT), due);
@@ -703,7 +758,6 @@
703 else758 else
704 strftime(right, 20, _(DEFAULT_TIME_FORMAT_WITH_DAY), due);759 strftime(right, 20, _(DEFAULT_TIME_FORMAT_WITH_DAY), due);
705 }760 }
706
707 g_debug("Appointment time: %s, for date %s", right, asctime(due));761 g_debug("Appointment time: %s, for date %s", right, asctime(due));
708 dbusmenu_menuitem_property_set (item, APPOINTMENT_MENUITEM_PROP_RIGHT, right);762 dbusmenu_menuitem_property_set (item, APPOINTMENT_MENUITEM_PROP_RIGHT, right);
709 763
@@ -723,10 +777,9 @@
723 // Draw the correct icon for the appointment type and then tint it using mask fill.777 // Draw the correct icon for the appointment type and then tint it using mask fill.
724 // For now we'll create a circle778 // For now we'll create a circle
725 if (color_spec != NULL) {779 if (color_spec != NULL) {
726 // Fixme causes segfault, but we have colours now yay!
727 GdkColor color;780 GdkColor color;
728 gdk_color_parse (color_spec, &color); 781 gdk_color_parse (color_spec, &color);
729 g_debug("Creating a cairo surface\n size, %d by %d", width, height); 782 g_debug("Creating a cairo surface: size, %d by %d", width, height);
730 cairo_surface_t *surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, width, height ); 783 cairo_surface_t *surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, width, height );
731784
732 cairo_t *cr = cairo_create(surface);785 cairo_t *cr = cairo_create(surface);
@@ -771,13 +824,13 @@
771 824
772 dbusmenu_menuitem_property_set_image (item, APPOINTMENT_MENUITEM_PROP_ICON, pixbuf);825 dbusmenu_menuitem_property_set_image (item, APPOINTMENT_MENUITEM_PROP_ICON, pixbuf);
773 } else {826 } else {
774 g_debug("Creating pixbuf from surface failed\n Couldn't create new pixbuf for size, %d by %d", width, height);827 g_debug("Creating pixbuf from surface failed");
775 }828 }
776 cairo_surface_destroy (surface);829 cairo_surface_destroy (surface);
777 cairo_destroy(cr);830 cairo_destroy(cr);
778 }831 }
779 dbusmenu_menuitem_child_add_position (root, item, 2+i);832 dbusmenu_menuitem_child_add_position (root, item, 2+i);
780 appointments = g_list_append (appointments, item); // Keep track of the items here to make them east to remove833 appointments = g_list_append (appointments, item); // Keep track of the items here to make them easy to remove
781 g_debug("Adding appointment: %p", item);834 g_debug("Adding appointment: %p", item);
782 }835 }
783 836
@@ -785,8 +838,8 @@
785 for (l = sorted_comp_instances; l; l = l->next) { 838 for (l = sorted_comp_instances; l; l = l->next) {
786 const struct comp_instance *ci = l->data;839 const struct comp_instance *ci = l->data;
787 g_object_unref(ci->comp);840 g_object_unref(ci->comp);
788 g_list_free(sorted_comp_instances);
789 }841 }
842 g_list_free(sorted_comp_instances);
790 843
791 updating_appointments = FALSE;844 updating_appointments = FALSE;
792 g_debug("End of objects");845 g_debug("End of objects");
@@ -820,6 +873,12 @@
820 check_timezone_sync();873 check_timezone_sync();
821}874}
822875
876static void
877time_format_changed (void)
878{
879 update_appointment_menu_items(NULL);
880}
881
823/* Does the work to build the default menu, really calls out882/* Does the work to build the default menu, really calls out
824 to other functions but this is the core to clean up the883 to other functions but this is the core to clean up the
825 main function. */884 main function. */
@@ -872,6 +931,7 @@
872 g_signal_connect (conf, "changed::" SETTINGS_SHOW_LOCATIONS_S, G_CALLBACK (show_locations_changed), NULL);931 g_signal_connect (conf, "changed::" SETTINGS_SHOW_LOCATIONS_S, G_CALLBACK (show_locations_changed), NULL);
873 g_signal_connect (conf, "changed::" SETTINGS_LOCATIONS_S, G_CALLBACK (show_locations_changed), NULL);932 g_signal_connect (conf, "changed::" SETTINGS_LOCATIONS_S, G_CALLBACK (show_locations_changed), NULL);
874 g_signal_connect (conf, "changed::" SETTINGS_SHOW_EVENTS_S, G_CALLBACK (show_events_changed), NULL);933 g_signal_connect (conf, "changed::" SETTINGS_SHOW_EVENTS_S, G_CALLBACK (show_events_changed), NULL);
934 g_signal_connect (conf, "changed::" SETTINGS_TIME_FORMAT_S, G_CALLBACK (time_format_changed), NULL);
875935
876 DbusmenuMenuitem * separator = dbusmenu_menuitem_new();936 DbusmenuMenuitem * separator = dbusmenu_menuitem_new();
877 dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR);937 dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR);
878938
=== modified file 'src/indicator-datetime.c'
--- src/indicator-datetime.c 2011-03-15 02:40:24 +0000
+++ src/indicator-datetime.c 2011-03-15 15:51:45 +0000
@@ -813,7 +813,7 @@
813 813
814 if (self->priv->show_seconds ||814 if (self->priv->show_seconds ||
815 (self->priv->time_mode == SETTINGS_TIME_CUSTOM && self->priv->custom_show_seconds)) {815 (self->priv->time_mode == SETTINGS_TIME_CUSTOM && self->priv->custom_show_seconds)) {
816 self->priv->timer = g_timeout_add_seconds(1, timer_func, self);816 self->priv->timer = g_timeout_add_full(G_PRIORITY_HIGH, 865, timer_func, self, NULL);
817 } else {817 } else {
818 if (datetime == NULL) {818 if (datetime == NULL) {
819 datetime = g_date_time_new_now_local();819 datetime = g_date_time_new_now_local();
@@ -1154,9 +1154,9 @@
1154 } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_CLEAR_MARKS)) {1154 } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_CLEAR_MARKS)) {
1155 ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data));1155 ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data));
1156 } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_SET_DATE)) {1156 } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_SET_DATE)) {
1157 // const gint * array = g_variant_get_fixed_array(value, NULL, sizeof(gint));1157 gsize size = 3;
1158 // TODO: Needs ido branch merged - lp:~karl-qdh/ido/select-activate-set-date1158 const gint * array = g_variant_get_fixed_array(value, &size, sizeof(gint));
1159 // ido_calendar_menu_item_set_date (IDO_CALENDAR_MENU_ITEM (mi_data), array[0], array[1], array[2]);1159 ido_calendar_menu_item_set_date (IDO_CALENDAR_MENU_ITEM (mi_data), array[0], array[1], array[2]);
1160 } else {1160 } else {
1161 g_warning("Indicator Item property '%s' unknown", prop);1161 g_warning("Indicator Item property '%s' unknown", prop);
1162 }1162 }
@@ -1257,13 +1257,10 @@
1257 guint timestamp = (guint)time(NULL);1257 guint timestamp = (guint)time(NULL);
1258 dbusmenu_menuitem_handle_event(DBUSMENU_MENUITEM(item), "month-changed", variant, timestamp);1258 dbusmenu_menuitem_handle_event(DBUSMENU_MENUITEM(item), "month-changed", variant, timestamp);
1259}1259}
12601260
1261// TODO: Needs ido branch merged - lp:~karl-qdh/ido/select-activate-set-date
1262/*
1263static void1261static void
1264day_selected_cb (IdoCalendarMenuItem *ido,1262day_selected_cb (IdoCalendarMenuItem *ido,
1265 guint day,1263 gpointer user_data)
1266 gpointer user_data)
1267{1264{
1268 guint d,m,y;1265 guint d,m,y;
1269 DbusmenuMenuitem * item = DBUSMENU_MENUITEM (user_data);1266 DbusmenuMenuitem * item = DBUSMENU_MENUITEM (user_data);
@@ -1281,7 +1278,6 @@
12811278
1282static void1279static void
1283day_selected_double_click_cb (IdoCalendarMenuItem *ido,1280day_selected_double_click_cb (IdoCalendarMenuItem *ido,
1284 guint day,
1285 gpointer user_data) 1281 gpointer user_data)
1286{1282{
1287 guint d,m,y;1283 guint d,m,y;
@@ -1297,8 +1293,6 @@
1297 guint timestamp = (guint)time(NULL);1293 guint timestamp = (guint)time(NULL);
1298 dbusmenu_menuitem_handle_event(DBUSMENU_MENUITEM(item), "day-selected-double-click", variant, timestamp);1294 dbusmenu_menuitem_handle_event(DBUSMENU_MENUITEM(item), "day-selected-double-click", variant, timestamp);
1299}1295}
1300*/
1301
13021296
1303static gboolean1297static gboolean
1304new_calendar_item (DbusmenuMenuitem * newitem,1298new_calendar_item (DbusmenuMenuitem * newitem,
@@ -1333,10 +1327,8 @@
13331327
1334 dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(ido), parent);1328 dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(ido), parent);
1335 g_signal_connect_after(ido, "month-changed", G_CALLBACK(month_changed_cb), (gpointer)newitem);1329 g_signal_connect_after(ido, "month-changed", G_CALLBACK(month_changed_cb), (gpointer)newitem);
1336 1330 g_signal_connect_after(ido, "day-selected", G_CALLBACK(day_selected_cb), (gpointer)newitem);
1337 // TODO: Needs ido branch merged - lp:~karl-qdh/ido/select-activate-set-date1331 g_signal_connect_after(ido, "day-selected-double-click", G_CALLBACK(day_selected_double_click_cb), (gpointer)newitem);
1338 /*g_signal_connect_after(ido, "day-selected", G_CALLBACK(day_selected_cb), (gpointer)newitem);
1339 g_signal_connect_after(ido, "day-selected-double-click", G_CALLBACK(day_selected_double_click_cb), (gpointer)newitem);*/
13401332
1341 return TRUE;1333 return TRUE;
1342}1334}

Subscribers

People subscribed via source and target branches