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 | |
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
-rw-r--r-- | debian/changelog | 2 | ||||
-rw-r--r-- | libmessaging-menu/messaging-menu.c | 42 | ||||
-rw-r--r-- | src/indicator-messages.c | 92 |
3 files changed, 98 insertions, 38 deletions
diff --git a/debian/changelog b/debian/changelog index 9c45768..4e46ba1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -12,7 +12,7 @@ indicator-messages (12.10.0-0ubuntu1) UNRELEASED; urgency=low * Updated packaging to dh9, current standards * Drop gtk2 build from the packaging since support for it was dropped in trunk, thanks Lars Uebernickel - * Backported fixes from trunk up to r284, some of those are needed for the + * Backported fixes from trunk up to r286, some of those are needed for the bindings to work -- Sebastien Bacher <seb128@ubuntu.com> Tue, 21 Aug 2012 18:17:34 +0200 diff --git a/libmessaging-menu/messaging-menu.c b/libmessaging-menu/messaging-menu.c index 69fb3b7..387412e 100644 --- a/libmessaging-menu/messaging-menu.c +++ b/libmessaging-menu/messaging-menu.c @@ -39,6 +39,7 @@ struct _MessagingMenuApp GMenu *menu; IndicatorMessagesService *messages_service; + guint watch_id; GCancellable *cancellable; }; @@ -119,6 +120,12 @@ messaging_menu_app_dispose (GObject *object) { MessagingMenuApp *app = MESSAGING_MENU_APP (object); + if (app->watch_id > 0) + { + g_bus_unwatch_name (app->watch_id); + app->watch_id = 0; + } + if (app->cancellable) { g_cancellable_cancel (app->cancellable); @@ -243,6 +250,17 @@ got_session_bus (GObject *source, g_error_free (error); } + g_object_unref (bus); +} + +static void +indicator_messages_appeared (GDBusConnection *bus, + const gchar *name, + const gchar *name_owner, + gpointer user_data) +{ + MessagingMenuApp *app = user_data; + indicator_messages_service_proxy_new (bus, G_DBUS_PROXY_FLAGS_NONE, "com.canonical.indicator.messages", @@ -250,8 +268,22 @@ got_session_bus (GObject *source, app->cancellable, created_messages_service, app); +} - g_object_unref (bus); +static void +indicator_messages_vanished (GDBusConnection *bus, + const gchar *name, + gpointer user_data) +{ + MessagingMenuApp *app = user_data; + + if (app->messages_service) + { + g_signal_handlers_disconnect_by_func (app->messages_service, + global_status_changed, + app); + g_clear_object (&app->messages_service); + } } static void @@ -272,6 +304,14 @@ messaging_menu_app_init (MessagingMenuApp *app) app->cancellable, got_session_bus, app); + + app->watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION, + "com.canonical.indicator.messages", + G_BUS_NAME_WATCHER_FLAGS_NONE, + indicator_messages_appeared, + indicator_messages_vanished, + app, + NULL); } /** 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); |