=== modified file 'src/indicator-approver.c'
--- src/indicator-approver.c 2013-02-20 01:16:27 +0000
+++ src/indicator-approver.c 2013-02-20 01:16:27 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright(C) 2011 Canonical Ltd.
+ * Copyright(C) 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
- * Authored by Ken VaDine
+ * Authored by Ken VanDine
*/
#include
@@ -36,6 +36,8 @@
static gint n_sources;
UnityLauncherEntry *launcher = NULL;
GList *conns;
+TpBaseClient *approver;
+TpBaseClient *observer;
static void update_launcher (gint count)
{
@@ -835,8 +837,6 @@
static TpBaseClient *
approver_setup (TpAccountManager *tp_am, GError **error)
{
- TpBaseClient *approver;
-
g_return_val_if_fail (TP_IS_ACCOUNT_MANAGER (tp_am), NULL);
approver = tp_simple_approver_new_with_am (tp_am, "IndicatorApprover",
@@ -856,8 +856,7 @@
if (!tp_base_client_register (approver, error))
{
- g_object_unref (tp_am);
- g_object_unref (approver);
+ g_clear_object (&approver);
return NULL;
}
return approver;
@@ -866,8 +865,6 @@
static TpBaseClient *
observer_setup (TpAccountManager *tp_am, GError **error)
{
- TpBaseClient *observer;
-
g_return_val_if_fail (TP_IS_ACCOUNT_MANAGER (tp_am), NULL);
observer = tp_simple_observer_new_with_am (tp_am, TRUE, "IndicatorObserver",
@@ -881,8 +878,7 @@
if (!tp_base_client_register (observer, error))
{
- g_object_unref (tp_am);
- g_object_unref (observer);
+ g_clear_object (&observer);
return NULL;
}
return observer;
@@ -1014,34 +1010,48 @@
}
}
-
-int setup ()
+static void
+empathy_appeared (GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner,
+ gpointer user_data)
{
+ GMainLoop *loop = user_data;
+ TpAccountManager *tp_am;
+ TpBaseClient *approver;
+ TpBaseClient *observer;
TpConnectionPresenceType presence;
GError *error = NULL;
- TpBaseClient *approver;
- TpBaseClient *observer;
+ g_debug (G_STRFUNC);
- TpAccountManager *tp_am = tp_account_manager_dup ();
+ tp_am = tp_account_manager_dup ();
approver = approver_setup (tp_am, &error);
if (approver == NULL)
{
g_warning ("Failed to register the approver: %s", error->message);
g_error_free (error);
- return 1;
+ g_object_unref (tp_am);
+ g_main_loop_quit (loop);
+ return;
}
+
observer = observer_setup (tp_am, &error);
if (observer == NULL)
{
g_warning ("Failed to register the observer: %s", error->message);
g_error_free (error);
- return 1;
+ g_object_unref (tp_am);
+ g_main_loop_quit (loop);
+ return;
}
mmapp = messaging_menu_app_new ("empathy.desktop");
+ if (check_enabled_accounts ())
+ messaging_menu_app_register (mmapp);
+
g_signal_connect (mmapp, "activate-source",
G_CALLBACK (message_source_activated), tp_am);
g_signal_connect (mmapp, "status-changed",
@@ -1064,9 +1074,22 @@
contact_list_setup (tp_am);
- return 0;
-}
-
+ g_object_unref (tp_am);
+}
+
+static void
+empathy_vanished (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ g_debug (G_STRFUNC);
+
+ g_clear_object (&approver);
+ g_clear_object (&observer);
+ g_clear_object (&launcher);
+ g_clear_pointer (&dispatch_ops, g_hash_table_unref);
+ g_clear_object (&mmapp);
+}
int
main (int argc, char **argv)
@@ -1077,14 +1100,12 @@
loop = g_main_loop_new (NULL, FALSE);
- ret = setup ();
- if (ret == 1)
- return ret;
-
- if (check_enabled_accounts ())
- {
- messaging_menu_app_register (mmapp);
- }
+ g_bus_watch_name (G_BUS_TYPE_SESSION,
+ "org.gnome.Empathy",
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ empathy_appeared,
+ empathy_vanished,
+ loop, NULL);
g_debug ("Telepathy Indicator started");
g_main_loop_run (loop);