aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/idoappointmentmenuitem.c4
-rw-r--r--src/idobasicmenuitem.c71
-rw-r--r--src/idobasicmenuitem.h17
3 files changed, 71 insertions, 21 deletions
diff --git a/src/idoappointmentmenuitem.c b/src/idoappointmentmenuitem.c
index 5659644..7ab593e 100644
--- a/src/idoappointmentmenuitem.c
+++ b/src/idoappointmentmenuitem.c
@@ -1,9 +1,11 @@
/*
* Copyright 2013 Canonical Ltd.
+ * Copyright 2021 AyatanaIndicators
*
* Authors:
* Charles Kerr <charles.kerr@canonical.com>
* Ted Gould <ted@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
@@ -104,7 +106,7 @@ ido_appointment_menu_item_new_from_model (GMenuItem * menu_item,
if (g_menu_item_get_attribute (menu_item, "x-ayatana-color", "s", &str))
{
- names[n] = "icon";
+ names[n] = "pixbuf";
g_value_init (&values[n], G_TYPE_OBJECT);
g_value_take_object (&values[n], create_color_icon_pixbuf (str));
g_free(str);
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)
{
diff --git a/src/idobasicmenuitem.h b/src/idobasicmenuitem.h
index 38ae830..cd15d57 100644
--- a/src/idobasicmenuitem.h
+++ b/src/idobasicmenuitem.h
@@ -1,19 +1,21 @@
/**
* 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
+ * 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
+ * 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
+ * You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -53,6 +55,9 @@ GtkWidget * ido_basic_menu_item_new (void);
void ido_basic_menu_item_set_icon (IdoBasicMenuItem * self,
GIcon * icon);
+void ido_basic_menu_item_set_pixbuf (IdoBasicMenuItem * self,
+ GdkPixbuf * pPixbuf);
+
void ido_basic_menu_item_set_icon_from_file (IdoBasicMenuItem * self,
const char * filename);