From 33e222af5379438fd002f1c816baf8f27c36a880 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 3 Oct 2012 23:42:04 -0500 Subject: a timing issue was causing the appointment menuitems to be grouped into the wrong section. Resolve this by creating them at the same time as the 'Add Event...' menuitem in the same group. --- src/datetime-service.c | 96 +++++++++++++++++++++----------------------------- 1 file changed, 40 insertions(+), 56 deletions(-) (limited to 'src/datetime-service.c') diff --git a/src/datetime-service.c b/src/datetime-service.c index 6d3c56a..bac7d7c 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -54,6 +54,8 @@ with this program. If not, see . /* how often to check for clock skew */ #define SKEW_CHECK_INTERVAL_SEC 10 +#define MAX_APPOINTMENT_MENUITEMS 5 + #define SKEW_DIFF_THRESHOLD_SEC (SKEW_CHECK_INTERVAL_SEC + 5) #ifdef HAVE_CCPANEL @@ -84,7 +86,7 @@ static DbusmenuMenuitem * settings = NULL; static DbusmenuMenuitem * events_separator = NULL; static DbusmenuMenuitem * locations_separator = NULL; static DbusmenuMenuitem * add_appointment = NULL; -static GList * appointments = NULL; +static DbusmenuMenuitem * appointments[MAX_APPOINTMENT_MENUITEMS]; static GSList * location_menu_items = NULL; static GList * comp_instances = NULL; static gboolean updating_appointments = FALSE; @@ -392,6 +394,15 @@ update_appointment_menu_items_idle (gpointer user_data) return FALSE; } +static void +hide_all_appointments (void) +{ + int i; + + for (i=0; idata); - dbusmenu_menuitem_property_set_bool(mi, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); - } + hide_all_appointments (); g_idle_add(update_appointment_menu_items_idle, NULL); return TRUE; @@ -439,11 +446,7 @@ day_selected_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, gu } } - GList * appointment; - for (appointment = appointments; appointment != NULL; appointment = g_list_next(appointment)) { - DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(appointment->data); - dbusmenu_menuitem_property_set_bool(mi, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); - } + hide_all_appointments (); start_time_appointments = new_time; @@ -512,17 +515,7 @@ show_events_changed (void) } else { dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); dbusmenu_menuitem_property_set_bool(events_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); - /* Remove all of the previous appointments */ - if (appointments != NULL) { - g_debug("Hiding old appointments"); - GList * appointment; - for (appointment = appointments; appointment != NULL; appointment = g_list_next(appointment)) { - DbusmenuMenuitem * litem = DBUSMENU_MENUITEM(appointment->data); - g_debug("Hiding old appointment: %p", litem); - // Remove all the existing menu items which are in appointments. - dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(litem), DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); - } - } + hide_all_appointments (); stop_ecal_timer(); } } @@ -551,19 +544,32 @@ check_for_calendar (gpointer user_data) dbusmenu_menuitem_property_set_bool(date, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); if (!get_greeter_mode () && calendar_app_is_usable()) { + + int i; + int pos = 2; g_signal_connect (G_OBJECT(date), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_cb), "evolution -c calendar"); events_separator = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(events_separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); - dbusmenu_menuitem_child_add_position(root, events_separator, 2); + dbusmenu_menuitem_child_add_position(root, events_separator, pos++); + + for (i=0; idata); - g_debug("Hiding old appointment: %p", litem); - // Remove all the existing menu items which are in appointments. - dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(litem), DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); - } - } + + hide_all_appointments (); gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); if (width <= 0) width = 12; @@ -796,7 +792,6 @@ update_appointment_menu_items (gpointer unused) g_variant_builder_init (&markeddays, G_VARIANT_TYPE ("ai")); i = 0; - GList * cached_appointment = appointments; for (l = sorted_comp_instances; l; l = l->next) { struct comp_instance *ci = l->data; ECalComponent *ecalcomp = ci->comp; @@ -828,28 +823,17 @@ update_appointment_menu_items (gpointer unused) } else if (vtype == E_CAL_COMPONENT_TODO) { if (ci->end < start_time_appointments) continue; } - - if (i >= 5) continue; + + if (i >= MAX_APPOINTMENT_MENUITEMS) continue; i++; - if (cached_appointment == NULL) { - g_debug("Create menu item"); - - item = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_TYPE, APPOINTMENT_MENUITEM_TYPE); - - dbusmenu_menuitem_child_add_position (root, item, 2+i); - appointments = g_list_append (appointments, item); // Keep track of the items here to make them easy to remove - } else { - item = DBUSMENU_MENUITEM(cached_appointment->data); - cached_appointment = g_list_next(cached_appointment); + item = appointments[i]; - /* Remove the icon as we might not replace it on error */ - dbusmenu_menuitem_property_remove(item, APPOINTMENT_MENUITEM_PROP_ICON); + /* Remove the icon as we might not replace it on error */ + dbusmenu_menuitem_property_remove(item, APPOINTMENT_MENUITEM_PROP_ICON); - /* Remove the activate handler */ - g_signal_handlers_disconnect_matched(G_OBJECT(item), G_SIGNAL_MATCH_FUNC, 0, 0, NULL, G_CALLBACK(activate_cb), NULL); - } + /* Remove the activate handler */ + g_signal_handlers_disconnect_matched(G_OBJECT(item), G_SIGNAL_MATCH_FUNC, 0, 0, NULL, G_CALLBACK(activate_cb), NULL); dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); -- cgit v1.2.3