[Xfce4-commits] <xfce4-indicator-plugin:master> Initial support for IndicatorNg service files

Andrzej noreply at xfce.org
Sun Sep 1 01:42:01 CEST 2013


Updating branch refs/heads/master
         to 48edafdc08b869bed74695ef257c0bd23c3cb3e3 (commit)
       from 05fdb4dd6c03d6c811448677973562cea51b5a83 (commit)

commit 48edafdc08b869bed74695ef257c0bd23c3cb3e3
Author: Andrzej <ndrwrdck at gmail.com>
Date:   Sun Sep 1 00:40:31 2013 +0100

    Initial support for IndicatorNg service files

 panel-plugin/indicator-button-box.c |    2 +-
 panel-plugin/indicator.c            |  121 +++++++++++++++++++++++++++++++++++
 2 files changed, 122 insertions(+), 1 deletion(-)

diff --git a/panel-plugin/indicator-button-box.c b/panel-plugin/indicator-button-box.c
index 75285c1..d20840e 100644
--- a/panel-plugin/indicator-button-box.c
+++ b/panel-plugin/indicator-button-box.c
@@ -510,7 +510,7 @@ indicator_button_box_size_allocate (GtkWidget     *widget,
   width  = allocation->width;
   height = allocation->height;
 
-  if (indicator_button_box_is_small (box)) // check & cache
+  if (indicator_button_box_is_small (box) && box->icon != NULL) // check & cache
     {
       child_allocation.x = x + (width - ICON_SIZE + 1) / 2;
       child_allocation.y = y + (height - ICON_SIZE + 1) / 2;
diff --git a/panel-plugin/indicator.c b/panel-plugin/indicator.c
index 0e7b996..74d542e 100644
--- a/panel-plugin/indicator.c
+++ b/panel-plugin/indicator.c
@@ -36,6 +36,7 @@
 #include <libxfce4util/libxfce4util.h>
 #include <libxfce4panel/xfce-panel-plugin.h>
 #include <libindicator/indicator-object.h>
+#include <libindicator/indicator-ng.h>
 
 #include "indicator.h"
 #include "indicator-box.h"
@@ -64,6 +65,7 @@ static void             indicator_mode_changed                     (XfcePanelPlu
 static void             indicator_orientation_changed              (XfcePanelPlugin       *plugin,
                                                                     GtkOrientation         orientation);
 #endif
+static gint             indicator_load_indicators_ng               (IndicatorPlugin       *indicator);
 
 
 struct _IndicatorPluginClass
@@ -332,6 +334,8 @@ indicator_construct (XfcePanelPlugin *plugin)
     g_dir_close (dir);
   }
 
+  indicators_loaded += indicator_load_indicators_ng (indicator);
+
   if (indicators_loaded == 0) {
     /* A label to allow for click through */
     indicator->item = xfce_indicator_button_new (NULL,
@@ -360,6 +364,8 @@ entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_d
                                                        plugin,
                                                        indicator->config);
 
+  g_debug("Entry added for io=%s", io_name);
+
   /* remove placeholder item when there are real entries to be added */
   if (indicator->item != NULL)
     {
@@ -436,6 +442,121 @@ load_module (const gchar * name, IndicatorPlugin * indicator)
 }
 
 
+static void
+load_indicator (IndicatorPlugin *indicator,
+		IndicatorObject *io,
+		const gchar     *name)
+{
+  GList                *entries, *entry;
+  IndicatorObjectEntry *entrydata;
+
+  g_debug ("Load indicator_ng: %s", name);
+
+  indicator_config_add_known_indicator (indicator->config, name);
+
+  g_object_set_data (G_OBJECT (io), "io-name", g_strdup (name));
+
+  /* Connect to its signals */
+  g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED,
+                   G_CALLBACK(entry_added), indicator);
+  g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED,
+                   G_CALLBACK(entry_removed), indicator->buttonbox);
+
+  /* Work on the entries */
+  entries = indicator_object_get_entries(io);
+  entry = NULL;
+
+  for (entry = entries; entry != NULL; entry = g_list_next(entry))
+    {
+      entrydata = (IndicatorObjectEntry *)entry->data;
+      entry_added(io, entrydata, indicator);
+    }
+
+  g_list_free(entries);
+}
+
+
+
+#define INDICATORS_NG_DIR "/usr/share/unity/indicators"
+
+static gint
+indicator_load_indicators_ng (IndicatorPlugin *indicator)
+{
+  GDir        *indicators_ng_dir;
+  const gchar *io_name;
+  GError      *err = NULL;
+  gint         indicators = 0;
+  gchar       *file_name = NULL;
+  IndicatorNg *indicator_ng = NULL;
+
+  g_return_val_if_fail (XFCE_IS_INDICATOR_PLUGIN (indicator), 0);
+
+  indicators_ng_dir = g_dir_open (INDICATORS_NG_DIR, 0, &err);
+
+  if (!indicators_ng_dir)
+    {
+      g_warning ("%s", err->message);
+      g_error_free (err);
+
+      return 0;
+    }
+
+  if (indicator_config_get_mode_whitelist (indicator->config))
+    {
+      while ((io_name = g_dir_read_name (indicators_ng_dir)) != NULL)
+	{
+          if (indicator_config_is_whitelisted (indicator->config, io_name))
+            {
+              g_debug ("Loading whitelisted IndicatorNg: %s", io_name);
+	      file_name = g_build_filename (INDICATORS_NG_DIR, io_name, NULL);
+	      indicator_ng = indicator_ng_new_for_profile (file_name, "desktop", &err);
+	      g_free (file_name);
+	      if (indicator_ng)
+		{
+		  load_indicator (indicator, INDICATOR_OBJECT (indicator_ng), io_name);
+		  indicators++;
+		}
+	      else
+		{
+		  g_warning ("Cannot load indicator '%s': %s", io_name, err->message);
+		  g_clear_error (&err);
+		}
+	    }
+	}
+    }
+  else
+    {
+      while ((io_name = g_dir_read_name (indicators_ng_dir)) != NULL)
+	{
+          if (indicator_config_is_blacklisted (indicator->config, io_name))
+            {
+              g_debug ("Excluding blacklisted IndicatorNg: %s", io_name);
+	    }
+	  else
+	    {
+	      file_name = g_build_filename (INDICATORS_NG_DIR, io_name, NULL);
+	      indicator_ng = indicator_ng_new_for_profile (file_name, "desktop", &err);
+	      g_free (file_name);
+	      if (indicator_ng)
+		{
+		  load_indicator (indicator, INDICATOR_OBJECT (indicator_ng), io_name);
+		  indicators++;
+		}
+	      else
+		{
+		  g_warning ("Cannot load indicator '%s': %s", io_name, err->message);
+		  g_clear_error (&err);
+		}
+	    }
+	}
+    }
+
+  g_dir_close (indicators_ng_dir);
+
+  return indicators;
+}
+
+
 XfceIndicatorBox *
 indicator_get_buttonbox (IndicatorPlugin *plugin)
 {


More information about the Xfce4-commits mailing list