← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~ted/libindicate/helpers into lp:libindicate

 

Ted Gould has proposed merging lp:~ted/libindicate/helpers into lp:libindicate.

Requested reviews:
    Aurélien Gâteau (agateau)
-- 
https://code.launchpad.net/~ted/libindicate/helpers/+merge/11704
Your team ayatana-commits is subscribed to branch lp:libindicate.
=== modified file 'libindicate/indicator.c'
--- libindicate/indicator.c	2009-09-01 17:05:33 +0000
+++ libindicate/indicator.c	2009-09-14 14:48:43 +0000
@@ -424,6 +424,48 @@
 }
 
 /**
+	indicate_indicator_set_property_int:
+	@indicator: a #IndicateIndicator to act on
+	@key: name of the property
+	@value: integer to set property with
+
+	This is a helper function that wraps around #indicate_indicator_set_property
+	but takes an integer property and turns into a string and
+	uses that data to call #indicate_indicator_set_property.
+*/
+void
+indicate_indicator_set_property_int (IndicateIndicator * indicator, const gchar * key, gint value)
+{
+	gchar * valuestr = g_strdup_printf("%d", value);
+	if (valuestr != NULL) {
+		indicate_indicator_set_property(indicator, key, valuestr);
+	}
+	g_free(valuestr);
+	return;
+}
+
+/**
+	indicate_indicator_set_property_bool:
+	@indicator: a #IndicateIndicator to act on
+	@key: name of the property
+	@value: integer to set property with
+
+	This is a helper function that wraps around #indicate_indicator_set_property
+	but takes a boolean property and turns into a string and
+	uses that data to call #indicate_indicator_set_property.
+*/
+void
+indicate_indicator_set_property_bool (IndicateIndicator * indicator, const gchar * key, gboolean value)
+{
+	if (value) {
+		indicate_indicator_set_property(indicator, key, INDICATE_INDICATOR_VALUE_TRUE);
+	} else {
+		indicate_indicator_set_property(indicator, key, INDICATE_INDICATOR_VALUE_FALSE);
+	}
+	return;
+}
+
+/**
 	indicate_indicator_get_property:
 	@indicator: a #IndicateIndicator to act on
 	@key: name of the property

=== modified file 'libindicate/indicator.h'
--- libindicate/indicator.h	2009-08-31 21:26:29 +0000
+++ libindicate/indicator.h	2009-09-14 14:48:43 +0000
@@ -43,6 +43,11 @@
 #define INDICATE_IS_INDICATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), INDICATE_TYPE_INDICATOR))
 #define INDICATE_INDICATOR_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), INDICATE_TYPE_INDICATOR, IndicateIndicatorClass))
 
+/* Some values that are commonly used.  Most likely only
+   internal, but if you need them, here they are! */
+#define INDICATE_INDICATOR_VALUE_TRUE       "true"
+#define INDICATE_INDICATOR_VALUE_FALSE      "false"
+
 /* This is a signal that signals to the indicator that the user
  * has done an action where they'd like this indicator to be
  * displayed. */
@@ -142,6 +147,9 @@
 /* Properties handling */
 void indicate_indicator_set_property (IndicateIndicator * indicator, const gchar * key, const gchar * data);
 void indicate_indicator_set_property_time (IndicateIndicator * indicator, const gchar * key, GTimeVal * time);
+void indicate_indicator_set_property_int (IndicateIndicator * indicator, const gchar * key, gint value);
+void indicate_indicator_set_property_bool (IndicateIndicator * indicator, const gchar * key, gboolean value);
+
 const gchar * indicate_indicator_get_property (IndicateIndicator * indicator, const gchar * key);
 GPtrArray * indicate_indicator_list_properties (IndicateIndicator * indicator);
 

=== modified file 'libindicate/listener.c'
--- libindicate/listener.c	2009-09-08 22:01:57 +0000
+++ libindicate/listener.c	2009-09-14 15:30:59 +0000
@@ -742,7 +742,9 @@
 typedef enum _get_property_type get_property_type;
 enum _get_property_type {
 	PROPERTY_TYPE_STRING,
-	PROPERTY_TYPE_TIME
+	PROPERTY_TYPE_TIME,
+	PROPERTY_TYPE_INT,
+	PROPERTY_TYPE_BOOL
 };
 
 typedef struct _get_property_t get_property_t;
