aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/empathy-account-manager.c164
-rw-r--r--libempathy/empathy-account.c46
-rw-r--r--libempathy/empathy-account.h2
-rw-r--r--libempathy/libempathy.pc.in4
4 files changed, 157 insertions, 59 deletions
diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c
index 75de6f193..5548a90e6 100644
--- a/libempathy/empathy-account-manager.c
+++ b/libempathy/empathy-account-manager.c
@@ -364,6 +364,76 @@ empathy_account_manager_ensure_account (EmpathyAccountManager *manager,
static void
+account_manager_ensure_all_accounts (EmpathyAccountManager *manager,
+ GPtrArray *accounts)
+{
+ int i, missing_accounts;
+ GHashTableIter iter;
+ EmpathyAccountManagerPriv *priv = GET_PRIV (manager);
+ gpointer value;
+ EmpathyAccount *account;
+ gboolean found = FALSE;
+ const gchar *name;
+
+ /* ensure all accounts coming from MC5 first */
+ for (i = 0; i < accounts->len; i++)
+ {
+ name = g_ptr_array_index (accounts, i);
+
+ account = empathy_account_manager_ensure_account (manager, name);
+ empathy_account_refresh_properties (account);
+ }
+
+ missing_accounts = empathy_account_manager_get_count (manager) -
+ accounts->len;
+
+ if (missing_accounts > 0)
+ {
+ /* look for accounts we have and the Tp AccountManager doesn't,
+ * and remove them from our cache.
+ */
+
+ DEBUG ("%d missing accounts", missing_accounts);
+
+ g_hash_table_iter_init (&iter, priv->accounts);
+
+ while (g_hash_table_iter_next (&iter, NULL, &value) &&
+ missing_accounts > 0)
+ {
+ account = value;
+
+ /* look for this account in the AccountManager provided array */
+ for (i = 0; i < accounts->len; i++)
+ {
+ name = g_ptr_array_index (accounts, i);
+
+ if (!tp_strdiff
+ (name, empathy_account_get_unique_name (account)))
+ {
+ found = TRUE;
+ break;
+ }
+ }
+
+ if (!found)
+ {
+ DEBUG ("Account %s was not found, remove it from the cache",
+ empathy_account_get_unique_name (account));
+
+ g_object_ref (account);
+ g_hash_table_iter_remove (&iter);
+ g_signal_emit (manager, signals[ACCOUNT_DELETED], 0, account);
+ g_object_unref (account);
+
+ missing_accounts--;
+ }
+
+ found = FALSE;
+ }
+ }
+}
+
+static void
account_manager_got_all_cb (TpProxy *proxy,
GHashTable *properties,
const GError *error,
@@ -372,7 +442,6 @@ account_manager_got_all_cb (TpProxy *proxy,
{
EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (weak_object);
GPtrArray *accounts;
- int i;
if (error != NULL)
{
@@ -384,14 +453,7 @@ account_manager_got_all_cb (TpProxy *proxy,
EMPATHY_ARRAY_TYPE_OBJECT);
if (accounts != NULL)
- {
- for (i = 0; i < accounts->len; i++)
- {
- gchar *name = g_ptr_array_index (accounts, i);
-
- empathy_account_manager_ensure_account (manager, name);
- }
- }
+ account_manager_ensure_all_accounts (manager, accounts);
empathy_account_manager_check_ready (manager);
}
@@ -412,6 +474,24 @@ account_validity_changed_cb (TpAccountManager *proxy,
}
static void
+account_manager_start_mc5 (TpDBusDaemon *bus)
+{
+ TpProxy *mc5_proxy;
+
+ /* trigger MC5 starting */
+ mc5_proxy = g_object_new (TP_TYPE_PROXY,
+ "dbus-daemon", bus,
+ "dbus-connection", tp_proxy_get_dbus_connection (TP_PROXY (bus)),
+ "bus-name", MC5_BUS_NAME,
+ "object-path", "/",
+ NULL);
+
+ tp_cli_dbus_peer_call_ping (mc5_proxy, -1, NULL, NULL, NULL, NULL);
+
+ g_object_unref (mc5_proxy);
+}
+
+static void
account_manager_name_owner_cb (TpDBusDaemon *proxy,
const gchar *name,
const gchar *new_owner,
@@ -420,32 +500,43 @@ account_manager_name_owner_cb (TpDBusDaemon *proxy,
EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (user_data);
EmpathyAccountManagerPriv *priv = GET_PRIV (manager);
- tp_dbus_daemon_cancel_name_owner_watch (proxy, name,
- account_manager_name_owner_cb, user_data);
+ DEBUG ("Name owner changed for %s, new name: %s", name, new_owner);
- priv->tp_manager = tp_account_manager_new (priv->dbus);
+ if (EMP_STR_EMPTY (new_owner))
+ {
+ /* MC5 quit or crashed for some reason, let's start it again */
+ account_manager_start_mc5 (priv->dbus);
- tp_cli_account_manager_connect_to_account_validity_changed (
- priv->tp_manager,
- account_validity_changed_cb,
- NULL,
- NULL,
- G_OBJECT (manager),
- NULL);
+ g_object_unref (priv->tp_manager);
+ priv->tp_manager = NULL;
+ return;
+ }
- tp_cli_dbus_properties_call_get_all (priv->tp_manager, -1,
- TP_IFACE_ACCOUNT_MANAGER,
- account_manager_got_all_cb,
- NULL,
- NULL,
- G_OBJECT (manager));
+ if (priv->tp_manager == NULL)
+ {
+ priv->tp_manager = tp_account_manager_new (priv->dbus);
+
+ tp_cli_account_manager_connect_to_account_validity_changed (
+ priv->tp_manager,
+ account_validity_changed_cb,
+ NULL,
+ NULL,
+ G_OBJECT (manager),
+ NULL);
+
+ tp_cli_dbus_properties_call_get_all (priv->tp_manager, -1,
+ TP_IFACE_ACCOUNT_MANAGER,
+ account_manager_got_all_cb,
+ NULL,
+ NULL,
+ G_OBJECT (manager));
+ }
}
static void
empathy_account_manager_init (EmpathyAccountManager *manager)
{
EmpathyAccountManagerPriv *priv;
- TpProxy *mc5_proxy;
priv = G_TYPE_INSTANCE_GET_PRIVATE (manager,
EMPATHY_TYPE_ACCOUNT_MANAGER, EmpathyAccountManagerPriv);
@@ -467,17 +558,7 @@ empathy_account_manager_init (EmpathyAccountManager *manager)
manager,
NULL);
- /* trigger MC5 starting */
- mc5_proxy = g_object_new (TP_TYPE_PROXY,
- "dbus-daemon", priv->dbus,
- "dbus-connection", tp_proxy_get_dbus_connection (TP_PROXY (priv->dbus)),
- "bus-name", MC5_BUS_NAME,
- "object-path", "/",
- NULL);
-
- tp_cli_dbus_peer_call_ping (mc5_proxy, -1, NULL, NULL, NULL, NULL);
-
- g_object_unref (mc5_proxy);
+ account_manager_start_mc5 (priv->dbus);
}
static void
@@ -547,9 +628,9 @@ do_constructor (GType type,
if (!manager_singleton)
{
- retval = G_OBJECT_CLASS (empathy_account_manager_parent_class)->constructor (type,
- n_construct_params,
- construct_params);
+ retval = G_OBJECT_CLASS
+ (empathy_account_manager_parent_class)->constructor (type,
+ n_construct_params, construct_params);
manager_singleton = EMPATHY_ACCOUNT_MANAGER (retval);
g_object_add_weak_pointer (retval, (gpointer) &manager_singleton);
}
@@ -715,7 +796,8 @@ empathy_account_manager_get_connected_accounts (EmpathyAccountManager *manager)
}
int
-empathy_account_manager_get_connecting_accounts (EmpathyAccountManager *manager)
+empathy_account_manager_get_connecting_accounts (
+ EmpathyAccountManager *manager)
{
EmpathyAccountManagerPriv *priv;
diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c
index b508f3952..0e4758baa 100644
--- a/libempathy/empathy-account.c
+++ b/libempathy/empathy-account.c
@@ -348,7 +348,7 @@ empathy_account_got_all_cb (TpProxy *proxy,
{
EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object);
- DEBUG ("Got initial set of properties for %s",
+ DEBUG ("Got whole set of properties for %s",
empathy_account_get_unique_name (account));
if (error != NULL)
@@ -475,12 +475,7 @@ empathy_account_constructed (GObject *object)
empathy_account_removed_cb,
NULL, NULL, object, NULL);
- tp_cli_dbus_properties_call_get_all (priv->account, -1,
- TP_IFACE_ACCOUNT,
- empathy_account_got_all_cb,
- NULL,
- NULL,
- G_OBJECT (account));
+ empathy_account_refresh_properties (account);
}
static void empathy_account_dispose (GObject *object);
@@ -957,17 +952,20 @@ empathy_account_set_enabled_async (EmpathyAccount *account,
return;
}
- acc_manager = empathy_account_manager_dup_singleton ();
- presence = empathy_account_manager_get_requested_global_presence
- (acc_manager, &status, &status_message);
+ if (enabled)
+ {
+ acc_manager = empathy_account_manager_dup_singleton ();
+ presence = empathy_account_manager_get_requested_global_presence
+ (acc_manager, &status, &status_message);
- if (presence != TP_CONNECTION_PRESENCE_TYPE_UNSET)
- empathy_account_request_presence (account, presence, status,
- status_message);
+ if (presence != TP_CONNECTION_PRESENCE_TYPE_UNSET)
+ empathy_account_request_presence (account, presence, status,
+ status_message);
- g_object_unref (acc_manager);
- g_free (status);
- g_free (status_message);
+ g_object_unref (acc_manager);
+ g_free (status);
+ g_free (status_message);
+ }
g_value_init (&value, G_TYPE_BOOLEAN);
g_value_set_boolean (&value, enabled);
@@ -1218,3 +1216,19 @@ empathy_account_remove_finish (EmpathyAccount *account,
return TRUE;
}
+void
+empathy_account_refresh_properties (EmpathyAccount *account)
+{
+ EmpathyAccountPriv *priv;
+
+ g_return_if_fail (EMPATHY_IS_ACCOUNT (account));
+
+ priv = GET_PRIV (account);
+
+ tp_cli_dbus_properties_call_get_all (priv->account, -1,
+ TP_IFACE_ACCOUNT,
+ empathy_account_got_all_cb,
+ NULL,
+ NULL,
+ G_OBJECT (account));
+}
diff --git a/libempathy/empathy-account.h b/libempathy/empathy-account.h
index 8a22335ea..e789ca702 100644
--- a/libempathy/empathy-account.h
+++ b/libempathy/empathy-account.h
@@ -110,6 +110,8 @@ void empathy_account_request_presence (EmpathyAccount *account,
const GHashTable *empathy_account_get_parameters (EmpathyAccount *account);
+void empathy_account_refresh_properties (EmpathyAccount *account);
+
G_END_DECLS
diff --git a/libempathy/libempathy.pc.in b/libempathy/libempathy.pc.in
index 6c1f81038..6dd89fd5a 100644
--- a/libempathy/libempathy.pc.in
+++ b/libempathy/libempathy.pc.in
@@ -6,8 +6,8 @@ includedir=@includedir@
Name: libempathy
Description: Empathy base library
Requires: pkg-config >= 0.21
-Requires.private: glib-2.0, gobject-2.0, libxml-2.0, libmissioncontrol, \
+Requires.private: glib-2.0, gobject-2.0, libxml-2.0, \
gio-2.0, gio-unix-2.0, telepathy-glib
Version: @VERSION@
Libs: -L${libdir} -lempathy
-Cflags: -I${includedir}
+Cflags: -I${includedir}