changeset 1692:a312d64a995d

[gaim-migrate @ 1702] and i thought i couldn't do it. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sun, 08 Apr 2001 09:26:00 +0000
parents d802b115800f
children 6ccd49e6f24c
files ChangeLog src/buddy_chat.c src/conversation.c src/gaim.h src/prefs.c src/server.c
diffstat 6 files changed, 192 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Apr 08 01:27:24 2001 +0000
+++ b/ChangeLog	Sun Apr 08 09:26:00 2001 +0000
@@ -7,6 +7,8 @@
 	* IRC Plugin can do whois (right click and info)
 	* IRC Plugin got away message support
 	* Gaim blist to WinAIM blt perl script (courtesy Andy Harrison)
+	* Can view all group chats in one tabbed window (same keybindings
+	  as for tabbed normal conversations)
 
 version 0.11.0-pre9 (03/26/2001):
 	* Can register Jabber accounts (load the Jabber plugin and click
--- a/src/buddy_chat.c	Sun Apr 08 01:27:24 2001 +0000
+++ b/src/buddy_chat.c	Sun Apr 08 09:26:00 2001 +0000
@@ -51,6 +51,10 @@
 static int community;
 extern int state_lock;
 
+GList *chats = NULL;
+GtkWidget *all_chats = NULL;
+GtkWidget *chat_notebook = NULL;
+
 static void destroy_join_chat()
 {
 	if (joinchat)
@@ -709,11 +713,37 @@
 	gtk_widget_show(list_item);
 }
 
+static gint delete_all_chats(GtkWidget *w, GdkEventAny *e, gpointer d)
+{
+	while (chats) {
+		struct conversation *c = chats->data;
+		close_callback(c->close, c);
+	}
+	return FALSE;
+}
 
+static void chat_switch(GtkNotebook *notebook, GtkWidget *page, gint page_num, gpointer data)
+{
+	GtkWidget *label = gtk_notebook_get_tab_label(GTK_NOTEBOOK(chat_notebook),
+			gtk_notebook_get_nth_page(GTK_NOTEBOOK(chat_notebook), page_num));
+	GtkStyle *style;
+	struct conversation *b = g_list_nth_data(chats, page_num);
+	if (b && b->window && b->entry)
+		gtk_window_set_focus(GTK_WINDOW(b->window), b->entry);
+	if (!GTK_WIDGET_REALIZED(label))
+		return;
+	style = gtk_style_new();
+	gdk_font_unref(style->font);
+	style->font = gdk_font_ref(label->style->font);
+	gtk_widget_set_style(label, style);
+	gtk_style_unref(style);
+	b->unseen = FALSE;
+}
 
 void show_new_buddy_chat(struct conversation *b)
 {
 	GtkWidget *win;
+	GtkWidget *cont;
 	GtkWidget *text;
 	GtkWidget *send;
 	GtkWidget *list;
@@ -735,21 +765,49 @@
 
 	int dispstyle = set_dispstyle(1);
 
-	win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-	b->window = win;
-	gtk_object_set_user_data(GTK_OBJECT(win), b);
-	gtk_window_set_wmclass(GTK_WINDOW(win), "buddy_chat", "Gaim");
-	gtk_window_set_policy(GTK_WINDOW(win), TRUE, TRUE, TRUE);
-	gtk_container_border_width(GTK_CONTAINER(win), 10);
-	g_snprintf(buf, sizeof(buf), "Gaim - %s (chat)", b->name);
-	gtk_window_set_title(GTK_WINDOW(win), buf);
-	gtk_signal_connect(GTK_OBJECT(win), "destroy", GTK_SIGNAL_FUNC(close_callback), b);
-	gtk_widget_realize(win);
-	aol_icon(win->window);
+	if (display_options & OPT_DISP_ONE_CHAT_WINDOW) {
+		if (!all_chats) {
+			win = all_chats = b->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+			gtk_window_set_wmclass(GTK_WINDOW(win), "buddy_chat", "Gaim");
+			gtk_window_set_policy(GTK_WINDOW(win), TRUE, TRUE, TRUE);
+			gtk_container_border_width(GTK_CONTAINER(win), 0);
+			gtk_widget_realize(win);
+			aol_icon(win->window);
+			gtk_window_set_title(GTK_WINDOW(win), _("Gaim - Group Chats"));
+			gtk_signal_connect(GTK_OBJECT(win), "delete_event",
+					   GTK_SIGNAL_FUNC(delete_all_chats), NULL);
+
+			chat_notebook = gtk_notebook_new();
+			gtk_notebook_set_scrollable(GTK_NOTEBOOK(chat_notebook), TRUE);
+			gtk_notebook_popup_enable(GTK_NOTEBOOK(chat_notebook));
+			gtk_container_add(GTK_CONTAINER(win), chat_notebook);
+			gtk_signal_connect(GTK_OBJECT(chat_notebook), "switch-page",
+					   GTK_SIGNAL_FUNC(chat_switch), NULL);
+			gtk_widget_show(chat_notebook);
+		} else
+			win = b->window = all_chats;
+
+		cont = gtk_vbox_new(FALSE, 5);
+		gtk_container_set_border_width(GTK_CONTAINER(cont), 5);
+		gtk_notebook_append_page(GTK_NOTEBOOK(chat_notebook), cont, gtk_label_new(b->name));
+		gtk_widget_show(cont);
+	} else {
+		cont = win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+		b->window = win;
+		gtk_object_set_user_data(GTK_OBJECT(win), b);
+		gtk_window_set_wmclass(GTK_WINDOW(win), "buddy_chat", "Gaim");
+		gtk_window_set_policy(GTK_WINDOW(win), TRUE, TRUE, TRUE);
+		gtk_container_border_width(GTK_CONTAINER(win), 10);
+		gtk_widget_realize(win);
+		aol_icon(win->window);
+		g_snprintf(buf, sizeof(buf), "Gaim - %s (chat)", b->name);
+		gtk_window_set_title(GTK_WINDOW(win), buf);
+		gtk_signal_connect(GTK_OBJECT(win), "destroy", GTK_SIGNAL_FUNC(close_callback), b);
+	}
 
 	vpaned = gtk_vpaned_new();
 	gtk_paned_set_gutter_size(GTK_PANED(vpaned), 15);
-	gtk_container_add(GTK_CONTAINER(win), vpaned);
+	gtk_container_add(GTK_CONTAINER(cont), vpaned);
 	gtk_widget_show(vpaned);
 
 	hpaned = gtk_hpaned_new();
@@ -758,6 +816,7 @@
 	gtk_widget_show(hpaned);
 
 	sw = gtk_scrolled_window_new(NULL, NULL);
+	b->sw = sw;
 	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
 	gtk_paned_pack1(GTK_PANED(hpaned), sw, TRUE, TRUE);
 	gtk_widget_set_usize(sw, 320, 160);
@@ -820,6 +879,8 @@
 
 	chatentry = gtk_text_new(NULL, NULL);
 	b->entry = chatentry;
+	if (!(display_options & OPT_DISP_ONE_CHAT_WINDOW))
+		gtk_window_set_focus(GTK_WINDOW(b->window), b->entry);
 
 	toolbar = build_conv_toolbar(b);
 	gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
@@ -1038,3 +1099,47 @@
 		bcs = bcs->next;
 	}
 }
