changeset 9019:db1dc2d02020

[gaim-migrate @ 9795] Fiddled with a few small things 1) Added a GAIM_CONNECTION_IS_CONNECTED(gc) #define to connection.h 2) In the functions that build the Account Actions and Plugin Actions menus, I didn't think the comment "plugin and gc will be set from the counting loop already" was accurate (but it might be, becase it seemed like the account actions menu worked with one account online). So I made sure plugin and gc are set to what they should be. 3) Changed gaim_account_is_connected() to use GAIM_CONNECTION_IS_CONNECTED Previously gaim_account_is_connected() would return true for gc's that were "GAIM_CONNECTING." Now it only returns true for gc's that are "GAIM_CONNECTED." committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sat, 22 May 2004 23:08:27 +0000
parents bb168141eb5f
children 8f281104c031
files src/account.c src/connection.c src/connection.h src/gtkblist.c
diffstat 4 files changed, 54 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/account.c	Sat May 22 22:37:33 2004 +0000
+++ b/src/account.c	Sat May 22 23:08:27 2004 +0000
@@ -677,10 +677,13 @@
 gboolean
 gaim_account_is_connected(const GaimAccount *account)
 {
+	GaimConnection *gc;
+
 	g_return_val_if_fail(account != NULL, FALSE);
 
-	return (account->gc != NULL &&
-			gaim_connection_get_state(account->gc) != GAIM_DISCONNECTED);
+	gc = gaim_account_get_connection(account);
+
+	return ((gc != NULL) && GAIM_CONNECTION_IS_CONNECTED(gc));
 }
 
 const char *
--- a/src/connection.c	Sat May 22 22:37:33 2004 +0000
+++ b/src/connection.c	Sat May 22 23:08:27 2004 +0000
@@ -32,7 +32,6 @@
 #include "request.h"
 #include "server.h"
 #include "signals.h"
-#include "sound.h"
 #include "util.h"
 
 static GList *connections = NULL;
--- a/src/connection.h	Sat May 22 22:37:33 2004 +0000
+++ b/src/connection.h	Sat May 22 23:08:27 2004 +0000
@@ -190,6 +190,14 @@
 GaimConnectionState gaim_connection_get_state(const GaimConnection *gc);
 
 /**
+ * Returns TRUE if the account is connected, otherwise returns FALSE.
+ *
+ * @return TRUE if the account is connected, otherwise returns FALSE.
+ */
+#define GAIM_CONNECTION_IS_CONNECTED(gc) \
+	(gc->state == GAIM_CONNECTED)
+
+/**
  * Returns the connection's account.
  *
  * @param gc The connection.
--- a/src/gtkblist.c	Sat May 22 22:37:33 2004 +0000
+++ b/src/gtkblist.c	Sat May 22 23:08:27 2004 +0000
@@ -4977,9 +4977,10 @@
 	GaimPlugin *plugin = NULL;
 	int count = 0;
 
-	if (! protomenu)
+	if (protomenu == NULL)
 		return;
 
+	/* Clear the old Account Actions menu */
 	for (l = gtk_container_get_children(GTK_CONTAINER(protomenu)); l; l = l->next) {
 		GaimPluginAction *action;
 		
@@ -4991,28 +4992,39 @@
 		gtk_container_remove(GTK_CONTAINER(protomenu), GTK_WIDGET(menuitem));
 	}
 
+	/* Count the number of accounts with actions */
 	for (l = gaim_connections_get_all(); l; l = l->next) {
 		gc = l->data;
 		plugin = gc->prpl;
 
+		if (GAIM_CONNECTION_IS_CONNECTED(gc) && GAIM_PLUGIN_HAS_ACTIONS(plugin))
+			count++;
+
 		/* no need to count past 2, so don't */
-		if (gc->login_time && GAIM_PLUGIN_HAS_ACTIONS(plugin) && count++)
+		if (count > 1)
 			break;
 	}
 
-	
 	if (count == 0) {
 		menuitem = gtk_menu_item_new_with_label(_("No actions available"));
 		gtk_menu_shell_append(GTK_MENU_SHELL(protomenu), menuitem);
 		gtk_widget_set_sensitive(menuitem, FALSE);
 		gtk_widget_show(menuitem);
-
 	}
