]> git.0d.be Git - empathy.git/commitdiff
status-icon: port to new tp-glib account API
authorJonny Lamb <jonnylamb@gnome.org>
Sat, 24 Oct 2009 15:02:52 +0000 (16:02 +0100)
committerJonny Lamb <jonnylamb@gnome.org>
Sat, 24 Oct 2009 15:02:52 +0000 (16:02 +0100)
Signed-off-by: Jonny Lamb <jonnylamb@gnome.org>
src/empathy-status-icon.c

index 3af060acf8b817f03c9c1ec382f65a979d300b8b..33c2da0311cee74dca0522792cdd4091e7603c35 100644 (file)
 #include <libnotify/notification.h>
 #include <libnotify/notify.h>
 
+#include <telepathy-glib/account-manager.h>
 #include <telepathy-glib/util.h>
 
 #include <libempathy/empathy-utils.h>
 #include <libempathy/empathy-idle.h>
-#include <libempathy/empathy-account-manager.h>
 
 #include <libempathy-gtk/empathy-presence-chooser.h>
 #include <libempathy-gtk/empathy-conf.h>
@@ -60,7 +60,7 @@
 typedef struct {
        GtkStatusIcon       *icon;
        EmpathyIdle         *idle;
-       EmpathyAccountManager *account_manager;
+       TpAccountManager    *account_manager;
        gboolean             showing_event_icon;
        guint                blink_timeout;
        EmpathyEventManager *event_manager;
@@ -506,20 +506,18 @@ status_icon_create_menu (EmpathyStatusIcon *icon)
 }
 
 static void
-status_icon_connection_changed_cb (EmpathyAccountManager *manager,
-                                  EmpathyAccount *account,
-                                  TpConnectionStatusReason reason,
-                                  TpConnectionStatus current,
-                                  TpConnectionStatus previous,
-                                  EmpathyStatusIcon *icon)
+status_icon_status_changed_cb (TpAccount *account,
+                              TpConnectionStatus current,
+                              TpConnectionStatus previous,
+                              TpConnectionStatusReason reason,
+                              gchar *dbus_error_name,
+                              GHashTable *details,
+                              EmpathyStatusIcon *icon)
 {
        EmpathyStatusIconPriv *priv = GET_PRIV (icon);
-       int connected_accounts;
 
-       /* Check for a connected account */
-       connected_accounts = empathy_account_manager_get_connected_accounts (manager);
-
-       gtk_action_set_sensitive (priv->new_message_item, connected_accounts > 0);
+       gtk_action_set_sensitive (priv->new_message_item,
+                                 empathy_account_manager_get_accounts_connected (NULL));
 }
 
 static void
@@ -531,10 +529,6 @@ status_icon_finalize (GObject *object)
                g_source_remove (priv->blink_timeout);
        }
 
-       g_signal_handlers_disconnect_by_func (priv->account_manager,
-                                             status_icon_connection_changed_cb,
-                                             object);
-
        if (priv->notification) {
                notify_notification_close (priv->notification, NULL);
                g_object_unref (priv->notification);
@@ -558,6 +552,28 @@ empathy_status_icon_class_init (EmpathyStatusIconClass *klass)
        g_type_class_add_private (object_class, sizeof (EmpathyStatusIconPriv));
 }
 
+static void
+account_manager_prepared_cb (GObject *source_object,
+                            GAsyncResult *result,
+                            gpointer user_data)
+{
+       GList *list, *l;
+       TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
+       EmpathyStatusIcon *icon = user_data;
+
+       if (!tp_account_manager_prepare_finish (account_manager, result, NULL)) {
+               return;
+       }
+
+       list = tp_account_manager_get_valid_accounts (account_manager);
+       for (l = list; l != NULL; l = l->next) {
+               empathy_signal_connect_weak (l->data, "status-changed",
+                                            G_CALLBACK (status_icon_status_changed_cb),
+                                            G_OBJECT (icon));
+       }
+       g_list_free (list);
+}
+
 static void
 empathy_status_icon_init (EmpathyStatusIcon *icon)
 {
@@ -567,13 +583,12 @@ empathy_status_icon_init (EmpathyStatusIcon *icon)
 
        icon->priv = priv;
        priv->icon = gtk_status_icon_new ();
-       priv->account_manager = empathy_account_manager_dup_singleton ();
+       priv->account_manager = tp_account_manager_dup ();
        priv->idle = empathy_idle_dup_singleton ();
        priv->event_manager = empathy_event_manager_dup_singleton ();
 
-       g_signal_connect (priv->account_manager,
-                         "account-connection-changed",
-                         G_CALLBACK (status_icon_connection_changed_cb), icon);
+       tp_account_manager_prepare_async (priv->account_manager, NULL,
+           account_manager_prepared_cb, icon);
 
        /* make icon listen and respond to MAIN_WINDOW_HIDDEN changes */
        empathy_conf_notify_add (empathy_conf_get (),