empathy r2042 - trunk/libempathy



Author: xclaesse
Date: Tue Jan  6 16:46:53 2009
New Revision: 2042
URL: http://svn.gnome.org/viewvc/empathy?rev=2042&view=rev

Log:
Add new API in EmpathyAccountManager to cache the number of connecting
and connected accounts.

Modified:
   trunk/libempathy/empathy-account-manager.c
   trunk/libempathy/empathy-account-manager.h

Modified: trunk/libempathy/empathy-account-manager.c
==============================================================================
--- trunk/libempathy/empathy-account-manager.c	(original)
+++ trunk/libempathy/empathy-account-manager.c	Tue Jan  6 16:46:53 2009
@@ -31,9 +31,11 @@
 
 typedef struct {
 	McAccountMonitor *monitor;
-	MissionControl *mc;
+	MissionControl   *mc;
 
-	GHashTable *accounts;
+	GHashTable       *accounts;
+	int               connected;
+	int               connecting;
 } EmpathyAccountManagerPriv;
 
 typedef struct {
@@ -89,7 +91,7 @@
 	actual_c = mission_control_get_connection_status (mc,
 							  account, &err);
 	if (err) {
-		actual_c = -1;
+		actual_c = TP_CONNECTION_STATUS_DISCONNECTED;
 	}
 
 	return account_data_new (actual_p, actual_c, mc_account_is_enabled (account));
@@ -197,6 +199,37 @@
 }
 
 static void
+update_connection_numbers (EmpathyAccountManager *manager,
+			   TpConnectionStatus conn,
+			   TpConnectionStatus old_c)
+{
+	EmpathyAccountManagerPriv *priv = GET_PRIV (manager);
+
+	if (conn == TP_CONNECTION_STATUS_CONNECTED) {
+		priv->connected++;
+		if (old_c == TP_CONNECTION_STATUS_CONNECTING) {
+			priv->connecting--;
+		}
+	}
+
+	if (conn == TP_CONNECTION_STATUS_CONNECTING) {
+		priv->connecting++;
+		if (old_c == TP_CONNECTION_STATUS_CONNECTED) {
+			priv->connected--;
+		}
+	}
+
+	if (conn == TP_CONNECTION_STATUS_DISCONNECTED) {
+		if (old_c == TP_CONNECTION_STATUS_CONNECTED) {
+			priv->connected--;
+		}
+		if (old_c == TP_CONNECTION_STATUS_CONNECTING) {
+			priv->connecting--;
+		}
+	}
+}
+
+static void
 account_status_changed_cb (MissionControl *mc,
 			   TpConnectionStatus connection,
 			   McPresence presence,
@@ -227,6 +260,8 @@
 
 		if (old_c != connection) {
 			data->connection = connection;
+			update_connection_numbers (manager, connection, old_c);
+
 			g_signal_emit (manager, signals[ACCOUNT_CONNECTION_CHANGED], 0,
 				       account, reason, connection, old_c);
 		}
@@ -247,6 +282,7 @@
 	manager->priv = priv;
 	priv->monitor = mc_account_monitor_new ();
 	priv->mc = empathy_mission_control_new ();
+	priv->connected = priv->connecting = 0;
 
 	priv->accounts = g_hash_table_new_full (empathy_account_hash,
 						empathy_account_equal,
@@ -383,6 +419,8 @@
 	g_type_class_add_private (oclass, sizeof (EmpathyAccountManagerPriv));
 }
 
+/* public methods */
+
 EmpathyAccountManager *
 empathy_account_manager_new (void)
 {
@@ -394,4 +432,29 @@
 	}
 
 	return manager;
-}
\ No newline at end of file
+}
+
+int
+empathy_account_manager_get_connected_accounts (EmpathyAccountManager *manager)
+{
+	EmpathyAccountManagerPriv *priv;
+
+	g_assert (EMPATHY_IS_ACCOUNT_MANAGER (manager));
+
+	priv = GET_PRIV (manager);
+
+	return priv->connected;
+}
+
+int
+empathy_account_manager_get_connecting_accounts (EmpathyAccountManager *manager)
+{
+	EmpathyAccountManagerPriv *priv;
+
+	g_assert (EMPATHY_IS_ACCOUNT_MANAGER (manager));
+
+	priv = GET_PRIV (manager);
+
+	return priv->connecting;
+}
+

Modified: trunk/libempathy/empathy-account-manager.h
==============================================================================
--- trunk/libempathy/empathy-account-manager.h	(original)
+++ trunk/libempathy/empathy-account-manager.h	Tue Jan  6 16:46:53 2009
@@ -46,8 +46,15 @@
 };
 
 GType empathy_account_manager_get_type (void);
-EmpathyAccountManager * empathy_account_manager_new (void);
 
+/* public methods */
+
+EmpathyAccountManager * empathy_account_manager_new (void);
+int                     empathy_account_manager_get_connected_accounts 
+				(EmpathyAccountManager *manager);
+int                     empathy_account_manager_get_connecting_accounts
+				(EmpathyAccountManager *manager);
 G_END_DECLS
 
-#endif /* __EMPATHY_ACCOUNT_MANAGER_H__ */
\ No newline at end of file
+#endif /* __EMPATHY_ACCOUNT_MANAGER_H__ */
+



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