changeset 4469:d76095396a0e

[gaim-migrate @ 4744] Phase 2 of the conversation rewrite! Did you think I was done? Okay everybody, the prefs page was slightly redesigned. Not much, though. It needs an overhaul, and still, not everything works.. What we have now is: Conversations | |- IMs |- Chats `- Tabs But that's not the good part of this patch. Oh no, not close. You see, in Conversations, we now have a "Placement" drop-down box. Though this prefs page is ugly and will eventually be redesigned, this gives you the opportunity to set one of a number of different types of conversation placement options. The defaults are: - Last created window: Adds the new conversation to the last created window, like how things have been lately. - New window: Adds the new conversation to a brand new window, every time. Tabs are still there, so you can drag them between windows if you want to manually group them. - By group: This is my new favorite. This will put the new conversation in whatever window it finds first that has another member from that same group on your buddy list. If it doesn't find one, it creates a new window. If the person you IM'd or the person who IM'd you is not on your list, it gets put in a window with other people not on your list. These are the only ones implemented, but don't think you're limited to that. You see, we have new API functions for registering these Conversation Placement functions. All a plugin would need to do is to write a function, take into account OPT_CONVO_COMBINE (oh yeah, "Show IMs and chats in same tabbed window" works again), make sure the conversation is added _somewhere_, and then just register that function. If the plugin is loaded, the user can select it from the existing drop-down box. Cool, huh? Make sure to unregister the function when the plugin is unloaded. Have fun. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Thu, 30 Jan 2003 09:22:15 +0000
parents a046ff4793ca
children c800ce24c571
files src/conversation.c src/conversation.h src/gaim.h src/gaimrc.c src/prefs.c
diffstat 5 files changed, 479 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/conversation.c	Thu Jan 30 05:33:24 2003 +0000
+++ b/src/conversation.c	Thu Jan 30 09:22:15 2003 +0000
@@ -36,12 +36,22 @@
 #include "win32dep.h"
 #endif
 
+struct ConvPlacementData
+{
+	char *name;
+	gaim_conv_placement_fnc fnc;
+
+};
+
 #define SEND_TYPED_TIMEOUT 5000
 
 static GList *conversations = NULL;
 static GList *ims = NULL;
 static GList *chats = NULL;
 static GList *windows = NULL;
+static GList *conv_placement_fncs = NULL;
+static gaim_conv_placement_fnc place_conv = NULL;
+static int place_conv_index = -1;
 
 static gint
 insertname_compare(gconstpointer one, gconstpointer two)
@@ -770,6 +780,62 @@
 	return windows;
 }
 
+struct gaim_window *
+gaim_get_first_window_with_type(GaimConversationType type)
+{
+	GList *wins, *convs;
+	struct gaim_window *win;
+	struct gaim_conversation *conv;
+
+	if (type == GAIM_CONV_UNKNOWN)
+		return NULL;
+
+	for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) {
+		win = (struct gaim_window *)wins->data;
+
+		for (convs = gaim_window_get_conversations(win);
+			 convs != NULL;
+			 convs = convs->next) {
+
+			conv = (struct gaim_conversation *)convs->data;
+
+			if (gaim_conversation_get_type(conv) == type)
+				return win;
+		}
+	}
+
+	return NULL;
+}
+
+struct gaim_window *
+gaim_get_last_window_with_type(GaimConversationType type)
+{
+	GList *wins, *convs;
+	struct gaim_window *win;
+	struct gaim_conversation *conv;
+
+	if (type == GAIM_CONV_UNKNOWN)
+		return NULL;
+
+	for (wins = g_list_last(gaim_get_windows());
+		 wins != NULL;
+		 wins = wins->prev) {
+
+		win = (struct gaim_window *)wins->data;
+
+		for (convs = gaim_window_get_conversations(win);
+			 convs != NULL;
+			 convs = convs->next) {
+
+			conv = (struct gaim_conversation *)convs->data;
+
+			if (gaim_conversation_get_type(conv) == type)
+				return win;
+		}
+	}
+
+	return NULL;
+}
 
 /**************************************************************************
  * Conversation API
@@ -778,7 +844,6 @@
 gaim_conversation_new(GaimConversationType type, const char *name)
 {
 	struct gaim_conversation *conv;
-	struct gaim_window *window;
 
 	if (type == GAIM_CONV_UNKNOWN)
 		return NULL;
@@ -830,19 +895,21 @@
 	 * Create a window if one does not exist. If it does, use the last
 	 * created window.
 	 */
-	/* XXX */
-#if 0
-	if (windows == NULL || gaim_window_get_conversation_count(windows->data) == 2)
-#endif
-	if (windows == NULL)
-		window = gaim_window_new();
-	else
-		window = g_list_last(windows)->data;
-
-	gaim_window_add_conversation(window, conv);
-
-	/* Ensure the window is visible. */
-	gaim_window_show(window);
+	if (windows == NULL) {
+		struct gaim_window *win;
+
+		win = gaim_window_new();
+		gaim_window_add_conversation(win, conv);
+
+		/* Ensure the window is visible. */
+		gaim_window_show(win);
+	}
+	else {
+		if (place_conv == NULL)
+			gaim_conv_placement_set_active(0);
+
+		place_conv(conv);
+	}
 
 	plugin_event(event_new_conversation, name);
 
@@ -1946,3 +2013,256 @@
 
 	return NULL;
 }
+
+/**************************************************************************
+ * Conversation placement functions
+ **************************************************************************/
+/* This one places conversations in the last made window. */
+static void
+conv_placement_last_created_win(struct gaim_conversation *conv)
+{
+	struct gaim_window *win;
+
+	if (convo_options & OPT_CONVO_COMBINE)
+		win = g_list_last(gaim_get_windows())->data;
+	else
+		win = gaim_get_last_window_with_type(gaim_conversation_get_type(conv));
+
+	if (win == NULL) {
+		win = gaim_window_new();
+
+		gaim_window_add_conversation(win, conv);
+		gaim_window_show(win);
+	}
+	else
+		gaim_window_add_conversation(win, conv);
+}
+
+/* This one places each conversation in its own window. */
+static void
+conv_placement_new_window(struct gaim_conversation *conv)
+{
+	struct gaim_window *win;
+
+	win = gaim_window_new();
+
+	gaim_window_add_conversation(win, conv);
+
+	gaim_window_show(win);
+}
+
+/*
+ * This groups things by, well, group. Buddies from groups will always be
+ * grouped together, and a buddy from a group not belonging to any currently
+ * open windows will get a new window.
+ */
+static void
+conv_placement_by_group(struct gaim_conversation *conv)
+{
+	struct gaim_window *win;
+	GaimConversationType type;
+
+	type = gaim_conversation_get_type(conv);
+
+	if (type != GAIM_CONV_IM) {
+		win = gaim_get_last_window_with_type(type);
+
+		if (win == NULL)
+			conv_placement_new_window(conv);
+		else
+			gaim_window_add_conversation(win, conv);
+	}
+	else {
+		struct buddy *b;
+		struct group *grp = NULL;
+		GList *wins, *convs;
+
+		b = find_buddy(gaim_conversation_get_user(conv),
+					   gaim_conversation_get_name(conv));
+
+		if (b != NULL)
+			grp = find_group_by_buddy(b);
+
+		/* Go through the list of IMs and find one with this group. */
+		for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) {
+			struct gaim_window *win2;
+			struct gaim_conversation *conv2;
+			struct buddy *b2;
+			struct group *grp2 = NULL;
+
+			win2 = (struct gaim_window *)wins->data;
+
+			for (convs = gaim_window_get_conversations(win2);
+				 convs != NULL;
+				 convs = convs->next) {
+
+				conv2 = (struct gaim_conversation *)convs->data;
+
+				b2 = find_buddy(gaim_conversation_get_user(conv2),
+								gaim_conversation_get_name(conv2));
+
+				if (b2 != NULL)
+					grp2 = find_group_by_buddy(b2);
+
+				if ((grp == NULL && grp2 == NULL) ||
+					(grp != NULL && grp2 != NULL &&
+					 !strncmp(grp2->name, grp->name, 80))) {
+
+					gaim_window_add_conversation(win2, conv);
+
+					return;
+				}
+			}
+		}
+
+		/* Make a new window. */
+		conv_placement_new_window(conv);
+	}
+}
+
+static int
+add_conv_placement_fnc(const char *name, gaim_conv_placement_fnc fnc)
+{
+	struct ConvPlacementData *data;
+
+	data = g_malloc0(sizeof(struct ConvPlacementData));
+
+	data->name = g_strdup(name);
+	data->fnc  = fnc;
+
+	conv_placement_fncs = g_list_append(conv_placement_fncs, data);
+
+	return gaim_conv_placement_get_fnc_count() - 1;
+}
+
+static void
+ensure_default_funcs(void)
+{
+	if (conv_placement_fncs == NULL) {
+		add_conv_placement_fnc(_("Last created window"),
+							   conv_placement_last_created_win);
+		add_conv_placement_fnc(_("New window"),
+							   conv_placement_new_window);
+		add_conv_placement_fnc(_("By group"),
+							   conv_placement_by_group);
+	}
+}
+
+int
+gaim_conv_placement_add_fnc(const char *name, gaim_conv_placement_fnc fnc)
+{
+	if (name == NULL || fnc == NULL)
+		return -1;
+
+	if (conv_placement_fncs == NULL)
+		ensure_default_funcs();
+
+	return add_conv_placement_fnc(name, fnc);
+}
+
+void
+gaim_conv_placement_remove_fnc(int index)
+{
+	struct ConvPlacementData *data;
+	GList *node;
+
+	if (index < 0 || index > g_list_length(conv_placement_fncs))
+		return;
+
+	node = g_list_nth(conv_placement_fncs, index);
+	data = (struct ConvPlacementData *)node->data;
+
+	g_free(data->name);
+	g_free(data);
+
+	conv_placement_fncs = g_list_remove_link(conv_placement_fncs, node);
+	g_list_free_1(node);
+}
+
+int
+gaim_conv_placement_get_fnc_count(void)
+{
+	ensure_default_funcs();
+
+	return g_list_length(conv_placement_fncs);
+}
+
+const char *
+gaim_conv_placement_get_name(int index)
+{
+	struct ConvPlacementData *data;
+
+	ensure_default_funcs();
+
+	if (index < 0 || index > g_list_length(conv_placement_fncs))
+		return NULL;
+
+	data = g_list_nth_data(conv_placement_fncs, index);
+
+	if (data == NULL)
+		return NULL;
+
+	return data->name;
+}
+
+gaim_conv_placement_fnc
+gaim_conv_placement_get_fnc(int index)
+{
+	struct ConvPlacementData *data;
+
+	ensure_default_funcs();
+
+	if (index < 0 || index > g_list_length(conv_placement_fncs))
+		return NULL;
+
+	data = g_list_nth_data(conv_placement_fncs, index);
+
+	if (data == NULL)
+		return NULL;
+
+	return data->fnc;
+}
+
+int
+gaim_conv_placement_get_fnc_index(gaim_conv_placement_fnc fnc)
+{
+	struct ConvPlacementData *data;
+	GList *node;
+	int i;
+
+	ensure_default_funcs();
+
+	for (node = conv_placement_fncs, i = 0;
+		 node != NULL;
+		 node = node->next, i++) {
+
+		data = (struct ConvPlacementData *)node->data;
+
+		if (data->fnc == fnc)
+			return i;
+	}
+
+	return -1;
+}
+
+int
+gaim_conv_placement_get_active(void)
+{
+	return place_conv_index;
+}
+
+void
+gaim_conv_placement_set_active(int index)
+{
+	gaim_conv_placement_fnc fnc;
+
+	ensure_default_funcs();
+
+	fnc = gaim_conv_placement_get_fnc(index);
+
+	if (fnc == NULL)
+		return;
+
+	place_conv = fnc;
+	place_conv_index = index;
+}
--- a/src/conversation.h	Thu Jan 30 05:33:24 2003 +0000
+++ b/src/conversation.h	Thu Jan 30 09:22:15 2003 +0000
@@ -224,6 +224,7 @@
 	void *ui_data;                           /**< UI-specific data.       */
 };
 
+typedef void (*gaim_conv_placement_fnc)(struct gaim_conversation *);
 
 /**************************************************************************/
 /** @name Conversation Window API                                         */
@@ -389,6 +390,24 @@
  */
 GList *gaim_get_windows(void);
 
+/**
+ * Returns the first window containing a conversation of the specified type.
+ *
+ * @param type The conversation type.
+ *
+ * @return The window if found, or @c NULL if not found.
+ */
+struct gaim_window *gaim_get_first_window_with_type(GaimConversationType type);
+
+/**
+ * Returns the last window containing a conversation of the specified type.
+ *
+ * @param type The conversation type.
+ *
+ * @return The window if found, or @c NULL if not found.
+ */
+struct gaim_window *gaim_get_last_window_with_type(GaimConversationType type);
+
 /*@}*/
 
 /**************************************************************************/
@@ -472,17 +491,6 @@
 struct aim_user *gaim_conversation_get_user(
 		const struct gaim_conversation *conv);
 
-#if 0
-/**
- * Sets the specified conversation's gaim_connection.
- *
- * @param conv The conversation.
- * @param gc   The gaim_connection.
- */
-void gaim_conversation_set_gc(struct gaim_conversation *conv,
-							  struct gaim_connection *gc);
-#endif
-
 /**
  * Returns the specified conversation's gaim_connection.
  *
@@ -1064,4 +1072,78 @@
 
 /*@}*/
 
+/**************************************************************************/
+/** @name Conversation Placement Functions                                */
+/**************************************************************************/
+
+/**
+ * Adds a conversation placement function to the list of possible functions.
+ *
+ * @param name The name of the function.
+ * @param fnc  A pointer to the function.
+ *
+ * @return The index of this entry.
+ */
+int gaim_conv_placement_add_fnc(const char *name, gaim_conv_placement_fnc fnc);
+
+/**
+ * Removes a conversation placement function from the list of possible
+ * functions.
+ *
+ * @param index The index of the function.
+ */
+void gaim_conv_placement_remove_fnc(int index);
+
+/**
+ * Returns the number of conversation placement functions.
+ *
+ * @return The number of registered functions.
+ */
+int gaim_conv_placement_get_fnc_count(void);
+
+/**
+ * Returns the name of the conversation placement function at the
+ * specified index.
+ *
+ * @param index The index.
+ *
+ * @return The name of the function, or @c NULL if this index is out of
+ *         range.
+ */
+const char *gaim_conv_placement_get_name(int index);
+
+/**
+ * Returns a pointer to the conversation placement function at the
+ * specified index.
+ *
+ * @param index The index.
+ *
+ * @return A pointer to the function.
+ */
+gaim_conv_placement_fnc gaim_conv_placement_get_fnc(int index);
+
+/**
+ * Returns the index of the specified conversation placement function.
+ *
+ * @param fnc A pointer to the registered function.
+ *
+ * @return The index of the conversation, or -1 if the function is not
+ *         registered.
+ */
+int gaim_conv_placement_get_fnc_index(gaim_conv_placement_fnc fnc);
+
+/**
+ * Returns the index of the active conversation placement function.
+ *
+ * @param index The index of the active function.
+ */
+int gaim_conv_placement_get_active(void);
+
+/**
+ * Sets the active conversation placement function.
+ *
+ * @param index The index of the function.
+ */
+void gaim_conv_placement_set_active(int index);
+
 #endif /* _CONVERSATION_H_ */
--- a/src/gaim.h	Thu Jan 30 05:33:24 2003 +0000
+++ b/src/gaim.h	Thu Jan 30 09:22:15 2003 +0000
@@ -280,6 +280,8 @@
 #define OPT_CHAT_OLD_STYLE_TAB		0x00000100
 #define OPT_CHAT_COLORIZE               0x00000200
 
+extern guint conv_placement_option;
+
 extern guint font_options;
 #define OPT_FONT_BOLD			0x00000001
 #define OPT_FONT_ITALIC			0x00000002
--- a/src/gaimrc.c	Thu Jan 30 05:33:24 2003 +0000
+++ b/src/gaimrc.c	Thu Jan 30 09:22:15 2003 +0000
@@ -53,6 +53,7 @@
 guint blist_options;
 guint convo_options;
 guint im_options;
+guint conv_placement_option;
 guint chat_options;
 guint font_options;
 guint sound_options;
@@ -773,6 +774,9 @@
 			convo_options = atoi(p->value[0]);
 		} else if (!strcmp(p->option, "im_options")) {
 			im_options = atoi(p->value[0]);
+		} else if (!strcmp(p->option, "conv_placement")) {
+			conv_placement_option = atoi(p->value[0]);
+			gaim_conv_placement_set_active(conv_placement_option);
 		} else if (!strcmp(p->option, "chat_options")) {
 			chat_options = atoi(p->value[0]);
 		} else if (!strcmp(p->option, "font_options")) {
@@ -888,6 +892,7 @@
 	fprintf(f, "\tblist_options { %u }\n", blist_options);
 	fprintf(f, "\tconvo_options { %u }\n", convo_options);
 	fprintf(f, "\tim_options { %u }\n", im_options);
+	fprintf(f, "\tconv_placement { %u }\n", conv_placement_option);
 	fprintf(f, "\tchat_options { %u }\n", chat_options);
 	fprintf(f, "\tfont_options { %u }\n", font_options);
 	fprintf(f, "\tsound_options { %u }\n", sound_options);
@@ -1217,6 +1222,8 @@
 		OPT_CONVO_SHOW_SMILEY |
 		OPT_CONVO_CHECK_SPELLING;
 
+	conv_placement_option = 0;
+
 	im_options =
 		OPT_IM_LOGON |
 		OPT_IM_BUTTON_XPM |
--- a/src/prefs.c	Thu Jan 30 05:33:24 2003 +0000
+++ b/src/prefs.c	Thu Jan 30 09:22:15 2003 +0000
@@ -566,6 +566,42 @@
 	return ret;
 }
 
+GtkWidget *conv_page() {
+	GtkWidget *ret;
+	GtkWidget *vbox;
+	GtkWidget *label;
+	GtkSizeGroup *sg;
+	GList *names = NULL;
+	int i;
+
+	ret = gtk_vbox_new(FALSE, 18);
+	gtk_container_set_border_width(GTK_CONTAINER(ret), 12);
+
+	sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+	vbox = make_frame(ret, _("Conversations"));
+
+	/* Build a list of names. */
+	for (i = 0; i < gaim_conv_placement_get_fnc_count(); i++) {
+		names = g_list_append(names, (char *)gaim_conv_placement_get_name(i));
+		names = g_list_append(names, GINT_TO_POINTER(i));
+	}
+
+	label = gaim_dropdown_from_list(vbox, _("_Placement:"),
+									&conv_placement_option, -1, names);
+
+	g_list_free(names);
+
+	gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
+	gtk_size_group_add_widget(sg, label);
+
+	gaim_button(_("Show IMs and chats in _same tabbed window."),
+				&convo_options, OPT_CONVO_COMBINE, vbox);
+
+	gtk_widget_show_all(ret);
+
+	return ret;
+}
+
 GtkWidget *im_page() {
 	GtkWidget *ret;
 	GtkWidget *vbox;
@@ -681,7 +717,6 @@
 	gtk_size_group_add_widget(sg, dd);
 
 	vbox = make_frame (ret, _("Tab Options"));
-	gaim_button(_("Show IMs and chats in _same tabbed window."), &convo_options, OPT_CONVO_COMBINE, vbox);
 	button = gaim_button(_("Show _close button on tabs."), &convo_options, OPT_CONVO_NO_X_ON_TAB, vbox);
 	convo_options ^= OPT_CONVO_NO_X_ON_TAB;
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(button), !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)));
@@ -1665,7 +1700,7 @@
 }
 
 void prefs_notebook_init() {
-	GtkTreeIter p, c;
+	GtkTreeIter p, p2, c;
 #if USE_PLUGINS
 	GtkWidget *(*config)();
 	GList *l = plugins;
@@ -1677,9 +1712,10 @@
 	prefs_notebook_add_page(_("Message Text"), NULL, messages_page(), &c, &p, notebook_page++);
 	prefs_notebook_add_page(_("Shortcuts"), NULL, hotkeys_page(), &c, &p, notebook_page++);
 	prefs_notebook_add_page(_("Buddy List"), NULL, list_page(), &c, &p, notebook_page++);
-	prefs_notebook_add_page(_("IM Window"), NULL, im_page(), &c, &p, notebook_page++);
-	prefs_notebook_add_page(_("Chat Window"), NULL, chat_page(), &c, &p, notebook_page++);
-	prefs_notebook_add_page(_("Tabs"), NULL, tab_page(), &c, &p, notebook_page++);
+	prefs_notebook_add_page(_("Conversations"), NULL, conv_page(), &p2, &p, notebook_page++);
+	prefs_notebook_add_page(_("IMs"), NULL, im_page(), &c, &p2, notebook_page++);
+	prefs_notebook_add_page(_("Chats"), NULL, chat_page(), &c, &p2, notebook_page++);
+	prefs_notebook_add_page(_("Tabs"), NULL, tab_page(), &c, &p2, notebook_page++);
 	prefs_notebook_add_page(_("Proxy"), NULL, proxy_page(), &p, NULL, notebook_page++);
 #ifndef _WIN32
 	/* We use the registered default browser in windows */
@@ -2275,17 +2311,17 @@
 	} else if (option == (int*)&im_options) { 
 		if (clear == (OPT_IM_SIDE_TAB | OPT_IM_BR_TAB))
 			gaim_gtkconv_update_tabs();
-			/* CONV XXX update_im_tabs(); */
 		else if (clear == (OPT_IM_BUTTON_TEXT | OPT_IM_BUTTON_XPM))
 			gaim_gtkconv_update_im_button_style();
 	} else if (option == (int*)&chat_options) {
 		if (clear == (OPT_CHAT_SIDE_TAB | OPT_CHAT_BR_TAB))
 			gaim_gtkconv_update_tabs();
-			/* CONV XXX update_chat_tabs(); */
 		else if (clear == (OPT_CHAT_BUTTON_TEXT | OPT_CHAT_BUTTON_XPM))
 			gaim_gtkconv_update_chat_button_style();
 	} else if (option == (int*)&blist_options) {
 		set_blist_tab();
+	} else if (option == (int *)&conv_placement_option) {
+		gaim_conv_placement_set_active(conv_placement_option);
 	}
 }