changeset 11251:ad9a61894d9b

[gaim-migrate @ 13420] sf patch #1242524, from Sadrul Habib Chowdhury gaim_account_is_connected fix committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sat, 13 Aug 2005 05:54:34 +0000
parents 4e25fb6678bd
children 55356a29cdd1
files src/account.c src/account.h src/connection.c src/gtkaccount.c src/gtkconn.c src/gtksavedstatuses.c src/gtkutils.c src/protocols/jabber/presence.c src/protocols/oscar/oscar.c src/protocols/yahoo/yahoo.c
diffstat 10 files changed, 72 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/src/account.c	Sat Aug 13 05:30:13 2005 +0000
+++ b/src/account.c	Sat Aug 13 05:54:34 2005 +0000
@@ -1002,7 +1002,7 @@
 	GaimConnection *gc;
 
 	g_return_if_fail(account != NULL);
-	g_return_if_fail(gaim_account_is_connected(account));
+	g_return_if_fail(!gaim_account_is_disconnected(account));
 
 	gaim_debug_info("account", "Disconnecting account %p\n", account);
 
@@ -1513,18 +1513,36 @@
 	schedule_accounts_save();
 }
 
-gboolean
-gaim_account_is_connected(const GaimAccount *account)
+static GaimConnectionState
+gaim_account_get_state(const GaimAccount *account)
 {
 	GaimConnection *gc;
 
-	g_return_val_if_fail(account != NULL, FALSE);
+	g_return_val_if_fail(account != NULL, GAIM_DISCONNECTED);
 
 	gc = gaim_account_get_connection(account);
+	if (!gc)
+		return GAIM_DISCONNECTED;
 
-	/* TODO: The first way is better... but it doesn't work quite right yet */
-	/* return ((gc != NULL) && GAIM_CONNECTION_IS_CONNECTED(gc)); */
-	return ((gc != NULL) && gaim_connection_get_state(gc) != GAIM_DISCONNECTED);
+	return gaim_connection_get_state(gc);
+}
+
+gboolean
+gaim_account_is_connected(const GaimAccount *account)
+{
+	return (gaim_account_get_state(account) == GAIM_CONNECTED);
+}
+
+gboolean
+gaim_account_is_connecting(const GaimAccount *account)
+{
+	return (gaim_account_get_state(account) == GAIM_CONNECTING);
+}
+
+gboolean
+gaim_account_is_disconnected(const GaimAccount *account)
+{
+	return (gaim_account_get_state(account) == GAIM_DISCONNECTED);
 }
 
 const char *
--- a/src/account.h	Sat Aug 13 05:30:13 2005 +0000
+++ b/src/account.h	Sat Aug 13 05:54:34 2005 +0000
@@ -403,6 +403,24 @@
 gboolean gaim_account_is_connected(const GaimAccount *account);
 
 /**
+ * Returns whether or not the account is connecting.
+ *
+ * @param account The account.
+ *
+ * @return @c TRUE if connecting, or @c FALSE otherwise.
+ */
+gboolean gaim_account_is_connecting(const GaimAccount *account);
+
+/**
+ * Returns whether or not the account is disconnected.
+ *
+ * @param account The account.
+ *
+ * @return @c TRUE if disconnected, or @c FALSE otherwise.
+ */
+gboolean gaim_account_is_disconnected(const GaimAccount *account);
+
+/**
  * Returns the account's username.
  *
  * @param account The account.
--- a/src/connection.c	Sat Aug 13 05:30:13 2005 +0000
+++ b/src/connection.c	Sat Aug 13 05:54:34 2005 +0000
@@ -83,7 +83,7 @@
 
 	g_return_if_fail(account != NULL);
 
-	if (gaim_account_is_connected(account))
+	if (!gaim_account_is_disconnected(account))
 		return;
 
 	prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
--- a/src/gtkaccount.c	Sat Aug 13 05:30:13 2005 +0000
+++ b/src/gtkaccount.c	Sat Aug 13 05:54:34 2005 +0000
@@ -1758,7 +1758,7 @@
 			scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16,
 											GDK_INTERP_BILINEAR);
 
-			if (!gaim_account_is_connected(account))
+			if (gaim_account_is_disconnected(account))
 				gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE);
 		}
 		gtk_list_store_set(dialog->model, &iter,
@@ -2144,7 +2144,7 @@
 	{
 		scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR);
 
-		if (!gaim_account_is_connected(account))
+		if (gaim_account_is_disconnected(account))
 			gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE);
 	}
 
--- a/src/gtkconn.c	Sat Aug 13 05:30:13 2005 +0000
+++ b/src/gtkconn.c	Sat Aug 13 05:54:34 2005 +0000
@@ -140,7 +140,7 @@
 	}
 
 	/*
-	 * If we have more than one disconnected account then show the 
+	 * If we have more than one disconnected account then show the
 	 * GtkTreeView and the "Reconnect All" button
 	 */
 	if (gtk_tree_model_iter_next(model, &iter)) {
@@ -161,21 +161,21 @@
 	}
 
 	/*
-	 * Update the Reconnect/Remove button appropriately and set the 
-	 * label in the dialog to what it should be.  If there is only 
-	 * one account in the tree model, and that account is connected, 
+	 * Update the Reconnect/Remove button appropriately and set the
+	 * label in the dialog to what it should be.  If there is only
+	 * one account in the tree model, and that account is connected,
 	 * then we don't show the remove button.
 	 */
 	gtk_tree_model_get(model, &iter, 3, &label_text, 4, &account, -1);
 	gtk_button_set_label(GTK_BUTTON(disconnect_window->reconnect_btn),
-		gaim_account_is_connected(account) ? _("_Remove") : _("_Reconnect"));
+		gaim_account_is_disconnected(account) ? _("Reconnect") : _("_Remove"));
 	gtk_label_set_markup(GTK_LABEL(disconnect_window->label), label_text);
 	gtk_dialog_set_response_sensitive(GTK_DIALOG(disconnect_window->window), GTK_RESPONSE_ACCEPT, TRUE);
 	gtk_tree_model_get_iter_first(model, &iter);
