jjk-jacky / statusnotifier

Library to use KDE's StatusNotifierItem via GObject
Other
25 stars 7 forks source link

provide a way to set "icon-theme-path" property #3

Open microcai opened 9 years ago

microcai commented 9 years ago

libappindicator allows that.

jjk-jacky commented 9 years ago

hmm, not sure what you mean by that, there is no such property in the StatusNotifier interface[1], only an icon name, or the actual pixmap data.

http://www.notmart.org/misc/statusnotifieritem/statusnotifieritem.html

microcai commented 9 years ago

http://bazaar.launchpad.net/~indicator-applet-developers/libappindicator/trunk.15.04/view/head:/src/app-indicator.c

find for "app_indicator_set_icon_theme_path"

libappindicator set it, and this is supported by Plasma-Next

jjk-jacky commented 9 years ago

I see... well if it's supported by KDE then it could be added I guess. However I don't really have time to work on this ATM... patches welcome though, of course. :)

microcai commented 9 years ago

there comes the patch

From d57a012b6deecf0472a5f5525bcf84142d8ab1f4 Mon Sep 17 00:00:00 2001
From: microcai <microcaicai@gmail.com>
Date: Fri, 6 Mar 2015 18:53:38 +0800
Subject: [PATCH] add NewIconPath property to statusnotifier

---
 Makefile.am          |  4 ++--
 src/statusnotifier.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 src/statusnotifier.h |  6 ++++++
 3 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 829010a..6cdad36 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -41,8 +41,8 @@ EXTRA_DIST = \
    src/mkenums

 src/enums.h: src/statusnotifier.h
-   $(AM_V_GEN)cd src && ./mkenums
+   $(AM_V_GEN) cd $(top_srcdir}/src && ./mkenums

 src/enums.c: src/statusnotifier.h
-   $(AM_V_GEN)cd src && ./mkenums
+   $(AM_V_GEN) cd $(top_srcdir)/src && ./mkenums

diff --git a/src/statusnotifier.c b/src/statusnotifier.c
index e258ed1..ea0b148 100644
--- a/src/statusnotifier.c
+++ b/src/statusnotifier.c
@@ -81,6 +81,7 @@ enum
     PROP_STATUS,
     PROP_MAIN_ICON_NAME,
     PROP_MAIN_ICON_PIXBUF,
+    PROP_ICON_THEME_PATH,
     PROP_OVERLAY_ICON_NAME,
     PROP_OVERLAY_ICON_PIXBUF,
     PROP_ATTENTION_ICON_NAME,
@@ -133,6 +134,8 @@ struct _StatusNotifierPrivate
             GdkPixbuf *pixbuf;
         };
     } icon[_NB_STATUS_NOTIFIER_ICONS];
+
+    gchar *icon_theme_path;
     gchar *attention_movie_name;
     gchar *tooltip_title;
     gchar *tooltip_body;