@@ -756,6 +758,14 @@
 	get_property_type type;
 };
 
+/* Look at the right align on this comment.  Sweeeeeeeet */
+/* A callback from getting a property that takes the string 
+   passed across the bus and turning it into something more
+   related to what we want on this side.  If it's a time it
+   gets converted to a #GTimeVal, if it's an int it goes to
+   a gint and if it's a bool we check that too.  This makes
+   it nice to work with properties and the listener.
+*/
 static void
 get_property_cb (DBusGProxy *proxy, char * OUT_value, GError *error, gpointer userdata)
 {
@@ -769,11 +779,13 @@
 
 	switch (get_property_data->type) {
 	case PROPERTY_TYPE_STRING: {
+		/* Just pass the string along. */
 		indicate_listener_get_property_cb cb = (indicate_listener_get_property_cb)get_property_data->cb;
 		cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, OUT_value, get_property_data->data);
 		break;
 	}
 	case PROPERTY_TYPE_TIME: {
+		/* Convert it to a time val */
 		indicate_listener_get_property_time_cb cb = (indicate_listener_get_property_time_cb)get_property_data->cb;
 		GTimeVal time;
 		if (g_time_val_from_iso8601(OUT_value, &time)) {
@@ -781,6 +793,25 @@
 		}
 		break;
 	}
+	case PROPERTY_TYPE_INT: {
+		/* Take the string and convert it to an integer */
+		indicate_listener_get_property_int_cb cb = (indicate_listener_get_property_int_cb)get_property_data->cb;
+		if (OUT_value == NULL) break;
+		gint intval = atoi(OUT_value);
+		cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, intval, get_property_data->data);
+		break;
+	}
+	case PROPERTY_TYPE_BOOL: {
+		/* Check to see if it's 'true', if not assume that
+		   it's false */
+		indicate_listener_get_property_bool_cb cb = (indicate_listener_get_property_bool_cb)get_property_data->cb;
+		if (g_strcmp0(OUT_value, INDICATE_INDICATOR_VALUE_TRUE) == 0) {
+			cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, TRUE, get_property_data->data);
+		} else {
+			cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, FALSE, get_property_data->data);
+		}
+		break;
+	}
 	}
 
 	g_free(get_property_data->property);
@@ -789,6 +820,9 @@
 	return;
 };
 
+/* A small function to take the common list of parameters and
+   build a callback structure to hold them all.  Eventually we
+   get the data and unwind this structure. */
 static void
 get_property_helper (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GCallback callback, gpointer data, get_property_type prop_type)
 {
@@ -807,18 +841,95 @@
 	return;
 }
 
+/**
+	indicate_listener_get_property:
+	@listener: The #IndicateListener representing the connection
+	@server: The server that the indicator is on
+	@indicator: Which indicator is being queried
+	@property: Name of the property to get
+	@callback: The callback function to call with the data
+	@data: Arbitrary data to give the callback
+
+	A function to get a property from an indicator on a server
+	and bring it back locally.  This wraps all the hassle of using
+	the DBus API and makes it pretty easy to get properties.
+*/
 void
 indicate_listener_get_property (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, indicate_listener_get_property_cb callback, gpointer data)
 {
 	return get_property_helper(listener, server, indicator, property, G_CALLBACK(callback), data, PROPERTY_TYPE_STRING);
 }
 
+/**
+	indicate_listener_get_property_time:
+	@listener: The #IndicateListener representing the connection
+	@server: The server that the indicator is on
+	@indicator: Which indicator is being queried
+	@property: Name of the property to get
+	@callback: The callback function to call with the data
+	@data: Arbitrary data to give the callback
+
+	A function to get a property from an indicator on a server
+	and bring it back locally.  This wraps all the hassle of using
+	the DBus API and makes it pretty easy to get properties.
+
+	Very similar to #indicate_listener_get_property but converts
+	the final value into a GTimeVal for easy (and type-safe)
+	usage by listeners.
+*/
 void
 indicate_listener_get_property_time (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, indicate_listener_get_property_time_cb callback, gpointer data)
 {
 	return get_property_helper(listener, server, indicator, property, G_CALLBACK(callback), data, PROPERTY_TYPE_TIME);
 }
 
