aboutsummaryrefslogtreecommitdiff
path: root/libindicate
diff options
context:
space:
mode:
Diffstat (limited to 'libindicate')
-rw-r--r--libindicate/indicator.c4
-rw-r--r--libindicate/listener.c158
-rw-r--r--libindicate/listener.h30
-rw-r--r--libindicate/server.c32
-rw-r--r--libindicate/server.h4
5 files changed, 207 insertions, 21 deletions
diff --git a/libindicate/indicator.c b/libindicate/indicator.c
index 71ce030..c6df80a 100644
--- a/libindicate/indicator.c
+++ b/libindicate/indicator.c
@@ -67,7 +67,7 @@ static GPtrArray * list_properties (IndicateIndicator * indicator);
static void
indicate_indicator_class_init (IndicateIndicatorClass * class)
{
- g_debug("Indicator Class Initialized.");
+ /* g_debug("Indicator Class Initialized."); */
GObjectClass * gobj;
gobj = G_OBJECT_CLASS(class);
@@ -116,7 +116,7 @@ indicate_indicator_class_init (IndicateIndicatorClass * class)
static void
indicate_indicator_init (IndicateIndicator * indicator)
{
- g_debug("Indicator Object Initialized.");
+ /* g_debug("Indicator Object Initialized."); */
IndicateIndicatorPrivate * priv = INDICATE_INDICATOR_GET_PRIVATE(indicator);
priv->is_visible = FALSE;
diff --git a/libindicate/listener.c b/libindicate/listener.c
index 01986ad..4da6d59 100644
--- a/libindicate/listener.c
+++ b/libindicate/listener.c
@@ -70,6 +70,8 @@ struct _IndicateListenerPrivate
typedef struct {
DBusGProxy * proxy;
+ DBusGProxy * property_proxy;
+ DBusGConnection * connection;
gchar * name;
gchar * type;
IndicateListener * listener;
@@ -90,6 +92,7 @@ static void proxy_struct_destroy (gpointer data);
static void build_todo_list_cb (DBusGProxy * proxy, char ** names, GError * error, void * data);
static void todo_list_add (const gchar * name, DBusGProxy * proxy, IndicateListener * listener);
static gboolean todo_idle (gpointer data);
+void get_type_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data);
static void proxy_server_added (DBusGProxy * proxy, const gchar * type, proxy_t * proxyt);
static void proxy_indicator_added (DBusGProxy * proxy, guint id, const gchar * type, proxy_t * proxyt);
static void proxy_indicator_removed (DBusGProxy * proxy, guint id, const gchar * type, proxy_t * proxyt);
@@ -242,11 +245,29 @@ indicate_listener_finalize (GObject * obj)
IndicateListener *
indicate_listener_new (void)
{
+ g_warning("Creating a new listener is generally discouraged, please use indicate_listener_ref_default");
+
IndicateListener * listener;
listener = g_object_new(INDICATE_TYPE_LISTENER, NULL);
return listener;
}
+static IndicateListener * default_indicate_listener = NULL;
+
+IndicateListener *
+indicate_listener_ref_default (void)
+{
+ if (default_indicate_listener != NULL) {
+ g_object_ref(default_indicate_listener);
+ } else {
+ default_indicate_listener = g_object_new(INDICATE_TYPE_LISTENER, NULL);
+ g_object_add_weak_pointer(G_OBJECT(default_indicate_listener),
+ (gpointer *)&default_indicate_listener);
+ }
+
+ return default_indicate_listener;
+}
+
static void
dbus_owner_change (DBusGProxy * proxy, const gchar * name, const gchar * prev, const gchar * new, IndicateListener * listener)
{
@@ -319,6 +340,14 @@ proxy_struct_destroy (gpointer data)
proxy_data->indicators = NULL;
}
+ if (proxy_data->property_proxy) {
+ g_object_unref(G_OBJECT(proxy_data->property_proxy));
+ }
+
+ if (proxy_data->proxy) {
+ g_object_unref(G_OBJECT(proxy_data->proxy));
+ }
+
g_free(proxy_data->name);
if (proxy_data->type != NULL) {
g_free(proxy_data->type);
@@ -407,8 +436,10 @@ todo_idle (gpointer data)
proxyt->name,
"/org/freedesktop/indicate",
"org.freedesktop.indicator");
+ proxyt->property_proxy = NULL;
proxyt->listener = listener;
proxyt->indicators = NULL;
+ proxyt->connection = todo->bus;
priv->proxy_todo = g_array_remove_index(priv->proxy_todo, priv->proxy_todo->len - 1);
@@ -422,13 +453,30 @@ todo_idle (gpointer data)
dbus_g_proxy_connect_signal(proxyt->proxy, "ServerShow",
G_CALLBACK(proxy_server_added), proxyt, NULL);
- org_freedesktop_indicator_get_indicator_list_async(proxyt->proxy, proxy_get_indicator_list, proxyt);
-
g_hash_table_insert(priv->proxies_possible, proxyt->name, proxyt);
+ indicate_listener_server_get_type(listener, (IndicateListenerServer *)proxyt->name, get_type_cb, proxyt);
+
return TRUE;
}
+void
+get_type_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data)
+{
+ if (type == NULL) {
+ /* This is usually caused by an error getting the type,
+ * which would mean that this isn't an indicator server */
+ return;
+ }
+
+ proxy_t * proxyt = (proxy_t *)data;
+
+ proxy_server_added (proxyt->proxy, type, proxyt);
+ org_freedesktop_indicator_get_indicator_list_async(proxyt->proxy, proxy_get_indicator_list, proxyt);
+
+ return;
+}
+
typedef struct {
guint id;
proxy_t * proxyt;
@@ -496,10 +544,12 @@ proxy_server_added (DBusGProxy * proxy, const gchar * type, proxy_t * proxyt)
dbus_g_proxy_connect_signal(proxyt->proxy, "IndicatorModified",
G_CALLBACK(proxy_indicator_modified), proxyt, NULL);
- if (proxyt->type != NULL) {
- g_free(proxyt->type);
+ if (type != NULL) {
+ if (proxyt->type != NULL) {
+ g_free(proxyt->type);
+ }
+ proxyt->type = g_strdup(type);
}
- proxyt->type = g_strdup(type);
g_signal_emit(proxyt->listener, signals[SERVER_ADDED], 0, proxyt->name, proxyt->type, TRUE);
}
@@ -511,7 +561,7 @@ static void
proxy_indicator_added (DBusGProxy * proxy, guint id, const gchar * type, proxy_t * proxyt)
{
if (proxyt->indicators == NULL) {
- proxy_server_added (proxy, type, proxyt);
+ proxy_server_added (proxy, NULL, proxyt);
}
GHashTable * indicators = g_hash_table_lookup(proxyt->indicators, type);
@@ -673,3 +723,99 @@ indicate_listener_display (IndicateListener * listener, IndicateListenerServer *
return;
}
+
+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)
+{
+ /* g_debug("Callback for property %s %s %s", dbus_g_proxy_get_bus_name(proxy), dbus_g_proxy_get_path(proxy), dbus_g_proxy_get_interface(proxy)); */
+ property_cb_t * propertyt = data;
+ GError * error = NULL;
+
+ GValue property = {0};
+
+ 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);
+
+ /* g_debug("\tProperty value: %s", propstr); */
+
+ return cb(listener, server, propstr, cb_data);
+}
+
+static void
+get_server_property (IndicateListener * listener, IndicateListenerServer * server, indicate_listener_get_server_property_cb callback, const gchar * property_name, gpointer data)
+{
+ /* g_debug("Setting up callback for property: %s", property_name); */
+ IndicateListenerPrivate * priv = INDICATE_LISTENER_GET_PRIVATE(listener);
+
+ proxy_t * proxyt = g_hash_table_lookup(priv->proxies_possible, server);
+ if (proxyt == NULL) {
+ proxy_t * proxyt = g_hash_table_lookup(priv->proxies_working, server);
+ }
+
+ if (proxyt == NULL) {
+ return;
+ }
+
+ if (proxyt->property_proxy == NULL) {
+ proxyt->property_proxy = dbus_g_proxy_new_for_name(proxyt->connection,
+ 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,
+ NULL,
+ G_TYPE_STRING, "org.freedesktop.indicator",
+ G_TYPE_STRING, property_name,
+ G_TYPE_INVALID, G_TYPE_VALUE, 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 70b7e51..3d8c7ef 100644
--- a/libindicate/listener.h
+++ b/libindicate/listener.h
@@ -79,18 +79,28 @@ 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_server_property_cb) (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data);
/* Create a new listener */
-IndicateListener * indicate_listener_new (void);
-void indicate_listener_get_property (IndicateListener * listener,
- IndicateListenerServer * server,
- IndicateListenerIndicator * indicator,
- gchar * property,
- indicate_listener_get_property_cb callback,
- gpointer data);
-void indicate_listener_display (IndicateListener * listener,
- IndicateListenerServer * server,
- IndicateListenerIndicator * indicator);
+IndicateListener * indicate_listener_new (void);
+IndicateListener * indicate_listener_ref_default (void);
+void indicate_listener_get_property (IndicateListener * listener,
+ IndicateListenerServer * server,
+ IndicateListenerIndicator * indicator,
+ gchar * property,
+ indicate_listener_get_property_cb callback,
+ gpointer data);
+void indicate_listener_display (IndicateListener * listener,
+ IndicateListenerServer * server,
+ IndicateListenerIndicator * indicator);
+void indicate_listener_server_get_type (IndicateListener * listener,
+ IndicateListenerServer * server,
+ indicate_listener_get_server_property_cb callback,
+ gpointer data);
+void indicate_listener_server_get_desktop (IndicateListener * listener,
+ IndicateListenerServer * server,
+ indicate_listener_get_server_property_cb callback,
+ gpointer data);
diff --git a/libindicate/server.c b/libindicate/server.c
index 766e312..0c74376 100644
--- a/libindicate/server.c
+++ b/libindicate/server.c
@@ -106,7 +106,7 @@ static void get_property (GObject * obj, guint id, GValue * value, GParamSpec *
static void
indicate_server_class_init (IndicateServerClass * class)
{
- g_debug("Server Class Initialized");
+ /* g_debug("Server Class Initialized"); */
GObjectClass * gobj;
gobj = G_OBJECT_CLASS(class);
@@ -182,7 +182,7 @@ indicate_server_class_init (IndicateServerClass * class)
static void
indicate_server_init (IndicateServer * server)
{
- g_debug("Server Object Initialized");
+ /* g_debug("Server Object Initialized"); */
IndicateServerPrivate * priv = INDICATE_SERVER_GET_PRIVATE(server);
@@ -396,6 +396,34 @@ indicate_server_remove_indicator (IndicateServer * server, IndicateIndicator * i
return;
}
+void
+indicate_server_set_dbus_object (const gchar * obj)
+{
+ /* TODO */
+
+ return;
+}
+
+void
+indicate_server_set_desktop_file (IndicateServer * server, const gchar * path)
+{
+ GValue value = {0};
+ g_value_init(&value, G_TYPE_STRING);
+ g_value_set_string(&value, path);
+ g_object_set_property(G_OBJECT(server), "desktop", &value);
+ return;
+}
+
+void
+indicate_server_set_type (IndicateServer * server, const gchar * type)
+{
+ GValue value = {0};
+ g_value_init(&value, G_TYPE_STRING);
+ g_value_set_string(&value, type);
+ g_object_set_property(G_OBJECT(server), "type", &value);
+ return;
+}
+
static IndicateServer * default_indicate_server = NULL;
IndicateServer *
diff --git a/libindicate/server.h b/libindicate/server.h
index 9347f16..4e3c931 100644
--- a/libindicate/server.h
+++ b/libindicate/server.h
@@ -83,7 +83,8 @@ void indicate_server_set_dbus_object (const gchar * obj);
/* Sets the desktop file to get data like name and description
* out of */
-void indicate_server_set_desktop_file (const gchar * path);
+void indicate_server_set_desktop_file (IndicateServer * server, const gchar * path);
+void indicate_server_set_type (IndicateServer * server, const gchar * type);
/* Show and hide the server on DBus, this allows for the server to
* be created, change the object, and then shown. If for some
@@ -99,6 +100,7 @@ void indicate_server_remove_indicator (IndicateServer * server, IndicateIndicato
IndicateServer * indicate_server_ref_default (void);
void indicate_server_set_default (IndicateServer * server);
+
/* DBus API */
gboolean indicate_server_get_indicator_count (IndicateServer * server, guint * count, GError **error);
gboolean indicate_server_get_indicator_count_by_type (IndicateServer * server, gchar * type, guint * count, GError **error);