+
+void chat_tabize()
+{
+	/* evil, evil i tell you! evil! */
+	if (display_options & OPT_DISP_ONE_CHAT_WINDOW) {
+		GList *x = chats;
+		while (x) {
+			struct conversation *c = x->data;
+			GtkWidget *imhtml, *win;
+
+			imhtml = c->text;
+			win = c->window;
+			show_new_buddy_chat(c);
+			gtk_widget_destroy(c->text);
+			gtk_widget_reparent(imhtml, c->sw);
+			c->text = imhtml;
+			gtk_signal_disconnect_by_func(GTK_OBJECT(win),
+					GTK_SIGNAL_FUNC(close_callback), c);
+			gtk_widget_destroy(win);
+
+			x = x->next;
+		}
+	} else {
+		GList *x, *m;
+		x = m = chats;
+		chats = NULL;
+		while (x) {
+			struct conversation *c = x->data;
+			GtkWidget *imhtml;
+
+			imhtml = c->text;
+			show_new_buddy_chat(c);
+			gtk_widget_destroy(c->text);
+			gtk_widget_reparent(imhtml, c->sw);
+			c->text = imhtml;
+
+			x = x->next;
+		}
+		if (all_chats)
+			gtk_widget_destroy(all_chats);
+		all_chats = NULL;
+		chats = m;
+	}
+}
--- a/src/conversation.c	Sun Apr 08 01:27:24 2001 +0000
+++ b/src/conversation.c	Sun Apr 08 09:26:00 2001 +0000
@@ -374,7 +374,7 @@
 
 int close_callback(GtkWidget *widget, struct conversation *c)
 {
-	if (c->is_chat && (widget == c->close)) {
+	if (c->is_chat && (widget == c->close) && !(display_options & OPT_DISP_ONE_CHAT_WINDOW)) {
 		GtkWidget *tmp = c->window;
 		debug_printf("chat clicked close button\n");
 		c->window = NULL;
@@ -387,20 +387,38 @@
 	if (general_options & OPT_GEN_CHECK_SPELLING)
 		gtkspell_detach(GTK_TEXT(c->entry));
 
-	if ((display_options & OPT_DISP_ONE_WINDOW) && (!c->is_chat)) {
-		if (g_list_length(conversations) > 1) {
-			gtk_notebook_remove_page(GTK_NOTEBOOK(convo_notebook),
-					g_list_index(conversations, c));
+	if (!c->is_chat) {
+		if (display_options & OPT_DISP_ONE_WINDOW) {
+			if (g_list_length(conversations) > 1) {
+				gtk_notebook_remove_page(GTK_NOTEBOOK(convo_notebook),
+						g_list_index(conversations, c));
+			} else {
+				if (c->window)
+					gtk_widget_destroy(c->window);
+				c->window = NULL;
+				all_convos = NULL;
+			}
 		} else {
 			if (c->window)
 				gtk_widget_destroy(c->window);
 			c->window = NULL;
-			all_convos = NULL;
 		}
 	} else {
-		if (c->window)
-			gtk_widget_destroy(c->window);
-		c->window = NULL;
+		if (display_options & OPT_DISP_ONE_CHAT_WINDOW) {
+			if (g_list_length(chats) > 1) {
+				gtk_notebook_remove_page(GTK_NOTEBOOK(chat_notebook),
+						g_list_index(chats, c));
+			} else {
+				if (c->window)
+					gtk_widget_destroy(c->window);
+				c->window = NULL;
+				all_chats = NULL;
+			}
+		} else {
+			if (c->window)
+				gtk_widget_destroy(c->window);
+			c->window = NULL;
+		}
 	}
 
 	if (c->fg_color_dialog)
@@ -423,6 +441,7 @@
 	c->log_dialog = NULL;
 
 	if (c->is_chat) {
+		chats = g_list_remove(chats, c);
 		if (c->gc)
 			serv_chat_leave(c->gc, c->id);
 		else {
@@ -648,17 +667,20 @@
 				gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
 			}
 		}
-		if (!c->is_chat && (display_options & OPT_DISP_ONE_WINDOW)) {
+		if ((!c->is_chat && (display_options & OPT_DISP_ONE_WINDOW)) ||
+		    ( c->is_chat && (display_options & OPT_DISP_ONE_CHAT_WINDOW))) {
+			GtkWidget *notebook = (c->is_chat ? chat_notebook : convo_notebook);
 			if (event->keyval == '[') {
-				gtk_notebook_prev_page(GTK_NOTEBOOK(convo_notebook));
+				gtk_notebook_prev_page(GTK_NOTEBOOK(notebook));
 				gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
 			} else if (event->keyval == ']') {
-				gtk_notebook_next_page(GTK_NOTEBOOK(convo_notebook));
+				gtk_notebook_next_page(GTK_NOTEBOOK(notebook));
 				gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
 			} else if (event->keyval == GDK_Tab) {
-				GList *cnv = g_list_nth(conversations,
+				GList *ws = (c->is_chat ? chats : conversations);
+				GList *cnv = g_list_nth(ws,
 						gtk_notebook_get_current_page(
-							GTK_NOTEBOOK(convo_notebook)));
+							GTK_NOTEBOOK(notebook)));
 				struct conversation *d;
 				while (cnv) {
 					d = cnv->data;
@@ -668,10 +690,10 @@
 					d = NULL;
 				}
 				if (d) {
-					gtk_notebook_set_page(GTK_NOTEBOOK(convo_notebook),
-							g_list_index(conversations, d));
+					gtk_notebook_set_page(GTK_NOTEBOOK(notebook),
+							g_list_index(ws, d));
 				} else {
-					cnv = conversations;
+					cnv = ws;
 					while (cnv) {
 						d = cnv->data;
 						if (d->unseen)
@@ -681,25 +703,27 @@
 					}
 					if (d) {
 						gtk_notebook_set_page(
-								GTK_NOTEBOOK(convo_notebook),
-								g_list_index(conversations, d));
+								GTK_NOTEBOOK(notebook),
+								g_list_index(chats, d));
 					} else {
-						cnv = g_list_last(conversations);
+						cnv = g_list_last(chats);
 						if (c == cnv->data)
 							gtk_notebook_set_page(
-								GTK_NOTEBOOK(convo_notebook), 0);
+								GTK_NOTEBOOK(notebook), 0);
 						else
 							gtk_notebook_next_page(
-								GTK_NOTEBOOK(convo_notebook));
+								GTK_NOTEBOOK(notebook));
 					}
 				}
 				gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
 			}
 		}
-	} else if (!c->is_chat && (display_options & OPT_DISP_ONE_WINDOW) &&
+	} else if (((!c->is_chat && (display_options & OPT_DISP_ONE_WINDOW)) ||
+		    ( c->is_chat && (display_options & OPT_DISP_ONE_CHAT_WINDOW))) &&
 			(event->state & GDK_MOD1_MASK) && isdigit(event->keyval) &&
 			(event->keyval > '0')) {
-		gtk_notebook_set_page(GTK_NOTEBOOK(convo_notebook), event->keyval - '1');
+		GtkWidget *notebook = (c->is_chat ? chat_notebook : convo_notebook);
+		gtk_notebook_set_page(GTK_NOTEBOOK(notebook), event->keyval - '1');
 		gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
 	}
 
@@ -1449,13 +1473,17 @@
 	    (!c->is_chat && (general_options & OPT_GEN_POPUP_WINDOWS)))
 		    gdk_window_show(c->window->window);
 
