aboutsummaryrefslogtreecommitdiff
path: root/src/indicator-menu-item.c
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2012-01-14 23:51:10 +0100
committerLars Uebernickel <lars.uebernickel@canonical.com>2012-01-14 23:51:10 +0100
commit1e56f31341ecdb60456929a3d6d07bb16409b399 (patch)
tree8c0946f0345af7324b1a217d33e9dad2fff0b4ae /src/indicator-menu-item.c
parent1b671f1d837a97fb60fe03958f6e1b704981607a (diff)
downloadayatana-indicator-printers-1e56f31341ecdb60456929a3d6d07bb16409b399.tar.gz
ayatana-indicator-printers-1e56f31341ecdb60456929a3d6d07bb16409b399.tar.bz2
ayatana-indicator-printers-1e56f31341ecdb60456929a3d6d07bb16409b399.zip
Add the possibility to set an icon on indicator-menu-item
Diffstat (limited to 'src/indicator-menu-item.c')
-rw-r--r--src/indicator-menu-item.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/indicator-menu-item.c b/src/indicator-menu-item.c
index 72faad6..afdf980 100644
--- a/src/indicator-menu-item.c
+++ b/src/indicator-menu-item.c
@@ -11,6 +11,7 @@ G_DEFINE_TYPE (IndicatorMenuItem, indicator_menu_item, GTK_TYPE_MENU_ITEM)
struct _IndicatorMenuItemPrivate
{
+ GtkImage *image;
GtkWidget *label;
GtkWidget *right_label;
gboolean right_is_lozenge;
@@ -19,6 +20,8 @@ struct _IndicatorMenuItemPrivate
enum {
PROP_0,
+ PROP_ICON,
+ PROP_ICON_NAME,
PROP_LABEL,
PROP_RIGHT,
PROP_RIGHT_IS_LOZENGE,
@@ -99,10 +102,19 @@ indicator_menu_item_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
+ IndicatorMenuItem *self = INDICATOR_MENU_ITEM (object);
IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (object);
switch (property_id)
{
+ case PROP_ICON:
+ g_value_set_object (value, indicator_menu_item_get_icon (self));
+ break;
+
+ case PROP_ICON_NAME:
+ g_value_set_string (value, indicator_menu_item_get_icon_name (self));
+ break;
+
case PROP_LABEL:
g_value_set_string (value, gtk_label_get_label (GTK_LABEL (priv->label)));
break;
@@ -131,6 +143,16 @@ indicator_menu_item_set_property (GObject *object,
switch (property_id)
{
+ case PROP_ICON:
+ indicator_menu_item_set_icon (INDICATOR_MENU_ITEM (object),
+ g_value_get_object (value));
+ break;
+
+ case PROP_ICON_NAME:
+ indicator_menu_item_set_icon_name (INDICATOR_MENU_ITEM (object),
+ g_value_get_string (value));
+ break;
+
case PROP_LABEL:
indicator_menu_item_set_label (INDICATOR_MENU_ITEM (object),
g_value_get_string (value));
@@ -158,6 +180,7 @@ indicator_menu_item_dispose (GObject *object)
{
IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (object);
+ g_clear_object (&priv->image);
g_clear_object (&priv->label);
g_clear_object (&priv->right_label);
@@ -176,6 +199,18 @@ indicator_menu_item_class_init (IndicatorMenuItemClass *klass)
object_class->set_property = indicator_menu_item_set_property;
object_class->dispose = indicator_menu_item_dispose;
+ properties[PROP_ICON] = g_param_spec_object ("icon",
+ "Icon",
+ "Icon for this menu item",
+ GDK_TYPE_PIXBUF,
+ G_PARAM_READWRITE);
+
+ properties[PROP_ICON_NAME] = g_param_spec_string ("icon-name",
+ "Icon name",
+ "Name of the themed icon",
+ "",
+ G_PARAM_READWRITE);
+
properties[PROP_LABEL] = g_param_spec_string ("label",
"Label",
"The text for the main label",
@@ -211,6 +246,10 @@ indicator_menu_item_init (IndicatorMenuItem *self)
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, spacing);
+ priv->image = g_object_new (GTK_TYPE_IMAGE, NULL);
+ g_object_ref_sink (priv->image);
+ gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (priv->image), FALSE, FALSE, 0);
+
priv->label = g_object_new (GTK_TYPE_LABEL,
"xalign", 0.0,
NULL);
@@ -265,3 +304,47 @@ indicator_menu_item_set_right (IndicatorMenuItem *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_RIGHT]);
}
+
+GdkPixbuf *
+indicator_menu_item_get_icon (IndicatorMenuItem *self)
+{
+ IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (self);
+ if (gtk_image_get_storage_type (priv->image) == GTK_IMAGE_PIXBUF)
+ return gtk_image_get_pixbuf (priv->image);
+ else
+ return NULL;
+}
+
+
+void
+indicator_menu_item_set_icon (IndicatorMenuItem *self,
+ GdkPixbuf *icon)
+{
+ IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (self);
+ gtk_image_set_from_pixbuf (priv->image, icon);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICON]);
+}
+
+
+const gchar *
+indicator_menu_item_get_icon_name (IndicatorMenuItem *self)
+{
+ IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (self);
+ const gchar *name = NULL;
+
+ if (gtk_image_get_storage_type (priv->image) == GTK_IMAGE_ICON_NAME)
+ gtk_image_get_icon_name (priv->image, &name, NULL);
+
+ return name;
+}
+
+
+void
+indicator_menu_item_set_icon_name (IndicatorMenuItem *self,
+ const gchar *name)
+{
+ IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (self);
+ gtk_image_set_from_icon_name (priv->image, name, GTK_ICON_SIZE_MENU);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICON_NAME]);
+}
+