[empathy: 17/59] account-chooser: port to new tp-glib account API



commit 38d2cb938c3b91f6cbc89b825d720bdf35fb8e5f
Author: Jonny Lamb <jonnylamb gnome org>
Date:   Sat Oct 24 15:43:38 2009 +0100

    account-chooser: port to new tp-glib account API
    
    Signed-off-by: Jonny Lamb <jonnylamb gnome org>

 libempathy-gtk/empathy-account-chooser.c |  171 +++++++++++++++++-------------
 libempathy-gtk/empathy-account-chooser.h |   10 +-
 2 files changed, 102 insertions(+), 79 deletions(-)
---
diff --git a/libempathy-gtk/empathy-account-chooser.c b/libempathy-gtk/empathy-account-chooser.c
index a91b0eb..3e9b9a3 100644
--- a/libempathy-gtk/empathy-account-chooser.c
+++ b/libempathy-gtk/empathy-account-chooser.c
@@ -29,7 +29,8 @@
 #include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
 
-#include <libempathy/empathy-account-manager.h>
+#include <telepathy-glib/account-manager.h>
+
 #include <libempathy/empathy-utils.h>
 
 #include "empathy-ui-utils.h"
@@ -54,7 +55,7 @@
 
 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountChooser)
 typedef struct {
-	EmpathyAccountManager          *manager;
+	TpAccountManager               *manager;
 	gboolean                        set_active_item;
 	gboolean			account_manually_set;
 	gboolean                        has_all_option;
@@ -64,7 +65,7 @@ typedef struct {
 
 typedef struct {
 	EmpathyAccountChooser *chooser;
-	EmpathyAccount        *account;
+	TpAccount             *account;
 	gboolean               set;
 } SetAccountData;
 
@@ -86,24 +87,26 @@ static void     account_chooser_set_property           (GObject
 							const GValue             *value,
 							GParamSpec               *pspec);
 static void     account_chooser_setup                  (EmpathyAccountChooser    *chooser);
-static void     account_chooser_account_created_cb     (EmpathyAccountManager    *manager,
-							EmpathyAccount           *account,
+static void     account_chooser_account_validity_changed_cb (TpAccountManager    *manager,
+							TpAccount                *account,
+							gboolean                  valid,
 							EmpathyAccountChooser    *chooser);
-static void     account_chooser_account_add_foreach    (EmpathyAccount                *account,
+static void     account_chooser_account_add_foreach    (TpAccount                *account,
 							EmpathyAccountChooser    *chooser);
-static void     account_chooser_account_deleted_cb     (EmpathyAccountManager    *manager,
-							EmpathyAccount           *account,
+static void     account_chooser_account_removed_cb     (TpAccountManager         *manager,
+							TpAccount                *account,
 							EmpathyAccountChooser    *chooser);
-static void     account_chooser_account_remove_foreach (EmpathyAccount                *account,
+static void     account_chooser_account_remove_foreach (TpAccount                *account,
 							EmpathyAccountChooser    *chooser);
 static void     account_chooser_update_iter            (EmpathyAccountChooser    *chooser,
 							GtkTreeIter              *iter);
-static void     account_chooser_connection_changed_cb  (EmpathyAccountManager    *manager,
-							EmpathyAccount                *account,
-							TpConnectionStatusReason  reason,
-							TpConnectionStatus        new_status,
-							TpConnectionStatus        old_status,
-							EmpathyAccountChooser    *chooser);
+static void     account_chooser_status_changed_cb      (TpAccount  *account,
+							guint       old_status,
+							guint       new_status,
+							guint       reason,
+							gchar      *dbus_error_name,
+							GHashTable *details,
+							gpointer    user_data);
 static gboolean account_chooser_separator_func         (GtkTreeModel             *model,
 							GtkTreeIter              *iter,
 							EmpathyAccountChooser    *chooser);
@@ -156,16 +159,13 @@ empathy_account_chooser_init (EmpathyAccountChooser *chooser)
 	priv->filter = NULL;
 	priv->filter_data = NULL;
 
-	priv->manager = empathy_account_manager_dup_singleton ();
+	priv->manager = tp_account_manager_dup ();
 
-	g_signal_connect (priv->manager, "account-created",
-			  G_CALLBACK (account_chooser_account_created_cb),
+	g_signal_connect (priv->manager, "account-validity-changed",
+			  G_CALLBACK (account_chooser_account_validity_changed_cb),
 			  chooser);
-	g_signal_connect (priv->manager, "account-deleted",
-			  G_CALLBACK (account_chooser_account_deleted_cb),
-			  chooser);
-	g_signal_connect (priv->manager, "account-connection-changed",
-			  G_CALLBACK (account_chooser_connection_changed_cb),
+	g_signal_connect (priv->manager, "account-removed",
+			  G_CALLBACK (account_chooser_account_removed_cb),
 			  chooser);
 
 	account_chooser_setup (EMPATHY_ACCOUNT_CHOOSER (chooser));
@@ -177,13 +177,10 @@ account_chooser_finalize (GObject *object)
 	EmpathyAccountChooserPriv *priv = GET_PRIV (object);
 
 	g_signal_handlers_disconnect_by_func (priv->manager,
-					      account_chooser_connection_changed_cb,
+					      account_chooser_account_validity_changed_cb,
 					      object);
 	g_signal_handlers_disconnect_by_func (priv->manager,
-					      account_chooser_account_created_cb,
-					      object);
-	g_signal_handlers_disconnect_by_func (priv->manager,
-					      account_chooser_account_deleted_cb,
+					      account_chooser_account_removed_cb,
 					      object);
 	g_object_unref (priv->manager);
 
@@ -253,16 +250,16 @@ empathy_account_chooser_new (void)
  * @chooser: an #EmpathyAccountChooser
  *
  * Returns the account which is currently selected in the chooser or %NULL
- * if there is no account selected. The #EmpathyAccount returned should be
+ * if there is no account selected. The #TpAccount returned should be
  * unrefed with g_object_unref() when finished with.
  *
- * Return value: a new ref to the #EmpathyAccount currently selected, or %NULL.
+ * Return value: a new ref to the #TpAccount currently selected, or %NULL.
  */
-EmpathyAccount *
+TpAccount *
 empathy_account_chooser_dup_account (EmpathyAccountChooser *chooser)
 {
 	EmpathyAccountChooserPriv *priv;
-	EmpathyAccount           *account;
+	TpAccount                 *account;
 	GtkTreeModel             *model;
 	GtkTreeIter               iter;
 
@@ -295,7 +292,7 @@ TpConnection *
 empathy_account_chooser_get_connection (EmpathyAccountChooser *chooser)
 {
 	EmpathyAccountChooserPriv *priv;
-	EmpathyAccount            *account;
+	TpAccount                 *account;
 	TpConnection              *connection;
 
 	g_return_val_if_fail (EMPATHY_IS_ACCOUNT_CHOOSER (chooser), NULL);
@@ -303,7 +300,7 @@ empathy_account_chooser_get_connection (EmpathyAccountChooser *chooser)
 	priv = GET_PRIV (chooser);
 
 	account = empathy_account_chooser_dup_account (chooser);
-	connection = empathy_account_get_connection (account);
+	connection = tp_account_get_connection (account);
 	g_object_unref (account);
 
 	return connection;
@@ -312,7 +309,7 @@ empathy_account_chooser_get_connection (EmpathyAccountChooser *chooser)
 /**
  * empathy_account_chooser_set_account:
  * @chooser: an #EmpathyAccountChooser
- * @account: an #EmpathyAccount
+ * @account: a #TpAccount
  *
  * Sets the currently selected account to @account, if it exists in the list.
  *
@@ -320,7 +317,7 @@ empathy_account_chooser_get_connection (EmpathyAccountChooser *chooser)
  */
 gboolean
 empathy_account_chooser_set_account (EmpathyAccountChooser *chooser,
-				     EmpathyAccount *account)
+				     TpAccount             *account)
 {
 	EmpathyAccountChooserPriv *priv;
 	GtkComboBox    *combobox;
@@ -443,10 +440,37 @@ empathy_account_chooser_set_has_all_option (EmpathyAccountChooser *chooser,
 }
 
 static void
+account_manager_prepared_cb (GObject *source_object,
+			     GAsyncResult *result,
+			     gpointer user_data)
+{
+	GList *accounts, *l;
+	TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
+	EmpathyAccountChooser *chooser = user_data;
+
+	if (!tp_account_manager_prepare_finish (manager, result, NULL)) {
+		return;
+	}
+
+	accounts = tp_account_manager_get_valid_accounts (manager);
+
+	for (l = accounts; l != NULL; l = l->next) {
+		TpAccount *account = l->data;
+
+		account_chooser_account_add_foreach (account, chooser);
+
+		empathy_signal_connect_weak (account, "status-changed",
+					     G_CALLBACK (account_chooser_status_changed_cb),
+					     G_OBJECT (chooser));
+	}
+
+	g_list_free (accounts);
+}
+
+static void
 account_chooser_setup (EmpathyAccountChooser *chooser)
 {
 	EmpathyAccountChooserPriv *priv;
-	GList                    *accounts;
 	GtkListStore             *store;
 	GtkCellRenderer          *renderer;
 	GtkComboBox              *combobox;
@@ -462,7 +486,7 @@ account_chooser_setup (EmpathyAccountChooser *chooser)
 				    G_TYPE_STRING,    /* Image */
 				    G_TYPE_STRING,    /* Name */
 				    G_TYPE_BOOLEAN,   /* Enabled */
-				    EMPATHY_TYPE_ACCOUNT);
+				    TP_TYPE_ACCOUNT);
 
 	gtk_combo_box_set_model (combobox, GTK_TREE_MODEL (store));
 
@@ -482,25 +506,27 @@ account_chooser_setup (EmpathyAccountChooser *chooser)
 					NULL);
 
 	/* Populate accounts */
-	accounts = empathy_account_manager_dup_accounts (priv->manager);
-	g_list_foreach (accounts,
-			(GFunc) account_chooser_account_add_foreach,
-			chooser);
+	tp_account_manager_prepare_async (priv->manager, NULL,
+					  account_manager_prepared_cb, chooser);
 
-	g_list_free (accounts);
 	g_object_unref (store);
 }
 
 static void
-account_chooser_account_created_cb (EmpathyAccountManager *manager,
-				    EmpathyAccount        *account,
-				    EmpathyAccountChooser *chooser)
+account_chooser_account_validity_changed_cb (TpAccountManager      *manager,
+					     TpAccount             *account,
+					     gboolean               valid,
+					     EmpathyAccountChooser *chooser)
 {
-	account_chooser_account_add_foreach (account, chooser);
+	if (valid) {
+		account_chooser_account_add_foreach (account, chooser);
+	} else {
+		account_chooser_account_remove_foreach (account, chooser);
+	}
 }
 
 static void
-account_chooser_account_add_foreach (EmpathyAccount        *account,
+account_chooser_account_add_foreach (TpAccount             *account,
 				     EmpathyAccountChooser *chooser)
 {
 	GtkListStore *store;
@@ -516,20 +542,18 @@ account_chooser_account_add_foreach (EmpathyAccount        *account,
 					   COL_ACCOUNT_POINTER, account,
 					   -1);
 	account_chooser_update_iter (chooser, &iter);
-	/* We got a reffed account and it was reffed by the liststore as well */
-	g_object_unref (account);
 }
 
 static void
-account_chooser_account_deleted_cb (EmpathyAccountManager *manager,
-				    EmpathyAccount        *account,
+account_chooser_account_removed_cb (TpAccountManager      *manager,
+				    TpAccount             *account,
 				    EmpathyAccountChooser *chooser)
 {
 	account_chooser_account_remove_foreach (account, chooser);
 }
 
 typedef struct {
-	EmpathyAccount   *account;
+	TpAccount   *account;
 	GtkTreeIter *iter;
 	gboolean     found;
 } FindAccountData;
@@ -541,7 +565,7 @@ account_chooser_find_account_foreach (GtkTreeModel *model,
 				      gpointer      user_data)
 {
 	FindAccountData *data = user_data;
-	EmpathyAccount  *account;
+	TpAccount  *account;
 
 	gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1);
 
@@ -560,7 +584,7 @@ account_chooser_find_account_foreach (GtkTreeModel *model,
 
 static gboolean
 account_chooser_find_account (EmpathyAccountChooser *chooser,
-			      EmpathyAccount        *account,
+			      TpAccount             *account,
 			      GtkTreeIter           *iter)
 {
 	GtkListStore    *store;
@@ -580,7 +604,7 @@ account_chooser_find_account (EmpathyAccountChooser *chooser,
 }
 
 static void
-account_chooser_account_remove_foreach (EmpathyAccount        *account,
+account_chooser_account_remove_foreach (TpAccount             *account,
 					EmpathyAccountChooser *chooser)
 {
 	GtkListStore *store;
@@ -602,7 +626,7 @@ account_chooser_update_iter (EmpathyAccountChooser *chooser,
 	EmpathyAccountChooserPriv *priv;
 	GtkListStore              *store;
 	GtkComboBox               *combobox;
-	EmpathyAccount            *account;
+	TpAccount                 *account;
 	const gchar               *icon_name;
 	gboolean                   is_enabled = TRUE;
 
@@ -615,14 +639,14 @@ account_chooser_update_iter (EmpathyAccountChooser *chooser,
 			    COL_ACCOUNT_POINTER, &account,
 			    -1);
 
-	icon_name = empathy_account_get_icon_name (account);
+	icon_name = tp_account_get_icon_name (account);
 	if (priv->filter) {
 		is_enabled = priv->filter (account, priv->filter_data);
 	}
 
 	gtk_list_store_set (store, iter,
 			    COL_ACCOUNT_IMAGE, icon_name,
-			    COL_ACCOUNT_TEXT, empathy_account_get_display_name (account),
+			    COL_ACCOUNT_TEXT, tp_account_get_display_name (account),
 			    COL_ACCOUNT_ENABLED, is_enabled,
 			    -1);
 
@@ -637,13 +661,15 @@ account_chooser_update_iter (EmpathyAccountChooser *chooser,
 }
 
 static void
-account_chooser_connection_changed_cb (EmpathyAccountManager   *manager,
-				       EmpathyAccount          *account,
-				       TpConnectionStatusReason reason,
-				       TpConnectionStatus       new_status,
-				       TpConnectionStatus       old_status,
-				       EmpathyAccountChooser   *chooser)
+account_chooser_status_changed_cb (TpAccount  *account,
+				   guint       old_status,
+				   guint       new_status,
+				   guint       reason,
+				   gchar      *dbus_error_name,
+				   GHashTable *details,
+				   gpointer    user_data)
 {
+	EmpathyAccountChooser *chooser = user_data;
 	GtkTreeIter iter;
 
 	if (account_chooser_find_account (chooser, account, &iter)) {
@@ -679,7 +705,7 @@ account_chooser_set_account_foreach (GtkTreeModel   *model,
 				     GtkTreeIter    *iter,
 				     SetAccountData *data)
 {
-	EmpathyAccount *account;
+	TpAccount *account;
 	gboolean   equal;
 
 	gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1);
@@ -750,7 +776,7 @@ empathy_account_chooser_set_filter (EmpathyAccountChooser           *chooser,
 
 /**
  * EmpathyAccountChooserFilterFunc:
- * @account: an #EmpathyAccount
+ * @account: a #TpAccount
  * @user_data: user data, or %NULL
  *
  * A function which decides whether the account indicated by @account
@@ -761,7 +787,7 @@ empathy_account_chooser_set_filter (EmpathyAccountChooser           *chooser,
 
 /**
  * empathy_account_chooser_filter_is_connected:
- * @account: an #EmpathyAccount
+ * @account: a #TpAccount
  * @user_data: user data or %NULL
  *
  * A useful #EmpathyAccountChooserFilterFunc that one could pass into
@@ -770,13 +796,10 @@ empathy_account_chooser_set_filter (EmpathyAccountChooser           *chooser,
  * Return value: Whether @account is connected
  */
 gboolean
-empathy_account_chooser_filter_is_connected (EmpathyAccount *account,
+empathy_account_chooser_filter_is_connected (TpAccount *account,
 					     gpointer   user_data)
 {
-	TpConnectionStatus  status;
-
-	g_object_get (account, "connection-status", &status, NULL);
-
-	return status == TP_CONNECTION_STATUS_CONNECTED;
+	return (tp_account_get_connection_status (account, NULL)
+	    == TP_CONNECTION_STATUS_CONNECTED);
 }
 
diff --git a/libempathy-gtk/empathy-account-chooser.h b/libempathy-gtk/empathy-account-chooser.h
index 255b684..075bea8 100644
--- a/libempathy-gtk/empathy-account-chooser.h
+++ b/libempathy-gtk/empathy-account-chooser.h
@@ -27,7 +27,7 @@
 
 #include <gtk/gtk.h>
 
-#include <libempathy/empathy-account.h>
+#include <telepathy-glib/account.h>
 
 G_BEGIN_DECLS
 
@@ -38,7 +38,7 @@ G_BEGIN_DECLS
 #define EMPATHY_IS_ACCOUNT_CHOOSER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_ACCOUNT_CHOOSER))
 #define EMPATHY_ACCOUNT_CHOOSER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_ACCOUNT_CHOOSER, EmpathyAccountChooserClass))
 
-typedef gboolean (* EmpathyAccountChooserFilterFunc) (EmpathyAccount *account,
+typedef gboolean (* EmpathyAccountChooserFilterFunc) (TpAccount *account,
 						      gpointer   user_data);
 
 
@@ -58,17 +58,17 @@ struct _EmpathyAccountChooserClass {
 
 GType          empathy_account_chooser_get_type           (void) G_GNUC_CONST;
 GtkWidget *    empathy_account_chooser_new                (void);
-EmpathyAccount *    empathy_account_chooser_dup_account        (EmpathyAccountChooser *chooser);
+TpAccount *    empathy_account_chooser_dup_account        (EmpathyAccountChooser *chooser);
 TpConnection * empathy_account_chooser_get_connection     (EmpathyAccountChooser *chooser);
 gboolean       empathy_account_chooser_set_account        (EmpathyAccountChooser *chooser,
-							   EmpathyAccount        *account);
+							   TpAccount             *account);
 gboolean       empathy_account_chooser_get_has_all_option (EmpathyAccountChooser *chooser);
 void           empathy_account_chooser_set_has_all_option (EmpathyAccountChooser *chooser,
 							   gboolean               has_all_option);
 void           empathy_account_chooser_set_filter         (EmpathyAccountChooser *chooser,
 							   EmpathyAccountChooserFilterFunc filter,
 							   gpointer               user_data);
-gboolean       empathy_account_chooser_filter_is_connected (EmpathyAccount       *account,
+gboolean       empathy_account_chooser_filter_is_connected (TpAccount            *account,
 							   gpointer               user_data);
 
 G_END_DECLS



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]