-	else
-	if (count == 1) {
-		/* plugin and gc will be set from the counting loop already */
+
+	else if (count == 1) {
+		/* Find the one account that has actions */
+		for (l = gaim_connections_get_all(); l; l = l->next) {
+			gc = l->data;
+			plugin = gc->prpl;
+
+			if (GAIM_CONNECTION_IS_CONNECTED(gc) && GAIM_PLUGIN_HAS_ACTIONS(plugin))
+				break;
+		}
+
 		build_plugin_actions(protomenu, plugin, gc);
 	}
+
 	else {
 		for (l = gaim_connections_get_all(); l; l = l->next) {
 			GaimAccount *account;
@@ -5023,7 +5035,7 @@
 			gc = l->data;
 			plugin = gc->prpl;
 
-			if (gc->login_time == 0	|| !GAIM_PLUGIN_HAS_ACTIONS(plugin))
+			if (!GAIM_CONNECTION_IS_CONNECTED(gc) || !GAIM_PLUGIN_HAS_ACTIONS(plugin))
 				continue;
 
 			account = gaim_connection_get_account(gc);
@@ -5033,7 +5045,7 @@
 			g_free(buf);
 
 			pixbuf = create_prpl_icon(account);
-			if(pixbuf) {
+			if (pixbuf) {
 				scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16,
 						GDK_INTERP_BILINEAR);
 				image = gtk_image_new_from_pixbuf(scale);
@@ -5064,9 +5076,10 @@
 	GList *l;
 	int count = 0;
 
-	if (! pluginmenu)
+	if (pluginmenu == NULL)
 		return;
 
+	/* Clear the old Account Actions menu */
 	for (l = gtk_container_get_children(GTK_CONTAINER(pluginmenu)); l; l = l->next) {
 		GaimPluginAction *action;
 
@@ -5077,11 +5090,15 @@
 		gtk_container_remove(GTK_CONTAINER(pluginmenu), GTK_WIDGET(menuitem));
 	}
 
+	/* Count the number of plugins with actions */
 	for (l = gaim_plugins_get_loaded(); l; l = l->next) {
 		plugin = (GaimPlugin *) l->data;
 
-		if( !GAIM_IS_PROTOCOL_PLUGIN(plugin) &&
-				GAIM_PLUGIN_HAS_ACTIONS(plugin) && count++)
+		if (!GAIM_IS_PROTOCOL_PLUGIN(plugin) && GAIM_PLUGIN_HAS_ACTIONS(plugin))
+			count++;
+
+		/* no need to count past 2, so don't */
+		if (count > 1)
 			break;
 	}
 
@@ -5090,13 +5107,20 @@
 		gtk_menu_shell_append(GTK_MENU_SHELL(pluginmenu), menuitem);
 		gtk_widget_set_sensitive(menuitem, FALSE);
 		gtk_widget_show(menuitem);
-
 	}
-	else
-	if (count == 1) {
-		/* plugin is already set */
+
+	else if (count == 1) {
+		/* Find the one plugin that has actions */
+		for (l = gaim_plugins_get_loaded(); l; l = l->next) {
+			plugin = (GaimPlugin *) l->data;
+
+			if (!GAIM_IS_PROTOCOL_PLUGIN(plugin) && GAIM_PLUGIN_HAS_ACTIONS(plugin))
+				break;
+		}
+
 		build_plugin_actions(pluginmenu, plugin, NULL);
 	}
+
 	else {
 		for (l = gaim_plugins_get_loaded(); l; l = l->next) {
 			plugin = (GaimPlugin *) l->data;
@@ -5104,7 +5128,7 @@
 			if (GAIM_IS_PROTOCOL_PLUGIN(plugin))
 				continue;
 
-			if (! GAIM_PLUGIN_HAS_ACTIONS(plugin))
+			if (!GAIM_PLUGIN_HAS_ACTIONS(plugin))
 				continue;
 
 			menuitem = gtk_image_menu_item_new_with_label(plugin->info->name);
@@ -5119,4 +5143,3 @@
 		}
 	}
 }
-