Add new lxpanel_image_change_icon() API for simplification reasons.
authorAndriy Grytsenko <andrej@rep.kiev.ua>
Sat, 15 Nov 2014 12:58:55 +0000 (14:58 +0200)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Sat, 15 Nov 2014 12:58:55 +0000 (14:58 +0200)
ChangeLog
src/misc.c
src/misc.h

index 685b2eb..1252bbd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -27,6 +27,8 @@
     size in configuration dialog was changed.
 * Improved lxpanel_image_new_for_icon() API to follow panel icons size
     changes, not only theme changes.
+* Added new lxpanel_image_change_icon() API for simplification reasons so
+    other lxpanel_image_* APIs can be replaced completely.
 
 0.7.2
 -------------------------------------------------------------------------
index 285fc5e..190b2c0 100644 (file)
@@ -1090,6 +1090,31 @@ GtkWidget *lxpanel_image_new_for_icon(LXPanel *panel, const gchar *name,
     return _gtk_image_new_for_icon(panel, fm_icon_from_name(name), height, fallback);
 }
 
+gboolean lxpanel_image_change_icon(GtkWidget *img, const gchar *name, const char *fallback)
+{
+    ImgData * data = (ImgData *) g_object_get_qdata(G_OBJECT(img), img_data_id);
+
+    g_return_val_if_fail(data != NULL && name != NULL, FALSE);
+    g_object_unref(data->icon);
+    g_free(data->fallback);
+    data->icon = fm_icon_from_name(name);
+    data->fallback = g_strdup(fallback);
+    if (!G_IS_THEMED_ICON(data->icon))
+    {
+        if (data->theme_changed_handler != 0)
+            g_signal_handler_disconnect(gtk_icon_theme_get_default(), data->theme_changed_handler);
+        data->theme_changed_handler = 0;
+    }
+    else if (data->theme_changed_handler == 0)
+    {
+        /* This image is loaded from icon theme.  Update the image if the icon theme is changed. */
+        data->theme_changed_handler = g_signal_connect_swapped(gtk_icon_theme_get_default(),
+                                                "changed", G_CALLBACK(on_theme_changed), img);
+    }
+    _gtk_image_set_from_file_scaled(img, data);
+    return TRUE;
+}
+
 void
 get_button_spacing(GtkRequisition *req, GtkContainer *parent, gchar *name)
 {
index 9e3f0ab..34c9b21 100644 (file)
@@ -178,6 +178,18 @@ void lxpanel_button_update_icon(GtkWidget* btn, FmIcon *icon, gint size);
 GtkWidget *lxpanel_image_new_for_icon(LXPanel *panel, const gchar *name,
                                       gint height, const gchar *fallback);
 
+/**
+ * lxpanel_image_change_icon
+ * @img: an image
+ * @name: icon name or image path
+ * @fallback: (allow-none): fallback image name or path
+ *
+ * Changes an image @img created by lxpanel_image_new_for_icon() to use
+ * new icon @name and @fallback.
+ */
+gboolean lxpanel_image_change_icon(GtkWidget *img, const gchar *name,
+                                   const char *fallback);
+
 G_END_DECLS
 
 #endif