changeset 7887:4b43a3f9de73

[gaim-migrate @ 8545] Change the New Instant Message shortcut to CTRL+M. Apparently CTRL+I is used for "italics." Also reworked how stuff in conv windows is hidden and grayed out when changing tabs and when accounts sign on and off. I had some problems with signing off and still being able to click the warn button and stuff, but that was probably caused by my changes from a few days ago. Anyway, this makes a lot more sense to me. I added a function that takes a conversation and updates all the buttons and menu items to be what they should be based on whether the conversation is an IM or a chat, and if the account is connected or not. It still has a few minor problems (tab icons don't become active after signing back in an account that was signed out), but I'll get to that in a day or 3. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Tue, 16 Dec 2003 05:29:37 +0000
parents 818835fb55cc
children d12b234959d5
files src/ft.h src/gtkblist.c src/gtkconv.c src/gtkconv.h
diffstat 4 files changed, 192 insertions(+), 161 deletions(-) [+]
line wrap: on
line diff
--- a/src/ft.h	Mon Dec 15 16:42:54 2003 +0000
+++ b/src/ft.h	Tue Dec 16 05:29:37 2003 +0000
@@ -51,7 +51,7 @@
 	GAIM_XFER_STATUS_STARTED,       /**< gaim_xfer_start has been called. */
 	GAIM_XFER_STATUS_DONE,          /**< The xfer completed successfully. */
 	GAIM_XFER_STATUS_CANCEL_LOCAL,  /**< The xfer was canceled by us. */
-	GAIM_XFER_STATUS_CANCEL_REMOTE /**< The xfer was canceled by the other end, or we couldn't connect. */
+	GAIM_XFER_STATUS_CANCEL_REMOTE  /**< The xfer was canceled by the other end, or we couldn't connect. */
 } GaimXferStatusType;
 
 /**
@@ -78,7 +78,7 @@
  */
 struct _GaimXfer
 {
-	guint ref;                    /**<The reference count.                 */
+	guint ref;                    /**< The reference count.                 */
 	GaimXferType type;            /**< The type of transfer.               */
 
 	GaimAccount *account;         /**< The account.                        */
--- a/src/gtkblist.c	Mon Dec 15 16:42:54 2003 +0000
+++ b/src/gtkblist.c	Tue Dec 16 05:29:37 2003 +0000
@@ -1678,7 +1678,7 @@
 {
 	/* Buddies menu */
 	{ N_("/_Buddies"), NULL, NULL, 0, "<Branch>" },
-	{ N_("/Buddies/New _Instant Message..."), "<CTL>I", show_im_dialog, 0, "<StockItem>", GAIM_STOCK_IM },
+	{ N_("/Buddies/New Instant _Message..."), "<CTL>M", show_im_dialog, 0, "<StockItem>", GAIM_STOCK_IM },
 	{ N_("/Buddies/Join a _Chat..."), "<CTL>C", join_chat, 0, "<StockItem>", GAIM_STOCK_CHAT },
 	{ N_("/Buddies/Get _User Info..."), "<CTL>J", show_info_dialog, 0, "<StockItem>", GAIM_STOCK_INFO },
 	{ "/Buddies/sep1", NULL, NULL, 0, "<Separator>" },
@@ -3204,8 +3204,15 @@
 		gaim_blist_add_buddy(b, NULL, g, NULL);
 		serv_add_buddy(gaim_account_get_connection(data->account), who, g);
 
+		/*
+		 * It really seems like it would be better if the call to serv_add_buddy() 
+		 * and gaim_conversation_update() were done in blist.c, possibly in the 
+		 * gaim_blist_add_buddy() function.  Maybe serv_add_buddy() should be 
+		 * renamed to gaim_blist_add_new_buddy() or something, and have it call 
+		 * gaim_blist_add_buddy() after it creates it.  --Mark
+		 */
+
 		if (c != NULL) {
-			/* This should be in blist.c somewhere... */
 			gaim_buddy_icon_update(gaim_conv_im_get_icon(GAIM_CONV_IM(c)));
 			gaim_conversation_update(c, GAIM_CONV_UPDATE_ADD);
 		}
--- a/src/gtkconv.c	Mon Dec 15 16:42:54 2003 +0000
+++ b/src/gtkconv.c	Tue Dec 16 05:29:37 2003 +0000
@@ -2061,110 +2061,220 @@
 	return status;
 }
 
+/*
+ * Makes sure all the menu items and all the buttons are hidden/shown and 
+ * sensitive/insensitve.  This is called after changing tabs and when an 
+ * account signs on or off.
+ */
 static void
-switch_conv_cb(GtkNotebook *notebook, GtkWidget *page, gint page_num,
-				gpointer user_data)
+gray_stuff_out(GaimConversation *conv)
 {
-	GaimPluginProtocolInfo *prpl_info = NULL;
 	GaimConvWindow *win;
-	GaimConversation *conv;
+	GaimGtkWindow *gtkwin;
 	GaimGtkConversation *gtkconv;
-	GaimGtkWindow *gtkwin;
 	GaimConnection *gc;
+	GaimPluginProtocolInfo *prpl_info = NULL;
 	GdkPixbuf *window_icon = NULL;
 
-	win = (GaimConvWindow *)user_data;
-
-	conv = gaim_conv_window_get_conversation_at(win, page_num);
-
-	g_return_if_fail(conv != NULL);
-
-	gc      = gaim_conversation_get_gc(conv);
+	win     = gaim_conversation_get_window(conv);
 	gtkwin  = GAIM_GTK_WINDOW(win);
 	gtkconv = GAIM_GTK_CONVERSATION(conv);
-
-	gaim_conversation_set_unseen(conv, GAIM_UNSEEN_NONE);
+	gc      = gaim_conversation_get_gc(conv);
 
 	if (gc != NULL)
 		prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
 
-	/* Update the menubar */
+	if (gtkwin->menu.send_as != NULL)
+		g_timeout_add(0, (GSourceFunc)update_send_as_selection, win);
+
+	/*
+	 * Handle hiding and showing stuff based on what type of conv this is.
+	 */
 	if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) {
+		/* Show stuff that applies to IMs, hide stuff that applies to chats */
+
+		/* Deal with buttons */
+		gtk_widget_show(gtkconv->info);
+		gtk_widget_show(gtkconv->send);
+		gtk_widget_show(gtkconv->u.im->warn);
+		gtk_widget_show(gtkconv->u.im->block);
+		gtk_widget_show(gtkconv->u.im->add);
+
+		/* Deal with the toolbar */
+		gtk_widget_show(gtkconv->toolbar.image);
+
+		/* Deal with menu items */
 		gtk_widget_show(gtkwin->menu.view_log);
 		gtk_widget_show(gtkwin->menu.add_pounce);
 		gtk_widget_show(gtkwin->menu.get_info);
+		gtk_widget_show(gtkwin->menu.warn);
 		gtk_widget_hide(gtkwin->menu.invite);
-
-		gtk_widget_show(gtkwin->menu.insert_link);
-
-		gtk_widget_show(gtkwin->menu.insert_image);
-		if (gc && prpl_info->options & OPT_PROTO_IM_IMAGE)
-			gtk_widget_set_sensitive(gtkwin->menu.insert_image, TRUE);
-		else
-			gtk_widget_set_sensitive(gtkwin->menu.insert_image, FALSE);
-
-		gtk_widget_show(gtkwin->menu.warn);
-		if (gc && prpl_info->warn != NULL)
-			gtk_widget_set_sensitive(gtkwin->menu.warn, TRUE);
-		else
-			gtk_widget_set_sensitive(gtkwin->menu.warn, FALSE);
-
+		gtk_widget_show(gtkwin->menu.alias);
 		gtk_widget_show(gtkwin->menu.block);
 
 		if (gaim_find_buddy(gaim_conversation_get_account(conv),
 				    gaim_conversation_get_name(conv)) == NULL) {
 			gtk_widget_show(gtkwin->menu.add);
 			gtk_widget_hide(gtkwin->menu.remove);
-			gtk_widget_set_sensitive(gtkwin->menu.alias, FALSE);
 		} else {
 			gtk_widget_show(gtkwin->menu.remove);
 			gtk_widget_hide(gtkwin->menu.add);
-			gtk_widget_set_sensitive(gtkwin->menu.alias, TRUE);
 		}
-		gtk_widget_set_sensitive(gtkwin->menu.add,    TRUE);
-		gtk_widget_set_sensitive(gtkwin->menu.remove, TRUE);
-
-		if (gtkwin->menu.send_as != NULL)
-			g_timeout_add(0, (GSourceFunc)update_send_as_selection, win);
-
-		if (gtkconv->u.im->anim) {
-			window_icon = gdk_pixbuf_animation_get_static_image(gtkconv->u.im->anim);
-			g_object_ref(window_icon);
-		} else {
-			window_icon = get_tab_icon(conv);
-		}
-	}
-	else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) {
+
+		gtk_widget_show(gtkwin->menu.insert_link);
+		gtk_widget_show(gtkwin->menu.insert_image);
+	} else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) {
+		/* Show stuff that applies to IMs, hide stuff that applies to chats */
+
+		/* Deal with buttons */
+		gtk_widget_hide(gtkconv->info);
+		gtk_widget_show(gtkconv->send);
+		gtk_widget_show(gtkconv->u.chat->invite);
+
+		/* Deal with the toolbar */
+		gtk_widget_hide(gtkconv->toolbar.image);
+
+		/* Deal with menu items */
 		gtk_widget_hide(gtkwin->menu.view_log);
 		gtk_widget_hide(gtkwin->menu.add_pounce);
 		gtk_widget_hide(gtkwin->menu.get_info);
+		gtk_widget_hide(gtkwin->menu.warn);
 		gtk_widget_show(gtkwin->menu.invite);
-
-		gtk_widget_show(gtkwin->menu.insert_link);
-
-		gtk_widget_hide(gtkwin->menu.insert_image);
-		gtk_widget_set_sensitive(gtkconv->toolbar.image, FALSE);
-
-		gtk_widget_hide(gtkwin->menu.warn);
+		gtk_widget_show(gtkwin->menu.alias);
 		gtk_widget_hide(gtkwin->menu.block);
 
 		if (gaim_blist_find_chat(gaim_conversation_get_account(conv),
 								 gaim_conversation_get_name(conv)) == NULL) {
 			gtk_widget_show(gtkwin->menu.add);
 			gtk_widget_hide(gtkwin->menu.remove);
-			gtk_widget_set_sensitive(gtkwin->menu.alias, FALSE);
 		} else {
 			gtk_widget_show(gtkwin->menu.remove);
 			gtk_widget_hide(gtkwin->menu.add);
-			gtk_widget_set_sensitive(gtkwin->menu.alias, TRUE);
+		}
+
+		gtk_widget_show(gtkwin->menu.insert_link);
+		gtk_widget_hide(gtkwin->menu.insert_image);
+	}
+
+	/*
+	 * Handle graying stuff out based on whether an account is connected 
+	 * and what features that account supports.
+	 */
+	if (gc != NULL) {
+		/* Account is online */
+
+		/* Deal with buttons */
+		gtk_widget_set_sensitive(gtkconv->info, (prpl_info->get_info != NULL));
+		if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) {
+			gtk_widget_set_sensitive(gtkconv->send, TRUE);
+			gtk_widget_set_sensitive(gtkconv->u.im->warn,
+									 (prpl_info->warn != NULL));
+			gtk_widget_set_sensitive(gtkconv->u.im->block,
+									 (prpl_info->add_deny != NULL));
+			gtk_widget_set_sensitive(gtkconv->u.im->add, TRUE);
+		} else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) {
+			gtk_widget_set_sensitive(gtkconv->send, (prpl_info->chat_send != NULL));
+			gtk_widget_set_sensitive(gtkconv->u.chat->invite,
+									 (prpl_info->chat_invite != NULL));
 		}
