diff options
author | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2021-04-27 17:13:14 +0200 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2021-04-27 17:13:14 +0200 |
commit | 12c8fa46e2b9b7596a89637ed62468c2c47d47a7 (patch) | |
tree | 0ef292d5db806afcf07736ac18d48d71b61cef0c /src/idobasicmenuitem.c | |
parent | fcf633bdbc0b7d64fe1ea6005ab007f0db151c4e (diff) | |
parent | 241bd377a1d0c4e3b4f66f1cf4ff63d59fae1286 (diff) | |
download | ayatana-ido-12c8fa46e2b9b7596a89637ed62468c2c47d47a7.tar.gz ayatana-ido-12c8fa46e2b9b7596a89637ed62468c2c47d47a7.tar.bz2 ayatana-ido-12c8fa46e2b9b7596a89637ed62468c2c47d47a7.zip |
Merge branch 'tari01-pr/add-appointment-icon'
Attribute GH PR #28: https://github.com/AyatanaIndicators/ayatana-ido/pull/28
Diffstat (limited to 'src/idobasicmenuitem.c')
-rw-r--r-- | src/idobasicmenuitem.c | 71 |
1 files changed, 57 insertions, 14 deletions
diff --git a/src/idobasicmenuitem.c b/src/idobasicmenuitem.c index 080151c..41f69db 100644 --- a/src/idobasicmenuitem.c +++ b/src/idobasicmenuitem.c @@ -1,8 +1,10 @@ /* * Copyright 2013 Canonical Ltd. + * Copyright 2021 AyatanaIndicators * * Authors: * Charles Kerr <charles.kerr@canonical.com> + * Robert Tari <robert@tari.in> * * 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 @@ -26,6 +28,7 @@ enum { PROP_0, PROP_ICON, + PROP_PIXBUF, PROP_TEXT, PROP_SECONDARY_TEXT, PROP_LAST @@ -35,6 +38,7 @@ static GParamSpec *properties[PROP_LAST]; typedef struct { GIcon * icon; + GdkPixbuf *pPixbuf; char * text; char * secondary_text; @@ -64,6 +68,10 @@ my_get_property (GObject * o, g_value_set_object (value, p->icon); break; + case PROP_PIXBUF: + g_value_set_object(value, p->pPixbuf); + break; + case PROP_TEXT: g_value_set_string (value, p->text); break; @@ -92,6 +100,10 @@ my_set_property (GObject * o, ido_basic_menu_item_set_icon (self, g_value_get_object (value)); break; + case PROP_PIXBUF: + ido_basic_menu_item_set_pixbuf(self, g_value_get_object(value)); + break; + case PROP_TEXT: ido_basic_menu_item_set_text (self, g_value_get_string (value)); break; @@ -113,6 +125,7 @@ my_dispose (GObject * object) IdoBasicMenuItemPrivate *p = ido_basic_menu_item_get_instance_private(self); g_clear_object (&p->icon); + g_clear_object (&p->pPixbuf); G_OBJECT_CLASS (ido_basic_menu_item_parent_class)->dispose (object); } @@ -136,31 +149,39 @@ ido_basic_menu_item_update_image (IdoBasicMenuItem *self) gtk_image_clear (GTK_IMAGE (p->image)); - if (p->icon == NULL) + if (p->icon == NULL && p->pPixbuf == NULL) { gtk_widget_set_visible (p->image, FALSE); } else { - GtkIconInfo *info; - const gchar *filename; + if (p->pPixbuf) + { + gtk_image_set_from_pixbuf(GTK_IMAGE(p->image), p->pPixbuf); + gtk_widget_set_visible(p->image, TRUE); + } + else if (p->icon) + { + GtkIconInfo *info; + const gchar *filename; - info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), p->icon, 16, 0); - filename = gtk_icon_info_get_filename (info); + info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), p->icon, 16, 0); + filename = gtk_icon_info_get_filename (info); - if (filename) - { - GdkPixbuf *pixbuf; + if (filename) + { + GdkPixbuf *pixbuf; - pixbuf = gdk_pixbuf_new_from_file_at_scale (filename, -1, 16, TRUE, NULL); - gtk_image_set_from_pixbuf (GTK_IMAGE (p->image), pixbuf); + pixbuf = gdk_pixbuf_new_from_file_at_scale (filename, -1, 16, TRUE, NULL); + gtk_image_set_from_pixbuf (GTK_IMAGE (p->image), pixbuf); - g_object_unref (pixbuf); - } + g_object_unref (pixbuf); + } - gtk_widget_set_visible (p->image, filename != NULL); + gtk_widget_set_visible (p->image, filename != NULL); - g_object_unref (info); + g_object_unref (info); + } } } @@ -201,6 +222,12 @@ ido_basic_menu_item_class_init (IdoBasicMenuItemClass *klass) G_TYPE_OBJECT, prop_flags); + properties[PROP_PIXBUF] = g_param_spec_object ("pixbuf", + "Pixbuf", + "The menuitem's GdkPixbuf", + G_TYPE_OBJECT, + prop_flags); + properties[PROP_TEXT] = g_param_spec_string ("text", "Text", "The menuitem's text", @@ -289,6 +316,22 @@ ido_basic_menu_item_set_icon (IdoBasicMenuItem * self, GIcon * icon) } } +void ido_basic_menu_item_set_pixbuf(IdoBasicMenuItem *self, GdkPixbuf *pPixbuf) +{ + IdoBasicMenuItemPrivate *pPrivate = ido_basic_menu_item_get_instance_private(self); + + if (pPrivate->pPixbuf != pPixbuf) + { + if (pPrivate->pPixbuf) + { + g_object_unref(pPrivate->pPixbuf); + } + + pPrivate->pPixbuf = pPixbuf ? g_object_ref(pPixbuf) : NULL; + ido_basic_menu_item_update_image(self); + } +} + void ido_basic_menu_item_set_icon_from_file (IdoBasicMenuItem * self, const char * filename) { |