-	if (((flags & WFLAG_RECV) || (flags & WFLAG_SYSTEM)) && !c->is_chat &&
-	    (display_options & OPT_DISP_ONE_WINDOW) &&
-	    (gtk_notebook_get_current_page(GTK_NOTEBOOK(convo_notebook))
-			 != g_list_index(conversations, c))) {
-		GtkWidget *label = gtk_notebook_get_tab_label(GTK_NOTEBOOK(convo_notebook),
-				gtk_notebook_get_nth_page(GTK_NOTEBOOK(convo_notebook),
-					g_list_index(conversations, c)));
+	if (((flags & WFLAG_RECV) || (flags & WFLAG_SYSTEM)) &&
+	    ((!c->is_chat && (display_options & OPT_DISP_ONE_WINDOW) &&
+	      (gtk_notebook_get_current_page(GTK_NOTEBOOK(convo_notebook))
+			!= g_list_index(conversations, c))) ||
+	     ( c->is_chat && (display_options & OPT_DISP_ONE_CHAT_WINDOW) &&
+	      (gtk_notebook_get_current_page(GTK_NOTEBOOK(chat_notebook))
+			!= g_list_index(chats, c))))) {
+		GtkWidget *notebook = (c->is_chat ? chat_notebook : convo_notebook);
+		GList *ws = (c->is_chat ? chats : conversations);
+		GtkWidget *label = gtk_notebook_get_tab_label(GTK_NOTEBOOK(notebook),
+				gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), g_list_index(ws, c)));
 		GtkStyle *style = gtk_style_new();
 		if (!GTK_WIDGET_REALIZED(label))
 			gtk_widget_realize(label);