-		gtk_widget_set_sensitive(gtkwin->menu.add,    TRUE);
+
+		/* Deal with the toolbar */
+		gtk_widget_set_sensitive(gtkconv->toolbar.image,
+								 (prpl_info->options & OPT_PROTO_IM_IMAGE));
+
+		/* Deal with menu items */
+		gtk_widget_set_sensitive(gtkwin->menu.view_log, TRUE);
+		gtk_widget_set_sensitive(gtkwin->menu.add_pounce, TRUE);
+		gtk_widget_set_sensitive(gtkwin->menu.get_info, (prpl_info->get_info != NULL));
+		gtk_widget_set_sensitive(gtkwin->menu.warn, (prpl_info->warn != NULL));
+		gtk_widget_set_sensitive(gtkwin->menu.invite,
+								 (prpl_info->chat_invite != NULL));
+
+		if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) {
+			if (gaim_find_buddy(gaim_conversation_get_account(conv),
+					    gaim_conversation_get_name(conv)) == NULL)
+				gtk_widget_set_sensitive(gtkwin->menu.alias, FALSE);
+			else
+				gtk_widget_set_sensitive(gtkwin->menu.alias, TRUE);
+		} else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) {
+			if (gaim_blist_find_chat(gaim_conversation_get_account(conv),
+									 gaim_conversation_get_name(conv)) == NULL)
+				gtk_widget_set_sensitive(gtkwin->menu.alias, FALSE);
+			else
+				gtk_widget_set_sensitive(gtkwin->menu.alias, TRUE);
+		}
+
+		gtk_widget_set_sensitive(gtkwin->menu.block, TRUE);
+		gtk_widget_set_sensitive(gtkwin->menu.add, TRUE);
 		gtk_widget_set_sensitive(gtkwin->menu.remove, TRUE);
