Replace few gtk_image_new* with lxpanel_image_* APIs to follow theme and icons size.
authorAndriy Grytsenko <andrej@rep.kiev.ua>
Sat, 15 Nov 2014 14:33:07 +0000 (16:33 +0200)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Sat, 15 Nov 2014 14:44:33 +0000 (16:44 +0200)
plugins/Makefile.am
plugins/cpufreq/cpufreq.c
plugins/kbled/kbled.c
plugins/netstat/netstat.c
plugins/netstat/netstat.h
plugins/netstat/nsconfig.h
plugins/netstat/statusicon.c
plugins/netstat/statusicon.h

index 166edc5..5c0f6de 100644 (file)
@@ -83,7 +83,6 @@ cpu_la_SOURCES = cpu/cpu.c
 
 # cpufreq
 cpufreq_la_SOURCES = cpufreq/cpufreq.c
-cpufreq_la_CFLAGS = -DPACKAGE_DATA_DIR=\""$(datadir)/lxpanel"\"
 
 # deskno
 deskno_la_SOURCES = deskno/deskno.c
@@ -111,9 +110,7 @@ netstat_la_SOURCES = \
        netstat/wireless.c \
        netstat/lxnm_client.c \
        netstat/passwd_gui.c
-netstat_la_CFLAGS = \
-       -I$(srcdir)/netstat \
-       -DPACKAGE_DATA_DIR=\""$(datadir)/lxpanel"\"
+netstat_la_CFLAGS = -I$(srcdir)/netstat
 netstat_la_LIBADD = -liw
 
 # netstatus
@@ -127,7 +124,6 @@ netstatus_la_SOURCES = \
        netstatus/netstatus-util.c
 netstatus_la_CFLAGS = \
        -I$(srcdir)/netstatus \
-       -DPACKAGE_DATA_DIR=\""$(datadir)/lxpanel"\" \
        -DPACKAGE_UI_DIR=\""$(datadir)/lxpanel/ui"\"
 
 # thermal
index 8a3b94a..b7db457 100644 (file)
 #include <string.h>
 
 #include "plugin.h"
+#include "misc.h"
 
 #include "dbg.h"
 
-#define PROC_ICON            PACKAGE_DATA_DIR "/images/cpufreq-icon.png"
+#define PROC_ICON           "cpufreq-icon"
 #define SYSFS_CPU_DIRECTORY "/sys/devices/system/cpu"
 #define SCALING_GOV         "scaling_governor"
 #define SCALING_AGOV        "scaling_available_governors"
