Replace all other lxpanel_image_* calls with new ones to make code simpler.
authorAndriy Grytsenko <andrej@rep.kiev.ua>
Sat, 15 Nov 2014 13:07:08 +0000 (15:07 +0200)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Sat, 15 Nov 2014 13:08:59 +0000 (15:08 +0200)
ChangeLog
plugins/Makefile.am
plugins/dclock.c
plugins/kbled/kbled.c
plugins/volumealsa/volumealsa.c
src/panel.h.in
src/private.h

index 1252bbd..b595852 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -26,7 +26,9 @@
 * Added "icon-size-changed" signal to LXPanel which is emitted when icons
     size in configuration dialog was changed.
 * Improved lxpanel_image_new_for_icon() API to follow panel icons size
-    changes, not only theme changes.
+    changes, not only theme changes. This way calls on lxpanel_image_*
+    APIs on theme or panel changes may be eliminated, i.e. code becomes
+    simpler.
 * Added new lxpanel_image_change_icon() API for simplification reasons so
     other lxpanel_image_* APIs can be replaced completely.
 
index be9b495..166edc5 100644 (file)
@@ -98,7 +98,6 @@ indicator_la_LIBADD = $(APPLET_LIBS)
 
 # kbled
 kbled_la_SOURCES = kbled/kbled.c
-kbled_la_CFLAGS = -DPACKAGE_DATA_DIR=\""$(datadir)/lxpanel"\"
 kbled_la_LIBADD = $(X11_LIBS)
 
 # monitors
@@ -142,7 +141,6 @@ volume_la_CFLAGS = -I$(srcdir)/volume
 
 # volumealsa
 volumealsa_la_SOURCES = volumealsa/volumealsa.c
-volumealsa_la_CFLAGS = -DPACKAGE_DATA_DIR=\""$(datadir)/lxpanel"\"
 volumealsa_la_LIBADD = -lasound
 
 # weather
index e054a90..b621e6d 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include "plugin.h"
+#include "misc.h"
 
 #include <libfm/fm-gtk.h>
 
@@ -316,7 +317,7 @@ static GtkWidget *dclock_constructor(LXPanel *panel, config_setting_t *settings)
     gtk_misc_set_alignment(GTK_MISC(dc->clock_label), 0.5, 0.5);
     gtk_misc_set_padding(GTK_MISC(dc->clock_label), 4, 0);
     gtk_container_add(GTK_CONTAINER(hbox), dc->clock_label);
-    dc->clock_icon = gtk_image_new();
+    dc->clock_icon = lxpanel_image_new_for_icon(panel, "clock", -1, NULL);
     gtk_container_add(GTK_CONTAINER(hbox), dc->clock_icon);
 
     /* Initialize the clock display. */
@@ -366,9 +367,6 @@ static gboolean dclock_apply_configuration(gpointer user_data)
     /* Set up the icon or the label as the displayable widget. */
     if (dc->icon_only)
     {
-        if(lxpanel_image_set_icon_theme(dc->panel, dc->clock_icon, "clock") != FALSE) {
-            lxpanel_image_set_from_file(dc->panel, dc->clock_icon, PACKAGE_DATA_DIR "/images/clock.png");
-        }
         gtk_widget_show(dc->clock_icon);
         gtk_widget_hide(dc->clock_label);
     }
index 4452828..3b71513 100644 (file)
@@ -21,6 +21,7 @@
 #endif
 
 #include "plugin.h"
+#include "misc.h"
 
 #include <gtk/gtk.h>
 #include <gdk/gdk.h>
@@ -45,24 +46,11 @@ static const char * off_icons_theme[] = {
     "scrllock-off"
 };
 