-
-		if (gtkwin->menu.send_as != NULL)
-			g_timeout_add(0, (GSourceFunc)update_send_as_selection, win);
+		gtk_widget_set_sensitive(gtkwin->menu.insert_link, TRUE);
+		gtk_widget_set_sensitive(gtkwin->menu.insert_image,
+								 (prpl_info->options & OPT_PROTO_IM_IMAGE));
+	} else {
+		/* Account is offline */
+
+		/* Deal with buttons */
+		gtk_widget_set_sensitive(gtkconv->info, FALSE);
+		gtk_widget_set_sensitive(gtkconv->send, FALSE);
+		if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) {
+			gtk_widget_set_sensitive(gtkconv->u.im->warn, FALSE);
+			gtk_widget_set_sensitive(gtkconv->u.im->block, FALSE);
+			gtk_widget_set_sensitive(gtkconv->u.im->add, FALSE);
+		} else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) {
+			gtk_widget_set_sensitive(gtkconv->u.chat->invite, FALSE);
+		}
+
+		/* Deal with the toolbar */
+		gtk_widget_set_sensitive(gtkconv->toolbar.image, FALSE);
+
+		/* Then deal with menu items */
+		gtk_widget_set_sensitive(gtkwin->menu.view_log, TRUE);
+		gtk_widget_set_sensitive(gtkwin->menu.add_pounce, TRUE);
+		gtk_widget_set_sensitive(gtkwin->menu.get_info, FALSE);
+		gtk_widget_set_sensitive(gtkwin->menu.warn, FALSE);
+		gtk_widget_set_sensitive(gtkwin->menu.invite, FALSE);
+		gtk_widget_set_sensitive(gtkwin->menu.alias, FALSE);
+		gtk_widget_set_sensitive(gtkwin->menu.block, FALSE);
+		gtk_widget_set_sensitive(gtkwin->menu.add, FALSE);
+		gtk_widget_set_sensitive(gtkwin->menu.remove, FALSE);
+		gtk_widget_set_sensitive(gtkwin->menu.insert_link, FALSE);
+		gtk_widget_set_sensitive(gtkwin->menu.insert_image, FALSE);
+	}
+
+	/*
+	 * Update the window's icon
+	 */
+	if ((gaim_conversation_get_type(conv) == GAIM_CONV_IM) && (gtkconv->u.im->anim)) {
+		window_icon = gdk_pixbuf_animation_get_static_image(gtkconv->u.im->anim);
+		g_object_ref(window_icon);
+	} else {
 		window_icon = get_tab_icon(conv);
 	}