-	if (gaim_account_is_connected(account) && !(gtk_tree_model_iter_next(model, &iter)))
+	if (gaim_account_is_disconnected(account) || gtk_tree_model_iter_next(model, &iter))
+		gtk_widget_show(disconnect_window->reconnect_btn);
+	else
 		gtk_widget_hide(disconnect_window->reconnect_btn);
-	else
-		gtk_widget_show(disconnect_window->reconnect_btn);
 	g_free(label_text);
 }
 
@@ -201,7 +201,7 @@
 				gtk_tree_path_free(path);
 
 				gtk_tree_model_get(model, &iter, 4, &account, -1);
-				if (!gaim_account_is_connected(account) && g_list_find(l_accts, account) == NULL)
+				if (gaim_account_is_disconnected(account) && g_list_find(l_accts, account) == NULL)
 					l_accts = g_list_append(l_accts, account);
 			} while (gtk_tree_model_iter_next(model, &iter));
 
@@ -325,7 +325,7 @@
 	scale = gdk_pixbuf_scale_simple(icon, 16, 16, GDK_INTERP_BILINEAR);
 
 	/* Mark all disconnections w/ the account type disconnected /w grey icon */
-	if (!gaim_account_is_connected(account))
+	if (gaim_account_is_disconnected(account))
 		gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE);
 
 	gtk_tree_model_get_iter_first(model, &iter);
@@ -337,7 +337,7 @@
 			gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, scale, -1);
 
 		/* Add  */
-		if (!gaim_account_is_connected(account2)
+		if (gaim_account_is_disconnected(account2)
 				&& g_list_find(l_disc_accts, account2) == NULL)
 			l_disc_accts = g_list_append(l_disc_accts, account2);
 	} while (gtk_tree_model_iter_next(model, &iter));
--- a/src/gtksavedstatuses.c	Sat Aug 13 05:30:13 2005 +0000
+++ b/src/gtksavedstatuses.c	Sat Aug 13 05:54:34 2005 +0000
@@ -650,7 +650,7 @@
 	{
 		scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR);
 
-		if (!gaim_account_is_connected(account))
+		if (gaim_account_is_disconnected(account))
 			gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE);
 	}
 
--- a/src/gtkutils.c	Sat Aug 13 05:30:13 2005 +0000
+++ b/src/gtkutils.c	Sat Aug 13 05:54:34 2005 +0000
@@ -632,7 +632,7 @@
 				scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16,
 				                                GDK_INTERP_BILINEAR);
 
