changeset 13014:5efbb0162f86

[gaim-migrate @ 15367] I don't expect any of this to be controversial. * Some comment and other small changes. * Changed gtkconn.c to store the list of errored accounts in a hash table instead of a glist * Added init and uninit functions to gtkconn.c. They're used to create and destroy the two hash tables used within that file. * Also use the new init and uninit functions to connect to the account deleted signal so that we clear out the old error message if we delete an account that had an error while connecting. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 23 Jan 2006 06:54:29 +0000
parents 8fe78402c010
children 2d71d4081e06
files src/gtkaccount.c src/gtkconn.c src/gtkconn.h src/gtkmain.c src/gtksavedstatuses.c src/gtksavedstatuses.h
diffstat 6 files changed, 156 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkaccount.c	Mon Jan 23 05:50:32 2006 +0000
+++ b/src/gtkaccount.c	Mon Jan 23 06:54:29 2006 +0000
@@ -2652,7 +2652,7 @@
 }
 
 void *
-gaim_gtk_account_get_handle() {
+gaim_gtk_account_get_handle(void) {
 	static int handle;
 
 	return &handle;
--- a/src/gtkconn.c	Mon Jan 23 05:50:32 2006 +0000
+++ b/src/gtkconn.c	Mon Jan 23 06:54:29 2006 +0000
@@ -45,13 +45,16 @@
 	guint timeout;
 } GaimAutoRecon;
 
-static GHashTable *hash = NULL;
-/*
- * TODO: Remove an account from this list if the account is deleted.
+/**
+ * Contains accounts that are auto-reconnecting.
+ * The key is a pointer to the GaimAccount and the
+ * value is a pointer to a GaimAutoRecon.
  */
-static GSList *errored_accounts = NULL;
+static GHashTable *hash = NULL;
+static GHashTable *errored_accounts = NULL;
 
-static void gaim_gtk_connection_connect_progress(GaimConnection *gc,
+static void
+gaim_gtk_connection_connect_progress(GaimConnection *gc,
 		const char *text, size_t step, size_t step_count)
 {
 	GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist();
@@ -62,26 +65,32 @@
 	gtk_gaim_status_box_pulse_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox));
 }
 
-static void gaim_gtk_connection_connected(GaimConnection *gc)
+static void
+gaim_gtk_connection_connected(GaimConnection *gc)
 {
-	GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist();
-	GaimAccount *account = NULL;
-	if (!gtkblist)
-		return;
-	gtk_gaim_status_box_set_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox),
+	GaimAccount *account;
+	GaimGtkBuddyList *gtkblist;
+
+	account  = gaim_connection_get_account(gc);
+	gtkblist = gaim_gtk_blist_get_default_gtk_blist();
+
+	if (gtkblist != NULL)
+		gtk_gaim_status_box_set_connecting(GTK_GAIM_STATUS_BOX(gtkblist->statusbox),
 					   (gaim_connections_get_connecting() != NULL));
-	account = gaim_connection_get_account(gc);
 
 	if (hash != NULL)
 		g_hash_table_remove(hash, account);
-	if (errored_accounts == NULL)
-		return;
-	errored_accounts = g_slist_remove(errored_accounts, account);
-	if (errored_accounts == NULL)
-		gtk_gaim_status_box_set_error(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), NULL);
+
+	if (g_hash_table_size(errored_accounts) > 0)
+	{
+		g_hash_table_remove(errored_accounts, account);
+		if (g_hash_table_size(errored_accounts) == 0)
+			gtk_gaim_status_box_set_error(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), NULL);
+	}
 }
 
-static void gaim_gtk_connection_disconnected(GaimConnection *gc)
+static void
+gaim_gtk_connection_disconnected(GaimConnection *gc)
 {
 	GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist();
 	if (!gtkblist)
@@ -95,7 +104,8 @@
 	gaim_gtkdialogs_destroy_all();
 }
 
-static void gaim_gtk_connection_notice(GaimConnection *gc,
+static void
+gaim_gtk_connection_notice(GaimConnection *gc,
 		const char *text)
 {
 }
@@ -118,40 +128,31 @@
 	GaimAccount *account = data;
 	GaimAutoRecon *info;
 
-	gaim_debug(GAIM_DEBUG_INFO, "autorecon", "do_signon called\n");
+	gaim_debug_info("autorecon", "do_signon called\n");
 	g_return_val_if_fail(account != NULL, FALSE);
 	info = g_hash_table_lookup(hash, account);
 
-	if (g_list_index(gaim_accounts_get_all(), account) < 0)
-		return FALSE;
-
 	if (info)
 		info->timeout = 0;
 
-	gaim_debug(GAIM_DEBUG_INFO, "autorecon", "calling gaim_account_connect\n");
+	gaim_debug_info("autorecon", "calling gaim_account_connect\n");
 	gaim_account_connect(account);
-	gaim_debug(GAIM_DEBUG_INFO, "autorecon", "done calling gaim_account_connect\n");
+	gaim_debug_info("autorecon", "done calling gaim_account_connect\n");
 
 	return FALSE;
 }
 