@@ -244,6 +247,16 @@ status_notifier_class_init (StatusNotifierClass *klass)
                 G_PARAM_READWRITE);

     /**
+     * StatusNotifier:icon-theme-path:
+     *
+     * the path that platform notify manager used to search for icon-name
+     */
+    status_notifier_props[PROP_ICON_THEME_PATH] =
+        g_param_spec_string ("icon-theme-path", "icon-path",
+                "Icon path the search for the icon",
+                NULL,
+                G_PARAM_READWRITE);
+    /**
      * StatusNotifier:main-icon-pixbuf:
      *
      * The item can carry an icon that can be used by the visualization to
@@ -638,6 +651,8 @@ status_notifier_set_property (GObject            *object,
         case PROP_MAIN_ICON_NAME:
             status_notifier_set_from_icon_name (sn, STATUS_NOTIFIER_ICON,
                     g_value_get_string (value));
+        case PROP_ICON_THEME_PATH:
+            status_notifier_set_icon_path (sn, g_value_get_string (value));
             break;
         case PROP_MAIN_ICON_PIXBUF:
             status_notifier_set_from_pixbuf (sn, STATUS_NOTIFIER_ICON,
@@ -711,6 +726,9 @@ status_notifier_get_property (GObject            *object,
             g_value_take_string (value, status_notifier_get_icon_name (sn,
                         STATUS_NOTIFIER_ICON));
             break;
+        case PROP_ICON_THEME_PATH:
+            g_value_take_string(value, status_notifier_get_icon_path (sn));
+            break;
         case PROP_MAIN_ICON_PIXBUF:
             g_value_take_object (value, status_notifier_get_pixbuf (sn,
                         STATUS_NOTIFIER_ICON));
@@ -823,6 +841,7 @@ status_notifier_finalize (GObject *object)
     g_free (priv->attention_movie_name);
     g_free (priv->tooltip_title);
     g_free (priv->tooltip_body);
+    g_free (priv->icon_theme_path);

     dbus_free (sn);

@@ -864,6 +883,16 @@ dbus_notify (StatusNotifier *sn, guint prop)
         case PROP_MAIN_ICON_PIXBUF:
             signal = "NewIcon";
             break;
+        case PROP_ICON_THEME_PATH:
+            signal = "NewIconThemePath";
+            g_dbus_connection_emit_signal (priv->dbus_conn,
+                                       NULL,
+                                       ITEM_OBJECT,
+                                       ITEM_INTERFACE,
+                                       signal,
+                                       g_variant_new("(s)", sn->priv->icon_theme_path),
+                                       NULL);
+            return;
         case PROP_ATTENTION_ICON_NAME:
         case PROP_ATTENTION_ICON_PIXBUF:
             signal = "NewAttentionIcon";
@@ -1031,6 +1060,22 @@ status_notifier_set_from_icon_name (StatusNotifier          *sn,
         dbus_notify (sn, prop_name_from_icon[icon]);
 }

+
+void                    status_notifier_set_icon_path (StatusNotifier*sn,
+                                            const gchar* newpath)
+{
+    g_free(sn->priv->icon_theme_path);
+    sn->priv->icon_theme_path = g_strdup(newpath);
+
+    dbus_notify(sn, PROP_ICON_THEME_PATH);
+}
+
+gchar *                 status_notifier_get_icon_path (StatusNotifier*sn)
+{
+   return g_strdup(sn->priv->icon_theme_path);
+}
+
+
 /**
  * status_notifier_has_pixbuf:
  * @sn: A #StatusNotifier
diff --git a/src/statusnotifier.h b/src/statusnotifier.h
index 3834064..4bb70ca 100644
--- a/src/statusnotifier.h
+++ b/src/statusnotifier.h
@@ -255,6 +255,12 @@ GdkPixbuf *             status_notifier_get_pixbuf (
 gchar *                 status_notifier_get_icon_name (
                                             StatusNotifier          *sn,
                                             StatusNotifierIcon       icon);
+
+void                    status_notifier_set_icon_path (StatusNotifier*sn,
+                                            const gchar*);
+
+gchar *                 status_notifier_get_icon_path (StatusNotifier*sn);
+
 void                    status_notifier_set_attention_movie_name (
                                             StatusNotifier          *sn,
                                             const gchar             *movie_name);
-- 
2.3.1
jjk-jacky commented 9 years ago

On 03/06/15 11:54, microcai wrote:

there comes the patch

Awesome, thanks!

From d57a012b6deecf0472a5f5525bcf84142d8ab1f4 Mon Sep 17 00:00:00 2001
From: microcai <microcaicai@gmail.com>
Date: Fri, 6 Mar 2015 18:53:38 +0800
Subject: [PATCH] add NewIconPath property to statusnotifier

I'd rather the actual property name be used, e.g. "Add property icon-theme-path"


Makefile.am | 4 ++-- src/statusnotifier.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/statusnotifier.h | 6 ++++++ 3 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/Makefile.am b/Makefile.am index 829010a..6cdad36 100644 --- a/Makefile.am +++ b/Makefile.am @@ -41,8 +41,8 @@ EXTRA_DIST = \ src/mkenums

src/enums.h: src/statusnotifier.h

  • $(AM_V_GEN)cd src && ./mkenums
  • $(AM_V_GEN) cd $(top_srcdir}/src && ./mkenums

    src/enums.c: src/statusnotifier.h

  • $(AM_V_GEN)cd src && ./mkenums
  • $(AM_V_GEN) cd $(top_srcdir)/src && ./mkenums

Those might be valid, but shouldn't be in this patch.

You did however forgot to update the interface.h to add definitions of the new signal (NewIconThemePath), as well as property IconThemePath -- which should also be accounted for in get_prop()

Looks good otherwise, save for some little nitpicking:

(snip)

@@ -1031,6 +1060,22 @@ status_notifier_set_from_icon_name (StatusNotifier *sn, dbus_notify (sn, prop_name_from_icon[icon]); }

+ +void status_notifier_set_icon_path (StatusNotifier*sn,

  • const gchar* newpath) +{
  • g_free(sn->priv->icon_theme_path);
  • sn->priv->icon_theme_path = g_strdup(newpath); +
  • dbus_notify(sn, PROP_ICON_THEME_PATH); +} + +gchar * status_notifier_get_icon_path (StatusNotifier*sn) +{
  • return g_strdup(sn->priv->icon_theme_path); +}

I'd appreciate if you could follow the same coding style here as well (e.g. space before parenthesis, etc), and include the g_return_val_if_fail() check and use priv as well, for consistency.

Thanks, -j

vovochka404 commented 9 years ago

No one would mind if i'll complete this job? :)

jjk-jacky commented 9 years ago

Of course not! If you're interested, feel free to work on this. :)