+	gtk_window_set_icon(GTK_WINDOW(gtkwin->window), window_icon);
+	g_object_unref(G_OBJECT(window_icon));
+}
+
+static void
+switch_conv_cb(GtkNotebook *notebook, GtkWidget *page, gint page_num,
+				gpointer user_data)
+{
+	GaimConvWindow *win;
+	GaimConversation *conv;
+	GaimGtkConversation *gtkconv;
+	GaimGtkWindow *gtkwin;
+
+	win = (GaimConvWindow *)user_data;
+	conv = gaim_conv_window_get_conversation_at(win, page_num);
+
+	g_return_if_fail(conv != NULL);
+
+	gtkwin  = GAIM_GTK_WINDOW(win);
+	gtkconv = GAIM_GTK_CONVERSATION(conv);
+
+	gaim_conversation_set_unseen(conv, GAIM_UNSEEN_NONE);
+
+	/* Update the menubar */
+	gray_stuff_out(conv);
 
 	update_typing_icon(conv);
 
@@ -2180,8 +2290,6 @@
 
 	gtk_widget_grab_focus(gtkconv->entry);
 
-	gtk_window_set_icon(GTK_WINDOW(gtkwin->window), window_icon);
-	g_object_unref(G_OBJECT(window_icon));
 	gtk_window_set_title(GTK_WINDOW(gtkwin->window),
 			     gtk_label_get_text(GTK_LABEL(gtkconv->tab_label)));
 }