--- a/src/gaim.h	Sun Apr 08 01:27:24 2001 +0000
+++ b/src/gaim.h	Sun Apr 08 09:26:00 2001 +0000
@@ -417,6 +417,13 @@
 extern char *opt_away_arg;
 extern char *opt_rcfile_arg;
 
+/* Globals in buddy_chat.c */
+/* it is very important that you don't use this for anything.
+ * its sole purpose is to allow all group chats to be in one
+ * window. use struct gaim_connection's buddy_chats instead. */
+extern GList *chats;
+extern GtkWidget *all_chats;
+extern GtkWidget *chat_notebook;
 
 /* Globals in away.c */
 extern struct away_message *awaymessage;
@@ -487,6 +494,7 @@
 #define OPT_DISP_IGNORE_FONTS     0x00400000
 #define OPT_DISP_IGNORE_SIZES     0x00800000
 #define OPT_DISP_ONE_WINDOW       0x01000000
+#define OPT_DISP_ONE_CHAT_WINDOW  0x02000000
 
 extern int sound_options;
 #define OPT_SOUND_LOGIN          0x00000001
--- a/src/prefs.c	Sun Apr 08 01:27:24 2001 +0000
+++ b/src/prefs.c	Sun Apr 08 09:26:00 2001 +0000
@@ -583,8 +583,8 @@
 	gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 5);
 	gtk_widget_show(label);
 
-	gaim_button(_("Show people joining/leaving in window"), &display_options, OPT_DISP_CHAT_LOGON,
-		    box);
+	gaim_button(_("Show all chats in one tabbed window"), &display_options, OPT_DISP_ONE_CHAT_WINDOW, box);
+	gaim_button(_("Show people joining/leaving in window"), &display_options, OPT_DISP_CHAT_LOGON, box);
 
 	hbox = gtk_hbox_new(FALSE, 0);
 	gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5);
@@ -2119,6 +2119,9 @@
 	if ((int)option == OPT_DISP_ONE_WINDOW)
 		tabize();
 
+	if ((int)option == OPT_DISP_ONE_CHAT_WINDOW)
+		chat_tabize();
+
 #ifdef USE_APPLET
 	update_pixmaps();
 #endif
--- a/src/server.c	Sun Apr 08 01:27:24 2001 +0000
+++ b/src/server.c	Sun Apr 08 09:26:00 2001 +0000
@@ -638,6 +638,7 @@
 
 	b = (struct conversation *)g_new0(struct conversation, 1);
 	gc->buddy_chats = g_slist_append(gc->buddy_chats, b);
+	chats = g_list_append(chats, b);
 
 	b->is_chat = TRUE;
 	b->ignored = NULL;