-static void gaim_gtk_connection_report_disconnect(GaimConnection *gc, const char *text)
+static void
+gaim_gtk_connection_report_disconnect(GaimConnection *gc, const char *text)
 {
 	GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist();
 	GaimAccount *account = NULL;
 	GaimAutoRecon *info;
 	GSList* errored_account;
 
-	if (hash == NULL) {
-		hash = g_hash_table_new_full(g_int_hash, g_int_equal, NULL,
-		free_auto_recon);
-	}
 	account = gaim_connection_get_account(gc);
 	info = g_hash_table_lookup(hash, account);
-	if (errored_accounts)
-		errored_account = g_slist_find(errored_accounts, account);
-	else
-		errored_account = NULL;
+	errored_account = g_hash_table_lookup(errored_accounts, account);
 
 	if (!gc->wants_to_die) {
 		if (gtkblist != NULL)
@@ -168,37 +169,43 @@
 		}
 		info->timeout = g_timeout_add(info->delay, do_signon, account);
 
-		if (!errored_account)
-			errored_accounts = g_slist_prepend(errored_accounts, account);
+		g_hash_table_insert(errored_accounts, account, NULL);
 	} else {
-	  char *p, *s, *n=NULL ;
-	  if (info != NULL)
-	    g_hash_table_remove(hash, account);
+		char *p, *s, *n=NULL ;
+		if (info != NULL)
+			g_hash_table_remove(hash, account);
 
-	  if (errored_account)
-	      errored_accounts = g_slist_delete_link(errored_accounts, errored_account);
+		if (errored_account != NULL)
+			g_hash_table_remove(errored_accounts, errored_account);
 
-	  if (gaim_account_get_alias(account)) {
-	    n = g_strdup_printf("%s (%s) (%s)",
-				  gaim_account_get_username(account),
-				  gaim_account_get_alias(account),
-				  gaim_account_get_protocol_name(account));
-	    } else {
-	      n = g_strdup_printf("%s (%s)",
-				  gaim_account_get_username(account),
-				  gaim_account_get_protocol_name(account));
-	    }
+		if (gaim_account_get_alias(account))
+		{
+			n = g_strdup_printf("%s (%s) (%s)",
+					gaim_account_get_username(account),
+					gaim_account_get_alias(account),
+					gaim_account_get_protocol_name(account));
+		}
+		else
+		{
+			n = g_strdup_printf("%s (%s)",
+					gaim_account_get_username(account),
+					gaim_account_get_protocol_name(account));
+		}
 
-	    p = g_strdup_printf(_("%s disconnected"), n);
-	    s = g_strdup_printf(_("%s was disconnected due to an error. %s The account has been disabled. "
-				  "Correct the error and reenable the account to connect."), n, text);
-	    gaim_notify_error(NULL, NULL, p, s);
-	    g_free(p);
-	    g_free(s);
-	    g_free(n);
-		/* XXX: do we really want to disable the account when it's disconnected by wants_to_die?
-		 *      This normally happens when you sign on from somewhere else. */
-	    gaim_account_set_enabled(account, GAIM_GTK_UI, FALSE);
+		p = g_strdup_printf(_("%s disconnected"), n);
+		s = g_strdup_printf(_("%s was disconnected due to an error. %s The account has been disabled. "
+				"Correct the error and reenable the account to connect."), n, text);
+		gaim_notify_error(NULL, NULL, p, s);
+		g_free(p);
+		g_free(s);
+		g_free(n);
+
+		/*
+		 * TODO: Do we really want to disable the account when it's
+		 * disconnected by wants_to_die?  This happens when you sign
+		 * on from somewhere else, or when you enter an invalid password.
+		 */
+		gaim_account_set_enabled(account, GAIM_GTK_UI, FALSE);
 	}
 }
 
@@ -216,3 +223,59 @@
 {
 	return &conn_ui_ops;
 }