-static const char * on_icons[] = {
-    "capslock-on.png",
-    "numlock-on.png",
-    "scrllock-on.png"
-};
-
-static const char * off_icons[] = {
-    "capslock-off.png",
-    "numlock-off.png",
-    "scrllock-off.png"
-};
-
 static int xkb_event_base = 0;
 static int xkb_error_base = 0;
 
 /* Private context for keyboard LED plugin. */
 typedef struct {
-    LXPanel * panel;                           /* Back pointer to panel */
     config_setting_t *settings;
     GtkWidget *indicator_image[3];             /* Image for each indicator */
     unsigned int current_state;                        /* Current LED state, bit encoded */
@@ -73,27 +61,12 @@ static void kbled_update_image(KeyboardLEDPlugin * kl, int i, unsigned int state
 static void kbled_update_display(KeyboardLEDPlugin * kl, unsigned int state);
 static void kbled_destructor(gpointer user_data);
 
-static void kbled_theme_changed(GtkWidget * widget, KeyboardLEDPlugin * kl)
-{
-    /* Set orientation into the icon grid. */
-
-    /* Do a full redraw. */
-    int current_state = kl->current_state;
-    kl->current_state = ~ kl->current_state;
-    kbled_update_display(kl, current_state);
-}
-
 /* Update image to correspond to current state. */
 static void kbled_update_image(KeyboardLEDPlugin * kl, int i, unsigned int state)
 {
-    if(lxpanel_image_set_icon_theme(kl->panel, kl->indicator_image[i], (state ? on_icons_theme[i] : off_icons_theme[i])) != TRUE) {
-        char * file = g_build_filename(
-            PACKAGE_DATA_DIR "/images",
-            ((state) ? on_icons[i] : off_icons[i]),
-            NULL);
-        lxpanel_image_set_from_file(kl->panel, kl->indicator_image[i], file);
-        g_free(file);
-    }
+    lxpanel_image_change_icon(kl->indicator_image[i],
+                              (state ? on_icons_theme[i] : off_icons_theme[i]),
+                              NULL);
 }
 
 /* Redraw after Xkb event or initialization. */
@@ -137,7 +110,6 @@ static GtkWidget *kbled_constructor(LXPanel *panel, config_setting_t *settings)
     unsigned int current_state;
     Display *xdisplay = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
 
-    kl->panel = panel;
     kl->settings = settings;
     kl->visible[0] = FALSE;
     kl->visible[1] = TRUE;
@@ -158,7 +130,6 @@ static GtkWidget *kbled_constructor(LXPanel *panel, config_setting_t *settings)
                             0, 0, panel_get_height(panel));
     lxpanel_plugin_set_data(p, kl, kbled_destructor);
     gtk_widget_add_events(p, GDK_BUTTON_PRESS_MASK);
-    g_signal_connect(panel_get_icon_theme(panel), "changed", G_CALLBACK(kbled_theme_changed), kl);
 
     /* Then allocate three images for the three indications, but make them visible only when the configuration requests. */
     for (i = 0; i < 3; i++)
@@ -202,8 +173,6 @@ static void kbled_destructor(gpointer user_data)
 
     /* Remove GDK event filter. */
     gdk_window_remove_filter(NULL, (GdkFilterFunc) kbled_event_filter, kl);
-    g_signal_handlers_disconnect_by_func(panel_get_icon_theme(kl->panel),
-                                         kbled_theme_changed, kl);
     g_free(kl);
 }
 
index 9c94cd5..2056334 100644 (file)
 #include <poll.h>
 #include <libfm/fm-gtk.h>
 #include "plugin.h"
+#include "misc.h"
 
-#define ICONS_VOLUME_HIGH   PACKAGE_DATA_DIR "/images/volume-high.png"
-#define ICONS_VOLUME_MEDIUM PACKAGE_DATA_DIR "/images/volume-medium.png"
-#define ICONS_VOLUME_LOW    PACKAGE_DATA_DIR "/images/volume-low.png"
-#define ICONS_MUTE          PACKAGE_DATA_DIR "/images/mute.png"
+#define ICONS_VOLUME_HIGH   "volume-high"
+#define ICONS_VOLUME_MEDIUM "volume-medium"
+#define ICONS_VOLUME_LOW    "volume-low"
+#define ICONS_MUTE          "mute"
 
 typedef struct {
 
@@ -60,7 +61,6 @@ typedef struct {
     guint num_channels;                         /* Number of channels */
 
     /* Icons */
-    const char* icon;
     const char* icon_panel;
     const char* icon_fallback;
 
@@ -294,36 +294,30 @@ static void volumealsa_update_current_icon(VolumeALSAPlugin * vol)
     int level = asound_get_volume(vol);
 
     /* Change icon according to mute / volume */
-    const char* icon="audio-volume-muted";
     const char* icon_panel="audio-volume-muted-panel";
     const char* icon_fallback=ICONS_MUTE;
     if (mute)
     {
          icon_panel = "audio-volume-muted-panel";
-         icon="audio-volume-muted";
          icon_fallback=ICONS_MUTE;
     }
     else if (level >= 75)
     {
          icon_panel = "audio-volume-high-panel";
-         icon="audio-volume-high";
          icon_fallback=ICONS_VOLUME_HIGH;
     }
     else if (level >= 50)
     {
          icon_panel = "audio-volume-medium-panel";
-         icon="audio-volume-medium";
          icon_fallback=ICONS_VOLUME_MEDIUM;
     }
     else if (level > 0)
     {
          icon_panel = "audio-volume-low-panel";
-         icon="audio-volume-low";
          icon_fallback=ICONS_VOLUME_LOW;
     }
 
     vol->icon_panel = icon_panel;
-    vol->icon = icon;
     vol->icon_fallback= icon_fallback;
 }
 
@@ -337,13 +331,7 @@ static void volumealsa_update_display(VolumeALSAPlugin * vol)
     volumealsa_update_current_icon(vol);
 
     /* Change icon, fallback to default icon if theme doesn't exsit */
-    if ( ! lxpanel_image_set_icon_theme(vol->panel, vol->tray_icon, vol->icon_panel))
-    {
-        if ( ! lxpanel_image_set_icon_theme(vol->panel, vol->tray_icon, vol->icon))
-        {
-            lxpanel_image_set_from_file(vol->panel, vol->tray_icon, vol->icon_fallback);
-        }
-    }
+    lxpanel_image_change_icon(vol->tray_icon, vol->icon_panel, vol->icon_fallback);
 
     g_signal_handler_block(vol->mute_check, vol->mute_check_handler);
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(vol->mute_check), mute);
@@ -408,17 +396,6 @@ static void volumealsa_popup_map(GtkWidget * widget, VolumeALSAPlugin * vol)
     lxpanel_plugin_adjust_popup_position(widget, vol->plugin);
 }
 
