]> git.0d.be Git - empathy.git/commitdiff
Add removed signal on EmpathyAccount
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>
Tue, 21 Jul 2009 18:02:37 +0000 (19:02 +0100)
committerSjoerd Simons <sjoerd.simons@collabora.co.uk>
Tue, 21 Jul 2009 18:02:37 +0000 (19:02 +0100)
libempathy/empathy-account-manager.c
libempathy/empathy-account.c

index 5d1363fcecc692ab397aeef848c26317806a6d84..7339acb9f80353b472beb2b5265ff55b0ca03b41 100644 (file)
@@ -220,6 +220,20 @@ signal:
       priv->global_presence, priv->global_status, priv->global_status_message);
 }
 
+static void
+emp_account_removed_cb (EmpathyAccount *account, gpointer user_data)
+{
+  EmpathyAccountManager *manager = EMPATHY_ACCOUNT_MANAGER (user_data);
+  EmpathyAccountManagerPriv *priv = GET_PRIV (manager);
+
+  g_object_ref (account);
+  g_hash_table_remove (priv->accounts,
+    empathy_account_get_unique_name (account));
+
+  g_signal_emit (manager, signals[ACCOUNT_DELETED], 0, account);
+  g_object_unref (account);
+}
+
 static void
 empathy_account_manager_check_ready (EmpathyAccountManager *manager)
 {
@@ -272,6 +286,9 @@ emp_account_ready_cb (GObject *obj, GParamSpec *spec, gpointer user_data)
   g_signal_connect (account, "presence-changed",
     G_CALLBACK (emp_account_presence_changed_cb), manager);
 
+  g_signal_connect (account, "removed",
+    G_CALLBACK (emp_account_removed_cb), manager);
+
   empathy_account_manager_check_ready (manager);
 }
 
index 5727a8a2554c5d405caf067a1e74f1e78e171ff4..51dd26316b435e788607092294a558a952eba161 100644 (file)
@@ -42,6 +42,7 @@
 enum {
   STATUS_CHANGED,
   PRESENCE_CHANGED,
+  REMOVED,
   LAST_SIGNAL
 };
 
@@ -84,6 +85,7 @@ struct _EmpathyAccountPriv
   gboolean enabled;
   gboolean valid;
   gboolean ready;
+  gboolean removed;
   /* Timestamp when the connection got connected in seconds since the epoch */
   glong connect_time;
 
@@ -324,6 +326,22 @@ empathy_account_properties_changed (TpAccount *proxy,
   empathy_account_update (account, properties);
 }
 
+static void
+empathy_account_removed_cb (TpAccount *proxy,
+    gpointer user_data,
+    GObject *weak_object)
+{
+  EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object);
+  EmpathyAccountPriv *priv = GET_PRIV (account);
+
+  if (priv->removed)
+    return;
+
+  priv->removed = TRUE;
+
+  g_signal_emit (account, signals[REMOVED], 0);
+}
+
 static void
 empathy_account_got_all_cb (TpProxy *proxy,
     GHashTable *properties,
@@ -420,6 +438,21 @@ empathy_account_parse_unique_name (const gchar *bus_name,
   return TRUE;
 }
 
+static void
+account_invalidated_cb (TpProxy *proxy, guint domain, gint code,
+  gchar *message, gpointer user_data)
+{
+  EmpathyAccount *account = EMPATHY_ACCOUNT (user_data);
+  EmpathyAccountPriv *priv = GET_PRIV (account);
+
+  if (priv->removed)
+    return;
+
+  priv->removed = TRUE;
+
+  g_signal_emit (account, signals[REMOVED], 0);
+}
+
 static void
 empathy_account_constructed (GObject *object)
 {
@@ -428,6 +461,9 @@ empathy_account_constructed (GObject *object)
 
   priv->account = tp_account_new (priv->dbus, priv->unique_name, NULL);
 
+  g_signal_connect (priv->account, "invalidated",
+    G_CALLBACK (account_invalidated_cb), object);
+
   empathy_account_parse_unique_name (priv->unique_name,
     &(priv->proto_name), &(priv->cm_name));
 
@@ -437,6 +473,10 @@ empathy_account_constructed (GObject *object)
     empathy_account_properties_changed,
     NULL, NULL, object, NULL);
 
+  tp_cli_account_connect_to_removed (priv->account,
+    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,
@@ -558,6 +598,13 @@ empathy_account_class_init (EmpathyAccountClass *empathy_account_class)
     0, NULL, NULL,
     _empathy_marshal_VOID__UINT_STRING_STRING,
     G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
+
+  signals[REMOVED] = g_signal_new ("removed",
+    G_TYPE_FROM_CLASS (object_class),
+    G_SIGNAL_RUN_LAST,
+    0, NULL, NULL,
+    g_cclosure_marshal_VOID__VOID,
+    G_TYPE_NONE, 0);
 }
 
 void