+
+static void
+account_removed_cb(GaimAccount *account, gpointer user_data)
+{
+	g_hash_table_remove(hash, account);
+
+	if (g_hash_table_size(errored_accounts) > 0)
+	{
+		g_hash_table_remove(errored_accounts, account);
+		if (g_hash_table_size(errored_accounts) == 0)
+		{
+			GaimGtkBuddyList *gtkblist;
+
+			gtkblist = gaim_gtk_blist_get_default_gtk_blist();
+			if (gtkblist != NULL)
+				gtk_gaim_status_box_set_error(GTK_GAIM_STATUS_BOX(gtkblist->statusbox), NULL);
+		}
+	}
+}
+
+
+/**************************************************************************
+* GTK+ connection glue
+**************************************************************************/
+
+void *
+gaim_gtk_connection_get_handle(void)
+{
+	static int handle;
+
+	return &handle;
+}
+
+void
+gaim_gtk_connection_init(void)
+{
+	hash = g_hash_table_new_full(
+							g_direct_hash, g_direct_equal,
+							NULL, free_auto_recon);
+	errored_accounts = g_hash_table_new_full(
+							g_direct_hash, g_direct_equal,
+							NULL, NULL);
+
+	gaim_signal_connect(gaim_accounts_get_handle(), "account-removed",
+						gaim_gtk_connection_get_handle(),
+						GAIM_CALLBACK(account_removed_cb), NULL);
+}
+
+void
+gaim_gtk_connection_uninit(void)
+{
+	gaim_signals_disconnect_by_handle(gaim_gtk_connection_get_handle());
+
+	g_hash_table_destroy(hash);
+	g_hash_table_destroy(errored_accounts);
+}
--- a/src/gtkconn.h	Mon Jan 23 05:50:32 2006 +0000
+++ b/src/gtkconn.h	Mon Jan 23 06:54:29 2006 +0000
@@ -38,4 +38,21 @@
 
 /*@}*/
 
+/**
+ * Returns the GTK+ connection handle.
+ *
+ * @return The handle to the GTK+ connection system.
+ */
+void *gaim_gtk_connection_get_handle(void);
+
+/**
+ * Initializes the GTK+ connection system.
+ */
+void gaim_gtk_connection_init(void);
+
+/**
+ * Uninitializes the GTK+ connection system.
+ */
+void gaim_gtk_connection_uninit(void);
+
 #endif /* _GAIM_GTKCONN_H_ */
--- a/src/gtkmain.c	Mon Jan 23 05:50:32 2006 +0000
+++ b/src/gtkmain.c	Mon Jan 23 06:54:29 2006 +0000
@@ -251,6 +251,7 @@
 	gaim_gtk_stock_init();
 	gaim_gtk_prefs_init();
 	gaim_gtk_account_init();
+	gaim_gtk_connection_init();
 	gaim_gtk_blist_init();
 	gaim_gtk_status_init();
 	gaim_gtk_conversations_init();
@@ -279,6 +280,7 @@
 	gaim_gtk_conversations_uninit();
 	gaim_gtk_status_uninit();
 	gaim_gtk_blist_uninit();
+	gaim_gtk_connection_uninit();
 	gaim_gtk_account_uninit();
 	gaim_gtk_xfers_uninit();
 	gaim_gtk_debug_uninit();
--- a/src/gtksavedstatuses.c	Mon Jan 23 05:50:32 2006 +0000
+++ b/src/gtksavedstatuses.c	Mon Jan 23 06:54:29 2006 +0000
@@ -1561,7 +1561,7 @@
 **************************************************************************/
 
 void *
-gaim_gtk_status_get_handle()
+gaim_gtk_status_get_handle(void)
 {
 	static int handle;
 
--- a/src/gtksavedstatuses.h	Mon Jan 23 05:50:32 2006 +0000
+++ b/src/gtksavedstatuses.h	Mon Jan 23 06:54:29 2006 +0000
@@ -48,7 +48,17 @@
 void gaim_gtk_status_editor_show(GaimSavedStatus *status);
 
 /**
- * Returns the gtkstatus handle.
+ * Creates a dropdown menu of saved statuses and calls a callback
+ * when one is selected
+ *
+ * @param status   The default saved_status to show as 'selected'
+ * @param callback The callback to call when the selection changes
+ * @return         The menu widget
+ */
+GtkWidget *gaim_gtk_status_menu(GaimSavedStatus *status, GCallback callback);
+
+/**
+ * Returns the GTK+ status handle.
  *
  * @return The handle to the GTK+ status system.
  */
@@ -64,14 +74,4 @@
  */
 void gaim_gtk_status_uninit(void);
 
-/**
- * Creates a dropdown menu of saved statuses and calls a callback
- * when one is selected
- *
- * @param status   The default saved_status to show as 'selected'
- * @param callback The callback to call when the selection changes
- * @return         The menu widget
- */
-GtkWidget *gaim_gtk_status_menu(GaimSavedStatus *status, GCallback callback);
-
 #endif /* _GAIM_GTKSAVEDSTATUSES_H_ */