diff options
-rw-r--r-- | src/datetime-service.c | 115 | ||||
-rw-r--r-- | src/dbus-shared.h | 4 | ||||
-rw-r--r-- | src/indicator-datetime.c | 129 | ||||
-rw-r--r-- | src/settings-shared.h | 2 |
4 files changed, 160 insertions, 90 deletions
diff --git a/src/datetime-service.c b/src/datetime-service.c index e284418..5172eea 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -276,22 +276,70 @@ activate_cb (DbusmenuMenuitem * menuitem, guint timestamp, const gchar *command) } static gboolean +update_appointment_menu_items_idle (gpointer user_data) +{ + update_appointment_menu_items(user_data); + return FALSE; +} + +static gboolean month_changed_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, guint timestamp) { start_time_appointments = (time_t)g_variant_get_uint32(variant); g_debug("Received month changed with timestamp: %d -> %s",(int)start_time_appointments, ctime(&start_time_appointments)); - update_appointment_menu_items(NULL); + /* By default one of the first things we do is + clear the marks as we don't know the correct + ones yet and we don't want to confuse the + user. */ + dbusmenu_menuitem_property_remove(menuitem, CALENDAR_MENUITEM_PROP_MARKS); + + 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); + } + + g_idle_add(update_appointment_menu_items_idle, NULL); return TRUE; } static gboolean day_selected_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, guint timestamp) { - start_time_appointments = (time_t)g_variant_get_uint32(variant); - + time_t new_time = (time_t)g_variant_get_uint32(variant); + g_warn_if_fail(new_time != 0); + + if (start_time_appointments == 0 || new_time == 0) { + /* If we've got nothing, assume everyhting is going to + get repopulated, let's start with a clean slate */ + dbusmenu_menuitem_property_remove(menuitem, CALENDAR_MENUITEM_PROP_MARKS); + } else { + /* No check to see if we changed months. If we did we'll + want to clear the marks. Otherwise we're cool keeping + them around. */ + struct tm start_tm; + struct tm new_tm; + + localtime_r(&start_time_appointments, &start_tm); + localtime_r(&new_time, &new_tm); + + if (start_tm.tm_mon != new_tm.tm_mon) { + dbusmenu_menuitem_property_remove(menuitem, CALENDAR_MENUITEM_PROP_MARKS); + } + } + + 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); + } + + start_time_appointments = new_time; + g_debug("Received day-selected with timestamp: %d -> %s",(int)start_time_appointments, ctime(&start_time_appointments)); - update_appointment_menu_items(NULL); + g_idle_add(update_appointment_menu_items_idle, NULL); + return TRUE; } @@ -372,14 +420,13 @@ show_events_changed (void) dbusmenu_menuitem_property_set_bool(events_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); /* Remove all of the previous appointments */ if (appointments != NULL) { - g_debug("Freeing old appointments"); - while (appointments != NULL) { - DbusmenuMenuitem * litem = DBUSMENU_MENUITEM(appointments->data); - g_debug("Freeing old appointment: %p", litem); + 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. - appointments = g_list_remove(appointments, litem); - dbusmenu_menuitem_child_delete(root, DBUSMENU_MENUITEM(litem)); - g_object_unref(G_OBJECT(litem)); + dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(litem), DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); } } stop_ecal_timer(); @@ -607,7 +654,7 @@ update_appointment_menu_items (gpointer user_data) const int mday = today->tm_mday; const int mon = today->tm_mon; const int year = today->tm_year; - + struct tm *start_tm = NULL; int this_year = today->tm_year + 1900; int days[12]={31,28,31,30,31,30,31,31,30,31,30,31}; @@ -677,16 +724,15 @@ update_appointment_menu_items (gpointer user_data) comp_instances = NULL; g_debug("Components sorted"); - /* Remove all of the previous appointments */ + /* Hiding all of the previous appointments */ if (appointments != NULL) { - g_debug("Freeing old appointments"); - while (appointments != NULL) { - DbusmenuMenuitem * litem = DBUSMENU_MENUITEM(appointments->data); - g_debug("Freeing old appointment: %p", litem); + 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. - appointments = g_list_remove(appointments, litem); - dbusmenu_menuitem_child_delete(root, DBUSMENU_MENUITEM(litem)); - g_object_unref(G_OBJECT(litem)); + dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(litem), DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); } } @@ -710,6 +756,7 @@ update_appointment_menu_items (gpointer user_data) g_variant_builder_init (&markeddays, G_VARIANT_TYPE_ARRAY); 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; @@ -744,12 +791,28 @@ update_appointment_menu_items (gpointer user_data) if (i >= 5) continue; i++; - g_debug("Create menu item"); - - item = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_TYPE, APPOINTMENT_MENUITEM_TYPE); + 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); + + /* 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); + } + dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + // Label text e_cal_component_get_summary (ecalcomp, &valuetext); @@ -847,8 +910,6 @@ update_appointment_menu_items (gpointer user_data) cairo_surface_destroy (surface); cairo_destroy(cr); } - 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 g_debug("Adding appointment: %p", item); } @@ -860,7 +921,7 @@ update_appointment_menu_items (gpointer user_data) g_list_free(sorted_comp_instances); GVariant * marks = g_variant_builder_end (&markeddays); - dbusmenu_menuitem_property_set_variant (calendar, CALENDAR_MENUITEM_PROP_MARK, marks); + dbusmenu_menuitem_property_set_variant (calendar, CALENDAR_MENUITEM_PROP_MARKS, marks); updating_appointments = FALSE; g_debug("End of objects"); diff --git a/src/dbus-shared.h b/src/dbus-shared.h index 8b1a20b..51632f9 100644 --- a/src/dbus-shared.h +++ b/src/dbus-shared.h @@ -31,9 +31,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. // The following properties are not *really* properties, but are just // a way of accessing the calendar from the service -#define CALENDAR_MENUITEM_PROP_MARK "calendar-mark" -#define CALENDAR_MENUITEM_PROP_UNMARK "calendar-unmark" -#define CALENDAR_MENUITEM_PROP_CLEAR_MARKS "calendar-clear-marks" +#define CALENDAR_MENUITEM_PROP_MARKS "calendar-marks" #define CALENDAR_MENUITEM_PROP_SET_DATE "calendar-set-date" diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index addc2c2..3f9344d 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -101,6 +101,8 @@ struct _IndicatorDatetimePrivate { GList * timezone_items; GSettings * settings; + + GtkSizeGroup * indicator_right_group; }; /* Enum for the properties so that they can be quickly @@ -175,6 +177,9 @@ static void system_proxy_cb (GObject * object, GAsyncResult * res, gpointer use static void service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data); static gint generate_strftime_bitmask (const char *time_str); static void timezone_update_labels (indicator_item_t * mi_data); +static gboolean new_calendar_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); +static gboolean new_appointment_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); +static gboolean new_timezone_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); /* Indicator Module Config */ INDICATOR_SET_VERSION @@ -182,8 +187,6 @@ INDICATOR_SET_TYPE(INDICATOR_DATETIME_TYPE) G_DEFINE_TYPE (IndicatorDatetime, indicator_datetime, INDICATOR_OBJECT_TYPE); -static GtkSizeGroup * indicator_right_group = NULL; - static void indicator_datetime_class_init (IndicatorDatetimeClass *klass) { @@ -341,6 +344,14 @@ indicator_datetime_init (IndicatorDatetime *self) } self->priv->sm = indicator_service_manager_new_version(SERVICE_NAME, SERVICE_VERSION); + self->priv->indicator_right_group = GTK_SIZE_GROUP(gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL)); + + self->priv->menu = dbusmenu_gtkmenu_new(SERVICE_NAME, MENU_OBJ); + + DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(self->priv->menu); + dbusmenu_client_add_type_handler_full(DBUSMENU_CLIENT(client), DBUSMENU_CALENDAR_MENUITEM_TYPE, new_calendar_item, self, NULL); + dbusmenu_client_add_type_handler_full(DBUSMENU_CLIENT(client), APPOINTMENT_MENUITEM_TYPE, new_appointment_item, self, NULL); + dbusmenu_client_add_type_handler_full(DBUSMENU_CLIENT(client), TIMEZONE_MENUITEM_TYPE, new_timezone_item, self, NULL); self->priv->service_proxy_cancel = g_cancellable_new(); @@ -458,6 +469,11 @@ indicator_datetime_dispose (GObject *object) self->priv->service_proxy = NULL; } + if (self->priv->indicator_right_group != NULL) { + g_object_unref(G_OBJECT(self->priv->indicator_right_group)); + self->priv->indicator_right_group = NULL; + } + G_OBJECT_CLASS (indicator_datetime_parent_class)->dispose (object); return; } @@ -540,7 +556,9 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec case PROP_SHOW_CLOCK: { if (g_value_get_boolean(value) != self->priv->show_clock) { self->priv->show_clock = g_value_get_boolean(value); - gtk_widget_set_visible (GTK_WIDGET (self->priv->label), self->priv->show_clock); + if (self->priv->label != NULL) { + gtk_widget_set_visible (GTK_WIDGET (self->priv->label), self->priv->show_clock); + } } break; } @@ -610,7 +628,9 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec case PROP_SHOW_CALENDAR: { if (g_value_get_boolean(value) != self->priv->show_calendar) { self->priv->show_calendar = g_value_get_boolean(value); - gtk_widget_set_visible (GTK_WIDGET (self->priv->ido_calendar), self->priv->show_calendar); + if (self->priv->ido_calendar != NULL) { + gtk_widget_set_visible (GTK_WIDGET (self->priv->ido_calendar), self->priv->show_calendar); + } } break; } @@ -1193,37 +1213,31 @@ indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, static void calendar_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, IdoCalendarMenuItem * mi_data) { - g_debug("Changing calendar property"); - if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_MARK)) { + g_debug("Changing calendar property: %s", prop); + if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_MARKS)) { ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data)); - g_debug("Marks: Cleared"); - GVariantIter *iter; - gint day; - - g_variant_get (value, "ai", &iter); - while (g_variant_iter_loop (iter, "i", &day)) { - ido_calendar_menu_item_mark_day (IDO_CALENDAR_MENU_ITEM (mi_data), day); - g_debug("Marks: Marked day: %d", day); - } - g_variant_iter_free (iter); - } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_UNMARK)) { - GVariantIter *iter; - gint day; - - g_variant_get (value, "ai", &iter); - while (g_variant_iter_loop (iter, "i", &day)) { - g_debug("Unmarked day: %d", day); - ido_calendar_menu_item_unmark_day (IDO_CALENDAR_MENU_ITEM (mi_data), day); + + if (value != NULL) { + GVariantIter *iter; + gint day; + + g_debug("\tMarks: %s", g_variant_print(value, FALSE)); + + g_variant_get (value, "ai", &iter); + while (g_variant_iter_loop (iter, "i", &day)) { + ido_calendar_menu_item_mark_day (IDO_CALENDAR_MENU_ITEM (mi_data), day); + } + g_variant_iter_free (iter); + } else { + g_debug("\tMarks: <cleared>"); } - g_variant_iter_free (iter); - } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_CLEAR_MARKS)) { - ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data)); - g_debug("Cleared Marks"); } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_SET_DATE)) { - gsize size = 3; - const gint * array = g_variant_get_fixed_array(value, &size, sizeof(gint)); - g_debug("Setting date y-m-d: %d-%d-%d", array[0], array[1], array[2]); - ido_calendar_menu_item_set_date (IDO_CALENDAR_MENU_ITEM (mi_data), array[0], array[1], array[2]); + if (value != NULL) { + gsize size = 3; + const gint * array = g_variant_get_fixed_array(value, &size, sizeof(gint)); + g_debug("Setting date y-m-d: %d-%d-%d", array[0], array[1], array[2]); + ido_calendar_menu_item_set_date (IDO_CALENDAR_MENU_ITEM (mi_data), array[0], array[1], array[2]); + } } else { g_warning("Indicator Item property '%s' unknown", prop); } @@ -1241,7 +1255,9 @@ new_appointment_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbu { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); + g_return_val_if_fail(IS_INDICATOR_DATETIME(user_data), FALSE); /* Note: not checking parent, it's reasonable for it to be NULL */ + IndicatorDatetime * self = INDICATOR_DATETIME(user_data); indicator_item_t * mi_data = g_new0(indicator_item_t, 1); @@ -1291,7 +1307,7 @@ new_appointment_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbu /* Usually either the time or the count on the individual item. */ mi_data->right = gtk_label_new(dbusmenu_menuitem_property_get(newitem, APPOINTMENT_MENUITEM_PROP_RIGHT)); - gtk_size_group_add_widget(indicator_right_group, mi_data->right); + gtk_size_group_add_widget(self->priv->indicator_right_group, mi_data->right); gtk_misc_set_alignment(GTK_MISC(mi_data->right), 1.0, 0.5); gtk_box_pack_start(GTK_BOX(hbox), mi_data->right, FALSE, FALSE, 0); gtk_widget_show(mi_data->right); @@ -1365,17 +1381,13 @@ new_calendar_item (DbusmenuMenuitem * newitem, DbusmenuClient * client, gpointer user_data) { + g_debug("New calendar item"); g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); + g_return_val_if_fail(IS_INDICATOR_DATETIME(user_data), FALSE); /* Note: not checking parent, it's reasonable for it to be NULL */ - IndicatorObject *io = g_object_get_data (G_OBJECT (client), "indicator"); - if (io == NULL) { - g_warning ("found no indicator to attach the caledar to"); - return FALSE; - } - - IndicatorDatetime *self = INDICATOR_DATETIME(io); + IndicatorDatetime *self = INDICATOR_DATETIME(user_data); self->priv = INDICATOR_DATETIME_GET_PRIVATE(self); IdoCalendarMenuItem *ido = IDO_CALENDAR_MENU_ITEM (ido_calendar_menu_item_new ()); @@ -1391,11 +1403,26 @@ new_calendar_item (DbusmenuMenuitem * newitem, gtk_widget_set_visible (GTK_WIDGET (self->priv->ido_calendar), self->priv->show_calendar); dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(ido), parent); + g_signal_connect_after(ido, "month-changed", G_CALLBACK(month_changed_cb), (gpointer)newitem); g_signal_connect_after(ido, "day-selected", G_CALLBACK(day_selected_cb), (gpointer)newitem); g_signal_connect_after(ido, "day-selected-double-click", G_CALLBACK(day_selected_double_click_cb), (gpointer)newitem); g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(calendar_prop_change_cb), ido); + + /* Run the current values through prop changed */ + GVariant * propval = NULL; + + propval = dbusmenu_menuitem_property_get_variant(newitem, CALENDAR_MENUITEM_PROP_MARKS); + if (propval != NULL) { + calendar_prop_change_cb(newitem, CALENDAR_MENUITEM_PROP_MARKS, propval, ido); + } + + propval = dbusmenu_menuitem_property_get_variant(newitem, CALENDAR_MENUITEM_PROP_SET_DATE); + if (propval != NULL) { + calendar_prop_change_cb(newitem, CALENDAR_MENUITEM_PROP_SET_DATE, propval, ido); + } + return TRUE; } @@ -1425,15 +1452,10 @@ new_timezone_item(DbusmenuMenuitem * newitem, { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); + g_return_val_if_fail(IS_INDICATOR_DATETIME(user_data), FALSE); /* Note: not checking parent, it's reasonable for it to be NULL */ - - IndicatorObject *io = g_object_get_data (G_OBJECT (client), "indicator"); - if (io == NULL) { - g_warning ("found no indicator to attach the timezone to"); - return FALSE; - } - IndicatorDatetime *self = INDICATOR_DATETIME(io); + IndicatorDatetime * self = INDICATOR_DATETIME(user_data); IndicatorDatetimePrivate *priv = INDICATOR_DATETIME_GET_PRIVATE(self); // Menu item with a radio button and a right aligned time @@ -1460,7 +1482,7 @@ new_timezone_item(DbusmenuMenuitem * newitem, /* Usually either the time or the count on the individual item. */ mi_data->right = gtk_label_new(""); - gtk_size_group_add_widget(indicator_right_group, mi_data->right); + gtk_size_group_add_widget(self->priv->indicator_right_group, mi_data->right); gtk_misc_set_alignment(GTK_MISC(mi_data->right), 1.0, 0.5); gtk_box_pack_start(GTK_BOX(hbox), mi_data->right, FALSE, FALSE, 0); gtk_widget_show(mi_data->right); @@ -1510,17 +1532,6 @@ get_menu (IndicatorObject * io) { IndicatorDatetime * self = INDICATOR_DATETIME(io); - if (self->priv->menu == NULL) { - self->priv->menu = dbusmenu_gtkmenu_new(SERVICE_NAME, MENU_OBJ); - } - - DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(self->priv->menu); - g_object_set_data (G_OBJECT (client), "indicator", io); - - dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_CALENDAR_MENUITEM_TYPE, new_calendar_item); - dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), APPOINTMENT_MENUITEM_TYPE, new_appointment_item); - dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), TIMEZONE_MENUITEM_TYPE, new_timezone_item); - return GTK_MENU(self->priv->menu); } diff --git a/src/settings-shared.h b/src/settings-shared.h index cdbb063..47ee6ef 100644 --- a/src/settings-shared.h +++ b/src/settings-shared.h @@ -51,7 +51,7 @@ enum { #define DEFAULT_TIME_24_FORMAT N_("%H:%M") #define DEFAULT_TIME_FORMAT DEFAULT_TIME_12_FORMAT -#define DEFAULT_TIME_FORMAT_WITH_DAY DEFAULT_TIME_12_FORMAT +#define DEFAULT_TIME_FORMAT_WITH_DAY DEFAULT_TIME_12_FORMAT_WITH_DAY /* TRANSLATORS: A format string for the strftime function for a clock showing the day of the week and the time in 12-hour format without |