@@ -2891,7 +2999,7 @@
 	/* Conversation menu */
 	{ N_("/_Conversation"), NULL, NULL, 0, "<Branch>" },
 
-	{ N_("/Conversation/New _Instant Message..."), "<CTL>I", menu_new_conv_cb,
+	{ N_("/Conversation/New Instant _Message..."), "<CTL>M", menu_new_conv_cb,
 	  0, "<StockItem>", GAIM_STOCK_IM },
 
 	{ "/Conversation/sep0", NULL, NULL, 0, "<Separator>" },
@@ -5466,98 +5574,15 @@
 void
 gaim_gtkconv_update_buttons_by_protocol(GaimConversation *conv)
 {
-	GaimPluginProtocolInfo *prpl_info = NULL;
 	GaimConvWindow *win;
-	GaimGtkWindow *gtkwin = NULL;
-	GaimGtkConversation *gtkconv;
-	GaimConnection *gc;
 
 	if (!GAIM_IS_GTK_CONVERSATION(conv))
 		return;
 
-	gc      = gaim_conversation_get_gc(conv);
-	win     = gaim_conversation_get_window(conv);
-	gtkconv = GAIM_GTK_CONVERSATION(conv);
-
-	if (win != NULL)
-		gtkwin = GAIM_GTK_WINDOW(win);
-
-	if (gc == NULL) {
-		gtk_widget_set_sensitive(gtkconv->send, FALSE);
-
-		if (win != NULL && gaim_conv_window_get_active_conversation(win) == conv) {
-			gtk_widget_set_sensitive(gtkwin->menu.insert_link, FALSE);
-		}
-	}
-	else {
-		prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
-
-		gtk_widget_set_sensitive(gtkconv->send, TRUE);
-
-		if (win != NULL)
-			gtk_widget_set_sensitive(gtkwin->menu.insert_link, TRUE);
-
-		gtk_widget_set_sensitive(gtkconv->toolbar.bgcolor,
-				!(gc->flags & GAIM_CONNECTION_NO_BGCOLOR));
-	}
-
-	if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) {
-		if (gc == NULL) {
-			gtk_widget_set_sensitive(gtkconv->info,        FALSE);
-			gtk_widget_set_sensitive(gtkconv->u.im->warn,  FALSE);
-			gtk_widget_set_sensitive(gtkconv->u.im->block, FALSE);
-			gtk_widget_set_sensitive(gtkconv->u.im->add,   FALSE);
-
-			if (win != NULL &&
-				gaim_conv_window_get_active_conversation(win) == conv) {
-
-				gtk_widget_set_sensitive(gtkwin->menu.insert_image, FALSE);
-			}
-
-			return;
-		}
-
-		gtk_widget_set_sensitive(gtkconv->info,
-								 (prpl_info->get_info != NULL));
-
-		gtk_widget_set_sensitive(gtkconv->toolbar.image,
-								 (prpl_info->options & OPT_PROTO_IM_IMAGE));
-
-		if (win != NULL && gaim_conv_window_get_active_conversation(win) == conv) {
-			gtk_widget_set_sensitive(gtkwin->menu.insert_image,
-									 (prpl_info->options & OPT_PROTO_IM_IMAGE));
-		}
-
-		gtk_widget_set_sensitive(gtkconv->u.im->warn,
-								 (prpl_info->warn != NULL));
-
-		gtk_widget_set_sensitive(gtkconv->u.im->block,
-								 (prpl_info->add_deny != NULL));
-
-		update_convo_add_button(conv);
-	}
-	else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) {
-		if (gc == NULL) {
-			if (gtkconv->u.chat->whisper != NULL)
-				gtk_widget_set_sensitive(gtkconv->u.chat->whisper, FALSE);
-
-			gtk_widget_set_sensitive(gtkconv->u.chat->invite,  FALSE);
-
-			return;
-		}
-
-		gtk_widget_set_sensitive(gtkconv->send, (prpl_info->chat_send != NULL));
-
-		gtk_widget_set_sensitive(gtkconv->toolbar.image, FALSE);
-		/* gtk_widget_set_sensitive(gtkwin->menu.insert_image, FALSE); */
-
-		if (gtkconv->u.chat->whisper != NULL)
-			gtk_widget_set_sensitive(gtkconv->u.chat->whisper,
-									 (prpl_info->chat_whisper != NULL));
-
-		gtk_widget_set_sensitive(gtkconv->u.chat->invite,
-								 (prpl_info->chat_invite != NULL));
-	}
+	win = gaim_conversation_get_window(conv);
+
+	if (win != NULL && gaim_conv_window_get_active_conversation(win) == conv)
+		gray_stuff_out(conv);
 }
 
 GaimConvWindow *
--- a/src/gtkconv.h	Mon Dec 15 16:42:54 2003 +0000
+++ b/src/gtkconv.h	Tue Dec 16 05:29:37 2003 +0000
@@ -52,18 +52,18 @@
 		GtkWidget *view_log;
 
 		GtkWidget *add_pounce;
+		GtkWidget *get_info;
+		GtkWidget *warn;
+		GtkWidget *invite;
+
 		GtkWidget *alias;
-		GtkWidget *get_info;
-		GtkWidget *invite;
+		GtkWidget *block;
+		GtkWidget *add;
+		GtkWidget *remove;
 
 		GtkWidget *insert_link;
 		GtkWidget *insert_image;
 
-		GtkWidget *warn;
-		GtkWidget *block;
-		GtkWidget *add;
-		GtkWidget *remove;
-
 		GtkWidget *logging;
 		GtkWidget *sounds;
 		GtkWidget *show_formatting_toolbar;
@@ -116,7 +116,6 @@
 {
 	GtkWidget *count;
 	GtkWidget *list;
-	GtkWidget *whisper;
 	GtkWidget *invite;
 	GtkWidget *topic_text;
 };