aboutsummaryrefslogtreecommitdiff
path: root/src/libcustomindicator/custom-indicator.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2009-11-24 17:07:41 -0600
committerTed Gould <ted@gould.cx>2009-11-24 17:07:41 -0600
commit62a7252cd51aa817f8f4a5fc338ba601c022133b (patch)
treef832f53ae154905e8079f4b5732190b5b5fb18f3 /src/libcustomindicator/custom-indicator.c
parent7c86b00eba7f9cb4afd72d349c3579bb5f3ab5c3 (diff)
parent8c7ce8faffe025e5c5cf8f4f23d9cf97cf719533 (diff)
downloadayatana-indicator-application-62a7252cd51aa817f8f4a5fc338ba601c022133b.tar.gz
ayatana-indicator-application-62a7252cd51aa817f8f4a5fc338ba601c022133b.tar.bz2
ayatana-indicator-application-62a7252cd51aa817f8f4a5fc338ba601c022133b.zip
Sync to trunk and fix distcheck by delaying connecting to
the service by checking for data.
Diffstat (limited to 'src/libcustomindicator/custom-indicator.c')
-rw-r--r--src/libcustomindicator/custom-indicator.c57
1 files changed, 34 insertions, 23 deletions
diff --git a/src/libcustomindicator/custom-indicator.c b/src/libcustomindicator/custom-indicator.c
index b2d1384..8d6633a 100644
--- a/src/libcustomindicator/custom-indicator.c
+++ b/src/libcustomindicator/custom-indicator.c
@@ -38,6 +38,7 @@ struct _CustomIndicatorPrivate {
/* Fun stuff */
DBusGProxy * watcher_proxy;
+ DBusGConnection * connection;
};
/* Signals Stuff */
@@ -261,7 +262,6 @@ static void
custom_indicator_init (CustomIndicator *self)
{
CustomIndicatorPrivate * priv = CUSTOM_INDICATOR_GET_PRIVATE(self);
- g_return_if_fail(priv != NULL);
priv->id = NULL;
priv->category = CUSTOM_INDICATOR_CATEGORY_OTHER;
@@ -271,34 +271,21 @@ custom_indicator_init (CustomIndicator *self)
priv->menu = NULL;
priv->watcher_proxy = NULL;
+ priv->connection = NULL;
/* Put the object on DBus */
GError * error = NULL;
- DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ priv->connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
if (error != NULL) {
g_error("Unable to connect to the session bus when creating custom indicator: %s", error->message);
g_error_free(error);
return;
}
- dbus_g_connection_register_g_object(connection,
+ dbus_g_connection_register_g_object(priv->connection,
"/need/a/path",
G_OBJECT(self));
- priv->watcher_proxy = dbus_g_proxy_new_for_name_owner(connection,
- INDICATOR_CUSTOM_DBUS_ADDR,
- NOTIFICATION_WATCHER_DBUS_OBJ,
- NOTIFICATION_WATCHER_DBUS_IFACE,
- &error);
- if (error != NULL) {
- g_warning("Unable to create Ayatana Watcher proxy! %s", error->message);
- /* TODO: This is where we should start looking at fallbacks */
- g_error_free(error);
- return;
- }
-
- org_ayatana_indicator_custom_NotificationWatcher_register_service_async(priv->watcher_proxy, "/need/a/path", register_service_cb, self);
-
return;
}
@@ -311,7 +298,6 @@ custom_indicator_dispose (GObject *object)
g_return_if_fail(self != NULL);
CustomIndicatorPrivate * priv = CUSTOM_INDICATOR_GET_PRIVATE(self);
- g_return_if_fail(priv != NULL);
if (priv->status != CUSTOM_INDICATOR_STATUS_PASSIVE) {
custom_indicator_set_status(self, CUSTOM_INDICATOR_STATUS_PASSIVE);
@@ -323,8 +309,7 @@ custom_indicator_dispose (GObject *object)
}
if (priv->watcher_proxy != NULL) {
- DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
- dbus_g_connection_flush(session_bus);
+ dbus_g_connection_flush(priv->connection);
g_object_unref(G_OBJECT(priv->watcher_proxy));
priv->watcher_proxy = NULL;
}
@@ -342,7 +327,6 @@ custom_indicator_finalize (GObject *object)
g_return_if_fail(self != NULL);
CustomIndicatorPrivate * priv = CUSTOM_INDICATOR_GET_PRIVATE(self);
- g_return_if_fail(priv != NULL);
if (priv->status != CUSTOM_INDICATOR_STATUS_PASSIVE) {
g_warning("Finalizing Custom Status with the status set to: %d", priv->status);
@@ -377,7 +361,6 @@ custom_indicator_set_property (GObject * object, guint prop_id, const GValue * v
g_return_if_fail(self != NULL);
CustomIndicatorPrivate * priv = CUSTOM_INDICATOR_GET_PRIVATE(self);
- g_return_if_fail(priv != NULL);
switch (prop_id) {
/* *********************** */
@@ -443,6 +426,7 @@ custom_indicator_set_property (GObject * object, guint prop_id, const GValue * v
} else {
WARN_BAD_TYPE(PROP_ICON_NAME_S, value);
}
+ check_connect(self);
break;
/* *********************** */
case PROP_ATTENTION_ICON_NAME:
@@ -477,6 +461,7 @@ custom_indicator_set_property (GObject * object, guint prop_id, const GValue * v
} else {
WARN_BAD_TYPE(PROP_MENU_S, value);
}
+ check_connect(self);
break;
/* *********************** */
default:
@@ -495,7 +480,6 @@ custom_indicator_get_property (GObject * object, guint prop_id, GValue * value,
g_return_if_fail(self != NULL);
CustomIndicatorPrivate * priv = CUSTOM_INDICATOR_GET_PRIVATE(self);
- g_return_if_fail(priv != NULL);
switch (prop_id) {
/* *********************** */
@@ -611,16 +595,43 @@ custom_indicator_get_property (GObject * object, guint prop_id, GValue * value,
static void
check_connect (CustomIndicator * self)
{
+ CustomIndicatorPrivate * priv = CUSTOM_INDICATOR_GET_PRIVATE(self);
+
+ /* We're alreadying connecting or trying to connect. */
+ if (priv->watcher_proxy != NULL) return;
+ /* Do we have enough information? */
+ if (priv->menu == NULL) return;
+ if (priv->icon_name == NULL) return;
+ if (priv->id == NULL) return;
+ GError * error = NULL;
+ priv->watcher_proxy = dbus_g_proxy_new_for_name_owner(priv->connection,
+ INDICATOR_CUSTOM_DBUS_ADDR,
+ NOTIFICATION_WATCHER_DBUS_OBJ,
+ NOTIFICATION_WATCHER_DBUS_IFACE,
+ &error);
+ if (error != NULL) {
+ g_warning("Unable to create Ayatana Watcher proxy! %s", error->message);
+ /* TODO: This is where we should start looking at fallbacks */
+ g_error_free(error);
+ return;
+ }
+
+ org_ayatana_indicator_custom_NotificationWatcher_register_service_async(priv->watcher_proxy, "/need/a/path", register_service_cb, self);
+ return;
}
static void
register_service_cb (DBusGProxy * proxy, GError * error, gpointer data)
{
+ CustomIndicatorPrivate * priv = CUSTOM_INDICATOR_GET_PRIVATE(data);
+
if (error != NULL) {
g_warning("Unable to connect to the Notification Watcher: %s", error->message);
+ g_object_unref(G_OBJECT(priv->watcher_proxy));
+ priv->watcher_proxy = NULL;
}
return;
}