From 44d14782870339fb1702ba42d26f43755c064e0d Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 5 Sep 2013 18:17:58 +0200 Subject: Use serialized icons for messages and sources The D-Bus protocol is not part of the public API, so it's okay to change it. --- src/im-application-list.c | 50 ++++++++++++++++++++++++++++++++++------------- src/im-desktop-menu.c | 14 ++++++------- src/im-phone-menu.c | 6 +++--- src/im-phone-menu.h | 2 +- 4 files changed, 47 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index bbe4be3..96ef5fd 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -467,7 +467,7 @@ im_application_list_class_init (ImApplicationListClass *klass) G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_STRING); + G_TYPE_VARIANT); signals[SOURCE_CHANGED] = g_signal_new ("source-changed", IM_TYPE_APPLICATION_LIST, @@ -505,7 +505,7 @@ im_application_list_class_init (ImApplicationListClass *klass) G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_STRING, + G_TYPE_VARIANT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, @@ -768,16 +768,20 @@ im_application_list_source_added (Application *app, { const gchar *id; const gchar *label; - const gchar *iconstr; + GVariant *maybe_serialized_icon; guint32 count; gint64 time; const gchar *string; gboolean draws_attention; + GVariant *serialized_icon = NULL; GVariant *state; GSimpleAction *action; - g_variant_get (source, "(&s&s&sux&sb)", - &id, &label, &iconstr, &count, &time, &string, &draws_attention); + g_variant_get (source, "(&s&s@avux&sb)", + &id, &label, &maybe_serialized_icon, &count, &time, &string, &draws_attention); + + if (g_variant_n_children (maybe_serialized_icon) == 1) + g_variant_get_child (maybe_serialized_icon, 0, "v", &serialized_icon); state = g_variant_new ("(uxsb)", count, time, string, draws_attention); action = g_simple_action_new_stateful (id, G_VARIANT_TYPE_BOOLEAN, state); @@ -785,7 +789,7 @@ im_application_list_source_added (Application *app, g_action_map_add_action (G_ACTION_MAP(app->source_actions), G_ACTION (action)); - g_signal_emit (app->list, signals[SOURCE_ADDED], 0, app->id, id, label, iconstr); + g_signal_emit (app->list, signals[SOURCE_ADDED], 0, app->id, id, label, serialized_icon); if (draws_attention) app->draws_attention = TRUE; @@ -793,6 +797,9 @@ im_application_list_source_added (Application *app, im_application_list_update_draws_attention (app->list); g_object_unref (action); + if (serialized_icon) + g_variant_unref (serialized_icon); + g_variant_unref (maybe_serialized_icon); } static void @@ -801,25 +808,33 @@ im_application_list_source_changed (Application *app, { const gchar *id; const gchar *label; - const gchar *iconstr; + GVariant *maybe_serialized_icon; guint32 count; gint64 time; const gchar *string; gboolean draws_attention; + GVariant *serialized_icon = NULL; gboolean visible; - g_variant_get (source, "(&s&s&sux&sb)", - &id, &label, &iconstr, &count, &time, &string, &draws_attention); + g_variant_get (source, "(&s&s@avux&sb)", + &id, &label, &maybe_serialized_icon, &count, &time, &string, &draws_attention); + + if (g_variant_n_children (maybe_serialized_icon) == 1) + g_variant_get_child (maybe_serialized_icon, 0, "v", &serialized_icon); g_action_group_change_action_state (G_ACTION_GROUP (app->source_actions), id, g_variant_new ("(uxsb)", count, time, string, draws_attention)); visible = count > 0; - g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->id, id, label, iconstr, visible); + g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->id, id, label, serialized_icon, visible); app->draws_attention = visible && draws_attention; im_application_list_update_draws_attention (app->list); + + if (serialized_icon) + g_variant_unref (serialized_icon); + g_variant_unref (maybe_serialized_icon); } static void @@ -885,20 +900,24 @@ im_application_list_message_added (Application *app, GVariant *message) { const gchar *id; - const gchar *iconstr; + GVariant *maybe_serialized_icon; const gchar *title; const gchar *subtitle; const gchar *body; gint64 time; GVariantIter *action_iter; gboolean draws_attention; + GVariant *serialized_icon = NULL; GSimpleAction *action; GIcon *app_icon; gchar *app_iconstr = NULL; GVariant *actions = NULL; - g_variant_get (message, "(&s&s&s&s&sxaa{sv}b)", - &id, &iconstr, &title, &subtitle, &body, &time, &action_iter, &draws_attention); + g_variant_get (message, "(&s@av&s&s&sxaa{sv}b)", + &id, &maybe_serialized_icon, &title, &subtitle, &body, &time, &action_iter, &draws_attention); + + if (g_variant_n_children (maybe_serialized_icon) == 1) + serialized_icon = g_variant_get_child_value (maybe_serialized_icon, 0); app_icon = g_app_info_get_icon (G_APP_INFO (app->info)); if (app_icon) @@ -981,12 +1000,15 @@ im_application_list_message_added (Application *app, im_application_list_update_draws_attention (app->list); g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, - app->id, app_iconstr, id, iconstr, title, + app->id, app_iconstr, id, serialized_icon, title, subtitle, body, actions, time, draws_attention); g_variant_iter_free (action_iter); g_free (app_iconstr); g_object_unref (action); + if (serialized_icon) + g_object_unref (serialized_icon); + g_variant_unref (maybe_serialized_icon); } static void diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c index 5707390..923ad91 100644 --- a/src/im-desktop-menu.c +++ b/src/im-desktop-menu.c @@ -109,7 +109,7 @@ static void im_desktop_menu_source_section_insert_source (GMenu *source_section, const gchar *source_id, const gchar *label, - const gchar *icon, + GVariant *serialized_icon, gint pos) { GMenuItem *item; @@ -119,8 +119,8 @@ im_desktop_menu_source_section_insert_source (GMenu *source_section, item = g_menu_item_new (label, NULL); g_menu_item_set_action_and_target_value (item, action, NULL); 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); + if (serialized_icon) + g_menu_item_set_attribute_value (item, "icon", serialized_icon); if (pos >= 0) g_menu_insert_item (source_section, pos, item); @@ -169,7 +169,7 @@ im_desktop_menu_source_added (ImApplicationList *applist, const gchar *app_id, const gchar *source_id, const gchar *label, - const gchar *icon, + GVariant *serialized_icon, gpointer user_data) { ImDesktopMenu *menu = user_data; @@ -178,7 +178,7 @@ im_desktop_menu_source_added (ImApplicationList *applist, source_section = g_hash_table_lookup (menu->source_sections, app_id); g_return_if_fail (source_section != NULL); - im_desktop_menu_source_section_insert_source (source_section, source_id, label, icon, -1); + im_desktop_menu_source_section_insert_source (source_section, source_id, label, serialized_icon, -1); } static void @@ -204,7 +204,7 @@ im_desktop_menu_source_changed (ImApplicationList *applist, const gchar *app_id, const gchar *source_id, const gchar *label, - const gchar *icon, + GVariant *serialized_icon, gboolean visible, gpointer user_data) { @@ -221,7 +221,7 @@ im_desktop_menu_source_changed (ImApplicationList *applist, g_menu_remove (section, pos); if (visible) - im_desktop_menu_source_section_insert_source (section, source_id, label, icon, pos); + im_desktop_menu_source_section_insert_source (section, source_id, label, serialized_icon, pos); } static void diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index a9c5977..54e32be 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -153,7 +153,7 @@ im_phone_menu_add_message (ImPhoneMenu *menu, const gchar *app_id, const gchar *app_icon, const gchar *id, - const gchar *iconstr, + GVariant *serialized_icon, const gchar *title, const gchar *subtitle, const gchar *body, @@ -179,8 +179,8 @@ im_phone_menu_add_message (ImPhoneMenu *menu, 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, "icon", "s", iconstr); + if (serialized_icon) + g_menu_item_set_attribute_value (item, "icon", serialized_icon); if (app_icon) g_menu_item_set_attribute (item, "x-canonical-app-icon", "s", app_icon); diff --git a/src/im-phone-menu.h b/src/im-phone-menu.h index 9742f61..728ecaa 100644 --- a/src/im-phone-menu.h +++ b/src/im-phone-menu.h @@ -39,7 +39,7 @@ void im_phone_menu_add_message (ImPhoneMenu *men const gchar *app_id, const gchar *app_icon, const gchar *id, - const gchar *iconstr, + GVariant *serialized_icon, const gchar *title, const gchar *subtitle, const gchar *body, -- cgit v1.2.3 From fde79fff1fddbf747915cf0fe477435a6dc479f8 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 6 Sep 2013 12:06:40 +0200 Subject: Use g_icon_serialize() for application icons --- src/im-application-list.c | 37 ++++++++++++++++++------------------- src/im-phone-menu.c | 10 +++++++--- src/im-phone-menu.h | 2 +- 3 files changed, 26 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index 96ef5fd..ce463fb 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -503,7 +503,7 @@ im_application_list_class_init (ImApplicationListClass *klass) G_TYPE_NONE, 10, G_TYPE_STRING, - G_TYPE_STRING, + G_TYPE_ICON, G_TYPE_STRING, G_TYPE_VARIANT, G_TYPE_STRING, @@ -868,31 +868,33 @@ im_application_list_sources_listed (GObject *source_object, } } -static gchar * -get_symbolic_app_icon_string (GIcon *icon) +static GIcon * +get_symbolic_app_icon (GAppInfo *info) { + GIcon *icon; const gchar * const *names; gchar *symbolic_name; GIcon *symbolic_icon; - gchar *str; - if (!G_IS_THEMED_ICON (icon)) + icon = g_app_info_get_icon (info); + if (icon == NULL) return NULL; + if (!G_IS_THEMED_ICON (icon)) + return g_object_ref (icon); + 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); + return g_object_ref (icon); 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); + symbolic_icon = g_themed_icon_new_from_names ((gchar **) names, -1); + g_themed_icon_prepend_name (G_THEMED_ICON (symbolic_icon), symbolic_name); g_free (symbolic_name); - g_object_unref (symbolic_icon); - return str; + + return symbolic_icon; } static void @@ -910,7 +912,6 @@ im_application_list_message_added (Application *app, GVariant *serialized_icon = NULL; GSimpleAction *action; GIcon *app_icon; - gchar *app_iconstr = NULL; GVariant *actions = NULL; g_variant_get (message, "(&s@av&s&s&sxaa{sv}b)", @@ -919,10 +920,6 @@ im_application_list_message_added (Application *app, if (g_variant_n_children (maybe_serialized_icon) == 1) serialized_icon = g_variant_get_child_value (maybe_serialized_icon, 0); - app_icon = g_app_info_get_icon (G_APP_INFO (app->info)); - if (app_icon) - 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); @@ -999,16 +996,18 @@ im_application_list_message_added (Application *app, im_application_list_update_draws_attention (app->list); + app_icon = get_symbolic_app_icon (G_APP_INFO (app->info)); + g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, - app->id, app_iconstr, id, serialized_icon, title, + app->id, app_icon, id, serialized_icon, title, subtitle, body, actions, time, draws_attention); g_variant_iter_free (action_iter); - g_free (app_iconstr); g_object_unref (action); if (serialized_icon) g_object_unref (serialized_icon); g_variant_unref (maybe_serialized_icon); + g_object_unref (app_icon); } static void diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index 54e32be..0f0a6da 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -151,7 +151,7 @@ im_phone_menu_get_message_time (GMenuModel *model, void im_phone_menu_add_message (ImPhoneMenu *menu, const gchar *app_id, - const gchar *app_icon, + GIcon *app_icon, const gchar *id, GVariant *serialized_icon, const gchar *title, @@ -164,6 +164,7 @@ im_phone_menu_add_message (ImPhoneMenu *menu, gchar *action_name; gint n_messages; gint pos; + GVariant *serialized_app_icon; g_return_if_fail (IM_IS_PHONE_MENU (menu)); g_return_if_fail (app_id); @@ -182,8 +183,11 @@ im_phone_menu_add_message (ImPhoneMenu *menu, if (serialized_icon) g_menu_item_set_attribute_value (item, "icon", serialized_icon); - if (app_icon) - g_menu_item_set_attribute (item, "x-canonical-app-icon", "s", app_icon); + if (app_icon && (serialized_app_icon = g_icon_serialize (app_icon))) + { + g_menu_item_set_attribute_value (item, "x-canonical-app-icon", serialized_app_icon); + g_variant_unref (serialized_app_icon); + } if (actions) g_menu_item_set_attribute (item, "x-canonical-message-actions", "v", actions); diff --git a/src/im-phone-menu.h b/src/im-phone-menu.h index 728ecaa..4f96c8c 100644 --- a/src/im-phone-menu.h +++ b/src/im-phone-menu.h @@ -37,7 +37,7 @@ ImPhoneMenu * im_phone_menu_new (ImApplicationList *app void im_phone_menu_add_message (ImPhoneMenu *menu, const gchar *app_id, - const gchar *app_icon, + GIcon *app_icon, const gchar *id, GVariant *serialized_icon, const gchar *title, -- cgit v1.2.3 From aa830233ca58715674aa6ef48ae6dad38d27c176 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 6 Sep 2013 12:14:38 +0200 Subject: im_application_list_update_draws_attention: fix GVariant leak g_icon_serialize() returns a full (not a floating) reference. --- src/im-application-list.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/im-application-list.c b/src/im-application-list.c index ce463fb..6b2da3f 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -161,6 +161,7 @@ im_application_list_update_draws_attention (ImApplicationList *list) const gchar *accessible_name; const gchar *icon_name; GIcon * icon; + GVariant *serialized_icon; GVariantBuilder builder; GVariant *state; @@ -182,12 +183,13 @@ im_application_list_update_draws_attention (ImApplicationList *list) g_variant_builder_init(&builder, G_VARIANT_TYPE_DICTIONARY); /* icon */ - g_variant_builder_open(&builder, G_VARIANT_TYPE_DICT_ENTRY); - g_variant_builder_add_value(&builder, g_variant_new_string("icon")); icon = g_themed_icon_new_with_default_fallbacks(icon_name); - g_variant_builder_add_value(&builder, g_variant_new_variant(g_icon_serialize(icon))); + if ((serialized_icon = g_icon_serialize(icon))) + { + g_variant_builder_add (&builder, "{sv}", "icon", serialized_icon); + g_variant_unref (serialized_icon); + } g_object_unref(icon); - g_variant_builder_close(&builder); /* accessible description */ g_variant_builder_open(&builder, G_VARIANT_TYPE_DICT_ENTRY); -- cgit v1.2.3 From 3fd7588b1617b3556d4e328cbb52bc0adede9d6e Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 6 Sep 2013 12:15:51 +0200 Subject: im_application_list_message_added: don't use g_object_unref for variants --- 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 6b2da3f..c3d9930 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -1007,7 +1007,7 @@ im_application_list_message_added (Application *app, g_variant_iter_free (action_iter); g_object_unref (action); if (serialized_icon) - g_object_unref (serialized_icon); + g_variant_unref (serialized_icon); g_variant_unref (maybe_serialized_icon); g_object_unref (app_icon); } -- cgit v1.2.3 From 22b393aa7e08004d14e45c23b9f159f3b5160ede Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 6 Sep 2013 12:23:28 +0200 Subject: create_status_section: use g_icon_serialize() --- src/im-desktop-menu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c index 923ad91..775483e 100644 --- a/src/im-desktop-menu.c +++ b/src/im-desktop-menu.c @@ -278,10 +278,17 @@ create_status_section (void) item = g_menu_item_new (NULL, NULL); for (i = 0; i < G_N_ELEMENTS (status_items); i++) { + GIcon *icon; + 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, "icon", "s", status_items[i].icon_name); + + icon = g_themed_icon_new (status_items[i].icon_name); + g_menu_item_set_icon (item, icon); + g_menu_append_item (menu, item); + + g_object_unref (icon); } g_object_unref (item); -- cgit v1.2.3 From 2b37622e83ae150320d6aa540c79e85a2574ffd5 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 6 Sep 2013 12:27:33 +0200 Subject: Remove gmenuutils, it's not being used anymore --- src/Makefile.am | 2 -- src/gmenuutils.c | 87 -------------------------------------------------- src/gmenuutils.h | 38 ---------------------- src/messages-service.c | 1 - 4 files changed, 128 deletions(-) delete mode 100644 src/gmenuutils.c delete mode 100644 src/gmenuutils.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 8d77dea..1802786 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,8 +10,6 @@ indicator_messages_service_SOURCES = \ gactionmuxer.h \ gsettingsstrv.c \ gsettingsstrv.h \ - gmenuutils.c \ - gmenuutils.h \ im-menu.c \ im-menu.h \ im-phone-menu.c \ diff --git a/src/gmenuutils.c b/src/gmenuutils.c deleted file mode 100644 index cfd751e..0000000 --- a/src/gmenuutils.c +++ /dev/null @@ -1,87 +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 "gmenuutils.h" -#include "dbus-data.h" - -/* g_menu_find_section: - * @menu: a #GMenu - * @section: the section to be found in @menu - * - * @Returns the index of the first menu item that is linked to #section, or -1 - * if there's no such item. - */ -int -g_menu_find_section (GMenu *menu, - GMenuModel *section) -{ - GMenuModel *model = G_MENU_MODEL (menu); - int n_items; - int i; - - g_return_val_if_fail (G_IS_MENU_MODEL (section), -1); - - n_items = g_menu_model_get_n_items (model); - for (i = 0; i < n_items; i++) - { - GMenuModel *link; - gboolean found; - - link = g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION); - found = section == link; - - g_object_unref (link); - - if (found) - return i; - } - - return -1; -} - - -void -g_menu_append_with_icon (GMenu *menu, - const gchar *label, - GIcon *icon, - const gchar *detailed_action) -{ - gchar *iconstr; - - iconstr = g_icon_to_string (icon); - g_menu_append_with_icon_name (menu, label, iconstr, detailed_action); - - g_free (iconstr); -} - -void -g_menu_append_with_icon_name (GMenu *menu, - const gchar *label, - const gchar *icon_name, - const gchar *detailed_action) -{ - GMenuItem *item; - - item = g_menu_item_new (label, detailed_action); - g_menu_item_set_attribute (item, "icon", "s", icon_name); - - g_menu_append_item (menu, item); - - g_object_unref (item); -} diff --git a/src/gmenuutils.h b/src/gmenuutils.h deleted file mode 100644 index e00ac55..0000000 --- a/src/gmenuutils.h +++ /dev/null @@ -1,38 +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 __G_MENU_UTILS_H__ -#define __G_MENU_UTILS_H__ - -#include - -int g_menu_find_section (GMenu *menu, - GMenuModel *section); - -void g_menu_append_with_icon (GMenu *menu, - const gchar *label, - GIcon *icon, - const gchar *detailed_action); - -void g_menu_append_with_icon_name (GMenu *menu, - const gchar *label, - const gchar *icon_name, - const gchar *detailed_action); - -#endif diff --git a/src/messages-service.c b/src/messages-service.c index a8deb6a..954fccc 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -29,7 +29,6 @@ with this program. If not, see . #include "dbus-data.h" #include "gsettingsstrv.h" -#include "gmenuutils.h" #include "indicator-messages-service.h" #include "indicator-messages-application.h" #include "im-phone-menu.h" -- cgit v1.2.3