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(-) 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