+/**
+	indicate_listener_get_property_int:
+	@listener: The #IndicateListener representing the connection
+	@server: The server that the indicator is on
+	@indicator: Which indicator is being queried
+	@property: Name of the property to get
+	@callback: The callback function to call with the data
+	@data: Arbitrary data to give the callback
+
+	A function to get a property from an indicator on a server
+	and bring it back locally.  This wraps all the hassle of using
+	the DBus API and makes it pretty easy to get properties.
+
+	Very similar to #indicate_listener_get_property but converts
+	the final value into a gint for easy (and type-safe)
+	usage by listeners.
+*/
+void
+indicate_listener_get_property_int (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, indicate_listener_get_property_int_cb callback, gpointer data)
+{
+	return get_property_helper(listener, server, indicator, property, G_CALLBACK(callback), data, PROPERTY_TYPE_INT);
+}
+
+/**
+	indicate_listener_get_property_bool:
+	@listener: The #IndicateListener representing the connection
+	@server: The server that the indicator is on
+	@indicator: Which indicator is being queried
+	@property: Name of the property to get
+	@callback: The callback function to call with the data
+	@data: Arbitrary data to give the callback
+
+	A function to get a property from an indicator on a server
+	and bring it back locally.  This wraps all the hassle of using
+	the DBus API and makes it pretty easy to get properties.
+
+	Very similar to #indicate_listener_get_property but converts
+	the final value into a gboolean for easy (and type-safe)
+	usage by listeners.
+*/
+void
+indicate_listener_get_property_bool (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, indicate_listener_get_property_bool_cb callback, gpointer data)
+{
+	return get_property_helper(listener, server, indicator, property, G_CALLBACK(callback), data, PROPERTY_TYPE_BOOL);
+}
+
+
 gboolean
 _indicate_listener_get_indicator_servers (IndicateListener * listener, GList * servers)
 {

=== modified file 'libindicate/listener.h'
--- libindicate/listener.h	2009-09-05 16:38:55 +0000
+++ libindicate/listener.h	2009-09-14 15:01:18 +0000
@@ -112,6 +112,8 @@
 
 typedef void (*indicate_listener_get_property_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data);
 typedef void (*indicate_listener_get_property_time_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GTimeVal * propertydata, gpointer data);
+typedef void (*indicate_listener_get_property_int_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gint propertydata, gpointer data);
+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, gchar * value, gpointer data);
 typedef void (*indicate_listener_get_server_uint_property_cb) (IndicateListener * listener, IndicateListenerServer * server, guint value, gpointer data);
 
@@ -130,6 +132,18 @@
                                                             gchar * property,
                                                             indicate_listener_get_property_time_cb callback,
                                                             gpointer data);
+void                  indicate_listener_get_property_int   (IndicateListener * listener,
+                                                            IndicateListenerServer * server,
+                                                            IndicateListenerIndicator * indicator,
+                                                            gchar * property,
+                                                            indicate_listener_get_property_int_cb callback,
+                                                            gpointer data);
+void                  indicate_listener_get_property_bool  (IndicateListener * listener,
+                                                            IndicateListenerServer * server,
+                                                            IndicateListenerIndicator * indicator,
+                                                            gchar * property,
+                                                            indicate_listener_get_property_bool_cb callback,
+                                                            gpointer data);
 void                  indicate_listener_display            (IndicateListener * listener,
                                                             IndicateListenerServer * server,
                                                             IndicateListenerIndicator * indicator);

=== modified file 'libindicate/server.c'
--- libindicate/server.c	2009-09-08 20:58:26 +0000
+++ libindicate/server.c	2009-09-14 14:12:39 +0000
@@ -1047,6 +1047,28 @@
 	return;
 }
 
+/**
+	indicate_server_set_count:
+	@server: The #IndicateServer to set the type of
+	@count: The number of items that the server believes the user
+		would be interested in.
+	
+	A small convience function to set the #IndicateServer:count
+	property on the server.  This should represent a number of messages
+	on a particular server.  This should not be used at the same time
+	as individual indicators to show information to the users.  They
+	sound be used independently.
+*/
+void
+indicate_server_set_count (IndicateServer * server, guint count)
+{
+	GValue value = {0};
+	g_value_init(&value, G_TYPE_UINT);
+	g_value_set_uint(&value, count);
+	g_object_set_property(G_OBJECT(server), "count", &value);
+	return;
+}
+
 static IndicateServer * default_indicate_server = NULL;
 
 /**


Follow ups