-static void volumealsa_theme_change(GtkWidget * widget, VolumeALSAPlugin * vol)
-{
-    if ( ! lxpanel_image_set_icon_theme(vol->panel, vol->tray_icon, vol->icon_panel))
-    {
-        if ( ! lxpanel_image_set_icon_theme(vol->panel, vol->tray_icon, vol->icon))
-        {
-            lxpanel_image_set_from_file(vol->panel, vol->tray_icon, vol->icon_fallback);
-        }
-    }
-}
-
 /* Handler for "value_changed" signal on popup window vertical scale. */
 static void volumealsa_popup_scale_changed(GtkRange * range, VolumeALSAPlugin * vol)
 {
@@ -547,7 +524,8 @@ static GtkWidget *volumealsa_constructor(LXPanel *panel, config_setting_t *setti
     gtk_widget_set_tooltip_text(p, _("Volume control"));
 
     /* Allocate icon as a child of top level. */
-    vol->tray_icon = gtk_image_new();
+    vol->tray_icon = lxpanel_image_new_for_icon(panel, "audio-volume-muted-panel",
+                                                -1, ICONS_MUTE);
     gtk_container_add(GTK_CONTAINER(p), vol->tray_icon);
 
     /* Initialize window to appear when icon clicked. */
@@ -555,7 +533,6 @@ static GtkWidget *volumealsa_constructor(LXPanel *panel, config_setting_t *setti
 
     /* Connect signals. */
     g_signal_connect(G_OBJECT(p), "scroll-event", G_CALLBACK(volumealsa_popup_scale_scrolled), vol );
-    g_signal_connect(panel_get_icon_theme(panel), "changed", G_CALLBACK(volumealsa_theme_change), vol );
 
     /* Update the display, show the widget, and return. */
     volumealsa_update_display(vol);
@@ -577,10 +554,6 @@ static void volumealsa_destructor(gpointer user_data)
     if (vol->restart_idle)
         g_source_remove(vol->restart_idle);
 
-    if (vol->panel) /* SF bug #683: crash if constructor failed */
-        g_signal_handlers_disconnect_by_func(panel_get_icon_theme(vol->panel),
-                                             volumealsa_theme_change, vol);
-
     /* Deallocate all memory. */
     g_free(vol);
 }
index e3b91a2..685c1a3 100644 (file)
@@ -85,28 +85,6 @@ extern void lxpanel_draw_label_text(LXPanel * p, GtkWidget * label, const char *
                                     gboolean custom_color);
 
 /**
- * lxpanel_image_set_from_file
- * @p: a panel instance
- * @image: a #GtkImage widget
- * @file: image file path
- *
- * Applies icon from @file to @image in accordance with icon size setting
- * on panel @p.
- */
-extern void lxpanel_image_set_from_file(LXPanel * p, GtkWidget * image, const char * file);
-
-/**
- * lxpanel_image_set_icon_theme
- * @p: a panel instance
- * @image: a #GtkImage widget
- * @icon: icon name
- *
- * Applies icon size and theme from settings of @p to @image using @icon
- * name to select icon.
- */
-extern gboolean lxpanel_image_set_icon_theme(LXPanel * p, GtkWidget * image, const gchar * icon);
-
-/**
  * lxpanel_config_save
  * @p: a panel instance
  *
index b3a47e3..d78b004 100644 (file)
@@ -390,4 +390,26 @@ extern void plugin_adjust_popup_position(GtkWidget * popup, Plugin * plugin);
 extern void plugin_popup_set_position_helper(Plugin * p, GtkWidget * near, GtkWidget * popup, GtkRequisition * popup_req, gint * px, gint * py);
                                                        /* Helper for position-calculation callback for popup menus */
 
+/**
+ * lxpanel_image_set_from_file
+ * @p: a panel instance
+ * @image: a #GtkImage widget
+ * @file: image file path
+ *
+ * Applies icon from @file to @image in accordance with icon size setting
+ * on panel @p.
+ */
+extern void lxpanel_image_set_from_file(LXPanel * p, GtkWidget * image, const char * file);
+
+/**
+ * lxpanel_image_set_icon_theme
+ * @p: a panel instance
+ * @image: a #GtkImage widget
+ * @icon: icon name
+ *
+ * Applies icon size and theme from settings of @p to @image using @icon
+ * name to select icon.
+ */
+extern gboolean lxpanel_image_set_icon_theme(LXPanel * p, GtkWidget * image, const gchar * icon);
+
 #endif