← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~robertcarr/libindicate/icon_search_path into lp:libindicate

 

Robert Carr has proposed merging lp:~robertcarr/libindicate/icon_search_path into lp:libindicate.

Requested reviews:
  Ted Gould (ted)

For more details, see:
https://code.launchpad.net/~robertcarr/libindicate/icon_search_path/+merge/85783

Support an icon path property on indicate server, this mirrors the icon path property on dbusmenu servers.

This is useful in the webapps project where we need to use .desktop files for indicate servers, where the icons are "unthemed" i.e. downloaded from a webapp.
-- 
https://code.launchpad.net/~robertcarr/libindicate/icon_search_path/+merge/85783
Your team ayatana-commits is subscribed to branch lp:libindicate.
=== modified file 'libindicate/indicate-interface.xml'
--- libindicate/indicate-interface.xml	2011-01-13 22:49:19 +0000
+++ libindicate/indicate-interface.xml	2011-12-15 02:27:23 +0000
@@ -35,6 +35,7 @@
 		<property name="type"    type="s" access="read" />
 		<property name="count"   type="u" access="read" />
 		<property name="menu"    type="o" access="read" />
+		<property name="iconpath" type="as" access="read" />
 
 <!-- Functions -->
 		<method name="GetIndicatorCount">

=== modified file 'libindicate/listener.c'
--- libindicate/listener.c	2011-09-20 03:17:39 +0000
+++ libindicate/listener.c	2011-12-15 02:27:23 +0000
@@ -1257,6 +1257,7 @@
 	IndicateListenerServer * server;
 	indicate_listener_get_server_property_cb callback;
 	indicate_listener_get_server_uint_property_cb callback_uint;
+	indicate_listener_get_server_strv_property_cb callback_strv;
 	gpointer data;
 };
 
