diff src/buddy.c @ 4359:5fb47ec9bfe4

[gaim-migrate @ 4625] Wow, okay, where to begin with this one ;) I rewrote the whole conversation backend. It is now core/UI split. Here's how it works.. Every conversation is represented by a gaim_conversation structure. This branches out into gaim_im and gaim_chat structures. Every conversation lives in (well, normally, but it doesn't have to) a gaim_window structure. This is a _CORE_ representation of a window. There can be multiple gaim_window structures around. The gaim_window and gaim_conversation structures have UI-specific operation structures associated with them. At the moment, the only UI is GTK+, and this will be for some time. Don't start thinking you can write a QT UI now. It's just not going to happen. Everything that is done on a conversation is done through the core API. This API does core processing and then calls the UI operations for the rendering and anything else. Now, what does this give the user? - Multiple windows. - Multiple tabs per window. - Draggable tabs. - Send As menu is moved to the menubar. - Menubar for chats. - Some very cool stuff in the future, like replacing, say, IRC chat windows with an X-Chat interface, or whatever. - Later on, customizable window/conversation positioning. For developers: - Fully documented API - Core/UI split - Variable checking and mostly sane handling of incorrect variables. - Logical structure to conversations, both core and UI. - Some very cool stuff in the future, like replacing, say, IRC chat windows with an X-Chat interface, or whatever. - Later on, customizable window/conversation positioning. - Oh yeah, and the beginning of a stock icon system. Now, there are things that aren't there yet. You will see tabs even if you have them turned off. This will be fixed in time. Also, the preferences will change to work with the new structure. I'm starting school in 2 days, so it may not be done immediately, but hopefully in the next week. Enjoy! committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Mon, 20 Jan 2003 09:10:23 +0000
parents 0c68d402f59f
children bca8256a91a6
line wrap: on
line diff
--- a/src/buddy.c	Mon Jan 20 07:00:10 2003 +0000
+++ b/src/buddy.c	Mon Jan 20 09:10:23 2003 +0000
@@ -150,7 +150,7 @@
 
 void handle_buddy_rename(struct buddy *b, char *prevname)
 {
-	struct conversation *cnv;
+	struct gaim_conversation *cnv;
 	struct buddy_show *bs;
 	struct group_show *gs;
 	struct group *g;
@@ -164,8 +164,8 @@
 		g_snprintf(buf, sizeof(buf), "%s", b->name);
 	gtk_ctree_node_set_text(GTK_CTREE(edittree), c, 0, buf);
 
-	if ((cnv = find_conversation(b->name)) != NULL)
-		set_convo_title(cnv);
+	if ((cnv = gaim_find_conversation(b->name)) != NULL)
+		gaim_conversation_autoset_title(cnv);
 
 	g = find_group_by_buddy(b);
 	if (!g) {
@@ -436,31 +436,34 @@
 
 void pressed_im_bud(GtkWidget *widget, struct buddy *b)
 {
-	struct conversation *c;
-
-	c = find_conversation(b->name);
+	struct gaim_conversation *c;
+
+	c = gaim_find_conversation(b->name);
 
 	if (c != NULL) {
-		gdk_window_show(c->window->window);
+		gaim_window_show(gaim_conversation_get_window(c));
 	} else {
-		c = new_conversation(b->name);
-
-		set_convo_gc(c, b->user->gc);
+		c = gaim_conversation_new(GAIM_CONV_IM, b->name);
+
+		gaim_conversation_set_user(c, b->user);
 	}
 }
 
 void pressed_im(GtkWidget *widget, struct buddy_show *b)
 {
-	struct conversation *c;
-
-	c = find_conversation(b->name);
+	struct gaim_conversation *c;
+
+	c = gaim_find_conversation(b->name);
 
 	if (c != NULL) {
-		gdk_window_show(c->window->window);
+		gaim_window_show(gaim_conversation_get_window(c));
 	} else {
-		c = new_conversation(b->name);
-
-		set_convo_gc(c, b->connlist->data);
+		struct gaim_connection *gc;
+
+		gc = (struct gaim_connection *)b->connlist->data;
+		c  = gaim_conversation_new(GAIM_CONV_IM, b->name);
+
+		gaim_conversation_set_user(c, gc->user);
 	}
 }
 
@@ -498,19 +501,28 @@
 	if (!b->connlist)
 		return FALSE;
 	if (event->type == GDK_2BUTTON_PRESS && event->button == 1) {
-		struct conversation *c;
-
-		c = find_conversation(b->name);
-
-		if (c != NULL)
-			gdk_window_show(c->window->window);
+		struct gaim_conversation *c;
+		struct gaim_connection *gc;
+
+		c = gaim_find_conversation(b->name);
+
+		if (c != NULL) {
+			struct gaim_window *win = gaim_conversation_get_window(c);
+			size_t index = gaim_conversation_get_index(c);
+
+			gaim_window_switch_conversation(win, index);
+			gaim_window_show(win);
+		}
 		else
-			c = new_conversation(b->name);
-
-		set_convo_gc(c, b->connlist->data);
-		if (im_options & OPT_IM_ONE_WINDOW)
-			raise_convo_tab(c);
-		gtk_widget_grab_focus(c->entry);
+			c = gaim_conversation_new(GAIM_CONV_IM, b->name);
+
+		gc = (struct gaim_connection *)b->connlist->data;
+		gaim_conversation_set_user(c, gc->user);
+
+		gaim_window_switch_conversation(gaim_conversation_get_window(c),
+										gaim_conversation_get_index(c));
+
+		/* XXX-GTK gtk_widget_grab_focus(c->entry); */
 	} else if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
 		static GtkWidget *menu = NULL;
 		static GList *mo_top = NULL;
@@ -783,7 +795,7 @@
 
 void ui_remove_buddy(struct buddy *rem_b)
 {
-	struct conversation *c;
+	struct gaim_conversation *c;
 	struct group *rem_g = find_group_by_buddy(rem_b);
 	struct group_show *gs;
 	struct buddy_show *bs;
@@ -818,9 +830,12 @@
 			update_num_group(gs);
 	}
 
-	c = find_conversation(rem_b->name);
+	c = gaim_find_conversation(rem_b->name);
+
 	if (c)
-		update_buttons_by_protocol(c);
+		gaim_conversation_update(c, GAIM_CONV_UPDATE_REMOVE);
+
+		/* CONVXXX update_buttons_by_protocol(c); */
 
 	/* Remove CTree node for buddy */
 	ui_remove_buddy_node(rem_g, rem_b);
@@ -938,8 +953,31 @@
 	update_idle_times();
 }
 
-static void edit_tree_move(GtkCTree *ctree, GtkCTreeNode *child, GtkCTreeNode *parent,
-			   GtkCTreeNode *sibling, gpointer data)
+void
+reset_convo_gcs()
+{
+	GList *l;
+	struct gaim_conversation *c;
+
+	for (l = gaim_get_ims(); l != NULL; l = l->next) {
+		c = (struct gaim_conversation *)l->data;
+
+		if (!g_slist_find(connections, gaim_conversation_get_gc(c))) {
+			struct aim_user *user;
+
+			if (connections == NULL)
+				user = ((struct gaim_connection *)connections->data)->user;
+			else
+				user = NULL;
+
+			gaim_conversation_set_user(c, user);
+		}
+	}
+}
+
+static void edit_tree_move(GtkCTree *ctree, GtkCTreeNode *child,
+						   GtkCTreeNode *parent, GtkCTreeNode *sibling,
+						   gpointer data)
 {
 	int *ctype, *ptype = NULL, *stype = NULL;
 
@@ -1241,7 +1279,9 @@
 {
 	GList *i;
 	struct buddy_show *b = NULL;
-	struct conversation *c;
+	struct gaim_conversation *c;
+	struct aim_user *user;
+
 	i = GTK_TREE_SELECTION_OLD(tree);
 	if (i) {
 		b = gtk_object_get_user_data(GTK_OBJECT(i->data));
@@ -1253,17 +1293,17 @@
 	if (!b->name)
 		return;
 
-	c = find_conversation(b->name);
-	if (c == NULL) {
-		c = new_conversation(b->name);
-	} else {
-		gdk_window_raise(c->window->window);
-	}
-
-	set_convo_gc(c, b->connlist->data);
+	c = gaim_find_conversation(b->name);
+
+	if (c == NULL)
+		c = gaim_conversation_new(GAIM_CONV_IM, b->name);
+	else
+		gaim_window_raise(gaim_conversation_get_window(c));
+
+	user = ((struct gaim_connection *)b->connlist->data)->user;
+	gaim_conversation_set_user(c, user);
 }
 
-
 static void info_callback(GtkWidget *widget, GtkTree *tree)
 {
 	GList *i;
@@ -1332,7 +1372,7 @@
 	char *who;
 
 	struct buddy_pounce *b;
-	struct conversation *c;
+	struct gaim_conversation *c;
 	struct aim_user *u;
 
 	GList *bp = buddy_pounces;
@@ -1356,11 +1396,12 @@
 
 		if (!g_strcasecmp(who, normalize (b->name))) {	/* find someone to pounce */
 			if (b->options & OPT_POUNCE_POPUP) {
-				c = find_conversation(name);
+				c = gaim_find_conversation(name);
+
 				if (c == NULL)
-					c = new_conversation(name);
-
-				set_convo_gc(c, u->gc);
+					c = gaim_conversation_new(GAIM_CONV_IM, name);
+
+				gaim_conversation_set_user(c, u);
 			}
 			if (b->options & OPT_POUNCE_NOTIFY) {
 				char tmp[1024];
@@ -1378,14 +1419,16 @@
 			}
 			if (b->options & OPT_POUNCE_SEND_IM) {
 				if (strlen(b->message) > 0) {
-					c = find_conversation(name);
+					c = gaim_find_conversation(name);
 
 					if (c == NULL)
-						c = new_conversation(name);
-
-					set_convo_gc(c, u->gc);
-
-					write_to_conv(c, b->message, WFLAG_SEND, NULL, time(NULL), -1);
+						c = gaim_conversation_new(GAIM_CONV_IM, name);
+
+					gaim_conversation_set_user(c, u);
+
+					gaim_conversation_write(c, NULL, b->message, -1,
+											WFLAG_SEND, time(NULL));
+
 					serv_send_im(u->gc, name, b->message, -1, 0);
 				}
 			}
@@ -2176,12 +2219,13 @@
 				g_source_remove(bs->log_timer);
 			bs->log_timer = g_timeout_add(10000, log_timeout, bs);
 			if ((bs->sound != 2) && (im_options & OPT_IM_LOGON)) {
-				struct conversation *c = find_conversation(b->name);
+				struct gaim_conversation *c = gaim_find_conversation(b->name);
 				if (c) {
 					char tmp[1024];
 					g_snprintf(tmp, sizeof(tmp), _("%s logged in."),
-							get_buddy_alias(b));
-					write_to_conv(c, tmp, WFLAG_SYSTEM, NULL, time(NULL), -1);
+							   get_buddy_alias(b));
+					gaim_conversation_write(c, NULL, tmp, -1,
+											WFLAG_SYSTEM, time(NULL));
 				} else if (clistqueue && find_queue_total_by_name(b->name)) {
 					struct queued_message *qm = g_new0(struct queued_message, 1);
 					g_snprintf(qm->name, sizeof(qm->name), "%s", b->name);
@@ -2237,12 +2281,13 @@
 		gdk_pixmap_unref(pm);
 		gdk_bitmap_unref(bm);
 		if ((bs->sound != 1) && (im_options & OPT_IM_LOGON)) {
-			struct conversation *c = find_conversation(b->name);
+			struct gaim_conversation *c = gaim_find_conversation(b->name);
 			if (c) {
 				char tmp[1024];
 				g_snprintf(tmp, sizeof(tmp), _("%s logged out."),
-						get_buddy_alias(b));
-				write_to_conv(c, tmp, WFLAG_SYSTEM, NULL, time(NULL), -1);
+						   get_buddy_alias(b));
+				gaim_conversation_write(c, NULL, tmp, -1,
+										WFLAG_SYSTEM, time(NULL));
 			} else if (clistqueue && find_queue_total_by_name(b->name)) {
 				struct queued_message *qm = g_new0(struct queued_message, 1);
 				g_snprintf(qm->name, sizeof(qm->name), "%s",