@@ -353,7 +354,7 @@ static GtkWidget *cpufreq_constructor(LXPanel *panel, config_setting_t *settings
     gtk_widget_set_has_window(cf->main, FALSE);
     gtk_container_set_border_width(GTK_CONTAINER(cf->main), 2);
 
-    cf->namew = gtk_image_new_from_file(PROC_ICON);
+    cf->namew = lxpanel_image_new_for_icon(panel, PROC_ICON, -1, NULL);
     gtk_container_add(GTK_CONTAINER(cf->main), cf->namew);
 
     cf->has_cpufreq = 0;
index 3b71513..9caab60 100644 (file)
@@ -134,7 +134,7 @@ static GtkWidget *kbled_constructor(LXPanel *panel, config_setting_t *settings)
     /* Then allocate three images for the three indications, but make them visible only when the configuration requests. */
     for (i = 0; i < 3; i++)
     {
-        kl->indicator_image[i] = gtk_image_new();
+        kl->indicator_image[i] = lxpanel_image_new_for_icon(panel, off_icons_theme[i], -1, NULL);
         gtk_container_add(GTK_CONTAINER(p), kl->indicator_image[i]);
         gtk_widget_set_visible(kl->indicator_image[i], kl->visible[i]);
     }
index f1fb809..932fc6a 100644 (file)
@@ -35,6 +35,7 @@
 #include "devproc.h"
 #include "wireless.h"
 #include "plugin.h"
+#include "misc.h"
 #include "dbg.h"
 
 /* 1 second */
@@ -169,7 +170,7 @@ wireless_menu(netdev_info *ni)
 
             /* Encryption */
             if (aps->apinfo->haskey) {
-                lockicon = gtk_image_new_from_file(ICONS_WL_LOCK);
+                lockicon = lxpanel_image_new_for_icon(NULL, ICONS_WL_LOCK, 18, NULL);
                 gtk_box_pack_start(GTK_BOX(item_box), lockicon, FALSE, FALSE, 0);
             }
 
@@ -323,6 +324,7 @@ static void refresh_systray(netstat *ns, NETDEVLIST_PTR netdev_list)
 {
     NETDEVLIST_PTR ptr;
     char *tooltip;
+    const char *icon, *theme_icon;
 
     if (netdev_list==NULL) {
         return;
@@ -375,6 +377,11 @@ static void refresh_systray(netstat *ns, NETDEVLIST_PTR netdev_list)
                                                                 ptr->info.trans_bytes, ptr->info.recv_bytes, _("bytes"),
                                                                 ptr->info.trans_packets, ptr->info.recv_packets, _("packets"));
 
+            icon = select_icon(ptr->info.plug, ptr->info.connected, ptr->info.status);
+            if (ns->use_theme)
+                theme_icon = select_icon_theme(ptr->info.plug, ptr->info.connected, ptr->info.status);
+            else
+                theme_icon = icon;
             /* status icon doesn't exist  */
             if (ptr->info.status_icon==NULL) {
                 netdev_info *ni;
@@ -382,12 +389,12 @@ static void refresh_systray(netstat *ns, NETDEVLIST_PTR netdev_list)
                 ni->ns = ns;
                 ni->netdev_list = ptr;
 
-                ptr->info.status_icon = create_statusicon(ns->mainw, select_icon(ptr->info.plug, ptr->info.connected, ptr->info.status), tooltip, select_icon_theme(ptr->info.plug, ptr->info.connected, ptr->info.status));
+                ptr->info.status_icon = create_statusicon(ns->panel, ns->mainw, icon, tooltip, theme_icon);
                 g_signal_connect(ptr->info.status_icon->main, "button-press-event", G_CALLBACK(menupopup), ni);
                 g_object_weak_ref(G_OBJECT(ptr->info.status_icon->main), g_free_weaknotify, ni);
             } else {
                 set_statusicon_tooltips(ptr->info.status_icon, tooltip);
-                set_statusicon_image_from_file(ptr->info.status_icon, select_icon(ptr->info.plug, ptr->info.connected, ptr->info.status));
+                update_statusicon(ptr->info.status_icon, icon, theme_icon);
                 set_statusicon_visible(ptr->info.status_icon, TRUE);
             }
             g_free(tooltip);
@@ -433,14 +440,18 @@ static GtkWidget *netstat_constructor(LXPanel *panel, config_setting_t *settings
 {
     netstat *ns;
     const char *tmp;
+    int tmp_int;
     GtkWidget *p;
 
     ENTER;
     ns = g_new0(netstat, 1);
     g_return_val_if_fail(ns != NULL, NULL);
+    ns->panel = panel;
     /* apply config */
     if (config_setting_lookup_string(settings, "FixCommand", &tmp))
         ns->fixcmd = g_strdup(tmp);
+    if (config_setting_lookup_int(settings, "UseTheme", &tmp_int))
+        ns->use_theme = !!tmp_int;
 
     /* initializing */
     ns->fnetd = malloc(sizeof(FNETD));
index 78f07c8..cc001c1 100644 (file)
@@ -5,6 +5,7 @@
 #include <netinet/in.h>
 #include <gtk/gtk.h>
 #include "wireless.h"
+#include "plugin.h"
 
 #define NETDEV_STAT_NORMAL     0
 #define NETDEV_STAT_PROBLEM    1
@@ -70,9 +71,11 @@ typedef struct {
 
 typedef struct {
     GtkWidget *mainw;
+    LXPanel *panel;
     FNETD *fnetd;
     char *fixcmd;
     gint ttag;
+    gboolean use_theme;
 } netstat;
 
 typedef struct {
index 4c9b13f..53af548 100644 (file)
@@ -1,18 +1,18 @@
 #ifndef HAVE_NSCONFIG_H
 #define HAVE_NSCONFIG_H
 
-#define RESOURCE_DIR PACKAGE_DATA_DIR "/images"
-#define ICONS_CONNECTED                RESOURCE_DIR "/ns-connected.png"
-#define ICONS_DISCONNECT       RESOURCE_DIR "/ns-disconnect.png"
-#define ICONS_PROBLEM          RESOURCE_DIR "/ns-problem.png"
-#define ICONS_RENEW            RESOURCE_DIR "/ns-renew.png"
-#define ICONS_BOTHRS           RESOURCE_DIR "/ns-bothrs.png"
-#define ICONS_SENDDATA         RESOURCE_DIR "/ns-senddata.png"
-#define ICONS_RECVDATA         RESOURCE_DIR "/ns-recvdata.png"
-#define ICONS_WL_CONNECTED     RESOURCE_DIR "/ns-wlconnected.png"
-#define ICONS_WL_DISCONNECT    RESOURCE_DIR "/ns-wldisconnect.png"
-#define ICONS_WL_RENEW         RESOURCE_DIR "/ns-wlrenew.png"
-#define ICONS_WL_LOCK          RESOURCE_DIR "/ns-lock.png"
+/* Icon names in fallback theme path */
+#define ICONS_CONNECTED                "ns-connected"
+#define ICONS_DISCONNECT       "ns-disconnect"
+#define ICONS_PROBLEM          "ns-problem"
+#define ICONS_RENEW            "ns-renew"
+#define ICONS_BOTHRS           "ns-bothrs"
+#define ICONS_SENDDATA         "ns-senddata"
+#define ICONS_RECVDATA         "ns-recvdata"
+#define ICONS_WL_CONNECTED     "ns-wlconnected"
+#define ICONS_WL_DISCONNECT    "ns-wldisconnect"
+#define ICONS_WL_RENEW         "ns-wlrenew"
+#define ICONS_WL_LOCK          "ns-lock"
 
 /*Themed icon names*/
 #define ICONS_CONNECTED_THEME          "network-idle"
index d3e0f14..d2047ef 100644 (file)
 #include <glib/gi18n.h>
 #include "netstat.h"
 #include "statusicon.h"
+#include "misc.h"
 
-struct statusicon *create_statusicon(GtkWidget *box, const char *filename,
-        const char *tooltips, const char* icon_name)
+struct statusicon *create_statusicon(LXPanel *panel, GtkWidget *box,
+        const char *filename, const char *tooltips, const char* icon_name)
 {
     struct statusicon *newicon;
     newicon = malloc(sizeof(struct statusicon));
@@ -34,24 +35,12 @@ struct statusicon *create_statusicon(GtkWidget *box, const char *filename,
 
     gtk_widget_set_has_window(newicon->main, FALSE);
     gtk_widget_add_events(newicon->main, GDK_BUTTON_PRESS_MASK);
-    gtk_widget_set_size_request(newicon->main, 24, 24);
+    //gtk_widget_set_size_request(newicon->main, 24, 24);
     gtk_box_pack_start(GTK_BOX(box), newicon->main, TRUE, TRUE, 0);
 
     /* icon */
+    newicon->icon = lxpanel_image_new_for_icon(panel, icon_name, -1, filename);
 
-    /*icon theme*/
-    GtkIconTheme* icon_theme = gtk_icon_theme_get_default();
-
-    /*if we've got a theme*/
-    if(gtk_icon_theme_has_icon(icon_theme, icon_name)) {
-        GdkPixbuf* temp_pixbuf = gtk_icon_theme_load_icon(icon_theme, icon_name, 24, 0, NULL);
-        newicon->icon = gtk_image_new_from_pixbuf(temp_pixbuf);
-    }
-
-    /* oh well...*/
-    else {
-        newicon->icon = gtk_image_new_from_file(filename);
-    }
     gtk_container_add(GTK_CONTAINER(newicon->main), newicon->icon);
     gtk_widget_show_all(newicon->main);
 
@@ -72,9 +61,10 @@ void statusicon_destroy(struct statusicon *icon)
 }
 
 
-void set_statusicon_image_from_file(struct statusicon *widget, const char *filename)
+//void set_statusicon_image_from_file(struct statusicon *widget, const char *filename)
+void update_statusicon(struct statusicon *widget, const char *filename, const char *icon_name)
 {
-    gtk_image_set_from_file(GTK_IMAGE(widget->icon), filename);
+    lxpanel_image_change_icon(widget->icon, icon_name, filename);
 }
 
 void set_statusicon_tooltips(struct statusicon *widget, const char *tooltips)
index 7ead050..a508096 100644 (file)
@@ -9,10 +9,12 @@ struct statusicon {
         GtkWidget *icon;
 };
 
-struct statusicon *create_statusicon(GtkWidget *box, const char *filename,
-               const char *tooltips, const char* icon_name);
+struct statusicon *create_statusicon(LXPanel *panel, GtkWidget *box,
+               const char *filename, const char *tooltips, const char* icon_name);
 void statusicon_destroy(struct statusicon *icon);
-void set_statusicon_image_from_file(struct statusicon *widget, const char *filename);
+void update_statusicon(struct statusicon *widget, const char *filename,
+               const char *icon_name);
+//void set_statusicon_image_from_file(struct statusicon *widget, const char *filename);
 void set_statusicon_tooltips(struct statusicon *widget, const char *tooltips);
 void set_statusicon_visible(struct statusicon *widget, gboolean b);