@@ -1267,8 +1268,10 @@
 get_server_property_work (get_server_prop_data_t * prop_t, GVariant * prop)
 {
 	if (prop == NULL) {
-		if (prop_t->callback == NULL) {
+		if (prop_t->callback == NULL && prop_t->callback_strv == NULL) {
 			prop_t->callback_uint(prop_t->listener, prop_t->server, 0, prop_t->data);
+		} else if (prop_t->callback == NULL) {
+			prop_t->callback_strv(prop_t->listener, prop_t->server, NULL, prop_t->data);
 		} else {
 			prop_t->callback(prop_t->listener, prop_t->server, NULL, prop_t->data);
 		}
@@ -1281,7 +1284,9 @@
 		prop_t->callback(prop_t->listener, prop_t->server, g_variant_get_string(prop, NULL), prop_t->data);
 	} else if (g_variant_is_of_type(prop, G_VARIANT_TYPE_UINT32) && prop_t->callback_uint != NULL) {
 		prop_t->callback_uint(prop_t->listener, prop_t->server, g_variant_get_uint32(prop), prop_t->data);
-	} else {
+	} else if (g_variant_is_of_type(prop, G_VARIANT_TYPE_STRING_ARRAY) && prop_t->callback_strv != NULL) {
+	  prop_t->callback_strv(prop_t->listener, prop_t->server, (GStrv)g_variant_dup_strv(prop, NULL), prop_t->data);
+	}else {
 		g_warning("Really?  This can't happen.  WTF!  %s", g_variant_get_type_string(prop));
 	}
 
@@ -1329,7 +1334,7 @@
    and this function builds and populates that, then uses
    a custom callback to call their callback */
 static void
-get_server_property (IndicateListener * listener, IndicateListenerServer * server, indicate_listener_get_server_property_cb callback, indicate_listener_get_server_uint_property_cb callback_uint, const gchar * property_name, gpointer data)
+get_server_property (IndicateListener * listener, IndicateListenerServer * server, indicate_listener_get_server_property_cb callback, indicate_listener_get_server_uint_property_cb callback_uint, indicate_listener_get_server_strv_property_cb callback_strv, const gchar * property_name, gpointer data)
 {
 	IndicateListenerPrivate * priv = INDICATE_LISTENER_GET_PRIVATE(listener);
 	get_server_prop_data_t * prop_t = g_new0(get_server_prop_data_t, 1);
@@ -1338,6 +1343,7 @@
 	prop_t->server = server;
 	prop_t->callback = callback;
 	prop_t->callback_uint = callback_uint;
+	prop_t->callback_strv = callback_strv;
 	prop_t->data = data;
 
 	g_object_ref(G_OBJECT(listener));
@@ -1363,25 +1369,31 @@
 void
 indicate_listener_server_get_type (IndicateListener * listener, IndicateListenerServer * server, indicate_listener_get_server_property_cb callback, gpointer data)
 {
-	return get_server_property(listener, server, callback, NULL, "type", data);
+	return get_server_property(listener, server, callback, NULL, NULL, "type", data);
 }
 
 void
 indicate_listener_server_get_desktop (IndicateListener * listener, IndicateListenerServer * server, indicate_listener_get_server_property_cb callback, gpointer data)
 {
-	return get_server_property(listener, server, callback, NULL, "desktop", data);
+	return get_server_property(listener, server, callback, NULL, NULL, "desktop", data);
+}
+
+void
+indicate_listener_server_get_icon_path (IndicateListener * listener, IndicateListenerServer * server, indicate_listener_get_server_strv_property_cb callback, gpointer data)
+{
+  return get_server_property(listener, server, NULL, NULL, callback, "iconpath", data);
 }
 
 void
 indicate_listener_server_get_count (IndicateListener * listener, IndicateListenerServer * server, indicate_listener_get_server_uint_property_cb callback, gpointer data)
 {
-	return get_server_property(listener, server, NULL, callback, "count", data);
+	return get_server_property(listener, server, NULL, callback, NULL, "count", data);
 }
 
 void
 indicate_listener_server_get_menu (IndicateListener * listener, IndicateListenerServer * server, indicate_listener_get_server_property_cb callback, gpointer data)
 {
-	return get_server_property(listener, server, callback, NULL, "menu", data);
+	return get_server_property(listener, server, callback, NULL, NULL, "menu", data);
 }
 
 /**

=== modified file 'libindicate/listener.h'
--- libindicate/listener.h	2011-08-15 21:21:46 +0000
+++ libindicate/listener.h	2011-12-15 02:27:23 +0000
@@ -134,6 +134,7 @@
 typedef void (*indicate_listener_get_property_bool_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gboolean propertydata, gpointer data);
 typedef void (*indicate_listener_get_server_property_cb) (IndicateListener * listener, IndicateListenerServer * server, const gchar * value, gpointer data);
 typedef void (*indicate_listener_get_server_uint_property_cb) (IndicateListener * listener, IndicateListenerServer * server, guint value, gpointer data);
+typedef void (*indicate_listener_get_server_strv_property_cb) (IndicateListener * listener, IndicateListenerServer * server, GStrv value, gpointer data);
 
 /* Create a new listener */
 IndicateListener *    indicate_listener_new                (void);
@@ -185,6 +186,11 @@
                                                             IndicateListenerServer * server,
                                                             void (*callback) (IndicateListener * listener, IndicateListenerServer * server, const gchar * value, gpointer data),
                                                             gpointer data);
+void                  indicate_listener_server_get_icon_path (IndicateListener *listener,
+							      IndicateListenerServer *server,
+							      void (*callback) (IndicateListener *listener, IndicateListenerServer *server, GStrv value, gpointer data),
+							      gpointer data);
+
 void                  indicate_listener_server_get_count   (IndicateListener * listener,
                                                             IndicateListenerServer * server,
                                                             void (*callback) (IndicateListener * listener, IndicateListenerServer * server, guint value, gpointer data),

=== modified file 'libindicate/server.c'
--- libindicate/server.c	2011-08-10 19:13:56 +0000
+++ libindicate/server.c	2011-12-15 02:27:23 +0000
@@ -79,7 +79,8 @@
 	PROP_DESKTOP,
 	PROP_TYPE,
 	PROP_COUNT,
-	PROP_MENU
+	PROP_MENU,
+	PROP_ICON_PATH
 };
 
 static guint signals[LAST_SIGNAL] = { 0 };
@@ -97,10 +98,12 @@
 	gboolean visible;
 	guint current_id;
 	guint registered;
-
+	
 	gchar * desktop;
 	gchar * type;
 	guint count;
+	
+	GStrv icon_path;
 
 	DbusmenuServer * dbusmenu;
 
@@ -408,6 +411,13 @@
 	                                              "The DBus Object path to an object with a dbusmenu interface on it.",
 												  "",
 	                                              G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+	
+	g_object_class_install_property (gobj, PROP_ICON_PATH,
+					 g_param_spec_boxed ("icon-path",
+							     "Icon Path",
+							     "The search path for icons",
+							     G_TYPE_STRV,
+							     G_PARAM_READWRITE));
 
 	class->get_indicator_count = get_indicator_count;
 	class->get_indicator_list = get_indicator_list;
@@ -582,6 +592,9 @@
 	if (priv->type) {
 		g_free(priv->type);
 	}
+	if (priv->icon_path) {
+		g_strfreev(priv->icon_path);
+	}
 
 	G_OBJECT_CLASS (indicate_server_parent_class)->finalize (obj);
 
@@ -591,10 +604,16 @@
 static void
 set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec)
 {
-	g_return_if_fail(G_VALUE_HOLDS_STRING(value) || G_VALUE_HOLDS_UINT(value));
+  g_return_if_fail(G_VALUE_HOLDS_STRING(value) || G_VALUE_HOLDS_UINT(value) || G_VALUE_HOLDS_BOXED(value));
 
 	IndicateServerPrivate * priv = INDICATE_SERVER_GET_PRIVATE(obj);
 	switch (id) {
+	case PROP_ICON_PATH:
+	        if (priv->icon_path != NULL) {
+			g_strfreev(priv->icon_path);
+	        }
+		priv->icon_path = (GStrv) g_value_dup_boxed (value);
+		break;
 	case PROP_DESKTOP:
 		if (priv->desktop != NULL) {
 			g_free(priv->desktop);
@@ -639,6 +658,14 @@
 {
 	IndicateServerPrivate * priv = INDICATE_SERVER_GET_PRIVATE(obj);
 	switch (id) {
+	case PROP_ICON_PATH:
+		if (priv->icon_path == NULL) {
+			gchar *default_path[] = {"", NULL};
+			g_value_set_boxed (value, (gpointer)default_path);
+		} else {
+			g_value_set_boxed (value, (gpointer)priv->icon_path);
+		}
+		break;
 	case PROP_DESKTOP:
 		if (priv->desktop == NULL) {
 			g_value_set_string(value, "");
@@ -795,11 +822,18 @@
 	GVariant * retvariant = NULL;
 	
 	if (g_strcmp0(property, "desktop") == 0) {
-		if (priv->desktop != NULL) {
+	  if (priv->desktop != NULL) {
 			retvariant = g_variant_new_string(priv->desktop);
 		} else {
 			retvariant = g_variant_new_string("");
 		}
+	} else if (g_strcmp0(property, "iconpath") ==0) {
+		if (priv->icon_path != NULL) {
+		  retvariant = g_variant_new_strv ((const gchar *const*)priv->icon_path, -1);
+		} else {
+			const gchar *const default_path[] = {"", NULL};
+			retvariant = g_variant_new_strv (default_path, 1);
+		}
 	} else if (g_strcmp0(property, "type") == 0) {
 		if (priv->type != NULL) {
 			retvariant = g_variant_new_string(priv->type);
@@ -1406,6 +1440,28 @@
 }
 
 /**
+ * indicate_server_set_icon_path:
+ * @server: The #IndicateServer to set the type of
+ * @path: An array of directories to use in the icon search path.
+ * 
+ * Sets the icon path, which listeners to the server should use for
+ * icon names.
+ *
+ * This is a convience function to set the #IndicateServer:icon-path
+ * property of the @server object.  The property can also be set
+ * via traditional means, but this one is easier to read.
+*/
+void
+indicate_server_set_icon_path (IndicateServer * server, GStrv path)
+{
+	GValue value = {0};
+	g_value_init(&value, G_TYPE_STRV);
+	g_value_set_boxed(&value, (gpointer)path);
+	g_object_set_property(G_OBJECT(server), "icon-path", &value);
+	return;
+}
+
+/**
  * indicate_server_set_type:
  * @server: The #IndicateServer to set the type of
  * @type: The new type of the server

=== modified file 'libindicate/server.h'
--- libindicate/server.h	2011-08-10 19:13:56 +0000
+++ libindicate/server.h	2011-12-15 02:27:23 +0000
@@ -219,6 +219,7 @@
 /* Sets the desktop file to get data like name and description
  * out of */
 void indicate_server_set_desktop_file (IndicateServer * server, const gchar * path);
+void indicate_server_set_icon_path (IndicateServer *server, GStrv icon_path);
 void indicate_server_set_type (IndicateServer * server, const gchar * type);
 void indicate_server_set_count (IndicateServer * server, guint count);
 

=== modified file 'tests/test-properties-server.c'
--- tests/test-properties-server.c	2010-01-26 05:11:59 +0000
+++ tests/test-properties-server.c	2011-12-15 02:27:23 +0000
@@ -6,6 +6,22 @@
 static GMainLoop * mainloop = NULL;
 static gint tests = 0;
 
+
+static void
+server_strv_cb (IndicateListener *listener,
+		IndicateListenerServer *server,
+		GStrv value, 
+		gpointer data)
+{
+  int i = 0;
+
+  while (value[i] != 0)
+    {
+      g_printf("Icon path entry: %s\n", value[i]);
+      i++;
+    }
+}
+
 static void
 string_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, const gchar * propertydata, gpointer data)
 {
@@ -64,6 +80,8 @@
 	tests++;
 	indicate_listener_get_property_bool(listener, server, indicator, "no-bool-value", bool_cb, GINT_TO_POINTER(FALSE));
 	tests++;
+	
+	indicate_listener_server_get_icon_path (listener, server, server_strv_cb, GINT_TO_POINTER (FALSE));
 
 	return;
 }


Follow ups