aboutsummaryrefslogtreecommitdiff
path: root/src/im-source-menu-item.c
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2012-08-21 11:40:47 +0200
committerLars Uebernickel <lars.uebernickel@canonical.com>2012-08-21 11:40:47 +0200
commit7d036b65aac90b646eb7845cfc8e229464f372f0 (patch)
tree0f35744b42ad90681db927832228d0002f0f41f9 /src/im-source-menu-item.c
parent699c7421e9591326e1629e2fce586e0336623936 (diff)
downloadayatana-indicator-messages-7d036b65aac90b646eb7845cfc8e229464f372f0.tar.gz
ayatana-indicator-messages-7d036b65aac90b646eb7845cfc8e229464f372f0.tar.bz2
ayatana-indicator-messages-7d036b65aac90b646eb7845cfc8e229464f372f0.zip
Show icons in application and source menu items
Everthing goes through GIcon now, using g_icon_{to,new_for}_string to set a string attribute on the menu item. The attribute is prefixed x-canonical- for now.
Diffstat (limited to 'src/im-source-menu-item.c')
-rw-r--r--src/im-source-menu-item.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/im-source-menu-item.c b/src/im-source-menu-item.c
index b0c55f4..269c75d 100644
--- a/src/im-source-menu-item.c
+++ b/src/im-source-menu-item.c
@@ -26,6 +26,7 @@ struct _ImSourceMenuItemPrivate
GActionGroup *action_group;
gchar *action;
+ GtkWidget *icon;
GtkWidget *label;
GtkWidget *detail;
};
@@ -51,8 +52,10 @@ im_source_menu_item_constructed (GObject *object)
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 + 2);
+
priv->label = g_object_ref (gtk_label_new (""));
- gtk_widget_set_margin_left (priv->label, icon_width + 2);
priv->detail = g_object_ref (gtk_label_new (""));
gtk_widget_set_halign (priv->detail, GTK_ALIGN_END);
@@ -61,8 +64,9 @@ im_source_menu_item_constructed (GObject *object)
gtk_style_context_add_class (gtk_widget_get_style_context (priv->detail), "accelerator");
grid = gtk_grid_new ();
- gtk_grid_attach (GTK_GRID (grid), priv->label, 0, 0, 1, 1);
- gtk_grid_attach (GTK_GRID (grid), priv->detail, 1, 0, 1, 1);
+ 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);
@@ -274,6 +278,7 @@ im_source_menu_item_dispose (GObject *object)
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);
@@ -343,15 +348,32 @@ 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);
}