changeset 10352:5879593a6a10

[gaim-migrate @ 11569] Gray out some buddy list menu items and the gtkstatusselector if no accounts are online. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 13 Dec 2004 01:49:55 +0000
parents 7fcdd669eb49
children fc7168f9ecb0
files src/connection.h src/gtkblist.c src/gtkpounce.c src/gtkprivacy.c src/gtkstatusselector.c
diffstat 5 files changed, 62 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/connection.h	Mon Dec 13 01:24:19 2004 +0000
+++ b/src/connection.h	Mon Dec 13 01:49:55 2004 +0000
@@ -250,7 +250,8 @@
 void gaim_connections_disconnect_all(void);
 
 /**
- * Returns a list of all active connections.
+ * Returns a list of all active connections.  This does not
+ * include connections that are in the process of connecting.
  *
  * @return A list of all active connections.
  */
--- a/src/gtkblist.c	Mon Dec 13 01:24:19 2004 +0000
+++ b/src/gtkblist.c	Mon Dec 13 01:49:55 2004 +0000
@@ -2989,16 +2989,44 @@
 	gtknode->row = NULL;
 }
 
-static void
-sign_on_off_cb(GaimConnection *gc, GaimBuddyList *blist)
+static const char *require_connection[] =
 {
-	GaimGtkBuddyList *gtkblist = GAIM_GTK_BLIST(blist);
+	N_("/Buddies/New Instant Message..."),
+	N_("/Buddies/Join a Chat..."),
+	N_("/Buddies/Get User Info..."),
+	N_("/Buddies/Add Buddy..."),
+	N_("/Buddies/Add Chat..."),
+	N_("/Buddies/Add Group..."),
+	N_("/Buddies/Log Out")
+};
+
+/* There's got to be a cleaner way to do this...? */
+#define SIZEOF_REQUIRE_CONNECTION 7
+
+/**
+ * Rebuild dynamic menus and make menu items sensitive/insensitive
+ * where appropriate.
+ */
+static void
+update_menu_bar(GaimGtkBuddyList *gtkblist)
+{
 	GtkWidget *widget;
+	gboolean sensitive;
+	int i;
+
+	g_return_if_fail(gtkblist != NULL);
 
 	gaim_gtk_blist_update_protocol_actions();
 	gaim_gtkpounce_menu_build(gtkblist->bpmenu);
 
-	/* Make menu items sensitive/insensitive where appropriate */
+	sensitive = (gaim_connections_get_all() != NULL);
+
+	for (i = 0; i < SIZEOF_REQUIRE_CONNECTION; i++)
+	{
+		widget = gtk_item_factory_get_widget(gtkblist->ift, require_connection[i]);
+		gtk_widget_set_sensitive(widget, sensitive);
+	}
+
 	widget = gtk_item_factory_get_widget(gtkblist->ift, N_("/Buddies/Join a Chat..."));
 	gtk_widget_set_sensitive(widget, gaim_gtk_blist_joinchat_is_showable());
 
@@ -3009,6 +3037,13 @@
 	gtk_widget_set_sensitive(widget, gaim_gtk_privacy_is_showable());
 }
 
+static void
+sign_on_off_cb(GaimConnection *gc, GaimBuddyList *blist)
+{
+	GaimGtkBuddyList *gtkblist = GAIM_GTK_BLIST(blist);
+
+	update_menu_bar(gtkblist);
+}
 
 static void
 plugin_changed_cb(GaimPlugin *p, gpointer *data)
@@ -3135,12 +3170,10 @@
 	gtk_box_pack_start(GTK_BOX(gtkblist->vbox), menu, FALSE, FALSE, 0);
 
 	gtkblist->bpmenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Buddy Pounce"));
-	gaim_gtkpounce_menu_build(gtkblist->bpmenu);
-
 	protomenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Account Actions"));
-	gaim_gtk_blist_update_protocol_actions();
-
 	pluginmenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Plugin Actions"));
+
+	update_menu_bar(gtkblist);
 	gaim_gtk_blist_update_plugin_actions();
 
 	/****************************** GtkTreeView **********************************/
@@ -4847,14 +4880,13 @@
 
 #endif
 
-
 static void
 plugin_act(GtkObject *obk, GaimPluginAction *pam)
 {
-	if (pam->callback) pam->callback(pam);
+	if (pam->callback)
+		pam->callback(pam);
 }
 
-
 static void
 build_plugin_actions(GtkWidget *menu, GaimPlugin *plugin, gpointer context)
 {
@@ -4982,7 +5014,6 @@
 	}
 }
 
-
 void
 gaim_gtk_blist_update_plugin_actions(void)
 {
--- a/src/gtkpounce.c	Mon Dec 13 01:24:19 2004 +0000
+++ b/src/gtkpounce.c	Mon Dec 13 01:49:55 2004 +0000
@@ -357,6 +357,9 @@
 	GPtrArray *sound_widgets;
 	GPtrArray *exec_widgets;
 
+	g_return_if_fail((cur_pounce != NULL) || (account != NULL) ||
+					 (gaim_connections_get_all() != NULL));
+
 	dialog = g_new0(GaimGtkPounceDialog, 1);
 
 	if (cur_pounce != NULL)
@@ -900,6 +903,7 @@
 	/* "New Buddy Pounce" */
 	item = gtk_menu_item_new_with_label(_("New Buddy Pounce"));
 	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+	gtk_widget_set_sensitive(item, (gaim_connections_get_all() != NULL));
 	gtk_widget_show(item);
 	g_signal_connect(G_OBJECT(item), "activate",
 					 G_CALLBACK(new_pounce_cb), NULL);
--- a/src/gtkprivacy.c	Mon Dec 13 01:24:19 2004 +0000
+++ b/src/gtkprivacy.c	Mon Dec 13 01:49:55 2004 +0000
@@ -521,6 +521,8 @@
 void
 gaim_gtk_privacy_dialog_show(void)
 {
+	g_return_if_fail(gaim_connections_get_all() != NULL);
+
 	if (privacy_dialog == NULL)
 		privacy_dialog = privacy_dialog_new();
 
--- a/src/gtkstatusselector.c	Mon Dec 13 01:24:19 2004 +0000
+++ b/src/gtkstatusselector.c	Mon Dec 13 01:49:55 2004 +0000
@@ -510,6 +510,17 @@
 #endif
 
 	/*
+	 * If no accounts are connected then gray ourself out and get
+	 * outta hee.
+	 */
+	if (gaim_connections_get_all() == NULL)
+	{
+		gtk_widget_set_sensitive(GTK_WIDGET(selector), FALSE);
+		return;
+	}
+	gtk_widget_set_sensitive(GTK_WIDGET(selector), TRUE);
+
+	/*
 	 * If the user only has one IM account or one type of IM account
 	 * connected, they'll see all their statuses. This is ideal for those
 	 * who use only one account, or one single protocol. Everyone else