ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #00095
[Merge] lp:~ted/libindicate/extra-funcs into lp:libindicate
Ted Gould has proposed merging lp:~ted/libindicate/extra-funcs into lp:libindicate.
Requested reviews:
Indicator Applet Developers (indicator-applet-developers)
Functions on getting the count that were forgotten.
--
https://code.launchpad.net/~ted/libindicate/extra-funcs/+merge/11376
Your team ayatana-commits is subscribed to branch lp:libindicate.
=== modified file 'libindicate/listener-marshal.list'
--- libindicate/listener-marshal.list 2009-08-28 20:38:15 +0000
+++ libindicate/listener-marshal.list 2009-09-05 04:24:47 +0000
@@ -33,3 +33,5 @@
VOID:POINTER,POINTER,STRING
# Local server_added and server_removed
VOID:POINTER,STRING
+# Local server_count_changed
+VOID:POINTER,UINT
=== modified file 'libindicate/listener.c'
--- libindicate/listener.c 2009-09-04 02:58:25 +0000
+++ libindicate/listener.c 2009-09-05 16:38:55 +0000
@@ -49,6 +49,7 @@
INDICATOR_MODIFIED,
SERVER_ADDED,
SERVER_REMOVED,
+ SERVER_COUNT_CHANGED,
LAST_SIGNAL
};
@@ -102,6 +103,7 @@
static void proxy_indicator_added (DBusGProxy * proxy, guint id, proxy_t * proxyt);
static void proxy_indicator_removed (DBusGProxy * proxy, guint id, proxy_t * proxyt);
static void proxy_indicator_modified (DBusGProxy * proxy, guint id, const gchar * property, proxy_t * proxyt);
+static void proxy_server_count_changed (DBusGProxy * proxy, guint count, proxy_t * proxyt);
static void proxy_get_indicator_list (DBusGProxy * proxy, GArray * indicators, GError * error, gpointer data);
static void proxy_get_indicator_type (DBusGProxy * proxy, gchar * type, GError * error, gpointer data);
static void introspect_this (DBusGProxy * proxy, char * OUT_data, GError * error, gpointer data);
@@ -159,6 +161,13 @@
NULL, NULL,
_indicate_listener_marshal_VOID__POINTER_STRING,
G_TYPE_NONE, 2, INDICATE_TYPE_LISTENER_SERVER, G_TYPE_STRING);
+ signals[SERVER_COUNT_CHANGED] = g_signal_new(INDICATE_LISTENER_SIGNAL_SERVER_COUNT_CHANGED,
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (IndicateListenerClass, server_count_changed),
+ NULL, NULL,
+ _indicate_listener_marshal_VOID__POINTER_UINT,
+ G_TYPE_NONE, 2, INDICATE_TYPE_LISTENER_SERVER, G_TYPE_UINT);
dbus_g_object_register_marshaller(_indicate_listener_marshal_VOID__UINT_STRING,
G_TYPE_NONE,
@@ -587,6 +596,10 @@
G_TYPE_UINT, G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(proxyt->proxy, "IndicatorModified",
G_CALLBACK(proxy_indicator_modified), proxyt, NULL);
+ dbus_g_proxy_add_signal(proxyt->proxy, "ServerCountChanged",
+ G_TYPE_UINT, G_TYPE_INVALID);
+ dbus_g_proxy_connect_signal(proxyt->proxy, "ServerCountChanged",
+ G_CALLBACK(proxy_server_count_changed), proxyt, NULL);
if (type != NULL) {
if (proxyt->type != NULL) {
@@ -663,6 +676,17 @@
return;
}
+/* This function gets called when the dbus count
+ signal comes it. Basically we're just translating
+ it into a local signal with the appropraite parameters
+ and structures. */
+static void
+proxy_server_count_changed (DBusGProxy * proxy, guint count, proxy_t * proxyt)
+{
+ g_signal_emit(proxyt->listener, signals[SERVER_COUNT_CHANGED], 0, &proxyt->server, count, TRUE);
+ return;
+}
+
typedef enum _get_property_type get_property_type;
enum _get_property_type {
PROPERTY_TYPE_STRING,
@@ -812,9 +836,14 @@
IndicateListener * listener;
IndicateListenerServer * server;
indicate_listener_get_server_property_cb cb;
+ indicate_listener_get_server_uint_property_cb cb_uint;
gpointer data;
} property_cb_t;
+/* A callback from getting the property off of the server
+ which unravels the property_cb_t structure that was passed
+ as data and calls back the call back that was in it with
+ the appropriate data, also unrolled. */
static void
property_cb (DBusGProxy * proxy, DBusGProxyCall * call, void * data)
{
@@ -824,6 +853,9 @@
GValue property = {0};
+ /* Finish the call and get our value. There might
+ be an error as if someone was using v1 API and
+ not v2. Let's handle that early. */
dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &property, G_TYPE_INVALID);
if (error != NULL) {
/* g_warning("Unable to get property: %s", error->message); */
@@ -832,28 +864,42 @@
return;
}
- if (!G_VALUE_HOLDS_STRING(&property)) {
- g_warning("Property returned is not a string!");
- g_free(propertyt);
- return;
- }
-
+ /* Dup all the values and make them local so that
+ we can free up the data structure to make the
+ rest of the code easier to read. */
IndicateListener * listener = propertyt->listener;
IndicateListenerServer * server = propertyt->server;
indicate_listener_get_server_property_cb cb = propertyt->cb;
+ indicate_listener_get_server_uint_property_cb cb_uint = propertyt->cb_uint;
gpointer cb_data = propertyt->data;
g_free(propertyt);
- gchar * propstr = g_value_dup_string(&property);
-
- /* g_debug("\tProperty value: %s", propstr); */
-
- return cb(listener, server, propstr, cb_data);
+ if (G_VALUE_HOLDS_STRING(&property) && cb != NULL) {
+ /* If it's got a string, and we have a value for that
+ we'll get the string out and call the call back */
+ gchar * propstr = g_value_dup_string(&property);
+ return cb(listener, server, propstr, cb_data);
+ } else if (G_VALUE_HOLDS_UINT(&property) && cb_uint != NULL) {
+ /* If it's got a UINT and we have a callback for that
+ let's grab the value and call the callback. */
+ guint val = g_value_get_uint(&property);
+ return cb_uint(listener, server, val, cb_data);
+ } else {
+ /* WTF!?!?!?! */
+ g_warning("Property back from server that we didn't understand.");
+ }
+
+ return;
}
+/* This is a helper function for all the functions that
+ get properties from the server. They all need to have
+ a callback setup with an intermediary data structure
+ 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, 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, const gchar * property_name, gpointer data)
{
/* g_debug("Setting up callback for property %s on %s", property_name, INDICATE_LISTENER_SERVER_DBUS_NAME(server)); */
IndicateListenerPrivate * priv = INDICATE_LISTENER_GET_PRIVATE(listener);
@@ -902,13 +948,19 @@
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, "type", data);
+ return get_server_property(listener, server, callback, 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, "desktop", data);
+ return get_server_property(listener, server, callback, NULL, "desktop", 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);
}
const gchar *
=== modified file 'libindicate/listener.h'
--- libindicate/listener.h 2009-09-01 17:09:56 +0000
+++ libindicate/listener.h 2009-09-05 16:38:55 +0000
@@ -52,6 +52,7 @@
#define INDICATE_LISTENER_SIGNAL_INDICATOR_MODIFIED "indicator-modified"
#define INDICATE_LISTENER_SIGNAL_SERVER_ADDED "server-added"
#define INDICATE_LISTENER_SIGNAL_SERVER_REMOVED "server-removed"
+#define INDICATE_LISTENER_SIGNAL_SERVER_COUNT_CHANGED "server-count-changed"
#define INDICATE_LISTENER_SERVER_DBUS_NAME(server) (indicate_listener_server_get_dbusname(server))
#define INDICATE_LISTENER_INDICATOR_ID(indicator) (indicate_listener_indicator_get_id(indicator))
@@ -77,6 +78,7 @@
@indicator_modified: Slot for IndicateListener::indicator-modified.
@server_added: Slot for IndicateListener::server-added.
@server_removed: Slot for IndicateListener::server-removed.
+ @server_count_changed: Slot for IndicateListener::server-count-changed.
@indicate_listener_reserved1: Reserved for future use
@indicate_listener_reserved2: Reserved for future use
@indicate_listener_reserved3: Reserved for future use
@@ -97,6 +99,7 @@
void (* server_added) (IndicateListenerServer * server, gchar * type);
void (* server_removed) (IndicateListenerServer * server, gchar * type);
+ void (* server_count_changed) (IndicateListenerServer * server, guint count);
/* Future Use */
void (*indicate_listener_reserved1)(void);
@@ -110,6 +113,7 @@
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_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);
/* Create a new listener */
IndicateListener * indicate_listener_new (void);
@@ -141,6 +145,10 @@
IndicateListenerServer * server,
indicate_listener_get_server_property_cb callback,
gpointer data);
+void indicate_listener_server_get_count (IndicateListener * listener,
+ IndicateListenerServer * server,
+ indicate_listener_get_server_uint_property_cb callback,
+ gpointer data);
const gchar * indicate_listener_server_get_dbusname (IndicateListenerServer * server);
guint indicate_listener_indicator_get_id (IndicateListenerIndicator * indicator);
void indicate_listener_server_show_interest (IndicateListener * listener,
Follow ups