aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-09-09 14:32:02 +0000
committerTarmac <Unknown>2013-09-09 14:32:02 +0000
commitbcb22de41454a1f8d7b7e5189c2590c94950f5c2 (patch)
treec22bbf4620910bdca7bcbbe9c60257beadb2337c /src
parent9b383fa4369926ac50e4999becad4e6af3650146 (diff)
parent2b37622e83ae150320d6aa540c79e85a2574ffd5 (diff)
downloadayatana-indicator-messages-bcb22de41454a1f8d7b7e5189c2590c94950f5c2.tar.gz
ayatana-indicator-messages-bcb22de41454a1f8d7b7e5189c2590c94950f5c2.tar.bz2
ayatana-indicator-messages-bcb22de41454a1f8d7b7e5189c2590c94950f5c2.zip
Use g_icon_serialize() instead of g_icon_to_string().
Approved by Charles Kerr, PS Jenkins bot.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gmenuutils.c87
-rw-r--r--src/gmenuutils.h38
-rw-r--r--src/im-application-list.c93
-rw-r--r--src/im-desktop-menu.c23
-rw-r--r--src/im-phone-menu.c16
-rw-r--r--src/im-phone-menu.h4
-rw-r--r--src/messages-service.c1
8 files changed, 85 insertions, 179 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index b9ea10a..bc674c2 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 <http://www.gnu.org/licenses/>.
- *
- * Authors:
- * Lars Uebernickel <lars.uebernickel@canonical.com>
- */
-
-#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 <http://www.gnu.org/licenses/>.
- *
- * Authors:
- * Lars Uebernickel <lars.uebernickel@canonical.com>
- */
-
-#ifndef __G_MENU_UTILS_H__
-#define __G_MENU_UTILS_H__
-
-#include <gio/gio.h>
-
-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/im-application-list.c b/src/im-application-list.c
index bbe4be3..c3d9930 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);
@@ -467,7 +469,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,
@@ -503,9 +505,9 @@ im_application_list_class_init (ImApplicationListClass *klass)
G_TYPE_NONE,
10,
G_TYPE_STRING,
+ G_TYPE_ICON,
G_TYPE_STRING,
- G_TYPE_STRING,
- G_TYPE_STRING,
+ G_TYPE_VARIANT,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
@@ -768,16 +770,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 +791,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 +799,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 +810,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
@@ -853,31 +870,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
@@ -885,24 +904,23 @@ 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);
- app_icon = g_app_info_get_icon (G_APP_INFO (app->info));
- if (app_icon)
- app_iconstr = get_symbolic_app_icon_string (app_icon);
+ if (g_variant_n_children (maybe_serialized_icon) == 1)
+ serialized_icon = g_variant_get_child_value (maybe_serialized_icon, 0);
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));
@@ -980,13 +998,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, iconstr, 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_variant_unref (serialized_icon);
+ g_variant_unref (maybe_serialized_icon);
+ g_object_unref (app_icon);
}
static void
diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c
index 5707390..775483e 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
@@ -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);
diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c
index a9c5977..0f0a6da 100644
--- a/src/im-phone-menu.c
+++ b/src/im-phone-menu.c
@@ -151,9 +151,9 @@ 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,
- const gchar *iconstr,
+ GVariant *serialized_icon,
const gchar *title,
const gchar *subtitle,
const gchar *body,
@@ -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);
@@ -179,11 +180,14 @@ 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);
+ 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 9742f61..4f96c8c 100644
--- a/src/im-phone-menu.h
+++ b/src/im-phone-menu.h
@@ -37,9 +37,9 @@ 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,
- const gchar *iconstr,
+ GVariant *serialized_icon,
const gchar *title,
const gchar *subtitle,
const gchar *body,
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 <http://www.gnu.org/licenses/>.
#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"