aboutsummaryrefslogtreecommitdiff
path: root/libindicate
diff options
context:
space:
mode:
authorTed Gould <ted@canonical.com>2009-02-10 16:49:33 -0600
committerTed Gould <ted@canonical.com>2009-02-10 16:49:33 -0600
commit49220be1da318eb6d3154c585fec5242c6e81194 (patch)
treed1edc36acf68b5bc03cf4c1eafb9aba5b4c9e23a /libindicate
parent8bfb5a1b6475f00cb503c794de585f4817c10163 (diff)
downloadlibayatana-indicator-49220be1da318eb6d3154c585fec5242c6e81194.tar.gz
libayatana-indicator-49220be1da318eb6d3154c585fec5242c6e81194.tar.bz2
libayatana-indicator-49220be1da318eb6d3154c585fec5242c6e81194.zip
Building a way to get properties. Seems like this should be in the DBus
libs, but anyway. Here is the code that compiles and claims that it'll do it. More code than I would have liked.
Diffstat (limited to 'libindicate')
-rw-r--r--libindicate/listener.c102
-rw-r--r--libindicate/listener.h7
2 files changed, 101 insertions, 8 deletions
diff --git a/libindicate/listener.c b/libindicate/listener.c
index ae948e3..42da50f 100644
--- a/libindicate/listener.c
+++ b/libindicate/listener.c
@@ -42,6 +42,7 @@ struct _IndicateListenerPrivate
typedef struct {
DBusGProxy * proxy;
+ DBusGProxy * property_proxy;
gchar * name;
gchar * type;
IndicateListener * listener;
@@ -291,6 +292,14 @@ proxy_struct_destroy (gpointer data)
proxy_data->indicators = NULL;
}
+ if (proxy_data->property_proxy) {
+ g_object_unref(G_OBJECT(proxy_data->proxy));
+ }
+
+ if (proxy_data->property_proxy) {
+ g_object_unref(G_OBJECT(proxy_data->proxy));
+ }
+
g_free(proxy_data->name);
if (proxy_data->type != NULL) {
g_free(proxy_data->type);
@@ -379,6 +388,7 @@ todo_idle (gpointer data)
proxyt->name,
"/org/freedesktop/indicate",
"org.freedesktop.indicator");
+ proxyt->property_proxy = NULL;
proxyt->listener = listener;
proxyt->indicators = NULL;
@@ -646,18 +656,102 @@ indicate_listener_display (IndicateListener * listener, IndicateListenerServer *
return;
}
-void
-indicate_listener_server_get_type (IndicateListener * listener, IndicateListenerServer * server, indicate_listener_get_type_cb callback, gpointer data)
+typedef struct {
+ IndicateListener * listener;
+ IndicateListenerServer * server;
+ indicate_listener_get_server_property_cb cb;
+ gpointer data;
+} property_cb_t;
+
+static void
+property_cb (DBusGProxy * proxy, DBusGProxyCall * call, void * data)
{
+ property_cb_t * propertyt = data;
+ GError * error = NULL;
+ GValue property;
+ 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);
+ g_error_free(error);
+ g_free(propertyt);
+ return;
+ }
+ if (!G_VALUE_HOLDS_STRING(&property)) {
+ g_warning("Property returned is not a string!");
+ g_free(propertyt);
+ return;
+ }
+
+ IndicateListener * listener = propertyt->listener;
+ IndicateListenerServer * server = propertyt->server;
+ indicate_listener_get_server_property_cb cb = propertyt->cb;
+ gpointer cb_data = propertyt->data;
+
+ g_free(propertyt);
+
+ gchar * propstr = g_value_dup_string(&property);
+
+ return cb(listener, server, propstr, cb_data);
}
-void
-indicate_listener_server_get_desktop (IndicateListener * listener, IndicateListenerServer * server, indicate_listener_get_desktop_cb callback, gpointer data)
+static void
+get_server_property (IndicateListener * listener, IndicateListenerServer * server, indicate_listener_get_server_property_cb callback, const gchar * property_name, gpointer data)
{
+ IndicateListenerPrivate * priv = INDICATE_LISTENER_GET_PRIVATE(listener);
+
+ proxy_t * proxyt = g_hash_table_lookup(priv->proxies_working, server);
+ if (proxyt == NULL) {
+ g_warning("Looking for a property on an interface that hasn't be setup for indicators.");
+ // Send NULL to the callback
+ return;
+ }
+
+ if (proxyt->property_proxy == NULL) {
+ DBusGConnection * bus;
+ gchar * bus_name;
+ if (proxyt->proxy == priv->dbus_proxy_system) {
+ bus = priv->system_bus;
+ bus_name = "system";
+ } else {
+ bus = priv->session_bus;
+ bus_name = "session";
+ }
+
+ proxyt->property_proxy = dbus_g_proxy_new_for_name(bus,
+ proxyt->name,
+ "/org/freedesktop/indicate",
+ DBUS_INTERFACE_PROPERTIES);
+ }
+ property_cb_t * localdata = g_new(property_cb_t, 1);
+ localdata->listener = listener;
+ localdata->server = server;
+ localdata->cb = callback;
+ localdata->data = data;
+ dbus_g_proxy_begin_call (proxyt->property_proxy,
+ "Get",
+ property_cb,
+ localdata,
+ G_TYPE_STRING, "org.freedesktop.indicator",
+ G_TYPE_STRING, property_name,
+ G_TYPE_INVALID, G_TYPE_INVALID);
+
+ return;
+}
+
+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);
+}
+
+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);
}
diff --git a/libindicate/listener.h b/libindicate/listener.h
index 44855bd..95303e1 100644
--- a/libindicate/listener.h
+++ b/libindicate/listener.h
@@ -51,8 +51,7 @@ struct _IndicateListenerClass {
GType indicate_listener_get_type (void) G_GNUC_CONST;
typedef void (*indicate_listener_get_property_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data);
-typedef void (*indicate_listener_get_type_cb) (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data);
-typedef void (*indicate_listener_get_desktop_cb) (IndicateListener * listener, IndicateListenerServer * server, gchar * desktop, gpointer data);
+typedef void (*indicate_listener_get_server_property_cb) (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data);
/* Create a new listener */
IndicateListener * indicate_listener_new (void);
@@ -67,11 +66,11 @@ void indicate_listener_display (IndicateListener * l
IndicateListenerIndicator * indicator);
void indicate_listener_server_get_type (IndicateListener * listener,
IndicateListenerServer * server,
- indicate_listener_get_type_cb callback,
+ indicate_listener_get_server_property_cb callback,
gpointer data);
void indicate_listener_server_get_desktop (IndicateListener * listener,
IndicateListenerServer * server,
- indicate_listener_get_desktop_cb callback,
+ indicate_listener_get_server_property_cb callback,
gpointer data);