diff options
author | Sebastien Bacher <seb128@ubuntu.com> | 2012-08-24 11:56:54 +0200 |
---|---|---|
committer | Sebastien Bacher <seb128@ubuntu.com> | 2012-08-24 11:56:54 +0200 |
commit | 1e2a94c141361b6b2269cb030a72bee068442942 (patch) | |
tree | 4d87ab627fc64d022df4720fe4edd4c7b5c4a521 /src | |
parent | f070076dd2d20dc90bdd9507acd751ec83070ae2 (diff) | |
parent | 423d61b377588e67cb570480828f752925371f85 (diff) | |
download | ayatana-indicator-messages-1e2a94c141361b6b2269cb030a72bee068442942.tar.gz ayatana-indicator-messages-1e2a94c141361b6b2269cb030a72bee068442942.tar.bz2 ayatana-indicator-messages-1e2a94c141361b6b2269cb030a72bee068442942.zip |
Backported fixes from trunk up to r286, some of those are needed for the
Diffstat (limited to 'src')
-rw-r--r-- | src/indicator-messages.c | 92 |
1 files changed, 56 insertions, 36 deletions
diff --git a/src/indicator-messages.c b/src/indicator-messages.c index 946da55..b3166f5 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -61,6 +61,7 @@ struct _IndicatorMessages { GMenu *menu_wrapper; GMenuModel *menu; GtkWidget *image; + GtkWidget *gtkmenu; gchar *accessible_desc; }; @@ -75,6 +76,9 @@ static void indicator_messages_class_init (IndicatorMessagesClass *klass); static void indicator_messages_init (IndicatorMessages *self); static void indicator_messages_dispose (GObject *object); static void indicator_messages_finalize (GObject *object); +static void service_connection_changed (IndicatorServiceManager *sm, + gboolean connected, + gpointer user_data); static GtkImage * get_image (IndicatorObject * io); static GtkMenu * get_menu (IndicatorObject * io); static const gchar * get_accessible_desc (IndicatorObject * io); @@ -110,40 +114,14 @@ indicator_messages_class_init (IndicatorMessagesClass *klass) static void indicator_messages_init (IndicatorMessages *self) { - GDBusConnection *bus; - GError *error = NULL; - - /* Default values */ - self->service = NULL; - - /* Complex stuff */ self->service = indicator_service_manager_new_version(INDICATOR_MESSAGES_DBUS_NAME, 1); + g_signal_connect (self->service, "connection-change", + G_CALLBACK (service_connection_changed), self); - bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); - if (!bus) { - g_warning ("error connecting to the session bus: %s", error->message); - g_error_free (error); - return; - } - - self->actions = G_ACTION_GROUP (g_dbus_action_group_get (bus, - INDICATOR_MESSAGES_DBUS_NAME, - INDICATOR_MESSAGES_DBUS_OBJECT)); - - self->menu = G_MENU_MODEL (g_dbus_menu_model_get (bus, - INDICATOR_MESSAGES_DBUS_NAME, - INDICATOR_MESSAGES_DBUS_OBJECT)); - - g_signal_connect (self->menu, "items-changed", G_CALLBACK (menu_items_changed), self); + self->menu_wrapper = g_object_ref_sink (g_menu_new ()); + self->gtkmenu = gtk_menu_new_from_model (G_MENU_MODEL (self->menu_wrapper)); self->image = g_object_ref_sink (gtk_image_new ()); - gtk_widget_show (self->image); - update_root_item (self); - - self->menu_wrapper = g_menu_new (); - update_menu (self); - - g_object_unref (bus); /* make sure custom menu item types are registered (so that * gtk_model_new_from_menu can pick them up */ @@ -162,6 +140,7 @@ indicator_messages_dispose (GObject *object) g_clear_object (&self->menu_wrapper); g_clear_object (&self->actions); g_clear_object (&self->menu); + g_clear_object (&self->gtkmenu); g_clear_object (&self->image); G_OBJECT_CLASS (indicator_messages_parent_class)->dispose (object); @@ -184,11 +163,56 @@ indicator_messages_finalize (GObject *object) /* Functions */ +static void service_connection_changed (IndicatorServiceManager *sm, + gboolean connected, + gpointer user_data) +{ + IndicatorMessages *self = user_data; + GDBusConnection *bus; + GError *error = NULL; + + g_clear_object (&self->actions); + if (self->menu != NULL) { + g_signal_handlers_disconnect_by_func (self->menu, menu_items_changed, self); + g_clear_object (&self->menu); + } + if (g_menu_model_get_n_items (G_MENU_MODEL (self->menu_wrapper)) == 1) + g_menu_remove (self->menu_wrapper, 0); + + if (connected == FALSE) + return; + + bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); + if (!bus) { + g_warning ("error connecting to the session bus: %s", error->message); + g_error_free (error); + return; + } + + self->actions = G_ACTION_GROUP (g_dbus_action_group_get (bus, + INDICATOR_MESSAGES_DBUS_NAME, + INDICATOR_MESSAGES_DBUS_OBJECT)); + gtk_widget_insert_action_group (self->gtkmenu, + get_name_hint (INDICATOR_OBJECT (self)), + self->actions); + + self->menu = G_MENU_MODEL (g_dbus_menu_model_get (bus, + INDICATOR_MESSAGES_DBUS_NAME, + INDICATOR_MESSAGES_DBUS_OBJECT)); + g_signal_connect (self->menu, "items-changed", G_CALLBACK (menu_items_changed), self); + + update_root_item (self); + update_menu (self); + + g_object_unref (bus); +} + static GtkImage * get_image (IndicatorObject * io) { IndicatorMessages *self = INDICATOR_MESSAGES (io); + gtk_widget_show (self->image); return GTK_IMAGE (self->image); } @@ -196,12 +220,8 @@ static GtkMenu * get_menu (IndicatorObject * io) { IndicatorMessages *self = INDICATOR_MESSAGES (io); - GtkWidget *menu; - - menu = gtk_menu_new_from_model (G_MENU_MODEL (self->menu_wrapper)); - gtk_widget_insert_action_group (menu, get_name_hint (io), self->actions); - return GTK_MENU (menu); + return GTK_MENU (self->gtkmenu); } static const gchar * @@ -269,7 +289,7 @@ update_menu (IndicatorMessages *self) GMenuModel *popup; GMenuItem *item; - if (g_menu_model_get_n_items (self->menu) == 0) + if (self->menu == NULL || g_menu_model_get_n_items (self->menu) == 0) return; popup = g_menu_model_get_item_link (self->menu, 0, G_MENU_LINK_SUBMENU); |