-				if (!gaim_account_is_connected(account) && show_all &&
+				if (gaim_account_is_disconnected(account) && show_all &&
 						gaim_connections_get_all())
 					gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE);
 
--- a/src/protocols/jabber/presence.c	Sat Aug 13 05:30:13 2005 +0000
+++ b/src/protocols/jabber/presence.c	Sat Aug 13 05:54:34 2005 +0000
@@ -91,7 +91,7 @@
 {
 	GaimConnection *gc = NULL;
 	JabberStream *js = NULL;
-	gboolean connected;
+	gboolean disconnected;
 	int primitive;
 	xmlnode *presence, *x, *photo;
 	char *stripped = NULL;
@@ -102,14 +102,14 @@
 	if(!gaim_status_is_active(status))
 		return;
 
-	connected = gaim_account_is_connected(account);
+	disconnected = gaim_account_is_disconnected(account);
 	primitive = gaim_status_type_get_primitive(gaim_status_get_type(status));
 
-	if(primitive != GAIM_STATUS_OFFLINE && !connected) {
+	if(primitive != GAIM_STATUS_OFFLINE && disconnected) {
 		gaim_account_connect(account);
 	}
 
-	if(!connected)
+	if(disconnected)
 		return;
 
 	gc = gaim_account_get_connection(account);
@@ -137,7 +137,7 @@
 
 	jabber_presence_fake_to_self(js, status);
 
-	if(primitive == GAIM_STATUS_OFFLINE && connected) {
+	if(primitive == GAIM_STATUS_OFFLINE && !disconnected) {
 		gaim_account_disconnect(account);
 	}
 }
--- a/src/protocols/oscar/oscar.c	Sat Aug 13 05:30:13 2005 +0000
+++ b/src/protocols/oscar/oscar.c	Sat Aug 13 05:54:34 2005 +0000
@@ -5963,7 +5963,7 @@
 static void
 oscar_set_status(GaimAccount *account, GaimStatus *status)
 {
-	gboolean connected = gaim_account_is_connected(account);
+	gboolean disconnected = gaim_account_is_disconnected(account);
 	GaimStatusType *type = gaim_status_get_type(status);
 	int primitive = gaim_status_type_get_primitive(type);
 
@@ -5972,12 +5972,12 @@
 	if (!gaim_status_is_active(status))
 		return;
 
-	if (primitive != GAIM_STATUS_OFFLINE && !connected) {
+	if (primitive != GAIM_STATUS_OFFLINE && disconnected) {
 		gaim_account_connect(account);
-	} else if (primitive == GAIM_STATUS_OFFLINE && connected) {
+	} else if (primitive == GAIM_STATUS_OFFLINE && !disconnected) {
 		gaim_account_disconnect(account);
 	} else {
-		if (!connected)
+		if (!gaim_account_is_connected(account))
 			return;
 
 		if (aim_sn_is_icq(gaim_account_get_username(account)))
--- a/src/protocols/yahoo/yahoo.c	Sat Aug 13 05:30:13 2005 +0000
+++ b/src/protocols/yahoo/yahoo.c	Sat Aug 13 05:54:34 2005 +0000
@@ -3008,7 +3008,7 @@
 static void yahoo_set_status(GaimAccount *account, GaimStatus *status)
 {
 	GaimConnection *gc = gaim_account_get_connection(account);
-	gboolean connected = gaim_account_is_connected(account);
+	gboolean disconnected = gaim_account_is_disconnected(account);
 	struct yahoo_data *yd;
 	struct yahoo_packet *pkt;
 	int old_status;
@@ -3019,15 +3019,15 @@
 	id = gaim_status_get_id(status);
 	if (!gaim_status_is_active(status))
 		return;
-	if (strcmp(id, YAHOO_STATUS_TYPE_OFFLINE) && !connected) {
+	if (strcmp(id, YAHOO_STATUS_TYPE_OFFLINE) && disconnected) {
 		gaim_account_connect(account);
 		return;
-	} else if (!strcmp(id, YAHOO_STATUS_TYPE_OFFLINE) && connected) {
+	} else if (!strcmp(id, YAHOO_STATUS_TYPE_OFFLINE) && !disconnected) {
 		gaim_account_disconnect(account);
 		return;
 	}
 
-	if (!connected)
+	if (!gaim_account_is_connected(account))
 		return;
 
 	yd = (struct yahoo_data *)gc->proto_data;