From ef6b3b8daaef62a502c60e0faa22c3a4b10c0399 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 13 Nov 2012 13:32:15 +0100 Subject: Move service .xml into a common directory Both the service (in src/) and the client library (in libmessaging-menu/) need access to the dbus interface description file. Until now, it resided in src, with both Makefiles calling gdbus-codegen on it. This patch moves the file to common/ and builds a convenience library that contains only the generated code. --- src/Makefile.am | 30 ++++++------------------------ src/messages-service.xml | 24 ------------------------ 2 files changed, 6 insertions(+), 48 deletions(-) delete mode 100644 src/messages-service.xml (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 1df80e5..a7bfe66 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,8 +1,5 @@ -BUILT_SOURCES = EXTRA_DIST = -CLEANFILES = -DISTCLEANFILES = libexec_PROGRAMS = indicator-messages-service @@ -23,19 +20,20 @@ libmessaging_la_SOURCES = \ im-source-menu-item.h \ ido-detail-label.c \ ido-detail-label.h \ - indicator-messages-service.c \ - indicator-messages-service.h dbus-data.h libmessaging_la_CFLAGS = \ $(APPLET_CFLAGS) \ $(COVERAGE_CFLAGS) \ + -I$(top_builddir)/common \ -Wall \ -Wl,-Bsymbolic-functions \ -Wl,-z,defs \ -Wl,--as-needed \ -Werror \ -DG_LOG_DOMAIN=\"Indicator-Messages\" -libmessaging_la_LIBADD = $(APPLET_LIBS) -lm +libmessaging_la_LIBADD = \ + $(top_builddir)/common/libmessaging-common.la \ + $(APPLET_LIBS) -lm libmessaging_la_LDFLAGS = \ $(COVERAGE_LDFLAGS) \ -module -avoid-version @@ -46,8 +44,6 @@ libmessaging_la_LDFLAGS = \ indicator_messages_service_SOURCES = \ messages-service.c \ - indicator-messages-service.c \ - indicator-messages-service.h \ app-section.c \ app-section.h \ dbus-data.h \ @@ -61,6 +57,7 @@ indicator_messages_service_SOURCES = \ indicator_messages_service_CFLAGS = \ $(APPLET_CFLAGS) \ $(COVERAGE_CFLAGS) \ + -I$(top_builddir)/common \ -Wall \ -Wl,-Bsymbolic-functions \ -Wl,-z,defs \ @@ -69,26 +66,11 @@ indicator_messages_service_CFLAGS = \ -DG_LOG_DOMAIN=\"Indicator-Messages\" indicator_messages_service_LDADD = \ + $(top_builddir)/common/libmessaging-common.la \ $(APPLET_LIBS) indicator_messages_service_LDFLAGS = \ $(COVERAGE_LDFLAGS) -indicator-messages-service.c: $(top_srcdir)/src/messages-service.xml - $(AM_V_GEN) gdbus-codegen \ - --interface-prefix com.canonical.indicator.messages. \ - --generate-c-code indicator-messages-service \ - --c-namespace IndicatorMessages \ - $^ -indicator-messages-service.h: indicator-messages-service.c - -BUILT_SOURCES += \ - indicator-messages-service.c \ - indicator-messages-service.h - EXTRA_DIST += \ messages-service.xml - -CLEANFILES += \ - $(BUILT_SOURCES) - diff --git a/src/messages-service.xml b/src/messages-service.xml deleted file mode 100644 index 00ae154..0000000 --- a/src/messages-service.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3 From 5a9434c6652ef1117a50a9226f8609cea2ee53c0 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 14 Nov 2012 17:57:54 +0100 Subject: Change application to service d-bus protocol Previously, the protocol was simply a menu model and an action group of the currently active sources. The service inserted the menu as a section into the indicator menu. This doesn't work anymore, because applications can (soon) expose individual messages, and the messaging menu doesn't always display all of those at once. This patch introduces a more specific d-bus API. That API is still considered private: applications have to use libmessaging-menu. --- common/Makefile.am | 12 +- ...om.canonical.indicator.messages.application.xml | 21 + libmessaging-menu/messaging-menu-app.c | 511 +++++++++++---------- src/app-section.c | 424 ++++++++++------- test/Makefile.am | 1 + 5 files changed, 555 insertions(+), 414 deletions(-) create mode 100644 common/com.canonical.indicator.messages.application.xml (limited to 'src') diff --git a/common/Makefile.am b/common/Makefile.am index 5bd7e20..0b8bad4 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -9,9 +9,19 @@ indicator-messages-service.c: com.canonical.indicator.messages.service.xml $^ indicator-messages-service.h: indicator-messages-service.c +indicator-messages-application.c: com.canonical.indicator.messages.application.xml + $(AM_V_GEN) gdbus-codegen \ + --interface-prefix com.canonical.indicator.messages. \ + --generate-c-code indicator-messages-application \ + --c-namespace IndicatorMessages \ + $^ +indicator-messages-application.h: indicator-messages-application.c + BUILT_SOURCES = \ indicator-messages-service.c \ - indicator-messages-service.h + indicator-messages-service.h \ + indicator-messages-application.c \ + indicator-messages-application.h libmessaging_common_la_SOURCES = \ $(BUILT_SOURCES) diff --git a/common/com.canonical.indicator.messages.application.xml b/common/com.canonical.indicator.messages.application.xml new file mode 100644 index 0000000..ec095dd --- /dev/null +++ b/common/com.canonical.indicator.messages.application.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/libmessaging-menu/messaging-menu-app.c b/libmessaging-menu/messaging-menu-app.c index 377aea0..20d9474 100644 --- a/libmessaging-menu/messaging-menu-app.c +++ b/libmessaging-menu/messaging-menu-app.c @@ -19,8 +19,10 @@ #include "messaging-menu-app.h" #include "indicator-messages-service.h" +#include "indicator-messages-application.h" #include +#include /** * SECTION:messaging-menu @@ -102,14 +104,13 @@ struct _MessagingMenuApp int registered; /* -1 for unknown */ MessagingMenuStatus status; gboolean status_set; - GSimpleActionGroup *source_actions; - GMenu *menu; GDBusConnection *bus; + GList *sources; + IndicatorMessagesApplication *app_interface; + IndicatorMessagesService *messages_service; guint watch_id; - guint action_export_id; - guint menu_export_id; GCancellable *cancellable; }; @@ -133,10 +134,56 @@ static guint signals[N_SIGNALS]; static const gchar *status_ids[] = { "available", "away", "busy", "invisible", "offline" }; +typedef struct +{ + gchar *id; + GIcon *icon; + gchar *label; + + guint32 count; + gint64 time; + gchar *string; + gboolean draws_attention; +} Source; + static void global_status_changed (IndicatorMessagesService *service, const gchar *status_str, gpointer user_data); +static void +source_free (Source *source) +{ + if (source) + { + g_free (source->id); + g_clear_object (&source->icon); + g_free (source->label); + g_free (source->string); + g_slice_free (Source, source); + } +} + +static GVariant * +source_to_variant (Source *source) +{ + GVariant *v; + gchar *iconstr; + + iconstr = source->icon ? g_icon_to_string (source->icon) : NULL; + + v = g_variant_new ("(sssuxsb)", source->id, + source->label, + iconstr ? iconstr : "", + source->count, + source->time, + source->string ? source->string : "", + source->draws_attention); + + g_free (iconstr); + + return v; +} + static gchar * messaging_menu_app_get_dbus_object_path (MessagingMenuApp *app) { @@ -155,18 +202,14 @@ messaging_menu_app_get_dbus_object_path (MessagingMenuApp *app) } static void -export_menus_and_actions (GObject *source, - GAsyncResult *res, - gpointer user_data) +messaging_menu_app_got_bus (GObject *source, + GAsyncResult *res, + gpointer user_data) { MessagingMenuApp *app = user_data; GError *error = NULL; gchar *object_path; - object_path = messaging_menu_app_get_dbus_object_path (app); - if (!object_path) - return; - app->bus = g_bus_get_finish (res, &error); if (app->bus == NULL) { @@ -175,23 +218,13 @@ export_menus_and_actions (GObject *source, return; } - app->action_export_id = g_dbus_connection_export_action_group (app->bus, - object_path, - G_ACTION_GROUP (app->source_actions), - &error); - if (!app->action_export_id) - { - g_warning ("unable to export action group: %s", error->message); - g_clear_error (&error); - } + object_path = messaging_menu_app_get_dbus_object_path (app); - app->menu_export_id = g_dbus_connection_export_menu_model (app->bus, - object_path, - G_MENU_MODEL (app->menu), - &error); - if (!app->menu_export_id) + if (object_path && + !g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (app->app_interface), + app->bus, object_path, &error)) { - g_warning ("unable to export menu: %s", error->message); + g_warning ("unable to export application interface: %s", error->message); g_clear_error (&error); } @@ -214,7 +247,7 @@ messaging_menu_app_set_desktop_id (MessagingMenuApp *app, g_bus_get (G_BUS_TYPE_SESSION, app->cancellable, - export_menus_and_actions, + messaging_menu_app_got_bus, app); } @@ -248,20 +281,6 @@ messaging_menu_app_dispose (GObject *object) { MessagingMenuApp *app = MESSAGING_MENU_APP (object); - if (app->bus) - { - if (app->action_export_id > 0) - g_dbus_connection_unexport_action_group (app->bus, app->action_export_id); - - if (app->menu_export_id > 0) - g_dbus_connection_unexport_menu_model (app->bus, app->menu_export_id); - - app->action_export_id = 0; - app->menu_export_id = 0; - g_object_unref (app->bus); - app->bus = NULL; - } - if (app->watch_id > 0) { g_bus_unwatch_name (app->watch_id); @@ -283,9 +302,9 @@ messaging_menu_app_dispose (GObject *object) g_clear_object (&app->messages_service); } + g_clear_object (&app->app_interface); g_clear_object (&app->appinfo); - g_clear_object (&app->source_actions); - g_clear_object (&app->menu); + g_clear_object (&app->bus); G_OBJECT_CLASS (messaging_menu_app_parent_class)->dispose (object); } @@ -416,6 +435,72 @@ indicator_messages_vanished (GDBusConnection *bus, } } +static gboolean +messaging_menu_app_list_sources (IndicatorMessagesApplication *app_interface, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + MessagingMenuApp *app = user_data; + GVariantBuilder builder; + GList *it; + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(sssuxsb)")); + + for (it = app->sources; it; it = it->next) + g_variant_builder_add_value (&builder, source_to_variant (it->data)); + + indicator_messages_application_complete_list_sources (app_interface, + invocation, + g_variant_builder_end (&builder)); + + return TRUE; +} + +static gint +compare_source_id (gconstpointer a, + gconstpointer b) +{ + const Source *source = a; + const gchar *id = b; + + return strcmp (source->id, id); +} + +static gboolean +messaging_menu_app_remove_source_internal (MessagingMenuApp *app, + const gchar *source_id) +{ + GList *node; + + node = g_list_find_custom (app->sources, source_id, compare_source_id); + if (node) + { + source_free (node->data); + app->sources = g_list_delete_link (app->sources, node); + return TRUE; + } + + return FALSE; +} + +static gboolean +messaging_menu_app_activate_source (IndicatorMessagesApplication *app_interface, + GDBusMethodInvocation *invocation, + const gchar *source_id, + gpointer user_data) +{ + MessagingMenuApp *app = user_data; + GQuark q = g_quark_from_string (source_id); + + /* Activate implies removing the source, no need for SourcesChanged */ + if (messaging_menu_app_remove_source_internal (app, source_id)) + g_signal_emit (app, signals[ACTIVATE_SOURCE], q, source_id); + + indicator_messages_application_complete_activate_source (app_interface, invocation); + + return TRUE; +} + static void messaging_menu_app_init (MessagingMenuApp *app) { @@ -423,13 +508,13 @@ messaging_menu_app_init (MessagingMenuApp *app) app->status_set = FALSE; app->bus = NULL; - app->action_export_id = 0; - app->menu_export_id = 0; - app->cancellable = g_cancellable_new (); - app->source_actions = g_simple_action_group_new (); - app->menu = g_menu_new (); + app->app_interface = indicator_messages_application_skeleton_new (); + g_signal_connect (app->app_interface, "handle-list-sources", + G_CALLBACK (messaging_menu_app_list_sources), app); + g_signal_connect (app->app_interface, "handle-activate-source", + G_CALLBACK (messaging_menu_app_activate_source), app); app->cancellable = g_cancellable_new (); @@ -604,123 +689,73 @@ global_status_changed (IndicatorMessagesService *service, g_signal_emit (app, signals[STATUS_CHANGED], 0, status); } -static void -source_action_activated (GSimpleAction *action, - GVariant *parameter, - gpointer user_data) +static Source * +messaging_menu_app_lookup_source (MessagingMenuApp *app, + const gchar *id) { - MessagingMenuApp *app = user_data; - const gchar *name = g_action_get_name (G_ACTION (action)); - GQuark q = g_quark_from_string (name); + GList *node; - messaging_menu_app_remove_source (app, name); + node = g_list_find_custom (app->sources, id, compare_source_id); - g_signal_emit (app, signals[ACTIVATE_SOURCE], q, name); + return node ? node->data : NULL; } -static void -messaging_menu_app_insert_source_action (MessagingMenuApp *app, - gint position, - const gchar *id, - GIcon *icon, - const gchar *label, - GVariant *state) +static Source * +messaging_menu_app_get_source (MessagingMenuApp *app, + const gchar *id) { - GSimpleAction *action; - GMenuItem *menuitem; + Source *source; - g_return_if_fail (MESSAGING_MENU_IS_APP (app)); - g_return_if_fail (id != NULL); - - if (g_simple_action_group_lookup (app->source_actions, id)) - { - g_warning ("a source with id '%s' already exists", id); - return; - } - - action = g_simple_action_new_stateful (id, NULL, state); - g_signal_connect (action, "activate", - G_CALLBACK (source_action_activated), app); - g_simple_action_group_insert (app->source_actions, G_ACTION (action)); - g_object_unref (action); - - menuitem = g_menu_item_new (label, id); - g_menu_item_set_attribute (menuitem, "x-canonical-type", "s", "ImSourceMenuItem"); - if (icon) - { - gchar *iconstr = g_icon_to_string (icon); - g_menu_item_set_attribute (menuitem, "x-canonical-icon", "s", iconstr); - g_free (iconstr); - } - g_menu_insert_item (app->menu, position, menuitem); - g_object_unref (menuitem); -} - -static GSimpleAction * -messaging_menu_app_get_source_action (MessagingMenuApp *app, - const gchar *source_id) - -{ - GAction *action; - - g_return_val_if_fail (MESSAGING_MENU_IS_APP (app), NULL); - g_return_val_if_fail (source_id != NULL, NULL); - - action = g_simple_action_group_lookup (app->source_actions, source_id); - if (action == NULL) - g_warning ("a source with id '%s' doesn't exist", source_id); + source = messaging_menu_app_lookup_source (app, id); + if (!source) + g_warning ("a source with id '%s' doesn't exist", id); - return G_SIMPLE_ACTION (action); + return source; } static void -messaging_menu_app_set_source_action (MessagingMenuApp *app, - const gchar *source_id, - guint count, - gint64 time, - const gchar *string) +messaging_menu_app_notify_source_changed (MessagingMenuApp *app, + Source *source) { - GSimpleAction *action; - GVariant *state; - gboolean draws_attention; - GVariant *new_state; - - action = messaging_menu_app_get_source_action (app, source_id); - if (!action) - return; - - state = g_action_get_state (G_ACTION (action)); - g_variant_get_child (state, 3, "b", &draws_attention); - - new_state = g_variant_new ("(uxsb)", count, time, string, draws_attention); - g_simple_action_set_state (action, new_state); - - g_variant_unref (state); + indicator_messages_application_emit_source_changed (app->app_interface, + source_to_variant (source)); } static void -messaging_menu_app_set_draws_attention (MessagingMenuApp *app, - const gchar *source_id, - gboolean draws_attention) +messaging_menu_app_insert_source_internal (MessagingMenuApp *app, + gint position, + const gchar *id, + GIcon *icon, + const gchar *label, + guint count, + gint64 time, + const gchar *string) { - GSimpleAction *action; - GVariant *state; - guint count; - gint64 time; - const gchar *string; - GVariant *new_state; + Source *source; - action = messaging_menu_app_get_source_action (app, source_id); - if (!action) - return; - - state = g_action_get_state (G_ACTION (action)); - g_variant_get (state, "(ux&sb)", &count, &time, &string); + g_return_if_fail (MESSAGING_MENU_IS_APP (app)); + g_return_if_fail (id != NULL); + g_return_if_fail (label != NULL); - new_state = g_variant_new ("(uxsb)", count, time, string, TRUE); - g_simple_action_set_state (action, new_state); + if (messaging_menu_app_lookup_source (app, id)) + { + g_warning ("a source with id '%s' already exists", id); + return; + } - g_variant_unref (state); + source = g_slice_new0 (Source); + source->id = g_strdup (id); + source->label = g_strdup (label); + if (icon) + source->icon = g_object_ref (icon); + source->count = count; + source->time = time; + source->string = g_strdup (string); + app->sources = g_list_insert (app->sources, source, position); + + indicator_messages_application_emit_source_added (app->app_interface, + position, + source_to_variant (source)); } /** @@ -797,8 +832,7 @@ messaging_menu_app_insert_source_with_count (MessagingMenuApp *app, const gchar *label, guint count) { - messaging_menu_app_insert_source_action (app, position, id, icon, label, - g_variant_new ("(uxsb)", count, 0, "", FALSE)); + messaging_menu_app_insert_source_internal (app, position, id, icon, label, count, 0, ""); } /** @@ -852,8 +886,7 @@ messaging_menu_app_insert_source_with_time (MessagingMenuApp *app, const gchar *label, gint64 time) { - messaging_menu_app_insert_source_action (app, position, id, icon, label, - g_variant_new ("(uxsb)", 0, time, "", FALSE)); + messaging_menu_app_insert_source_internal (app, position, id, icon, label, 0, time, ""); } /** @@ -909,8 +942,7 @@ messaging_menu_app_insert_source_with_string (MessagingMenuApp *app, const gchar *label, const gchar *str) { - messaging_menu_app_insert_source_action (app, position, id, icon, label, - g_variant_new ("(uxsb)", 0, 0, str, FALSE)); + messaging_menu_app_insert_source_internal (app, position, id, icon, label, 0, 0, str); } /** @@ -950,34 +982,11 @@ void messaging_menu_app_remove_source (MessagingMenuApp *app, const gchar *source_id) { - int n_items; - int i; - g_return_if_fail (MESSAGING_MENU_IS_APP (app)); g_return_if_fail (source_id != NULL); - if (g_simple_action_group_lookup (app->source_actions, source_id) == NULL) - return; - - n_items = g_menu_model_get_n_items (G_MENU_MODEL (app->menu)); - for (i = 0; i < n_items; i++) - { - gchar *action; - - if (g_menu_model_get_item_attribute (G_MENU_MODEL (app->menu), i, - "action", "s", &action)) - { - if (!g_strcmp0 (action, source_id)) - { - g_menu_remove (app->menu, i); - break; - } - - g_free (action); - } - } - - g_simple_action_group_remove (app->source_actions, source_id); + if (messaging_menu_app_remove_source_internal (app, source_id)) + indicator_messages_application_emit_source_removed (app->app_interface, source_id); } /** @@ -994,46 +1003,7 @@ messaging_menu_app_has_source (MessagingMenuApp *app, g_return_val_if_fail (MESSAGING_MENU_IS_APP (app), FALSE); g_return_val_if_fail (source_id != NULL, FALSE); - return g_simple_action_group_lookup (app->source_actions, source_id) != NULL; -} - -static GMenuItem * -g_menu_find_item_with_action (GMenu *menu, - const gchar *action, - gint *out_pos) -{ - gint i; - gint n_elements; - GMenuItem *item = NULL; - - n_elements = g_menu_model_get_n_items (G_MENU_MODEL (menu)); - - for (i = 0; i < n_elements && item == NULL; i++) - { - GVariant *attr; - - item = g_menu_item_new_from_model (G_MENU_MODEL (menu), i); - attr = g_menu_item_get_attribute_value (item, G_MENU_ATTRIBUTE_ACTION, G_VARIANT_TYPE_STRING); - - if (!g_str_equal (action, g_variant_get_string (attr, NULL))) - g_clear_object (&item); - - g_variant_unref (attr); - } - - if (item && out_pos) - *out_pos = i - 1; - - return item; -} - -static void -g_menu_replace_item (GMenu *menu, - gint pos, - GMenuItem *item) -{ - g_menu_remove (menu, pos); - g_menu_insert_item (menu, pos, item); + return messaging_menu_app_lookup_source (app, source_id) != NULL; } /** @@ -1049,21 +1019,19 @@ messaging_menu_app_set_source_label (MessagingMenuApp *app, const gchar *source_id, const gchar *label) { - gint pos; - GMenuItem *item; + Source *source; g_return_if_fail (MESSAGING_MENU_IS_APP (app)); g_return_if_fail (source_id != NULL); g_return_if_fail (label != NULL); - item = g_menu_find_item_with_action (app->menu, source_id, &pos); - if (item == NULL) - return; - - g_menu_item_set_attribute (item, G_MENU_ATTRIBUTE_LABEL, "s", label); - g_menu_replace_item (app->menu, pos, item); - - g_object_unref (item); + source = messaging_menu_app_get_source (app, source_id); + if (source) + { + g_free (source->label); + source->label = g_strdup (label); + messaging_menu_app_notify_source_changed (app, source); + } } /** @@ -1079,33 +1047,19 @@ messaging_menu_app_set_source_icon (MessagingMenuApp *app, const gchar *source_id, GIcon *icon) { - gint pos; - GMenuItem *item; + Source *source; g_return_if_fail (MESSAGING_MENU_IS_APP (app)); g_return_if_fail (source_id != NULL); - item = g_menu_find_item_with_action (app->menu, source_id, &pos); - if (item == NULL) - return; - - if (icon) + source = messaging_menu_app_get_source (app, source_id); + if (source) { - gchar *iconstr; - - iconstr = g_icon_to_string (icon); - g_menu_item_set_attribute (item, "x-canonical-icon", "s", iconstr); - - g_free (iconstr); - } - else - { - g_menu_item_set_attribute_value (item, "x-canonical-icon", NULL); + g_clear_object (&source->icon); + if (icon) + source->icon = g_object_ref (icon); + messaging_menu_app_notify_source_changed (app, source); } - - g_menu_replace_item (app->menu, pos, item); - - g_object_unref (item); } /** @@ -1120,7 +1074,17 @@ void messaging_menu_app_set_source_count (MessagingMenuApp *app, const gchar *source_id, guint count) { - messaging_menu_app_set_source_action (app, source_id, count, 0, ""); + Source *source; + + g_return_if_fail (MESSAGING_MENU_IS_APP (app)); + g_return_if_fail (source_id != NULL); + + source = messaging_menu_app_get_source (app, source_id); + if (source) + { + source->count = count; + messaging_menu_app_notify_source_changed (app, source); + } } /** @@ -1136,7 +1100,17 @@ messaging_menu_app_set_source_time (MessagingMenuApp *app, const gchar *source_id, gint64 time) { - messaging_menu_app_set_source_action (app, source_id, 0, time, ""); + Source *source; + + g_return_if_fail (MESSAGING_MENU_IS_APP (app)); + g_return_if_fail (source_id != NULL); + + source = messaging_menu_app_get_source (app, source_id); + if (source) + { + source->time = time; + messaging_menu_app_notify_source_changed (app, source); + } } /** @@ -1152,7 +1126,18 @@ messaging_menu_app_set_source_string (MessagingMenuApp *app, const gchar *source_id, const gchar *str) { - messaging_menu_app_set_source_action (app, source_id, 0, 0, str); + Source *source; + + g_return_if_fail (MESSAGING_MENU_IS_APP (app)); + g_return_if_fail (source_id != NULL); + + source = messaging_menu_app_get_source (app, source_id); + if (source) + { + g_free (source->string); + source->string = g_strdup (str); + messaging_menu_app_notify_source_changed (app, source); + } } /** @@ -1170,7 +1155,17 @@ void messaging_menu_app_draw_attention (MessagingMenuApp *app, const gchar *source_id) { - messaging_menu_app_set_draws_attention (app, source_id, TRUE); + Source *source; + + g_return_if_fail (MESSAGING_MENU_IS_APP (app)); + g_return_if_fail (source_id != NULL); + + source = messaging_menu_app_get_source (app, source_id); + if (source) + { + source->draws_attention = TRUE; + messaging_menu_app_notify_source_changed (app, source); + } } /** @@ -1191,7 +1186,17 @@ void messaging_menu_app_remove_attention (MessagingMenuApp *app, const gchar *source_id) { - messaging_menu_app_set_draws_attention (app, source_id, TRUE); + Source *source; + + g_return_if_fail (MESSAGING_MENU_IS_APP (app)); + g_return_if_fail (source_id != NULL); + + source = messaging_menu_app_get_source (app, source_id); + if (source) + { + source->draws_attention = FALSE; + messaging_menu_app_notify_source_changed (app, source); + } } /** diff --git a/src/app-section.c b/src/app-section.c index 6aac52a..19532f2 100644 --- a/src/app-section.c +++ b/src/app-section.c @@ -33,6 +33,7 @@ with this program. If not, see . #include "dbus-data.h" #include "gmenuutils.h" #include "gactionmuxer.h" +#include "indicator-messages-application.h" struct _AppSectionPrivate { @@ -41,11 +42,14 @@ struct _AppSectionPrivate IndicatorDesktopShortcuts * ids; + GCancellable *app_proxy_cancellable; + IndicatorMessagesApplication *app_proxy; + GMenu *menu; - GMenuModel *source_menu; + GMenu *source_menu; GSimpleActionGroup *static_shortcuts; - GActionGroup *source_actions; + GSimpleActionGroup *source_actions; GActionMuxer *muxer; gboolean draws_attention; @@ -89,19 +93,6 @@ static void launch_action_change_state (GSimpleAction *action, gpointer user_data); static void app_section_set_app_info (AppSection *self, GDesktopAppInfo *appinfo); -static gboolean any_action_draws_attention (GActionGroup *group, - const gchar *ignored_action); -static void action_added (GActionGroup *group, - const gchar *action_name, - gpointer user_data); -static void action_state_changed (GActionGroup *group, - const gchar *action_name, - GVariant *value, - gpointer user_data); -static void action_removed (GActionGroup *group, - const gchar *action_name, - gpointer user_data); -static gboolean action_draws_attention (GVariant *state); static void desktop_file_changed_cb (GFileMonitor *monitor, GFile *file, GFile *other_file, @@ -169,6 +160,7 @@ static void app_section_init (AppSection *self) { AppSectionPrivate *priv; + GMenuItem *item; self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, APP_SECTION_TYPE, @@ -178,10 +170,19 @@ app_section_init (AppSection *self) priv->appinfo = NULL; priv->menu = g_menu_new (); + + priv->source_menu = g_menu_new (); + item = g_menu_item_new_section (NULL, G_MENU_MODEL (priv->source_menu)); + g_menu_item_set_attribute (item, "action-namespace", "s", "source"); + g_menu_append_item (priv->menu, item); + g_object_unref (item); + priv->static_shortcuts = g_simple_action_group_new (); + priv->source_actions = g_simple_action_group_new (); priv->muxer = g_action_muxer_new (); g_action_muxer_insert (priv->muxer, NULL, G_ACTION_GROUP (priv->static_shortcuts)); + g_action_muxer_insert (priv->muxer, "source", G_ACTION_GROUP (priv->source_actions)); priv->draws_attention = FALSE; @@ -248,32 +249,30 @@ app_section_dispose (GObject *object) AppSection * self = APP_SECTION(object); AppSectionPrivate * priv = self->priv; + if (priv->app_proxy_cancellable) { + g_cancellable_cancel (priv->app_proxy_cancellable); + g_clear_object (&priv->app_proxy_cancellable); + } + if (priv->desktop_file_monitor) { g_signal_handlers_disconnect_by_func (priv->desktop_file_monitor, desktop_file_changed_cb, self); g_clear_object (&priv->desktop_file_monitor); } + g_clear_object (&priv->app_proxy); + g_clear_object (&priv->menu); + g_clear_object (&priv->source_menu); g_clear_object (&priv->static_shortcuts); + g_clear_object (&priv->source_actions); if (priv->name_watch_id) { g_bus_unwatch_name (priv->name_watch_id); priv->name_watch_id = 0; } - if (priv->source_actions) { - g_action_muxer_remove (priv->muxer, "source"); - g_object_disconnect (priv->source_actions, - "any_signal::action-added", action_added, self, - "any_signal::action-state-changed", action_state_changed, self, - "any_signal::action-removed", action_removed, self, - NULL); - g_clear_object (&priv->source_actions); - } - g_clear_object (&priv->muxer); - g_clear_object (&priv->source_menu); g_clear_object (&priv->ids); g_clear_object (&priv->appinfo); @@ -429,6 +428,11 @@ app_section_update_menu (AppSection *self) g_free(name); } + item = g_menu_item_new_section (NULL, G_MENU_MODEL (priv->source_menu)); + g_menu_item_set_attribute (item, "action-namespace", "s", "source"); + g_menu_append_item (priv->menu, item); + g_object_unref (item); + keyfile = g_file_new_for_path (g_desktop_app_info_get_filename (priv->appinfo)); g_file_load_contents_async (keyfile, NULL, keyfile_loaded, self); @@ -564,49 +568,242 @@ app_section_get_draws_attention (AppSection *self) void app_section_clear_draws_attention (AppSection *self) { - AppSectionPrivate * priv = self->priv; - gchar **action_names; + self->priv->draws_attention = FALSE; + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DRAWS_ATTENTION]); +} + +static void +application_vanished (GDBusConnection *bus, + const gchar *name, + gpointer user_data) +{ + AppSection *self = user_data; + + app_section_unset_object_path (self); +} + +static void +update_draws_attention (AppSection *self) +{ + AppSectionPrivate *priv = self->priv; + gchar **actions; gchar **it; + gboolean draws_attention = FALSE; + + actions = g_action_group_list_actions (G_ACTION_GROUP (priv->source_actions)); + + for (it = actions; *it; it++) { + GVariant *state; + + state = g_action_group_get_action_state (G_ACTION_GROUP (priv->source_actions), *it); + if (state) { + gboolean b; + g_variant_get (state, "(uxsb)", NULL, NULL, NULL, &b); + draws_attention = b || draws_attention; + g_variant_unref (state); + } + + if (draws_attention) + break; + } + + if (draws_attention != priv->draws_attention) { + priv->draws_attention = draws_attention; + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DRAWS_ATTENTION]); + } + + g_strfreev (actions); +} + +static void +remove_source (AppSection *self, + const gchar *id) +{ + AppSectionPrivate *priv = self->priv; + guint n_items; + guint i; + + n_items = g_menu_model_get_n_items (G_MENU_MODEL (priv->source_menu)); + for (i = 0; i < n_items; i++) { + gchar *action; + gboolean found = FALSE; + + if (g_menu_model_get_item_attribute (G_MENU_MODEL (priv->source_menu), i, + G_MENU_ATTRIBUTE_ACTION, "s", &action)) { + found = g_str_equal (action, id); + g_free (action); + } + + if (found) { + g_menu_remove (priv->source_menu, i); + break; + } + } + + g_simple_action_group_remove (priv->source_actions, id); + update_draws_attention (self); +} + +static void +source_action_activated (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + AppSection *self = APP_SECTION (user_data); + AppSectionPrivate *priv = APP_SECTION (user_data)->priv; + + g_return_if_fail (priv->app_proxy != NULL); + + indicator_messages_application_call_activate_source (priv->app_proxy, + g_action_get_name (G_ACTION (action)), + priv->app_proxy_cancellable, + NULL, NULL); + + remove_source (self, g_action_get_name (G_ACTION (action))); +} + +static void +sources_listed (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + AppSection *self = user_data; + AppSectionPrivate *priv = self->priv; + GVariant *sources = NULL; + GError *error = NULL; + GVariantIter iter; + const gchar *id; + const gchar *label; + const gchar *iconstr; + guint32 count; + gint64 time; + const gchar *string; + gboolean draws_attention; - if (priv->source_actions == NULL) + if (!indicator_messages_application_call_list_sources_finish (INDICATOR_MESSAGES_APPLICATION (source_object), + &sources, result, &error)) + { + g_warning ("could not fetch the list of sources: %s", error->message); + g_error_free (error); return; + } - action_names = g_action_group_list_actions (priv->source_actions); + g_menu_clear (priv->source_menu); + g_simple_action_group_clear (priv->source_actions); + priv->draws_attention = FALSE; - for (it = action_names; *it; it++) { + g_variant_iter_init (&iter, sources); + while (g_variant_iter_next (&iter, "(&s&s&sux&sb)", &id, &label, &iconstr, + &count, &time, &string, &draws_attention)) + { GVariant *state; + GSimpleAction *action; + GMenuItem *item; - state = g_action_group_get_action_state (priv->source_actions, *it); - if (!state) - continue; + state = g_variant_new ("(uxsb)", count, time, string, draws_attention); + action = g_simple_action_new_stateful (id, NULL, state); + g_signal_connect (action, "activate", G_CALLBACK (source_action_activated), self); + g_simple_action_group_insert (priv->source_actions, G_ACTION (action)); - /* clear draws-attention while preserving other state */ - if (action_draws_attention (state)) { - guint32 count; - gint64 time; - const gchar *str; - GVariant *new_state; + item = g_menu_item_new (label, id); + g_menu_item_set_attribute (item, "x-canonical-type", "s", "ImSourceMenuItem"); + g_menu_append_item (priv->source_menu, item); - g_variant_get (state, "(ux&sb)", &count, &time, &str, NULL); + priv->draws_attention = priv->draws_attention || draws_attention; - new_state = g_variant_new ("(uxsb)", count, time, str, FALSE); - g_action_group_change_action_state (priv->source_actions, *it, new_state); - } + g_object_unref (item); + g_object_unref (action); + } + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DRAWS_ATTENTION]); + + g_variant_unref (sources); +} + +static void +source_added (IndicatorMessagesApplication *app, + const gchar *id, + const gchar *label, + const gchar *iconstr, + guint count, + gint64 time, + const gchar *string, + gboolean draws_attention, + gpointer user_data) +{ + AppSection *self = user_data; + AppSectionPrivate *priv = self->priv; + GVariant *state; + GSimpleAction *action; + + /* TODO put label and icon into the action as well */ - g_variant_unref (state); + state = g_variant_new ("(uxsb)", count, time, string, draws_attention); + action = g_simple_action_new_stateful (id, NULL, state); + + g_simple_action_group_insert (priv->source_actions, G_ACTION (action)); + + if (draws_attention && !priv->draws_attention) { + priv->draws_attention = TRUE; + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DRAWS_ATTENTION]); } - g_strfreev (action_names); + g_object_unref (action); +} +static void +source_changed (IndicatorMessagesApplication *app, + const gchar *id, + const gchar *label, + const gchar *iconstr, + guint count, + gint64 time, + const gchar *string, + gboolean draws_attention, + gpointer user_data) +{ + AppSection *self = user_data; + AppSectionPrivate *priv = self->priv; + GVariant *state; + + /* TODO put label and icon into the action as well */ + + state = g_variant_new ("(uxsb)", count, time, string, draws_attention); + g_action_group_change_action_state (G_ACTION_GROUP (priv->source_actions), id, state); + + update_draws_attention (self); } static void -application_vanished (GDBusConnection *bus, - const gchar *name, - gpointer user_data) +source_removed (IndicatorMessagesApplication *app, + const gchar *id, + gpointer user_data) { AppSection *self = user_data; - app_section_unset_object_path (self); + remove_source (self, id); +} + +static void +app_proxy_created (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + AppSectionPrivate *priv = APP_SECTION (user_data)->priv; + GError *error = NULL; + + priv->app_proxy = indicator_messages_application_proxy_new_finish (result, &error); + if (!priv->app_proxy) { + g_warning ("could not create application proxy: %s", error->message); + g_error_free (error); + return; + } + + indicator_messages_application_call_list_sources (priv->app_proxy, priv->app_proxy_cancellable, + sources_listed, user_data); + + g_signal_connect (priv->app_proxy, "source-added", G_CALLBACK (source_added), user_data); + g_signal_connect (priv->app_proxy, "source-changed", G_CALLBACK (source_changed), user_data); + g_signal_connect (priv->app_proxy, "source-removed", G_CALLBACK (source_removed), user_data); } /* @@ -627,27 +824,20 @@ app_section_set_object_path (AppSection *self, const gchar *object_path) { AppSectionPrivate *priv = self->priv; - GMenuItem *item; g_object_freeze_notify (G_OBJECT (self)); app_section_unset_object_path (self); - priv->source_actions = G_ACTION_GROUP (g_dbus_action_group_get (bus, bus_name, object_path)); - g_action_muxer_insert (priv->muxer, "source", priv->source_actions); - - priv->draws_attention = any_action_draws_attention (priv->source_actions, NULL); - g_object_connect (priv->source_actions, - "signal::action-added", action_added, self, - "signal::action-state-changed", action_state_changed, self, - "signal::action-removed", action_removed, self, - NULL); + priv->app_proxy_cancellable = g_cancellable_new (); + indicator_messages_application_proxy_new (bus, + G_DBUS_PROXY_FLAGS_NONE, + bus_name, + object_path, + priv->app_proxy_cancellable, + app_proxy_created, + self); - priv->source_menu = G_MENU_MODEL (g_dbus_menu_model_get (bus, bus_name, object_path)); - - item = g_menu_item_new_section (NULL, priv->source_menu); - g_menu_item_set_attribute (item, "action-namespace", "s", "source"); - g_menu_append_item (priv->menu, item); - g_object_unref (item); + priv->draws_attention = FALSE; priv->name_watch_id = g_bus_watch_name_on_connection (bus, bus_name, 0, NULL, application_vanished, @@ -675,26 +865,19 @@ app_section_unset_object_path (AppSection *self) { AppSectionPrivate *priv = self->priv; + if (priv->app_proxy_cancellable) { + g_cancellable_cancel (priv->app_proxy_cancellable); + g_clear_object (&priv->app_proxy_cancellable); + } + g_clear_object (&priv->app_proxy); + if (priv->name_watch_id) { g_bus_unwatch_name (priv->name_watch_id); priv->name_watch_id = 0; } - if (priv->source_actions) { - g_object_disconnect (priv->source_actions, - "any_signal::action-added", action_added, self, - "any_signal::action-state-changed", action_state_changed, self, - "any_signal::action-removed", action_removed, self, - NULL); - g_clear_object (&priv->source_actions); - } - - if (priv->source_menu) { - /* the last menu item points is linked to the app's menumodel */ - gint n_items = g_menu_model_get_n_items (G_MENU_MODEL (priv->menu)); - g_menu_remove (priv->menu, n_items -1); - g_clear_object (&priv->source_menu); - } + g_simple_action_group_clear (priv->source_actions); + g_menu_clear (priv->source_menu); priv->draws_attention = FALSE; g_clear_pointer (&priv->chat_status, g_free); @@ -708,85 +891,6 @@ app_section_unset_object_path (AppSection *self) "launch", g_variant_new_boolean (FALSE)); } -static gboolean -action_draws_attention (GVariant *state) -{ - gboolean attention; - - if (state && g_variant_is_of_type (state, G_VARIANT_TYPE ("(uxsb)"))) - g_variant_get_child (state, 3, "b", &attention); - else - attention = FALSE; - - return attention; -} - -static gboolean -any_action_draws_attention (GActionGroup *group, - const gchar *ignored_action) -{ - gchar **actions; - gchar **it; - gboolean attention = FALSE; - - actions = g_action_group_list_actions (group); - - for (it = actions; *it && !attention; it++) { - GVariant *state; - - if (ignored_action && g_str_equal (ignored_action, *it)) - continue; - - state = g_action_group_get_action_state (group, *it); - if (state) { - attention = action_draws_attention (state); - g_variant_unref (state); - } - } - - g_strfreev (actions); - return attention; -} - -static void -action_added (GActionGroup *group, - const gchar *action_name, - gpointer user_data) -{ - AppSection *self = user_data; - GVariant *state; - - state = g_action_group_get_action_state (group, action_name); - if (state) { - self->priv->draws_attention |= action_draws_attention (state); - g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DRAWS_ATTENTION]); - g_variant_unref (state); - } -} - -static void -action_state_changed (GActionGroup *group, - const gchar *action_name, - GVariant *value, - gpointer user_data) -{ - AppSection *self = user_data; - - self->priv->draws_attention = any_action_draws_attention (group, NULL); - g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DRAWS_ATTENTION]); -} - -static void -action_removed (GActionGroup *group, - const gchar *action_name, - gpointer user_data) -{ - AppSection *self = user_data; - - self->priv->draws_attention = any_action_draws_attention (group, action_name); - g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DRAWS_ATTENTION]); -} - gboolean app_section_get_uses_chat_status (AppSection *self) { diff --git a/test/Makefile.am b/test/Makefile.am index ee7cb3e..8c8c160 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -53,6 +53,7 @@ libindicator_messages_service_la_CFLAGS = \ $(APPLET_CFLAGS) \ $(COVERAGE_CFLAGS) \ -I$(top_builddir)/src \ + -I$(top_builddir)/common \ -Wall \ -Wl,-Bsymbolic-functions \ -Wl,-z,defs \ -- cgit v1.2.3 From b55e637321b0c3fdcb5e8aafab9614f80a3228d3 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 16 Nov 2012 14:41:50 +0100 Subject: Export menu for the phone client This is a rough first draft: It only fetched the sources and messages from applications once and doesn't listen for further changes. This removes all code for the desktop menu for now. --- ...om.canonical.indicator.messages.application.xml | 2 +- src/dbus-data.h | 2 +- src/gactionmuxer.c | 8 + src/gactionmuxer.h | 3 + src/messages-service.c | 551 ++++++--------------- 5 files changed, 170 insertions(+), 396 deletions(-) (limited to 'src') diff --git a/common/com.canonical.indicator.messages.application.xml b/common/com.canonical.indicator.messages.application.xml index 33aed7c..fb9f079 100644 --- a/common/com.canonical.indicator.messages.application.xml +++ b/common/com.canonical.indicator.messages.application.xml @@ -27,7 +27,7 @@ - + diff --git a/src/dbus-data.h b/src/dbus-data.h index 64747a9..ceeb546 100644 --- a/src/dbus-data.h +++ b/src/dbus-data.h @@ -3,7 +3,7 @@ #define __DBUS_DATA_H__ 1 #define INDICATOR_MESSAGES_DBUS_NAME "com.canonical.indicator.messages" -#define INDICATOR_MESSAGES_DBUS_OBJECT "/com/canonical/indicator/messages/menu" +#define INDICATOR_MESSAGES_DBUS_OBJECT "/com/canonical/indicator/messages" #define INDICATOR_MESSAGES_DBUS_SERVICE_OBJECT "/com/canonical/indicator/messages/service" #define INDICATOR_MESSAGES_DBUS_SERVICE_INTERFACE "com.canonical.indicator.messages.service" diff --git a/src/gactionmuxer.c b/src/gactionmuxer.c index 2b1d11a..0f3cda4 100644 --- a/src/gactionmuxer.c +++ b/src/gactionmuxer.c @@ -483,3 +483,11 @@ g_action_muxer_remove (GActionMuxer *muxer, g_clear_object (&muxer->global_actions); } +GActionGroup * +g_action_muxer_get_group (GActionMuxer *muxer, + const gchar *prefix) +{ + g_return_val_if_fail (G_IS_ACTION_MUXER (muxer), NULL); + + return prefix ? g_hash_table_lookup (muxer->groups, prefix) : muxer->global_actions; +} diff --git a/src/gactionmuxer.h b/src/gactionmuxer.h index 5c5e839..caf9ec7 100644 --- a/src/gactionmuxer.h +++ b/src/gactionmuxer.h @@ -40,5 +40,8 @@ void g_action_muxer_insert (GActionMuxer *muxer, void g_action_muxer_remove (GActionMuxer *muxer, const gchar *prefix); +GActionGroup * g_action_muxer_get_group (GActionMuxer *muxer, + const gchar *prefix); + #endif diff --git a/src/messages-service.c b/src/messages-service.c index b36a0a2..9d64412 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -28,12 +28,12 @@ with this program. If not, see . #include #include -#include "app-section.h" #include "dbus-data.h" #include "gactionmuxer.h" #include "gsettingsstrv.h" #include "gmenuutils.h" #include "indicator-messages-service.h" +#include "indicator-messages-application.h" #define NUM_STATUSES 5 @@ -44,7 +44,8 @@ static GSimpleActionGroup *actions; static GActionMuxer *action_muxer; static GMenu *toplevel_menu; static GMenu *menu; -static GMenuModel *chat_section; +static GMenu *messages_section; +static GMenu *sources_section; static GSettings *settings; static gboolean draws_attention; static const gchar *global_status[6]; /* max 5: available, away, busy, invisible, offline */ @@ -82,358 +83,173 @@ indicator_messages_get_icon_name () return iconstr; } -static void -indicator_messages_update_icon () -{ - GSimpleAction *messages; - gchar *icon; - - messages = G_SIMPLE_ACTION (g_simple_action_group_lookup (actions, "messages")); - g_return_if_fail (messages != NULL); - - icon = indicator_messages_get_icon_name (); - g_simple_action_set_state (messages, g_variant_new_string (icon)); - - g_free (icon); -} - -static gchar * -g_app_info_get_simple_id (GAppInfo *appinfo) -{ - const gchar *id; - - id = g_app_info_get_id (appinfo); - if (!id) - return NULL; - - if (g_str_has_suffix (id, ".desktop")) - return g_strndup (id, strlen (id) - 8); - else - return g_strdup (id); -} - -static void -actions_changed (GObject *object, - GParamSpec *pspec, - gpointer user_data) +static void +service_shutdown (IndicatorService * service, gpointer user_data) { - AppSection *section = APP_SECTION (object); - gchar *id; - GActionGroup *actions; - - id = g_app_info_get_simple_id (app_section_get_app_info (section)); - actions = app_section_get_actions (section); - - g_action_muxer_insert (action_muxer, id, actions); - g_free (id); -} - + GMainLoop *mainloop = user_data; -static gboolean -app_section_draws_attention (gpointer key, - gpointer value, - gpointer user_data) -{ - AppSection *section = value; - return app_section_get_draws_attention (section); + g_warning("Shutting down service!"); + g_main_loop_quit(mainloop); } static void -draws_attention_changed (GObject *object, - GParamSpec *pspec, - gpointer user_data) -{ - GSimpleAction *clear; - - clear = G_SIMPLE_ACTION (g_simple_action_group_lookup (actions, "clear")); - g_return_if_fail (clear != NULL); - - draws_attention = g_hash_table_find (applications, app_section_draws_attention, NULL) != NULL; - - g_simple_action_set_enabled (clear, draws_attention); - - indicator_messages_update_icon (); -} - -static gboolean -app_section_uses_chat (gpointer key, - gpointer value, +clear_action_activate (GSimpleAction *simple, + GVariant *param, gpointer user_data) { - AppSection *section = value; - return app_section_get_uses_chat_status (section); + /* TODO */ } static void -update_chat_section () +status_action_activate (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { - gboolean show_chat; - GMenuModel *first_section; - - show_chat = g_hash_table_find (applications, app_section_uses_chat, NULL) != NULL; - - first_section = g_menu_model_get_item_link (G_MENU_MODEL (menu), 0, G_MENU_LINK_SECTION); - if (first_section == chat_section) { - if (!show_chat) - g_menu_remove (menu, 0); - } - else { - if (show_chat) - g_menu_insert_section (menu, 0, NULL, chat_section); - } + const gchar *status; - if (first_section != NULL) - g_object_unref (first_section); + status = g_variant_get_string (parameter, NULL); - indicator_messages_update_icon (); + indicator_messages_service_emit_status_changed (messages_service, status); } static void -uses_chat_status_changed (GObject *object, - GParamSpec *pspec, - gpointer user_data) +sources_listed (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { - update_chat_section (); -} - -static gboolean -strv_contains (const gchar **strv, - const gchar *needle) -{ - const gchar **it; - - it = strv; - while (*it != NULL && !g_str_equal (*it, needle)) - it++; - - return *it != NULL; -} + gchar *app_id = user_data; + GVariant *sources; + GVariantIter iter; + const gchar *id; + const gchar *label; + const gchar *iconstr; + guint32 count; + gint64 time; + const gchar *string; + gboolean draws_attention; + GError *error = NULL; -static void -update_chat_status () -{ - GHashTableIter iter; - AppSection *section; - int pos; - GAction *status; - - for (pos = 0; pos < G_N_ELEMENTS (global_status); pos++) - global_status[pos] = NULL; - - pos = 0; - g_hash_table_iter_init (&iter, applications); - while (g_hash_table_iter_next (&iter, NULL, (gpointer) §ion) && - pos < G_N_ELEMENTS (global_status)) + if (!indicator_messages_application_call_list_sources_finish (INDICATOR_MESSAGES_APPLICATION (source_object), + &sources, result, &error)) { - const gchar *status_str = NULL; - - status_str = app_section_get_status (section); - if (status_str != NULL && !strv_contains (global_status, status_str)) - global_status[pos++] = status_str; - } - - if (pos == 0) - global_status[0] = "offline"; - - status = g_simple_action_group_lookup (actions, "status"); - g_return_if_fail (status != NULL); - - g_simple_action_set_state (G_SIMPLE_ACTION (status), g_variant_new_strv (global_status, -1)); - - indicator_messages_update_icon (); -} - -static void -chat_status_changed (GObject *object, - GParamSpec *pspec, - gpointer user_data) -{ - update_chat_status (); -} - -static void -remove_section (AppSection *section, - const gchar *id) -{ - int pos = g_menu_find_section (menu, app_section_get_menu (section)); - if (pos >= 0) - g_menu_remove (menu, pos); - g_action_muxer_remove (action_muxer, id); - - g_signal_handlers_disconnect_by_func (section, actions_changed, NULL); - g_signal_handlers_disconnect_by_func (section, draws_attention_changed, NULL); - g_signal_handlers_disconnect_by_func (section, uses_chat_status_changed, NULL); - g_signal_handlers_disconnect_by_func (section, chat_status_changed, NULL); - g_signal_handlers_disconnect_by_func (section, remove_section, NULL); - - g_hash_table_remove (applications, id); - - if (g_hash_table_size (applications) == 0 && - g_menu_model_get_n_items (G_MENU_MODEL (toplevel_menu)) == 1) { - g_menu_remove (toplevel_menu, 0); - } - - update_chat_status (); - update_chat_section (); -} - -static AppSection * -add_application (const gchar *desktop_id) -{ - GDesktopAppInfo *appinfo; - gchar *id; - AppSection *section; - - appinfo = g_desktop_app_info_new (desktop_id); - if (!appinfo) { - g_warning ("could not add '%s', there's no desktop file with that id", desktop_id); - return NULL; - } - - id = g_app_info_get_simple_id (G_APP_INFO (appinfo)); - section = g_hash_table_lookup (applications, id); - - if (!section) { - GMenuItem *menuitem; - - section = app_section_new(appinfo); - g_hash_table_insert (applications, g_strdup (id), section); - - g_action_muxer_insert (action_muxer, id, app_section_get_actions (section)); - g_signal_connect (section, "notify::actions", - G_CALLBACK (actions_changed), NULL); - g_signal_connect (section, "notify::draws-attention", - G_CALLBACK (draws_attention_changed), NULL); - g_signal_connect (section, "notify::uses-chat-status", - G_CALLBACK (uses_chat_status_changed), NULL); - g_signal_connect (section, "notify::chat-status", - G_CALLBACK (chat_status_changed), NULL); - g_signal_connect_data (section, "destroy", - G_CALLBACK (remove_section), - g_strdup (id), - (GClosureNotify) g_free, - 0); - - /* TODO insert it at the right position (alphabetically by application name) */ - menuitem = g_menu_item_new_section (NULL, app_section_get_menu (section)); - g_menu_item_set_attribute (menuitem, "action-namespace", "s", id); - g_menu_insert_item (menu, g_menu_model_get_n_items (G_MENU_MODEL (menu)) -1, menuitem); - g_object_unref (menuitem); + g_warning ("could not fetch the list of sources: %s", error->message); + g_error_free (error); + g_free (app_id); + return; } - if (g_menu_model_get_n_items (G_MENU_MODEL (toplevel_menu)) == 0) { - GMenuItem *header; - - header = g_menu_item_new (NULL, "messages"); - g_menu_item_set_submenu (header, G_MENU_MODEL (menu)); - g_menu_item_set_attribute (header, "x-canonical-accessible-description", "s", _("Messages")); - g_menu_append_item (toplevel_menu, header); - - g_object_unref (header); + g_variant_iter_init (&iter, sources); + while (g_variant_iter_next (&iter, "(&s&s&sux&sb)", &id, &label, &iconstr, &count, + &time, &string, &draws_attention)) + { + GMenuItem *item; + GActionGroup *app_actions; + GSimpleAction *action; + gchar *action_name; + + app_actions = g_action_muxer_get_group (action_muxer, app_id); + g_assert (app_actions); + action = g_simple_action_new_stateful (id, NULL, g_variant_new_uint32 (count)); + g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (app_actions), G_ACTION (action)); + + action_name = g_strconcat (app_id, ".", id, NULL); + item = g_menu_item_new (label, action_name); + g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.sourceitem"); + if (iconstr && *iconstr) + g_menu_item_set_attribute (item, "x-canonical-icon", "s", iconstr); + g_menu_append_item (sources_section, item); + + g_object_unref (action); + g_free (action_name); + g_object_unref (item); } - g_free (id); - g_object_unref (appinfo); - return section; + g_variant_unref (sources); + g_free (app_id); } static void -remove_application (const char *desktop_id) +messages_listed (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { - GDesktopAppInfo *appinfo; - gchar *id; - AppSection *section; - - appinfo = g_desktop_app_info_new (desktop_id); - if (!appinfo) { - g_warning ("could not remove '%s', there's no desktop file with that id", desktop_id); + gchar *app_id = user_data; + GVariant *messages; + GError *error = NULL; + GVariantIter iter; + const gchar *id; + const gchar *iconstr; + const gchar *title; + const gchar *subtitle; + const gchar *body; + gint64 time; + gboolean draws_attention; + + if (!indicator_messages_application_call_list_messages_finish (INDICATOR_MESSAGES_APPLICATION (source_object), + &messages, result, &error)) + { + g_warning ("could not fetch the list of messages: %s", error->message); + g_error_free (error); + g_free (app_id); return; } - id = g_app_info_get_simple_id (G_APP_INFO (appinfo)); - - section = g_hash_table_lookup (applications, id); - if (section) { - remove_section (section, id); - } - else { - g_warning ("could not remove '%s', it's not registered", desktop_id); - } - - g_free (id); - g_object_unref (appinfo); -} - -/* This function turns a specific desktop id into a menu - item and registers it appropriately with everyone */ -static gboolean -build_launcher (gpointer data) -{ - gchar *desktop_id = data; - - add_application (desktop_id); - - g_free (desktop_id); - return FALSE; -} - -/* This function goes through all the launchers that we're - supposed to be grabbing and decides to show turn them - into menu items or not. It doens't do the work, but it - makes the decision. */ -static gboolean -build_launchers (gpointer data) -{ - gchar **applications = g_settings_get_strv (settings, "applications"); - gchar **app; - - g_return_val_if_fail (applications != NULL, FALSE); - - for (app = applications; *app; app++) + g_variant_iter_init (&iter, messages); + while (g_variant_iter_next (&iter, "(&s&s&s&s&sxb)", &id, &iconstr, &title, &subtitle, &body, + &time, &draws_attention)) { - g_idle_add(build_launcher, g_strdup (*app)); + GMenuItem *item; + GActionGroup *app_actions; + GSimpleAction *action; + gchar *action_name; + + app_actions = g_action_muxer_get_group (action_muxer, app_id); + g_assert (app_actions); + action = g_simple_action_new (id, NULL); + g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (app_actions), G_ACTION (action)); + + action_name = g_strconcat (app_id, ".", id, NULL); + item = g_menu_item_new (NULL, action_name); + g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.messageitem"); + g_menu_item_set_attribute (item, "x-canonical-message-id", "s", id); + g_menu_item_set_attribute (item, "x-canonical-sender", "s", title); + g_menu_item_set_attribute (item, "x-canonical-subject", "s", subtitle); + g_menu_item_set_attribute (item, "x-canonical-body", "s", body); + g_menu_item_set_attribute (item, "x-canonical-time", "x", time); + if (iconstr && *iconstr) + g_menu_item_set_attribute (item, "x-canonical-avatar", "s", iconstr); + g_menu_append_item (messages_section, item); + + g_object_unref (action); + g_free (action_name); + g_object_unref (item); } - g_strfreev (applications); - return FALSE; -} - -static void -service_shutdown (IndicatorService * service, gpointer user_data) -{ - GMainLoop *mainloop = user_data; - - g_warning("Shutting down service!"); - g_main_loop_quit(mainloop); + g_variant_unref (messages); + g_free (app_id); } static void -app_section_remove_attention (gpointer key, - gpointer value, - gpointer user_data) +app_proxy_created (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { - AppSection *section = value; - app_section_clear_draws_attention (section); -} - -static void -clear_action_activate (GSimpleAction *simple, - GVariant *param, - gpointer user_data) -{ - g_hash_table_foreach (applications, app_section_remove_attention, NULL); -} + gchar *desktop_id = user_data; + IndicatorMessagesApplication *app_proxy; + GError *error = NULL; -static void -status_action_activate (GSimpleAction *action, - GVariant *parameter, - gpointer user_data) -{ - const gchar *status; + app_proxy = indicator_messages_application_proxy_new_finish (result, &error); + if (!app_proxy) { + g_warning ("could not create application proxy: %s", error->message); + g_error_free (error); + return; + } - status = g_variant_get_string (parameter, NULL); + /* hash table takes ownership of desktop_id and app_proxy */ + g_hash_table_insert (applications, desktop_id, app_proxy); - indicator_messages_service_emit_status_changed (messages_service, status); + indicator_messages_application_call_list_sources (app_proxy, NULL, sources_listed, g_strdup (desktop_id)); + indicator_messages_application_call_list_messages (app_proxy, NULL, messages_listed, g_strdup (desktop_id)); } static void @@ -443,21 +259,33 @@ register_application (IndicatorMessagesService *service, const gchar *menu_path, gpointer user_data) { - AppSection *section; GDBusConnection *bus; const gchar *sender; + GSimpleActionGroup *app_actions; - section = add_application (desktop_id); - if (!section) + if (g_hash_table_lookup (applications, desktop_id)) { + g_warning ("application with id '%s' already exists", desktop_id); + g_dbus_method_invocation_return_dbus_error (invocation, + "com.canonical.indicator.messages.ApplicationAlreadyRegistered", + "another application is already registered with this id"); return; + } bus = g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (service)); sender = g_dbus_method_invocation_get_sender (invocation); - app_section_set_object_path (section, bus, sender, menu_path); + indicator_messages_application_proxy_new (bus, G_DBUS_PROXY_FLAGS_NONE, + sender, menu_path, NULL, + app_proxy_created, g_strdup (desktop_id)); + + app_actions = g_simple_action_group_new (); + g_action_muxer_insert (action_muxer, desktop_id, G_ACTION_GROUP (app_actions)); + g_settings_strv_append_unique (settings, "applications", desktop_id); indicator_messages_service_complete_register_application (service, invocation); + + g_object_unref (app_actions); } static void @@ -466,44 +294,15 @@ unregister_application (IndicatorMessagesService *service, const gchar *desktop_id, gpointer user_data) { - remove_application (desktop_id); - g_settings_strv_remove (settings, "applications", desktop_id); + if (g_hash_table_remove (applications, desktop_id)) { - indicator_messages_service_complete_unregister_application (service, invocation); -} + /* TODO remove menu items that refer to this application */ + g_action_muxer_remove (action_muxer, desktop_id); -static void -set_status (IndicatorMessagesService *service, - GDBusMethodInvocation *invocation, - const gchar *desktop_id, - const gchar *status_str, - gpointer user_data) -{ - GDesktopAppInfo *appinfo; - gchar *id; - AppSection *section; - - g_return_if_fail (g_str_equal (status_str, "available") || - g_str_equal (status_str, "away")|| - g_str_equal (status_str, "busy") || - g_str_equal (status_str, "invisible") || - g_str_equal (status_str, "offline")); - - appinfo = g_desktop_app_info_new (desktop_id); - if (!appinfo) { - g_warning ("could not set status for '%s', there's no desktop file with that id", desktop_id); - return; + g_settings_strv_remove (settings, "applications", desktop_id); } - id = g_app_info_get_simple_id (G_APP_INFO (appinfo)); - section = g_hash_table_lookup (applications, id); - if (section != NULL) - app_section_set_status (section, status_str); - - indicator_messages_service_complete_set_status (service, invocation); - - g_free (id); - g_object_unref (appinfo); + indicator_messages_service_complete_unregister_application (service, invocation); } static GSimpleActionGroup * @@ -539,40 +338,6 @@ create_action_group (void) return actions; } -static GMenuModel * -create_status_section (void) -{ - GMenu *menu; - GMenuItem *item; - struct status_item { - gchar *label; - gchar *action; - gchar *icon_name; - } status_items[] = { - { _("Available"), "status::available", "user-available" }, - { _("Away"), "status::away", "user-away" }, - { _("Busy"), "status::busy", "user-busy" }, - { _("Invisible"), "status::invisible", "user-invisible" }, - { _("Offline"), "status::offline", "user-offline" } - }; - int i; - - menu = g_menu_new (); - - item = g_menu_item_new (NULL, NULL); - g_menu_item_set_attribute (item, "x-canonical-type", "s", "IdoMenuItem"); - - for (i = 0; i < G_N_ELEMENTS (status_items); i++) { - g_menu_item_set_label (item, status_items[i].label); - g_menu_item_set_detailed_action (item, status_items[i].action); - g_menu_item_set_attribute (item, "x-canonical-icon", "s", status_items[i].icon_name); - g_menu_append_item (menu, item); - } - - g_object_unref (item); - return G_MENU_MODEL (menu); -} - static void got_bus (GObject *object, GAsyncResult * res, @@ -596,7 +361,7 @@ got_bus (GObject *object, return; } - g_dbus_connection_export_menu_model (bus, INDICATOR_MESSAGES_DBUS_OBJECT, + g_dbus_connection_export_menu_model (bus, INDICATOR_MESSAGES_DBUS_OBJECT "/phone", G_MENU_MODEL (toplevel_menu), &error); if (error) { g_warning ("unable to export menu on dbus: %s", error->message); @@ -651,26 +416,24 @@ main (int argc, char ** argv) G_CALLBACK (register_application), NULL); g_signal_connect (messages_service, "handle-unregister-application", G_CALLBACK (unregister_application), NULL); - g_signal_connect (messages_service, "handle-set-status", - G_CALLBACK (set_status), NULL); menu = g_menu_new (); - chat_section = create_status_section (); - g_menu_append (menu, _("Clear"), "clear"); + sources_section = g_menu_new (); + messages_section = g_menu_new (); + g_menu_append_section (menu, NULL, G_MENU_MODEL (sources_section)); + g_menu_append_section (menu, NULL, G_MENU_MODEL (messages_section)); toplevel_menu = g_menu_new (); + g_menu_append_submenu (toplevel_menu, NULL, G_MENU_MODEL (menu)); settings = g_settings_new ("com.canonical.indicator.messages"); applications = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); - g_idle_add(build_launchers, NULL); - g_main_loop_run(mainloop); /* Clean up */ g_object_unref (messages_service); - g_object_unref (chat_section); g_object_unref (settings); g_hash_table_unref (applications); return 0; -- cgit v1.2.3 From f371bb64a0c6d57d496def504327047ff63b11e2 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 16 Nov 2012 15:05:39 +0100 Subject: Use different menu attributes for the phone menu --- src/messages-service.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/messages-service.c b/src/messages-service.c index 9d64412..81b7f0b 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -209,15 +209,14 @@ messages_listed (GObject *source_object, g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (app_actions), G_ACTION (action)); action_name = g_strconcat (app_id, ".", id, NULL); - item = g_menu_item_new (NULL, action_name); + item = g_menu_item_new (title, action_name); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.messageitem"); g_menu_item_set_attribute (item, "x-canonical-message-id", "s", id); - g_menu_item_set_attribute (item, "x-canonical-sender", "s", title); - g_menu_item_set_attribute (item, "x-canonical-subject", "s", subtitle); - g_menu_item_set_attribute (item, "x-canonical-body", "s", body); + g_menu_item_set_attribute (item, "x-canonical-subtitle", "s", subtitle); + g_menu_item_set_attribute (item, "x-canonical-text", "s", body); g_menu_item_set_attribute (item, "x-canonical-time", "x", time); if (iconstr && *iconstr) - g_menu_item_set_attribute (item, "x-canonical-avatar", "s", iconstr); + g_menu_item_set_attribute (item, "x-canonical-icon", "s", iconstr); g_menu_append_item (messages_section, item); g_object_unref (action); @@ -362,7 +361,7 @@ got_bus (GObject *object, } g_dbus_connection_export_menu_model (bus, INDICATOR_MESSAGES_DBUS_OBJECT "/phone", - G_MENU_MODEL (toplevel_menu), &error); + G_MENU_MODEL (menu), &error); if (error) { g_warning ("unable to export menu on dbus: %s", error->message); g_error_free (error); -- cgit v1.2.3 From 6f990698f610eb444845f36a70cad04bca2415f3 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 20 Nov 2012 15:45:03 +0100 Subject: messages-serivce: move menu creation into separate class --- src/Makefile.am | 4 +- src/im-phone-menu.c | 216 +++++++++++++++++++++++++++++++++++++++++++++++++ src/im-phone-menu.h | 67 +++++++++++++++ src/messages-service.c | 81 ++++++++----------- 4 files changed, 319 insertions(+), 49 deletions(-) create mode 100644 src/im-phone-menu.c create mode 100644 src/im-phone-menu.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index a7bfe66..12c8031 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -52,7 +52,9 @@ indicator_messages_service_SOURCES = \ gsettingsstrv.c \ gsettingsstrv.h \ gmenuutils.c \ - gmenuutils.h + gmenuutils.h \ + im-phone-menu.c \ + im-phone-menu.h indicator_messages_service_CFLAGS = \ $(APPLET_CFLAGS) \ diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c new file mode 100644 index 0000000..abb3a11 --- /dev/null +++ b/src/im-phone-menu.c @@ -0,0 +1,216 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Lars Uebernickel + */ + +#include "im-phone-menu.h" + +#include + +typedef GObjectClass ImPhoneMenuClass; + +struct _ImPhoneMenu +{ + GObject parent; + + GMenu *toplevel_menu; + GMenu *message_section; + GMenu *source_section; + +}; + +G_DEFINE_TYPE (ImPhoneMenu, im_phone_menu, G_TYPE_OBJECT); + +typedef void (*ImMenuForeachFunc) (GMenuModel *menu, gint pos); + +static void +im_phone_menu_foreach_item_with_action (GMenuModel *menu, + const gchar *action, + ImMenuForeachFunc func) +{ + gint n_items; + gint i; + + n_items = g_menu_model_get_n_items (menu); + for (i = 0; i < n_items; i++) + { + gchar *item_action; + + g_menu_model_get_item_attribute (menu, i, G_MENU_ATTRIBUTE_ACTION, "s", &item_action); + + if (g_str_equal (action, item_action)) + func (menu, i); + + g_free (item_action); + } +} + +static void +im_phone_menu_dispose (GObject *object) +{ + ImPhoneMenu *menu = IM_PHONE_MENU (object); + + g_clear_object (&menu->toplevel_menu); + g_clear_object (&menu->message_section); + g_clear_object (&menu->source_section); + + G_OBJECT_CLASS (im_phone_menu_parent_class)->dispose (object); +} + +static void +im_phone_menu_finalize (GObject *object) +{ + G_OBJECT_CLASS (im_phone_menu_parent_class)->finalize (object); +} + +static void +im_phone_menu_class_init (ImPhoneMenuClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = im_phone_menu_dispose; + object_class->finalize = im_phone_menu_finalize; +} + +static void +im_phone_menu_init (ImPhoneMenu *menu) +{ + menu->message_section = g_menu_new (); + menu->source_section = g_menu_new (); + + menu->toplevel_menu = g_menu_new (); + g_menu_append_section (menu->toplevel_menu, NULL, G_MENU_MODEL (menu->message_section)); + g_menu_append_section (menu->toplevel_menu, NULL, G_MENU_MODEL (menu->source_section)); +} + +ImPhoneMenu * +im_phone_menu_new (void) +{ + return g_object_new (IM_TYPE_PHONE_MENU, NULL); +} + +GMenuModel * +im_phone_menu_get_model (ImPhoneMenu *menu) +{ + g_return_val_if_fail (IM_IS_PHONE_MENU (menu), NULL); + + return G_MENU_MODEL (menu->toplevel_menu); +} + +void +im_phone_menu_add_message (ImPhoneMenu *menu, + GDesktopAppInfo *app, + const gchar *id, + const gchar *iconstr, + const gchar *title, + const gchar *subtitle, + const gchar *body, + gint64 time) +{ + const gchar *app_id; + GMenuItem *item; + gchar *action_name; + + g_return_if_fail (IM_IS_PHONE_MENU (menu)); + g_return_if_fail (G_IS_DESKTOP_APP_INFO (app)); + + app_id = g_app_info_get_id (G_APP_INFO (app)); + g_return_if_fail (app_id); + + action_name = g_strconcat (app_id, ".", id, NULL); + + item = g_menu_item_new (title, action_name); + g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.messageitem"); + g_menu_item_set_attribute (item, "x-canonical-message-id", "s", id); + g_menu_item_set_attribute (item, "x-canonical-subtitle", "s", subtitle); + g_menu_item_set_attribute (item, "x-canonical-text", "s", body); + g_menu_item_set_attribute (item, "x-canonical-time", "x", time); + + if (iconstr) + g_menu_item_set_attribute (item, "x-canonical-icon", "s", iconstr); + + g_menu_append_item (menu->message_section, item); + + g_free (action_name); + g_object_unref (item); +} + +void +im_phone_menu_remove_message (ImPhoneMenu *menu, + GDesktopAppInfo *app, + const gchar *id) +{ + gchar *action_name; + + g_return_if_fail (IM_IS_PHONE_MENU (menu)); + g_return_if_fail (G_IS_DESKTOP_APP_INFO (app)); + + action_name = g_strconcat (g_app_info_get_id (G_APP_INFO (app)), ".", id, NULL); + im_phone_menu_foreach_item_with_action (G_MENU_MODEL (menu->message_section), + action_name, + (ImMenuForeachFunc) g_menu_remove); + + g_free (action_name); +} + +void +im_phone_menu_add_source (ImPhoneMenu *menu, + GDesktopAppInfo *app, + const gchar *id, + const gchar *label, + const gchar *iconstr, + guint32 count, + gint64 time, + const gchar *string) +{ + GMenuItem *item; + gchar *action_name; + + g_return_if_fail (IM_IS_PHONE_MENU (menu)); + g_return_if_fail (G_IS_DESKTOP_APP_INFO (app)); + + action_name = g_strconcat (g_app_info_get_id (G_APP_INFO (app)), ".", id, NULL); + + item = g_menu_item_new (label, action_name); + g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.sourceitem"); + + if (iconstr) + g_menu_item_set_attribute (item, "x-canonical-icon", "s", iconstr); + + g_menu_append_item (menu->source_section, item); + + g_free (action_name); + g_object_unref (item); +} + +void +im_phone_menu_remove_source (ImPhoneMenu *menu, + GDesktopAppInfo *app, + const gchar *id) +{ + gchar *action_name; + + g_return_if_fail (IM_IS_PHONE_MENU (menu)); + g_return_if_fail (G_IS_DESKTOP_APP_INFO (app)); + + action_name = g_strconcat (g_app_info_get_id (G_APP_INFO (app)), ".", id, NULL); + im_phone_menu_foreach_item_with_action (G_MENU_MODEL (menu->source_section), + action_name, + (ImMenuForeachFunc) g_menu_remove); + + g_free (action_name); +} diff --git a/src/im-phone-menu.h b/src/im-phone-menu.h new file mode 100644 index 0000000..f7cc645 --- /dev/null +++ b/src/im-phone-menu.h @@ -0,0 +1,67 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Lars Uebernickel + */ + +#ifndef __IM_PHONE_MENU_H__ +#define __IM_PHONE_MENU_H__ + +#include +#include + +#define IM_TYPE_PHONE_MENU (im_phone_menu_get_type ()) +#define IM_PHONE_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_TYPE_PHONE_MENU, ImPhoneMenu)) +#define IM_PHONE_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IM_TYPE_PHONE_MENU, ImPhoneMenuClass)) +#define IM_IS_PHONE_MENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IM_TYPE_PHONE_MENU)) +#define IM_IS_PHONE_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IM_TYPE_PHONE_MENU)) +#define IM_PHONE_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IM_TYPE_PHONE_MENU, ImPhoneMenuClass)) + +typedef struct _ImPhoneMenu ImPhoneMenu; + +GType im_phone_menu_get_type (void); + +ImPhoneMenu * im_phone_menu_new (void); + +GMenuModel * im_phone_menu_get_model (ImPhoneMenu *menu); + +void im_phone_menu_add_message (ImPhoneMenu *menu, + GDesktopAppInfo *app, + const gchar *id, + const gchar *iconstr, + const gchar *title, + const gchar *subtitle, + const gchar *body, + gint64 time); + +void im_phone_menu_remove_message (ImPhoneMenu *menu, + GDesktopAppInfo *app, + const gchar *id); + +void im_phone_menu_add_source (ImPhoneMenu *menu, + GDesktopAppInfo *app, + const gchar *id, + const gchar *label, + const gchar *iconstr, + guint32 count, + gint64 time, + const gchar *string); + +void im_phone_menu_remove_source (ImPhoneMenu *menu, + GDesktopAppInfo *app, + const gchar *id); + +#endif diff --git a/src/messages-service.c b/src/messages-service.c index 81b7f0b..9cd7298 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -34,6 +34,7 @@ with this program. If not, see . #include "gmenuutils.h" #include "indicator-messages-service.h" #include "indicator-messages-application.h" +#include "im-phone-menu.h" #define NUM_STATUSES 5 @@ -43,9 +44,7 @@ static IndicatorMessagesService *messages_service; static GSimpleActionGroup *actions; static GActionMuxer *action_muxer; static GMenu *toplevel_menu; -static GMenu *menu; -static GMenu *messages_section; -static GMenu *sources_section; +static ImPhoneMenu *menu; static GSettings *settings; static gboolean draws_attention; static const gchar *global_status[6]; /* max 5: available, away, busy, invisible, offline */ @@ -117,7 +116,7 @@ sources_listed (GObject *source_object, GAsyncResult *result, gpointer user_data) { - gchar *app_id = user_data; + GDesktopAppInfo *app = user_data; GVariant *sources; GVariantIter iter; const gchar *id; @@ -134,7 +133,7 @@ sources_listed (GObject *source_object, { g_warning ("could not fetch the list of sources: %s", error->message); g_error_free (error); - g_free (app_id); + g_object_unref (app); return; } @@ -142,30 +141,21 @@ sources_listed (GObject *source_object, while (g_variant_iter_next (&iter, "(&s&s&sux&sb)", &id, &label, &iconstr, &count, &time, &string, &draws_attention)) { - GMenuItem *item; GActionGroup *app_actions; GSimpleAction *action; - gchar *action_name; - app_actions = g_action_muxer_get_group (action_muxer, app_id); + app_actions = g_action_muxer_get_group (action_muxer, g_app_info_get_id (G_APP_INFO (app))); g_assert (app_actions); action = g_simple_action_new_stateful (id, NULL, g_variant_new_uint32 (count)); g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (app_actions), G_ACTION (action)); - action_name = g_strconcat (app_id, ".", id, NULL); - item = g_menu_item_new (label, action_name); - g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.sourceitem"); - if (iconstr && *iconstr) - g_menu_item_set_attribute (item, "x-canonical-icon", "s", iconstr); - g_menu_append_item (sources_section, item); + im_phone_menu_add_source (menu, app, id, label, iconstr, count, time, string); g_object_unref (action); - g_free (action_name); - g_object_unref (item); } g_variant_unref (sources); - g_free (app_id); + g_object_unref (app); } static void @@ -173,7 +163,7 @@ messages_listed (GObject *source_object, GAsyncResult *result, gpointer user_data) { - gchar *app_id = user_data; + GDesktopAppInfo *app = user_data; GVariant *messages; GError *error = NULL; GVariantIter iter; @@ -190,7 +180,7 @@ messages_listed (GObject *source_object, { g_warning ("could not fetch the list of messages: %s", error->message); g_error_free (error); - g_free (app_id); + g_object_unref (app); return; } @@ -198,34 +188,21 @@ messages_listed (GObject *source_object, while (g_variant_iter_next (&iter, "(&s&s&s&s&sxb)", &id, &iconstr, &title, &subtitle, &body, &time, &draws_attention)) { - GMenuItem *item; GActionGroup *app_actions; GSimpleAction *action; - gchar *action_name; - app_actions = g_action_muxer_get_group (action_muxer, app_id); + app_actions = g_action_muxer_get_group (action_muxer, g_app_info_get_id (G_APP_INFO (app))); g_assert (app_actions); action = g_simple_action_new (id, NULL); g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (app_actions), G_ACTION (action)); - action_name = g_strconcat (app_id, ".", id, NULL); - item = g_menu_item_new (title, action_name); - g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.messageitem"); - g_menu_item_set_attribute (item, "x-canonical-message-id", "s", id); - g_menu_item_set_attribute (item, "x-canonical-subtitle", "s", subtitle); - g_menu_item_set_attribute (item, "x-canonical-text", "s", body); - g_menu_item_set_attribute (item, "x-canonical-time", "x", time); - if (iconstr && *iconstr) - g_menu_item_set_attribute (item, "x-canonical-icon", "s", iconstr); - g_menu_append_item (messages_section, item); + im_phone_menu_add_message (menu, app, id, iconstr, title, subtitle, body, time); g_object_unref (action); - g_free (action_name); - g_object_unref (item); } g_variant_unref (messages); - g_free (app_id); + g_object_unref (app); } static void @@ -233,7 +210,7 @@ app_proxy_created (GObject *source_object, GAsyncResult *result, gpointer user_data) { - gchar *desktop_id = user_data; + GDesktopAppInfo *app = user_data; IndicatorMessagesApplication *app_proxy; GError *error = NULL; @@ -244,11 +221,12 @@ app_proxy_created (GObject *source_object, return; } - /* hash table takes ownership of desktop_id and app_proxy */ - g_hash_table_insert (applications, desktop_id, app_proxy); + g_hash_table_insert (applications, (gpointer) g_app_info_get_id (G_APP_INFO (app)), app_proxy); - indicator_messages_application_call_list_sources (app_proxy, NULL, sources_listed, g_strdup (desktop_id)); - indicator_messages_application_call_list_messages (app_proxy, NULL, messages_listed, g_strdup (desktop_id)); + indicator_messages_application_call_list_sources (app_proxy, NULL, sources_listed, g_object_ref (app)); + indicator_messages_application_call_list_messages (app_proxy, NULL, messages_listed, g_object_ref (app)); + + g_object_unref (app); } static void @@ -261,6 +239,7 @@ register_application (IndicatorMessagesService *service, GDBusConnection *bus; const gchar *sender; GSimpleActionGroup *app_actions; + GDesktopAppInfo *app; if (g_hash_table_lookup (applications, desktop_id)) { g_warning ("application with id '%s' already exists", desktop_id); @@ -270,12 +249,21 @@ register_application (IndicatorMessagesService *service, return; } + app = g_desktop_app_info_new (desktop_id); + if (!app) { + g_warning ("application with id '%s' already exists", desktop_id); + g_dbus_method_invocation_return_dbus_error (invocation, + "com.canonical.indicator.messages.UnknownApplication", + "an application with the given id doesn't exist"); + return; + } + bus = g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (service)); sender = g_dbus_method_invocation_get_sender (invocation); indicator_messages_application_proxy_new (bus, G_DBUS_PROXY_FLAGS_NONE, sender, menu_path, NULL, - app_proxy_created, g_strdup (desktop_id)); + app_proxy_created, g_object_ref (app)); app_actions = g_simple_action_group_new (); g_action_muxer_insert (action_muxer, desktop_id, G_ACTION_GROUP (app_actions)); @@ -285,6 +273,7 @@ register_application (IndicatorMessagesService *service, indicator_messages_service_complete_register_application (service, invocation); g_object_unref (app_actions); + g_object_unref (app); } static void @@ -361,7 +350,7 @@ got_bus (GObject *object, } g_dbus_connection_export_menu_model (bus, INDICATOR_MESSAGES_DBUS_OBJECT "/phone", - G_MENU_MODEL (menu), &error); + im_phone_menu_get_model (menu), &error); if (error) { g_warning ("unable to export menu on dbus: %s", error->message); g_error_free (error); @@ -416,14 +405,10 @@ main (int argc, char ** argv) g_signal_connect (messages_service, "handle-unregister-application", G_CALLBACK (unregister_application), NULL); - menu = g_menu_new (); - sources_section = g_menu_new (); - messages_section = g_menu_new (); - g_menu_append_section (menu, NULL, G_MENU_MODEL (sources_section)); - g_menu_append_section (menu, NULL, G_MENU_MODEL (messages_section)); + menu = im_phone_menu_new (); toplevel_menu = g_menu_new (); - g_menu_append_submenu (toplevel_menu, NULL, G_MENU_MODEL (menu)); + g_menu_append_submenu (toplevel_menu, NULL, im_phone_menu_get_model (menu)); settings = g_settings_new ("com.canonical.indicator.messages"); -- cgit v1.2.3 From 2021da310c84d28efcf9bb359b7a8f7065743267 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 20 Nov 2012 22:20:23 +0100 Subject: messages-service: move app handling into separate class Add ImApplicationList, a class that manages the list of applictions that are currently registered with the messaging menu. It creates dbus proxies for running applications and sends signals when the app adds messages or sources. --- src/Makefile.am | 4 +- src/im-application-list.c | 348 ++++++++++++++++++++++++++++++++++++++++++++++ src/im-application-list.h | 52 +++++++ src/messages-service.c | 176 +++-------------------- 4 files changed, 419 insertions(+), 161 deletions(-) create mode 100644 src/im-application-list.c create mode 100644 src/im-application-list.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 12c8031..5d8bad8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -54,7 +54,9 @@ indicator_messages_service_SOURCES = \ gmenuutils.c \ gmenuutils.h \ im-phone-menu.c \ - im-phone-menu.h + im-phone-menu.h \ + im-application-list.c \ + im-application-list.h indicator_messages_service_CFLAGS = \ $(APPLET_CFLAGS) \ diff --git a/src/im-application-list.c b/src/im-application-list.c new file mode 100644 index 0000000..33f06ab --- /dev/null +++ b/src/im-application-list.c @@ -0,0 +1,348 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Lars Uebernickel + */ + +#include "im-application-list.h" + +#include "indicator-messages-application.h" +#include "gactionmuxer.h" + +#include + +typedef GObjectClass ImApplicationListClass; + +struct _ImApplicationList +{ + GObject parent; + + GHashTable *applications; + GActionMuxer *muxer; +}; + +G_DEFINE_TYPE (ImApplicationList, im_application_list, G_TYPE_OBJECT); + +enum +{ + SOURCE_ADDED, + MESSAGE_ADDED, + N_SIGNALS +}; + +static guint signals[N_SIGNALS]; + +typedef struct +{ + ImApplicationList *list; + GDesktopAppInfo *info; + IndicatorMessagesApplication *proxy; + GSimpleActionGroup *actions; + GCancellable *cancellable; +} Application; + +static void +application_free (gpointer data) +{ + Application *app = data; + + if (!app) + return; + + g_clear_object (&app->info); + + if (app->cancellable) + { + g_cancellable_cancel (app->cancellable); + g_clear_object (&app->cancellable); + } + + if (app->proxy) + g_object_unref (app->proxy); + + if (app->actions) + g_object_unref (app->actions); + + g_slice_free (Application, app); +} + +static void +im_application_list_dispose (GObject *object) +{ + ImApplicationList *list = IM_APPLICATION_LIST (object); + + g_clear_pointer (&list->applications, g_hash_table_unref); + g_clear_object (&list->muxer); + + G_OBJECT_CLASS (im_application_list_parent_class)->dispose (object); +} + +static void +im_application_list_finalize (GObject *object) +{ + G_OBJECT_CLASS (im_application_list_parent_class)->finalize (object); +} + +static void +im_application_list_class_init (ImApplicationListClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = im_application_list_dispose; + object_class->finalize = im_application_list_finalize; + + signals[SOURCE_ADDED] = g_signal_new ("source-added", + IM_TYPE_APPLICATION_LIST, + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_generic, + G_TYPE_NONE, + 8, + G_TYPE_DESKTOP_APP_INFO, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_UINT, + G_TYPE_INT64, + G_TYPE_STRING, + G_TYPE_BOOLEAN); + + signals[MESSAGE_ADDED] = g_signal_new ("message-added", + IM_TYPE_APPLICATION_LIST, + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_generic, + G_TYPE_NONE, + 8, + G_TYPE_DESKTOP_APP_INFO, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_INT64, + G_TYPE_BOOLEAN); +} + +static void +im_application_list_init (ImApplicationList *list) +{ + list->applications = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, application_free); + list->muxer = g_action_muxer_new (); +} + +ImApplicationList * +im_application_list_new (void) +{ + return g_object_new (IM_TYPE_APPLICATION_LIST, NULL); +} + +gboolean +im_application_list_add (ImApplicationList *list, + const gchar *desktop_id) +{ + GDesktopAppInfo *info; + Application *app; + const gchar *id; + + g_return_val_if_fail (IM_IS_APPLICATION_LIST (list), FALSE); + g_return_val_if_fail (desktop_id != NULL, FALSE); + + if (g_hash_table_contains (list->applications, desktop_id)) + { + g_warning ("an application with id '%s' already exists", desktop_id); + return FALSE; + } + + info = g_desktop_app_info_new (desktop_id); + if (!info) + { + g_warning ("application with id '%s' already exists", desktop_id); + return FALSE; + } + + id = g_app_info_get_id (G_APP_INFO (info)); + + app = g_slice_new0 (Application); + app->list = list; + app->info = info; + app->actions = g_simple_action_group_new (); + + g_hash_table_insert (list->applications, (gpointer) id, app); + g_action_muxer_insert (list->muxer, id, G_ACTION_GROUP (app->actions)); + + return TRUE; +} + +void +im_application_list_remove (ImApplicationList *list, + const gchar *id) +{ + g_return_if_fail (IM_IS_APPLICATION_LIST (list)); + + g_hash_table_remove (list->applications, id); + g_action_muxer_remove (list->muxer, id); +} + +static void +im_application_list_sources_listed (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + Application *app = user_data; + GVariant *sources; + GError *error = NULL; + + if (indicator_messages_application_call_list_sources_finish (app->proxy, &sources, result, &error)) + { + GVariantIter iter; + const gchar *id; + const gchar *label; + const gchar *iconstr; + guint32 count; + gint64 time; + const gchar *string; + gboolean draws_attention; + + g_variant_iter_init (&iter, sources); + while (g_variant_iter_next (&iter, "(&s&s&sux&sb)", &id, &label, &iconstr, &count, + &time, &string, &draws_attention)) + { + GSimpleAction *action; + + action = g_simple_action_new_stateful (id, NULL, g_variant_new_uint32 (count)); + g_simple_action_group_insert (app->actions, G_ACTION (action)); + + g_signal_emit (app->list, signals[SOURCE_ADDED], 0, + app->info, id, label, iconstr, count, time, string, draws_attention); + + g_object_unref (action); + } + g_variant_unref (sources); + } + else + { + g_warning ("could not fetch the list of sources: %s", error->message); + g_error_free (error); + } +} + +static void +im_application_list_messages_listed (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + Application *app = user_data; + GVariant *messages; + GError *error = NULL; + + if (indicator_messages_application_call_list_messages_finish (app->proxy, &messages, result, &error)) + { + GVariantIter iter; + const gchar *id; + const gchar *iconstr; + const gchar *title; + const gchar *subtitle; + const gchar *body; + gint64 time; + gboolean draws_attention; + + g_variant_iter_init (&iter, messages); + while (g_variant_iter_next (&iter, "(&s&s&s&s&sxb)", &id, &iconstr, &title, &subtitle, &body, + &time, &draws_attention)) + { + GSimpleAction *action; + + action = g_simple_action_new (id, NULL); + g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (app->actions), G_ACTION (action)); + + g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, + app->info, id, iconstr, title, subtitle, body, time, draws_attention); + + g_object_unref (action); + } + + g_variant_unref (messages); + } + else + { + g_warning ("could not fetch the list of messages: %s", error->message); + g_error_free (error); + } +} + +static void +im_application_list_proxy_created (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + Application *app = user_data; + GError *error = NULL; + + app->proxy = indicator_messages_application_proxy_new_finish (result, &error); + if (!app) + { + g_warning ("could not create application proxy: %s", error->message); + g_error_free (error); + return; + } + + indicator_messages_application_call_list_sources (app->proxy, app->cancellable, + im_application_list_sources_listed, app); + indicator_messages_application_call_list_messages (app->proxy, app->cancellable, + im_application_list_messages_listed, app); +} + +void +im_application_list_set_remote (ImApplicationList *list, + const gchar *id, + GDBusConnection *connection, + const gchar *unique_bus_name, + const gchar *object_path) +{ + Application *app; + + g_return_if_fail (IM_IS_APPLICATION_LIST (list)); + + app = g_hash_table_lookup (list->applications, id); + if (!app) + { + g_warning ("'%s' is not a registered appliction", id); + return; + } + + if (app->proxy || app->cancellable) + { + g_warning ("application '%s' is already running on '%s'", + id, g_dbus_proxy_get_name_owner (G_DBUS_PROXY (app->proxy))); + return; + } + + app->cancellable = g_cancellable_new (); + indicator_messages_application_proxy_new (connection, G_DBUS_PROXY_FLAGS_NONE, + unique_bus_name, object_path, app->cancellable, + im_application_list_proxy_created, app); +} + +GActionGroup * +im_application_list_get_action_group (ImApplicationList *list) +{ + g_return_val_if_fail (IM_IS_APPLICATION_LIST (list), NULL); + + return G_ACTION_GROUP (list->muxer); +} diff --git a/src/im-application-list.h b/src/im-application-list.h new file mode 100644 index 0000000..3bf21c9 --- /dev/null +++ b/src/im-application-list.h @@ -0,0 +1,52 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Lars Uebernickel + */ + +#ifndef __IM_APPLICATION_LIST_H__ +#define __IM_APPLICATION_LIST_H__ + +#include + +#define IM_TYPE_APPLICATION_LIST (im_application_list_get_type ()) +#define IM_APPLICATION_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_TYPE_APPLICATION_LIST, ImApplicationList)) +#define IM_APPLICATION_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IM_TYPE_APPLICATION_LIST, ImApplicationListClass)) +#define IM_IS_APPLICATION_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IM_TYPE_APPLICATION_LIST)) +#define IM_IS_APPLICATION_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IM_TYPE_APPLICATION_LIST)) +#define IM_APPLICATION_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IM_TYPE_APPLICATION_LIST, ImApplicationListClass)) + +typedef struct _ImApplicationList ImApplicationList; + +GType im_application_list_get_type (void); + +ImApplicationList * im_application_list_new (void); + +gboolean im_application_list_add (ImApplicationList *list, + const gchar *desktop_id); + +void im_application_list_remove (ImApplicationList *list, + const gchar *id); + +void im_application_list_set_remote (ImApplicationList *list, + const gchar *id, + GDBusConnection *connection, + const gchar *unique_bus_name, + const gchar *object_path); + +GActionGroup * im_application_list_get_action_group (ImApplicationList *list); + +#endif diff --git a/src/messages-service.c b/src/messages-service.c index 9cd7298..a65e2d8 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -25,24 +25,22 @@ with this program. If not, see . #include #include #include -#include #include #include "dbus-data.h" -#include "gactionmuxer.h" #include "gsettingsstrv.h" #include "gmenuutils.h" #include "indicator-messages-service.h" #include "indicator-messages-application.h" #include "im-phone-menu.h" +#include "im-application-list.h" #define NUM_STATUSES 5 -static GHashTable *applications; +static ImApplicationList *applications; static IndicatorMessagesService *messages_service; static GSimpleActionGroup *actions; -static GActionMuxer *action_muxer; static GMenu *toplevel_menu; static ImPhoneMenu *menu; static GSettings *settings; @@ -111,124 +109,6 @@ status_action_activate (GSimpleAction *action, indicator_messages_service_emit_status_changed (messages_service, status); } -static void -sources_listed (GObject *source_object, - GAsyncResult *result, - gpointer user_data) -{ - GDesktopAppInfo *app = user_data; - GVariant *sources; - GVariantIter iter; - const gchar *id; - const gchar *label; - const gchar *iconstr; - guint32 count; - gint64 time; - const gchar *string; - gboolean draws_attention; - GError *error = NULL; - - if (!indicator_messages_application_call_list_sources_finish (INDICATOR_MESSAGES_APPLICATION (source_object), - &sources, result, &error)) - { - g_warning ("could not fetch the list of sources: %s", error->message); - g_error_free (error); - g_object_unref (app); - return; - } - - g_variant_iter_init (&iter, sources); - while (g_variant_iter_next (&iter, "(&s&s&sux&sb)", &id, &label, &iconstr, &count, - &time, &string, &draws_attention)) - { - GActionGroup *app_actions; - GSimpleAction *action; - - app_actions = g_action_muxer_get_group (action_muxer, g_app_info_get_id (G_APP_INFO (app))); - g_assert (app_actions); - action = g_simple_action_new_stateful (id, NULL, g_variant_new_uint32 (count)); - g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (app_actions), G_ACTION (action)); - - im_phone_menu_add_source (menu, app, id, label, iconstr, count, time, string); - - g_object_unref (action); - } - - g_variant_unref (sources); - g_object_unref (app); -} - -static void -messages_listed (GObject *source_object, - GAsyncResult *result, - gpointer user_data) -{ - GDesktopAppInfo *app = user_data; - GVariant *messages; - GError *error = NULL; - GVariantIter iter; - const gchar *id; - const gchar *iconstr; - const gchar *title; - const gchar *subtitle; - const gchar *body; - gint64 time; - gboolean draws_attention; - - if (!indicator_messages_application_call_list_messages_finish (INDICATOR_MESSAGES_APPLICATION (source_object), - &messages, result, &error)) - { - g_warning ("could not fetch the list of messages: %s", error->message); - g_error_free (error); - g_object_unref (app); - return; - } - - g_variant_iter_init (&iter, messages); - while (g_variant_iter_next (&iter, "(&s&s&s&s&sxb)", &id, &iconstr, &title, &subtitle, &body, - &time, &draws_attention)) - { - GActionGroup *app_actions; - GSimpleAction *action; - - app_actions = g_action_muxer_get_group (action_muxer, g_app_info_get_id (G_APP_INFO (app))); - g_assert (app_actions); - action = g_simple_action_new (id, NULL); - g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (app_actions), G_ACTION (action)); - - im_phone_menu_add_message (menu, app, id, iconstr, title, subtitle, body, time); - - g_object_unref (action); - } - - g_variant_unref (messages); - g_object_unref (app); -} - -static void -app_proxy_created (GObject *source_object, - GAsyncResult *result, - gpointer user_data) -{ - GDesktopAppInfo *app = user_data; - IndicatorMessagesApplication *app_proxy; - GError *error = NULL; - - app_proxy = indicator_messages_application_proxy_new_finish (result, &error); - if (!app_proxy) { - g_warning ("could not create application proxy: %s", error->message); - g_error_free (error); - return; - } - - g_hash_table_insert (applications, (gpointer) g_app_info_get_id (G_APP_INFO (app)), app_proxy); - - indicator_messages_application_call_list_sources (app_proxy, NULL, sources_listed, g_object_ref (app)); - indicator_messages_application_call_list_messages (app_proxy, NULL, messages_listed, g_object_ref (app)); - - g_object_unref (app); -} - static void register_application (IndicatorMessagesService *service, GDBusMethodInvocation *invocation, @@ -238,42 +118,21 @@ register_application (IndicatorMessagesService *service, { GDBusConnection *bus; const gchar *sender; - GSimpleActionGroup *app_actions; - GDesktopAppInfo *app; - - if (g_hash_table_lookup (applications, desktop_id)) { - g_warning ("application with id '%s' already exists", desktop_id); - g_dbus_method_invocation_return_dbus_error (invocation, - "com.canonical.indicator.messages.ApplicationAlreadyRegistered", - "another application is already registered with this id"); - return; - } - app = g_desktop_app_info_new (desktop_id); - if (!app) { - g_warning ("application with id '%s' already exists", desktop_id); + if (!im_application_list_add (applications, desktop_id)) { g_dbus_method_invocation_return_dbus_error (invocation, - "com.canonical.indicator.messages.UnknownApplication", - "an application with the given id doesn't exist"); + "com.canonical.indicator.messages.RegistrationFailed", + "registration failed"); return; } bus = g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (service)); sender = g_dbus_method_invocation_get_sender (invocation); - indicator_messages_application_proxy_new (bus, G_DBUS_PROXY_FLAGS_NONE, - sender, menu_path, NULL, - app_proxy_created, g_object_ref (app)); - - app_actions = g_simple_action_group_new (); - g_action_muxer_insert (action_muxer, desktop_id, G_ACTION_GROUP (app_actions)); - + im_application_list_set_remote (applications, desktop_id, bus, sender, menu_path); g_settings_strv_append_unique (settings, "applications", desktop_id); indicator_messages_service_complete_register_application (service, invocation); - - g_object_unref (app_actions); - g_object_unref (app); } static void @@ -282,13 +141,8 @@ unregister_application (IndicatorMessagesService *service, const gchar *desktop_id, gpointer user_data) { - if (g_hash_table_remove (applications, desktop_id)) { - - /* TODO remove menu items that refer to this application */ - g_action_muxer_remove (action_muxer, desktop_id); - - g_settings_strv_remove (settings, "applications", desktop_id); - } + im_application_list_remove (applications, desktop_id); + g_settings_strv_remove (settings, "applications", desktop_id); indicator_messages_service_complete_unregister_application (service, invocation); } @@ -342,7 +196,8 @@ got_bus (GObject *object, } g_dbus_connection_export_action_group (bus, INDICATOR_MESSAGES_DBUS_OBJECT, - G_ACTION_GROUP (action_muxer), &error); + im_application_list_get_action_group (applications), + &error); if (error) { g_warning ("unable to export action group on dbus: %s", error->message); g_error_free (error); @@ -397,9 +252,6 @@ main (int argc, char ** argv) actions = create_action_group (); - action_muxer = g_action_muxer_new (); - g_action_muxer_insert (action_muxer, NULL, G_ACTION_GROUP (actions)); - g_signal_connect (messages_service, "handle-register-application", G_CALLBACK (register_application), NULL); g_signal_connect (messages_service, "handle-unregister-application", @@ -412,13 +264,17 @@ main (int argc, char ** argv) settings = g_settings_new ("com.canonical.indicator.messages"); - applications = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); + applications = im_application_list_new (); + g_signal_connect_swapped (applications, "source-added", + G_CALLBACK (im_phone_menu_add_source), menu); + g_signal_connect_swapped (applications, "message-added", + G_CALLBACK (im_phone_menu_add_message), menu); g_main_loop_run(mainloop); /* Clean up */ g_object_unref (messages_service); g_object_unref (settings); - g_hash_table_unref (applications); + g_object_unref (applications); return 0; } -- cgit v1.2.3 From 717f9be0d9319ed4aa680c77aa2a30318da10fda Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 20 Nov 2012 23:14:48 +0100 Subject: ImApplicationList: listen for added and removed signals --- src/im-application-list.c | 185 +++++++++++++++++++++++++++++++++++++--------- src/messages-service.c | 4 + 2 files changed, 153 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 33f06ab..920626d 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -39,7 +39,10 @@ G_DEFINE_TYPE (ImApplicationList, im_application_list, G_TYPE_OBJECT); enum { SOURCE_ADDED, + SOURCE_CHANGED, + SOURCE_REMOVED, MESSAGE_ADDED, + MESSAGE_REMOVED, N_SIGNALS }; @@ -121,6 +124,34 @@ im_application_list_class_init (ImApplicationListClass *klass) G_TYPE_STRING, G_TYPE_BOOLEAN); + signals[SOURCE_CHANGED] = g_signal_new ("source-changed", + IM_TYPE_APPLICATION_LIST, + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_generic, + G_TYPE_NONE, + 8, + G_TYPE_DESKTOP_APP_INFO, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_UINT, + G_TYPE_INT64, + G_TYPE_STRING, + G_TYPE_BOOLEAN); + + signals[SOURCE_REMOVED] = g_signal_new ("source-removed", + IM_TYPE_APPLICATION_LIST, + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_generic, + G_TYPE_NONE, + 2, + G_TYPE_DESKTOP_APP_INFO, + G_TYPE_STRING); + signals[MESSAGE_ADDED] = g_signal_new ("message-added", IM_TYPE_APPLICATION_LIST, G_SIGNAL_RUN_FIRST, @@ -137,6 +168,17 @@ im_application_list_class_init (ImApplicationListClass *klass) G_TYPE_STRING, G_TYPE_INT64, G_TYPE_BOOLEAN); + + signals[MESSAGE_REMOVED] = g_signal_new ("message-removed", + IM_TYPE_APPLICATION_LIST, + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_generic, + G_TYPE_NONE, + 2, + G_TYPE_DESKTOP_APP_INFO, + G_TYPE_STRING); } static void @@ -199,6 +241,63 @@ im_application_list_remove (ImApplicationList *list, g_action_muxer_remove (list->muxer, id); } +static void +im_application_list_source_added (Application *app, + guint position, + GVariant *source) +{ + const gchar *id; + const gchar *label; + const gchar *iconstr; + guint32 count; + gint64 time; + const gchar *string; + gboolean draws_attention; + GSimpleAction *action; + + g_variant_get (source, "(&s&s&sux&sb)", + &id, &label, &iconstr, &count, &time, &string, &draws_attention); + + action = g_simple_action_new_stateful (id, NULL, g_variant_new_uint32 (count)); + g_simple_action_group_insert (app->actions, G_ACTION (action)); + + g_signal_emit (app->list, signals[SOURCE_ADDED], 0, + app->info, id, label, iconstr, count, time, string, draws_attention); + + g_object_unref (action); +} + +static void +im_application_list_source_changed (Application *app, + GVariant *source) +{ + const gchar *id; + const gchar *label; + const gchar *iconstr; + guint32 count; + gint64 time; + const gchar *string; + gboolean draws_attention; + + g_variant_get (source, "(&s&s&sux&sb)", + &id, &label, &iconstr, &count, &time, &string, &draws_attention); + + g_action_group_change_action_state (G_ACTION_GROUP (app->actions), id, + g_variant_new_uint32 (count)); + + g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, + app->info, id, label, iconstr, count, time, string, draws_attention); +} + +static void +im_application_list_source_removed (Application *app, + const gchar *id) +{ + g_simple_action_group_remove (app->actions, id); + + g_signal_emit (app->list, signals[SOURCE_REMOVED], 0, app->info, id); +} + static void im_application_list_sources_listed (GObject *source_object, GAsyncResult *result, @@ -211,28 +310,16 @@ im_application_list_sources_listed (GObject *source_object, if (indicator_messages_application_call_list_sources_finish (app->proxy, &sources, result, &error)) { GVariantIter iter; - const gchar *id; - const gchar *label; - const gchar *iconstr; - guint32 count; - gint64 time; - const gchar *string; - gboolean draws_attention; + GVariant *source; + guint i = 0; g_variant_iter_init (&iter, sources); - while (g_variant_iter_next (&iter, "(&s&s&sux&sb)", &id, &label, &iconstr, &count, - &time, &string, &draws_attention)) + while ((source = g_variant_iter_next_value (&iter))) { - GSimpleAction *action; - - action = g_simple_action_new_stateful (id, NULL, g_variant_new_uint32 (count)); - g_simple_action_group_insert (app->actions, G_ACTION (action)); - - g_signal_emit (app->list, signals[SOURCE_ADDED], 0, - app->info, id, label, iconstr, count, time, string, draws_attention); - - g_object_unref (action); + im_application_list_source_added (app, i++, source); + g_variant_unref (source); } + g_variant_unref (sources); } else @@ -242,6 +329,40 @@ im_application_list_sources_listed (GObject *source_object, } } +static void +im_application_list_message_added (Application *app, + GVariant *message) +{ + const gchar *id; + const gchar *iconstr; + const gchar *title; + const gchar *subtitle; + const gchar *body; + gint64 time; + gboolean draws_attention; + GSimpleAction *action; + + g_variant_get (message, "(&s&s&s&s&sxb)", + &id, &iconstr, &title, &subtitle, &body, &time, &draws_attention); + + action = g_simple_action_new (id, NULL); + g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (app->actions), G_ACTION (action)); + + g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, + app->info, id, iconstr, title, subtitle, body, time, draws_attention); + + g_object_unref (action); +} + +static void +im_application_list_message_removed (Application *app, + const gchar *id) +{ + g_simple_action_group_remove (app->actions, id); + + g_signal_emit (app->list, signals[MESSAGE_REMOVED], 0, app->info, id); +} + static void im_application_list_messages_listed (GObject *source_object, GAsyncResult *result, @@ -254,27 +375,13 @@ im_application_list_messages_listed (GObject *source_object, if (indicator_messages_application_call_list_messages_finish (app->proxy, &messages, result, &error)) { GVariantIter iter; - const gchar *id; - const gchar *iconstr; - const gchar *title; - const gchar *subtitle; - const gchar *body; - gint64 time; - gboolean draws_attention; + GVariant *message; g_variant_iter_init (&iter, messages); - while (g_variant_iter_next (&iter, "(&s&s&s&s&sxb)", &id, &iconstr, &title, &subtitle, &body, - &time, &draws_attention)) + while ((message = g_variant_iter_next_value (&iter))) { - GSimpleAction *action; - - action = g_simple_action_new (id, NULL); - g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (app->actions), G_ACTION (action)); - - g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, - app->info, id, iconstr, title, subtitle, body, time, draws_attention); - - g_object_unref (action); + im_application_list_message_added (app, message); + g_variant_unref (message); } g_variant_unref (messages); @@ -306,6 +413,12 @@ im_application_list_proxy_created (GObject *source_object, im_application_list_sources_listed, app); indicator_messages_application_call_list_messages (app->proxy, app->cancellable, im_application_list_messages_listed, app); + + g_signal_connect_swapped (app->proxy, "source-added", G_CALLBACK (im_application_list_source_added), app); + g_signal_connect_swapped (app->proxy, "source-changed", G_CALLBACK (im_application_list_source_changed), app); + g_signal_connect_swapped (app->proxy, "source-removed", G_CALLBACK (im_application_list_source_removed), app); + g_signal_connect_swapped (app->proxy, "message-added", G_CALLBACK (im_application_list_message_added), app); + g_signal_connect_swapped (app->proxy, "message-removed", G_CALLBACK (im_application_list_message_removed), app); } void diff --git a/src/messages-service.c b/src/messages-service.c index a65e2d8..467224d 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -267,8 +267,12 @@ main (int argc, char ** argv) applications = im_application_list_new (); g_signal_connect_swapped (applications, "source-added", G_CALLBACK (im_phone_menu_add_source), menu); + g_signal_connect_swapped (applications, "source-removed", + G_CALLBACK (im_phone_menu_remove_source), menu); g_signal_connect_swapped (applications, "message-added", G_CALLBACK (im_phone_menu_add_message), menu); + g_signal_connect_swapped (applications, "message-removed", + G_CALLBACK (im_phone_menu_remove_message), menu); g_main_loop_run(mainloop); -- cgit v1.2.3 From d22b49e5fee5ae352ec6050e63181850a857fb3a Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 21 Nov 2012 00:02:12 +0100 Subject: Remove applications from the menu when the disappear from the bus --- src/im-application-list.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/im-phone-menu.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/im-phone-menu.h | 3 +++ src/messages-service.c | 2 ++ 4 files changed, 90 insertions(+) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 920626d..6da2950 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -43,6 +43,7 @@ enum SOURCE_REMOVED, MESSAGE_ADDED, MESSAGE_REMOVED, + APP_STOPPED, N_SIGNALS }; @@ -179,6 +180,16 @@ im_application_list_class_init (ImApplicationListClass *klass) 2, G_TYPE_DESKTOP_APP_INFO, G_TYPE_STRING); + + signals[APP_STOPPED] = g_signal_new ("app-stopped", + IM_TYPE_APPLICATION_LIST, + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, + 1, + G_TYPE_DESKTOP_APP_INFO); } static void @@ -393,6 +404,31 @@ im_application_list_messages_listed (GObject *source_object, } } +static void +im_application_list_app_vanished (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + Application *app = user_data; + + if (app->cancellable) + { + g_cancellable_cancel (app->cancellable); + g_clear_object (&app->cancellable); + } + g_clear_object (&app->proxy); + + /* clear actions by creating a new action group and overriding it in + * the muxer */ + g_object_unref (app->actions); + app->actions = g_simple_action_group_new (); + g_action_muxer_insert (app->list->muxer, + g_app_info_get_id (G_APP_INFO (app->info)), + G_ACTION_GROUP (app->actions)); + + g_signal_emit (app->list, signals[APP_STOPPED], 0, app->info); +} + static void im_application_list_proxy_created (GObject *source_object, GAsyncResult *result, @@ -419,6 +455,12 @@ im_application_list_proxy_created (GObject *source_object, g_signal_connect_swapped (app->proxy, "source-removed", G_CALLBACK (im_application_list_source_removed), app); g_signal_connect_swapped (app->proxy, "message-added", G_CALLBACK (im_application_list_message_added), app); g_signal_connect_swapped (app->proxy, "message-removed", G_CALLBACK (im_application_list_message_removed), app); + + g_bus_watch_name_on_connection (g_dbus_proxy_get_connection (G_DBUS_PROXY (app->proxy)), + g_dbus_proxy_get_name (G_DBUS_PROXY (app->proxy)), + G_BUS_NAME_WATCHER_FLAGS_NONE, + NULL, im_application_list_app_vanished, + app, NULL); } void diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index abb3a11..43b7a6c 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -214,3 +214,46 @@ im_phone_menu_remove_source (ImPhoneMenu *menu, g_free (action_name); } + +static void +im_phone_menu_remove_all_for_app (GMenu *menu, + GDesktopAppInfo *app) +{ + gchar *prefix; + gint n_items; + gint i = 0; + + prefix = g_strconcat (g_app_info_get_id (G_APP_INFO (app)), ".", NULL); + + n_items = g_menu_model_get_n_items (G_MENU_MODEL (menu)); + while (i < n_items) + { + gchar *action; + + g_menu_model_get_item_attribute (G_MENU_MODEL (menu), i, G_MENU_ATTRIBUTE_ACTION, "s", &action); + if (g_str_has_prefix (action, prefix)) + { + g_menu_remove (menu, i); + n_items--; + } + else + { + i++; + } + + g_free (action); + } + + g_free (prefix); +} + +void +im_phone_menu_remove_application (ImPhoneMenu *menu, + GDesktopAppInfo *app) +{ + g_return_if_fail (IM_IS_PHONE_MENU (menu)); + g_return_if_fail (G_IS_DESKTOP_APP_INFO (app)); + + im_phone_menu_remove_all_for_app (menu->source_section, app); + im_phone_menu_remove_all_for_app (menu->message_section, app); +} diff --git a/src/im-phone-menu.h b/src/im-phone-menu.h index f7cc645..91aae2c 100644 --- a/src/im-phone-menu.h +++ b/src/im-phone-menu.h @@ -64,4 +64,7 @@ void im_phone_menu_remove_source (ImPhoneMenu *men GDesktopAppInfo *app, const gchar *id); +void im_phone_menu_remove_application (ImPhoneMenu *menu, + GDesktopAppInfo *app); + #endif diff --git a/src/messages-service.c b/src/messages-service.c index 467224d..18f3d0a 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -273,6 +273,8 @@ main (int argc, char ** argv) G_CALLBACK (im_phone_menu_add_message), menu); g_signal_connect_swapped (applications, "message-removed", G_CALLBACK (im_phone_menu_remove_message), menu); + g_signal_connect_swapped (applications, "app-stopped", + G_CALLBACK (im_phone_menu_remove_application), menu); g_main_loop_run(mainloop); -- cgit v1.2.3 From 1d96aab069071bd6f73b3be8beb40ca25d37fa86 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 21 Nov 2012 00:16:44 +0100 Subject: Replace app when another process is registering with the same id --- src/im-application-list.c | 28 +++++++++++++--------------- src/im-application-list.h | 2 +- src/messages-service.c | 7 +------ 3 files changed, 15 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 6da2950..3221413 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -205,7 +205,7 @@ im_application_list_new (void) return g_object_new (IM_TYPE_APPLICATION_LIST, NULL); } -gboolean +void im_application_list_add (ImApplicationList *list, const gchar *desktop_id) { @@ -213,20 +213,18 @@ im_application_list_add (ImApplicationList *list, Application *app; const gchar *id; - g_return_val_if_fail (IM_IS_APPLICATION_LIST (list), FALSE); - g_return_val_if_fail (desktop_id != NULL, FALSE); + g_return_if_fail (IM_IS_APPLICATION_LIST (list)); + g_return_if_fail (desktop_id != NULL); - if (g_hash_table_contains (list->applications, desktop_id)) - { - g_warning ("an application with id '%s' already exists", desktop_id); - return FALSE; - } + app = g_hash_table_lookup (list->applications, desktop_id); + if (app) + return; info = g_desktop_app_info_new (desktop_id); if (!info) { - g_warning ("application with id '%s' already exists", desktop_id); - return FALSE; + g_warning ("an application with id '%s' is no installed", desktop_id); + return; } id = g_app_info_get_id (G_APP_INFO (info)); @@ -238,8 +236,6 @@ im_application_list_add (ImApplicationList *list, g_hash_table_insert (list->applications, (gpointer) id, app); g_action_muxer_insert (list->muxer, id, G_ACTION_GROUP (app->actions)); - - return TRUE; } void @@ -483,9 +479,11 @@ im_application_list_set_remote (ImApplicationList *list, if (app->proxy || app->cancellable) { - g_warning ("application '%s' is already running on '%s'", - id, g_dbus_proxy_get_name_owner (G_DBUS_PROXY (app->proxy))); - return; + g_warning ("replacing '%s' at %s with %s", id, unique_bus_name, + g_dbus_proxy_get_name_owner (G_DBUS_PROXY (app->proxy))); + g_cancellable_cancel (app->cancellable); + g_object_unref (app->cancellable); + g_clear_object (&app->proxy); } app->cancellable = g_cancellable_new (); diff --git a/src/im-application-list.h b/src/im-application-list.h index 3bf21c9..ecba312 100644 --- a/src/im-application-list.h +++ b/src/im-application-list.h @@ -35,7 +35,7 @@ GType im_application_list_get_type (void); ImApplicationList * im_application_list_new (void); -gboolean im_application_list_add (ImApplicationList *list, +void im_application_list_add (ImApplicationList *list, const gchar *desktop_id); void im_application_list_remove (ImApplicationList *list, diff --git a/src/messages-service.c b/src/messages-service.c index 18f3d0a..b3731a8 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -119,12 +119,7 @@ register_application (IndicatorMessagesService *service, GDBusConnection *bus; const gchar *sender; - if (!im_application_list_add (applications, desktop_id)) { - g_dbus_method_invocation_return_dbus_error (invocation, - "com.canonical.indicator.messages.RegistrationFailed", - "registration failed"); - return; - } + im_application_list_add (applications, desktop_id); bus = g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (service)); sender = g_dbus_method_invocation_get_sender (invocation); -- cgit v1.2.3 From 0a9533c90d46c4bfda4e0527f5475ce8c22c08e7 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 21 Nov 2012 00:28:12 +0100 Subject: Remove application messages when it unregisters itself --- src/im-application-list.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 3221413..9e9df9d 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -242,10 +242,19 @@ void im_application_list_remove (ImApplicationList *list, const gchar *id) { + Application *app; + g_return_if_fail (IM_IS_APPLICATION_LIST (list)); - g_hash_table_remove (list->applications, id); - g_action_muxer_remove (list->muxer, id); + app = g_hash_table_lookup (list->applications, id); + if (app) + { + if (app->proxy || app->cancellable) + g_signal_emit (app->list, signals[APP_STOPPED], 0, app->info); + + g_hash_table_remove (list->applications, id); + g_action_muxer_remove (list->muxer, id); + } } static void @@ -401,11 +410,11 @@ im_application_list_messages_listed (GObject *source_object, } static void -im_application_list_app_vanished (GDBusConnection *connection, - const gchar *name, - gpointer user_data) +im_application_list_unset_remote (Application *app) { - Application *app = user_data; + gboolean was_running; + + was_running = app->proxy || app->cancellable; if (app->cancellable) { @@ -422,7 +431,18 @@ im_application_list_app_vanished (GDBusConnection *connection, g_app_info_get_id (G_APP_INFO (app->info)), G_ACTION_GROUP (app->actions)); - g_signal_emit (app->list, signals[APP_STOPPED], 0, app->info); + if (was_running) + g_signal_emit (app->list, signals[APP_STOPPED], 0, app->info); +} + +static void +im_application_list_app_vanished (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + Application *app = user_data; + + im_application_list_unset_remote (app); } static void @@ -481,9 +501,7 @@ im_application_list_set_remote (ImApplicationList *list, { g_warning ("replacing '%s' at %s with %s", id, unique_bus_name, g_dbus_proxy_get_name_owner (G_DBUS_PROXY (app->proxy))); - g_cancellable_cancel (app->cancellable); - g_object_unref (app->cancellable); - g_clear_object (&app->proxy); + im_application_list_unset_remote (app); } app->cancellable = g_cancellable_new (); -- cgit v1.2.3 From 7d78b08907c94be166da15adc9b7dad3c282d0f2 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 21 Nov 2012 11:25:20 +0100 Subject: ImApplicationList: no need to include the dynamic data in the signals This data can (and should) always be retrieved via actions. --- src/im-application-list.c | 22 ++++++---------------- src/im-phone-menu.c | 5 +---- src/im-phone-menu.h | 5 +---- 3 files changed, 8 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 9e9df9d..05d3a52 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -115,15 +115,11 @@ im_application_list_class_init (ImApplicationListClass *klass) NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, - 8, + 4, G_TYPE_DESKTOP_APP_INFO, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_UINT, - G_TYPE_INT64, - G_TYPE_STRING, - G_TYPE_BOOLEAN); + G_TYPE_STRING); signals[SOURCE_CHANGED] = g_signal_new ("source-changed", IM_TYPE_APPLICATION_LIST, @@ -132,15 +128,11 @@ im_application_list_class_init (ImApplicationListClass *klass) NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, - 8, + 4, G_TYPE_DESKTOP_APP_INFO, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_UINT, - G_TYPE_INT64, - G_TYPE_STRING, - G_TYPE_BOOLEAN); + G_TYPE_STRING); signals[SOURCE_REMOVED] = g_signal_new ("source-removed", IM_TYPE_APPLICATION_LIST, @@ -277,8 +269,7 @@ im_application_list_source_added (Application *app, action = g_simple_action_new_stateful (id, NULL, g_variant_new_uint32 (count)); g_simple_action_group_insert (app->actions, G_ACTION (action)); - g_signal_emit (app->list, signals[SOURCE_ADDED], 0, - app->info, id, label, iconstr, count, time, string, draws_attention); + g_signal_emit (app->list, signals[SOURCE_ADDED], 0, app->info, id, label, iconstr); g_object_unref (action); } @@ -301,8 +292,7 @@ im_application_list_source_changed (Application *app, g_action_group_change_action_state (G_ACTION_GROUP (app->actions), id, g_variant_new_uint32 (count)); - g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, - app->info, id, label, iconstr, count, time, string, draws_attention); + g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->info, id, label, iconstr); } static void diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index 43b7a6c..0ba41c4 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -172,10 +172,7 @@ im_phone_menu_add_source (ImPhoneMenu *menu, GDesktopAppInfo *app, const gchar *id, const gchar *label, - const gchar *iconstr, - guint32 count, - gint64 time, - const gchar *string) + const gchar *iconstr) { GMenuItem *item; gchar *action_name; diff --git a/src/im-phone-menu.h b/src/im-phone-menu.h index 91aae2c..b0b6b4f 100644 --- a/src/im-phone-menu.h +++ b/src/im-phone-menu.h @@ -55,10 +55,7 @@ void im_phone_menu_add_source (ImPhoneMenu *men GDesktopAppInfo *app, const gchar *id, const gchar *label, - const gchar *iconstr, - guint32 count, - gint64 time, - const gchar *string); + const gchar *iconstr); void im_phone_menu_remove_source (ImPhoneMenu *menu, GDesktopAppInfo *app, -- cgit v1.2.3 From e8eda4af8432d36d82b1124a4bad0f5eee876188 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 21 Nov 2012 13:40:11 +0100 Subject: ImApplicationList: fix typos Thanks Olivier! --- src/im-application-list.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 05d3a52..732a117 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -215,7 +215,7 @@ im_application_list_add (ImApplicationList *list, info = g_desktop_app_info_new (desktop_id); if (!info) { - g_warning ("an application with id '%s' is no installed", desktop_id); + g_warning ("an application with id '%s' is not installed", desktop_id); return; } @@ -483,7 +483,7 @@ im_application_list_set_remote (ImApplicationList *list, app = g_hash_table_lookup (list->applications, id); if (!app) { - g_warning ("'%s' is not a registered appliction", id); + g_warning ("'%s' is not a registered application", id); return; } -- cgit v1.2.3 From a7ca54762c465cd5d26f9eafe11beb3e205a97ab Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 22 Nov 2012 11:58:58 +0100 Subject: ImApplicationList: use specified state for source actions (uxsb) --- src/im-application-list.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 732a117..acd6e2b 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -261,12 +261,14 @@ im_application_list_source_added (Application *app, gint64 time; const gchar *string; gboolean draws_attention; + GVariant *state; GSimpleAction *action; g_variant_get (source, "(&s&s&sux&sb)", &id, &label, &iconstr, &count, &time, &string, &draws_attention); - action = g_simple_action_new_stateful (id, NULL, g_variant_new_uint32 (count)); + state = g_variant_new ("(uxsb)", count, time, string, draws_attention); + action = g_simple_action_new_stateful (id, NULL, state); g_simple_action_group_insert (app->actions, G_ACTION (action)); g_signal_emit (app->list, signals[SOURCE_ADDED], 0, app->info, id, label, iconstr); @@ -290,7 +292,7 @@ im_application_list_source_changed (Application *app, &id, &label, &iconstr, &count, &time, &string, &draws_attention); g_action_group_change_action_state (G_ACTION_GROUP (app->actions), id, - g_variant_new_uint32 (count)); + g_variant_new ("(uxsb)", count, time, string, draws_attention)); g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->info, id, label, iconstr); } -- cgit v1.2.3 From e5985f89f62fdac65d4f80037835691630cc3d2c Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 22 Nov 2012 12:03:01 +0100 Subject: ImPhoneMenu: expose application icon on message items --- src/im-phone-menu.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index 0ba41c4..9fd52df 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -124,6 +124,7 @@ im_phone_menu_add_message (ImPhoneMenu *menu, const gchar *app_id; GMenuItem *item; gchar *action_name; + GIcon *app_icon; g_return_if_fail (IM_IS_PHONE_MENU (menu)); g_return_if_fail (G_IS_DESKTOP_APP_INFO (app)); @@ -143,6 +144,17 @@ im_phone_menu_add_message (ImPhoneMenu *menu, if (iconstr) g_menu_item_set_attribute (item, "x-canonical-icon", "s", iconstr); + app_icon = g_app_info_get_icon (G_APP_INFO (app)); + if (app_icon) + { + gchar *app_iconstr; + + app_iconstr = g_icon_to_string (app_icon); + g_menu_item_set_attribute (item, "x-canonical-app-icon", "s", app_iconstr); + + g_free (app_iconstr); + } + g_menu_append_item (menu->message_section, item); g_free (action_name); -- cgit v1.2.3 From 979a9b32a625adb29af3b5bd6bfe324268a51b2c Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 26 Nov 2012 11:34:50 +0100 Subject: Canonicalize application ids Remove trailing '.desktop' and replace all dots by underscores to make GActionMuxer work (which uses the dot as a separator). In order to contain the canonicalization to ImApplicationList, its signals now contain string parameters to id and icon name instead of GDesktopAppInfo pointers. --- src/im-application-list.c | 87 ++++++++++++++++++++++++++++++++++------------- src/im-phone-menu.c | 48 ++++++++++---------------- src/im-phone-menu.h | 14 ++++---- 3 files changed, 88 insertions(+), 61 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index acd6e2b..24df19e 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -23,6 +23,7 @@ #include "gactionmuxer.h" #include +#include typedef GObjectClass ImApplicationListClass; @@ -53,6 +54,7 @@ typedef struct { ImApplicationList *list; GDesktopAppInfo *info; + gchar *id; IndicatorMessagesApplication *proxy; GSimpleActionGroup *actions; GCancellable *cancellable; @@ -66,7 +68,8 @@ application_free (gpointer data) if (!app) return; - g_clear_object (&app->info); + g_object_unref (app->info); + g_free (app->id); if (app->cancellable) { @@ -116,7 +119,7 @@ im_application_list_class_init (ImApplicationListClass *klass) g_cclosure_marshal_generic, G_TYPE_NONE, 4, - G_TYPE_DESKTOP_APP_INFO, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); @@ -129,7 +132,7 @@ im_application_list_class_init (ImApplicationListClass *klass) g_cclosure_marshal_generic, G_TYPE_NONE, 4, - G_TYPE_DESKTOP_APP_INFO, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); @@ -142,7 +145,7 @@ im_application_list_class_init (ImApplicationListClass *klass) g_cclosure_marshal_generic, G_TYPE_NONE, 2, - G_TYPE_DESKTOP_APP_INFO, + G_TYPE_STRING, G_TYPE_STRING); signals[MESSAGE_ADDED] = g_signal_new ("message-added", @@ -153,7 +156,7 @@ im_application_list_class_init (ImApplicationListClass *klass) g_cclosure_marshal_generic, G_TYPE_NONE, 8, - G_TYPE_DESKTOP_APP_INFO, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, @@ -170,7 +173,7 @@ im_application_list_class_init (ImApplicationListClass *klass) g_cclosure_marshal_generic, G_TYPE_NONE, 2, - G_TYPE_DESKTOP_APP_INFO, + G_TYPE_STRING, G_TYPE_STRING); signals[APP_STOPPED] = g_signal_new ("app-stopped", @@ -181,7 +184,7 @@ im_application_list_class_init (ImApplicationListClass *klass) g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, - G_TYPE_DESKTOP_APP_INFO); + G_TYPE_STRING); } static void @@ -197,6 +200,37 @@ im_application_list_new (void) return g_object_new (IM_TYPE_APPLICATION_LIST, NULL); } +static gchar * +im_application_list_canonical_id (const gchar *id) +{ + gchar *str; + gchar *p; + + str = g_strndup (id, strlen (id) - g_str_has_suffix (id, ".desktop") ? 7 : 0); + + for (p = str; *p; p++) + { + if (*p == '.') + *p = '_'; + } + + return str; +} + +static Application * +im_application_list_lookup (ImApplicationList *list, + const gchar *desktop_id) +{ + gchar *id; + Application *app; + + id = im_application_list_canonical_id (desktop_id); + app = g_hash_table_lookup (list->applications, id); + + g_free (id); + return app; +} + void im_application_list_add (ImApplicationList *list, const gchar *desktop_id) @@ -208,8 +242,7 @@ im_application_list_add (ImApplicationList *list, g_return_if_fail (IM_IS_APPLICATION_LIST (list)); g_return_if_fail (desktop_id != NULL); - app = g_hash_table_lookup (list->applications, desktop_id); - if (app) + if (im_application_list_lookup (list, desktop_id)) return; info = g_desktop_app_info_new (desktop_id); @@ -220,14 +253,16 @@ im_application_list_add (ImApplicationList *list, } id = g_app_info_get_id (G_APP_INFO (info)); + g_return_if_fail (id != NULL); app = g_slice_new0 (Application); - app->list = list; app->info = info; + app->id = im_application_list_canonical_id (id); + app->list = list; app->actions = g_simple_action_group_new (); - g_hash_table_insert (list->applications, (gpointer) id, app); - g_action_muxer_insert (list->muxer, id, G_ACTION_GROUP (app->actions)); + g_hash_table_insert (list->applications, (gpointer) app->id, app); + g_action_muxer_insert (list->muxer, app->id, G_ACTION_GROUP (app->actions)); } void @@ -238,11 +273,11 @@ im_application_list_remove (ImApplicationList *list, g_return_if_fail (IM_IS_APPLICATION_LIST (list)); - app = g_hash_table_lookup (list->applications, id); + app = im_application_list_lookup (list, id); if (app) { if (app->proxy || app->cancellable) - g_signal_emit (app->list, signals[APP_STOPPED], 0, app->info); + g_signal_emit (app->list, signals[APP_STOPPED], 0, app->id); g_hash_table_remove (list->applications, id); g_action_muxer_remove (list->muxer, id); @@ -271,7 +306,7 @@ im_application_list_source_added (Application *app, action = g_simple_action_new_stateful (id, NULL, state); g_simple_action_group_insert (app->actions, G_ACTION (action)); - g_signal_emit (app->list, signals[SOURCE_ADDED], 0, app->info, id, label, iconstr); + g_signal_emit (app->list, signals[SOURCE_ADDED], 0, app->id, id, label, iconstr); g_object_unref (action); } @@ -294,7 +329,7 @@ im_application_list_source_changed (Application *app, g_action_group_change_action_state (G_ACTION_GROUP (app->actions), id, g_variant_new ("(uxsb)", count, time, string, draws_attention)); - g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->info, id, label, iconstr); + g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->id, id, label, iconstr); } static void @@ -303,7 +338,7 @@ im_application_list_source_removed (Application *app, { g_simple_action_group_remove (app->actions, id); - g_signal_emit (app->list, signals[SOURCE_REMOVED], 0, app->info, id); + g_signal_emit (app->list, signals[SOURCE_REMOVED], 0, app->id, id); } static void @@ -349,16 +384,22 @@ im_application_list_message_added (Application *app, gint64 time; gboolean draws_attention; GSimpleAction *action; + GIcon *app_icon; + gchar *app_iconstr; g_variant_get (message, "(&s&s&s&s&sxb)", &id, &iconstr, &title, &subtitle, &body, &time, &draws_attention); + app_icon = g_app_info_get_icon (G_APP_INFO (app->info)); + app_iconstr = app_icon ? g_icon_to_string (app_icon) : NULL; + action = g_simple_action_new (id, NULL); g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (app->actions), G_ACTION (action)); g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, - app->info, id, iconstr, title, subtitle, body, time, draws_attention); + app->id, app_iconstr, id, iconstr, title, subtitle, body, time, draws_attention); + g_free (app_iconstr); g_object_unref (action); } @@ -368,7 +409,7 @@ im_application_list_message_removed (Application *app, { g_simple_action_group_remove (app->actions, id); - g_signal_emit (app->list, signals[MESSAGE_REMOVED], 0, app->info, id); + g_signal_emit (app->list, signals[MESSAGE_REMOVED], 0, app->id, id); } static void @@ -419,12 +460,10 @@ im_application_list_unset_remote (Application *app) * the muxer */ g_object_unref (app->actions); app->actions = g_simple_action_group_new (); - g_action_muxer_insert (app->list->muxer, - g_app_info_get_id (G_APP_INFO (app->info)), - G_ACTION_GROUP (app->actions)); + g_action_muxer_insert (app->list->muxer, app->id, G_ACTION_GROUP (app->actions)); if (was_running) - g_signal_emit (app->list, signals[APP_STOPPED], 0, app->info); + g_signal_emit (app->list, signals[APP_STOPPED], 0, app->id); } static void @@ -482,7 +521,7 @@ im_application_list_set_remote (ImApplicationList *list, g_return_if_fail (IM_IS_APPLICATION_LIST (list)); - app = g_hash_table_lookup (list->applications, id); + app = im_application_list_lookup (list, id); if (!app) { g_warning ("'%s' is not a registered application", id); diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index 9fd52df..65718be 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -113,7 +113,8 @@ im_phone_menu_get_model (ImPhoneMenu *menu) void im_phone_menu_add_message (ImPhoneMenu *menu, - GDesktopAppInfo *app, + const gchar *app_id, + const gchar *app_icon, const gchar *id, const gchar *iconstr, const gchar *title, @@ -121,15 +122,10 @@ im_phone_menu_add_message (ImPhoneMenu *menu, const gchar *body, gint64 time) { - const gchar *app_id; GMenuItem *item; gchar *action_name; - GIcon *app_icon; g_return_if_fail (IM_IS_PHONE_MENU (menu)); - g_return_if_fail (G_IS_DESKTOP_APP_INFO (app)); - - app_id = g_app_info_get_id (G_APP_INFO (app)); g_return_if_fail (app_id); action_name = g_strconcat (app_id, ".", id, NULL); @@ -144,16 +140,8 @@ im_phone_menu_add_message (ImPhoneMenu *menu, if (iconstr) g_menu_item_set_attribute (item, "x-canonical-icon", "s", iconstr); - app_icon = g_app_info_get_icon (G_APP_INFO (app)); if (app_icon) - { - gchar *app_iconstr; - - app_iconstr = g_icon_to_string (app_icon); - g_menu_item_set_attribute (item, "x-canonical-app-icon", "s", app_iconstr); - - g_free (app_iconstr); - } + g_menu_item_set_attribute (item, "x-canonical-app-icon", "s", app_icon); g_menu_append_item (menu->message_section, item); @@ -163,15 +151,15 @@ im_phone_menu_add_message (ImPhoneMenu *menu, void im_phone_menu_remove_message (ImPhoneMenu *menu, - GDesktopAppInfo *app, + const gchar *app_id, const gchar *id) { gchar *action_name; g_return_if_fail (IM_IS_PHONE_MENU (menu)); - g_return_if_fail (G_IS_DESKTOP_APP_INFO (app)); + g_return_if_fail (app_id != NULL); - action_name = g_strconcat (g_app_info_get_id (G_APP_INFO (app)), ".", id, NULL); + action_name = g_strconcat (app_id, ".", id, NULL); im_phone_menu_foreach_item_with_action (G_MENU_MODEL (menu->message_section), action_name, (ImMenuForeachFunc) g_menu_remove); @@ -181,7 +169,7 @@ im_phone_menu_remove_message (ImPhoneMenu *menu, void im_phone_menu_add_source (ImPhoneMenu *menu, - GDesktopAppInfo *app, + const gchar *app_id, const gchar *id, const gchar *label, const gchar *iconstr) @@ -190,9 +178,9 @@ im_phone_menu_add_source (ImPhoneMenu *menu, gchar *action_name; g_return_if_fail (IM_IS_PHONE_MENU (menu)); - g_return_if_fail (G_IS_DESKTOP_APP_INFO (app)); + g_return_if_fail (app_id != NULL); - action_name = g_strconcat (g_app_info_get_id (G_APP_INFO (app)), ".", id, NULL); + action_name = g_strconcat (app_id, ".", id, NULL); item = g_menu_item_new (label, action_name); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.sourceitem"); @@ -208,15 +196,15 @@ im_phone_menu_add_source (ImPhoneMenu *menu, void im_phone_menu_remove_source (ImPhoneMenu *menu, - GDesktopAppInfo *app, + const gchar *app_id, const gchar *id) { gchar *action_name; g_return_if_fail (IM_IS_PHONE_MENU (menu)); - g_return_if_fail (G_IS_DESKTOP_APP_INFO (app)); + g_return_if_fail (app_id != NULL); - action_name = g_strconcat (g_app_info_get_id (G_APP_INFO (app)), ".", id, NULL); + action_name = g_strconcat (app_id, ".", id, NULL); im_phone_menu_foreach_item_with_action (G_MENU_MODEL (menu->source_section), action_name, (ImMenuForeachFunc) g_menu_remove); @@ -226,13 +214,13 @@ im_phone_menu_remove_source (ImPhoneMenu *menu, static void im_phone_menu_remove_all_for_app (GMenu *menu, - GDesktopAppInfo *app) + const gchar *app_id) { gchar *prefix; gint n_items; gint i = 0; - prefix = g_strconcat (g_app_info_get_id (G_APP_INFO (app)), ".", NULL); + prefix = g_strconcat (app_id, ".", NULL); n_items = g_menu_model_get_n_items (G_MENU_MODEL (menu)); while (i < n_items) @@ -258,11 +246,11 @@ im_phone_menu_remove_all_for_app (GMenu *menu, void im_phone_menu_remove_application (ImPhoneMenu *menu, - GDesktopAppInfo *app) + const gchar *app_id) { g_return_if_fail (IM_IS_PHONE_MENU (menu)); - g_return_if_fail (G_IS_DESKTOP_APP_INFO (app)); + g_return_if_fail (app_id != NULL); - im_phone_menu_remove_all_for_app (menu->source_section, app); - im_phone_menu_remove_all_for_app (menu->message_section, app); + im_phone_menu_remove_all_for_app (menu->source_section, app_id); + im_phone_menu_remove_all_for_app (menu->message_section, app_id); } diff --git a/src/im-phone-menu.h b/src/im-phone-menu.h index b0b6b4f..f6a6118 100644 --- a/src/im-phone-menu.h +++ b/src/im-phone-menu.h @@ -21,7 +21,6 @@ #define __IM_PHONE_MENU_H__ #include -#include #define IM_TYPE_PHONE_MENU (im_phone_menu_get_type ()) #define IM_PHONE_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_TYPE_PHONE_MENU, ImPhoneMenu)) @@ -39,7 +38,8 @@ ImPhoneMenu * im_phone_menu_new (void); GMenuModel * im_phone_menu_get_model (ImPhoneMenu *menu); void im_phone_menu_add_message (ImPhoneMenu *menu, - GDesktopAppInfo *app, + const gchar *app_id, + const gchar *app_icon, const gchar *id, const gchar *iconstr, const gchar *title, @@ -48,20 +48,20 @@ void im_phone_menu_add_message (ImPhoneMenu *men gint64 time); void im_phone_menu_remove_message (ImPhoneMenu *menu, - GDesktopAppInfo *app, + const gchar *app_id, const gchar *id); void im_phone_menu_add_source (ImPhoneMenu *menu, - GDesktopAppInfo *app, + const gchar *app_id, const gchar *id, const gchar *label, const gchar *iconstr); void im_phone_menu_remove_source (ImPhoneMenu *menu, - GDesktopAppInfo *app, + const gchar *app_id, const gchar *id); -void im_phone_menu_remove_application (ImPhoneMenu *menu, - GDesktopAppInfo *app); +void im_phone_menu_remove_application (ImPhoneMenu *menu, + const gchar *app_id); #endif -- cgit v1.2.3 From 629b28e7f86d13eb78274c51a9164bdcac4e2cd7 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 26 Nov 2012 11:49:17 +0100 Subject: ImApplicationList: listen to activate signal --- src/im-application-list.c | 76 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 24df19e..dc8c146 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -86,6 +86,60 @@ application_free (gpointer data) g_slice_free (Application, app); } +static void +im_application_list_source_removed (Application *app, + const gchar *id) +{ + g_simple_action_group_remove (app->actions, id); + + g_signal_emit (app->list, signals[SOURCE_REMOVED], 0, app->id, id); +} + +static void +im_application_list_source_activated (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + Application *app = user_data; + const gchar *source_id; + + source_id = g_action_get_name (G_ACTION (action)); + + indicator_messages_application_call_activate_source (app->proxy, + source_id, + app->cancellable, + NULL, NULL); + + im_application_list_source_removed (app, source_id); +} + +static void +im_application_list_message_removed (Application *app, + const gchar *id) +{ + g_simple_action_group_remove (app->actions, id); + + g_signal_emit (app->list, signals[MESSAGE_REMOVED], 0, app->id, id); +} + +static void +im_application_list_message_activated (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + Application *app = user_data; + const gchar *message_id; + + message_id = g_action_get_name (G_ACTION (action)); + + indicator_messages_application_call_activate_message (app->proxy, + message_id, + app->cancellable, + NULL, NULL); + + im_application_list_message_removed (app, message_id); +} + static void im_application_list_dispose (GObject *object) { @@ -304,6 +358,8 @@ im_application_list_source_added (Application *app, state = g_variant_new ("(uxsb)", count, time, string, draws_attention); action = g_simple_action_new_stateful (id, NULL, state); + g_signal_connect (action, "activate", G_CALLBACK (im_application_list_source_activated), app); + g_simple_action_group_insert (app->actions, G_ACTION (action)); g_signal_emit (app->list, signals[SOURCE_ADDED], 0, app->id, id, label, iconstr); @@ -332,15 +388,6 @@ im_application_list_source_changed (Application *app, g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->id, id, label, iconstr); } -static void -im_application_list_source_removed (Application *app, - const gchar *id) -{ - g_simple_action_group_remove (app->actions, id); - - g_signal_emit (app->list, signals[SOURCE_REMOVED], 0, app->id, id); -} - static void im_application_list_sources_listed (GObject *source_object, GAsyncResult *result, @@ -394,6 +441,8 @@ im_application_list_message_added (Application *app, app_iconstr = app_icon ? g_icon_to_string (app_icon) : NULL; action = g_simple_action_new (id, NULL); + g_signal_connect (action, "activate", G_CALLBACK (im_application_list_message_activated), app); + g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (app->actions), G_ACTION (action)); g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, @@ -403,15 +452,6 @@ im_application_list_message_added (Application *app, g_object_unref (action); } -static void -im_application_list_message_removed (Application *app, - const gchar *id) -{ - g_simple_action_group_remove (app->actions, id); - - g_signal_emit (app->list, signals[MESSAGE_REMOVED], 0, app->id, id); -} - static void im_application_list_messages_listed (GObject *source_object, GAsyncResult *result, -- cgit v1.2.3 From eeb48cb2ecc059080ef6c079d1527eebe88da42f Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 26 Nov 2012 13:36:43 +0100 Subject: ImApplicationList: give message and source actions a boolean parameter The application will only be notified about the activation when this parameter is true. False denotes a dismissed item. --- src/im-application-list.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index dc8c146..644051f 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -105,10 +105,13 @@ im_application_list_source_activated (GSimpleAction *action, source_id = g_action_get_name (G_ACTION (action)); - indicator_messages_application_call_activate_source (app->proxy, - source_id, - app->cancellable, - NULL, NULL); + if (g_variant_get_boolean (parameter)) + { + indicator_messages_application_call_activate_source (app->proxy, + source_id, + app->cancellable, + NULL, NULL); + } im_application_list_source_removed (app, source_id); } @@ -132,10 +135,13 @@ im_application_list_message_activated (GSimpleAction *action, message_id = g_action_get_name (G_ACTION (action)); - indicator_messages_application_call_activate_message (app->proxy, - message_id, - app->cancellable, - NULL, NULL); + if (g_variant_get_boolean (parameter)) + { + indicator_messages_application_call_activate_message (app->proxy, + message_id, + app->cancellable, + NULL, NULL); + } im_application_list_message_removed (app, message_id); } @@ -357,7 +363,7 @@ im_application_list_source_added (Application *app, &id, &label, &iconstr, &count, &time, &string, &draws_attention); state = g_variant_new ("(uxsb)", count, time, string, draws_attention); - action = g_simple_action_new_stateful (id, NULL, state); + action = g_simple_action_new_stateful (id, G_VARIANT_TYPE_BOOLEAN, state); g_signal_connect (action, "activate", G_CALLBACK (im_application_list_source_activated), app); g_simple_action_group_insert (app->actions, G_ACTION (action)); @@ -440,7 +446,7 @@ im_application_list_message_added (Application *app, app_icon = g_app_info_get_icon (G_APP_INFO (app->info)); app_iconstr = app_icon ? g_icon_to_string (app_icon) : NULL; - action = g_simple_action_new (id, NULL); + action = g_simple_action_new (id, G_VARIANT_TYPE_BOOLEAN); g_signal_connect (action, "activate", G_CALLBACK (im_application_list_message_activated), app); g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (app->actions), G_ACTION (action)); -- cgit v1.2.3 From 76da35f3747a9efaa509d54d92b5511e6a0b69d0 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 26 Nov 2012 16:15:55 +0100 Subject: Namespace actions with 'src' and 'msg' for sources and messages --- src/im-application-list.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 644051f..71100d4 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -56,7 +56,9 @@ typedef struct GDesktopAppInfo *info; gchar *id; IndicatorMessagesApplication *proxy; - GSimpleActionGroup *actions; + GActionMuxer *actions; + GSimpleActionGroup *source_actions; + GSimpleActionGroup *message_actions; GCancellable *cancellable; } Application; @@ -81,7 +83,11 @@ application_free (gpointer data) g_object_unref (app->proxy); if (app->actions) - g_object_unref (app->actions); + { + g_object_unref (app->actions); + g_object_unref (app->source_actions); + g_object_unref (app->message_actions); + } g_slice_free (Application, app); } @@ -90,7 +96,7 @@ static void im_application_list_source_removed (Application *app, const gchar *id) { - g_simple_action_group_remove (app->actions, id); + g_simple_action_group_remove (app->source_actions, id); g_signal_emit (app->list, signals[SOURCE_REMOVED], 0, app->id, id); } @@ -120,7 +126,7 @@ static void im_application_list_message_removed (Application *app, const gchar *id) { - g_simple_action_group_remove (app->actions, id); + g_simple_action_group_remove (app->message_actions, id); g_signal_emit (app->list, signals[MESSAGE_REMOVED], 0, app->id, id); } @@ -319,7 +325,12 @@ im_application_list_add (ImApplicationList *list, app->info = info; app->id = im_application_list_canonical_id (id); app->list = list; - app->actions = g_simple_action_group_new (); + app->actions = g_action_muxer_new (); + app->source_actions = g_simple_action_group_new (); + app->message_actions = g_simple_action_group_new (); + + g_action_muxer_insert (app->actions, "src", G_ACTION_GROUP (app->source_actions)); + g_action_muxer_insert (app->actions, "msg", G_ACTION_GROUP (app->message_actions)); g_hash_table_insert (list->applications, (gpointer) app->id, app); g_action_muxer_insert (list->muxer, app->id, G_ACTION_GROUP (app->actions)); @@ -366,7 +377,7 @@ im_application_list_source_added (Application *app, action = g_simple_action_new_stateful (id, G_VARIANT_TYPE_BOOLEAN, state); g_signal_connect (action, "activate", G_CALLBACK (im_application_list_source_activated), app); - g_simple_action_group_insert (app->actions, G_ACTION (action)); + g_simple_action_group_insert (app->source_actions, G_ACTION (action)); g_signal_emit (app->list, signals[SOURCE_ADDED], 0, app->id, id, label, iconstr); @@ -388,7 +399,7 @@ im_application_list_source_changed (Application *app, g_variant_get (source, "(&s&s&sux&sb)", &id, &label, &iconstr, &count, &time, &string, &draws_attention); - g_action_group_change_action_state (G_ACTION_GROUP (app->actions), id, + g_action_group_change_action_state (G_ACTION_GROUP (app->source_actions), id, g_variant_new ("(uxsb)", count, time, string, draws_attention)); g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->id, id, label, iconstr); @@ -449,7 +460,7 @@ im_application_list_message_added (Application *app, action = g_simple_action_new (id, G_VARIANT_TYPE_BOOLEAN); g_signal_connect (action, "activate", G_CALLBACK (im_application_list_message_activated), app); - g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (app->actions), G_ACTION (action)); + g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (app->message_actions), G_ACTION (action)); g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, app->id, app_iconstr, id, iconstr, title, subtitle, body, time, draws_attention); @@ -504,9 +515,12 @@ im_application_list_unset_remote (Application *app) /* clear actions by creating a new action group and overriding it in * the muxer */ - g_object_unref (app->actions); - app->actions = g_simple_action_group_new (); - g_action_muxer_insert (app->list->muxer, app->id, G_ACTION_GROUP (app->actions)); + g_object_unref (app->source_actions); + g_object_unref (app->message_actions); + app->source_actions = g_simple_action_group_new (); + app->message_actions = g_simple_action_group_new (); + g_action_muxer_insert (app->actions, "src", G_ACTION_GROUP (app->source_actions)); + g_action_muxer_insert (app->actions, "msg", G_ACTION_GROUP (app->message_actions)); if (was_running) g_signal_emit (app->list, signals[APP_STOPPED], 0, app->id); -- cgit v1.2.3 From f758143a4c818e23b2e410d5bf63305c84a07590 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 26 Nov 2012 16:26:25 +0100 Subject: Add "Clear All" --- src/im-application-list.c | 44 +++++++++++++++++++++++++++++++++++++++++++- src/im-phone-menu.c | 8 ++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 71100d4..c3be647 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -152,6 +152,33 @@ im_application_list_message_activated (GSimpleAction *action, im_application_list_message_removed (app, message_id); } +static void +im_application_list_remove_all (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + ImApplicationList *list = user_data; + GHashTableIter iter; + Application *app; + + g_hash_table_iter_init (&iter, list->applications); + while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &app)) + { + gchar **actions; + gchar **it; + + actions = g_action_group_list_actions (G_ACTION_GROUP (app->source_actions)); + for (it = actions; *it; it++) + im_application_list_source_removed (app, *it); + g_strfreev (actions); + + actions = g_action_group_list_actions (G_ACTION_GROUP (app->message_actions)); + for (it = actions; *it; it++) + im_application_list_message_removed (app, *it); + g_strfreev (actions); + } +} + static void im_application_list_dispose (GObject *object) { @@ -256,8 +283,23 @@ im_application_list_class_init (ImApplicationListClass *klass) static void im_application_list_init (ImApplicationList *list) { + GSimpleActionGroup *actions; + GSimpleAction *remove_all_action; + list->applications = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, application_free); list->muxer = g_action_muxer_new (); + + actions = g_simple_action_group_new (); + + remove_all_action = g_simple_action_new ("remove-all", NULL); + g_signal_connect (remove_all_action, "activate", G_CALLBACK (im_application_list_remove_all), list); + + g_simple_action_group_insert (actions, G_ACTION (remove_all_action)); + + g_action_muxer_insert (list->muxer, NULL, G_ACTION_GROUP (actions)); + + g_object_unref (remove_all_action); + g_object_unref (actions); } ImApplicationList * @@ -460,7 +502,7 @@ im_application_list_message_added (Application *app, action = g_simple_action_new (id, G_VARIANT_TYPE_BOOLEAN); g_signal_connect (action, "activate", G_CALLBACK (im_application_list_message_activated), app); - g_simple_action_group_insert (G_SIMPLE_ACTION_GROUP (app->message_actions), G_ACTION (action)); + g_simple_action_group_insert (app->message_actions, G_ACTION (action)); g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, app->id, app_iconstr, id, iconstr, title, subtitle, body, time, draws_attention); diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index 65718be..f1a5074 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -89,12 +89,20 @@ im_phone_menu_class_init (ImPhoneMenuClass *klass) static void im_phone_menu_init (ImPhoneMenu *menu) { + GMenuItem *item; + menu->message_section = g_menu_new (); menu->source_section = g_menu_new (); menu->toplevel_menu = g_menu_new (); g_menu_append_section (menu->toplevel_menu, NULL, G_MENU_MODEL (menu->message_section)); g_menu_append_section (menu->toplevel_menu, NULL, G_MENU_MODEL (menu->source_section)); + + item = g_menu_item_new ("Clear All", "remove-all"); + g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.button"); + g_menu_append_item (menu->toplevel_menu, item); + + g_object_unref (item); } ImPhoneMenu * -- cgit v1.2.3 From abdb9c6e7bd033e8a9aa29a467e9f2e69cb6af2b Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 26 Nov 2012 17:10:04 +0100 Subject: Remove sections and "Clear All" when no sources or messages are available --- src/im-phone-menu.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index f1a5074..7842920 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -59,6 +59,33 @@ im_phone_menu_foreach_item_with_action (GMenuModel *menu, } } +static void +im_phone_menu_update_toplevel (ImPhoneMenu *menu) +{ + if (g_menu_model_get_n_items (G_MENU_MODEL (menu->message_section)) || + g_menu_model_get_n_items (G_MENU_MODEL (menu->source_section))) + { + if (g_menu_model_get_n_items (G_MENU_MODEL (menu->toplevel_menu)) == 0) + { + GMenuItem *item; + + g_menu_append_section (menu->toplevel_menu, NULL, G_MENU_MODEL (menu->message_section)); + g_menu_append_section (menu->toplevel_menu, NULL, G_MENU_MODEL (menu->source_section)); + + item = g_menu_item_new ("Clear All", "remove-all"); + g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.button"); + g_menu_append_item (menu->toplevel_menu, item); + + g_object_unref (item); + } + } + else + { + while (g_menu_model_get_n_items (G_MENU_MODEL (menu->toplevel_menu))) + g_menu_remove (menu->toplevel_menu, 0); + } +} + static void im_phone_menu_dispose (GObject *object) { @@ -89,20 +116,16 @@ im_phone_menu_class_init (ImPhoneMenuClass *klass) static void im_phone_menu_init (ImPhoneMenu *menu) { - GMenuItem *item; - + menu->toplevel_menu = g_menu_new (); menu->message_section = g_menu_new (); menu->source_section = g_menu_new (); - menu->toplevel_menu = g_menu_new (); - g_menu_append_section (menu->toplevel_menu, NULL, G_MENU_MODEL (menu->message_section)); - g_menu_append_section (menu->toplevel_menu, NULL, G_MENU_MODEL (menu->source_section)); - - item = g_menu_item_new ("Clear All", "remove-all"); - g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.button"); - g_menu_append_item (menu->toplevel_menu, item); + g_signal_connect_swapped (menu->message_section, "items-changed", + G_CALLBACK (im_phone_menu_update_toplevel), menu); + g_signal_connect_swapped (menu->source_section, "items-changed", + G_CALLBACK (im_phone_menu_update_toplevel), menu); - g_object_unref (item); + im_phone_menu_update_toplevel (menu); } ImPhoneMenu * -- cgit v1.2.3 From b2c6b50cdfc1cc9a288516cef102ad2943b0e950 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 26 Nov 2012 20:06:47 +0100 Subject: Use namespaced action names (src. and msg.) in phone menu --- src/im-phone-menu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index 7842920..728c08b 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -159,7 +159,7 @@ im_phone_menu_add_message (ImPhoneMenu *menu, g_return_if_fail (IM_IS_PHONE_MENU (menu)); g_return_if_fail (app_id); - action_name = g_strconcat (app_id, ".", id, NULL); + action_name = g_strconcat (app_id, ".msg.", id, NULL); item = g_menu_item_new (title, action_name); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.messageitem"); @@ -190,7 +190,7 @@ im_phone_menu_remove_message (ImPhoneMenu *menu, g_return_if_fail (IM_IS_PHONE_MENU (menu)); g_return_if_fail (app_id != NULL); - action_name = g_strconcat (app_id, ".", id, NULL); + action_name = g_strconcat (app_id, ".msg.", id, NULL); im_phone_menu_foreach_item_with_action (G_MENU_MODEL (menu->message_section), action_name, (ImMenuForeachFunc) g_menu_remove); @@ -211,7 +211,7 @@ im_phone_menu_add_source (ImPhoneMenu *menu, g_return_if_fail (IM_IS_PHONE_MENU (menu)); g_return_if_fail (app_id != NULL); - action_name = g_strconcat (app_id, ".", id, NULL); + action_name = g_strconcat (app_id, ".src.", id, NULL); item = g_menu_item_new (label, action_name); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.sourceitem"); @@ -235,7 +235,7 @@ im_phone_menu_remove_source (ImPhoneMenu *menu, g_return_if_fail (IM_IS_PHONE_MENU (menu)); g_return_if_fail (app_id != NULL); - action_name = g_strconcat (app_id, ".", id, NULL); + action_name = g_strconcat (app_id, ".src.", id, NULL); im_phone_menu_foreach_item_with_action (G_MENU_MODEL (menu->source_section), action_name, (ImMenuForeachFunc) g_menu_remove); -- cgit v1.2.3 From 9287c2e6577e71d8f68d9c9e7d393a4f8524ab10 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 26 Nov 2012 20:12:13 +0100 Subject: Tell applications when messages and sources are dismissed Right now, this is only used to clean up internal data structures in libmessaging-menu. It's not exposed to the application itself. --- ...om.canonical.indicator.messages.application.xml | 4 +++ libmessaging-menu/messaging-menu-app.c | 21 +++++++++++++ src/im-application-list.c | 35 +++++++++++++++++----- 3 files changed, 53 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/common/com.canonical.indicator.messages.application.xml b/common/com.canonical.indicator.messages.application.xml index fb9f079..552b6a4 100644 --- a/common/com.canonical.indicator.messages.application.xml +++ b/common/com.canonical.indicator.messages.application.xml @@ -13,6 +13,10 @@ + + + + diff --git a/libmessaging-menu/messaging-menu-app.c b/libmessaging-menu/messaging-menu-app.c index 61547c5..d037da9 100644 --- a/libmessaging-menu/messaging-menu-app.c +++ b/libmessaging-menu/messaging-menu-app.c @@ -607,6 +607,25 @@ messaging_menu_app_activate_message (IndicatorMessagesApplication *app_interface return TRUE; } +static gboolean +messaging_menu_app_dismiss (IndicatorMessagesApplication *app_interface, + GDBusMethodInvocation *invocation, + const gchar * const *sources, + const gchar * const *messages, + gpointer user_data) +{ + MessagingMenuApp *app = user_data; + const gchar * const *it; + + for (it = sources; *it; it++) + messaging_menu_app_remove_source_internal (app, *it); + + for (it = messages; *it; it++) + messaging_menu_app_remove_message_internal (app, *it); + + return TRUE; +} + static void messaging_menu_app_init (MessagingMenuApp *app) { @@ -625,6 +644,8 @@ messaging_menu_app_init (MessagingMenuApp *app) G_CALLBACK (messaging_menu_app_list_messages), app); g_signal_connect (app->app_interface, "handle-activate-message", G_CALLBACK (messaging_menu_app_activate_message), app); + g_signal_connect (app->app_interface, "handle-dismiss", + G_CALLBACK (messaging_menu_app_dismiss), app); app->messages = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); diff --git a/src/im-application-list.c b/src/im-application-list.c index c3be647..d766f24 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -118,6 +118,13 @@ im_application_list_source_activated (GSimpleAction *action, app->cancellable, NULL, NULL); } + else + { + const gchar *sources[] = { source_id, NULL }; + const gchar *messages[] = { NULL }; + indicator_messages_application_call_dismiss (app->proxy, sources, messages, + app->cancellable, NULL, NULL); + } im_application_list_source_removed (app, source_id); } @@ -148,6 +155,13 @@ im_application_list_message_activated (GSimpleAction *action, app->cancellable, NULL, NULL); } + else + { + const gchar *sources[] = { NULL }; + const gchar *messages[] = { message_id, NULL }; + indicator_messages_application_call_dismiss (app->proxy, sources, messages, + app->cancellable, NULL, NULL); + } im_application_list_message_removed (app, message_id); } @@ -164,18 +178,25 @@ im_application_list_remove_all (GSimpleAction *action, g_hash_table_iter_init (&iter, list->applications); while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &app)) { - gchar **actions; + gchar **source_actions; + gchar **message_actions; gchar **it; - actions = g_action_group_list_actions (G_ACTION_GROUP (app->source_actions)); - for (it = actions; *it; it++) + source_actions = g_action_group_list_actions (G_ACTION_GROUP (app->source_actions)); + for (it = source_actions; *it; it++) im_application_list_source_removed (app, *it); - g_strfreev (actions); - actions = g_action_group_list_actions (G_ACTION_GROUP (app->message_actions)); - for (it = actions; *it; it++) + message_actions = g_action_group_list_actions (G_ACTION_GROUP (app->message_actions)); + for (it = message_actions; *it; it++) im_application_list_message_removed (app, *it); - g_strfreev (actions); + + indicator_messages_application_call_dismiss (app->proxy, + (const gchar * const *) source_actions, + (const gchar * const *) message_actions, + app->cancellable, NULL, NULL); + + g_strfreev (source_actions); + g_strfreev (message_actions); } } -- cgit v1.2.3 From e8e99703ef0c565f07a9d1eba03c1003d82ff697 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 27 Nov 2012 15:14:26 +0100 Subject: Allow adding actions to MessagingMenuMessage --- ...om.canonical.indicator.messages.application.xml | 4 +- libmessaging-menu/messaging-menu-app.c | 28 +--- libmessaging-menu/messaging-menu-message.c | 160 +++++++++++++++++++++ libmessaging-menu/messaging-menu-message.h | 6 + src/im-application-list.c | 6 +- 5 files changed, 176 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/common/com.canonical.indicator.messages.application.xml b/common/com.canonical.indicator.messages.application.xml index 552b6a4..f37cd25 100644 --- a/common/com.canonical.indicator.messages.application.xml +++ b/common/com.canonical.indicator.messages.application.xml @@ -5,7 +5,7 @@ - + @@ -28,7 +28,7 @@ - + diff --git a/libmessaging-menu/messaging-menu-app.c b/libmessaging-menu/messaging-menu-app.c index d037da9..491c123 100644 --- a/libmessaging-menu/messaging-menu-app.c +++ b/libmessaging-menu/messaging-menu-app.c @@ -152,6 +152,9 @@ static void global_status_changed (IndicatorMessagesService *service, const gchar *status_str, gpointer user_data); +/* in messaging-menu-message.c */ +GVariant * messaging_menu_message_to_variant (MessagingMenuMessage *msg); + static void source_free (gpointer data) { @@ -188,29 +191,6 @@ source_to_variant (Source *source) return v; } -static GVariant * -messaging_menu_message_to_variant (MessagingMenuMessage *message) -{ - GVariant *v; - GIcon *icon; - gchar *iconstr; - - icon = messaging_menu_message_get_icon (message); - iconstr = icon ? g_icon_to_string (icon) : NULL; - - v = g_variant_new ("(sssssxb)", messaging_menu_message_get_id (message), - iconstr ? iconstr : "", - messaging_menu_message_get_title (message), - messaging_menu_message_get_subtitle (message), - messaging_menu_message_get_body (message), - messaging_menu_message_get_time (message), - messaging_menu_message_get_draws_attention (message)); - - g_free (iconstr); - - return v; -} - static gchar * messaging_menu_app_get_dbus_object_path (MessagingMenuApp *app) { @@ -571,7 +551,7 @@ messaging_menu_app_list_messages (IndicatorMessagesApplication *app_interface, GHashTableIter iter; MessagingMenuMessage *message; - g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(sssssxb)")); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(sssssxa(ssgav)b)")); g_hash_table_iter_init (&iter, app->messages); while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &message)) diff --git a/libmessaging-menu/messaging-menu-message.c b/libmessaging-menu/messaging-menu-message.c index f5cb18c..cf050d3 100644 --- a/libmessaging-menu/messaging-menu-message.c +++ b/libmessaging-menu/messaging-menu-message.c @@ -32,6 +32,8 @@ struct _MessagingMenuMessage gchar *body; gint64 time; gboolean draws_attention; + + GSList *actions; }; G_DEFINE_TYPE (MessagingMenuMessage, messaging_menu_message, G_TYPE_OBJECT); @@ -51,6 +53,31 @@ enum static GParamSpec *properties[NUM_PROPERTIES]; +typedef struct +{ + gchar *id; + gchar *label; + GVariantType *parameter_type; + GVariant *parameter_hint; +} Action; + +static void +action_free (gpointer data) +{ + Action *action = data; + + g_free (action->id); + g_free (action->label); + + if (action->parameter_type) + g_variant_type_free (action->parameter_type); + + if (action->parameter_hint) + g_variant_unref (action->parameter_hint); + + g_slice_free (Action, action); +} + static void messaging_menu_message_dispose (GObject *object) { @@ -71,6 +98,9 @@ messaging_menu_message_finalize (GObject *object) g_free (msg->subtitle); g_free (msg->body); + g_slist_free_full (msg->actions, action_free); + msg->actions = NULL; + G_OBJECT_CLASS (messaging_menu_message_parent_class)->finalize (object); } @@ -370,3 +400,133 @@ messaging_menu_message_set_draws_attention (MessagingMenuMessage *msg, msg->draws_attention = draws_attention; g_object_notify_by_pspec (G_OBJECT (msg), properties[PROP_DRAWS_ATTENTION]); } + +/** + * messaging_menu_message_add_action: + * @msg: a #MessagingMenuMessage + * @id: unique id of the action + * @label: (allow-none): label of the action + * @parameter_type: (allow-none): a #GVariantType + * @parameter_hint: (allow-none): a #GVariant suggesting a valid range + * for parameters + * + * Adds an action with @id and @label to @message. Actions are an + * alternative way for users to activate a message. Note that messages + * can still be activated without an action. + * + * If @parameter_type is non-%NULL, the action is able to receive user + * input in addition to simply activating the action. Currently, only + * string parameters are supported. + * + * A list of predefined parameters can be supplied as a #GVariant array + * of @parameter_type in @parameter_hint. If @parameter_hint is + * floating, it will be consumed. + * + * It is recommended to add at most two actions to a message. + */ +void +messaging_menu_message_add_action (MessagingMenuMessage *msg, + const gchar *id, + const gchar *label, + const GVariantType *parameter_type, + GVariant *parameter_hint) +{ + Action *action; + + g_return_if_fail (MESSAGING_MENU_IS_MESSAGE (msg)); + g_return_if_fail (id != NULL); + + action = g_slice_new (Action); + action->id = g_strdup (id); + action->label = g_strdup (label); + action->parameter_type = parameter_type ? g_variant_type_copy (parameter_type) : NULL; + action->parameter_hint = parameter_hint ? g_variant_ref_sink (parameter_hint) : NULL; + + msg->actions = g_slist_append (msg->actions, action); +} + +static GVariant * +action_to_variant (Action *action) +{ + GVariantBuilder builder; + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("(ssgav)")); + + g_variant_builder_add (&builder, "s", action->id); + g_variant_builder_add (&builder, "s", action->label ? action->label : ""); + + if (action->parameter_type) + { + gchar *type = g_variant_type_dup_string (action->parameter_type); + g_variant_builder_add (&builder, "g", type); + g_free (type); + } + else + g_variant_builder_add (&builder, "g", ""); + + g_variant_builder_open (&builder, G_VARIANT_TYPE ("av")); + if (action->parameter_hint) + g_variant_builder_add (&builder, "v", action->parameter_hint); + g_variant_builder_close (&builder); + + return g_variant_builder_end (&builder); +} + +/* + * messaging_menu_message_to_variant: + * @msg: a #MessagingMenuMessage + * + * Serializes @msg to a #GVariant of the form (sssssxa(ssgav)b): + * + * id + * icon + * title + * subtitle + * body + * time + * array of actions: id + * label + * parameter_type + * parameter_hint (0 or 1 elements) + * draws_attention + * + * Returns: a new floating #GVariant instance + */ +GVariant * +messaging_menu_message_to_variant (MessagingMenuMessage *msg) +{ + GVariantBuilder builder; + GSList *it; + + g_return_val_if_fail (MESSAGING_MENU_IS_MESSAGE (msg), NULL); + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("(sssssxa(ssgav)b)")); + + g_variant_builder_add (&builder, "s", msg->id); + + if (msg->icon) + { + gchar *iconstr; + + iconstr = g_icon_to_string (msg->icon); + g_variant_builder_add (&builder, "s", iconstr); + + g_free (iconstr); + } + else + g_variant_builder_add (&builder, "s", ""); + + g_variant_builder_add (&builder, "s", msg->title ? msg->title : ""); + g_variant_builder_add (&builder, "s", msg->subtitle ? msg->subtitle : ""); + g_variant_builder_add (&builder, "s", msg->body ? msg->body : ""); + g_variant_builder_add (&builder, "x", msg->time); + + g_variant_builder_open (&builder, G_VARIANT_TYPE ("a(ssgav)")); + for (it = msg->actions; it; it = it->next) + g_variant_builder_add_value (&builder, action_to_variant (it->data)); + g_variant_builder_close (&builder); + + g_variant_builder_add (&builder, "b", msg->draws_attention); + + return g_variant_builder_end (&builder); +} diff --git a/libmessaging-menu/messaging-menu-message.h b/libmessaging-menu/messaging-menu-message.h index 068247b..4708246 100644 --- a/libmessaging-menu/messaging-menu-message.h +++ b/libmessaging-menu/messaging-menu-message.h @@ -59,6 +59,12 @@ gboolean messaging_menu_message_get_draws_attention (MessagingMe void messaging_menu_message_set_draws_attention (MessagingMenuMessage *msg, gboolean draws_attention); +void messaging_menu_message_add_action (MessagingMenuMessage *msg, + const gchar *id, + const gchar *label, + const GVariantType *parameter_type, + GVariant *parameter_hint); + G_END_DECLS #endif diff --git a/src/im-application-list.c b/src/im-application-list.c index d766f24..4eaaed0 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -509,13 +509,14 @@ im_application_list_message_added (Application *app, const gchar *subtitle; const gchar *body; gint64 time; + GVariantIter *action_iter; gboolean draws_attention; GSimpleAction *action; GIcon *app_icon; gchar *app_iconstr; - g_variant_get (message, "(&s&s&s&s&sxb)", - &id, &iconstr, &title, &subtitle, &body, &time, &draws_attention); + g_variant_get (message, "(&s&s&s&s&sxa(ssgav)b)", + &id, &iconstr, &title, &subtitle, &body, &time, &action_iter, &draws_attention); app_icon = g_app_info_get_icon (G_APP_INFO (app->info)); app_iconstr = app_icon ? g_icon_to_string (app_icon) : NULL; @@ -528,6 +529,7 @@ im_application_list_message_added (Application *app, g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, app->id, app_iconstr, id, iconstr, title, subtitle, body, time, draws_attention); + g_variant_iter_free (action_iter); g_free (app_iconstr); g_object_unref (action); } -- cgit v1.2.3 From ced173aa7ea78c76922e07c84743d5b7f76c265e Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 27 Nov 2012 16:40:38 +0100 Subject: Pass message action and its parameter through to the application --- ...om.canonical.indicator.messages.application.xml | 2 ++ libmessaging-menu/messaging-menu-app.c | 23 +++++++++++++++++++++- src/im-application-list.c | 2 ++ 3 files changed, 26 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/common/com.canonical.indicator.messages.application.xml b/common/com.canonical.indicator.messages.application.xml index f37cd25..5e99780 100644 --- a/common/com.canonical.indicator.messages.application.xml +++ b/common/com.canonical.indicator.messages.application.xml @@ -12,6 +12,8 @@ + + diff --git a/libmessaging-menu/messaging-menu-app.c b/libmessaging-menu/messaging-menu-app.c index cea0eb9..8b9f76b 100644 --- a/libmessaging-menu/messaging-menu-app.c +++ b/libmessaging-menu/messaging-menu-app.c @@ -546,6 +546,8 @@ static gboolean messaging_menu_app_activate_message (IndicatorMessagesApplication *app_interface, GDBusMethodInvocation *invocation, const gchar *message_id, + const gchar *action_id, + GVariant *params, gpointer user_data) { MessagingMenuApp *app = user_data; @@ -554,7 +556,26 @@ messaging_menu_app_activate_message (IndicatorMessagesApplication *app_interface msg = g_hash_table_lookup (app->messages, message_id); if (msg) { - g_signal_emit_by_name (msg, "activate", NULL, NULL); + if (*action_id) + { + gchar *signal; + + signal = g_strconcat ("activate::", action_id, NULL); + + if (g_variant_n_children (params)) + { + GVariant *param = g_variant_get_child_value (params, 0); + g_signal_emit_by_name (msg, signal, action_id, param); + g_variant_unref (param); + } + else + g_signal_emit_by_name (msg, signal, action_id, NULL); + + g_free (signal); + } + else + g_signal_emit_by_name (msg, "activate", NULL, NULL); + /* Activate implies removing the message, no need for MessageRemoved */ messaging_menu_app_remove_message_internal (app, message_id); diff --git a/src/im-application-list.c b/src/im-application-list.c index 4eaaed0..7c53e69 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -152,6 +152,8 @@ im_application_list_message_activated (GSimpleAction *action, { indicator_messages_application_call_activate_message (app->proxy, message_id, + "", + g_variant_new_array (G_VARIANT_TYPE_VARIANT, NULL, 0), app->cancellable, NULL, NULL); } -- cgit v1.2.3 From 83598a9e4fe059703faa806e7a9cdab1e6cb293c Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 28 Nov 2012 13:29:15 +0100 Subject: Add root menu item The action for that root item lives in ImApplicationList for now, because it owns the action group (which should probably factored into its own class at some point). --- src/im-application-list.c | 15 +++++++-------- src/messages-service.c | 8 ++++++-- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index d766f24..c5e34b7 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -304,22 +304,21 @@ im_application_list_class_init (ImApplicationListClass *klass) static void im_application_list_init (ImApplicationList *list) { + const GActionEntry action_entries[] = { + { "messages", NULL, NULL, "('', 'indicator-messages', 'Messages', true)", NULL }, + { "remove-all", im_application_list_remove_all } + }; + GSimpleActionGroup *actions; - GSimpleAction *remove_all_action; list->applications = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, application_free); - list->muxer = g_action_muxer_new (); actions = g_simple_action_group_new (); + g_simple_action_group_add_entries (actions, action_entries, G_N_ELEMENTS (action_entries), list); - remove_all_action = g_simple_action_new ("remove-all", NULL); - g_signal_connect (remove_all_action, "activate", G_CALLBACK (im_application_list_remove_all), list); - - g_simple_action_group_insert (actions, G_ACTION (remove_all_action)); - + list->muxer = g_action_muxer_new (); g_action_muxer_insert (list->muxer, NULL, G_ACTION_GROUP (actions)); - g_object_unref (remove_all_action); g_object_unref (actions); } diff --git a/src/messages-service.c b/src/messages-service.c index b3731a8..62abc81 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -200,7 +200,7 @@ got_bus (GObject *object, } g_dbus_connection_export_menu_model (bus, INDICATOR_MESSAGES_DBUS_OBJECT "/phone", - im_phone_menu_get_model (menu), &error); + G_MENU_MODEL (toplevel_menu), &error); if (error) { g_warning ("unable to export menu on dbus: %s", error->message); g_error_free (error); @@ -224,6 +224,7 @@ main (int argc, char ** argv) { GMainLoop * mainloop = NULL; IndicatorService * service = NULL; + GMenuItem *root; /* Glib init */ g_type_init(); @@ -255,7 +256,9 @@ main (int argc, char ** argv) menu = im_phone_menu_new (); toplevel_menu = g_menu_new (); - g_menu_append_submenu (toplevel_menu, NULL, im_phone_menu_get_model (menu)); + root = g_menu_item_new (NULL, "messages"); + g_menu_item_set_submenu (root, im_phone_menu_get_model (menu)); + g_menu_append_item (toplevel_menu, root); settings = g_settings_new ("com.canonical.indicator.messages"); @@ -274,6 +277,7 @@ main (int argc, char ** argv) g_main_loop_run(mainloop); /* Clean up */ + g_object_unref (root); g_object_unref (messages_service); g_object_unref (settings); g_object_unref (applications); -- cgit v1.2.3 From 8ff464d1a1d99e016b4719f090816c2c6f712abb Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 28 Nov 2012 13:42:34 +0100 Subject: messages-service.c: remove chat status action It isn't used right now (the action group wasn't even exported on the bus) and would need to be refactored anyway once chat status is added back in. --- src/messages-service.c | 91 -------------------------------------------------- 1 file changed, 91 deletions(-) (limited to 'src') diff --git a/src/messages-service.c b/src/messages-service.c index 62abc81..6b8f26b 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -40,45 +40,9 @@ with this program. If not, see . static ImApplicationList *applications; static IndicatorMessagesService *messages_service; -static GSimpleActionGroup *actions; static GMenu *toplevel_menu; static ImPhoneMenu *menu; static GSettings *settings; -static gboolean draws_attention; -static const gchar *global_status[6]; /* max 5: available, away, busy, invisible, offline */ - -static gchar * -indicator_messages_get_icon_name () -{ - GString *name; - GIcon *icon; - gchar *iconstr; - - name = g_string_new ("indicator-messages"); - - if (global_status[0] != NULL) - { - if (global_status[1] != NULL) - g_string_append (name, "-mixed"); - else - g_string_append_printf (name, "-%s", global_status[0]); - } - - if (draws_attention) - g_string_append (name, "-new"); - - icon = g_themed_icon_new (name->str); - g_themed_icon_append_name (G_THEMED_ICON (icon), - draws_attention ? "indicator-messages-new" - : "indicator-messages"); - - iconstr = g_icon_to_string (icon); - - g_object_unref (icon); - g_string_free (name, TRUE); - - return iconstr; -} static void service_shutdown (IndicatorService * service, gpointer user_data) @@ -89,26 +53,6 @@ service_shutdown (IndicatorService * service, gpointer user_data) g_main_loop_quit(mainloop); } -static void -clear_action_activate (GSimpleAction *simple, - GVariant *param, - gpointer user_data) -{ - /* TODO */ -} - -static void -status_action_activate (GSimpleAction *action, - GVariant *parameter, - gpointer user_data) -{ - const gchar *status; - - status = g_variant_get_string (parameter, NULL); - - indicator_messages_service_emit_status_changed (messages_service, status); -} - static void register_application (IndicatorMessagesService *service, GDBusMethodInvocation *invocation, @@ -142,39 +86,6 @@ unregister_application (IndicatorMessagesService *service, indicator_messages_service_complete_unregister_application (service, invocation); } -static GSimpleActionGroup * -create_action_group (void) -{ - GSimpleActionGroup *actions; - GSimpleAction *messages; - GSimpleAction *clear; - GSimpleAction *status; - const gchar *default_status[] = { "offline", NULL }; - gchar *icon; - - actions = g_simple_action_group_new (); - - /* state of the messages action is its icon name */ - icon = indicator_messages_get_icon_name (); - messages = g_simple_action_new_stateful ("messages", G_VARIANT_TYPE ("s"), - g_variant_new_string (icon)); - - status = g_simple_action_new_stateful ("status", G_VARIANT_TYPE ("s"), - g_variant_new_strv (default_status, -1)); - g_signal_connect (status, "activate", G_CALLBACK (status_action_activate), NULL); - - clear = g_simple_action_new ("clear", NULL); - g_simple_action_set_enabled (clear, FALSE); - g_signal_connect (clear, "activate", G_CALLBACK (clear_action_activate), NULL); - - g_simple_action_group_insert (actions, G_ACTION (messages)); - g_simple_action_group_insert (actions, G_ACTION (status)); - g_simple_action_group_insert (actions, G_ACTION (clear)); - - g_free (icon); - return actions; -} - static void got_bus (GObject *object, GAsyncResult * res, @@ -246,8 +157,6 @@ main (int argc, char ** argv) g_bus_get (G_BUS_TYPE_SESSION, NULL, got_bus, NULL); - actions = create_action_group (); - g_signal_connect (messages_service, "handle-register-application", G_CALLBACK (register_application), NULL); g_signal_connect (messages_service, "handle-unregister-application", -- cgit v1.2.3 From 5c7569e03d770c5f29b0011b2b0ad04f0be2ff88 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 28 Nov 2012 14:09:26 +0100 Subject: Add x-canonical-type to the root item --- src/messages-service.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/messages-service.c b/src/messages-service.c index 6b8f26b..61e786f 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -166,6 +166,7 @@ main (int argc, char ** argv) toplevel_menu = g_menu_new (); root = g_menu_item_new (NULL, "messages"); + g_menu_item_set_attribute (root, "x-canonical-type", "s", "com.canonical.indicator.root"); g_menu_item_set_submenu (root, im_phone_menu_get_model (menu)); g_menu_append_item (toplevel_menu, root); -- cgit v1.2.3 From 235a7edc5c2fc2435c837f8a3d427dd0755f966d Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 28 Nov 2012 17:24:31 +0100 Subject: Use aa{sv} instead of a(ssgav) to communicate actions to the service --- ...om.canonical.indicator.messages.application.xml | 4 ++-- libmessaging-menu/messaging-menu-app.c | 2 +- libmessaging-menu/messaging-menu-message.c | 27 +++++++++------------- src/im-application-list.c | 8 +++---- 4 files changed, 18 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/common/com.canonical.indicator.messages.application.xml b/common/com.canonical.indicator.messages.application.xml index 5e99780..6f038e6 100644 --- a/common/com.canonical.indicator.messages.application.xml +++ b/common/com.canonical.indicator.messages.application.xml @@ -5,7 +5,7 @@ - + @@ -30,7 +30,7 @@ - + diff --git a/libmessaging-menu/messaging-menu-app.c b/libmessaging-menu/messaging-menu-app.c index 8b9f76b..3747705 100644 --- a/libmessaging-menu/messaging-menu-app.c +++ b/libmessaging-menu/messaging-menu-app.c @@ -529,7 +529,7 @@ messaging_menu_app_list_messages (IndicatorMessagesApplication *app_interface, GHashTableIter iter; MessagingMenuMessage *message; - g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(sssssxa(ssgav)b)")); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(sssssxaa{sv}b)")); g_hash_table_iter_init (&iter, app->messages); while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &message)) diff --git a/libmessaging-menu/messaging-menu-message.c b/libmessaging-menu/messaging-menu-message.c index a17cdb6..886c552 100644 --- a/libmessaging-menu/messaging-menu-message.c +++ b/libmessaging-menu/messaging-menu-message.c @@ -470,24 +470,22 @@ action_to_variant (Action *action) { GVariantBuilder builder; - g_variant_builder_init (&builder, G_VARIANT_TYPE ("(ssgav)")); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); - g_variant_builder_add (&builder, "s", action->id); - g_variant_builder_add (&builder, "s", action->label ? action->label : ""); + g_variant_builder_add (&builder, "{sv}", "name", g_variant_new_string (action->id)); + + if (action->label) + g_variant_builder_add (&builder, "{sv}", "label", g_variant_new_string (action->label)); if (action->parameter_type) { gchar *type = g_variant_type_dup_string (action->parameter_type); - g_variant_builder_add (&builder, "g", type); + g_variant_builder_add (&builder, "{sv}", "parameter-type", g_variant_new_signature (type)); g_free (type); } - else - g_variant_builder_add (&builder, "g", ""); - g_variant_builder_open (&builder, G_VARIANT_TYPE ("av")); if (action->parameter_hint) - g_variant_builder_add (&builder, "v", action->parameter_hint); - g_variant_builder_close (&builder); + g_variant_builder_add (&builder, "{sv}", "parameter-hint", action->parameter_hint); return g_variant_builder_end (&builder); } @@ -496,7 +494,7 @@ action_to_variant (Action *action) * messaging_menu_message_to_variant: * @msg: a #MessagingMenuMessage * - * Serializes @msg to a #GVariant of the form (sssssxa(ssgav)b): + * Serializes @msg to a #GVariant of the form (sssssxaa{sv}b): * * id * icon @@ -504,10 +502,7 @@ action_to_variant (Action *action) * subtitle * body * time - * array of actions: id - * label - * parameter_type - * parameter_hint (0 or 1 elements) + * array of action dictionaries * draws_attention * * Returns: a new floating #GVariant instance @@ -520,7 +515,7 @@ messaging_menu_message_to_variant (MessagingMenuMessage *msg) g_return_val_if_fail (MESSAGING_MENU_IS_MESSAGE (msg), NULL); - g_variant_builder_init (&builder, G_VARIANT_TYPE ("(sssssxa(ssgav)b)")); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("(sssssxaa{sv}b)")); g_variant_builder_add (&builder, "s", msg->id); @@ -541,7 +536,7 @@ messaging_menu_message_to_variant (MessagingMenuMessage *msg) g_variant_builder_add (&builder, "s", msg->body ? msg->body : ""); g_variant_builder_add (&builder, "x", msg->time); - g_variant_builder_open (&builder, G_VARIANT_TYPE ("a(ssgav)")); + g_variant_builder_open (&builder, G_VARIANT_TYPE ("aa{sv}")); for (it = msg->actions; it; it = it->next) g_variant_builder_add_value (&builder, action_to_variant (it->data)); g_variant_builder_close (&builder); diff --git a/src/im-application-list.c b/src/im-application-list.c index 7c53e69..1f901ec 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -511,14 +511,14 @@ im_application_list_message_added (Application *app, const gchar *subtitle; const gchar *body; gint64 time; - GVariantIter *action_iter; + GVariant *actions; gboolean draws_attention; GSimpleAction *action; GIcon *app_icon; gchar *app_iconstr; - g_variant_get (message, "(&s&s&s&s&sxa(ssgav)b)", - &id, &iconstr, &title, &subtitle, &body, &time, &action_iter, &draws_attention); + g_variant_get (message, "(&s&s&s&s&sx@aa{sv}b)", + &id, &iconstr, &title, &subtitle, &body, &time, &actions, &draws_attention); app_icon = g_app_info_get_icon (G_APP_INFO (app->info)); app_iconstr = app_icon ? g_icon_to_string (app_icon) : NULL; @@ -531,7 +531,7 @@ im_application_list_message_added (Application *app, g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, app->id, app_iconstr, id, iconstr, title, subtitle, body, time, draws_attention); - g_variant_iter_free (action_iter); + g_variant_unref (actions); g_free (app_iconstr); g_object_unref (action); } -- cgit v1.2.3 From e6930c0df67ab53fcb2f7183741dee1bc0d599d4 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 28 Nov 2012 17:39:14 +0100 Subject: Expose message actions in the phone menu And use com.canonical.indicator.messages.snapdecision as widget type if the message has actions. --- src/im-application-list.c | 6 ++++-- src/im-phone-menu.c | 11 ++++++++++- src/im-phone-menu.h | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 1f901ec..c446d12 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -271,13 +271,15 @@ im_application_list_class_init (ImApplicationListClass *klass) NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, - 8, + 10, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_VARIANT, G_TYPE_INT64, G_TYPE_BOOLEAN); @@ -529,7 +531,7 @@ im_application_list_message_added (Application *app, g_simple_action_group_insert (app->message_actions, G_ACTION (action)); g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, - app->id, app_iconstr, id, iconstr, title, subtitle, body, time, draws_attention); + app->id, app_iconstr, id, iconstr, title, subtitle, body, actions, time, draws_attention); g_variant_unref (actions); g_free (app_iconstr); diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index 728c08b..6e511ac 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -151,6 +151,7 @@ im_phone_menu_add_message (ImPhoneMenu *menu, const gchar *title, const gchar *subtitle, const gchar *body, + GVariant *actions, gint64 time) { GMenuItem *item; @@ -162,7 +163,15 @@ im_phone_menu_add_message (ImPhoneMenu *menu, action_name = g_strconcat (app_id, ".msg.", id, NULL); item = g_menu_item_new (title, action_name); - g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.messageitem"); + + if (g_variant_n_children (actions)) + { + g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.snapdecision"); + g_menu_item_set_attribute (item, "x-canonical-message-actions", "v", actions); + } + else + g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.messageitem"); + g_menu_item_set_attribute (item, "x-canonical-message-id", "s", id); g_menu_item_set_attribute (item, "x-canonical-subtitle", "s", subtitle); g_menu_item_set_attribute (item, "x-canonical-text", "s", body); diff --git a/src/im-phone-menu.h b/src/im-phone-menu.h index f6a6118..84908e2 100644 --- a/src/im-phone-menu.h +++ b/src/im-phone-menu.h @@ -45,6 +45,7 @@ void im_phone_menu_add_message (ImPhoneMenu *men const gchar *title, const gchar *subtitle, const gchar *body, + GVariant *actions, gint64 time); void im_phone_menu_remove_message (ImPhoneMenu *menu, -- cgit v1.2.3 From 4bfe4198605a873fdede8b7cf454b4134ce2ce52 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 29 Nov 2012 20:44:38 +0100 Subject: ImApplicationList: specify right number of args for 'message-added' This fixes a crash on arm, because g_signal_emit was called with one argument too many. --- src/im-application-list.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index c5e34b7..f0bf362 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -269,7 +269,8 @@ im_application_list_class_init (ImApplicationListClass *klass) NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, - 8, + 9, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, -- cgit v1.2.3 From 16aeadbeb7f0b108c2ba5e68a6ad0d96766380ba Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 30 Nov 2012 18:35:53 +0100 Subject: Expose message actions on the bus (as GActions) --- src/im-application-list.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index c446d12..70d288c 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -59,6 +59,7 @@ typedef struct GActionMuxer *actions; GSimpleActionGroup *source_actions; GSimpleActionGroup *message_actions; + GActionMuxer *message_sub_actions; GCancellable *cancellable; } Application; @@ -87,6 +88,7 @@ application_free (gpointer data) g_object_unref (app->actions); g_object_unref (app->source_actions); g_object_unref (app->message_actions); + g_object_unref (app->message_sub_actions); } g_slice_free (Application, app); @@ -134,6 +136,7 @@ im_application_list_message_removed (Application *app, const gchar *id) { g_simple_action_group_remove (app->message_actions, id); + g_action_muxer_remove (app->message_sub_actions, id); g_signal_emit (app->list, signals[MESSAGE_REMOVED], 0, app->id, id); } @@ -168,6 +171,34 @@ im_application_list_message_activated (GSimpleAction *action, im_application_list_message_removed (app, message_id); } +static void +im_application_list_sub_message_activated (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + Application *app = user_data; + const gchar *message_id; + const gchar *action_id; + GVariantBuilder builder; + + message_id = g_object_get_data (G_OBJECT (action), "message"); + action_id = g_action_get_name (G_ACTION (action)); + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("av")); + if (parameter) + g_variant_builder_add (&builder, "v", parameter); + + indicator_messages_application_call_activate_message (app->proxy, + message_id, + action_id, + g_variant_builder_end (&builder), + app->cancellable, + NULL, NULL); + + im_application_list_message_removed (app, message_id); +} + + static void im_application_list_remove_all (GSimpleAction *action, GVariant *parameter, @@ -395,9 +426,11 @@ im_application_list_add (ImApplicationList *list, app->actions = g_action_muxer_new (); app->source_actions = g_simple_action_group_new (); app->message_actions = g_simple_action_group_new (); + app->message_sub_actions = g_action_muxer_new (); g_action_muxer_insert (app->actions, "src", G_ACTION_GROUP (app->source_actions)); g_action_muxer_insert (app->actions, "msg", G_ACTION_GROUP (app->message_actions)); + g_action_muxer_insert (app->actions, "msg-actions", G_ACTION_GROUP (app->message_sub_actions)); g_hash_table_insert (list->applications, (gpointer) app->id, app); g_action_muxer_insert (list->muxer, app->id, G_ACTION_GROUP (app->actions)); @@ -527,9 +560,52 @@ im_application_list_message_added (Application *app, action = g_simple_action_new (id, G_VARIANT_TYPE_BOOLEAN); g_signal_connect (action, "activate", G_CALLBACK (im_application_list_message_activated), app); - g_simple_action_group_insert (app->message_actions, G_ACTION (action)); + { + GVariantIter iter; + GVariant *entry; + GSimpleActionGroup *action_group; + + action_group = g_simple_action_group_new (); + + g_variant_iter_init (&iter, actions); + while ((entry = g_variant_iter_next_value (&iter))) + { + const gchar *name; + GSimpleAction *action; + GVariant *label; + const gchar *type = NULL; + GVariant *hint; + + if (!g_variant_lookup (entry, "name", "&s", &name)) + { + g_warning ("action dictionary for message '%s' is missing 'name' key", id); + continue; + } + + label = g_variant_lookup_value (entry, "label", G_VARIANT_TYPE_STRING); + g_variant_lookup (entry, "parameter-type", "&g", &type); + hint = g_variant_lookup_value (entry, "parameter-hint", NULL); + + action = g_simple_action_new (name, type ? G_VARIANT_TYPE (type) : NULL); + g_object_set_data_full (G_OBJECT (action), "message", g_strdup (id), g_free); + g_signal_connect (action, "activate", G_CALLBACK (im_application_list_sub_message_activated), app); + g_simple_action_group_insert (action_group, G_ACTION (action)); + + g_object_unref (action); + if (label) + g_variant_unref (label); + if (hint) + g_variant_unref (hint); + g_variant_unref (entry); + } + + g_action_muxer_insert (app->message_sub_actions, id, G_ACTION_GROUP (action_group)); + + g_object_unref (action_group); + } + g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, app->id, app_iconstr, id, iconstr, title, subtitle, body, actions, time, draws_attention); @@ -586,10 +662,13 @@ im_application_list_unset_remote (Application *app) * the muxer */ g_object_unref (app->source_actions); g_object_unref (app->message_actions); + g_object_unref (app->message_sub_actions); app->source_actions = g_simple_action_group_new (); app->message_actions = g_simple_action_group_new (); + app->message_sub_actions = g_action_muxer_new (); g_action_muxer_insert (app->actions, "src", G_ACTION_GROUP (app->source_actions)); g_action_muxer_insert (app->actions, "msg", G_ACTION_GROUP (app->message_actions)); + g_action_muxer_insert (app->actions, "msg-actions", G_ACTION_GROUP (app->message_sub_actions)); if (was_running) g_signal_emit (app->list, signals[APP_STOPPED], 0, app->id); -- cgit v1.2.3 From c21c6e9a3e204bccae7b9a30c56845cbc45661ff Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 3 Dec 2012 15:42:46 +0000 Subject: Stop using IndicatorService This doesn't require every consumer ("panel") to know about IndicatorServiceManager's protocol. Also, it ensures that objects are exported before the name is acquired, getting rid of a race condition (when a consumer tries to access objects in NameAppeared before they're exported). This patch also adds a --replace command line option -- replacing the INDICATOR_SERVICE_REPLACE_MODE environment variable. --- src/messages-service.c | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/messages-service.c b/src/messages-service.c index 61e786f..d10e98a 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -23,7 +23,6 @@ with this program. If not, see . #include #include -#include #include #include @@ -44,15 +43,6 @@ static GMenu *toplevel_menu; static ImPhoneMenu *menu; static GSettings *settings; -static void -service_shutdown (IndicatorService * service, gpointer user_data) -{ - GMainLoop *mainloop = user_data; - - g_warning("Shutting down service!"); - g_main_loop_quit(mainloop); -} - static void register_application (IndicatorMessagesService *service, GDBusMethodInvocation *invocation, @@ -87,20 +77,12 @@ unregister_application (IndicatorMessagesService *service, } static void -got_bus (GObject *object, - GAsyncResult * res, - gpointer user_data) +on_bus_acquired (GDBusConnection *bus, + const gchar *name, + gpointer user_data) { - GDBusConnection *bus; GError *error = NULL; - bus = g_bus_get_finish (res, &error); - if (!bus) { - g_warning ("unable to connect to the session bus: %s", error->message); - g_error_free (error); - return; - } - g_dbus_connection_export_action_group (bus, INDICATOR_MESSAGES_DBUS_OBJECT, im_application_list_get_action_group (applications), &error); @@ -130,22 +112,28 @@ got_bus (GObject *object, g_object_unref (bus); } +static void +on_name_lost (GDBusConnection *bus, + const gchar *name, + gpointer user_data) +{ + GMainLoop *mainloop = user_data; + + g_main_loop_quit (mainloop); +} + int main (int argc, char ** argv) { GMainLoop * mainloop = NULL; - IndicatorService * service = NULL; GMenuItem *root; + GBusNameOwnerFlags flags; /* Glib init */ g_type_init(); mainloop = g_main_loop_new (NULL, FALSE); - /* Create the Indicator Service interface */ - service = indicator_service_new_version(INDICATOR_MESSAGES_DBUS_NAME, 1); - g_signal_connect(service, INDICATOR_SERVICE_SIGNAL_SHUTDOWN, G_CALLBACK(service_shutdown), mainloop); - /* Setting up i18n and gettext. Apparently, we need all of these. */ setlocale (LC_ALL, ""); @@ -155,7 +143,12 @@ main (int argc, char ** argv) /* Bring up the service DBus interface */ messages_service = indicator_messages_service_skeleton_new (); - g_bus_get (G_BUS_TYPE_SESSION, NULL, got_bus, NULL); + flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT; + if (argc >= 2 && g_str_equal (argv[1], "--replace")) + flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; + + g_bus_own_name (G_BUS_TYPE_SESSION, "com.canonical.indicator.messages", flags, + on_bus_acquired, NULL, on_name_lost, mainloop, NULL); g_signal_connect (messages_service, "handle-register-application", G_CALLBACK (register_application), NULL); -- cgit v1.2.3 From 4e8bff91265ee85f00793bbfd065e5832e436954 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 3 Dec 2012 17:21:39 +0000 Subject: Prefix message action names with the right namespace --- src/im-application-list.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index d4c5687..c41c858 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -545,14 +545,15 @@ im_application_list_message_added (Application *app, const gchar *subtitle; const gchar *body; gint64 time; - GVariant *actions; + GVariantIter *action_iter; gboolean draws_attention; GSimpleAction *action; GIcon *app_icon; gchar *app_iconstr; + GVariant *actions = NULL; - g_variant_get (message, "(&s&s&s&s&sx@aa{sv}b)", - &id, &iconstr, &title, &subtitle, &body, &time, &actions, &draws_attention); + g_variant_get (message, "(&s&s&s&s&sxaa{sv}b)", + &id, &iconstr, &title, &subtitle, &body, &time, &action_iter, &draws_attention); app_icon = g_app_info_get_icon (G_APP_INFO (app->info)); app_iconstr = app_icon ? g_icon_to_string (app_icon) : NULL; @@ -562,20 +563,22 @@ im_application_list_message_added (Application *app, g_simple_action_group_insert (app->message_actions, G_ACTION (action)); { - GVariantIter iter; GVariant *entry; GSimpleActionGroup *action_group; + GVariantBuilder actions_builder; + g_variant_builder_init (&actions_builder, G_VARIANT_TYPE ("aa{sv}")); action_group = g_simple_action_group_new (); - g_variant_iter_init (&iter, actions); - while ((entry = g_variant_iter_next_value (&iter))) + while ((entry = g_variant_iter_next_value (action_iter))) { const gchar *name; GSimpleAction *action; GVariant *label; const gchar *type = NULL; GVariant *hint; + GVariantBuilder dict_builder; + gchar *prefixed_name; if (!g_variant_lookup (entry, "name", "&s", &name)) { @@ -592,15 +595,35 @@ im_application_list_message_added (Application *app, g_signal_connect (action, "activate", G_CALLBACK (im_application_list_sub_message_activated), app); g_simple_action_group_insert (action_group, G_ACTION (action)); - g_object_unref (action); + g_variant_builder_init (&dict_builder, G_VARIANT_TYPE ("a{sv}")); + + prefixed_name = g_strjoin (".", app->id, "msg-actions", id, name, NULL); + g_variant_builder_add (&dict_builder, "{sv}", "name", g_variant_new_string (prefixed_name)); + if (label) - g_variant_unref (label); + { + g_variant_builder_add (&dict_builder, "{sv}", "label", label); + g_variant_unref (label); + } + + if (type) + g_variant_builder_add (&dict_builder, "{sv}", "parameter-type", g_variant_new_string (type)); + if (hint) - g_variant_unref (hint); + { + g_variant_builder_add (&dict_builder, "{sv}", "parameter-hint", hint); + g_variant_unref (hint); + } + + g_variant_builder_add (&actions_builder, "a{sv}", &dict_builder); + + g_object_unref (action); g_variant_unref (entry); + g_free (prefixed_name); } g_action_muxer_insert (app->message_sub_actions, id, G_ACTION_GROUP (action_group)); + actions = g_variant_builder_end (&actions_builder); g_object_unref (action_group); } @@ -608,7 +631,7 @@ im_application_list_message_added (Application *app, g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, app->id, app_iconstr, id, iconstr, title, subtitle, body, actions, time, draws_attention); - g_variant_unref (actions); + g_variant_iter_free (action_iter); g_free (app_iconstr); g_object_unref (action); } -- cgit v1.2.3 From 0e126bb708f9381819e01debdcbdfd508aa47d2d Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 4 Dec 2012 10:35:04 +0000 Subject: Reverse order of messages Newest messages should show up on top. The menu is still sorted by the time messages were added, not by the time property of MessagingMenuMessage. --- src/im-phone-menu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index 6e511ac..ed28023 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -183,7 +183,7 @@ im_phone_menu_add_message (ImPhoneMenu *menu, if (app_icon) g_menu_item_set_attribute (item, "x-canonical-app-icon", "s", app_icon); - g_menu_append_item (menu->message_section, item); + g_menu_prepend_item (menu->message_section, item); g_free (action_name); g_object_unref (item); @@ -228,7 +228,7 @@ im_phone_menu_add_source (ImPhoneMenu *menu, if (iconstr) g_menu_item_set_attribute (item, "x-canonical-icon", "s", iconstr); - g_menu_append_item (menu->source_section, item); + g_menu_prepend_item (menu->source_section, item); g_free (action_name); g_object_unref (item); -- cgit v1.2.3 From af58f8e28e5ab5ed29de518bd921f8ae699ac972 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 4 Dec 2012 12:31:33 +0000 Subject: Export symbolic application icons on messages This is implemented by appending '-symbolic' to the first icon name. The old icon name is kept as a fallback in case there's no symbolic icon installed. This doesn't work yet for applications that specify their icon as a filename. --- src/im-application-list.c | 41 ++++++++++++++++++++++++++++++++++++++--- src/im-phone-menu.c | 4 ++++ src/im-phone-menu.h | 1 + 3 files changed, 43 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index c41c858..77c0e47 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -302,7 +302,8 @@ im_application_list_class_init (ImApplicationListClass *klass) NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, - 10, + 11, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, @@ -535,6 +536,33 @@ im_application_list_sources_listed (GObject *source_object, } } +static gchar * +get_symbolic_app_icon_string (GIcon *icon) +{ + const gchar * const *names; + gchar *symbolic_name; + GIcon *symbolic_icon; + gchar *str; + + if (!G_IS_THEMED_ICON (icon)) + return NULL; + + names = g_themed_icon_get_names (G_THEMED_ICON (icon)); + if (!names || !names[0]) + return NULL; + + symbolic_icon = g_themed_icon_new_from_names ((gchar **) names, -1); + + symbolic_name = g_strconcat (names[0], "-symbolic", NULL); + g_themed_icon_prepend_name (G_THEMED_ICON (symbolic_icon), symbolic_name); + + str = g_icon_to_string (symbolic_icon); + + g_free (symbolic_name); + g_object_unref (symbolic_icon); + return str; +} + static void im_application_list_message_added (Application *app, GVariant *message) @@ -550,13 +578,18 @@ im_application_list_message_added (Application *app, GSimpleAction *action; GIcon *app_icon; gchar *app_iconstr; + gchar *symbolic_app_iconstr; GVariant *actions = NULL; g_variant_get (message, "(&s&s&s&s&sxaa{sv}b)", &id, &iconstr, &title, &subtitle, &body, &time, &action_iter, &draws_attention); app_icon = g_app_info_get_icon (G_APP_INFO (app->info)); - app_iconstr = app_icon ? g_icon_to_string (app_icon) : NULL; + if (app_icon) + { + app_iconstr = g_icon_to_string (app_icon); + symbolic_app_iconstr = get_symbolic_app_icon_string (app_icon); + } action = g_simple_action_new (id, G_VARIANT_TYPE_BOOLEAN); g_signal_connect (action, "activate", G_CALLBACK (im_application_list_message_activated), app); @@ -629,10 +662,12 @@ im_application_list_message_added (Application *app, } g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, - app->id, app_iconstr, id, iconstr, title, subtitle, body, actions, time, draws_attention); + app->id, app_iconstr, symbolic_app_iconstr, id, + iconstr, title, subtitle, body, actions, time, draws_attention); g_variant_iter_free (action_iter); g_free (app_iconstr); + g_free (symbolic_app_iconstr); g_object_unref (action); } diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index ed28023..51467ba 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -146,6 +146,7 @@ void im_phone_menu_add_message (ImPhoneMenu *menu, const gchar *app_id, const gchar *app_icon, + const gchar *symbolic_app_icon, const gchar *id, const gchar *iconstr, const gchar *title, @@ -183,6 +184,9 @@ im_phone_menu_add_message (ImPhoneMenu *menu, if (app_icon) g_menu_item_set_attribute (item, "x-canonical-app-icon", "s", app_icon); + if (symbolic_app_icon) + g_menu_item_set_attribute (item, "x-canonical-app-icon-symbolic", "s", symbolic_app_icon); + g_menu_prepend_item (menu->message_section, item); g_free (action_name); diff --git a/src/im-phone-menu.h b/src/im-phone-menu.h index 84908e2..f78e06f 100644 --- a/src/im-phone-menu.h +++ b/src/im-phone-menu.h @@ -40,6 +40,7 @@ GMenuModel * im_phone_menu_get_model (ImPhoneMenu *men void im_phone_menu_add_message (ImPhoneMenu *menu, const gchar *app_id, const gchar *app_icon, + const gchar *symbolic_app_icon, const gchar *id, const gchar *iconstr, const gchar *title, -- cgit v1.2.3 From af3d39b6cc447fad30e97ecdc715e0496e971d85 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 4 Dec 2012 13:58:23 +0000 Subject: im-application-list: initialize local variables with NULL They are not set in every code path but freed at the end of the function. --- src/im-application-list.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 77c0e47..da78813 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -577,8 +577,8 @@ im_application_list_message_added (Application *app, gboolean draws_attention; GSimpleAction *action; GIcon *app_icon; - gchar *app_iconstr; - gchar *symbolic_app_iconstr; + gchar *app_iconstr = NULL; + gchar *symbolic_app_iconstr = NULL; GVariant *actions = NULL; g_variant_get (message, "(&s&s&s&s&sxaa{sv}b)", -- cgit v1.2.3 From 40b99f3e6fc6170da525c88cf79186cd9cb565de Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 4 Dec 2012 18:33:55 +0000 Subject: Only expose one application icon (the -symbolic one) --- src/im-application-list.c | 14 ++++---------- src/im-phone-menu.c | 4 ---- src/im-phone-menu.h | 1 - 3 files changed, 4 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index da78813..64b15e3 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -302,8 +302,7 @@ im_application_list_class_init (ImApplicationListClass *klass) NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, - 11, - G_TYPE_STRING, + 10, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, @@ -578,7 +577,6 @@ im_application_list_message_added (Application *app, GSimpleAction *action; GIcon *app_icon; gchar *app_iconstr = NULL; - gchar *symbolic_app_iconstr = NULL; GVariant *actions = NULL; g_variant_get (message, "(&s&s&s&s&sxaa{sv}b)", @@ -586,10 +584,7 @@ im_application_list_message_added (Application *app, app_icon = g_app_info_get_icon (G_APP_INFO (app->info)); if (app_icon) - { - app_iconstr = g_icon_to_string (app_icon); - symbolic_app_iconstr = get_symbolic_app_icon_string (app_icon); - } + app_iconstr = get_symbolic_app_icon_string (app_icon); action = g_simple_action_new (id, G_VARIANT_TYPE_BOOLEAN); g_signal_connect (action, "activate", G_CALLBACK (im_application_list_message_activated), app); @@ -662,12 +657,11 @@ im_application_list_message_added (Application *app, } g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, - app->id, app_iconstr, symbolic_app_iconstr, id, - iconstr, title, subtitle, body, actions, time, draws_attention); + app->id, app_iconstr, id, iconstr, title, + subtitle, body, actions, time, draws_attention); g_variant_iter_free (action_iter); g_free (app_iconstr); - g_free (symbolic_app_iconstr); g_object_unref (action); } diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index 51467ba..ed28023 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -146,7 +146,6 @@ void im_phone_menu_add_message (ImPhoneMenu *menu, const gchar *app_id, const gchar *app_icon, - const gchar *symbolic_app_icon, const gchar *id, const gchar *iconstr, const gchar *title, @@ -184,9 +183,6 @@ im_phone_menu_add_message (ImPhoneMenu *menu, if (app_icon) g_menu_item_set_attribute (item, "x-canonical-app-icon", "s", app_icon); - if (symbolic_app_icon) - g_menu_item_set_attribute (item, "x-canonical-app-icon-symbolic", "s", symbolic_app_icon); - g_menu_prepend_item (menu->message_section, item); g_free (action_name); diff --git a/src/im-phone-menu.h b/src/im-phone-menu.h index f78e06f..84908e2 100644 --- a/src/im-phone-menu.h +++ b/src/im-phone-menu.h @@ -40,7 +40,6 @@ GMenuModel * im_phone_menu_get_model (ImPhoneMenu *men void im_phone_menu_add_message (ImPhoneMenu *menu, const gchar *app_id, const gchar *app_icon, - const gchar *symbolic_app_icon, const gchar *id, const gchar *iconstr, const gchar *title, -- cgit v1.2.3 From ae7c525208acc860a5bcd035fc37801f33488c67 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 4 Dec 2012 20:07:50 +0000 Subject: Change icon when there are any messages in the menu --- src/im-application-list.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index da78813..255049f 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -131,6 +131,47 @@ im_application_list_source_activated (GSimpleAction *action, im_application_list_source_removed (app, source_id); } +static guint +g_action_group_get_n_actions (GActionGroup *group) +{ + guint len; + gchar **actions; + + actions = g_action_group_list_actions (group); + len = g_strv_length (actions); + + g_strfreev (actions); + return len; +} + +static gboolean +application_draws_attention (gpointer key, + gpointer value, + gpointer user_data) +{ + Application *app = value; + + return (g_action_group_get_n_actions (G_ACTION_GROUP (app->source_actions)) + + g_action_group_get_n_actions (G_ACTION_GROUP (app->message_actions))) > 0; +} + +static void +im_application_list_update_draws_attention (ImApplicationList *list) +{ + const gchar *icon_name; + GVariant *state; + GActionGroup *main_actions; + + if (g_hash_table_find (list->applications, application_draws_attention, NULL)) + icon_name = "indicator-messages-new"; + else + icon_name = "indicator-messages"; + + main_actions = g_action_muxer_get_group (list->muxer, NULL); + state = g_variant_new ("(sssb)", "", "Messages", icon_name, TRUE); + g_action_group_change_action_state (main_actions, "messages", state); +} + static void im_application_list_message_removed (Application *app, const gchar *id) @@ -138,6 +179,8 @@ im_application_list_message_removed (Application *app, g_simple_action_group_remove (app->message_actions, id); g_action_muxer_remove (app->message_sub_actions, id); + im_application_list_update_draws_attention (app->list); + g_signal_emit (app->list, signals[MESSAGE_REMOVED], 0, app->id, id); } @@ -661,6 +704,8 @@ im_application_list_message_added (Application *app, g_object_unref (action_group); } + im_application_list_update_draws_attention (app->list); + g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, app->id, app_iconstr, symbolic_app_iconstr, id, iconstr, title, subtitle, body, actions, time, draws_attention); @@ -727,6 +772,8 @@ im_application_list_unset_remote (Application *app) g_action_muxer_insert (app->actions, "msg", G_ACTION_GROUP (app->message_actions)); g_action_muxer_insert (app->actions, "msg-actions", G_ACTION_GROUP (app->message_sub_actions)); + im_application_list_update_draws_attention (app->list); + if (was_running) g_signal_emit (app->list, signals[APP_STOPPED], 0, app->id); } -- cgit v1.2.3 From 69ee426c0e5d81b95b2907fc8cc1bd7ed2ef559c Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 4 Dec 2012 20:18:34 +0000 Subject: Switch accessible name and icon-name (see last commit) --- src/im-application-list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 255049f..b936859 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -168,7 +168,7 @@ im_application_list_update_draws_attention (ImApplicationList *list) icon_name = "indicator-messages"; main_actions = g_action_muxer_get_group (list->muxer, NULL); - state = g_variant_new ("(sssb)", "", "Messages", icon_name, TRUE); + state = g_variant_new ("(sssb)", "", icon_name, "Messages", TRUE); g_action_group_change_action_state (main_actions, "messages", state); } -- cgit v1.2.3 From 0a1d7c1844dc6104eefe43b38400f3d94868428b Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 5 Dec 2012 10:37:16 +0000 Subject: Don't shorten the app id to seven characters --- src/im-application-list.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 607b0fc..5a7f768 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -411,8 +411,13 @@ im_application_list_canonical_id (const gchar *id) { gchar *str; gchar *p; + int len; - str = g_strndup (id, strlen (id) - g_str_has_suffix (id, ".desktop") ? 7 : 0); + len = strlen (id); + if (g_str_has_suffix (id, ".desktop")) + len -= 8; + + str = g_strndup (id, len); for (p = str; *p; p++) { -- cgit v1.2.3 From e1988a3d3857b4a3c51e9e4b5132e91c188ec28c Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 10 Dec 2012 13:42:29 +0100 Subject: Remove the snapdecision widget type Always use messageitem instead. --- src/im-phone-menu.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index ed28023..83363d1 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -164,14 +164,7 @@ im_phone_menu_add_message (ImPhoneMenu *menu, item = g_menu_item_new (title, action_name); - if (g_variant_n_children (actions)) - { - g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.snapdecision"); - g_menu_item_set_attribute (item, "x-canonical-message-actions", "v", actions); - } - else - g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.messageitem"); - + g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.messageitem"); g_menu_item_set_attribute (item, "x-canonical-message-id", "s", id); g_menu_item_set_attribute (item, "x-canonical-subtitle", "s", subtitle); g_menu_item_set_attribute (item, "x-canonical-text", "s", body); @@ -183,6 +176,9 @@ im_phone_menu_add_message (ImPhoneMenu *menu, if (app_icon) g_menu_item_set_attribute (item, "x-canonical-app-icon", "s", app_icon); + if (actions) + g_menu_item_set_attribute (item, "x-canonical-message-actions", "v", actions); + g_menu_prepend_item (menu->message_section, item); g_free (action_name); -- cgit v1.2.3 From e5caa5032da9e5cd41876934f9073e1f3646edd5 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 10 Dec 2012 14:30:10 +0100 Subject: Don't show sources in the phone menu --- src/messages-service.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') diff --git a/src/messages-service.c b/src/messages-service.c index d10e98a..27bce4e 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -166,10 +166,6 @@ main (int argc, char ** argv) settings = g_settings_new ("com.canonical.indicator.messages"); applications = im_application_list_new (); - g_signal_connect_swapped (applications, "source-added", - G_CALLBACK (im_phone_menu_add_source), menu); - g_signal_connect_swapped (applications, "source-removed", - G_CALLBACK (im_phone_menu_remove_source), menu); g_signal_connect_swapped (applications, "message-added", G_CALLBACK (im_phone_menu_add_message), menu); g_signal_connect_swapped (applications, "message-removed", -- cgit v1.2.3 From c46e38d7ab03589a7c7d4fd5fa52ef0bb5f1a9d5 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 14 Dec 2012 10:56:00 +0100 Subject: im_application_list_proxy_created: fix error condition Also, don't print a warning when the proy couldn't be created because the operation was cancelled. This only happens when the service is shutting down or when one application replaces another one with the same desktop file (in which case we already warn with a more descriptive message). --- src/im-application-list.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 5a7f768..d3d8dad 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -796,9 +796,10 @@ im_application_list_proxy_created (GObject *source_object, GError *error = NULL; app->proxy = indicator_messages_application_proxy_new_finish (result, &error); - if (!app) + if (!app->proxy) { - g_warning ("could not create application proxy: %s", error->message); + if (error->code != G_IO_ERROR_CANCELLED) + g_warning ("could not create application proxy: %s", error->message); g_error_free (error); return; } -- cgit v1.2.3 From 12c0fb327dfef1f778de252c715f3b61bfcaea28 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 14 Dec 2012 10:59:23 +0100 Subject: im_application_list_set_remote: robuster check for running async operation This fixes the case when app->proxy is still NULL but another application with the same desktop file replaces it. This should never happen in practice, but turned up while testing multiple processes which used the same desktop file. Their proxy_create async functions raced each other because the first one's wasn't properly cancelled. Also fixes a small memory leak. --- src/im-application-list.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index d3d8dad..959a820 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -840,11 +840,17 @@ im_application_list_set_remote (ImApplicationList *list, return; } - if (app->proxy || app->cancellable) + if (app->cancellable) { - g_warning ("replacing '%s' at %s with %s", id, unique_bus_name, - g_dbus_proxy_get_name_owner (G_DBUS_PROXY (app->proxy))); + gchar *name_owner = NULL; + + if (app->proxy) + name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (app->proxy)); + g_warning ("replacing '%s' at %s with %s", id, name_owner, unique_bus_name); + im_application_list_unset_remote (app); + + g_free (name_owner); } app->cancellable = g_cancellable_new (); -- cgit v1.2.3 From 1b61967566bdb16bd6fea882bb6f3c73c625cb35 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 14 Dec 2012 12:05:30 +0100 Subject: ImPhoneMenu: sort messages by time --- src/im-phone-menu.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index 83363d1..922dc82 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -142,6 +142,17 @@ im_phone_menu_get_model (ImPhoneMenu *menu) return G_MENU_MODEL (menu->toplevel_menu); } +static gint64 +im_phone_menu_get_message_time (GMenuModel *model, + gint i) +{ + gint64 time; + + g_menu_model_get_item_attribute (model, i, "x-canonical-time", "x", &time); + + return time; +} + void im_phone_menu_add_message (ImPhoneMenu *menu, const gchar *app_id, @@ -156,6 +167,8 @@ im_phone_menu_add_message (ImPhoneMenu *menu, { GMenuItem *item; gchar *action_name; + gint n_messages; + gint pos; g_return_if_fail (IM_IS_PHONE_MENU (menu)); g_return_if_fail (app_id); @@ -179,7 +192,13 @@ im_phone_menu_add_message (ImPhoneMenu *menu, if (actions) g_menu_item_set_attribute (item, "x-canonical-message-actions", "v", actions); - g_menu_prepend_item (menu->message_section, item); + n_messages = g_menu_model_get_n_items (G_MENU_MODEL (menu->message_section)); + pos = 0; + while (pos < n_messages && + time < im_phone_menu_get_message_time (G_MENU_MODEL (menu->message_section), pos)) + pos++; + + g_menu_insert_item (menu->message_section, pos, item); g_free (action_name); g_object_unref (item); -- cgit v1.2.3 From dd756106c02cabc79c7429e42ff6658bd37bba6c Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 20 Dec 2012 17:46:15 +0100 Subject: ImApplicationList: add "remove-all" signal This is a temporary hack to work around a crash in QMenuModel. --- src/im-application-list.c | 12 ++++++++++++ src/im-phone-menu.c | 20 ++++++++++++++++++++ src/im-phone-menu.h | 2 ++ src/messages-service.c | 2 ++ 4 files changed, 36 insertions(+) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 959a820..9a673c9 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -45,6 +45,7 @@ enum MESSAGE_ADDED, MESSAGE_REMOVED, APP_STOPPED, + REMOVE_ALL, N_SIGNALS }; @@ -251,6 +252,8 @@ im_application_list_remove_all (GSimpleAction *action, GHashTableIter iter; Application *app; + g_signal_emit (list, signals[REMOVE_ALL], 0); + g_hash_table_iter_init (&iter, list->applications); while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &app)) { @@ -377,6 +380,15 @@ im_application_list_class_init (ImApplicationListClass *klass) G_TYPE_NONE, 1, G_TYPE_STRING); + + signals[REMOVE_ALL] = g_signal_new ("remove-all", + IM_TYPE_APPLICATION_LIST, + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); } static void diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index 922dc82..3d5f94d 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -309,3 +309,23 @@ im_phone_menu_remove_application (ImPhoneMenu *menu, im_phone_menu_remove_all_for_app (menu->source_section, app_id); im_phone_menu_remove_all_for_app (menu->message_section, app_id); } + +void +im_phone_menu_remove_all (ImPhoneMenu *menu) +{ + g_return_if_fail (IM_IS_PHONE_MENU (menu)); + + while (g_menu_model_get_n_items (G_MENU_MODEL (menu->toplevel_menu))) + g_menu_remove (menu->toplevel_menu, 0); + + g_object_unref (menu->message_section); + g_object_unref (menu->source_section); + + menu->message_section = g_menu_new (); + menu->source_section = g_menu_new (); + + g_signal_connect_swapped (menu->message_section, "items-changed", + G_CALLBACK (im_phone_menu_update_toplevel), menu); + g_signal_connect_swapped (menu->source_section, "items-changed", + G_CALLBACK (im_phone_menu_update_toplevel), menu); +} diff --git a/src/im-phone-menu.h b/src/im-phone-menu.h index 84908e2..258ce73 100644 --- a/src/im-phone-menu.h +++ b/src/im-phone-menu.h @@ -65,4 +65,6 @@ void im_phone_menu_remove_source (ImPhoneMenu *men void im_phone_menu_remove_application (ImPhoneMenu *menu, const gchar *app_id); +void im_phone_menu_remove_all (ImPhoneMenu *menu); + #endif diff --git a/src/messages-service.c b/src/messages-service.c index 27bce4e..c2ca1a0 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -172,6 +172,8 @@ main (int argc, char ** argv) G_CALLBACK (im_phone_menu_remove_message), menu); g_signal_connect_swapped (applications, "app-stopped", G_CALLBACK (im_phone_menu_remove_application), menu); + g_signal_connect_swapped (applications, "remove-all", + G_CALLBACK (im_phone_menu_remove_all), menu); g_main_loop_run(mainloop); -- cgit v1.2.3 From ba4d0379dc193dc44942a3e96d6ea121f8ae142b Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 20 Feb 2013 11:01:02 -0300 Subject: Fixed missing copyright header. --- src/dbus-data.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/dbus-data.h b/src/dbus-data.h index ceeb546..59bd305 100644 --- a/src/dbus-data.h +++ b/src/dbus-data.h @@ -1,3 +1,18 @@ +/* + * Copyright 2012-2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ #ifndef __DBUS_DATA_H__ #define __DBUS_DATA_H__ 1 -- cgit v1.2.3 From 5e3abf725e0628673c1bb16869edc67dfa7e2729 Mon Sep 17 00:00:00 2001 From: Sergio Schvezov Date: Fri, 22 Mar 2013 16:54:38 -0300 Subject: Adding glib version guard to g_type_init --- doc/reference/Makefile.am | 1 - src/messages-service.c | 2 ++ test/indicator-messages-service-activate.c | 2 ++ test/test-gactionmuxer.cpp | 8 ++++++++ 4 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/doc/reference/Makefile.am b/doc/reference/Makefile.am index 3ea08f2..3993b41 100644 --- a/doc/reference/Makefile.am +++ b/doc/reference/Makefile.am @@ -4,7 +4,6 @@ DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.xml DOC_SOURCE_DIR = $(top_srcdir)/libmessaging-menu -SCANGOBJ_OPTIONS=--type-init-func="g_type_init()" MKDB_OPTIONS=--xml-mode --output-format=xml # Used for dependencies. The docs will be rebuilt if any of these change. diff --git a/src/messages-service.c b/src/messages-service.c index c2ca1a0..5f320fc 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -130,7 +130,9 @@ main (int argc, char ** argv) GBusNameOwnerFlags flags; /* Glib init */ +#if G_ENCODE_VERSION(GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION) <= GLIB_VERSION_2_34 g_type_init(); +#endif mainloop = g_main_loop_new (NULL, FALSE); diff --git a/test/indicator-messages-service-activate.c b/test/indicator-messages-service-activate.c index 98c6522..f5a26b0 100644 --- a/test/indicator-messages-service-activate.c +++ b/test/indicator-messages-service-activate.c @@ -28,7 +28,9 @@ with this program. If not, see . int main (int argc, char ** argv) { +#if G_ENCODE_VERSION(GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION) <= GLIB_VERSION_2_34 g_type_init(); +#endif guint returnval = 0; GError * error = NULL; diff --git a/test/test-gactionmuxer.cpp b/test/test-gactionmuxer.cpp index de51211..efd6e4f 100644 --- a/test/test-gactionmuxer.cpp +++ b/test/test-gactionmuxer.cpp @@ -43,7 +43,9 @@ strv_contains (gchar **str_array, TEST(GActionMuxerTest, Sanity) { GActionMuxer *muxer; +#if G_ENCODE_VERSION(GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION) <= GLIB_VERSION_2_34 g_type_init (); +#endif g_action_muxer_insert (NULL, NULL, NULL); g_action_muxer_remove (NULL, NULL); @@ -64,7 +66,9 @@ TEST(GActionMuxerTest, Empty) { GActionMuxer *muxer; gchar **actions; +#if G_ENCODE_VERSION(GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION) <= GLIB_VERSION_2_34 g_type_init (); +#endif muxer = g_action_muxer_new (); @@ -85,7 +89,9 @@ TEST(GActionMuxerTest, AddAndRemove) { GActionMuxer *muxer; gchar **actions; +#if G_ENCODE_VERSION(GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION) <= GLIB_VERSION_2_34 g_type_init (); +#endif group1 = g_simple_action_group_new (); g_simple_action_group_add_entries (group1, @@ -178,7 +184,9 @@ TEST(GActionMuxerTest, ActionAttributes) { GVariant *state_hint[2]; GVariant *state[2]; +#if G_ENCODE_VERSION(GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION) <= GLIB_VERSION_2_34 g_type_init (); +#endif group = g_simple_action_group_new (); action = g_simple_action_new ("one", G_VARIANT_TYPE_STRING); -- cgit v1.2.3 From 7f4ac7cc08765cd139d6c3ac1f3d501598eb6324 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Thu, 11 Jul 2013 15:37:33 -0400 Subject: Fixed deprecations --- src/app-section.c | 2 +- src/ido-detail-label.c | 7 ++++--- src/messages-service.c | 3 --- 3 files changed, 5 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/app-section.c b/src/app-section.c index 6aac52a..823d75a 100644 --- a/src/app-section.c +++ b/src/app-section.c @@ -302,7 +302,7 @@ nick_activate_cb (GSimpleAction *action, g_return_if_fail(priv->ids != NULL); - if (!indicator_desktop_shortcuts_nick_exec(priv->ids, nick)) { + if (!indicator_desktop_shortcuts_nick_exec_with_context(priv->ids, nick, NULL)) { g_warning("Unable to execute nick '%s' for desktop file '%s'", nick, g_desktop_app_info_get_filename (priv->appinfo)); } diff --git a/src/ido-detail-label.c b/src/ido-detail-label.c index 780a2dd..74af602 100644 --- a/src/ido-detail-label.c +++ b/src/ido-detail-label.c @@ -139,9 +139,10 @@ gtk_widget_get_font_metrics (GtkWidget *widget, PangoContext *context) { const PangoFontDescription *font; - - font = gtk_style_context_get_font (gtk_widget_get_style_context (widget), - gtk_widget_get_state_flags (widget)); + GtkStyleContext *style; + style = gtk_widget_get_style_context (GTK_WIDGET (widget)); + gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, + "font", &font, NULL); return pango_context_get_metrics (context, font, diff --git a/src/messages-service.c b/src/messages-service.c index b36a0a2..8f64478 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -622,9 +622,6 @@ main (int argc, char ** argv) GMainLoop * mainloop = NULL; IndicatorService * service = NULL; - /* Glib init */ - g_type_init(); - mainloop = g_main_loop_new (NULL, FALSE); /* Create the Indicator Service interface */ -- cgit v1.2.3 From 3b39985ac5acdd739643e3d8b0c5f2e80548ef97 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 30 Jul 2013 14:50:52 +0200 Subject: Remove panel plugin --- src/Makefile.am | 39 ----- src/ido-detail-label.c | 400 ------------------------------------------- src/ido-detail-label.h | 59 ------- src/ido-menu-item.c | 425 ---------------------------------------------- src/ido-menu-item.h | 54 ------ src/im-app-menu-item.c | 351 -------------------------------------- src/im-app-menu-item.h | 54 ------ src/im-source-menu-item.c | 407 -------------------------------------------- src/im-source-menu-item.h | 54 ------ src/indicator-messages.c | 382 ----------------------------------------- 10 files changed, 2225 deletions(-) delete mode 100644 src/ido-detail-label.c delete mode 100644 src/ido-detail-label.h delete mode 100644 src/ido-menu-item.c delete mode 100644 src/ido-menu-item.h delete mode 100644 src/im-app-menu-item.c delete mode 100644 src/im-app-menu-item.h delete mode 100644 src/im-source-menu-item.c delete mode 100644 src/im-source-menu-item.h delete mode 100644 src/indicator-messages.c (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 5d8bad8..c011d5d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,45 +3,6 @@ EXTRA_DIST = libexec_PROGRAMS = indicator-messages-service - -###################################### -# Building the messages indicator -###################################### - -messaginglibdir = $(INDICATORDIR) -messaginglib_LTLIBRARIES = libmessaging.la -libmessaging_la_SOURCES = \ - indicator-messages.c \ - ido-menu-item.c \ - ido-menu-item.h \ - im-app-menu-item.c \ - im-app-menu-item.h \ - im-source-menu-item.c \ - im-source-menu-item.h \ - ido-detail-label.c \ - ido-detail-label.h \ - dbus-data.h -libmessaging_la_CFLAGS = \ - $(APPLET_CFLAGS) \ - $(COVERAGE_CFLAGS) \ - -I$(top_builddir)/common \ - -Wall \ - -Wl,-Bsymbolic-functions \ - -Wl,-z,defs \ - -Wl,--as-needed \ - -Werror \ - -DG_LOG_DOMAIN=\"Indicator-Messages\" -libmessaging_la_LIBADD = \ - $(top_builddir)/common/libmessaging-common.la \ - $(APPLET_LIBS) -lm -libmessaging_la_LDFLAGS = \ - $(COVERAGE_LDFLAGS) \ - -module -avoid-version - -###################################### -# Building the messages service -###################################### - indicator_messages_service_SOURCES = \ messages-service.c \ app-section.c \ diff --git a/src/ido-detail-label.c b/src/ido-detail-label.c deleted file mode 100644 index c97c06d..0000000 --- a/src/ido-detail-label.c +++ /dev/null @@ -1,400 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - * - * Authors: - * Lars Uebernickel - */ - -#include "ido-detail-label.h" - -#include - -G_DEFINE_TYPE (IdoDetailLabel, ido_detail_label, GTK_TYPE_WIDGET) - -struct _IdoDetailLabelPrivate -{ - gchar *text; - PangoLayout *layout; - gboolean draw_lozenge; -}; - -enum -{ - PROP_0, - PROP_TEXT, - NUM_PROPERTIES -}; - -static GParamSpec *properties[NUM_PROPERTIES]; - -static void -ido_detail_label_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - IdoDetailLabel *self = IDO_DETAIL_LABEL (object); - - switch (property_id) - { - case PROP_TEXT: - g_value_set_string (value, self->priv->text); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -ido_detail_label_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - IdoDetailLabel *self = IDO_DETAIL_LABEL (object); - - switch (property_id) - { - case PROP_TEXT: - ido_detail_label_set_text (self, g_value_get_string (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - - -static void -ido_detail_label_finalize (GObject *object) -{ - IdoDetailLabelPrivate *priv = IDO_DETAIL_LABEL (object)->priv; - - g_free (priv->text); - - G_OBJECT_CLASS (ido_detail_label_parent_class)->finalize (object); -} - -static void -ido_detail_label_dispose (GObject *object) -{ - IdoDetailLabelPrivate *priv = IDO_DETAIL_LABEL (object)->priv; - - g_clear_object (&priv->layout); - - G_OBJECT_CLASS (ido_detail_label_parent_class)->dispose (object); -} - -static void -ido_detail_label_ensure_layout (IdoDetailLabel *label) -{ - IdoDetailLabelPrivate *priv = label->priv; - - if (priv->layout == NULL) - { - priv->layout = gtk_widget_create_pango_layout (GTK_WIDGET (label), priv->text); - pango_layout_set_alignment (priv->layout, PANGO_ALIGN_CENTER); - pango_layout_set_ellipsize (priv->layout, PANGO_ELLIPSIZE_END); - pango_layout_set_height (priv->layout, -1); - - // TODO update layout on "style-updated" and "direction-changed" - } -} - -static void -cairo_lozenge (cairo_t *cr, - double x, - double y, - double w, - double h, - double radius) -{ - double x1 = x + w - radius; - double x2 = x + radius; - double y1 = y + radius; - double y2 = y + h - radius; - - cairo_move_to (cr, x + radius, y); - cairo_arc (cr, x1, y1, radius, G_PI * 1.5, G_PI * 2); - cairo_arc (cr, x1, y2, radius, 0, G_PI * 0.5); - cairo_arc (cr, x2, y2, radius, G_PI * 0.5, G_PI); - cairo_arc (cr, x2, y1, radius, G_PI, G_PI * 1.5); -} - -static PangoFontMetrics * -gtk_widget_get_font_metrics (GtkWidget *widget, - PangoContext *context) -{ - PangoFontMetrics *font_metrics; - PangoFontDescription *font; - GtkStyleContext *style; - style = gtk_widget_get_style_context (GTK_WIDGET (widget)); - gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, - "font", &font, NULL); - - font_metrics = pango_context_get_metrics (context, - font, - pango_context_get_language (context)); - pango_font_description_free (font); - return font_metrics; -} - -static gint -ido_detail_label_get_minimum_text_width (IdoDetailLabel *label) -{ - IdoDetailLabelPrivate *priv = label->priv; - PangoContext *context; - PangoFontMetrics *metrics; - gint char_width; - gint w; - - context = pango_layout_get_context (priv->layout); - metrics = gtk_widget_get_font_metrics (GTK_WIDGET (label), context); - char_width = pango_font_metrics_get_approximate_digit_width (metrics); - - w = 2 * char_width / PANGO_SCALE; - pango_font_metrics_unref (metrics); - return w; -} - -static gboolean -ido_detail_label_draw (GtkWidget *widget, - cairo_t *cr) -{ - IdoDetailLabel *label = IDO_DETAIL_LABEL (widget); - IdoDetailLabelPrivate *priv = IDO_DETAIL_LABEL (widget)->priv; - PangoRectangle extents; - GtkAllocation allocation; - double x, w, h, radius; - GdkRGBA color; - - if (!priv->text || !*priv->text) - return TRUE; - - gtk_widget_get_allocation (widget, &allocation); - - ido_detail_label_ensure_layout (IDO_DETAIL_LABEL (widget)); - - pango_layout_get_extents (priv->layout, NULL, &extents); - pango_extents_to_pixels (&extents, NULL); - - h = MIN (allocation.height, extents.height); - radius = floor (h / 2.0); - w = MAX (ido_detail_label_get_minimum_text_width (label), extents.width) + 2.0 * radius; - x = allocation.width - w; - - pango_layout_set_width (priv->layout, (allocation.width - 2 * radius) * PANGO_SCALE); - pango_layout_get_extents (priv->layout, NULL, &extents); - pango_extents_to_pixels (&extents, NULL); - - gtk_style_context_get_color (gtk_widget_get_style_context (widget), - gtk_widget_get_state_flags (widget), - &color); - gdk_cairo_set_source_rgba (cr, &color); - - cairo_set_line_width (cr, 1.0); - cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); - - if (priv->draw_lozenge) - cairo_lozenge (cr, x, 0.0, w, h, radius); - - cairo_move_to (cr, x + radius, (allocation.height - extents.height) / 2.0); - pango_cairo_layout_path (cr, priv->layout); - cairo_fill (cr); - - return TRUE; -} - -static void -ido_detail_label_get_preferred_width (GtkWidget *widget, - gint *minimum, - gint *natural) -{ - IdoDetailLabelPrivate *priv = IDO_DETAIL_LABEL (widget)->priv; - PangoRectangle extents; - double radius; - - ido_detail_label_ensure_layout (IDO_DETAIL_LABEL (widget)); - - pango_layout_get_extents (priv->layout, NULL, &extents); - pango_extents_to_pixels (&extents, NULL); - - radius = floor (extents.height / 2.0); - - *minimum = ido_detail_label_get_minimum_text_width (IDO_DETAIL_LABEL (widget)) + 2.0 * radius; - *natural = MAX (*minimum, extents.width + 2.0 * radius); -} - -static void -ido_detail_label_get_preferred_height (GtkWidget *widget, - gint *minimum, - gint *natural) -{ - IdoDetailLabelPrivate *priv = IDO_DETAIL_LABEL (widget)->priv; - PangoContext *context; - PangoFontMetrics *metrics; - PangoRectangle extents; - - ido_detail_label_ensure_layout (IDO_DETAIL_LABEL (widget)); - - pango_layout_get_extents (priv->layout, NULL, &extents); - pango_extents_to_pixels (&extents, NULL); - context = pango_layout_get_context (priv->layout); - metrics = gtk_widget_get_font_metrics (widget, context); - - *minimum = *natural = (pango_font_metrics_get_ascent (metrics) + - pango_font_metrics_get_descent (metrics)) / PANGO_SCALE; - - pango_font_metrics_unref (metrics); -} - -static void -ido_detail_label_class_init (IdoDetailLabelClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->get_property = ido_detail_label_get_property; - object_class->set_property = ido_detail_label_set_property; - object_class->finalize = ido_detail_label_finalize; - object_class->dispose = ido_detail_label_dispose; - - widget_class->draw = ido_detail_label_draw; - widget_class->get_preferred_width = ido_detail_label_get_preferred_width; - widget_class->get_preferred_height = ido_detail_label_get_preferred_height; - - g_type_class_add_private (klass, sizeof (IdoDetailLabelPrivate)); - - properties[PROP_TEXT] = g_param_spec_string ("text", - "Text", - "The text of the label", - NULL, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties (object_class, NUM_PROPERTIES, properties); -} - -static void -ido_detail_label_init (IdoDetailLabel *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - IDO_TYPE_DETAIL_LABEL, - IdoDetailLabelPrivate); - - gtk_widget_set_has_window (GTK_WIDGET (self), FALSE); -} - -GtkWidget * -ido_detail_label_new (const gchar *label) -{ - return g_object_new (IDO_TYPE_DETAIL_LABEL, - "text", label, - NULL); -} - -const gchar * -ido_detail_label_get_text (IdoDetailLabel *label) -{ - g_return_val_if_fail (IDO_IS_DETAIL_LABEL (label), NULL); - return label->priv->text; -} - -/* collapse_whitespace: - * @str: the source string - * - * Collapses all occurences of consecutive whitespace charactes in @str - * into a single space. - * - * Returns: (transfer full): a newly-allocated string - */ -static gchar * -collapse_whitespace (const gchar *str) -{ - GString *result; - gboolean in_space = FALSE; - - if (str == NULL) - return NULL; - - result = g_string_new (""); - - while (*str) - { - gunichar c = g_utf8_get_char_validated (str, -1); - - if (c < 0) - break; - - if (!g_unichar_isspace (c)) - { - g_string_append_unichar (result, c); - in_space = FALSE; - } - else if (!in_space) - { - g_string_append_c (result, ' '); - in_space = TRUE; - } - - str = g_utf8_next_char (str); - } - - return g_string_free (result, FALSE); -} - -static void -ido_detail_label_set_text_impl (IdoDetailLabel *label, - const gchar *text, - gboolean draw_lozenge) -{ - IdoDetailLabelPrivate * priv = label->priv; - - g_clear_object (&priv->layout); - g_free (priv->text); - - priv->text = g_strdup (text); - priv->draw_lozenge = draw_lozenge; - - g_object_notify_by_pspec (G_OBJECT (label), properties[PROP_TEXT]); - gtk_widget_queue_resize (GTK_WIDGET (label)); -} - -void -ido_detail_label_set_text (IdoDetailLabel *label, - const gchar *text) -{ - gchar *str; - - g_return_if_fail (IDO_IS_DETAIL_LABEL (label)); - - str = collapse_whitespace (text); - ido_detail_label_set_text_impl (label, str, FALSE); - g_free (str); -} - -void -ido_detail_label_set_count (IdoDetailLabel *label, - gint count) -{ - gchar *text; - - g_return_if_fail (IDO_IS_DETAIL_LABEL (label)); - - text = g_strdup_printf ("%d", count); - ido_detail_label_set_text_impl (label, text, TRUE); - g_free (text); -} diff --git a/src/ido-detail-label.h b/src/ido-detail-label.h deleted file mode 100644 index 1995fee..0000000 --- a/src/ido-detail-label.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - * - * Authors: - * Lars Uebernickel - */ - -#ifndef __IDO_DETAIL_LABEL_H__ -#define __IDO_DETAIL_LABEL_H__ - -#include - -#define IDO_TYPE_DETAIL_LABEL (ido_detail_label_get_type()) -#define IDO_DETAIL_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_TYPE_DETAIL_LABEL, IdoDetailLabel)) -#define IDO_DETAIL_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IDO_TYPE_DETAIL_LABEL, IdoDetailLabelClass)) -#define IDO_IS_DETAIL_LABEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_TYPE_DETAIL_LABEL)) -#define IDO_IS_DETAIL_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IDO_TYPE_DETAIL_LABEL)) -#define IDO_DETAIL_LABEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IDO_TYPE_DETAIL_LABEL, IdoDetailLabelClass)) - -typedef struct _IdoDetailLabel IdoDetailLabel; -typedef struct _IdoDetailLabelClass IdoDetailLabelClass; -typedef struct _IdoDetailLabelPrivate IdoDetailLabelPrivate; - -struct _IdoDetailLabel -{ - GtkWidget parent; - IdoDetailLabelPrivate *priv; -}; - -struct _IdoDetailLabelClass -{ - GtkWidgetClass parent_class; -}; - -GType ido_detail_label_get_type (void) G_GNUC_CONST; - -GtkWidget * ido_detail_label_new (const gchar *str); - -const gchar * ido_detail_label_get_text (IdoDetailLabel *label); - -void ido_detail_label_set_text (IdoDetailLabel *label, - const gchar *text); - -void ido_detail_label_set_count (IdoDetailLabel *label, - gint count); - -#endif diff --git a/src/ido-menu-item.c b/src/ido-menu-item.c deleted file mode 100644 index 32044ff..0000000 --- a/src/ido-menu-item.c +++ /dev/null @@ -1,425 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - * - * Authors: - * Lars Uebernickel - */ - -#include "ido-menu-item.h" - -struct _IdoMenuItemPrivate -{ - GActionGroup *action_group; - gchar *action; - GVariant *target; - - GtkWidget *icon; - GtkWidget *label; - - gboolean has_indicator; - gboolean in_set_active; -}; - -enum -{ - PROP_0, - PROP_MENU_ITEM, - PROP_ACTION_GROUP, - NUM_PROPERTIES -}; - -static GParamSpec *properties[NUM_PROPERTIES]; - -G_DEFINE_TYPE (IdoMenuItem, ido_menu_item, GTK_TYPE_CHECK_MENU_ITEM); - -static void -ido_menu_item_constructed (GObject *object) -{ - IdoMenuItemPrivate *priv = IDO_MENU_ITEM (object)->priv; - GtkWidget *grid; - - priv->icon = g_object_ref (gtk_image_new ()); - gtk_widget_set_margin_right (priv->icon, 6); - - priv->label = g_object_ref (gtk_label_new ("")); - - grid = gtk_grid_new (); - gtk_grid_attach (GTK_GRID (grid), priv->icon, 0, 0, 1, 1); - gtk_grid_attach (GTK_GRID (grid), priv->label, 1, 0, 1, 1); - - gtk_container_add (GTK_CONTAINER (object), grid); - gtk_widget_show_all (grid); - - G_OBJECT_CLASS (ido_menu_item_parent_class)->constructed (object); -} - -static void -ido_menu_item_set_active (IdoMenuItem *self, - gboolean active) -{ - /* HACK gtk_check_menu_item_set_active calls gtk_menu_item_activate. - * Make sure our activate handler doesn't toggle the action as a - * result of calling this function. */ - - self->priv->in_set_active = TRUE; - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (self), active); - self->priv->in_set_active = FALSE; -} - -static void -ido_menu_item_set_has_indicator (IdoMenuItem *self, - gboolean has_indicator) -{ - if (has_indicator == self->priv->has_indicator) - return; - - self->priv->has_indicator = has_indicator; - - gtk_widget_queue_resize (GTK_WIDGET (self)); -} - -static void -ido_menu_item_set_state (IdoMenuItem *self, - GVariant *state) -{ - IdoMenuItemPrivate *priv = self->priv; - - if (priv->target) - { - ido_menu_item_set_has_indicator (self, TRUE); - ido_menu_item_set_active (self, FALSE); - gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (self), TRUE); - gtk_check_menu_item_set_inconsistent (GTK_CHECK_MENU_ITEM (self), FALSE); - - if (g_variant_is_of_type (state, G_VARIANT_TYPE_STRING)) - { - ido_menu_item_set_active (self, g_variant_equal (priv->target, state)); - } - else if (g_variant_is_of_type (state, G_VARIANT_TYPE ("as")) && - g_variant_is_of_type (priv->target, G_VARIANT_TYPE_STRING)) - { - const gchar *target_str; - const gchar **state_strs; - const gchar **it; - - target_str = g_variant_get_string (priv->target, NULL); - state_strs = g_variant_get_strv (state, NULL); - - it = state_strs; - while (*it != NULL && !g_str_equal (*it, target_str)) - it++; - - if (*it != NULL) - { - ido_menu_item_set_active (self, TRUE); - gtk_check_menu_item_set_inconsistent (GTK_CHECK_MENU_ITEM (self), - g_strv_length ((gchar **)state_strs) > 1); - } - - g_free (state_strs); - } - } - else if (g_variant_is_of_type (state, G_VARIANT_TYPE_BOOLEAN)) - { - ido_menu_item_set_has_indicator (self, TRUE); - gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (self), FALSE); - ido_menu_item_set_active (self, g_variant_get_boolean (state)); - } - else - { - ido_menu_item_set_has_indicator (self, FALSE); - } -} - -static void -ido_menu_item_set_action_name (IdoMenuItem *self, - const gchar *action_name) -{ - IdoMenuItemPrivate *priv = self->priv; - gboolean enabled = FALSE; - GVariant *state; - const GVariantType *param_type; - - if (priv->action != NULL) - g_free (priv->action); - - priv->action = g_strdup (action_name); - - if (priv->action_group != NULL && priv->action != NULL && - g_action_group_query_action (priv->action_group, priv->action, - &enabled, ¶m_type, NULL, NULL, &state)) - { - gtk_widget_set_sensitive (GTK_WIDGET (self), enabled); - - if (state) - { - ido_menu_item_set_state (self, state); - g_variant_unref (state); - } - } - else - { - ido_menu_item_set_active (self, FALSE); - gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE); - ido_menu_item_set_has_indicator (self, FALSE); - } -} - -static void -ido_menu_item_action_added (GActionGroup *action_group, - gchar *action_name, - gpointer user_data) -{ - IdoMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - ido_menu_item_set_action_name (self, action_name); -} - -static void -ido_menu_item_action_removed (GActionGroup *action_group, - gchar *action_name, - gpointer user_data) -{ - IdoMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - { - gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE); - } -} - -static void -ido_menu_item_action_enabled_changed (GActionGroup *action_group, - gchar *action_name, - gboolean enabled, - gpointer user_data) -{ - IdoMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - gtk_widget_set_sensitive (GTK_WIDGET (self), enabled); -} - -static void -ido_menu_item_action_state_changed (GActionGroup *action_group, - gchar *action_name, - GVariant *value, - gpointer user_data) -{ - IdoMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - ido_menu_item_set_state (self, value); -} - -static void -ido_menu_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - IdoMenuItem *self = IDO_MENU_ITEM (object); - - switch (property_id) - { - case PROP_MENU_ITEM: - ido_menu_item_set_menu_item (self, G_MENU_ITEM (g_value_get_object (value))); - break; - - case PROP_ACTION_GROUP: - ido_menu_item_set_action_group (self, G_ACTION_GROUP (g_value_get_object (value))); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -ido_menu_item_dispose (GObject *object) -{ - IdoMenuItem *self = IDO_MENU_ITEM (object); - - if (self->priv->action_group) - ido_menu_item_set_action_group (self, NULL); - - g_clear_object (&self->priv->icon); - g_clear_object (&self->priv->label); - - if (self->priv->target) - { - g_variant_unref (self->priv->target); - self->priv->target = NULL; - } - - G_OBJECT_CLASS (ido_menu_item_parent_class)->dispose (object); -} - -static void -ido_menu_item_finalize (GObject *object) -{ - IdoMenuItemPrivate *priv = IDO_MENU_ITEM (object)->priv; - - g_free (priv->action); - - G_OBJECT_CLASS (ido_menu_item_parent_class)->finalize (object); -} - -static void -ido_menu_item_activate (GtkMenuItem *item) -{ - IdoMenuItemPrivate *priv = IDO_MENU_ITEM (item)->priv; - - /* see ido_menu_item_set_active */ - if (!priv->in_set_active && priv->action && priv->action_group) - g_action_group_activate_action (priv->action_group, priv->action, priv->target); - - if (priv->in_set_active) - GTK_MENU_ITEM_CLASS (ido_menu_item_parent_class)->activate (item); -} - -static void -ido_menu_item_draw_indicator (GtkCheckMenuItem *item, - cairo_t *cr) -{ - IdoMenuItem *self = IDO_MENU_ITEM (item); - - if (self->priv->has_indicator) - GTK_CHECK_MENU_ITEM_CLASS (ido_menu_item_parent_class) - ->draw_indicator (item, cr); -} - -static void -ido_menu_item_class_init (IdoMenuItemClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkMenuItemClass *menu_item_class = GTK_MENU_ITEM_CLASS (klass); - GtkCheckMenuItemClass *check_class = GTK_CHECK_MENU_ITEM_CLASS (klass); - - g_type_class_add_private (klass, sizeof (IdoMenuItemPrivate)); - - object_class->constructed = ido_menu_item_constructed; - object_class->set_property = ido_menu_set_property; - object_class->dispose = ido_menu_item_dispose; - object_class->finalize = ido_menu_item_finalize; - - menu_item_class->activate = ido_menu_item_activate; - - check_class->draw_indicator = ido_menu_item_draw_indicator; - - properties[PROP_MENU_ITEM] = g_param_spec_object ("menu-item", - "Menu item", - "The model GMenuItem for this menu item", - G_TYPE_MENU_ITEM, - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS); - - properties[PROP_ACTION_GROUP] = g_param_spec_object ("action-group", - "Action group", - "The action group associated with this menu item", - G_TYPE_ACTION_GROUP, - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties (object_class, NUM_PROPERTIES, properties); -} - -static void -ido_menu_item_init (IdoMenuItem *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - IDO_TYPE_MENU_ITEM, - IdoMenuItemPrivate); -} - -void -ido_menu_item_set_menu_item (IdoMenuItem *self, - GMenuItem *menuitem) -{ - gchar *iconstr = NULL; - GIcon *icon = NULL; - gchar *label = NULL; - gchar *action = NULL; - - if (g_menu_item_get_attribute (menuitem, "x-canonical-icon", "s", &iconstr)) - { - GError *error; - - /* only indent the label if icon is set to "" */ - if (iconstr[0] == '\0') - { - gint width; - - gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, NULL); - gtk_widget_set_size_request (self->priv->icon, width, -1); - } - else - { - icon = g_icon_new_for_string (iconstr, &error); - if (icon == NULL) - { - g_warning ("unable to set icon: %s", error->message); - g_error_free (error); - } - } - g_free (iconstr); - } - gtk_image_set_from_gicon (GTK_IMAGE (self->priv->icon), icon, GTK_ICON_SIZE_MENU); - - g_menu_item_get_attribute (menuitem, "label", "s", &label); - gtk_label_set_label (GTK_LABEL (self->priv->label), label ? label : ""); - - self->priv->target = g_menu_item_get_attribute_value (menuitem, "target", NULL); - - g_menu_item_get_attribute (menuitem, "action", "s", &action); - ido_menu_item_set_action_name (self, action); - - if (icon) - g_object_unref (icon); - g_free (label); - g_free (action); -} - -void -ido_menu_item_set_action_group (IdoMenuItem *self, - GActionGroup *action_group) -{ - IdoMenuItemPrivate *priv = self->priv; - - if (priv->action_group != NULL) - { - g_signal_handlers_disconnect_by_func (priv->action_group, ido_menu_item_action_added, self); - g_signal_handlers_disconnect_by_func (priv->action_group, ido_menu_item_action_removed, self); - g_signal_handlers_disconnect_by_func (priv->action_group, ido_menu_item_action_enabled_changed, self); - g_signal_handlers_disconnect_by_func (priv->action_group, ido_menu_item_action_state_changed, self); - - g_clear_object (&priv->action_group); - } - - if (action_group != NULL) - { - priv->action_group = g_object_ref (action_group); - - g_signal_connect (priv->action_group, "action-added", - G_CALLBACK (ido_menu_item_action_added), self); - g_signal_connect (priv->action_group, "action-removed", - G_CALLBACK (ido_menu_item_action_removed), self); - g_signal_connect (priv->action_group, "action-enabled-changed", - G_CALLBACK (ido_menu_item_action_enabled_changed), self); - g_signal_connect (priv->action_group, "action-state-changed", - G_CALLBACK (ido_menu_item_action_state_changed), self); - } -} diff --git a/src/ido-menu-item.h b/src/ido-menu-item.h deleted file mode 100644 index 0521928..0000000 --- a/src/ido-menu-item.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - * - * Authors: - * Lars Uebernickel - */ - -#ifndef __IDO_MENU_ITEM_H__ -#define __IDO_MENU_ITEM_H__ - -#include - -#define IDO_TYPE_MENU_ITEM (ido_menu_item_get_type ()) -#define IDO_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_TYPE_MENU_ITEM, IdoMenuItem)) -#define IDO_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IDO_TYPE_MENU_ITEM, IdoMenuItemClass)) -#define IS_IDO_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_TYPE_MENU_ITEM)) -#define IS_IDO_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IDO_TYPE_MENU_ITEM)) -#define IDO_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IDO_TYPE_MENU_ITEM, IdoMenuItemClass)) - -typedef struct _IdoMenuItem IdoMenuItem; -typedef struct _IdoMenuItemClass IdoMenuItemClass; -typedef struct _IdoMenuItemPrivate IdoMenuItemPrivate; - -struct _IdoMenuItemClass -{ - GtkCheckMenuItemClass parent_class; -}; - -struct _IdoMenuItem -{ - GtkCheckMenuItem parent; - IdoMenuItemPrivate *priv; -}; - -GType ido_menu_item_get_type (void); - -void ido_menu_item_set_menu_item (IdoMenuItem *item, - GMenuItem *menuitem); -void ido_menu_item_set_action_group (IdoMenuItem *self, - GActionGroup *action_group); - -#endif diff --git a/src/im-app-menu-item.c b/src/im-app-menu-item.c deleted file mode 100644 index a204631..0000000 --- a/src/im-app-menu-item.c +++ /dev/null @@ -1,351 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - * - * Authors: - * Lars Uebernickel - */ - -#include "im-app-menu-item.h" - -struct _ImAppMenuItemPrivate -{ - GActionGroup *action_group; - gchar *action; - gboolean is_running; - - GtkWidget *icon; - GtkWidget *label; -}; - -enum -{ - PROP_0, - PROP_MENU_ITEM, - PROP_ACTION_GROUP, - NUM_PROPERTIES -}; - -static GParamSpec *properties[NUM_PROPERTIES]; - -G_DEFINE_TYPE (ImAppMenuItem, im_app_menu_item, GTK_TYPE_MENU_ITEM); - -static void -im_app_menu_item_constructed (GObject *object) -{ - ImAppMenuItemPrivate *priv = IM_APP_MENU_ITEM (object)->priv; - GtkWidget *grid; - - priv->icon = g_object_ref (gtk_image_new ()); - gtk_widget_set_margin_right (priv->icon, 6); - - priv->label = g_object_ref (gtk_label_new ("")); - - grid = gtk_grid_new (); - gtk_grid_attach (GTK_GRID (grid), priv->icon, 0, 0, 1, 1); - gtk_grid_attach (GTK_GRID (grid), priv->label, 1, 0, 1, 1); - - gtk_container_add (GTK_CONTAINER (object), grid); - gtk_widget_show_all (grid); - - G_OBJECT_CLASS (im_app_menu_item_parent_class)->constructed (object); -} - -static void -im_app_menu_item_set_action_name (ImAppMenuItem *self, - const gchar *action_name) -{ - ImAppMenuItemPrivate *priv = self->priv; - gboolean enabled = FALSE; - GVariant *state; - - if (priv->action != NULL) - g_free (priv->action); - - priv->action = g_strdup (action_name); - - priv->is_running = FALSE; - - if (priv->action_group != NULL && priv->action != NULL && - g_action_group_query_action (priv->action_group, priv->action, - &enabled, NULL, NULL, NULL, &state)) - { - if (state && g_variant_is_of_type (state, G_VARIANT_TYPE ("b"))) - priv->is_running = g_variant_get_boolean (state); - else - enabled = FALSE; - - if (state) - g_variant_unref (state); - } - - gtk_widget_set_sensitive (GTK_WIDGET (self), enabled); - gtk_widget_queue_draw (GTK_WIDGET (self)); -} - -static void -im_app_menu_item_action_added (GActionGroup *action_group, - gchar *action_name, - gpointer user_data) -{ - ImAppMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - im_app_menu_item_set_action_name (self, action_name); -} - -static void -im_app_menu_item_action_removed (GActionGroup *action_group, - gchar *action_name, - gpointer user_data) -{ - ImAppMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - { - gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE); - self->priv->is_running = FALSE; - gtk_widget_queue_draw (GTK_WIDGET (self)); - } -} - -static void -im_app_menu_item_action_enabled_changed (GActionGroup *action_group, - gchar *action_name, - gboolean enabled, - gpointer user_data) -{ - ImAppMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - gtk_widget_set_sensitive (GTK_WIDGET (self), enabled); -} - -static void -im_app_menu_item_action_state_changed (GActionGroup *action_group, - gchar *action_name, - GVariant *value, - gpointer user_data) -{ - ImAppMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - { - g_return_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE ("b"))); - - self->priv->is_running = g_variant_get_boolean (value); - gtk_widget_queue_draw (GTK_WIDGET (self)); - } -} - -static void -im_app_menu_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ImAppMenuItem *self = IM_APP_MENU_ITEM (object); - - switch (property_id) - { - case PROP_MENU_ITEM: - im_app_menu_item_set_menu_item (self, G_MENU_ITEM (g_value_get_object (value))); - break; - - case PROP_ACTION_GROUP: - im_app_menu_item_set_action_group (self, G_ACTION_GROUP (g_value_get_object (value))); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -im_app_menu_item_dispose (GObject *object) -{ - ImAppMenuItem *self = IM_APP_MENU_ITEM (object); - - if (self->priv->action_group) - im_app_menu_item_set_action_group (self, NULL); - - g_clear_object (&self->priv->icon); - g_clear_object (&self->priv->label); - - G_OBJECT_CLASS (im_app_menu_item_parent_class)->dispose (object); -} - -static void -im_app_menu_item_finalize (GObject *object) -{ - ImAppMenuItemPrivate *priv = IM_APP_MENU_ITEM (object)->priv; - - g_free (priv->action); - - G_OBJECT_CLASS (im_app_menu_item_parent_class)->finalize (object); -} - -static gboolean -im_app_menu_item_draw (GtkWidget *widget, - cairo_t *cr) -{ - ImAppMenuItemPrivate *priv = IM_APP_MENU_ITEM (widget)->priv; - - GTK_WIDGET_CLASS (im_app_menu_item_parent_class)->draw (widget, cr); - - if (priv->is_running) - { - const int arrow_width = 5; - const double half_arrow_height = 4.5; - GtkAllocation alloc; - GdkRGBA color; - double center; - - gtk_widget_get_allocation (widget, &alloc); - - gtk_style_context_get_color (gtk_widget_get_style_context (widget), - gtk_widget_get_state_flags (widget), - &color); - gdk_cairo_set_source_rgba (cr, &color); - - center = alloc.height / 2 + 0.5; - - cairo_move_to (cr, 0, center - half_arrow_height); - cairo_line_to (cr, 0, center + half_arrow_height); - cairo_line_to (cr, arrow_width, center); - cairo_close_path (cr); - - cairo_fill (cr); - } - - return FALSE; -} - -static void -im_app_menu_item_activate (GtkMenuItem *item) -{ - ImAppMenuItemPrivate *priv = IM_APP_MENU_ITEM (item)->priv; - - if (priv->action && priv->action_group) - g_action_group_activate_action (priv->action_group, priv->action, NULL); -} - -static void -im_app_menu_item_class_init (ImAppMenuItemClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - GtkMenuItemClass *menu_item_class = GTK_MENU_ITEM_CLASS (klass); - - g_type_class_add_private (klass, sizeof (ImAppMenuItemPrivate)); - - object_class->constructed = im_app_menu_item_constructed; - object_class->set_property = im_app_menu_set_property; - object_class->dispose = im_app_menu_item_dispose; - object_class->finalize = im_app_menu_item_finalize; - - widget_class->draw = im_app_menu_item_draw; - - menu_item_class->activate = im_app_menu_item_activate; - - properties[PROP_MENU_ITEM] = g_param_spec_object ("menu-item", - "Menu item", - "The model GMenuItem for this menu item", - G_TYPE_MENU_ITEM, - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS); - - properties[PROP_ACTION_GROUP] = g_param_spec_object ("action-group", - "Action group", - "The action group associated with this menu item", - G_TYPE_ACTION_GROUP, - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties (object_class, NUM_PROPERTIES, properties); -} - -static void -im_app_menu_item_init (ImAppMenuItem *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - IM_TYPE_APP_MENU_ITEM, - ImAppMenuItemPrivate); -} - -void -im_app_menu_item_set_menu_item (ImAppMenuItem *self, - GMenuItem *menuitem) -{ - gchar *iconstr = NULL; - GIcon *icon = NULL; - gchar *label; - gchar *action = NULL; - - if (g_menu_item_get_attribute (menuitem, "x-canonical-icon", "s", &iconstr)) - { - GError *error; - - icon = g_icon_new_for_string (iconstr, &error); - if (icon == NULL) - { - g_warning ("unable to set icon: %s", error->message); - g_error_free (error); - } - g_free (iconstr); - } - gtk_image_set_from_gicon (GTK_IMAGE (self->priv->icon), icon, GTK_ICON_SIZE_MENU); - - g_menu_item_get_attribute (menuitem, "label", "s", &label); - gtk_label_set_label (GTK_LABEL (self->priv->label), label ? label : ""); - - g_menu_item_get_attribute (menuitem, "action", "s", &action); - im_app_menu_item_set_action_name (self, action); - - if (icon) - g_object_unref (icon); - g_free (label); - g_free (action); -} - -void -im_app_menu_item_set_action_group (ImAppMenuItem *self, - GActionGroup *action_group) -{ - ImAppMenuItemPrivate *priv = self->priv; - - if (priv->action_group != NULL) - { - g_signal_handlers_disconnect_by_func (priv->action_group, im_app_menu_item_action_added, self); - g_signal_handlers_disconnect_by_func (priv->action_group, im_app_menu_item_action_removed, self); - g_signal_handlers_disconnect_by_func (priv->action_group, im_app_menu_item_action_enabled_changed, self); - g_signal_handlers_disconnect_by_func (priv->action_group, im_app_menu_item_action_state_changed, self); - - g_clear_object (&priv->action_group); - } - - if (action_group != NULL) - { - priv->action_group = g_object_ref (action_group); - - g_signal_connect (priv->action_group, "action-added", - G_CALLBACK (im_app_menu_item_action_added), self); - g_signal_connect (priv->action_group, "action-removed", - G_CALLBACK (im_app_menu_item_action_removed), self); - g_signal_connect (priv->action_group, "action-enabled-changed", - G_CALLBACK (im_app_menu_item_action_enabled_changed), self); - g_signal_connect (priv->action_group, "action-state-changed", - G_CALLBACK (im_app_menu_item_action_state_changed), self); - } -} diff --git a/src/im-app-menu-item.h b/src/im-app-menu-item.h deleted file mode 100644 index 519de8d..0000000 --- a/src/im-app-menu-item.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - * - * Authors: - * Lars Uebernickel - */ - -#ifndef __IM_APP_MENU_ITEM_H__ -#define __IM_APP_MENU_ITEM_H__ - -#include - -#define IM_TYPE_APP_MENU_ITEM (im_app_menu_item_get_type ()) -#define IM_APP_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_TYPE_APP_MENU_ITEM, ImAppMenuItem)) -#define IM_APP_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IM_TYPE_APP_MENU_ITEM, ImAppMenuItemClass)) -#define IS_IM_APP_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IM_TYPE_APP_MENU_ITEM)) -#define IS_IM_APP_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IM_TYPE_APP_MENU_ITEM)) -#define IM_APP_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IM_TYPE_APP_MENU_ITEM, ImAppMenuItemClass)) - -typedef struct _ImAppMenuItem ImAppMenuItem; -typedef struct _ImAppMenuItemClass ImAppMenuItemClass; -typedef struct _ImAppMenuItemPrivate ImAppMenuItemPrivate; - -struct _ImAppMenuItemClass -{ - GtkMenuItemClass parent_class; -}; - -struct _ImAppMenuItem -{ - GtkMenuItem parent; - ImAppMenuItemPrivate *priv; -}; - -GType im_app_menu_item_get_type (void); - -void im_app_menu_item_set_menu_item (ImAppMenuItem *item, - GMenuItem *menuitem); -void im_app_menu_item_set_action_group (ImAppMenuItem *self, - GActionGroup *action_group); - -#endif diff --git a/src/im-source-menu-item.c b/src/im-source-menu-item.c deleted file mode 100644 index 775fa91..0000000 --- a/src/im-source-menu-item.c +++ /dev/null @@ -1,407 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - * - * Authors: - * Lars Uebernickel - */ - -#include "im-source-menu-item.h" - -#include -#include "ido-detail-label.h" - -struct _ImSourceMenuItemPrivate -{ - GActionGroup *action_group; - gchar *action; - - GtkWidget *icon; - GtkWidget *label; - GtkWidget *detail; - - gint64 time; - guint timer_id; -}; - -enum -{ - PROP_0, - PROP_MENU_ITEM, - PROP_ACTION_GROUP, - NUM_PROPERTIES -}; - -static GParamSpec *properties[NUM_PROPERTIES]; - -G_DEFINE_TYPE (ImSourceMenuItem, im_source_menu_item, GTK_TYPE_MENU_ITEM); - -static void -im_source_menu_item_constructed (GObject *object) -{ - ImSourceMenuItemPrivate *priv = IM_SOURCE_MENU_ITEM (object)->priv; - GtkWidget *grid; - gint icon_width; - - gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_width, NULL); - - priv->icon = g_object_ref (gtk_image_new ()); - gtk_widget_set_margin_left (priv->icon, icon_width + 6); - - priv->label = g_object_ref (gtk_label_new ("")); - gtk_label_set_max_width_chars (GTK_LABEL (priv->label), 40); - gtk_label_set_ellipsize (GTK_LABEL (priv->label), PANGO_ELLIPSIZE_END); - gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.5); - - priv->detail = g_object_ref (ido_detail_label_new ("")); - gtk_widget_set_halign (priv->detail, GTK_ALIGN_END); - gtk_widget_set_hexpand (priv->detail, TRUE); - gtk_style_context_add_class (gtk_widget_get_style_context (priv->detail), "accelerator"); - - grid = gtk_grid_new (); - gtk_grid_attach (GTK_GRID (grid), priv->icon, 0, 0, 1, 1); - gtk_grid_attach (GTK_GRID (grid), priv->label, 1, 0, 1, 1); - gtk_grid_attach (GTK_GRID (grid), priv->detail, 2, 0, 1, 1); - - gtk_container_add (GTK_CONTAINER (object), grid); - gtk_widget_show_all (grid); - - G_OBJECT_CLASS (im_source_menu_item_parent_class)->constructed (object); -} - -static gchar * -im_source_menu_item_time_span_string (gint64 timestamp) -{ - gchar *str; - gint64 span; - gint hours; - gint minutes; - - span = MAX (g_get_real_time () - timestamp, 0) / G_USEC_PER_SEC; - hours = span / 3600; - minutes = (span / 60) % 60; - - if (hours == 0) - { - /* TRANSLATORS: number of minutes that have passed */ - str = g_strdup_printf (ngettext ("%d m", "%d m", minutes), minutes); - } - else - { - /* TRANSLATORS: number of hours that have passed */ - str = g_strdup_printf (ngettext ("%d h", "%d h", hours), hours); - } - - return str; -} - -static void -im_source_menu_item_set_detail_time (ImSourceMenuItem *self, - gint64 time) -{ - ImSourceMenuItemPrivate *priv = self->priv; - gchar *str; - - priv->time = time; - - str = im_source_menu_item_time_span_string (priv->time); - ido_detail_label_set_text (IDO_DETAIL_LABEL (priv->detail), str); - - g_free (str); -} - -static gboolean -im_source_menu_item_update_time (gpointer data) -{ - ImSourceMenuItem *self = data; - - im_source_menu_item_set_detail_time (self, self->priv->time); - - return TRUE; -} - -static gboolean -im_source_menu_item_set_state (ImSourceMenuItem *self, - GVariant *state) -{ - ImSourceMenuItemPrivate *priv = self->priv; - guint32 count; - gint64 time; - const gchar *str; - - if (priv->timer_id != 0) - { - g_source_remove (priv->timer_id); - priv->timer_id = 0; - } - - g_return_val_if_fail (g_variant_is_of_type (state, G_VARIANT_TYPE ("(uxsb)")), FALSE); - - g_variant_get (state, "(ux&sb)", &count, &time, &str, NULL); - - if (count != 0) - ido_detail_label_set_count (IDO_DETAIL_LABEL (priv->detail), count); - else if (time != 0) - { - im_source_menu_item_set_detail_time (self, time); - priv->timer_id = g_timeout_add_seconds (59, im_source_menu_item_update_time, self); - } - else if (str != NULL && *str) - ido_detail_label_set_text (IDO_DETAIL_LABEL (priv->detail), str); - - return TRUE; -} - -static void -im_source_menu_item_set_action_name (ImSourceMenuItem *self, - const gchar *action_name) -{ - ImSourceMenuItemPrivate *priv = self->priv; - gboolean enabled = FALSE; - GVariant *state; - - if (priv->action != NULL) - g_free (priv->action); - - priv->action = g_strdup (action_name); - - if (priv->action_group != NULL && priv->action != NULL && - g_action_group_query_action (priv->action_group, priv->action, - &enabled, NULL, NULL, NULL, &state)) - { - if (!state || !im_source_menu_item_set_state (self, state)) - enabled = FALSE; - - if (state) - g_variant_unref (state); - } - - gtk_widget_set_sensitive (GTK_WIDGET (self), enabled); -} - -static void -im_source_menu_item_action_added (GActionGroup *action_group, - gchar *action_name, - gpointer user_data) -{ - ImSourceMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - im_source_menu_item_set_action_name (self, action_name); -} - -static void -im_source_menu_item_action_removed (GActionGroup *action_group, - gchar *action_name, - gpointer user_data) -{ - ImSourceMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - { - gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE); - } -} - -static void -im_source_menu_item_action_enabled_changed (GActionGroup *action_group, - gchar *action_name, - gboolean enabled, - gpointer user_data) -{ - ImSourceMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - gtk_widget_set_sensitive (GTK_WIDGET (self), enabled); -} - -static void -im_source_menu_item_action_state_changed (GActionGroup *action_group, - gchar *action_name, - GVariant *value, - gpointer user_data) -{ - ImSourceMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - im_source_menu_item_set_state (self, value); -} - -static void -im_source_menu_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ImSourceMenuItem *self = IM_SOURCE_MENU_ITEM (object); - - switch (property_id) - { - case PROP_MENU_ITEM: - im_source_menu_item_set_menu_item (self, G_MENU_ITEM (g_value_get_object (value))); - break; - - case PROP_ACTION_GROUP: - im_source_menu_item_set_action_group (self, G_ACTION_GROUP (g_value_get_object (value))); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -im_source_menu_item_dispose (GObject *object) -{ - ImSourceMenuItem *self = IM_SOURCE_MENU_ITEM (object); - - if (self->priv->timer_id != 0) - { - g_source_remove (self->priv->timer_id); - self->priv->timer_id = 0; - } - - if (self->priv->action_group) - im_source_menu_item_set_action_group (self, NULL); - - g_clear_object (&self->priv->icon); - g_clear_object (&self->priv->label); - g_clear_object (&self->priv->detail); - - G_OBJECT_CLASS (im_source_menu_item_parent_class)->dispose (object); -} - -static void -im_source_menu_item_finalize (GObject *object) -{ - ImSourceMenuItemPrivate *priv = IM_SOURCE_MENU_ITEM (object)->priv; - - g_free (priv->action); - - G_OBJECT_CLASS (im_source_menu_item_parent_class)->finalize (object); -} - -static void -im_source_menu_item_activate (GtkMenuItem *item) -{ - ImSourceMenuItemPrivate *priv = IM_SOURCE_MENU_ITEM (item)->priv; - - if (priv->action && priv->action_group) - g_action_group_activate_action (priv->action_group, priv->action, NULL); -} - -static void -im_source_menu_item_class_init (ImSourceMenuItemClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkMenuItemClass *menu_item_class = GTK_MENU_ITEM_CLASS (klass); - - g_type_class_add_private (klass, sizeof (ImSourceMenuItemPrivate)); - - object_class->constructed = im_source_menu_item_constructed; - object_class->set_property = im_source_menu_set_property; - object_class->dispose = im_source_menu_item_dispose; - object_class->finalize = im_source_menu_item_finalize; - - menu_item_class->activate = im_source_menu_item_activate; - - properties[PROP_MENU_ITEM] = g_param_spec_object ("menu-item", - "Menu item", - "The model GMenuItem for this menu item", - G_TYPE_MENU_ITEM, - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS); - - properties[PROP_ACTION_GROUP] = g_param_spec_object ("action-group", - "Action group", - "The action group associated with this menu item", - G_TYPE_ACTION_GROUP, - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties (object_class, NUM_PROPERTIES, properties); -} - -static void -im_source_menu_item_init (ImSourceMenuItem *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - IM_TYPE_SOURCE_MENU_ITEM, - ImSourceMenuItemPrivate); -} - -void -im_source_menu_item_set_menu_item (ImSourceMenuItem *self, - GMenuItem *menuitem) -{ - gchar *iconstr = NULL; - GIcon *icon = NULL; - gchar *label; - gchar *action = NULL; - - if (g_menu_item_get_attribute (menuitem, "x-canonical-icon", "s", &iconstr)) - { - GError *error; - icon = g_icon_new_for_string (iconstr, &error); - if (icon == NULL) - { - g_warning ("unable to set icon: %s", error->message); - g_error_free (error); - } - g_free (iconstr); - } - gtk_image_set_from_gicon (GTK_IMAGE (self->priv->icon), icon, GTK_ICON_SIZE_MENU); - - g_menu_item_get_attribute (menuitem, "label", "s", &label); - gtk_label_set_label (GTK_LABEL (self->priv->label), label ? label : ""); - - g_menu_item_get_attribute (menuitem, "action", "s", &action); - im_source_menu_item_set_action_name (self, action); - - if (icon) - g_object_unref (icon); - g_free (label); - g_free (action); -} - -void -im_source_menu_item_set_action_group (ImSourceMenuItem *self, - GActionGroup *action_group) -{ - ImSourceMenuItemPrivate *priv = self->priv; - - if (priv->action_group != NULL) - { - g_signal_handlers_disconnect_by_func (priv->action_group, im_source_menu_item_action_added, self); - g_signal_handlers_disconnect_by_func (priv->action_group, im_source_menu_item_action_removed, self); - g_signal_handlers_disconnect_by_func (priv->action_group, im_source_menu_item_action_enabled_changed, self); - g_signal_handlers_disconnect_by_func (priv->action_group, im_source_menu_item_action_state_changed, self); - - g_clear_object (&priv->action_group); - } - - if (action_group != NULL) - { - priv->action_group = g_object_ref (action_group); - - g_signal_connect (priv->action_group, "action-added", - G_CALLBACK (im_source_menu_item_action_added), self); - g_signal_connect (priv->action_group, "action-removed", - G_CALLBACK (im_source_menu_item_action_removed), self); - g_signal_connect (priv->action_group, "action-enabled-changed", - G_CALLBACK (im_source_menu_item_action_enabled_changed), self); - g_signal_connect (priv->action_group, "action-state-changed", - G_CALLBACK (im_source_menu_item_action_state_changed), self); - } -} diff --git a/src/im-source-menu-item.h b/src/im-source-menu-item.h deleted file mode 100644 index c359b94..0000000 --- a/src/im-source-menu-item.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - * - * Authors: - * Lars Uebernickel - */ - -#ifndef __IM_SOURCE_MENU_ITEM_H__ -#define __IM_SOURCE_MENU_ITEM_H__ - -#include - -#define IM_TYPE_SOURCE_MENU_ITEM (im_source_menu_item_get_type ()) -#define IM_SOURCE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_TYPE_SOURCE_MENU_ITEM, ImSourceMenuItem)) -#define IM_SOURCE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IM_TYPE_SOURCE_MENU_ITEM, ImSourceMenuItemClass)) -#define IS_IM_SOURCE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IM_TYPE_SOURCE_MENU_ITEM)) -#define IS_IM_SOURCE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IM_TYPE_SOURCE_MENU_ITEM)) -#define IM_SOURCE_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IM_TYPE_SOURCE_MENU_ITEM, ImSourceMenuItemClass)) - -typedef struct _ImSourceMenuItem ImSourceMenuItem; -typedef struct _ImSourceMenuItemClass ImSourceMenuItemClass; -typedef struct _ImSourceMenuItemPrivate ImSourceMenuItemPrivate; - -struct _ImSourceMenuItemClass -{ - GtkMenuItemClass parent_class; -}; - -struct _ImSourceMenuItem -{ - GtkMenuItem parent; - ImSourceMenuItemPrivate *priv; -}; - -GType im_source_menu_item_get_type (void); - -void im_source_menu_item_set_menu_item (ImSourceMenuItem *item, - GMenuItem *menuitem); -void im_source_menu_item_set_action_group (ImSourceMenuItem *self, - GActionGroup *action_group); - -#endif diff --git a/src/indicator-messages.c b/src/indicator-messages.c deleted file mode 100644 index 5c5df31..0000000 --- a/src/indicator-messages.c +++ /dev/null @@ -1,382 +0,0 @@ -/* -An indicator to show information that is in messaging applications -that the user is using. - -Copyright 2012 Canonical Ltd. - -Authors: - Ted Gould - Lars Uebernickel - -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License version 3, as published -by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR -PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program. If not, see . -*/ - -#include "config.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "dbus-data.h" - -#include "ido-menu-item.h" -#include "im-app-menu-item.h" -#include "im-source-menu-item.h" - -#define INDICATOR_MESSAGES_TYPE (indicator_messages_get_type ()) -#define INDICATOR_MESSAGES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_MESSAGES_TYPE, IndicatorMessages)) -#define INDICATOR_MESSAGES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_MESSAGES_TYPE, IndicatorMessagesClass)) -#define IS_INDICATOR_MESSAGES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_MESSAGES_TYPE)) -#define IS_INDICATOR_MESSAGES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_MESSAGES_TYPE)) -#define INDICATOR_MESSAGES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_MESSAGES_TYPE, IndicatorMessagesClass)) - -typedef struct _IndicatorMessages IndicatorMessages; -typedef struct _IndicatorMessagesClass IndicatorMessagesClass; - -struct _IndicatorMessagesClass { - IndicatorObjectClass parent_class; -}; - -struct _IndicatorMessages { - IndicatorObject parent; - IndicatorServiceManager * service; - GActionGroup *actions; - GMenuModel *menu; - GtkWidget *image; - GtkWidget *gtkmenu; - gchar *accessible_desc; -}; - -GType indicator_messages_get_type (void); - -/* Indicator Module Config */ -INDICATOR_SET_VERSION -INDICATOR_SET_TYPE(INDICATOR_MESSAGES_TYPE) - -/* Prototypes */ -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); -static const gchar * get_name_hint (IndicatorObject * io); -static void menu_items_changed (GMenuModel *menu, - gint position, - gint removed, - gint added, - gpointer user_data); -static void messages_action_added (GActionGroup *action_group, - gchar *action_name, - gpointer user_data); -static void messages_state_changed (GActionGroup *action_group, - gchar *action_name, - GVariant *value, - gpointer user_data); -static void indicator_messages_add_toplevel_menu (IndicatorMessages *self); - -G_DEFINE_TYPE (IndicatorMessages, indicator_messages, INDICATOR_OBJECT_TYPE); - -/* Initialize the one-timers */ -static void -indicator_messages_class_init (IndicatorMessagesClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->dispose = indicator_messages_dispose; - object_class->finalize = indicator_messages_finalize; - - IndicatorObjectClass * io_class = INDICATOR_OBJECT_CLASS(klass); - - io_class->get_image = get_image; - io_class->get_menu = get_menu; - io_class->get_accessible_desc = get_accessible_desc; - io_class->get_name_hint = get_name_hint; -} - -/* Build up our per-instance variables */ -static void -indicator_messages_init (IndicatorMessages *self) -{ - 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); - - self->gtkmenu = gtk_menu_new (); - g_object_ref_sink (self->gtkmenu); - - self->image = g_object_ref_sink (gtk_image_new ()); - - /* make sure custom menu item types are registered (so that - * gtk_model_new_from_menu can pick them up */ - ido_menu_item_get_type (); - im_app_menu_item_get_type (); - im_source_menu_item_get_type (); -} - -/* Unref stuff */ -static void -indicator_messages_dispose (GObject *object) -{ - IndicatorMessages * self = INDICATOR_MESSAGES(object); - g_return_if_fail(self != NULL); - - g_clear_object (&self->service); - 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); - return; -} - -/* Destory all memory users */ -static void -indicator_messages_finalize (GObject *object) -{ - IndicatorMessages *self = INDICATOR_MESSAGES (object); - - g_free (self->accessible_desc); - - G_OBJECT_CLASS (indicator_messages_parent_class)->finalize (object); - return; -} - - - -/* Functions */ - -static void service_connection_changed (IndicatorServiceManager *sm, - gboolean connected, - gpointer user_data) -{ - IndicatorMessages *self = user_data; - GDBusConnection *bus; - GError *error = NULL; - - if (self->actions != NULL) { - g_signal_handlers_disconnect_by_func (self->actions, messages_action_added, self); - g_signal_handlers_disconnect_by_func (self->actions, messages_state_changed, self); - 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); - } - gtk_menu_shell_bind_model (GTK_MENU_SHELL (self->gtkmenu), NULL, NULL, FALSE); - - 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); - g_signal_connect (self->actions, "action-added::messages", - G_CALLBACK (messages_action_added), self); - g_signal_connect (self->actions, "action-state-changed::messages", - G_CALLBACK (messages_state_changed), self); - - 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); - - if (g_menu_model_get_n_items (self->menu) == 1) - indicator_messages_add_toplevel_menu (self); - else - indicator_object_set_visible (INDICATOR_OBJECT (self), FALSE); - - 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); -} - -static GtkMenu * -get_menu (IndicatorObject * io) -{ - IndicatorMessages *self = INDICATOR_MESSAGES (io); - - return GTK_MENU (self->gtkmenu); -} - -static const gchar * -get_accessible_desc (IndicatorObject * io) -{ - IndicatorMessages *self = INDICATOR_MESSAGES (io); - return self->accessible_desc; -} - -static const gchar * -get_name_hint (IndicatorObject *io) -{ - return PACKAGE; -} - -static void -indicator_messages_accessible_desc_updated (IndicatorMessages *self) -{ - GList *entries; - - entries = indicator_object_get_entries (INDICATOR_OBJECT (self)); - g_return_if_fail (entries != NULL); - - g_signal_emit_by_name (self, INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE, entries->data); - - g_list_free (entries); -} - -static GIcon * -g_menu_model_get_item_attribute_icon (GMenuModel *menu, - gint index, - const gchar *attribute) -{ - gchar *iconstr; - GIcon *icon = NULL; - - if (g_menu_model_get_item_attribute (menu, index, attribute, "s", &iconstr)) { - GError *error; - - icon = g_icon_new_for_string (iconstr, &error); - if (icon == NULL) { - g_warning ("unable to load icon: %s", error->message); - g_error_free (error); - } - - g_free (iconstr); - } - - return icon; -} - -static void -indicator_messages_add_toplevel_menu (IndicatorMessages *self) -{ - GIcon *icon; - GMenuModel *popup; - - indicator_object_set_visible (INDICATOR_OBJECT (self), TRUE); - - icon = g_menu_model_get_item_attribute_icon (self->menu, 0, "x-canonical-icon"); - if (icon) { - gtk_image_set_from_gicon (GTK_IMAGE (self->image), icon, GTK_ICON_SIZE_LARGE_TOOLBAR); - g_object_unref (icon); - } - - g_free (self->accessible_desc); - self->accessible_desc = NULL; - if (g_menu_model_get_item_attribute (self->menu, 0, "x-canonical-accessible-description", - "s", &self->accessible_desc)) { - indicator_messages_accessible_desc_updated (self); - } - - popup = g_menu_model_get_item_link (self->menu, 0, G_MENU_LINK_SUBMENU); - if (popup) { - gtk_menu_shell_bind_model (GTK_MENU_SHELL (self->gtkmenu), - popup, - get_name_hint (INDICATOR_OBJECT (self)), - TRUE); - - g_object_unref (popup); - } -} - -static void -menu_items_changed (GMenuModel *menu, - gint position, - gint removed, - gint added, - gpointer user_data) -{ - IndicatorMessages *self = user_data; - - g_return_if_fail (position == 0); - - if (added == 1) - indicator_messages_add_toplevel_menu (self); - else if (removed == 1) - indicator_object_set_visible (INDICATOR_OBJECT (self), FALSE); -} - -static void -indicator_messages_update_icon (IndicatorMessages *self, - GVariant *state) -{ - GIcon *icon; - GError *error = NULL; - - g_return_if_fail (g_variant_is_of_type (state, G_VARIANT_TYPE_STRING)); - - icon = g_icon_new_for_string (g_variant_get_string (state, NULL), &error); - if (icon == NULL) { - g_warning ("unable to load icon: %s", error->message); - g_error_free (error); - } - else { - gtk_image_set_from_gicon (GTK_IMAGE (self->image), icon, GTK_ICON_SIZE_LARGE_TOOLBAR); - g_object_unref (icon); - } -} - -static void -messages_action_added (GActionGroup *action_group, - gchar *action_name, - gpointer user_data) -{ - IndicatorMessages *self = user_data; - GVariant *state; - - state = g_action_group_get_action_state (action_group, "messages"); - indicator_messages_update_icon (self, state); - - g_variant_unref (state); -} - -static void -messages_state_changed (GActionGroup *action_group, - gchar *action_name, - GVariant *value, - gpointer user_data) -{ - IndicatorMessages *self = user_data; - - indicator_messages_update_icon (self, value); -} -- cgit v1.2.3 From 769affeef08a04881a5a84aa5c2db2caedf70646 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 31 Jul 2013 09:55:32 +0200 Subject: Prefix action names with "indicator." --- src/im-application-list.c | 2 +- src/im-phone-menu.c | 6 +++--- src/messages-service.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 9a673c9..3944f3f 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -685,7 +685,7 @@ im_application_list_message_added (Application *app, g_variant_builder_init (&dict_builder, G_VARIANT_TYPE ("a{sv}")); - prefixed_name = g_strjoin (".", app->id, "msg-actions", id, name, NULL); + prefixed_name = g_strjoin (".", "indicator", app->id, "msg-actions", id, name, NULL); g_variant_builder_add (&dict_builder, "{sv}", "name", g_variant_new_string (prefixed_name)); if (label) diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index 3d5f94d..907749f 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -72,7 +72,7 @@ im_phone_menu_update_toplevel (ImPhoneMenu *menu) g_menu_append_section (menu->toplevel_menu, NULL, G_MENU_MODEL (menu->message_section)); g_menu_append_section (menu->toplevel_menu, NULL, G_MENU_MODEL (menu->source_section)); - item = g_menu_item_new ("Clear All", "remove-all"); + item = g_menu_item_new ("Clear All", "indicator.remove-all"); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.button"); g_menu_append_item (menu->toplevel_menu, item); @@ -173,7 +173,7 @@ im_phone_menu_add_message (ImPhoneMenu *menu, g_return_if_fail (IM_IS_PHONE_MENU (menu)); g_return_if_fail (app_id); - action_name = g_strconcat (app_id, ".msg.", id, NULL); + action_name = g_strconcat ("indicator.", app_id, ".msg.", id, NULL); item = g_menu_item_new (title, action_name); @@ -235,7 +235,7 @@ im_phone_menu_add_source (ImPhoneMenu *menu, g_return_if_fail (IM_IS_PHONE_MENU (menu)); g_return_if_fail (app_id != NULL); - action_name = g_strconcat (app_id, ".src.", id, NULL); + action_name = g_strconcat ("indicator.", app_id, ".src.", id, NULL); item = g_menu_item_new (label, action_name); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.sourceitem"); diff --git a/src/messages-service.c b/src/messages-service.c index 5f320fc..94d6d29 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -160,7 +160,7 @@ main (int argc, char ** argv) menu = im_phone_menu_new (); toplevel_menu = g_menu_new (); - root = g_menu_item_new (NULL, "messages"); + root = g_menu_item_new (NULL, "indicator.messages"); g_menu_item_set_attribute (root, "x-canonical-type", "s", "com.canonical.indicator.root"); g_menu_item_set_submenu (root, im_phone_menu_get_model (menu)); g_menu_append_item (toplevel_menu, root); -- cgit v1.2.3 From ff4aefe6c8d9c36881f26c2cf8514c2ce1f3edca Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 12 Aug 2013 21:19:42 +0200 Subject: Add ImMenu A base class for all messaging menus. ImPhoneMenu already subclasses from it, with a desktop version coming up. --- src/Makefile.am | 2 + src/im-menu.c | 148 +++++++++++++++++++++++++++++++++++++++++++++++++ src/im-menu.h | 56 +++++++++++++++++++ src/im-phone-menu.c | 38 ++++++++----- src/im-phone-menu.h | 6 +- src/messages-service.c | 45 +++++++-------- 6 files changed, 252 insertions(+), 43 deletions(-) create mode 100644 src/im-menu.c create mode 100644 src/im-menu.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index c011d5d..74a1142 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,6 +14,8 @@ indicator_messages_service_SOURCES = \ gsettingsstrv.h \ gmenuutils.c \ gmenuutils.h \ + im-menu.c \ + im-menu.h \ im-phone-menu.c \ im-phone-menu.h \ im-application-list.c \ diff --git a/src/im-menu.c b/src/im-menu.c new file mode 100644 index 0000000..9f4d3e0 --- /dev/null +++ b/src/im-menu.c @@ -0,0 +1,148 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Lars Uebernickel + */ + +#include "im-menu.h" + +struct _ImMenuPrivate +{ + GMenu *toplevel_menu; + GMenu *menu; + ImApplicationList *applist; +}; + +G_DEFINE_TYPE_WITH_PRIVATE (ImMenu, im_menu, G_TYPE_OBJECT) + +enum +{ + PROP_0, + PROP_APPLICATION_LIST, + NUM_PROPERTIES +}; + +static void +im_menu_finalize (GObject *object) +{ + ImMenuPrivate *priv = im_menu_get_instance_private (IM_MENU (object)); + + g_object_unref (priv->toplevel_menu); + g_object_unref (priv->menu); + g_object_unref (priv->applist); + + G_OBJECT_CLASS (im_menu_parent_class)->finalize (object); +} + +static void +im_menu_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + ImMenuPrivate *priv = im_menu_get_instance_private (IM_MENU (object)); + + switch (property_id) + { + case PROP_APPLICATION_LIST: + g_value_set_object (value, priv->applist); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +im_menu_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + ImMenuPrivate *priv = im_menu_get_instance_private (IM_MENU (object)); + + switch (property_id) + { + case PROP_APPLICATION_LIST: /* construct only */ + priv->applist = g_value_dup_object (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +im_menu_class_init (ImMenuClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->finalize = im_menu_finalize; + object_class->get_property = im_menu_get_property; + object_class->set_property = im_menu_set_property; + + g_object_class_install_property (object_class, PROP_APPLICATION_LIST, + g_param_spec_object ("application-list", "", "", + IM_TYPE_APPLICATION_LIST, + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); +} + +static void +im_menu_init (ImMenu *menu) +{ + ImMenuPrivate *priv = im_menu_get_instance_private (menu); + GMenuItem *root; + + priv->toplevel_menu = g_menu_new (); + priv->menu = g_menu_new (); + + root = g_menu_item_new (NULL, "indicator.messages"); + g_menu_item_set_attribute (root, "x-canonical-type", "s", "com.canonical.indicator.root"); + g_menu_item_set_submenu (root, G_MENU_MODEL (priv->menu)); + g_menu_append_item (priv->toplevel_menu, root); + + g_object_unref (root); +} + +ImApplicationList * +im_menu_get_application_list (ImMenu *menu) +{ + ImMenuPrivate *priv; + + g_return_val_if_fail (IM_IS_MENU (menu), FALSE); + + priv = im_menu_get_instance_private (menu); + return priv->applist; +} + +gboolean +im_menu_export (ImMenu *menu, + GDBusConnection *connection, + const gchar *object_path, + GError **error) +{ + ImMenuPrivate *priv; + + g_return_val_if_fail (IM_IS_MENU (menu), FALSE); + + priv = im_menu_get_instance_private (menu); + return g_dbus_connection_export_menu_model (connection, + object_path, + G_MENU_MODEL (priv->toplevel_menu), + error) > 0; +} diff --git a/src/im-menu.h b/src/im-menu.h new file mode 100644 index 0000000..7276020 --- /dev/null +++ b/src/im-menu.h @@ -0,0 +1,56 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Lars Uebernickel + */ + +#ifndef __IM_MENU_H__ +#define __IM_MENU_H__ + +#include +#include "im-application-list.h" + +#define IM_TYPE_MENU (im_menu_get_type ()) +#define IM_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_TYPE_MENU, ImMenu)) +#define IM_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IM_TYPE_MENU, ImMenuClass)) +#define IM_IS_MENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IM_TYPE_MENU)) +#define IM_IS_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IM_TYPE_MENU)) +#define IM_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IM_TYPE_MENU, ImMenuClass)) + +typedef struct _ImMenuClass ImMenuClass; +typedef struct _ImMenu ImMenu; +typedef struct _ImMenuPrivate ImMenuPrivate; + +struct _ImMenuClass +{ + GObjectClass parent_class; +}; + +struct _ImMenu +{ + GObject parent_instance; +}; + +GType im_menu_get_type (void) G_GNUC_CONST; + +ImApplicationList * im_menu_get_application_list (ImMenu *menu); + +gboolean im_menu_export (ImMenu *menu, + GDBusConnection *connection, + const gchar *object_path, + GError **error); + +#endif diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index 907749f..b24e235 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -21,19 +21,18 @@ #include -typedef GObjectClass ImPhoneMenuClass; +typedef ImMenuClass ImPhoneMenuClass; struct _ImPhoneMenu { - GObject parent; + ImMenu parent; GMenu *toplevel_menu; GMenu *message_section; GMenu *source_section; - }; -G_DEFINE_TYPE (ImPhoneMenu, im_phone_menu, G_TYPE_OBJECT); +G_DEFINE_TYPE (ImPhoneMenu, im_phone_menu, IM_TYPE_MENU); typedef void (*ImMenuForeachFunc) (GMenuModel *menu, gint pos); @@ -86,6 +85,22 @@ im_phone_menu_update_toplevel (ImPhoneMenu *menu) } } +static void +im_phone_menu_constructed (GObject *object) +{ + ImPhoneMenu *menu = IM_PHONE_MENU (object); + ImApplicationList *applist; + + applist = im_menu_get_application_list (IM_MENU (menu)); + + g_signal_connect_swapped (applist, "message-added", G_CALLBACK (im_phone_menu_add_message), menu); + g_signal_connect_swapped (applist, "message-removed", G_CALLBACK (im_phone_menu_remove_message), menu); + g_signal_connect_swapped (applist, "app-stopped", G_CALLBACK (im_phone_menu_remove_application), menu); + g_signal_connect_swapped (applist, "remove-all", G_CALLBACK (im_phone_menu_remove_all), menu); + + G_OBJECT_CLASS (im_phone_menu_parent_class)->constructed (object); +} + static void im_phone_menu_dispose (GObject *object) { @@ -109,6 +124,7 @@ im_phone_menu_class_init (ImPhoneMenuClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->constructed = im_phone_menu_constructed; object_class->dispose = im_phone_menu_dispose; object_class->finalize = im_phone_menu_finalize; } @@ -129,17 +145,13 @@ im_phone_menu_init (ImPhoneMenu *menu) } ImPhoneMenu * -im_phone_menu_new (void) -{ - return g_object_new (IM_TYPE_PHONE_MENU, NULL); -} - -GMenuModel * -im_phone_menu_get_model (ImPhoneMenu *menu) +im_phone_menu_new (ImApplicationList *applist) { - g_return_val_if_fail (IM_IS_PHONE_MENU (menu), NULL); + g_return_val_if_fail (IM_IS_APPLICATION_LIST (applist), NULL); - return G_MENU_MODEL (menu->toplevel_menu); + return g_object_new (IM_TYPE_PHONE_MENU, + "application-list", applist, + NULL); } static gint64 diff --git a/src/im-phone-menu.h b/src/im-phone-menu.h index 258ce73..9742f61 100644 --- a/src/im-phone-menu.h +++ b/src/im-phone-menu.h @@ -20,7 +20,7 @@ #ifndef __IM_PHONE_MENU_H__ #define __IM_PHONE_MENU_H__ -#include +#include "im-menu.h" #define IM_TYPE_PHONE_MENU (im_phone_menu_get_type ()) #define IM_PHONE_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_TYPE_PHONE_MENU, ImPhoneMenu)) @@ -33,9 +33,7 @@ typedef struct _ImPhoneMenu ImPhoneMenu; GType im_phone_menu_get_type (void); -ImPhoneMenu * im_phone_menu_new (void); - -GMenuModel * im_phone_menu_get_model (ImPhoneMenu *menu); +ImPhoneMenu * im_phone_menu_new (ImApplicationList *applist); void im_phone_menu_add_message (ImPhoneMenu *menu, const gchar *app_id, diff --git a/src/messages-service.c b/src/messages-service.c index 94d6d29..781e261 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -39,8 +39,7 @@ with this program. If not, see . static ImApplicationList *applications; static IndicatorMessagesService *messages_service; -static GMenu *toplevel_menu; -static ImPhoneMenu *menu; +static GHashTable *menus; static GSettings *settings; static void @@ -82,6 +81,9 @@ on_bus_acquired (GDBusConnection *bus, gpointer user_data) { GError *error = NULL; + GHashTableIter it; + const gchar *profile; + ImMenu *menu; g_dbus_connection_export_action_group (bus, INDICATOR_MESSAGES_DBUS_OBJECT, im_application_list_get_action_group (applications), @@ -92,12 +94,17 @@ on_bus_acquired (GDBusConnection *bus, return; } - g_dbus_connection_export_menu_model (bus, INDICATOR_MESSAGES_DBUS_OBJECT "/phone", - G_MENU_MODEL (toplevel_menu), &error); - if (error) { - g_warning ("unable to export menu on dbus: %s", error->message); - g_error_free (error); - return; + g_hash_table_iter_init (&it, menus); + while (g_hash_table_iter_next (&it, (gpointer *) &profile, (gpointer *) &menu)) { + gchar *object_path; + + object_path = g_strconcat (INDICATOR_MESSAGES_DBUS_OBJECT, "/", profile, NULL); + if (!im_menu_export (menu, bus, object_path, &error)) { + g_warning ("unable to export menu for profile '%s': %s", profile, error->message); + g_clear_error (&error); + } + + g_free (object_path); } g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (messages_service), @@ -126,7 +133,6 @@ int main (int argc, char ** argv) { GMainLoop * mainloop = NULL; - GMenuItem *root; GBusNameOwnerFlags flags; /* Glib init */ @@ -157,30 +163,17 @@ main (int argc, char ** argv) g_signal_connect (messages_service, "handle-unregister-application", G_CALLBACK (unregister_application), NULL); - menu = im_phone_menu_new (); - - toplevel_menu = g_menu_new (); - root = g_menu_item_new (NULL, "indicator.messages"); - g_menu_item_set_attribute (root, "x-canonical-type", "s", "com.canonical.indicator.root"); - g_menu_item_set_submenu (root, im_phone_menu_get_model (menu)); - g_menu_append_item (toplevel_menu, root); - settings = g_settings_new ("com.canonical.indicator.messages"); applications = im_application_list_new (); - g_signal_connect_swapped (applications, "message-added", - G_CALLBACK (im_phone_menu_add_message), menu); - g_signal_connect_swapped (applications, "message-removed", - G_CALLBACK (im_phone_menu_remove_message), menu); - g_signal_connect_swapped (applications, "app-stopped", - G_CALLBACK (im_phone_menu_remove_application), menu); - g_signal_connect_swapped (applications, "remove-all", - G_CALLBACK (im_phone_menu_remove_all), menu); + + menus = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); + g_hash_table_insert (menus, "phone", im_phone_menu_new (applications)); g_main_loop_run(mainloop); /* Clean up */ - g_object_unref (root); + g_hash_table_unref (menus); g_object_unref (messages_service); g_object_unref (settings); g_object_unref (applications); -- cgit v1.2.3 From 0b24c6a91ff91400568cab9b4d192a0a85db918e Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 12 Aug 2013 21:33:39 +0200 Subject: Move toplevel menu logic into ImMenu Also, get rid of only exporting sections if they were non-empty. That was a hack for non-conformant GMenuModel renderers. --- src/im-menu.c | 14 +++++++++++ src/im-menu.h | 3 +++ src/im-phone-menu.c | 70 +++++++++++++++++------------------------------------ 3 files changed, 39 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/im-menu.c b/src/im-menu.c index 9f4d3e0..4c660e5 100644 --- a/src/im-menu.c +++ b/src/im-menu.c @@ -146,3 +146,17 @@ im_menu_export (ImMenu *menu, G_MENU_MODEL (priv->toplevel_menu), error) > 0; } + +void +im_menu_append_section (ImMenu *menu, + GMenuModel *section) +{ + ImMenuPrivate *priv; + + g_return_if_fail (IM_IS_MENU (menu)); + g_return_if_fail (G_IS_MENU_MODEL (section)); + + priv = im_menu_get_instance_private (menu); + + g_menu_append_section (priv->menu, NULL, section); +} diff --git a/src/im-menu.h b/src/im-menu.h index 7276020..ec41bff 100644 --- a/src/im-menu.h +++ b/src/im-menu.h @@ -53,4 +53,7 @@ gboolean im_menu_export (ImMenu const gchar *object_path, GError **error); +void im_menu_append_section (ImMenu *menu, + GMenuModel *section); + #endif diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index b24e235..7b5132b 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -27,7 +27,6 @@ struct _ImPhoneMenu { ImMenu parent; - GMenu *toplevel_menu; GMenu *message_section; GMenu *source_section; }; @@ -59,37 +58,29 @@ im_phone_menu_foreach_item_with_action (GMenuModel *menu, } static void -im_phone_menu_update_toplevel (ImPhoneMenu *menu) +im_phone_menu_constructed (GObject *object) { - if (g_menu_model_get_n_items (G_MENU_MODEL (menu->message_section)) || - g_menu_model_get_n_items (G_MENU_MODEL (menu->source_section))) - { - if (g_menu_model_get_n_items (G_MENU_MODEL (menu->toplevel_menu)) == 0) - { - GMenuItem *item; + ImPhoneMenu *menu = IM_PHONE_MENU (object); + ImApplicationList *applist; - g_menu_append_section (menu->toplevel_menu, NULL, G_MENU_MODEL (menu->message_section)); - g_menu_append_section (menu->toplevel_menu, NULL, G_MENU_MODEL (menu->source_section)); + im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (menu->message_section)); + im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (menu->source_section)); - item = g_menu_item_new ("Clear All", "indicator.remove-all"); - g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.button"); - g_menu_append_item (menu->toplevel_menu, item); + { + GMenu *clear_section; + GMenuItem *item; - g_object_unref (item); - } - } - else - { - while (g_menu_model_get_n_items (G_MENU_MODEL (menu->toplevel_menu))) - g_menu_remove (menu->toplevel_menu, 0); - } -} + clear_section = g_menu_new (); -static void -im_phone_menu_constructed (GObject *object) -{ - ImPhoneMenu *menu = IM_PHONE_MENU (object); - ImApplicationList *applist; + item = g_menu_item_new ("Clear All", "indicator.remove-all"); + g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.button"); + g_menu_append_item (clear_section, item); + + im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (clear_section)); + + g_object_unref (item); + g_object_unref (clear_section); + } applist = im_menu_get_application_list (IM_MENU (menu)); @@ -106,7 +97,6 @@ im_phone_menu_dispose (GObject *object) { ImPhoneMenu *menu = IM_PHONE_MENU (object); - g_clear_object (&menu->toplevel_menu); g_clear_object (&menu->message_section); g_clear_object (&menu->source_section); @@ -132,16 +122,8 @@ im_phone_menu_class_init (ImPhoneMenuClass *klass) static void im_phone_menu_init (ImPhoneMenu *menu) { - menu->toplevel_menu = g_menu_new (); menu->message_section = g_menu_new (); menu->source_section = g_menu_new (); - - g_signal_connect_swapped (menu->message_section, "items-changed", - G_CALLBACK (im_phone_menu_update_toplevel), menu); - g_signal_connect_swapped (menu->source_section, "items-changed", - G_CALLBACK (im_phone_menu_update_toplevel), menu); - - im_phone_menu_update_toplevel (menu); } ImPhoneMenu * @@ -327,17 +309,9 @@ im_phone_menu_remove_all (ImPhoneMenu *menu) { g_return_if_fail (IM_IS_PHONE_MENU (menu)); - while (g_menu_model_get_n_items (G_MENU_MODEL (menu->toplevel_menu))) - g_menu_remove (menu->toplevel_menu, 0); - - g_object_unref (menu->message_section); - g_object_unref (menu->source_section); - - menu->message_section = g_menu_new (); - menu->source_section = g_menu_new (); + while (g_menu_model_get_n_items (G_MENU_MODEL (menu->message_section))) + g_menu_remove (menu->message_section, 0); - g_signal_connect_swapped (menu->message_section, "items-changed", - G_CALLBACK (im_phone_menu_update_toplevel), menu); - g_signal_connect_swapped (menu->source_section, "items-changed", - G_CALLBACK (im_phone_menu_update_toplevel), menu); + while (g_menu_model_get_n_items (G_MENU_MODEL (menu->source_section))) + g_menu_remove (menu->source_section, 0); } -- cgit v1.2.3 From 046ef6f5581ab2634d5ef097e6c449316c2404bf Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 13 Aug 2013 09:43:22 +0200 Subject: Add desktop menu Only shows application launchers right now. --- data/com.canonical.indicator.messages | 3 + src/Makefile.am | 2 + src/im-application-list.c | 84 +++++++++++++--- src/im-application-list.h | 6 ++ src/im-desktop-menu.c | 174 ++++++++++++++++++++++++++++++++++ src/im-desktop-menu.h | 35 +++++++ src/im-menu.c | 29 ++++++ src/im-menu.h | 5 + src/messages-service.c | 2 + 9 files changed, 329 insertions(+), 11 deletions(-) create mode 100644 src/im-desktop-menu.c create mode 100644 src/im-desktop-menu.h (limited to 'src') diff --git a/data/com.canonical.indicator.messages b/data/com.canonical.indicator.messages index dc37549..fa0ac50 100644 --- a/data/com.canonical.indicator.messages +++ b/data/com.canonical.indicator.messages @@ -3,5 +3,8 @@ Name=indicator-messages ObjectPath=/com/canonical/indicator/messages Position=50 +[desktop] +ObjectPath=/com/canonical/indicator/messages/desktop + [phone] ObjectPath=/com/canonical/indicator/messages/phone diff --git a/src/Makefile.am b/src/Makefile.am index 74a1142..e03406a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,6 +18,8 @@ indicator_messages_service_SOURCES = \ im-menu.h \ im-phone-menu.c \ im-phone-menu.h \ + im-desktop-menu.c \ + im-desktop-menu.h \ im-application-list.c \ im-application-list.h diff --git a/src/im-application-list.c b/src/im-application-list.c index 3944f3f..8eaa601 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -44,6 +44,7 @@ enum SOURCE_REMOVED, MESSAGE_ADDED, MESSAGE_REMOVED, + APP_ADDED, APP_STOPPED, REMOVE_ALL, N_SIGNALS @@ -57,7 +58,8 @@ typedef struct GDesktopAppInfo *info; gchar *id; IndicatorMessagesApplication *proxy; - GActionMuxer *actions; + GActionMuxer *muxer; + GSimpleActionGroup *actions; GSimpleActionGroup *source_actions; GSimpleActionGroup *message_actions; GActionMuxer *message_sub_actions; @@ -84,9 +86,9 @@ application_free (gpointer data) if (app->proxy) g_object_unref (app->proxy); - if (app->actions) + if (app->muxer) { - g_object_unref (app->actions); + g_object_unref (app->muxer); g_object_unref (app->source_actions); g_object_unref (app->message_actions); g_object_unref (app->message_sub_actions); @@ -371,6 +373,17 @@ im_application_list_class_init (ImApplicationListClass *klass) G_TYPE_STRING, G_TYPE_STRING); + signals[APP_ADDED] = g_signal_new ("app-added", + IM_TYPE_APPLICATION_LIST, + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_generic, + G_TYPE_NONE, + 2, + G_TYPE_STRING, + G_TYPE_DESKTOP_APP_INFO); + signals[APP_STOPPED] = g_signal_new ("app-stopped", IM_TYPE_APPLICATION_LIST, G_SIGNAL_RUN_FIRST, @@ -454,6 +467,21 @@ im_application_list_lookup (ImApplicationList *list, return app; } +void +im_application_list_activate_launch (ImApplicationList *list, + GVariant *parameter, + gpointer user_data) +{ + Application *app = user_data; + GError *error = NULL; + + if (!g_app_info_launch (G_APP_INFO (app->info), NULL, NULL, &error)) + { + g_warning ("unable to launch application: %s", error->message); + g_error_free (error); + } +} + void im_application_list_add (ImApplicationList *list, const gchar *desktop_id) @@ -461,6 +489,8 @@ im_application_list_add (ImApplicationList *list, GDesktopAppInfo *info; Application *app; const gchar *id; + GSimpleActionGroup *actions; + GSimpleAction *launch_action; g_return_if_fail (IM_IS_APPLICATION_LIST (list)); g_return_if_fail (desktop_id != NULL); @@ -482,17 +512,29 @@ im_application_list_add (ImApplicationList *list, app->info = info; app->id = im_application_list_canonical_id (id); app->list = list; - app->actions = g_action_muxer_new (); + app->muxer = g_action_muxer_new (); app->source_actions = g_simple_action_group_new (); app->message_actions = g_simple_action_group_new (); app->message_sub_actions = g_action_muxer_new (); - g_action_muxer_insert (app->actions, "src", G_ACTION_GROUP (app->source_actions)); - g_action_muxer_insert (app->actions, "msg", G_ACTION_GROUP (app->message_actions)); - g_action_muxer_insert (app->actions, "msg-actions", G_ACTION_GROUP (app->message_sub_actions)); + launch_action = g_simple_action_new_stateful ("launch", NULL, g_variant_new_boolean (FALSE)); + g_signal_connect (launch_action, "activate", G_CALLBACK (im_application_list_activate_launch), app); + + actions = g_simple_action_group_new (); + g_action_map_add_action (G_ACTION_MAP (actions), G_ACTION (launch_action)); + + g_action_muxer_insert (app->muxer, NULL, G_ACTION_GROUP (actions)); + g_action_muxer_insert (app->muxer, "src", G_ACTION_GROUP (app->source_actions)); + g_action_muxer_insert (app->muxer, "msg", G_ACTION_GROUP (app->message_actions)); + g_action_muxer_insert (app->muxer, "msg-actions", G_ACTION_GROUP (app->message_sub_actions)); g_hash_table_insert (list->applications, (gpointer) app->id, app); - g_action_muxer_insert (list->muxer, app->id, G_ACTION_GROUP (app->actions)); + g_action_muxer_insert (list->muxer, app->id, G_ACTION_GROUP (app->muxer)); + + g_signal_emit (app->list, signals[APP_ADDED], 0, app->id, app->info); + + g_object_unref (launch_action); + g_object_unref (actions); } void @@ -779,9 +821,9 @@ im_application_list_unset_remote (Application *app) app->source_actions = g_simple_action_group_new (); app->message_actions = g_simple_action_group_new (); app->message_sub_actions = g_action_muxer_new (); - g_action_muxer_insert (app->actions, "src", G_ACTION_GROUP (app->source_actions)); - g_action_muxer_insert (app->actions, "msg", G_ACTION_GROUP (app->message_actions)); - g_action_muxer_insert (app->actions, "msg-actions", G_ACTION_GROUP (app->message_sub_actions)); + g_action_muxer_insert (app->muxer, "src", G_ACTION_GROUP (app->source_actions)); + g_action_muxer_insert (app->muxer, "msg", G_ACTION_GROUP (app->message_actions)); + g_action_muxer_insert (app->muxer, "msg-actions", G_ACTION_GROUP (app->message_sub_actions)); im_application_list_update_draws_attention (app->list); @@ -878,3 +920,23 @@ im_application_list_get_action_group (ImApplicationList *list) return G_ACTION_GROUP (list->muxer); } + +GList * +im_application_list_get_applications (ImApplicationList *list) +{ + g_return_val_if_fail (IM_IS_APPLICATION_LIST (list), NULL); + + return g_hash_table_get_keys (list->applications); +} + +GDesktopAppInfo * +im_application_list_get_application (ImApplicationList *list, + const gchar *id) +{ + Application *app; + + g_return_val_if_fail (IM_IS_APPLICATION_LIST (list), NULL); + + app = g_hash_table_lookup (list->applications, id); + return app ? app->info : NULL; +} diff --git a/src/im-application-list.h b/src/im-application-list.h index ecba312..53dac50 100644 --- a/src/im-application-list.h +++ b/src/im-application-list.h @@ -21,6 +21,7 @@ #define __IM_APPLICATION_LIST_H__ #include +#include #define IM_TYPE_APPLICATION_LIST (im_application_list_get_type ()) #define IM_APPLICATION_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_TYPE_APPLICATION_LIST, ImApplicationList)) @@ -49,4 +50,9 @@ void im_application_list_set_remote (ImApplicationLi GActionGroup * im_application_list_get_action_group (ImApplicationList *list); +GList * im_application_list_get_applications (ImApplicationList *list); + +GDesktopAppInfo * im_application_list_get_application (ImApplicationList *list, + const gchar *id); + #endif diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c new file mode 100644 index 0000000..ee25f02 --- /dev/null +++ b/src/im-desktop-menu.c @@ -0,0 +1,174 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Lars Uebernickel + */ + +#include "im-desktop-menu.h" + +typedef ImMenuClass ImDesktopMenuClass; + +struct _ImDesktopMenu +{ + ImMenu parent; + + GHashTable *source_sections; +}; + +G_DEFINE_TYPE (ImDesktopMenu, im_desktop_menu, IM_TYPE_MENU); + +static void +im_desktop_menu_app_added (ImApplicationList *applist, + const gchar *app_id, + GDesktopAppInfo *app_info, + gpointer user_data) +{ + ImDesktopMenu *menu = user_data; + GMenu *section; + GMenu *app_section; + GMenu *source_section; + gchar *namespace; + + app_section = g_menu_new (); + + /* application launcher */ + { + GMenuItem *item; + GVariant *icon; + + item = g_menu_item_new (g_app_info_get_name (G_APP_INFO (app_info)), "launch"); + g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.application"); + + icon = g_icon_serialize (g_app_info_get_icon (G_APP_INFO (app_info))); + if (icon) + { + g_menu_item_set_attribute_value (item, "x-canonical-icon", icon); + g_variant_unref (icon); + } + + g_menu_append_item (app_section, item); + + g_object_unref (item); + } + + /* TODO application actions */ + + source_section = g_menu_new (); + + section = g_menu_new (); + g_menu_append_section (section, NULL, G_MENU_MODEL (app_section)); + g_menu_append_section (section, NULL, G_MENU_MODEL (source_section)); + + namespace = g_strconcat ("indicator.", app_id, NULL); + im_menu_insert_section (IM_MENU (menu), -1, namespace, G_MENU_MODEL (section)); + g_hash_table_insert (menu->source_sections, g_strdup (app_id), source_section); + + g_free (namespace); + g_object_unref (section); + g_object_unref (app_section); +} + +static void +im_desktop_menu_remove_all (ImApplicationList *applist, + gpointer user_data) +{ + ImDesktopMenu *menu = user_data; + GHashTableIter it; + GMenu *section; + + g_hash_table_iter_init (&it, menu->source_sections); + while (g_hash_table_iter_next (&it, NULL, (gpointer *) §ion)) + { + while (g_menu_model_get_n_items (G_MENU_MODEL (section)) > 0) + g_menu_remove (section, 0); + } +} + +static void +im_desktop_menu_constructed (GObject *object) +{ + ImDesktopMenu *menu = IM_DESKTOP_MENU (object); + ImApplicationList *applist; + + /* TODO: chat section */ + + { + GMenu *clear_section; + + clear_section = g_menu_new (); + g_menu_append (clear_section, "Clear", "indicator.remove-all"); + im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (clear_section)); + + g_object_unref (clear_section); + } + + applist = im_menu_get_application_list (IM_MENU (menu)); + + { + GList *apps; + GList *it; + + apps = im_application_list_get_applications (applist); + for (it = apps; it != NULL; it = it->next) + { + const gchar *id = it->data; + im_desktop_menu_app_added (applist, id, im_application_list_get_application (applist, id), menu); + } + + g_list_free (apps); + } + + + g_signal_connect (applist, "app-added", G_CALLBACK (im_desktop_menu_app_added), menu); + g_signal_connect (applist, "remove-all", G_CALLBACK (im_desktop_menu_remove_all), menu); + + G_OBJECT_CLASS (im_desktop_menu_parent_class)->constructed (object); +} + +static void +im_desktop_menu_finalize (GObject *object) +{ + ImDesktopMenu *menu = IM_DESKTOP_MENU (object); + + g_hash_table_unref (menu->source_sections); + + G_OBJECT_CLASS (im_desktop_menu_parent_class)->finalize (object); +} + +static void +im_desktop_menu_class_init (ImDesktopMenuClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->constructed = im_desktop_menu_constructed; + object_class->finalize = im_desktop_menu_finalize; +} + +static void +im_desktop_menu_init (ImDesktopMenu *menu) +{ + menu->source_sections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); +} + +ImDesktopMenu * +im_desktop_menu_new (ImApplicationList *applist) +{ + g_return_val_if_fail (IM_IS_APPLICATION_LIST (applist), NULL); + + return g_object_new (IM_TYPE_DESKTOP_MENU, + "application-list", applist, + NULL); +} diff --git a/src/im-desktop-menu.h b/src/im-desktop-menu.h new file mode 100644 index 0000000..9469ea6 --- /dev/null +++ b/src/im-desktop-menu.h @@ -0,0 +1,35 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Lars Uebernickel + */ + +#ifndef __IM_DESKTOP_MENU_H__ +#define __IM_DESKTOP_MENU_H__ + +#include "im-menu.h" + +#define IM_TYPE_DESKTOP_MENU (im_desktop_menu_get_type ()) +#define IM_DESKTOP_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_TYPE_DESKTOP_MENU, ImDesktopMenu)) +#define IM_IS_DESKTOP_MENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IM_TYPE_DESKTOP_MENU)) + +typedef struct _ImDesktopMenu ImDesktopMenu; + +GType im_desktop_menu_get_type (void); + +ImDesktopMenu * im_desktop_menu_new (ImApplicationList *applist); + +#endif diff --git a/src/im-menu.c b/src/im-menu.c index 4c660e5..ac23a29 100644 --- a/src/im-menu.c +++ b/src/im-menu.c @@ -113,6 +113,7 @@ im_menu_init (ImMenu *menu) root = g_menu_item_new (NULL, "indicator.messages"); g_menu_item_set_attribute (root, "x-canonical-type", "s", "com.canonical.indicator.root"); + g_menu_item_set_attribute (root, "action-namespace", "s", "indicator"); g_menu_item_set_submenu (root, G_MENU_MODEL (priv->menu)); g_menu_append_item (priv->toplevel_menu, root); @@ -160,3 +161,31 @@ im_menu_append_section (ImMenu *menu, g_menu_append_section (priv->menu, NULL, section); } + +void +im_menu_insert_section (ImMenu *menu, + gint position, + const gchar *namespace, + GMenuModel *section) +{ + ImMenuPrivate *priv; + GMenuItem *item; + + g_return_if_fail (IM_IS_MENU (menu)); + g_return_if_fail (G_IS_MENU_MODEL (section)); + + priv = im_menu_get_instance_private (menu); + + /* count from the back if position is < 0 */ + if (position < 0) + position = g_menu_model_get_n_items (G_MENU_MODEL (priv->menu)) + position; + + item = g_menu_item_new_section (NULL, section); + + if (namespace) + g_menu_item_set_attribute (item, "action-namespace", "s", namespace); + + g_menu_insert_item (priv->menu, position, item); + + g_object_unref (item); +} diff --git a/src/im-menu.h b/src/im-menu.h index ec41bff..d3775ad 100644 --- a/src/im-menu.h +++ b/src/im-menu.h @@ -56,4 +56,9 @@ gboolean im_menu_export (ImMenu void im_menu_append_section (ImMenu *menu, GMenuModel *section); +void im_menu_insert_section (ImMenu *menu, + gint position, + const gchar *namespace, + GMenuModel *section); + #endif diff --git a/src/messages-service.c b/src/messages-service.c index 781e261..efe9602 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -32,6 +32,7 @@ with this program. If not, see . #include "indicator-messages-service.h" #include "indicator-messages-application.h" #include "im-phone-menu.h" +#include "im-desktop-menu.h" #include "im-application-list.h" #define NUM_STATUSES 5 @@ -169,6 +170,7 @@ main (int argc, char ** argv) menus = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); g_hash_table_insert (menus, "phone", im_phone_menu_new (applications)); + g_hash_table_insert (menus, "desktop", im_desktop_menu_new (applications)); g_main_loop_run(mainloop); -- cgit v1.2.3 From 2cd06d6f970df9f9f8f8ae67905f88f6518ea25b Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 13 Aug 2013 10:06:59 +0200 Subject: Add application actions --- src/im-application-list.c | 35 ++++++++++++++++++++++++++++++----- src/im-desktop-menu.c | 15 ++++++++++++++- 2 files changed, 44 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 8eaa601..95a9cd0 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -468,9 +468,9 @@ im_application_list_lookup (ImApplicationList *list, } void -im_application_list_activate_launch (ImApplicationList *list, - GVariant *parameter, - gpointer user_data) +im_application_list_activate_launch (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { Application *app = user_data; GError *error = NULL; @@ -482,6 +482,16 @@ im_application_list_activate_launch (ImApplicationList *list, } } +void +im_application_list_activate_app_action (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + Application *app = user_data; + + g_desktop_app_info_launch_action (app->info, g_action_get_name (G_ACTION (action)), NULL); +} + void im_application_list_add (ImApplicationList *list, const gchar *desktop_id) @@ -517,12 +527,27 @@ im_application_list_add (ImApplicationList *list, app->message_actions = g_simple_action_group_new (); app->message_sub_actions = g_action_muxer_new (); + actions = g_simple_action_group_new (); + launch_action = g_simple_action_new_stateful ("launch", NULL, g_variant_new_boolean (FALSE)); g_signal_connect (launch_action, "activate", G_CALLBACK (im_application_list_activate_launch), app); - - actions = g_simple_action_group_new (); g_action_map_add_action (G_ACTION_MAP (actions), G_ACTION (launch_action)); + { + const gchar *const *app_actions; + + for (app_actions = g_desktop_app_info_list_actions (app->info); *app_actions; app_actions++) + { + GSimpleAction *action; + + action = g_simple_action_new (*app_actions, NULL); + g_signal_connect (action, "activate", G_CALLBACK (im_application_list_activate_app_action), app); + g_action_map_add_action (G_ACTION_MAP (actions), G_ACTION (action)); + + g_object_unref (action); + } + } + g_action_muxer_insert (app->muxer, NULL, G_ACTION_GROUP (actions)); g_action_muxer_insert (app->muxer, "src", G_ACTION_GROUP (app->source_actions)); g_action_muxer_insert (app->muxer, "msg", G_ACTION_GROUP (app->message_actions)); diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c index ee25f02..f5fea9a 100644 --- a/src/im-desktop-menu.c +++ b/src/im-desktop-menu.c @@ -64,7 +64,20 @@ im_desktop_menu_app_added (ImApplicationList *applist, g_object_unref (item); } - /* TODO application actions */ + /* application actions */ + { + const gchar *const *actions; + + for (actions = g_desktop_app_info_list_actions (app_info); *actions; actions++) + { + gchar *label; + + label = g_desktop_app_info_get_action_name (app_info, *actions); + g_menu_append (app_section, label, *actions); + + g_free (label); + } + } source_section = g_menu_new (); -- cgit v1.2.3 From 7877dfd936cbd8f95d07867ea89d7d1e9e730bff Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 13 Aug 2013 12:55:39 +0200 Subject: desktop menu: show message sources --- src/im-desktop-menu.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'src') diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c index f5fea9a..b9de18d 100644 --- a/src/im-desktop-menu.c +++ b/src/im-desktop-menu.c @@ -94,6 +94,68 @@ im_desktop_menu_app_added (ImApplicationList *applist, g_object_unref (app_section); } +static void +im_desktop_menu_source_added (ImApplicationList *applist, + const gchar *app_id, + const gchar *source_id, + const gchar *label, + const gchar *icon, + gpointer user_data) +{ + ImDesktopMenu *menu = user_data; + GMenu *source_section; + GMenuItem *item; + gchar *action; + + source_section = g_hash_table_lookup (menu->source_sections, app_id); + g_return_if_fail (source_section != NULL); + + action = g_strconcat ("src.", source_id, NULL); + item = g_menu_item_new (label, NULL); + g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.source"); + if (icon) + g_menu_item_set_attribute (item, "x-canonical-icon", "s", icon); + + g_menu_append_item (source_section, item); + + g_free (action); + g_object_unref (item); +} + +static void +im_desktop_menu_source_removed (ImApplicationList *applist, + const gchar *app_id, + const gchar *source_id, + gpointer user_data) +{ + ImDesktopMenu *menu = user_data; + GMenu *source_section; + gint n_items; + gchar *action; + gint i; + + source_section = g_hash_table_lookup (menu->source_sections, app_id); + g_return_if_fail (source_section != NULL); + + n_items = g_menu_model_get_n_items (G_MENU_MODEL (source_section)); + action = g_strconcat ("src.", source_id, NULL); + + for (i = 0; i < n_items; i++) + { + gchar *item_action; + + if (g_menu_model_get_item_attribute (G_MENU_MODEL (source_section), i, "action", "s", &item_action)) + { + if (g_str_equal (action, item_action)) + g_menu_remove (source_section, i); + + g_free (item_action); + } + } + + g_free (action); +} + static void im_desktop_menu_remove_all (ImApplicationList *applist, gpointer user_data) @@ -146,6 +208,8 @@ im_desktop_menu_constructed (GObject *object) g_signal_connect (applist, "app-added", G_CALLBACK (im_desktop_menu_app_added), menu); + g_signal_connect (applist, "source-added", G_CALLBACK (im_desktop_menu_source_added), menu); + g_signal_connect (applist, "source-removed", G_CALLBACK (im_desktop_menu_source_removed), menu); g_signal_connect (applist, "remove-all", G_CALLBACK (im_desktop_menu_remove_all), menu); G_OBJECT_CLASS (im_desktop_menu_parent_class)->constructed (object); -- cgit v1.2.3 From a545cafca29ffcd2044cc69dc5e9871f9e21f0f8 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 13 Aug 2013 13:33:22 +0200 Subject: application list: update draws-attention when necessary --- src/im-application-list.c | 84 ++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 95a9cd0..f87fcec 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -97,43 +97,6 @@ application_free (gpointer data) g_slice_free (Application, app); } -static void -im_application_list_source_removed (Application *app, - const gchar *id) -{ - g_simple_action_group_remove (app->source_actions, id); - - g_signal_emit (app->list, signals[SOURCE_REMOVED], 0, app->id, id); -} - -static void -im_application_list_source_activated (GSimpleAction *action, - GVariant *parameter, - gpointer user_data) -{ - Application *app = user_data; - const gchar *source_id; - - source_id = g_action_get_name (G_ACTION (action)); - - if (g_variant_get_boolean (parameter)) - { - indicator_messages_application_call_activate_source (app->proxy, - source_id, - app->cancellable, - NULL, NULL); - } - else - { - const gchar *sources[] = { source_id, NULL }; - const gchar *messages[] = { NULL }; - indicator_messages_application_call_dismiss (app->proxy, sources, messages, - app->cancellable, NULL, NULL); - } - - im_application_list_source_removed (app, source_id); -} - static guint g_action_group_get_n_actions (GActionGroup *group) { @@ -175,6 +138,45 @@ im_application_list_update_draws_attention (ImApplicationList *list) g_action_group_change_action_state (main_actions, "messages", state); } +static void +im_application_list_source_removed (Application *app, + const gchar *id) +{ + g_simple_action_group_remove (app->source_actions, id); + + g_signal_emit (app->list, signals[SOURCE_REMOVED], 0, app->id, id); + + im_application_list_update_draws_attention (app->list); +} + +static void +im_application_list_source_activated (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + Application *app = user_data; + const gchar *source_id; + + source_id = g_action_get_name (G_ACTION (action)); + + if (g_variant_get_boolean (parameter)) + { + indicator_messages_application_call_activate_source (app->proxy, + source_id, + app->cancellable, + NULL, NULL); + } + else + { + const gchar *sources[] = { source_id, NULL }; + const gchar *messages[] = { NULL }; + indicator_messages_application_call_dismiss (app->proxy, sources, messages, + app->cancellable, NULL, NULL); + } + + im_application_list_source_removed (app, source_id); +} + static void im_application_list_message_removed (Application *app, const gchar *id) @@ -279,6 +281,8 @@ im_application_list_remove_all (GSimpleAction *action, g_strfreev (source_actions); g_strfreev (message_actions); } + + im_application_list_update_draws_attention (list); } static void @@ -578,6 +582,8 @@ im_application_list_remove (ImApplicationList *list, g_hash_table_remove (list->applications, id); g_action_muxer_remove (list->muxer, id); + + im_application_list_update_draws_attention (list); } } @@ -607,6 +613,8 @@ im_application_list_source_added (Application *app, g_signal_emit (app->list, signals[SOURCE_ADDED], 0, app->id, id, label, iconstr); + im_application_list_update_draws_attention (app->list); + g_object_unref (action); } @@ -629,6 +637,8 @@ im_application_list_source_changed (Application *app, g_variant_new ("(uxsb)", count, time, string, draws_attention)); g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->id, id, label, iconstr); + + im_application_list_update_draws_attention (app->list); } static void -- cgit v1.2.3 From 4fcb03be88fcd4ce0358db56f311f8c59dc85d44 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 13 Aug 2013 15:16:42 +0200 Subject: Use "icon" instead of "x-canonical-icon" --- src/gmenuutils.c | 2 +- src/im-desktop-menu.c | 4 ++-- src/im-phone-menu.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gmenuutils.c b/src/gmenuutils.c index f63615b..cfd751e 100644 --- a/src/gmenuutils.c +++ b/src/gmenuutils.c @@ -79,7 +79,7 @@ g_menu_append_with_icon_name (GMenu *menu, GMenuItem *item; item = g_menu_item_new (label, detailed_action); - g_menu_item_set_attribute (item, "x-canonical-icon", "s", icon_name); + g_menu_item_set_attribute (item, "icon", "s", icon_name); g_menu_append_item (menu, item); diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c index b9de18d..9dcd6c1 100644 --- a/src/im-desktop-menu.c +++ b/src/im-desktop-menu.c @@ -55,7 +55,7 @@ im_desktop_menu_app_added (ImApplicationList *applist, icon = g_icon_serialize (g_app_info_get_icon (G_APP_INFO (app_info))); if (icon) { - g_menu_item_set_attribute_value (item, "x-canonical-icon", icon); + g_menu_item_set_attribute_value (item, "icon", icon); g_variant_unref (icon); } @@ -114,7 +114,7 @@ im_desktop_menu_source_added (ImApplicationList *applist, item = g_menu_item_new (label, NULL); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.source"); if (icon) - g_menu_item_set_attribute (item, "x-canonical-icon", "s", icon); + g_menu_item_set_attribute (item, "icon", "s", icon); g_menu_append_item (source_section, item); diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index 7b5132b..96bae42 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -178,7 +178,7 @@ im_phone_menu_add_message (ImPhoneMenu *menu, g_menu_item_set_attribute (item, "x-canonical-time", "x", time); if (iconstr) - g_menu_item_set_attribute (item, "x-canonical-icon", "s", iconstr); + g_menu_item_set_attribute (item, "icon", "s", iconstr); if (app_icon) g_menu_item_set_attribute (item, "x-canonical-app-icon", "s", app_icon); -- cgit v1.2.3 From ed16f39ed4e571bb75005453b5af33ab737deb6c Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 13 Aug 2013 16:04:34 +0200 Subject: application list: show non-running applications --- src/im-application-list.c | 3 +++ src/messages-service.c | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index f87fcec..dd868df 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -861,6 +861,7 @@ im_application_list_unset_remote (Application *app) g_action_muxer_insert (app->muxer, "msg-actions", G_ACTION_GROUP (app->message_sub_actions)); im_application_list_update_draws_attention (app->list); + g_action_group_change_action_state (G_ACTION_GROUP (app->muxer), "launch", g_variant_new_boolean (FALSE)); if (was_running) g_signal_emit (app->list, signals[APP_STOPPED], 0, app->id); @@ -904,6 +905,8 @@ im_application_list_proxy_created (GObject *source_object, g_signal_connect_swapped (app->proxy, "message-added", G_CALLBACK (im_application_list_message_added), app); g_signal_connect_swapped (app->proxy, "message-removed", G_CALLBACK (im_application_list_message_removed), app); + g_action_group_change_action_state (G_ACTION_GROUP (app->muxer), "launch", g_variant_new_boolean (TRUE)); + g_bus_watch_name_on_connection (g_dbus_proxy_get_connection (G_DBUS_PROXY (app->proxy)), g_dbus_proxy_get_name (G_DBUS_PROXY (app->proxy)), G_BUS_NAME_WATCHER_FLAGS_NONE, diff --git a/src/messages-service.c b/src/messages-service.c index efe9602..3d4bcca 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -164,9 +164,19 @@ main (int argc, char ** argv) g_signal_connect (messages_service, "handle-unregister-application", G_CALLBACK (unregister_application), NULL); + applications = im_application_list_new (); + settings = g_settings_new ("com.canonical.indicator.messages"); + { + gchar **app_ids; + gchar **id; - applications = im_application_list_new (); + app_ids = g_settings_get_strv (settings, "applications"); + for (id = app_ids; *id; id++) + im_application_list_add (applications, *id); + + g_strfreev (app_ids); + } menus = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); g_hash_table_insert (menus, "phone", im_phone_menu_new (applications)); -- cgit v1.2.3 From 393294faaf9b8bd1780778e9355e502a52822843 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 13 Aug 2013 18:49:49 +0200 Subject: desktop menu: don't export an item if the name is '' --- src/im-desktop-menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c index 9dcd6c1..7a9b9bf 100644 --- a/src/im-desktop-menu.c +++ b/src/im-desktop-menu.c @@ -113,7 +113,7 @@ im_desktop_menu_source_added (ImApplicationList *applist, action = g_strconcat ("src.", source_id, NULL); item = g_menu_item_new (label, NULL); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.source"); - if (icon) + if (icon && *icon) g_menu_item_set_attribute (item, "icon", "s", icon); g_menu_append_item (source_section, item); -- cgit v1.2.3 From ec9ca618ca3f0bb6c3c8ab470b3ef3e1c6f8c0c9 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 13 Aug 2013 19:01:44 +0200 Subject: Disable action shortcuts for now This version isn't honoring OnlyShowIn=MessagingMenu. Disabling it seems like the lesser evil. --- src/im-desktop-menu.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c index 7a9b9bf..6cc51cd 100644 --- a/src/im-desktop-menu.c +++ b/src/im-desktop-menu.c @@ -65,6 +65,7 @@ im_desktop_menu_app_added (ImApplicationList *applist, } /* application actions */ +#if 0 { const gchar *const *actions; @@ -78,6 +79,7 @@ im_desktop_menu_app_added (ImApplicationList *applist, g_free (label); } } +#endif source_section = g_menu_new (); -- cgit v1.2.3 From 8fa163fca4df8dfc2a85c5899ec745059269cfe4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 13 Aug 2013 14:09:40 -0500 Subject: Small merge error --- src/app-section.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/app-section.c b/src/app-section.c index 4f91835..b7b557a 100644 --- a/src/app-section.c +++ b/src/app-section.c @@ -318,7 +318,7 @@ nick_activate_cb (GSimpleAction *action, nick, g_desktop_app_info_get_filename (priv->appinfo)); } - g_object_unref (context); + return; } static void -- cgit v1.2.3 From 24b52f4270c0c4f9b2fa120c895908e3b50e8471 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 14 Aug 2013 23:01:17 -0500 Subject: Adding a set_status virtual function --- src/im-menu.c | 16 ++++++++++++++++ src/im-menu.h | 5 +++++ 2 files changed, 21 insertions(+) (limited to 'src') diff --git a/src/im-menu.c b/src/im-menu.c index ac23a29..931d998 100644 --- a/src/im-menu.c +++ b/src/im-menu.c @@ -189,3 +189,19 @@ im_menu_insert_section (ImMenu *menu, g_object_unref (item); } + +void +im_menu_set_status (ImMenu * menu, + const gchar *id, + const gchar *status_str) +{ + g_return_if_fail(IM_IS_MENU(menu)); + g_return_if_fail(id != NULL); + g_return_if_fail(status_str != NULL); + + ImMenuClass * klass = IM_MENU_GET_CLASS(menu); + if (klass->set_status != NULL) + klass->set_status(menu, id, status_str); + + return; +} diff --git a/src/im-menu.h b/src/im-menu.h index d3775ad..633a444 100644 --- a/src/im-menu.h +++ b/src/im-menu.h @@ -37,6 +37,7 @@ typedef struct _ImMenuPrivate ImMenuPrivate; struct _ImMenuClass { GObjectClass parent_class; + void (*set_status) (ImMenu * menu, const gchar * id, const gchar * status_str); }; struct _ImMenu @@ -61,4 +62,8 @@ void im_menu_insert_section (ImMenu const gchar *namespace, GMenuModel *section); +void im_menu_set_status (ImMenu * menu, + const gchar *id, + const gchar *status_str); + #endif -- cgit v1.2.3 From 3baa8097f77fc731b3cbbc83f766d90020b32d6e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 14 Aug 2013 23:06:23 -0500 Subject: React to the set-status call on dbus and pass that down to the menus --- src/messages-service.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src') diff --git a/src/messages-service.c b/src/messages-service.c index 3d4bcca..92a3f99 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -76,6 +76,44 @@ unregister_application (IndicatorMessagesService *service, indicator_messages_service_complete_unregister_application (service, invocation); } +static void +set_status (IndicatorMessagesService *service, + GDBusMethodInvocation *invocation, + const gchar *desktop_id, + const gchar *status_str, + gpointer user_data) +{ + GDesktopAppInfo *appinfo; + const gchar *id; + GList * menulist, * menu; + + g_return_if_fail (g_str_equal (status_str, "available") || + g_str_equal (status_str, "away")|| + g_str_equal (status_str, "busy") || + g_str_equal (status_str, "invisible") || + g_str_equal (status_str, "offline")); + + appinfo = g_desktop_app_info_new (desktop_id); + if (!appinfo) { + g_warning ("could not set status for '%s', there's no desktop file with that id", desktop_id); + return; + } + + id = g_app_info_get_id (G_APP_INFO (appinfo)); + + menulist = g_hash_table_get_values(menus); + for (menu = menulist; menu != NULL; menu = g_list_next(menu)) { + ImMenu * immenu = IM_MENU(menu->data); + im_menu_set_status(immenu, id, status_str); + } + + indicator_messages_service_complete_set_status (service, invocation); + + g_object_unref (appinfo); + g_list_free(menulist); +} + + static void on_bus_acquired (GDBusConnection *bus, const gchar *name, @@ -163,6 +201,8 @@ main (int argc, char ** argv) G_CALLBACK (register_application), NULL); g_signal_connect (messages_service, "handle-unregister-application", G_CALLBACK (unregister_application), NULL); + g_signal_connect (messages_service, "handle-set-status", + G_CALLBACK (set_status), NULL); applications = im_application_list_new (); -- cgit v1.2.3 From a7e92c991d3970710eb94ecae1a3c7bd66ea1d3c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 14 Aug 2013 23:06:54 -0500 Subject: Create the status section of the desktop menu --- src/im-desktop-menu.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c index 6cc51cd..ad6318e 100644 --- a/src/im-desktop-menu.c +++ b/src/im-desktop-menu.c @@ -18,6 +18,7 @@ */ #include "im-desktop-menu.h" +#include typedef ImMenuClass ImDesktopMenuClass; @@ -174,13 +175,54 @@ im_desktop_menu_remove_all (ImApplicationList *applist, } } +static GMenu * +create_status_section (void) +{ + GMenu *menu; + GMenuItem *item; + struct status_item { + gchar *label; + gchar *action; + gchar *icon_name; + } status_items[] = { + { _("Available"), "indicator.status::available", "user-available" }, + { _("Away"), "indicator.status::away", "user-away" }, + { _("Busy"), "indicator.status::busy", "user-busy" }, + { _("Invisible"), "indicator.status::invisible", "user-invisible" }, + { _("Offline"), "indicator.status::offline", "user-offline" } + }; + int i; + + menu = g_menu_new (); + + item = g_menu_item_new (NULL, NULL); + g_menu_item_set_attribute (item, "x-canonical-type", "s", "IdoMenuItem"); + + for (i = 0; i < G_N_ELEMENTS (status_items); i++) { + g_menu_item_set_label (item, status_items[i].label); + g_menu_item_set_detailed_action (item, status_items[i].action); + g_menu_item_set_attribute (item, "x-canonical-icon", "s", status_items[i].icon_name); + g_menu_append_item (menu, item); + } + + g_object_unref (item); + return menu; +} + static void im_desktop_menu_constructed (GObject *object) { ImDesktopMenu *menu = IM_DESKTOP_MENU (object); ImApplicationList *applist; - /* TODO: chat section */ + { + GMenu *status_section; + + status_section = create_status_section(); + im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (status_section)); + + g_object_unref (status_section); + } { GMenu *clear_section; -- cgit v1.2.3 From 194c8bf9e07b10fb4857aeb5366b3aaee07dd9a2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Aug 2013 12:50:16 -0500 Subject: Really we should set status on the application list --- src/im-application-list.c | 9 +++++++++ src/im-application-list.h | 4 ++++ src/im-menu.c | 16 ---------------- src/im-menu.h | 5 ----- src/messages-service.c | 8 +------- 5 files changed, 14 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index dd868df..33b9d4a 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -978,3 +978,12 @@ im_application_list_get_application (ImApplicationList *list, app = g_hash_table_lookup (list->applications, id); return app ? app->info : NULL; } + +void +im_application_list_set_status (ImApplicationList * list, const gchar * id, const gchar *status) +{ + + + return; +} + diff --git a/src/im-application-list.h b/src/im-application-list.h index 53dac50..f1de220 100644 --- a/src/im-application-list.h +++ b/src/im-application-list.h @@ -55,4 +55,8 @@ GList * im_application_list_get_applications (ImApplicationLi GDesktopAppInfo * im_application_list_get_application (ImApplicationList *list, const gchar *id); +void im_application_list_set_status (ImApplicationList *list, + const gchar *id, + const gchar *status); + #endif diff --git a/src/im-menu.c b/src/im-menu.c index 931d998..ac23a29 100644 --- a/src/im-menu.c +++ b/src/im-menu.c @@ -189,19 +189,3 @@ im_menu_insert_section (ImMenu *menu, g_object_unref (item); } - -void -im_menu_set_status (ImMenu * menu, - const gchar *id, - const gchar *status_str) -{ - g_return_if_fail(IM_IS_MENU(menu)); - g_return_if_fail(id != NULL); - g_return_if_fail(status_str != NULL); - - ImMenuClass * klass = IM_MENU_GET_CLASS(menu); - if (klass->set_status != NULL) - klass->set_status(menu, id, status_str); - - return; -} diff --git a/src/im-menu.h b/src/im-menu.h index 633a444..d3775ad 100644 --- a/src/im-menu.h +++ b/src/im-menu.h @@ -37,7 +37,6 @@ typedef struct _ImMenuPrivate ImMenuPrivate; struct _ImMenuClass { GObjectClass parent_class; - void (*set_status) (ImMenu * menu, const gchar * id, const gchar * status_str); }; struct _ImMenu @@ -62,8 +61,4 @@ void im_menu_insert_section (ImMenu const gchar *namespace, GMenuModel *section); -void im_menu_set_status (ImMenu * menu, - const gchar *id, - const gchar *status_str); - #endif diff --git a/src/messages-service.c b/src/messages-service.c index 92a3f99..6423cd5 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -85,7 +85,6 @@ set_status (IndicatorMessagesService *service, { GDesktopAppInfo *appinfo; const gchar *id; - GList * menulist, * menu; g_return_if_fail (g_str_equal (status_str, "available") || g_str_equal (status_str, "away")|| @@ -101,16 +100,11 @@ set_status (IndicatorMessagesService *service, id = g_app_info_get_id (G_APP_INFO (appinfo)); - menulist = g_hash_table_get_values(menus); - for (menu = menulist; menu != NULL; menu = g_list_next(menu)) { - ImMenu * immenu = IM_MENU(menu->data); - im_menu_set_status(immenu, id, status_str); - } + im_application_list_set_status(applications, id, status_str); indicator_messages_service_complete_set_status (service, invocation); g_object_unref (appinfo); - g_list_free(menulist); } -- cgit v1.2.3 From 02ba00aad4d9755c96b5706301af60e73eb3786a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Aug 2013 13:39:42 -0500 Subject: Create a status action --- src/im-application-list.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 33b9d4a..810886a 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -33,6 +33,9 @@ struct _ImApplicationList GHashTable *applications; GActionMuxer *muxer; + + GSimpleActionGroup * globalactions; + GSimpleAction * statusaction; }; G_DEFINE_TYPE (ImApplicationList, im_application_list, G_TYPE_OBJECT); @@ -290,6 +293,9 @@ im_application_list_dispose (GObject *object) { ImApplicationList *list = IM_APPLICATION_LIST (object); + g_clear_object (&list->statusaction); + g_clear_object (&list->globalactions); + g_clear_pointer (&list->applications, g_hash_table_unref); g_clear_object (&list->muxer); @@ -416,17 +422,17 @@ im_application_list_init (ImApplicationList *list) { "remove-all", im_application_list_remove_all } }; - GSimpleActionGroup *actions; - list->applications = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, application_free); - actions = g_simple_action_group_new (); - g_simple_action_group_add_entries (actions, action_entries, G_N_ELEMENTS (action_entries), list); + list->globalactions = g_simple_action_group_new (); + g_simple_action_group_add_entries (list->globalactions, action_entries, G_N_ELEMENTS (action_entries), list); + + list->statusaction = g_simple_action_new_stateful("status", G_VARIANT_TYPE_STRING, g_variant_new_string("offline")); + g_simple_action_group_insert(list->globalactions, G_ACTION(list->statusaction)); list->muxer = g_action_muxer_new (); - g_action_muxer_insert (list->muxer, NULL, G_ACTION_GROUP (actions)); + g_action_muxer_insert (list->muxer, NULL, G_ACTION_GROUP (list->globalactions)); - g_object_unref (actions); } ImApplicationList * -- cgit v1.2.3 From 5ca1b7a06fe94cb7e2d760d9a5a98de022e5376b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Aug 2013 14:29:00 -0500 Subject: Tracking application status --- src/im-application-list.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 810886a..d9b3e2f 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -36,6 +36,8 @@ struct _ImApplicationList GSimpleActionGroup * globalactions; GSimpleAction * statusaction; + + GHashTable *app_status; }; G_DEFINE_TYPE (ImApplicationList, im_application_list, G_TYPE_OBJECT); @@ -295,6 +297,7 @@ im_application_list_dispose (GObject *object) g_clear_object (&list->statusaction); g_clear_object (&list->globalactions); + g_clear_pointer (&list->app_status, g_hash_table_unref); g_clear_pointer (&list->applications, g_hash_table_unref); g_clear_object (&list->muxer); @@ -423,6 +426,7 @@ im_application_list_init (ImApplicationList *list) }; list->applications = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, application_free); + list->app_status = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); list->globalactions = g_simple_action_group_new (); g_simple_action_group_add_entries (list->globalactions, action_entries, G_N_ELEMENTS (action_entries), list); @@ -988,7 +992,11 @@ im_application_list_get_application (ImApplicationList *list, void im_application_list_set_status (ImApplicationList * list, const gchar * id, const gchar *status) { + g_return_if_fail (IM_IS_APPLICATION_LIST (list)); + + g_hash_table_insert(list->app_status, im_application_list_canonical_id(id), g_strdup(status)); + /* TODO: Update status */ return; } -- cgit v1.2.3 From 1f28cf89abf224957c3e9eb60e103d4204958fcc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Aug 2013 15:21:52 -0500 Subject: Setting up a callback on the activation to set the state and update the applications --- src/im-application-list.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index d9b3e2f..8083704 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -71,6 +71,12 @@ typedef struct GCancellable *cancellable; } Application; + +/* Prototypes */ +static void status_activated (GSimpleAction * action, + GVariant * param, + gpointer user_data); + static void application_free (gpointer data) { @@ -432,6 +438,7 @@ im_application_list_init (ImApplicationList *list) g_simple_action_group_add_entries (list->globalactions, action_entries, G_N_ELEMENTS (action_entries), list); list->statusaction = g_simple_action_new_stateful("status", G_VARIANT_TYPE_STRING, g_variant_new_string("offline")); + g_signal_connect(list->statusaction, "activate", G_CALLBACK(status_activated), list); g_simple_action_group_insert(list->globalactions, G_ACTION(list->statusaction)); list->muxer = g_action_muxer_new (); @@ -989,6 +996,24 @@ im_application_list_get_application (ImApplicationList *list, return app ? app->info : NULL; } +static void +status_activated (GSimpleAction * action, GVariant * param, gpointer user_data) +{ + g_return_if_fail (IM_IS_APPLICATION_LIST(user_data)); + ImApplicationList * list = IM_APPLICATION_LIST(user_data); + + g_simple_action_set_state(action, param); + + /* We assume all the applications are now seeing our status + and updating. We don't need to track their status until + they tell us different. */ + g_hash_table_remove_all(list->app_status); + + /* TODO: Emit a state change */ + + return; +} + void im_application_list_set_status (ImApplicationList * list, const gchar * id, const gchar *status) { -- cgit v1.2.3 From 86cedd8ccb7c779436f5d9cf0caec90dfef97dd7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Aug 2013 15:28:10 -0500 Subject: Adding a set status signal --- src/im-application-list.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 8083704..878e57f 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -52,6 +52,7 @@ enum APP_ADDED, APP_STOPPED, REMOVE_ALL, + STATUS_SET, N_SIGNALS }; @@ -421,6 +422,16 @@ im_application_list_class_init (ImApplicationListClass *klass) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + + signals[STATUS_SET] = g_signal_new ("status-set", + IM_TYPE_APPLICATION_LIST, + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_generic, + G_TYPE_NONE, + 1, + G_TYPE_STRING); } static void @@ -1009,7 +1020,8 @@ status_activated (GSimpleAction * action, GVariant * param, gpointer user_data) they tell us different. */ g_hash_table_remove_all(list->app_status); - /* TODO: Emit a state change */ + const gchar * status = g_variant_get_string(param, NULL); + g_signal_emit (list, signals[STATUS_SET], 0, status); return; } -- cgit v1.2.3 From 190841b5d7262d9619c618e19bcb08e30968fd41 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Aug 2013 15:32:36 -0500 Subject: Emit to dbus when the status changes --- src/messages-service.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/messages-service.c b/src/messages-service.c index 6423cd5..71fa09b 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -107,6 +107,13 @@ set_status (IndicatorMessagesService *service, g_object_unref (appinfo); } +/* The status has been set by the user, let's tell the world! */ +static void +status_set_by_user (ImApplicationList * list, const gchar * status, gpointer user_data) +{ + indicator_messages_service_emit_status_changed(messages_service, status); + return; +} static void on_bus_acquired (GDBusConnection *bus, @@ -199,6 +206,8 @@ main (int argc, char ** argv) G_CALLBACK (set_status), NULL); applications = im_application_list_new (); + g_signal_connect (applications, "status-set", + G_CALLBACK (status_set_by_user), NULL); settings = g_settings_new ("com.canonical.indicator.messages"); { -- cgit v1.2.3 From 04aad431b226943042233a11aa98e30b9e82c820 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Aug 2013 16:02:00 -0500 Subject: Setting the status of the menu based on the aggregate application status --- src/im-application-list.c | 49 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 878e57f..b23923a 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -1026,15 +1026,56 @@ status_activated (GSimpleAction * action, GVariant * param, gpointer user_data) return; } +#define STATUS_ID_OFFLINE (G_N_ELEMENTS(status_ids) - 1) +static const gchar *status_ids[] = { "available", "away", "busy", "invisible", "offline" }; + +static guint +status2val (const gchar * string) +{ + if (string == NULL) return STATUS_ID_OFFLINE; + + guint i; + for (i = 0; i < G_N_ELEMENTS(status_ids); i++) { + if (g_strcmp0(status_ids[i], string) == 0) { + break; + } + } + + if (i > STATUS_ID_OFFLINE) + i = STATUS_ID_OFFLINE; + + return i; +} + void im_application_list_set_status (ImApplicationList * list, const gchar * id, const gchar *status) { - g_return_if_fail (IM_IS_APPLICATION_LIST (list)); + g_return_if_fail (IM_IS_APPLICATION_LIST (list)); - g_hash_table_insert(list->app_status, im_application_list_canonical_id(id), g_strdup(status)); + g_hash_table_insert(list->app_status, im_application_list_canonical_id(id), g_strdup(status)); - /* TODO: Update status */ + GVariant * action_state = NULL; + g_object_get(list->statusaction, "state", &action_state, NULL); - return; + guint final_status = STATUS_ID_OFFLINE; + + if (action_state != NULL) { + final_status = status2val(g_variant_get_string(action_state, NULL)); + g_variant_unref(action_state); + } + + GList * statuses = g_hash_table_get_values(list->app_status); + GList * statusentry; + + for (statusentry = statuses; statusentry != NULL; statusentry = g_list_next(statusentry)) { + guint statusval = status2val((gchar *)statusentry->data); + final_status = MIN(final_status, statusval); + } + + g_list_free(statuses); + + g_simple_action_set_state(list->statusaction, g_variant_new_string(status_ids[final_status])); + + return; } -- cgit v1.2.3 From 922fb55f693e3ac2523414a150b667bd0236138a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Aug 2013 16:13:49 -0500 Subject: Couldn't make that assumption, instead assume they're all listening and adjust themselves or tell us otherwise --- src/im-application-list.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index b23923a..aaa1c38 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -1012,15 +1012,21 @@ status_activated (GSimpleAction * action, GVariant * param, gpointer user_data) { g_return_if_fail (IM_IS_APPLICATION_LIST(user_data)); ImApplicationList * list = IM_APPLICATION_LIST(user_data); + const gchar * status = g_variant_get_string(param, NULL); g_simple_action_set_state(action, param); - /* We assume all the applications are now seeing our status - and updating. We don't need to track their status until - they tell us different. */ - g_hash_table_remove_all(list->app_status); + GList * appshash = g_hash_table_get_keys(list->app_status); + GList * appsfree = g_list_copy_deep(appshash, (GCopyFunc)g_strdup, NULL); + GList * app; + + for (app = appsfree; app != NULL; app = g_list_next(app)) { + g_hash_table_insert(list->app_status, app->data, g_strdup(status)); + } + + g_list_free(appshash); + g_list_free(appsfree); - const gchar * status = g_variant_get_string(param, NULL); g_signal_emit (list, signals[STATUS_SET], 0, status); return; @@ -1054,16 +1060,8 @@ im_application_list_set_status (ImApplicationList * list, const gchar * id, cons g_hash_table_insert(list->app_status, im_application_list_canonical_id(id), g_strdup(status)); - GVariant * action_state = NULL; - g_object_get(list->statusaction, "state", &action_state, NULL); - guint final_status = STATUS_ID_OFFLINE; - if (action_state != NULL) { - final_status = status2val(g_variant_get_string(action_state, NULL)); - g_variant_unref(action_state); - } - GList * statuses = g_hash_table_get_values(list->app_status); GList * statusentry; -- cgit v1.2.3 From 185d6e251c18205e51827002b57c71051dcdbaf0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Aug 2013 16:24:58 -0500 Subject: Don't need a special type for these --- src/im-desktop-menu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c index ad6318e..e8dff6f 100644 --- a/src/im-desktop-menu.c +++ b/src/im-desktop-menu.c @@ -196,12 +196,11 @@ create_status_section (void) menu = g_menu_new (); item = g_menu_item_new (NULL, NULL); - g_menu_item_set_attribute (item, "x-canonical-type", "s", "IdoMenuItem"); for (i = 0; i < G_N_ELEMENTS (status_items); i++) { g_menu_item_set_label (item, status_items[i].label); g_menu_item_set_detailed_action (item, status_items[i].action); - g_menu_item_set_attribute (item, "x-canonical-icon", "s", status_items[i].icon_name); + g_menu_item_set_attribute (item, "icon", "s", status_items[i].icon_name); g_menu_append_item (menu, item); } -- cgit v1.2.3 From 3b9907270084a6bd9edb72206ecaa34312370f09 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Aug 2013 23:22:12 -0500 Subject: Make sure we've got an icon str before setting it --- src/app-section.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/app-section.c b/src/app-section.c index b7b557a..aad994d 100644 --- a/src/app-section.c +++ b/src/app-section.c @@ -411,7 +411,9 @@ app_section_update_menu (AppSection *self) item = g_menu_item_new (g_app_info_get_name (G_APP_INFO (priv->appinfo)), "launch"); g_menu_item_set_attribute (item, "x-canonical-type", "s", "ImAppMenuItem"); iconstr = g_icon_to_string (g_app_info_get_icon (G_APP_INFO (priv->appinfo))); - g_menu_item_set_attribute (item, "x-canonical-icon", "s", iconstr); + if (iconstr != NULL) { + g_menu_item_set_attribute (item, "x-canonical-icon", "s", iconstr); + } g_free (iconstr); g_menu_append_item (priv->menu, item); -- cgit v1.2.3 From b0626bc33d3ec1b0580869045c1b2c5ff295d05c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 16 Aug 2013 09:24:22 -0500 Subject: Making it so that we cache the draw attention state in the app --- src/im-application-list.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index aaa1c38..2be470e 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -70,6 +70,7 @@ typedef struct GSimpleActionGroup *message_actions; GActionMuxer *message_sub_actions; GCancellable *cancellable; + gboolean draws_attention; } Application; @@ -109,19 +110,6 @@ application_free (gpointer data) g_slice_free (Application, app); } -static guint -g_action_group_get_n_actions (GActionGroup *group) -{ - guint len; - gchar **actions; - - actions = g_action_group_list_actions (group); - len = g_strv_length (actions); - - g_strfreev (actions); - return len; -} - static gboolean application_draws_attention (gpointer key, gpointer value, @@ -129,8 +117,7 @@ application_draws_attention (gpointer key, { Application *app = value; - return (g_action_group_get_n_actions (G_ACTION_GROUP (app->source_actions)) + - g_action_group_get_n_actions (G_ACTION_GROUP (app->message_actions))) > 0; + return app->draws_attention; } static void @@ -558,6 +545,7 @@ im_application_list_add (ImApplicationList *list, app->source_actions = g_simple_action_group_new (); app->message_actions = g_simple_action_group_new (); app->message_sub_actions = g_action_muxer_new (); + app->draws_attention = FALSE; actions = g_simple_action_group_new (); @@ -641,6 +629,9 @@ im_application_list_source_added (Application *app, g_signal_emit (app->list, signals[SOURCE_ADDED], 0, app->id, id, label, iconstr); + if (draws_attention) + app->draws_attention = TRUE; + im_application_list_update_draws_attention (app->list); g_object_unref (action); -- cgit v1.2.3 From 201482b9190f616031e1db01a648d3d943f6fa5f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 16 Aug 2013 09:25:56 -0500 Subject: Forgot to draw attention for new messages --- src/im-application-list.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 2be470e..d9426f9 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -812,6 +812,9 @@ im_application_list_message_added (Application *app, g_object_unref (action_group); } + if (draws_attention) + app->draws_attention = TRUE; + im_application_list_update_draws_attention (app->list); g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, -- cgit v1.2.3 From 4c8c9dc742282e4bf63c2931c61dff5b89ea5cb9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 16 Aug 2013 09:55:54 -0500 Subject: Stop removing sources, just set them to no longer draw attention --- src/im-application-list.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index d9426f9..2acb3d9 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -245,6 +245,53 @@ im_application_list_sub_message_activated (GSimpleAction *action, im_application_list_message_removed (app, message_id); } +/* If a source has a draw_attention state set, this clears it so that it + doesn't get calculated to draw attention */ +static void +im_application_list_source_clear_attention (Application * app, + gchar * source_name) +{ + GVariant * action_value = NULL; + GVariant * action_state = g_action_group_get_action_state(G_ACTION_GROUP(app->source_actions), source_name); + + /* If it doesn't draw attention, we're done */ + action_value = g_variant_get_child_value(action_state, 3); + if (!g_variant_get_boolean(action_value)) + { + g_variant_unref(action_value); + g_variant_unref(action_state); + return; + } + + g_variant_unref(action_value); + + /* We need to build a new state without the draw attention */ + GVariantBuilder new_state_builder; + g_variant_builder_init(&new_state_builder, G_VARIANT_TYPE_TUPLE); + + /* Count */ + action_value = g_variant_get_child_value(action_state, 0); + g_variant_builder_add_value(&new_state_builder, action_value); + g_variant_unref(action_value); + + /* Time */ + action_value = g_variant_get_child_value(action_state, 1); + g_variant_builder_add_value(&new_state_builder, action_value); + g_variant_unref(action_value); + + /* String */ + action_value = g_variant_get_child_value(action_state, 2); + g_variant_builder_add_value(&new_state_builder, action_value); + g_variant_unref(action_value); + + /* Draws Attention */ + g_variant_builder_add_value(&new_state_builder, g_variant_new_boolean(FALSE)); + + g_action_group_change_action_state(G_ACTION_GROUP(app->source_actions), source_name, g_variant_builder_end(&new_state_builder)); + + g_variant_unref(action_state); + return; +} static void im_application_list_remove_all (GSimpleAction *action, @@ -266,7 +313,7 @@ im_application_list_remove_all (GSimpleAction *action, source_actions = g_action_group_list_actions (G_ACTION_GROUP (app->source_actions)); for (it = source_actions; *it; it++) - im_application_list_source_removed (app, *it); + im_application_list_source_clear_attention (app, *it); message_actions = g_action_group_list_actions (G_ACTION_GROUP (app->message_actions)); for (it = message_actions; *it; it++) @@ -279,6 +326,8 @@ im_application_list_remove_all (GSimpleAction *action, g_strfreev (source_actions); g_strfreev (message_actions); + + app->draws_attention = FALSE; } im_application_list_update_draws_attention (list); -- cgit v1.2.3 From 234e9dd70074a0eb4734ced3a271447d44a29a8b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 16 Aug 2013 10:16:10 -0500 Subject: Only dismiss if there is a proxy connected and the application is remote --- src/im-application-list.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 2acb3d9..47d81ce 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -319,10 +319,14 @@ im_application_list_remove_all (GSimpleAction *action, for (it = message_actions; *it; it++) im_application_list_message_removed (app, *it); - indicator_messages_application_call_dismiss (app->proxy, - (const gchar * const *) source_actions, - (const gchar * const *) message_actions, - app->cancellable, NULL, NULL); + if (app->proxy != NULL) /* If it is remote, we tell the app we've cleared */ + { + gchar * null_list[1] = { NULL }; + indicator_messages_application_call_dismiss (app->proxy, + (const gchar * const *) null_list, + (const gchar * const *) message_actions, + app->cancellable, NULL, NULL); + } g_strfreev (source_actions); g_strfreev (message_actions); -- cgit v1.2.3 From cacbeac6d8aafa701a80a57475a768bab54b8b2b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 16 Aug 2013 10:22:09 -0500 Subject: Whitespace --- src/im-application-list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 47d81ce..7d75c84 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -321,7 +321,7 @@ im_application_list_remove_all (GSimpleAction *action, if (app->proxy != NULL) /* If it is remote, we tell the app we've cleared */ { - gchar * null_list[1] = { NULL }; + gchar * null_list[1] = { NULL }; indicator_messages_application_call_dismiss (app->proxy, (const gchar * const *) null_list, (const gchar * const *) message_actions, -- cgit v1.2.3 From 08739c5fe918d9aef5b3f2f8b0e86a2fbed08a7f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 16 Aug 2013 14:01:36 -0500 Subject: Dropping indicator prefixes as they're set up with the base namespace of the section --- src/im-application-list.c | 2 +- src/im-phone-menu.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 7d75c84..5a56df3 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -834,7 +834,7 @@ im_application_list_message_added (Application *app, g_variant_builder_init (&dict_builder, G_VARIANT_TYPE ("a{sv}")); - prefixed_name = g_strjoin (".", "indicator", app->id, "msg-actions", id, name, NULL); + prefixed_name = g_strjoin (".", app->id, "msg-actions", id, name, NULL); g_variant_builder_add (&dict_builder, "{sv}", "name", g_variant_new_string (prefixed_name)); if (label) diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index 96bae42..7381097 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -72,7 +72,7 @@ im_phone_menu_constructed (GObject *object) clear_section = g_menu_new (); - item = g_menu_item_new ("Clear All", "indicator.remove-all"); + item = g_menu_item_new ("Clear All", "remove-all"); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.button"); g_menu_append_item (clear_section, item); @@ -167,7 +167,7 @@ im_phone_menu_add_message (ImPhoneMenu *menu, g_return_if_fail (IM_IS_PHONE_MENU (menu)); g_return_if_fail (app_id); - action_name = g_strconcat ("indicator.", app_id, ".msg.", id, NULL); + action_name = g_strconcat (app_id, ".msg.", id, NULL); item = g_menu_item_new (title, action_name); @@ -229,7 +229,7 @@ im_phone_menu_add_source (ImPhoneMenu *menu, g_return_if_fail (IM_IS_PHONE_MENU (menu)); g_return_if_fail (app_id != NULL); - action_name = g_strconcat ("indicator.", app_id, ".src.", id, NULL); + action_name = g_strconcat (app_id, ".src.", id, NULL); item = g_menu_item_new (label, action_name); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.sourceitem"); -- cgit v1.2.3 From 7ac72f494336f93e5fe4454f10fb43e5007ba21b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 16 Aug 2013 16:39:55 -0500 Subject: Can't clear the sources because that clears the mailboxes --- src/im-desktop-menu.c | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'src') diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c index e8dff6f..25c83a4 100644 --- a/src/im-desktop-menu.c +++ b/src/im-desktop-menu.c @@ -159,22 +159,6 @@ im_desktop_menu_source_removed (ImApplicationList *applist, g_free (action); } -static void -im_desktop_menu_remove_all (ImApplicationList *applist, - gpointer user_data) -{ - ImDesktopMenu *menu = user_data; - GHashTableIter it; - GMenu *section; - - g_hash_table_iter_init (&it, menu->source_sections); - while (g_hash_table_iter_next (&it, NULL, (gpointer *) §ion)) - { - while (g_menu_model_get_n_items (G_MENU_MODEL (section)) > 0) - g_menu_remove (section, 0); - } -} - static GMenu * create_status_section (void) { @@ -253,7 +237,6 @@ im_desktop_menu_constructed (GObject *object) g_signal_connect (applist, "app-added", G_CALLBACK (im_desktop_menu_app_added), menu); g_signal_connect (applist, "source-added", G_CALLBACK (im_desktop_menu_source_added), menu); g_signal_connect (applist, "source-removed", G_CALLBACK (im_desktop_menu_source_removed), menu); - g_signal_connect (applist, "remove-all", G_CALLBACK (im_desktop_menu_remove_all), menu); G_OBJECT_CLASS (im_desktop_menu_parent_class)->constructed (object); } -- cgit v1.2.3 From aa21be1e0794713e2aeb091516c8c784821a5352 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 18 Aug 2013 22:48:46 -0500 Subject: Putting back the removing of sources --- src/im-desktop-menu.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c index 25c83a4..e8dff6f 100644 --- a/src/im-desktop-menu.c +++ b/src/im-desktop-menu.c @@ -159,6 +159,22 @@ im_desktop_menu_source_removed (ImApplicationList *applist, g_free (action); } +static void +im_desktop_menu_remove_all (ImApplicationList *applist, + gpointer user_data) +{ + ImDesktopMenu *menu = user_data; + GHashTableIter it; + GMenu *section; + + g_hash_table_iter_init (&it, menu->source_sections); + while (g_hash_table_iter_next (&it, NULL, (gpointer *) §ion)) + { + while (g_menu_model_get_n_items (G_MENU_MODEL (section)) > 0) + g_menu_remove (section, 0); + } +} + static GMenu * create_status_section (void) { @@ -237,6 +253,7 @@ im_desktop_menu_constructed (GObject *object) g_signal_connect (applist, "app-added", G_CALLBACK (im_desktop_menu_app_added), menu); g_signal_connect (applist, "source-added", G_CALLBACK (im_desktop_menu_source_added), menu); g_signal_connect (applist, "source-removed", G_CALLBACK (im_desktop_menu_source_removed), menu); + g_signal_connect (applist, "remove-all", G_CALLBACK (im_desktop_menu_remove_all), menu); G_OBJECT_CLASS (im_desktop_menu_parent_class)->constructed (object); } -- cgit v1.2.3 From 341152a55798c18a4116f6940bbe6a3aaf28355c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 18 Aug 2013 22:50:15 -0500 Subject: clearing the sources on remove all --- src/im-application-list.c | 53 ++--------------------------------------------- 1 file changed, 2 insertions(+), 51 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 5a56df3..5884048 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -245,54 +245,6 @@ im_application_list_sub_message_activated (GSimpleAction *action, im_application_list_message_removed (app, message_id); } -/* If a source has a draw_attention state set, this clears it so that it - doesn't get calculated to draw attention */ -static void -im_application_list_source_clear_attention (Application * app, - gchar * source_name) -{ - GVariant * action_value = NULL; - GVariant * action_state = g_action_group_get_action_state(G_ACTION_GROUP(app->source_actions), source_name); - - /* If it doesn't draw attention, we're done */ - action_value = g_variant_get_child_value(action_state, 3); - if (!g_variant_get_boolean(action_value)) - { - g_variant_unref(action_value); - g_variant_unref(action_state); - return; - } - - g_variant_unref(action_value); - - /* We need to build a new state without the draw attention */ - GVariantBuilder new_state_builder; - g_variant_builder_init(&new_state_builder, G_VARIANT_TYPE_TUPLE); - - /* Count */ - action_value = g_variant_get_child_value(action_state, 0); - g_variant_builder_add_value(&new_state_builder, action_value); - g_variant_unref(action_value); - - /* Time */ - action_value = g_variant_get_child_value(action_state, 1); - g_variant_builder_add_value(&new_state_builder, action_value); - g_variant_unref(action_value); - - /* String */ - action_value = g_variant_get_child_value(action_state, 2); - g_variant_builder_add_value(&new_state_builder, action_value); - g_variant_unref(action_value); - - /* Draws Attention */ - g_variant_builder_add_value(&new_state_builder, g_variant_new_boolean(FALSE)); - - g_action_group_change_action_state(G_ACTION_GROUP(app->source_actions), source_name, g_variant_builder_end(&new_state_builder)); - - g_variant_unref(action_state); - return; -} - static void im_application_list_remove_all (GSimpleAction *action, GVariant *parameter, @@ -313,7 +265,7 @@ im_application_list_remove_all (GSimpleAction *action, source_actions = g_action_group_list_actions (G_ACTION_GROUP (app->source_actions)); for (it = source_actions; *it; it++) - im_application_list_source_clear_attention (app, *it); + im_application_list_source_removed (app, *it); message_actions = g_action_group_list_actions (G_ACTION_GROUP (app->message_actions)); for (it = message_actions; *it; it++) @@ -321,9 +273,8 @@ im_application_list_remove_all (GSimpleAction *action, if (app->proxy != NULL) /* If it is remote, we tell the app we've cleared */ { - gchar * null_list[1] = { NULL }; indicator_messages_application_call_dismiss (app->proxy, - (const gchar * const *) null_list, + (const gchar * const *) source_actions, (const gchar * const *) message_actions, app->cancellable, NULL, NULL); } -- cgit v1.2.3 From 2673fba29a0f3bd090dc3a8dc0002d91ebf401a1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 18 Aug 2013 23:13:51 -0500 Subject: Starting to regen the draw attention flag from the source actions --- src/im-application-list.c | 51 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 5884048..8078582 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -137,6 +137,47 @@ im_application_list_update_draws_attention (ImApplicationList *list) g_action_group_change_action_state (main_actions, "messages", state); } +/* Check a source action to see if it draws */ +static gboolean +app_source_action_check_draw (Application * app, const gchar * action_name) +{ + + return FALSE; +} + +/* Check a message action to see if it draws */ +static gboolean +app_message_action_check_draw (Application * app, const gchar * action_name) +{ + + return FALSE; +} + +/* Regenerate the draw attention flag based on the sources and messages + that we have in the action groups */ +static void +app_check_draw_attention (Application * app) +{ + gchar **source_actions = NULL; + gchar **message_actions = NULL; + gchar **it; + + source_actions = g_action_group_list_actions (G_ACTION_GROUP (app->source_actions)); + for (it = source_actions; *it && !app->draws_attention; it++) + app->draws_attention = app_source_action_check_draw (app, *it); + + message_actions = g_action_group_list_actions (G_ACTION_GROUP (app->message_actions)); + for (it = message_actions; *it; it++) + app->draws_attention = app_message_action_check_draw (app, *it); + + g_strfreev (source_actions); + g_strfreev (message_actions); + + return; +} + +/* Remove a source from an application, signal up and update the status + of the draws attention flag. */ static void im_application_list_source_removed (Application *app, const gchar *id) @@ -145,6 +186,12 @@ im_application_list_source_removed (Application *app, g_signal_emit (app->list, signals[SOURCE_REMOVED], 0, app->id, id); + if (app->draws_attention) + { + app->draws_attention = FALSE; + app_check_draw_attention(app); + } + im_application_list_update_draws_attention (app->list); } @@ -263,6 +310,8 @@ im_application_list_remove_all (GSimpleAction *action, gchar **message_actions; gchar **it; + app->draws_attention = FALSE; + source_actions = g_action_group_list_actions (G_ACTION_GROUP (app->source_actions)); for (it = source_actions; *it; it++) im_application_list_source_removed (app, *it); @@ -281,8 +330,6 @@ im_application_list_remove_all (GSimpleAction *action, g_strfreev (source_actions); g_strfreev (message_actions); - - app->draws_attention = FALSE; } im_application_list_update_draws_attention (list); -- cgit v1.2.3 From a48ab9b84578f6d3f22d7be310d8e32be779c0e0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 18 Aug 2013 23:17:35 -0500 Subject: Check the action state to get whether it's drawing or not --- src/im-application-list.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 8078582..fedd9e1 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -141,14 +141,27 @@ im_application_list_update_draws_attention (ImApplicationList *list) static gboolean app_source_action_check_draw (Application * app, const gchar * action_name) { + gboolean retval = FALSE; + GVariant * state; + GVariant * draw; - return FALSE; + state = g_action_group_get_action_state (G_ACTION_GROUP(app->source_actions), action_name); + + /* uxsb */ + draw = g_variant_get_child_value(state, 3); + retval = g_variant_get_boolean(draw); + + g_variant_unref(draw); + g_variant_unref(state); + + return retval; } /* Check a message action to see if it draws */ static gboolean app_message_action_check_draw (Application * app, const gchar * action_name) { + /* TODO: Not stored currently */ return FALSE; } -- cgit v1.2.3 From 00d61143f54e7b0e2551f6db54b8c6ba4deef250 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 18 Aug 2013 23:25:05 -0500 Subject: Save the draws attention for messages and react to that --- src/im-application-list.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index fedd9e1..bba7972 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -41,6 +41,7 @@ struct _ImApplicationList }; G_DEFINE_TYPE (ImApplicationList, im_application_list, G_TYPE_OBJECT); +G_DEFINE_QUARK (draws_attention, message_action_draws_attention); enum { @@ -161,9 +162,9 @@ app_source_action_check_draw (Application * app, const gchar * action_name) static gboolean app_message_action_check_draw (Application * app, const gchar * action_name) { - /* TODO: Not stored currently */ - - return FALSE; + GAction * action = NULL; + action = g_simple_action_group_lookup (app->message_actions, action_name); + return GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(action), message_action_draws_attention_quark())); } /* Regenerate the draw attention flag based on the sources and messages @@ -807,6 +808,7 @@ im_application_list_message_added (Application *app, app_iconstr = get_symbolic_app_icon_string (app_icon); action = g_simple_action_new (id, G_VARIANT_TYPE_BOOLEAN); + g_object_set_qdata(G_OBJECT(action), message_action_draws_attention_quark(), GINT_TO_POINTER(draws_attention)); g_signal_connect (action, "activate", G_CALLBACK (im_application_list_message_activated), app); g_simple_action_group_insert (app->message_actions, G_ACTION (action)); -- cgit v1.2.3 From d519c3e75bfbaa4f66ea8306ee5d785bdcead1aa Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 19 Aug 2013 09:14:30 -0500 Subject: Set the action --- src/im-desktop-menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c index e8dff6f..1040d62 100644 --- a/src/im-desktop-menu.c +++ b/src/im-desktop-menu.c @@ -114,7 +114,7 @@ im_desktop_menu_source_added (ImApplicationList *applist, g_return_if_fail (source_section != NULL); action = g_strconcat ("src.", source_id, NULL); - item = g_menu_item_new (label, NULL); + item = g_menu_item_new (label, action); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.source"); if (icon && *icon) g_menu_item_set_attribute (item, "icon", "s", icon); -- cgit v1.2.3