[gaim-migrate @ 4625]

Mon, 20 Jan 2003 09:10:23 +0000

author
Christian Hammond <chipx86@chipx86.com>
date
Mon, 20 Jan 2003 09:10:23 +0000
changeset 4359
cf899ee07d1d
parent 4358
a6fc799d5c40
child 4360
28aa945b7c16

[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!

ChangeLog file | annotate | diff | comparison | revisions
pixmaps/Makefile.am file | annotate | diff | comparison | revisions
pixmaps/tb_drag_arrow_down.xpm file | annotate | diff | comparison | revisions
pixmaps/tb_drag_arrow_left.xpm file | annotate | diff | comparison | revisions
pixmaps/tb_drag_arrow_right.xpm file | annotate | diff | comparison | revisions
pixmaps/tb_drag_arrow_up.xpm file | annotate | diff | comparison | revisions
plugins/filectl.c file | annotate | diff | comparison | revisions
plugins/history.c file | annotate | diff | comparison | revisions
plugins/iconaway.c file | annotate | diff | comparison | revisions
plugins/notify.c file | annotate | diff | comparison | revisions
plugins/ticker/ticker.c file | annotate | diff | comparison | revisions
plugins/timestamp.c file | annotate | diff | comparison | revisions
src/Makefile.am file | annotate | diff | comparison | revisions
src/Makefile.mingw file | annotate | diff | comparison | revisions
src/aim.c file | annotate | diff | comparison | revisions
src/away.c file | annotate | diff | comparison | revisions
src/buddy.c file | annotate | diff | comparison | revisions
src/buddy_chat.c file | annotate | diff | comparison | revisions
src/conversation.c file | annotate | diff | comparison | revisions
src/conversation.h file | annotate | diff | comparison | revisions
src/convo.h file | annotate | diff | comparison | revisions
src/core.h file | annotate | diff | comparison | revisions
src/dialogs.c file | annotate | diff | comparison | revisions
src/dnd-hints.c file | annotate | diff | comparison | revisions
src/dnd-hints.h file | annotate | diff | comparison | revisions
src/gaim.h file | annotate | diff | comparison | revisions
src/gtkconv.c file | annotate | diff | comparison | revisions
src/gtkconv.h file | annotate | diff | comparison | revisions
src/gtkutils.c file | annotate | diff | comparison | revisions
src/gtkutils.h file | annotate | diff | comparison | revisions
src/html.c file | annotate | diff | comparison | revisions
src/log.c file | annotate | diff | comparison | revisions
src/multi.c file | annotate | diff | comparison | revisions
src/perl.c file | annotate | diff | comparison | revisions
src/prefs.c file | annotate | diff | comparison | revisions
src/protocols/irc/irc.c file | annotate | diff | comparison | revisions
src/protocols/jabber/jabber.c file | annotate | diff | comparison | revisions
src/protocols/msn/msn.c file | annotate | diff | comparison | revisions
src/protocols/napster/napster.c file | annotate | diff | comparison | revisions
src/protocols/oscar/oscar.c file | annotate | diff | comparison | revisions
src/protocols/toc/toc.c file | annotate | diff | comparison | revisions
src/prpl.c file | annotate | diff | comparison | revisions
src/server.c file | annotate | diff | comparison | revisions
src/stock.c file | annotate | diff | comparison | revisions
src/stock.h file | annotate | diff | comparison | revisions
src/themes.c file | annotate | diff | comparison | revisions
src/ui.h file | annotate | diff | comparison | revisions
src/util.c file | annotate | diff | comparison | revisions
--- a/ChangeLog	Mon Jan 20 07:00:10 2003 +0000
+++ b/ChangeLog	Mon Jan 20 09:10:23 2003 +0000
@@ -14,6 +14,8 @@
 	* Quit Gaim remotely with gaim-remote. (Thanks, John Silvestri)
 	* Added rudimentary support for X11R6 session management. (Thanks, 
 	  Robert McQueen)
+	* Conversation backend and UI are now separated. (Thanks,
+	  Christian Hammond)
 
 	Plugins:
 	* Tray icon plugin--replaces the old GNOME applet. You'll need 
@@ -115,7 +117,7 @@
 		- Account editor (rewritten by Christian Hammond)
 		- Preferences dialog (rewritten by Sean Egan)
 		- SignOn Screen (rewritten by Rob Flynn)
-		- Conversation Window (needs tooltips)
+		- Conversation Window
 		- Chat Window (sort of: needs menu bar, tooltips)
 		- GtkIMHtml (Ari Pollak, Christian Hammond)
 		- Buddy Icons
@@ -137,6 +139,8 @@
 	* Word-wrapping on mail notification text (Thanks, Andrew Molloy)
 	* Generic File Transfer PRPL interface (Thanks, William T. Mahan)
 	* Better supression of auto-responses (Thanks, Joshua Blanton)
+	* Drag-and-drop tabs in conversations, and multiple windows with tabs
+	  in each (Thanks, Christian Hammond)
 
 version 0.59 (06/24/2002):
 	* Hungarian translation added (Thanks, Sutto Zoltan)
--- a/pixmaps/Makefile.am	Mon Jan 20 07:00:10 2003 +0000
+++ b/pixmaps/Makefile.am	Mon Jan 20 09:10:23 2003 +0000
@@ -50,6 +50,10 @@
 		status-game.xpm			\
 		status-here.xpm			\
 		status-idle.xpm			\
+		tb_drag_arrow_down.xpm  \
+		tb_drag_arrow_left.xpm  \
+		tb_drag_arrow_right.xpm \
+		tb_drag_arrow_up.xpm    \
 		tb_forward.xpm			\
 		tb_redo.xpm			\
 		tb_refresh.xpm			\
@@ -72,7 +76,7 @@
 gaimmenupix_DATA = insert-image-small.png about_menu.png import-menu.png accounts-menu.png insert-link-small.png
 
 gaimdistpixdir = $(datadir)/pixmaps/gaim
-gaimdistpix_DATA = away.png connect.png msgpend.png offline.png online.png msgunread.png logo.png
+gaimdistpix_DATA = away.png connect.png msgpend.png offline.png online.png msgunread.png logo.png tb_drag_arrow_down.xpm tb_drag_arrow_left.xpm tb_drag_arrow_right.xpm tb_drag_arrow_up.xpm
 
 distpixmapdir = $(datadir)/pixmaps
 distpixmap_DATA = gaim.png
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pixmaps/tb_drag_arrow_down.xpm	Mon Jan 20 09:10:23 2003 +0000
@@ -0,0 +1,21 @@
+/* XPM */
+static const char * arrow_down_xpm[] = {
+"13 16 2 1",
+" 	c None",
+".	c #FF0000",
+"     ...     ",
+"     ...     ",
+"     ...     ",
+"     ...     ",
+"     ...     ",
+"     ...     ",
+"     ...     ",
+"     ...     ",
+"     ...     ",
+".............",
+" ........... ",
+"  .........  ",
+"   .......   ",
+"    .....    ",
+"     ...     ",
+"      .      "};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pixmaps/tb_drag_arrow_left.xpm	Mon Jan 20 09:10:23 2003 +0000
@@ -0,0 +1,18 @@
+/* XPM */
+static char * tb_drag_arrow_left_xpm[] = {
+"16 13 2 1",
+" 	c None",
+".	c #FF0000",
+"      .         ",
+"     ..         ",
+"    ...         ",
+"   ....         ",
+"  .....         ",
+" ...............",
+"................",
+" ...............",
+"  .....         ",
+"   ....         ",
+"    ...         ",
+"     ..         ",
+"      .         "};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pixmaps/tb_drag_arrow_right.xpm	Mon Jan 20 09:10:23 2003 +0000
@@ -0,0 +1,18 @@
+/* XPM */
+static char * tb_drag_arrow_left_xpm[] = {
+"16 13 2 1",
+" 	c None",
+".	c #FF0000",
+"         .      ",
+"         ..     ",
+"         ...    ",
+"         ....   ",
+"         .....  ",
+"............... ",
+"................",
+"............... ",
+"         .....  ",
+"         ....   ",
+"         ...    ",
+"         ..     ",
+"         .      "};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pixmaps/tb_drag_arrow_up.xpm	Mon Jan 20 09:10:23 2003 +0000
@@ -0,0 +1,21 @@
+/* XPM */
+static const char * arrow_up_xpm[] = {
+"13 16 2 1",
+" 	c None",
+".	c #FF0000",
+"      .      ",
+"     ...     ",
+"    .....    ",
+"   .......   ",
+"  .........  ",
+" ........... ",
+".............",
+"     ...     ",
+"     ...     ",
+"     ...     ",
+"     ...     ",
+"     ...     ",
+"     ...     ",
+"     ...     ",
+"     ...     ",
+"     ...     "};
--- a/plugins/filectl.c	Mon Jan 20 07:00:10 2003 +0000
+++ b/plugins/filectl.c	Mon Jan 20 09:10:23 2003 +0000
@@ -72,11 +72,11 @@
 				signoff_all(NULL, NULL);
 			free(arg1);
 		} else if (!strncasecmp(command, "send", 4)) {
-			struct conversation *c;
+			struct gaim_conversation *c;
 			arg1 = getarg(buffer, 1, 0);
 			arg2 = getarg(buffer, 2, 1);
 			c = find_conversation(arg1);
-			if (!c) c = new_conversation(arg1);
+			if (!c) c = gaim_conversation_new(GAIM_CONV_IM, arg1);
 			write_to_conv(c, arg2, WFLAG_SEND, NULL, time(NULL), -1);
 			serv_send_im(c->gc, arg1, arg2, -1, 0);
 			free(arg1);
--- a/plugins/history.c	Mon Jan 20 07:00:10 2003 +0000
+++ b/plugins/history.c	Mon Jan 20 09:10:23 2003 +0000
@@ -19,7 +19,8 @@
 
 void historize (char *name, void *data)
 {
-	struct conversation *c = find_conversation(name);
+	struct gaim_conversation *c = gaim_find_conversation(name);
+	struct gaim_gtk_conversation *gtkconv;
 	struct stat st;
 	FILE *fd;
 	char *userdir = g_strdup(gaim_user_dir());
@@ -52,7 +53,9 @@
 	if(*tmp == '<')
 		options |= GTK_IMHTML_NO_NEWLINE;
 
-	gtk_imhtml_append_text(GTK_IMHTML(c->text), tmp, strlen(tmp), options);
+	gtkconv = GAIM_GTK_CONVERSATION(c);
+
+	gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), tmp, strlen(tmp), options);
 
 	g_free(userdir);
 	g_free(logfile);
--- a/plugins/iconaway.c	Mon Jan 20 07:00:10 2003 +0000
+++ b/plugins/iconaway.c	Mon Jan 20 09:10:23 2003 +0000
@@ -16,22 +16,38 @@
 
 G_MODULE_IMPORT GtkWidget *imaway;
 G_MODULE_IMPORT GtkWidget *blist;
-G_MODULE_IMPORT GtkWidget *all_chats;
+/* XXX G_MODULE_IMPORT GtkWidget *all_chats; */
 G_MODULE_IMPORT GtkWidget *all_convos;
 
 #ifdef USE_APPLET
 extern void applet_destroy_buddy();
 #endif
 
-void iconify_windows(struct gaim_connection *gc, char *state, char *message, void *data) {
+void iconify_windows(struct gaim_connection *gc, char *state,
+					 char *message, void *data) {
+	struct gaim_window *win;
+	GList *windows;
+
 	if (!imaway || !gc->away)
 		return;
+
 	gtk_window_iconify(GTK_WINDOW(imaway));
 	hide_buddy_list();
-	if (all_convos)
-		gtk_window_iconify(GTK_WINDOW(all_convos));
-	if (all_chats)
-		gtk_window_iconify(GTK_WINDOW(all_chats));
+
+	for (windows = gaim_get_windows();
+		 windows != NULL;
+		 windows = windows->next) {
+
+		win = (struct gaim_window *)windows->data;
+
+		if (gaim_window_get_ops(win) == gaim_get_gtk_window_ops()) {
+			struct gaim_gtk_window *gtkwin;
+
+			gtkwin = GAIM_GTK_WINDOW(win);
+
+			gtk_window_iconify(GTK_WINDOW(gtkwin->window));
+		}
+	}
 }
 
 /*
--- a/plugins/notify.c	Mon Jan 20 07:00:10 2003 +0000
+++ b/plugins/notify.c	Mon Jan 20 09:10:23 2003 +0000
@@ -70,46 +70,38 @@
 void quote_add(GtkWidget *widget);
 gboolean quote_remove(GtkWidget *widget);
 /* urgent functions */
-void urgent_add(struct conversation *c);
-gboolean urgent_remove(struct conversation *c);
-
-struct conversation *find_chat(struct gaim_connection *gc, int id) {
-	GList *cnv = chats;
-	struct conversation *c;
-
-	while (cnv) {
-		c = (struct conversation *) cnv->data;
+void urgent_add(struct gaim_conversation *c);
+gboolean urgent_remove(struct gaim_conversation *c);
 
-		if (c && (c->gc == gc) && c->is_chat && (c->id == id))
-			return c;
-
-		cnv = cnv->next;
-	}
-	return NULL;
-}
-
-int notify(struct conversation *cnv) {
+int notify(struct gaim_conversation *cnv) {
+	struct gaim_gtk_window *gtkwin;
 	Window focus_return;
 	int revert_to_return;
 
-	XGetInputFocus(GDK_WINDOW_XDISPLAY(cnv->window->window), &focus_return, &revert_to_return);
+	gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(cnv));
+
+	XGetInputFocus(GDK_WINDOW_XDISPLAY(gtkwin->window->window), &focus_return, &revert_to_return);
 
 	if ((choice & NOTIFY_IN_FOCUS) ||
-			focus_return != GDK_WINDOW_XWINDOW(cnv->window->window)) {
+			focus_return != GDK_WINDOW_XWINDOW(gtkwin->window->window)) {
 		if (method & METHOD_STRING)
-			string_add(cnv->window);
+			string_add(gtkwin->window);
 		if (method & METHOD_COUNT)
-			count_add(cnv->window, 0);
+			count_add(gtkwin->window, 0);
 		if (method & METHOD_QUOTE)
-			quote_add(cnv->window);
+			quote_add(gtkwin->window);
 		if (method & METHOD_URGENT)
 			urgent_add(cnv);
 	}
 	return 0;
 }
 
-guint unnotify(struct conversation *c, gboolean clean) {
+guint unnotify(struct gaim_conversation *c, gboolean clean) {
+	struct gaim_gtk_window *gtkwin;
 	guint option = 0;
+
+	gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c));
+	
 	/* The top level ifs check whether we are either cleaning all methods,
 	 * or whether we have that method is currently selected.
 	 * If we do then they are cleaned
@@ -118,15 +110,15 @@
 	 * and if that method is currently selected.
 	 * If we did and it is then set option so that it can be re-added */
 	if (clean || (method & METHOD_QUOTE))
-		if (quote_remove(c->window) && (method & METHOD_QUOTE))
+		if (quote_remove(gtkwin->window) && (method & METHOD_QUOTE))
 			option ^= METHOD_QUOTE;
 	
 	if (clean || (method & METHOD_COUNT))
-		if (count_remove(c->window) && (method & METHOD_COUNT))
+		if (count_remove(gtkwin->window) && (method & METHOD_COUNT))
 			option ^= METHOD_COUNT;
 
 	if (clean || (method & METHOD_STRING))
-		if (string_remove(c->window) && (method & METHOD_STRING))
+		if (string_remove(gtkwin->window) && (method & METHOD_STRING))
 			option ^= METHOD_STRING;
 
 	if (clean || (method & METHOD_URGENT))
@@ -137,7 +129,7 @@
 }
 
 void chat_recv_im(struct gaim_connection *gc, int id, char **who, char **text) {
-	struct conversation *c = find_chat(gc, id);
+	struct gaim_conversation *c = gaim_find_chat(gc, id);
 
 	if (c && (type & TYPE_CHAT))
 		notify(c);
@@ -145,7 +137,7 @@
 }
 
 void chat_sent_im(struct gaim_connection *gc, int id, char **text) {
-	struct conversation *c = find_chat(gc, id);
+	struct gaim_conversation *c = gaim_find_chat(gc, id);
 
 	if (c && (type & TYPE_CHAT))
 		unnotify(c, FALSE);
@@ -153,7 +145,7 @@
 }
 
 int im_recv_im(struct gaim_connection *gc, char **who, char **what, void *m) {
-	struct conversation *c = find_conversation(*who);
+	struct gaim_conversation *c = gaim_find_conversation(*who);
 
 	if (c && (type & TYPE_IM))
 		notify(c);
@@ -161,70 +153,81 @@
 }
 
 int im_sent_im(struct gaim_connection *gc, char *who, char **what, void *m) {
-	struct conversation *c = find_conversation(who);
+	struct gaim_conversation *c = gaim_find_conversation(who);
 
 	if (c && (type & TYPE_IM))
 		unnotify(c, FALSE);
 	return 0;
 }
 
-int attach_signals(struct conversation *c) {
+int attach_signals(struct gaim_conversation *c) {
+	struct gaim_gtk_conversation *gtkconv;
+	struct gaim_gtk_window *gtkwin;
+
+	gtkconv = GAIM_GTK_CONVERSATION(c);
+	gtkwin  = GAIM_GTK_WINDOW(gaim_conversation_get_window(c));
+
 	if (choice & NOTIFY_FOCUS) {
-		g_signal_connect(G_OBJECT(c->window), "focus-in-event", G_CALLBACK(un_star), NULL);
+		g_signal_connect(G_OBJECT(gtkwin->window), "focus-in-event", G_CALLBACK(un_star), NULL);
 	}
 
 	if (choice & NOTIFY_CLICK) {
-		g_signal_connect(G_OBJECT(c->window), "button_press_event", G_CALLBACK(un_star), NULL);
+		g_signal_connect(G_OBJECT(gtkwin->window), "button_press_event", G_CALLBACK(un_star), NULL);
 
-		g_signal_connect_swapped(G_OBJECT(c->text), "button_press_event", G_CALLBACK(un_star), G_OBJECT(c->window));
+		g_signal_connect_swapped(G_OBJECT(gtkconv->imhtml), "button_press_event", G_CALLBACK(un_star), G_OBJECT(gtkwin->window));
 
-		g_signal_connect_swapped(G_OBJECT(c->entry), "button_press_event", G_CALLBACK(un_star), G_OBJECT(c->window));
+		g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "button_press_event", G_CALLBACK(un_star), G_OBJECT(gtkwin->window));
 	}
 
 	if (choice & NOTIFY_TYPE) {
-		g_signal_connect_swapped(G_OBJECT(c->entry), "key-press-event", G_CALLBACK(un_star), G_OBJECT(c->window));
+		g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "key-press-event", G_CALLBACK(un_star), G_OBJECT(gtkwin->window));
 	}
 
-	g_object_set_data(G_OBJECT(c->window), "user_data", c);
-	g_object_set_data(G_OBJECT(c->window), "notify_data", GUINT_TO_POINTER(choice));
+	g_object_set_data(G_OBJECT(gtkwin->window), "user_data", c);
+	g_object_set_data(G_OBJECT(gtkwin->window), "notify_data", GUINT_TO_POINTER(choice));
 	return 0;
 }
 
-void detach_signals(struct conversation *c) {
-	guint options = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(c->window), "notify_data"));
+void detach_signals(struct gaim_conversation *c) {
+	struct gaim_gtk_conversation *gtkconv;
+	struct gaim_gtk_window *gtkwin;
+	guint options;
+	
+	gtkconv = GAIM_GTK_CONVERSATION(c);
+	gtkwin  = GAIM_GTK_WINDOW(gaim_conversation_get_window(c));
+	
+	options = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(gtkwin->window), "notify_data"));
 
 	if (options & NOTIFY_FOCUS) {
-		g_signal_handlers_disconnect_by_func(G_OBJECT(c->window), un_star, NULL);
+		g_signal_handlers_disconnect_by_func(G_OBJECT(gtkwin->window), un_star, NULL);
 	}
 	if (options & NOTIFY_CLICK) {
-		g_signal_handlers_disconnect_by_func(G_OBJECT(c->window), un_star, NULL);
-		g_signal_handlers_disconnect_by_func(G_OBJECT(c->text), un_star, c->window);
-		g_signal_handlers_disconnect_by_func(G_OBJECT(c->entry), un_star, c->window);
+		g_signal_handlers_disconnect_by_func(G_OBJECT(gtkwin->window), un_star, NULL);
+		g_signal_handlers_disconnect_by_func(G_OBJECT(gtkconv->imhtml), un_star, gtkwin->window);
+		g_signal_handlers_disconnect_by_func(G_OBJECT(gtkconv->entry), un_star, gtkwin->window);
 	}
 
 	if (options & NOTIFY_TYPE) {
-		g_signal_handlers_disconnect_by_func(G_OBJECT(c->entry), un_star, c->window);
+		g_signal_handlers_disconnect_by_func(G_OBJECT(gtkconv->entry), un_star, gtkwin->window);
 	}
 }
 
 void new_conv(char *who) {
-	struct conversation *c = find_conversation(who);
+	struct gaim_conversation *c = gaim_find_conversation(who);
 
 	if (c && (type & TYPE_IM))
 		attach_signals(c);
-	return;
 }
 
 void chat_join(struct gaim_connection *gc, int id, char *room) {
-	struct conversation *c = find_chat(gc, id);
+	struct gaim_conversation *c = gaim_find_chat(gc, id);
 
 	if (c && (type & TYPE_CHAT))
 		attach_signals(c);
-	return;
 }
 
 int un_star(GtkWidget *widget, gpointer data) {
-	struct conversation *c = g_object_get_data(G_OBJECT(widget), "user_data");
+	struct gaim_conversation *c = g_object_get_data(G_OBJECT(widget), "user_data");
 
 	if (method & METHOD_QUOTE)
 		quote_remove(widget);
@@ -338,36 +341,60 @@
 	return FALSE;
 }
 
-void urgent_add(struct conversation *c) {
-	XWMHints *hints = XGetWMHints(GDK_WINDOW_XDISPLAY(c->window->window), GDK_WINDOW_XWINDOW(c->window->window));
+void urgent_add(struct gaim_conversation *c) {
+	struct gaim_gtk_window *gtkwin;
+	XWMHints *hints;
+
+	gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c));
+
+	hints = XGetWMHints(GDK_WINDOW_XDISPLAY(gtkwin->window->window), GDK_WINDOW_XWINDOW(gtkwin->window->window));
 	hints->flags |= XUrgencyHint;
-	XSetWMHints(GDK_WINDOW_XDISPLAY(c->window->window), GDK_WINDOW_XWINDOW(c->window->window), hints);
+	XSetWMHints(GDK_WINDOW_XDISPLAY(gtkwin->window->window), GDK_WINDOW_XWINDOW(gtkwin->window->window), hints);
 	XFree(hints);
 }
 
-gboolean urgent_remove(struct conversation *c) {
-	if ((c->is_chat && (chat_options & OPT_CHAT_ONE_WINDOW)) || (!c->is_chat && (im_options & OPT_IM_ONE_WINDOW))) {
-		if (c->is_chat) {
-			struct conversation *c = (struct conversation *)chats->data;
-			GdkWindow *win = c->window->window;
+gboolean urgent_remove(struct gaim_conversation *c) {
+	struct gaim_gtk_conversation *gtkconv;
+
+	gtkconv = GAIM_GTK_CONVERSATION(c);
 
-			XWMHints *hints = XGetWMHints(GDK_WINDOW_XDISPLAY(win), GDK_WINDOW_XWINDOW(win));
+	if ((gaim_conversation_get_type(c) == GAIM_CONV_CHAT &&
+		 (chat_options & OPT_CHAT_ONE_WINDOW)) ||
+		(gaim_conversation_get_type(c) != GAIM_CONV_CHAT &&
+		 (im_options & OPT_IM_ONE_WINDOW))) {
+		if (gaim_conversation_get_type(c) == GAIM_CONV_CHAT) {
+			struct gaim_conversation *c = (struct gaim_conversation *)gaim_get_chats()->data;
+			struct gaim_gtk_window *gtkwin;
+			GdkWindow *win;
+			XWMHints *hints;
+
+			gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c));
+
+			win = gtkwin->window->window;
+
+			hints = XGetWMHints(GDK_WINDOW_XDISPLAY(win), GDK_WINDOW_XWINDOW(win));
 			if (hints->flags & XUrgencyHint) {
 				hints->flags &= ~XUrgencyHint;
-				XSetWMHints(GDK_WINDOW_XDISPLAY(c->window->window), GDK_WINDOW_XWINDOW(c->window->window), hints);
+				XSetWMHints(GDK_WINDOW_XDISPLAY(gtkwin->window->window), GDK_WINDOW_XWINDOW(gtkwin->window->window), hints);
 				XFree(hints);
 				return TRUE;
 			}
 			XFree(hints);
 			return FALSE;
 		} else {
-			struct conversation *c = (struct conversation *)conversations->data;
-			GdkWindow *win = c->window->window;
+			struct gaim_conversation *c;
+			struct gaim_gtk_window *gtkwin;
+			GdkWindow *win;
+			XWMHints *hints;
 
-			XWMHints *hints = XGetWMHints(GDK_WINDOW_XDISPLAY(win), GDK_WINDOW_XWINDOW(win));
+			c = (struct gaim_conversation *)gaim_get_ims()->data;
+			gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c));
+			win = gtkwin->window->window;
+
+			hints = XGetWMHints(GDK_WINDOW_XDISPLAY(win), GDK_WINDOW_XWINDOW(win));
 			if (hints->flags & XUrgencyHint) {
 				hints->flags &= ~XUrgencyHint;
-				XSetWMHints(GDK_WINDOW_XDISPLAY(c->window->window), GDK_WINDOW_XWINDOW(c->window->window), hints);
+				XSetWMHints(GDK_WINDOW_XDISPLAY(gtkwin->window->window), GDK_WINDOW_XWINDOW(gtkwin->window->window), hints);
 				XFree(hints);
 				return TRUE;
 			}
@@ -375,10 +402,15 @@
 			return FALSE;
 		}
 	} else {
-		XWMHints *hints = XGetWMHints(GDK_WINDOW_XDISPLAY(c->window->window), GDK_WINDOW_XWINDOW(c->window->window));
+		struct gaim_gtk_window *gtkwin;
+		XWMHints *hints;
+
+		gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c));
+		hints = XGetWMHints(GDK_WINDOW_XDISPLAY(gtkwin->window->window), GDK_WINDOW_XWINDOW(gtkwin->window->window));
+
 		if (hints->flags & XUrgencyHint) {
 			hints->flags &= ~XUrgencyHint;
-			XSetWMHints(GDK_WINDOW_XDISPLAY(c->window->window), GDK_WINDOW_XWINDOW(c->window->window), hints);
+			XSetWMHints(GDK_WINDOW_XDISPLAY(gtkwin->window->window), GDK_WINDOW_XWINDOW(gtkwin->window->window), hints);
 			XFree(hints);
 			return TRUE;
 		}
@@ -480,7 +512,16 @@
 
 	while (cnv) {
 		guint notification;
-		struct conversation *c = (struct conversation *) cnv->data;
+		struct gaim_conversation *c = (struct gaim_conversation *) cnv->data;
+		struct gaim_gtk_conversation *gtkconv;
+		struct gaim_gtk_window *gtkwin;
+		guint options = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(c->window), "notify_data"));
+
+		gtkconv = GAIM_GTK_CONVERSATION(c);
+		gtkwin  = GAIM_GTK_WINDOW(gaim_conversation_get_window(c));
+
+		if (options & NOTIFY_FOCUS)
+			g_signal_handlers_disconnect_by_func(G_OBJECT(gtkwin->window), un_star, NULL);
 
 		/* remove old notification signals */
 		detach_signals(c);
@@ -490,11 +531,11 @@
 	
 		/* re-add appropriate notification methods cleaned above */
 		if (notification & METHOD_STRING) /* re-add string */
-			string_add(c->window);
+			string_add(gtkwin->window);
 		if (notification & METHOD_QUOTE) /* re-add quote */
-			quote_add(c->window);
+			quote_add(gtkwin->window);
 		if (notification & METHOD_COUNT) /* re-add count */
-			count_add(c->window, Number);
+			count_add(gtkwin->window, Number);
 		if (notification & METHOD_URGENT) /* re-add urgent */
 			urgent_add(c);
 
@@ -503,8 +544,6 @@
 
 		cnv = cnv->next;
 	}
-
-	return;
 }
 
 char *gaim_plugin_init(GModule *hndl) {
@@ -523,14 +562,17 @@
 }
 
 void gaim_plugin_remove() {
-	GList *c = conversations;
+	GList *c = gaim_get_ims();
 
 	while (c) {
-		struct conversation *cnv = (struct conversation *)c->data;
-		
+		struct gaim_conversation *cnv = (struct gaim_conversation *)c->data;
+		struct gaim_gtk_window *gtkwin;
+
+		gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(cnv));
+
 		detach_signals(cnv);
-		un_star(cnv->window, NULL);
-		
+		un_star(gtkwin->window, NULL);
+
 		c = c->next;
 	}
 	
--- a/plugins/ticker/ticker.c	Mon Jan 20 07:00:10 2003 +0000
+++ b/plugins/ticker/ticker.c	Mon Jan 20 09:10:23 2003 +0000
@@ -121,7 +121,7 @@
 ButtonPressCallback( GtkWidget *widget, GdkEvent *event, gpointer callback_data ) 
 {
 	TickerData *p = (TickerData *) callback_data;
-	new_conversation(p->buddy);
+	gaim_conversation_new(GAIM_CONV_IM, p->buddy);
 	
 	return TRUE;
 }
--- a/plugins/timestamp.c	Mon Jan 20 07:00:10 2003 +0000
+++ b/plugins/timestamp.c	Mon Jan 20 09:10:23 2003 +0000
@@ -21,7 +21,7 @@
 
 gboolean do_timestamp (gpointer data)
 {
-	struct conversation *c = data;
+	struct gaim_conversation *c = (struct gaim_conversation *)data;
 	char *buf;
 	char mdate[6];
 	time_t tim = time(NULL);
@@ -31,14 +31,14 @@
 
 	strftime(mdate, sizeof(mdate), "%H:%M", localtime(&tim));
 	buf = g_strdup_printf("            %s", mdate);
-	write_to_conv(c, buf, WFLAG_NOLOG, NULL, tim, -1);
+	gaim_conversation_write(c, NULL, buf, WFLAG_NOLOG, tim, -1);
 	g_free(buf);
 	return TRUE;
 }
 
 void timestamp_new_convo(char *name)
 {
-	struct conversation *c = find_conversation(name);
+	struct gaim_conversation *c = gaim_find_conversation(name);
 	do_timestamp(c);
 
 	timestamp_timeouts = g_slist_append(timestamp_timeouts,
@@ -100,7 +100,7 @@
 
 char *gaim_plugin_init(GModule *h) {
 	GList *cnvs = conversations;
-	struct conversation *c;
+	struct gaim_conversation *c;
 	handle = h;
 
 	while (cnvs) {
--- a/src/Makefile.am	Mon Jan 20 07:00:10 2003 +0000
+++ b/src/Makefile.am	Mon Jan 20 09:10:23 2003 +0000
@@ -13,16 +13,21 @@
 		buddy.c \
 		buddy_chat.c \
 		conversation.c \
-		convo.h \
+		conversation.h \
 		core.c \
 		core.h \
 		dialogs.c \
+		dnd-hints.c \
+		dnd-hints.h \
 		ft.c \
 		gaim.h \
 		gaim-socket.h \
 		gaimrc.c \
+		gtkconv.c \
+		gtkconv.h \
 		gtkimhtml.c \
 		gtkimhtml.h \
+		gtkutils.c \
 		html.c \
 		idle.c \
 		list.c \
@@ -42,6 +47,8 @@
 		session.c \
 		socket.c \
 		sound.c \
+		stock.c \
+		stock.h \
 		themes.c \
 		util.c \
 		ui.h
@@ -68,4 +75,3 @@
 	-DLIBDIR=\"$(libdir)/gaim/\" \
 	-DDATADIR=\"$(datadir)\" \
 	$(DEBUG_CFLAGS)
-
--- a/src/Makefile.mingw	Mon Jan 20 07:00:10 2003 +0000
+++ b/src/Makefile.mingw	Mon Jan 20 09:10:23 2003 +0000
@@ -84,9 +84,12 @@
 			conversation.c \
 			core.c \
 			dialogs.c \
+			dnd-utils.c \
 			ft.c \
 			gaimrc.c \
+			gtkconv.c \
 			gtkimhtml.c \
+			gtkutils.c \
 			html.c \
 			idle.c \
 			list.c \
--- a/src/aim.c	Mon Jan 20 07:00:10 2003 +0000
+++ b/src/aim.c	Mon Jan 20 09:10:23 2003 +0000
@@ -520,6 +520,9 @@
 			load_smiley_theme(smile->path, TRUE);
 		}
 	}
+
+	setup_stock();
+
 #ifndef _WIN32
 	/* use the nice PNG icon for all the windows */
 	icon_path = g_build_filename(DATADIR, "pixmaps", "gaim.png", NULL);
--- a/src/away.c	Mon Jan 20 07:00:10 2003 +0000
+++ b/src/away.c	Mon Jan 20 09:10:23 2003 +0000
@@ -57,19 +57,20 @@
 {
 	GSList *q = *queue;
 	struct queued_message *qm;
-	struct conversation *cnv;
+	struct gaim_conversation *cnv;
 
 	while (q) {
 		qm = q->data;
 
-		cnv = find_conversation(qm->name);
+		cnv = gaim_find_conversation(qm->name);
+
 		if (!cnv)
-			cnv = new_conversation(qm->name);
+			cnv = gaim_conversation_new(GAIM_CONV_IM, qm->name);
 
 		if (g_slist_index(connections, qm->gc) >= 0)
-			set_convo_gc(cnv, qm->gc);
+			gaim_conversation_set_user(cnv, qm->gc->user);
 
-		write_to_conv(cnv, qm->message, qm->flags, NULL, qm->tm, qm->len);
+		gaim_im_write(GAIM_IM(cnv), NULL, qm->message, -1, qm->flags, qm->tm);
 
 		g_free(qm->message);
 		g_free(qm);
@@ -86,7 +87,7 @@
 	char *temp;
 	char *name;
 	GSList *templist;
-	struct conversation *cnv;
+	struct gaim_conversation *cnv;
 	
 	if(!(event->type == GDK_2BUTTON_PRESS && event->button == 1))
 		return; /* Double clicking on the clist will unqueue that users messages. */
@@ -102,13 +103,16 @@
 		struct queued_message *qm = templist->data;
 		if (templist->data) {
 			if (!g_strcasecmp(qm->name, name)) {
-				cnv = find_conversation(name);
+				cnv = gaim_find_conversation(name);
+
 				if (!cnv)
-					cnv = new_conversation(qm->name);
+					cnv = gaim_conversation_new(GAIM_CONV_IM, qm->name);
+
 				if (g_slist_index(connections, qm->gc) >= 0)
-					set_convo_gc(cnv, qm->gc);
-				
-				write_to_conv(cnv, qm->message, qm->flags, NULL, qm->tm, qm->len);
+					gaim_conversation_set_user(cnv, qm->gc->user);
+
+				gaim_conversation_write(cnv, NULL, qm->message, qm->len,
+										qm->flags, qm->tm);
 				g_free(qm->message);
 				g_free(qm);
 				templist = message_queue = g_slist_remove(message_queue, qm);
--- 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",
--- a/src/buddy_chat.c	Mon Jan 20 07:00:10 2003 +0000
+++ b/src/buddy_chat.c	Mon Jan 20 09:10:23 2003 +0000
@@ -35,101 +35,53 @@
 #endif
 #include <gdk/gdkkeysyms.h>
 
-#include "convo.h"
 #include "prpl.h"
 
-/*#include "pixmaps/tb_forward.xpm"*/
-#include "pixmaps/join.xpm"
-/*#include "pixmaps/close.xpm"*/
-#include "pixmaps/cancel.xpm"
-
-GtkWidget *joinchat;
-static struct gaim_connection *joinchatgc;
-static GtkWidget *invite;
-static GtkWidget *inviteentry;
-static GtkWidget *invitemess;
+static GList *chatentries = NULL;
+static GtkWidget *joinchat = NULL;
 static GtkWidget *jc_vbox = NULL;
-static GList *chatentries = NULL;
-extern int state_lock;
-
-GList *chats = NULL;
-GtkWidget *all_chats = NULL;
-GtkWidget *chat_notebook = NULL;
-
-static char *ignored(struct conversation *b, char *who)
-{
-	GList *ignore = b->ignored;
+static struct gaim_connection *joinchatgc;
 
-	while (ignore) {
-		char *ign = ignore->data;
-		if (!g_strcasecmp(who, ign))
-			return ign;
-		if (*ign == '+' && !g_strcasecmp(who, ign + 1))
-			return ign;
-		if (*ign == '@') {
-			ign++;
-			if (*ign == '+' && !g_strcasecmp(who, ign + 1))
-				return ign;
-			if (*ign != '+' && !g_strcasecmp(who, ign))
-				return ign;
-		}
-		ignore = ignore->next;
-	}
-	return NULL;
-}
-
-
-static void destroy_join_chat()
-{
-	if (joinchat)
-		gtk_widget_destroy(joinchat);
-	joinchat = NULL;
-}
-
-static void destroy_invite()
-{
-	if (invite)
-		gtk_widget_destroy(invite);
-	invite = NULL;
-}
-
-
-void do_join_chat()
+static void
+do_join_chat()
 {
 	if (joinchat) {
 		GList *data = NULL;
-		GList *tmp = chatentries;
+		GList *tmp;
 		int *ival;
 		char *sval;
-		while (tmp) {
+
+		for (tmp = chatentries; tmp != NULL; tmp = tmp->next) {
 			if (gtk_object_get_user_data(tmp->data)) {
 				ival = g_new0(int, 1);
 				*ival = gtk_spin_button_get_value_as_int(tmp->data);
 				data = g_list_append(data, ival);
-			} else {
+			}
+			else {
 				sval = g_strdup(gtk_entry_get_text(tmp->data));
 				data = g_list_append(data, sval);
 			}
-			tmp = tmp->next;
 		}
+
 		serv_join_chat(joinchatgc, data);
 
-		tmp = data;
-		while (tmp) {
+		for (tmp = data; tmp != NULL; tmp = tmp->next)
 			g_free(tmp->data);
-			tmp = tmp->next;
-		}
+
 		g_list_free(data);
 
 		gtk_widget_destroy(joinchat);
+
 		if (chatentries)
 			g_list_free(chatentries);
+
 		chatentries = NULL;
+		joinchat = NULL;
 	}
-	joinchat = NULL;
 }
 
-static void rebuild_jc()
+static void
+rebuild_jc()
 {
 	GList *list, *tmp;
 	struct proto_chat_entry *pce;
@@ -141,15 +93,19 @@
 	while (GTK_BOX(jc_vbox)->children)
 		gtk_container_remove(GTK_CONTAINER(jc_vbox),
 				     ((GtkBoxChild *)GTK_BOX(jc_vbox)->children->data)->widget);
+
 	if (chatentries)
 		g_list_free(chatentries);
+
 	chatentries = NULL;
 
-	tmp = list = joinchatgc->prpl->chat_info(joinchatgc);
-	while (list) {
+	list = joinchatgc->prpl->chat_info(joinchatgc);
+
+	for (tmp = list; tmp != NULL; tmp = tmp->next) {
 		GtkWidget *label;
 		GtkWidget *rowbox;
-		pce = list->data;
+
+		pce = tmp->data;
 
 		rowbox = gtk_hbox_new(FALSE, 5);
 		gtk_box_pack_start(GTK_BOX(jc_vbox), rowbox, TRUE, TRUE, 0);
@@ -162,49 +118,61 @@
 		if (pce->is_int) {
 			GtkObject *adjust;
 			GtkWidget *spin;
-			adjust = gtk_adjustment_new(pce->min, pce->min, pce->max, 1, 10, 10);
+			adjust = gtk_adjustment_new(pce->min, pce->min,
+										pce->max, 1, 10, 10);
 			spin = gtk_spin_button_new(GTK_ADJUSTMENT(adjust), 1, 0);
 			gtk_object_set_user_data(GTK_OBJECT(spin), (void *)1);
 			chatentries = g_list_append(chatentries, spin);
 			gtk_widget_set_usize(spin, 50, -1);
 			gtk_box_pack_end(GTK_BOX(rowbox), spin, FALSE, FALSE, 0);
 			gtk_widget_show(spin);
-		} else {
+		}
+		else {
 			GtkWidget *entry;
+
 			entry = gtk_entry_new();
+			gtk_box_pack_end(GTK_BOX(rowbox), entry, FALSE, FALSE, 0);
+
 			chatentries = g_list_append(chatentries, entry);
-			gtk_box_pack_end(GTK_BOX(rowbox), entry, FALSE, FALSE, 0);
+
 			if (pce->def)
 				gtk_entry_set_text(GTK_ENTRY(entry), pce->def);
+
 			if (focus) {
 				gtk_widget_grab_focus(entry);
 				focus = FALSE;
 			}
-			g_signal_connect(GTK_OBJECT(entry), "activate",
-					   G_CALLBACK(do_join_chat), NULL);
+
+			g_signal_connect(G_OBJECT(entry), "activate",
+							 G_CALLBACK(do_join_chat), NULL);
+
 			gtk_widget_show(entry);
 		}
 
 		g_free(pce);
-		list = list->next;
 	}
-	g_list_free(tmp);
+
+	g_list_free(list);
 }
 
-static void joinchat_choose(GtkWidget *w, struct gaim_connection *g)
+static void
+joinchat_choose(GtkWidget *w, struct gaim_connection *g)
 {
 	if (joinchatgc == g)
 		return;
+
 	joinchatgc = g;
+
 	rebuild_jc();
 }
 
-static void create_joinchat_menu(GtkWidget *box)
+static void
+create_joinchat_menu(GtkWidget *box)
 {
 	GtkWidget *optmenu;
 	GtkWidget *menu;
 	GtkWidget *opt;
-	GSList *c = connections;
+	GSList *c;
 	struct gaim_connection *g;
 	char buf[2048];
 
@@ -214,17 +182,23 @@
 	menu = gtk_menu_new();
 	joinchatgc = NULL;
 
-	while (c) {
+	for (c = connections; c != NULL; c = c->next) {
 		g = (struct gaim_connection *)c->data;
-		c = c->next;
+
 		if (!g->prpl->join_chat)
 			continue;
+
 		if (!joinchatgc)
 			joinchatgc = g;
-		g_snprintf(buf, sizeof buf, "%s (%s)", g->username, g->prpl->name);
+
+		g_snprintf(buf, sizeof(buf), "%s (%s)", g->username, g->prpl->name);
 		opt = gtk_menu_item_new_with_label(buf);
+
 		gtk_object_set_user_data(GTK_OBJECT(opt), g);
-		g_signal_connect(GTK_OBJECT(opt), "activate", G_CALLBACK(joinchat_choose), g);
+
+		g_signal_connect(G_OBJECT(opt), "activate",
+						 G_CALLBACK(joinchat_choose), g);
+
 		gtk_menu_append(GTK_MENU(menu), opt);
 		gtk_widget_show(opt);
 	}
@@ -233,7 +207,17 @@
 	gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
 }
 
-void join_chat()
+static void
+destroy_join_chat()
+{
+	if (joinchat)
+		gtk_widget_destroy(joinchat);
+
+	joinchat = NULL;
+}
+
+void
+join_chat()
 {
 	GtkWidget *mainbox;
 	GtkWidget *frame;
@@ -243,19 +227,24 @@
 	GtkWidget *join;
 	GtkWidget *cancel;
 	GtkWidget *label;
-	GSList *c = connections;
+	GtkWidget *sep;
+	GSList *c;
 	struct gaim_connection *gc = NULL;
 
-	while (c) {
+	for (c = connections; c != NULL; c = c->next) {
 		gc = c->data;
+
 		if (gc->prpl->join_chat)
 			break;
+
 		gc = NULL;
-		c = c->next;
 	}
+
 	if (gc == NULL) {
-		do_error_dialog("You are not currently signed on with any protocols that have "
-				"the ability to chat.", NULL, GAIM_ERROR);
+		do_error_dialog(
+			_("You are not currently signed on with any protocols that have "
+			  "the ability to chat."), NULL, GAIM_ERROR);
+
 		return;
 	}
 
@@ -264,7 +253,7 @@
 		gtk_window_set_role(GTK_WINDOW(joinchat), "joinchat");
 		gtk_window_set_policy(GTK_WINDOW(joinchat), FALSE, TRUE, TRUE);
 		gtk_widget_realize(joinchat);
-		g_signal_connect(GTK_OBJECT(joinchat), "delete_event",
+		g_signal_connect(G_OBJECT(joinchat), "delete_event",
 				   G_CALLBACK(destroy_join_chat), joinchat);
 		gtk_window_set_title(GTK_WINDOW(joinchat), _("Join Chat"));
 
@@ -272,8 +261,7 @@
 		gtk_container_set_border_width(GTK_CONTAINER(mainbox), 5);
 		gtk_container_add(GTK_CONTAINER(joinchat), mainbox);
 
-		frame = gtk_frame_new(_("Buddy Chat"));
-		gtk_box_pack_start(GTK_BOX(mainbox), frame, TRUE, TRUE, 0);
+		frame = make_frame(mainbox, _("Buddy Chat"));
 
 		fbox = gtk_vbox_new(FALSE, 5);
 		gtk_container_set_border_width(GTK_CONTAINER(fbox), 5);
@@ -288,1431 +276,37 @@
 
 		create_joinchat_menu(rowbox);
 
-		{
-			GtkWidget *tmp = fbox;
-			fbox = gtk_vbox_new(FALSE, 5);
-			gtk_container_add(GTK_CONTAINER(tmp), fbox);
-			gtk_container_set_border_width(GTK_CONTAINER(fbox), 0);
-			jc_vbox = fbox;
-		}
+		jc_vbox = gtk_vbox_new(FALSE, 5);
+		gtk_container_add(GTK_CONTAINER(fbox), jc_vbox);
+		gtk_container_set_border_width(GTK_CONTAINER(jc_vbox), 0);
+
 #else
 		joinchatgc = connections->data;
 #endif
 		rebuild_jc();
 		/* buttons */
 
+		sep = gtk_hseparator_new();
+		gtk_widget_show(sep);
+		gtk_box_pack_start(GTK_BOX(mainbox), sep, FALSE, FALSE, 0);
+
 		bbox = gtk_hbox_new(FALSE, 5);
 		gtk_box_pack_start(GTK_BOX(mainbox), bbox, FALSE, FALSE, 0);
 
-		join = picture_button(joinchat, _("Join"), join_xpm);
-		gtk_box_pack_end(GTK_BOX(bbox), join, FALSE, FALSE, 0);
-		g_signal_connect(GTK_OBJECT(join), "clicked", G_CALLBACK(do_join_chat), NULL);
-
-		cancel = picture_button(joinchat, _("Cancel"), cancel_xpm);
-		gtk_box_pack_end(GTK_BOX(bbox), cancel, FALSE, FALSE, 0);
-		g_signal_connect(GTK_OBJECT(cancel), "clicked",
-				   G_CALLBACK(destroy_join_chat), joinchat);
-	}
-	gtk_widget_show_all(joinchat);
-}
-
-
-static void do_invite(GtkWidget *w, struct conversation *b)
-{
-	const char *buddy;
-	const char *mess;
-
-	if (!b->is_chat) {
-		debug_printf("do_invite: expecting chat, got IM\n");
-		return;
-	}
-
-	buddy = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(inviteentry)->entry));
-	mess = gtk_entry_get_text(GTK_ENTRY(invitemess));
-
-	if (invite) {
-		serv_chat_invite(b->gc, b->id, mess, buddy);
-		gtk_widget_destroy(invite);
-	}
-	invite = NULL;
-}
-
-
-GList *generate_invite_user_names(struct gaim_connection *gc)
-{
-	GSList *grp;
-	GSList *bl;
-	struct group *g;
-	struct buddy *buddy;
-
-	static GList *tmp = NULL;
-
-	if (tmp)
-		g_list_free(tmp);
-	tmp = NULL;
-
-	tmp = g_list_append(tmp, "");
-
-	if (gc) {
-		grp = groups;
-
-		while (grp) {
-			g = (struct group *)grp->data;
-
-			bl = g->members;
-
-			while (bl) {
-				buddy = (struct buddy *)bl->data;
-
-				if (buddy->user->gc == gc && buddy->present)
-					tmp = g_list_append(tmp, buddy->name);
-
-				bl = g_slist_next(bl);
-			}
-
-			grp = g_slist_next(grp);
-		}
-	}
-
-	return tmp;
-
-}
-
-void invite_callback(GtkWidget *w, struct conversation *b)
-{
-	GtkWidget *cancel;
-	GtkWidget *invite_btn;
-	GtkWidget *label;
-	GtkWidget *bbox;
-	GtkWidget *vbox;
-	GtkWidget *table;
-	GtkWidget *frame;
-
-	if (!invite) {
-		GAIM_DIALOG(invite);
-		gtk_widget_realize(invite);
-
-		cancel = picture_button(invite, _("Cancel"), cancel_xpm);
-		invite_btn = picture_button(invite, _("Invite"), join_xpm);
-		inviteentry = gtk_combo_new();
-		invitemess = gtk_entry_new();
-		frame = gtk_frame_new(_("Invite"));
-		table = gtk_table_new(2, 2, FALSE);
-
-		gtk_table_set_row_spacings(GTK_TABLE(table), 5);
-		gtk_table_set_col_spacings(GTK_TABLE(table), 5);
-		gtk_container_set_border_width(GTK_CONTAINER(table), 5);
-
-		gtk_container_set_border_width(GTK_CONTAINER(frame), 5);
-
-		/* Now we should fill out all of the names */
-		gtk_combo_set_popdown_strings(GTK_COMBO(inviteentry), generate_invite_user_names(b->gc));
-
-		vbox = gtk_vbox_new(FALSE, 0);
-		gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
-		gtk_container_add(GTK_CONTAINER(frame), table);
-
-		label = gtk_label_new(_("Buddy"));
-		gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
-		gtk_widget_show(label);
-		gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, 0, 0, 0);
-
-		label = gtk_label_new(_("Message"));
-		gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
-		gtk_widget_show(label);
-		gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_FILL, 0, 0, 0);
-
-		/* Now the right side of the table */
-		gtk_table_attach(GTK_TABLE(table), inviteentry, 1, 2, 0, 1, GTK_FILL | GTK_EXPAND, 0, 0,
-				 0);
-		gtk_table_attach(GTK_TABLE(table), invitemess, 1, 2, 1, 2, GTK_FILL | GTK_EXPAND, 0, 0,
-				 0);
-
-		/* And now for the button box */
-		bbox = gtk_hbox_new(FALSE, 10);
-		gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
-
+		/* Cancel button. */
+		cancel = gaim_pixbuf_button_from_stock(_("Cancel"), GTK_STOCK_CANCEL,
+											 GAIM_BUTTON_HORIZONTAL);
 		gtk_box_pack_end(GTK_BOX(bbox), cancel, FALSE, FALSE, 0);
-		gtk_box_pack_end(GTK_BOX(bbox), invite_btn, FALSE, FALSE, 0);
-
-		/* Handle closes right */
-		g_signal_connect(GTK_OBJECT(invite), "delete_event",
-				   G_CALLBACK(destroy_invite), invite);
-
-		g_signal_connect(GTK_OBJECT(cancel), "clicked", G_CALLBACK(destroy_invite), b);
-		g_signal_connect(GTK_OBJECT(invite_btn), "clicked", G_CALLBACK(do_invite), b);
-		g_signal_connect(GTK_OBJECT(GTK_ENTRY(GTK_COMBO(inviteentry)->entry)), "activate",
-				   G_CALLBACK(do_invite), b);
-
-		/* Finish up */
-		gtk_widget_set_usize(GTK_WIDGET(invite), 550, 115);
-		gtk_widget_show(invite_btn);
-		gtk_widget_show(cancel);
-		gtk_widget_show(inviteentry);
-		gtk_widget_show(invitemess);
-		gtk_widget_show(vbox);
-		gtk_widget_show(bbox);
-		gtk_widget_show(table);
-		gtk_widget_show(frame);
-		gtk_window_set_title(GTK_WINDOW(invite), _("Gaim - Invite Buddy Into Chat Room"));
-		gtk_window_set_focus(GTK_WINDOW(invite), GTK_WIDGET(GTK_COMBO(inviteentry)->entry));
-		gtk_container_add(GTK_CONTAINER(invite), vbox);
-
-
-	}
-	gtk_widget_show(invite);
-}
-
-void tab_complete(struct conversation *c)
-{
-	GtkTextIter cursor, word_start, start_buffer;
-	int start;
-	int most_matched = -1;
-	char *entered, *partial = NULL;
-	char *text;
-	GList *matches = NULL;
-	GList *nicks = NULL;
-
-	gtk_text_buffer_get_start_iter(c->entry_buffer, &start_buffer);
-	gtk_text_buffer_get_iter_at_mark(c->entry_buffer, &cursor,
-					 gtk_text_buffer_get_insert(c->entry_buffer));
-	word_start = cursor;
-
-	/* if there's nothing there just return */
-	if (!gtk_text_iter_compare(&cursor, &start_buffer))
-		return;
-	
-	text = gtk_text_buffer_get_text(c->entry_buffer, &start_buffer, &cursor, FALSE);
-
-	/* if we're at the end of ": " we need to move back 2 spaces */
-	start = strlen(text)-1;
-	if (strlen(text)>=2 && !strncmp(&text[start-1], ": ", 2)) {
-		gtk_text_iter_backward_chars(&word_start, 2);
-	}
-
-	/* find the start of the word that we're tabbing */
-	while (start >= 0 && text[start] != ' ') {
-		gtk_text_iter_backward_char(&word_start);
-		start--;
-	}
-	g_free(text);
-
-	entered = gtk_text_buffer_get_text(c->entry_buffer, &word_start, &cursor, FALSE);
-	if (chat_options & OPT_CHAT_OLD_STYLE_TAB) {
-		if (strlen(entered) >= 2 && !strncmp(": ", entered + strlen(entered) - 2, 2))
-			entered[strlen(entered) - 2] = 0;
-	}
-
-	if (!strlen(entered)) {
-		g_free(entered);
-		return;
-	}
-
-	debug_printf("checking tab-completion for %s\n", entered);
-
-	nicks = c->in_room;
-	while (nicks) {
-		char *nick = nicks->data;
-		/* this checks to see if the current nick could be a completion */
-		if (g_strncasecmp(nick, entered, strlen(entered))) {
-			if (nick[0] != '+' && nick[0] != '@') {
-				nicks = nicks->next;
-				continue;
-			}
-			if (g_strncasecmp(nick + 1, entered, strlen(entered))) {
-				if (nick[0] != '@' || nick[1] != '+') {
-					nicks = nicks->next;
-					continue;
-				}
-				if (g_strncasecmp(nick + 2, entered, strlen(entered))) {
-					nicks = nicks->next;
-					continue;
-				}
-				else
-					nick += 2;
-			} else
-				nick++;
-		}
-		/* if we're here, it's a possible completion */
-		debug_printf("possible completion: %s\n", nick);
-
-		/* if we're doing old-style, just fill in the completion */
-		if (chat_options & OPT_CHAT_OLD_STYLE_TAB) {
-		        gtk_text_buffer_delete(c->entry_buffer, &word_start, &cursor);
-			if (strlen(nick) == strlen(entered)) {
-				nicks = nicks->next ? nicks->next : c->in_room;
-				nick = nicks->data;
-				if (*nick == '@')
-					nick++;
-				if (*nick == '+')
-					nick++;
-			}
-
-			gtk_text_buffer_get_start_iter(c->entry_buffer, &start_buffer);
-			gtk_text_buffer_get_iter_at_mark(c->entry_buffer, &cursor,
-							 gtk_text_buffer_get_insert(c->entry_buffer));
-			if (!gtk_text_iter_compare(&cursor, &start_buffer)) {
-				char *tmp = g_strdup_printf("%s: ", nick);
-				gtk_text_buffer_insert_at_cursor(c->entry_buffer, tmp, -1);
-				g_free(tmp);
-			} else {
-				gtk_text_buffer_insert_at_cursor(c->entry_buffer, nick, -1);
-			}
-			g_free(entered);
-			return;
-		}
-
-		/* we're only here if we're doing new style */
-		if (most_matched == -1) {
-			/* this will only get called once, since from now on most_matched is >= 0 */
-			most_matched = strlen(nick);
-			partial = g_strdup(nick);
-		} else if (most_matched) {
-			while (g_strncasecmp(nick, partial, most_matched))
-				most_matched--;
-			partial[most_matched] = 0;
-		}
-		matches = g_list_append(matches, nick);
-
-		nicks = nicks->next;
-	}
-	/* we're only here if we're doing new style */
-	
-	/* if there weren't any matches, return */
-	if (!matches) {
-		/* if matches isn't set partials won't be either */
-		g_free(entered);
-		return;
-	}
-	
-	gtk_text_buffer_delete(c->entry_buffer, &word_start, &cursor);
-	if (!matches->next) {
-		/* there was only one match. fill it in. */
-		gtk_text_buffer_get_start_iter(c->entry_buffer, &start_buffer);
-		gtk_text_buffer_get_iter_at_mark(c->entry_buffer, &cursor,
-						 gtk_text_buffer_get_insert(c->entry_buffer));
-		if (!gtk_text_iter_compare(&cursor, &start_buffer)) {
-			char *tmp = g_strdup_printf("%s: ", (char *)matches->data);
-			gtk_text_buffer_insert_at_cursor(c->entry_buffer, tmp, -1);
-			g_free(tmp);
-		} else {
-			gtk_text_buffer_insert_at_cursor(c->entry_buffer, matches->data, -1);
-		}
-		matches = g_list_remove(matches, matches->data);
-	} else {
-		/* there were lots of matches, fill in as much as possible and display all of them */
-		char *addthis = g_malloc0(1);
-		while (matches) {
-			char *tmp = addthis;
-			addthis = g_strconcat(tmp, matches->data, " ", NULL);
-			g_free(tmp);
-			matches = g_list_remove(matches, matches->data);
-		}
-		write_to_conv(c, addthis, WFLAG_NOLOG, NULL, time(NULL), -1);
-		gtk_text_buffer_insert_at_cursor(c->entry_buffer, partial, -1);
-		g_free(addthis);
-	}
-
-	g_free(entered);
-	g_free(partial);
-}
-
-gboolean meify(char *message, int len)
-{
-	/* read /me-ify : if the message (post-HTML) starts with /me, remove
-	 * the "/me " part of it (including that space) and return TRUE */
-	char *c = message;
-	int inside_HTML = 0;	/* i really don't like descriptive names */
-	if (!c)
-		return FALSE;	/* um... this would be very bad if this happens */
-	if (len == -1)
-		len = strlen(message);
-	while (*c) {
-		if (inside_HTML) {
-			if (*c == '>')
-				inside_HTML = 0;
-		} else {
-			if (*c == '<')
-				inside_HTML = 1;
-			else
-				break;
-		}
-		c++;		/* i really don't like c++ either */
-		len--;
-	}
-	/* k, so now we've gotten past all the HTML who. */
-	if (!*c)
-		return FALSE;
-	if (!g_strncasecmp(c, "/me ", 4)) {
-		memmove(c, c + 4, len - 3);
-		return TRUE;
-	} else
-		return FALSE;
-}
-
-static gboolean find_nick(struct gaim_connection *gc, char *message)
-{
-	char *msg = g_strdup(message), *who, *p;
-	int n;
-	g_strdown(msg);
+		g_signal_connect(G_OBJECT(cancel), "clicked",
+						 G_CALLBACK(destroy_join_chat), joinchat);
 
-	who = g_strdup(gc->username);
-	n = strlen(who);
-	g_strdown(who);
-
-	if ((p = strstr(msg, who)) != NULL) {
-		if (((p == msg) || !isalnum(*(p - 1))) && !isalnum(*(p + n))) {
-			g_free(who);
-			g_free(msg);
-			return TRUE;
-		}
-	}
-	g_free(who);
-
-	if (!g_strcasecmp(gc->username, gc->displayname)) {
-		g_free(msg);
-		return FALSE;
-	}
-
-	who = g_strdup(gc->displayname);
-	n = strlen(who);
-	g_strdown(who);
-
-	if (n > 0 && (p = strstr(msg, who)) != NULL) {
-		if (((p == msg) || !isalnum(*(p - 1))) && !isalnum(*(p + n))) {
-			g_free(who);
-			g_free(msg);
-			return TRUE;
-		}
-	}
-	g_free(who);
-	g_free(msg);
-	return FALSE;
-}
-
-void chat_write(struct conversation *b, char *who, int flag, char *message, time_t mtime)
-{
-	char *str;
-
-	if (!b->is_chat) {
-		debug_printf("chat_write: expecting chat, got IM\n");
-		return;
-	}
-
-	if (ignored(b, who))
-		return;
-
-	if (!(flag & WFLAG_WHISPER)) {
-		str = g_strdup(normalize (who));
-		if (!g_strcasecmp(str, normalize(b->gc->username))) {
-			if (b->makesound)
-				play_sound(SND_CHAT_YOU_SAY);
-			flag |= WFLAG_SEND;
-		} else if (!g_strcasecmp(str, normalize(b->gc->displayname))) {
-			if (b->makesound)
-				play_sound(SND_CHAT_YOU_SAY);
-			flag |= WFLAG_SEND;
-		} else {
-		       	flag |= WFLAG_RECV;
-			if (find_nick(b->gc, message))
-				flag |= WFLAG_NICK;
-		}
-		g_free(str);
-	}
-
-	if (flag & WFLAG_RECV && b->makesound) {
-		if (flag & WFLAG_NICK && (sound_options & OPT_SOUND_CHAT_NICK)) {
-			play_sound(SND_CHAT_NICK);
-		} else {
-			play_sound(SND_CHAT_SAY);
-		}
-	}
-
-	if (chat_options & OPT_CHAT_COLORIZE) 
-		flag |= WFLAG_COLORIZE;
-	write_to_conv(b, message, flag, who, mtime, -1);
-}
-
-static gint insertname(gconstpointer one, gconstpointer two)
-{
-	const char *a = (const char *)one;
-	const char *b = (const char *)two;
-
-	if (*a == '@') {
-		if (*b != '@')
-			return -1;
-		return (strcasecmp(a + 1, b + 1));
-	} else if (*a == '+') {
-		if (*b == '@')
-			return 1;
-		if (*b != '+')
-			return -1;
-		return (strcasecmp(a + 1, b + 1));
-	} else {
-		if (*b == '@' || *b == '+')
-			return 1;
-		return strcasecmp(a, b);
-	}
-}
-
-static void chat_press_im(GtkObject *obj, struct conversation *b)
-{
-	struct conversation *c;
-
-	c = find_conversation(gtk_object_get_user_data(obj));
-
-	if (c != NULL)
-		gdk_window_show(c->window->window);
-	else {
-		c = new_conversation(gtk_object_get_user_data(obj));
-		set_convo_gc(c, b->gc);
-	}
-}
-
-static void chat_press_ign(GtkWidget *obj, struct conversation *b)
-{
-	ignore_callback(obj, b);
-}
-
-static void chat_press_info(GtkObject *obj, struct conversation *b)
-{
-	if (b->gc) {
-		/*
-		 * If there are special needs for getting info on users in
-		 * buddy chat "rooms"...
-		 */
-		if(b->gc->prpl->get_cb_info != NULL) {
-			b->gc->prpl->get_cb_info(b->gc, b->id, gtk_object_get_user_data(obj));
-		} else {
-			b->gc->prpl->get_info(b->gc, gtk_object_get_user_data(obj));
-		}
-	}
-}
-
-
-static void chat_press_away(GtkObject *obj, struct conversation *b)
-{
-	if (b->gc) {
-		/*
-		 * May want to expand this to work similarly to chat_press_info?
-		 */
-		if(b->gc->prpl->get_cb_away != NULL) {
-			b->gc->prpl->get_cb_away(b->gc, b->id, gtk_object_get_user_data(obj));
-		}
-	}
-}
-
-/* Added by Jonas <jonas@birme.se> */
-static void chat_press_add(GtkObject *obj, struct conversation *c)
-{
-	char *name = gtk_object_get_user_data(obj);
-	struct buddy *b = find_buddy(c->gc->user, name);
-
-	if (b) {
-		show_confirm_del(c->gc, name);
-	} else if (c->gc)
-		show_add_buddy(c->gc, name, NULL, NULL);
-	
-	gtk_widget_grab_focus(c->entry);	
-}
-/* End Jonas */
-
-static gint right_click_chat(GtkObject *obj, GdkEventButton *event, struct conversation *b)
-{
-	GtkTreePath *path;
-	int x;
-	int y;
-	GtkTreeIter iter;
-	GtkTreeModel *mod;
-	GtkTreeViewColumn *column;
-	gchar *who;
-
-	
-	mod = gtk_tree_view_get_model(GTK_TREE_VIEW(b->list));
-	
-	gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(b->list), event->x, event->y, &path, &column, &x, &y);
-	
-	if (path == NULL)
-			return FALSE;
-
-	gtk_tree_selection_select_path(GTK_TREE_SELECTION(gtk_tree_view_get_selection(GTK_TREE_VIEW(b->list))), path);
-	gtk_tree_model_get_iter(GTK_TREE_MODEL(mod), &iter, path);
-	gtk_tree_model_get(GTK_TREE_MODEL(mod), &iter, 1, &who, -1);
-
-	if ((event->button == 1) && (event->type == GDK_2BUTTON_PRESS)) {
-		struct conversation *c;
-
-		if ((c = find_conversation(who)) == NULL)
-			c = new_conversation(who);
-
-		set_convo_gc(c, b->gc);
-	} else if (event->button == 3 && event->type == GDK_BUTTON_PRESS) {
-		static GtkWidget *menu = NULL;
-		GtkWidget *button;
-
-		/*
-		 * If a menu already exists, destroy it before creating a new one,
-		 * thus freeing-up the memory it occupied.
-		 */
-
-		if(menu)
-			gtk_widget_destroy(menu);
-
-		menu = gtk_menu_new();
-
-		button = gtk_menu_item_new_with_label(_("IM"));
-		g_signal_connect(GTK_OBJECT(button), "activate", G_CALLBACK(chat_press_im), b);
-		gtk_object_set_user_data(GTK_OBJECT(button), who);
-		gtk_menu_append(GTK_MENU(menu), button);
-		gtk_widget_show(button);
-
-		if (ignored(b, gtk_object_get_user_data(obj)))
-			button = gtk_menu_item_new_with_label(_("Un-Ignore"));
-		else
-			button = gtk_menu_item_new_with_label(_("Ignore"));
-		
-		g_signal_connect(GTK_OBJECT(button), "activate", G_CALLBACK(chat_press_ign), b);
-		gtk_object_set_user_data(GTK_OBJECT(button), who);
-		gtk_menu_append(GTK_MENU(menu), button);
-		gtk_widget_show(button);
-
-		if (b->gc && b->gc->prpl->get_info) {
-			button = gtk_menu_item_new_with_label(_("Info"));
-			g_signal_connect(GTK_OBJECT(button), "activate",
-					   G_CALLBACK(chat_press_info), b);
-			gtk_object_set_user_data(GTK_OBJECT(button), who);
-			gtk_menu_append(GTK_MENU(menu), button);
-			gtk_widget_show(button);
-		}
-
-		if (b->gc && b->gc->prpl->get_cb_away) {
-			button = gtk_menu_item_new_with_label(_("Get Away Msg"));
-			g_signal_connect(GTK_OBJECT(button), "activate",
-					   G_CALLBACK(chat_press_away), b);
-			gtk_object_set_user_data(GTK_OBJECT(button), who);
-			gtk_menu_append(GTK_MENU(menu), button);
-			gtk_widget_show(button);
-		}
-
-		/* Added by Jonas <jonas@birme.se> */
-		if (b->gc) {
-			if (find_buddy(b->gc->user, who))
-				button = gtk_menu_item_new_with_label(_("Remove"));
-			else
-				button = gtk_menu_item_new_with_label(_("Add"));
-			g_signal_connect(GTK_OBJECT(button), "activate",
-					   G_CALLBACK(chat_press_add), b);
-			gtk_object_set_user_data(GTK_OBJECT(button), 
-						 who);
-			gtk_menu_append(GTK_MENU(menu), button);
-			gtk_widget_show(button);
-		}
-		/* End Jonas */
-		
-		gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time);
-
-		return TRUE;
-	}
-
-	return TRUE;
-}
-
-/*
- * Common code for adding a chat buddy to the list
- */
-static void add_chat_buddy_common(struct conversation *b, char *name, int pos)
-{
-	GtkTreeIter iter;
-	GtkListStore *ls;
-
-
-	ls = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(b->list)));
-
-	gtk_list_store_append(ls, &iter);
-	gtk_list_store_set(ls, &iter, 0, ignored(b, name) ? "X" : " ", 1, name, -1);
-	gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(ls), 1, GTK_SORT_ASCENDING);
-}
-
-void add_chat_buddy(struct conversation *b, char *buddy, char *extra_msg)
-{
-	char *name = g_strdup(buddy);
-	char tmp[BUF_LONG];
-	int pos;
-
-	plugin_event(event_chat_buddy_join, b->gc, b->id, name);
-	b->in_room = g_list_insert_sorted(b->in_room, name, insertname);
-	pos = g_list_index(b->in_room, name);
-
-	add_chat_buddy_common(b, name, pos);
-
-	g_snprintf(tmp, sizeof(tmp), ngettext("%d person in room", "%d people in room",
-		    g_list_length(b->in_room)),  g_list_length(b->in_room));
-	gtk_label_set_text(GTK_LABEL(b->count), tmp);
-
-	if (b->makesound)
-		play_sound(SND_CHAT_JOIN);
-
-	if (chat_options & OPT_CHAT_LOGON) {
-		if (!extra_msg)
-			g_snprintf(tmp, sizeof(tmp), _("%s entered the room."), name);
-		else
-			g_snprintf(tmp, sizeof(tmp), _("%s [<I>%s</I>] entered the room."), name, 
-				   extra_msg);
-		write_to_conv(b, tmp, WFLAG_SYSTEM, NULL, time(NULL), -1);
-	}
-}
-
-
-void rename_chat_buddy(struct conversation *b, char *old, char *new)
-{
-	GList *names = b->in_room;
-	char *name = g_strdup(new);
-	char *ign;
-	int pos;
-	char tmp[BUF_LONG];
-	GtkTreeIter iter;
-	GtkTreeModel *mod;
-	int f = 1;
-
-	while (names) {
-		if (!g_strcasecmp((char *)names->data, old)) {
-			char *tmp2 = names->data;
-			b->in_room = g_list_remove(b->in_room, names->data);
-			
-			mod = gtk_tree_view_get_model(GTK_TREE_VIEW(b->list));	
-			
-			if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(mod), &iter))
-				break;
-
-			while (f != 0) {
-				gchar *val;
-
-				gtk_tree_model_get(GTK_TREE_MODEL(mod), &iter, 1, &val, -1);
-
-			
-				if (!g_strcasecmp(old, val)) 
-					gtk_list_store_remove(GTK_LIST_STORE(mod), &iter);
-
-				f = gtk_tree_model_iter_next(GTK_TREE_MODEL(mod), &iter);
-
-				g_free(val);
-			}
-
-			g_free(tmp2);
-			break;
-		}
-		names = names->next;
-	}
-
-	if (!names) {
-		g_free(name);
-		return;
+		/* Join button. */
+		join = gaim_pixbuf_button_from_stock(_("Join"), GTK_STOCK_JUMP_TO,
+											 GAIM_BUTTON_HORIZONTAL);
+		gtk_box_pack_end(GTK_BOX(bbox), join, FALSE, FALSE, 0);
+		g_signal_connect(G_OBJECT(join), "clicked",
+						 G_CALLBACK(do_join_chat), NULL);
 	}
 
-	b->in_room = g_list_insert_sorted(b->in_room, name, insertname);
-	pos = g_list_index(b->in_room, name);
-
-	ign = ignored(b, old);
-
-	if (ign) {
-		g_free(ign);
-		b->ignored = g_list_remove(b->ignored, ign);
-
-		/* we haven't added them yet. if we find them, don't add them again */
-		if (!ignored(b, new))
-			b->ignored = g_list_append(b->ignored, g_strdup(name));
-
-	} else {
-		if ((ign = ignored(b, new)) != NULL) {
-			/* if they weren't ignored and change to someone who is ignored,
-			 * assume it's someone else. that may seem a little backwards but
-			 * it's better when it *is* actually someone else. Sorry Sean. */
-			g_free(ign);
-			b->ignored = g_list_remove(b->ignored, ign);
-		}
-	}
-
-	add_chat_buddy_common(b, name, pos);
-
-	if (chat_options & OPT_CHAT_LOGON) {
-		g_snprintf(tmp, sizeof(tmp), _("%s is now known as %s"), old, new);
-		write_to_conv(b, tmp, WFLAG_SYSTEM, NULL, time(NULL), -1);
-	}
-}
-
-
-void remove_chat_buddy(struct conversation *b, char *buddy, char *reason)
-{
-	GList *names = b->in_room;
-	char tmp[BUF_LONG];
-	GtkTreeIter iter;
-	GtkTreeModel *mod;
-	int f = 1;
-
-	plugin_event(event_chat_buddy_leave, b->gc, b->id, buddy);
-
-	while (names) {
-		if (!g_strcasecmp((char *)names->data, buddy)) {
-			b->in_room = g_list_remove(b->in_room, names->data);
-
-			mod = gtk_tree_view_get_model(GTK_TREE_VIEW(b->list));	
-			
-			if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(mod), &iter))
-				break;
-
-			while (f != 0) {
-				gchar *val;
-
-				gtk_tree_model_get(GTK_TREE_MODEL(mod), &iter, 1, &val, -1);
-
-			
-				if (!g_strcasecmp(buddy, val)) 
-					gtk_list_store_remove(GTK_LIST_STORE(mod), &iter);
-
-				f = gtk_tree_model_iter_next(GTK_TREE_MODEL(mod), &iter);
-
-				g_free(val);
-			}
-
-			break;
-		}
-
-		names = names->next;
-	}
-
-	if (!names)
-		return;
-
-	/* don't remove them from ignored in case they re-enter */
-	g_snprintf(tmp, sizeof(tmp), ngettext("%d person in room", "%d people in room",
-		    g_list_length(b->in_room)),  g_list_length(b->in_room));
-	gtk_label_set_text(GTK_LABEL(b->count), tmp);
-
-	if (b->makesound)
-		play_sound(SND_CHAT_LEAVE);
-
-	if (chat_options & OPT_CHAT_LOGON) {
-		if (reason && *reason)
-			g_snprintf(tmp, sizeof(tmp), _("%s left the room (%s)."), buddy, reason);
-		else
-			g_snprintf(tmp, sizeof(tmp), _("%s left the room."), buddy);
-		write_to_conv(b, tmp, WFLAG_SYSTEM, NULL, time(NULL), -1);
-	}
-}
-
-
-void im_callback(GtkWidget *w, struct conversation *b)
-{
-	gchar *name;
-	struct conversation *c;
-	GtkTreeIter iter;
-	GtkTreeModel *mod = gtk_tree_view_get_model(GTK_TREE_VIEW(b->list));
-	GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(b->list));
-
-	if (gtk_tree_selection_get_selected(sel, NULL, &iter)) {
-		gtk_tree_model_get(GTK_TREE_MODEL(mod), &iter, 1, &name, -1);
-	} else {
-		return;
-	}
-
-	if (*name == '@')
-		name++;
-	if (*name == '+')
-		name++;
-
-	c = find_conversation(name);
-
-	if (c != NULL) {
-		gdk_window_raise(c->window->window);
-	} else {
-		c = new_conversation(name);
-	}
-
-	set_convo_gc(c, b->gc);
-}
-
-void ignore_callback(GtkWidget *w, struct conversation *b)
-{
-	GtkTreeIter iter;
-	GtkTreeModel *mod = gtk_tree_view_get_model(GTK_TREE_VIEW(b->list));
-	GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(b->list));
-	char *name;
-	char *ign;
-	int pos;
-
-	if (gtk_tree_selection_get_selected(sel, NULL, &iter)) {
-		gtk_tree_model_get(GTK_TREE_MODEL(mod), &iter, 1, &name, -1);
-		gtk_list_store_remove(GTK_LIST_STORE(mod), &iter);
-	} else {
-		return;
-	}
-
-	pos = g_list_index(b->in_room, name);
-
-	ign = ignored(b, name);
-
-	if (ign) {
-		g_free(ign);
-		b->ignored = g_list_remove(b->ignored, ign);
-	} else {
-		b->ignored = g_list_append(b->ignored, g_strdup(name));
-	}
-
-	add_chat_buddy_common(b, name, pos);
+	gtk_widget_show_all(joinchat);
 }
-
-void show_new_buddy_chat(struct conversation *b)
-{
-	GtkWidget *win;
-	GtkWidget *cont;
-	GtkWidget *text;
-	/*GtkWidget *close;*/
-	GtkWidget *frame;
-	GtkWidget *chatentry;
-	GtkWidget *lbox;
-	GtkWidget *bbox;
-	GtkWidget *bbox2;
-	GtkWidget *button;
-	GtkWidget *sw;
-	GtkWidget *sw2;
-	GtkWidget *vbox;
-	GtkWidget *vpaned;
-	GtkWidget *hpaned;
-	GtkWidget *toolbar;
-	GtkWidget *sep;
-	GtkListStore *ls;
-	GtkWidget *list;
-	GtkCellRenderer *rend;
-	GtkTreeViewColumn *col;
-	GtkWidget *tabby;
-
-	char buf[BUF_LONG];
-
-	int dispstyle = set_dispstyle(1);
-
-	if (chat_options & OPT_CHAT_ONE_WINDOW) {
-		if (!all_chats) {
-			GtkWidget *testidea;
-
-			win = all_chats = b->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-			if ((convo_options & OPT_CONVO_COMBINE) && (im_options & OPT_IM_ONE_WINDOW))
-				all_convos = all_chats;
-			gtk_window_set_role(GTK_WINDOW(win), "buddy_chat");
-			gtk_window_set_policy(GTK_WINDOW(win), TRUE, TRUE, FALSE);
-			gtk_container_border_width(GTK_CONTAINER(win), 0);
-			gtk_widget_realize(win);
-			gtk_window_set_title(GTK_WINDOW(win), _("Gaim - Group Chats"));
-			g_signal_connect(GTK_OBJECT(win), "delete_event",
-					   G_CALLBACK(delete_all_convo), NULL);
-
-			chat_notebook = gtk_notebook_new();
-			if ((convo_options & OPT_CONVO_COMBINE) && (im_options & OPT_IM_ONE_WINDOW))
-				convo_notebook = chat_notebook;
-			if (chat_options & OPT_CHAT_SIDE_TAB) {
-				if (chat_options & OPT_CHAT_BR_TAB) {
-					gtk_notebook_set_tab_pos(GTK_NOTEBOOK(chat_notebook),
-								 GTK_POS_RIGHT);
-				} else {
-					gtk_notebook_set_tab_pos(GTK_NOTEBOOK(chat_notebook),
-								 GTK_POS_LEFT);
-				}
-			} else {
-				if (chat_options & OPT_CHAT_BR_TAB) {
-					gtk_notebook_set_tab_pos(GTK_NOTEBOOK(chat_notebook),
-								 GTK_POS_BOTTOM);
-				} else {
-					gtk_notebook_set_tab_pos(GTK_NOTEBOOK(chat_notebook),
-								 GTK_POS_TOP);
-				}
-			}
-			
-			testidea = gtk_vbox_new(FALSE, 0);
-			gtk_box_pack_start(GTK_BOX(testidea), chat_notebook, TRUE, TRUE, 0);
-			gtk_widget_show(testidea);
-
-			gtk_notebook_set_scrollable(GTK_NOTEBOOK(chat_notebook), TRUE);
-			gtk_notebook_popup_enable(GTK_NOTEBOOK(chat_notebook));
-			gtk_container_add(GTK_CONTAINER(win), testidea);
-			g_signal_connect_after(GTK_OBJECT(chat_notebook), "switch-page",
-					   G_CALLBACK(convo_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);
-
-		tabby = gtk_hbox_new(FALSE, 5);
-		b->close = gtk_button_new();
-		gtk_widget_set_size_request(GTK_WIDGET(b->close), 16, 16);
-		gtk_container_add(GTK_CONTAINER(b->close), gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU));
-		gtk_button_set_relief(GTK_BUTTON(b->close), GTK_RELIEF_NONE);
-		b->tab_label = gtk_label_new(b->name);
-
-		g_signal_connect(GTK_OBJECT(b->close), "clicked", G_CALLBACK(close_callback), b);
-
-		gtk_box_pack_start(GTK_BOX(tabby), b->tab_label, FALSE, FALSE, 0);
-		gtk_box_pack_start(GTK_BOX(tabby), b->close, FALSE, FALSE, 0);
-		gtk_widget_show_all(tabby);
-		gtk_notebook_append_page(GTK_NOTEBOOK(chat_notebook), cont, tabby);
-		gtk_notebook_set_menu_label_text(GTK_NOTEBOOK(chat_notebook), cont,
-				b->name);
-		gtk_widget_show(cont);
-	} else {
-		win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-		b->window = win;
-		gtk_object_set_user_data(GTK_OBJECT(win), b);
-		gtk_window_set_role(GTK_WINDOW(win), "buddy_chat");
-		gtk_window_set_policy(GTK_WINDOW(win), TRUE, TRUE, TRUE);
-		gtk_container_border_width(GTK_CONTAINER(win), 10);
-		gtk_widget_realize(win);
-		g_snprintf(buf, sizeof(buf), "Gaim - %s (chat)", b->name);
-		gtk_window_set_title(GTK_WINDOW(win), buf);
-		g_signal_connect(GTK_OBJECT(win), "destroy", G_CALLBACK(close_callback), b);
-
-		cont = gtk_vbox_new(FALSE, 5);
-		gtk_container_add(GTK_CONTAINER(win), cont);
-		gtk_widget_show(cont);
-	}
-
-	if (b->gc->prpl->options & OPT_PROTO_CHAT_TOPIC) {
-		GtkWidget *hbox;
-		GtkWidget *label;
-
-		hbox = gtk_hbox_new(FALSE, 0);
-		gtk_box_pack_start(GTK_BOX(cont), hbox, FALSE, FALSE, 5);
-		gtk_widget_show(hbox);
-
-		label = gtk_label_new(_("Topic:"));
-		gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
-		gtk_widget_show(label);
-
-		b->topic_text = gtk_entry_new();
-		gtk_entry_set_editable(GTK_ENTRY(b->topic_text), FALSE);
-		gtk_box_pack_start(GTK_BOX(hbox), b->topic_text, TRUE, TRUE, 5);
-		gtk_widget_show(b->topic_text);
-	}
-
-	vpaned = gtk_vpaned_new();
-	gtk_paned_set_gutter_size(GTK_PANED(vpaned), 15);
-	gtk_container_add(GTK_CONTAINER(cont), vpaned);
-	gtk_widget_show(vpaned);
-
-	hpaned = gtk_hpaned_new();
-	gtk_paned_set_gutter_size(GTK_PANED(hpaned), 15);
-	gtk_paned_pack1(GTK_PANED(vpaned), hpaned, TRUE, FALSE);
-	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, buddy_chat_size.width, buddy_chat_size.height);
-	gtk_widget_show(sw);
-
-	text = gtk_imhtml_new(NULL, NULL);
-	b->text = text;
-	gtk_container_add(GTK_CONTAINER(sw), text);
-	if (convo_options & OPT_CONVO_SHOW_TIME)
-		gtk_imhtml_show_comments(GTK_IMHTML(text), TRUE);
-	else
-		gtk_imhtml_show_comments(GTK_IMHTML(text), FALSE);
-	gaim_setup_imhtml(text);
-	gtk_widget_show(text);
-
-	lbox = gtk_vbox_new(FALSE, 5);
-	gtk_paned_pack2(GTK_PANED(hpaned), lbox, TRUE, TRUE);
-	gtk_widget_show(lbox);
-
-	b->count = gtk_label_new(_("0 people in room"));
-	gtk_box_pack_start(GTK_BOX(lbox), b->count, FALSE, FALSE, 0);
-	gtk_widget_show(b->count);
-
-	sw2 = gtk_scrolled_window_new(NULL, NULL);
-	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw2), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-	gtk_box_pack_start(GTK_BOX(lbox), sw2, TRUE, TRUE, 0);
-	gtk_widget_show(sw2);
-
-	ls = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
-	gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(ls), 1, GTK_SORT_ASCENDING);
-	list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ls));
-
-	rend = gtk_cell_renderer_text_new();
-	col = gtk_tree_view_column_new_with_attributes(NULL, rend, "text", 0, NULL);
-	gtk_tree_view_column_set_clickable(GTK_TREE_VIEW_COLUMN(col), TRUE);
-	g_signal_connect(GTK_OBJECT(list), "button_press_event",
-		G_CALLBACK(right_click_chat), b);
-	gtk_tree_view_append_column(GTK_TREE_VIEW(list), col);
-
-	col = gtk_tree_view_column_new_with_attributes(NULL, rend, "text", 1, NULL);
-	gtk_tree_view_column_set_clickable(GTK_TREE_VIEW_COLUMN(col), TRUE);
-	g_signal_connect(GTK_OBJECT(list), "button_press_event",
-		G_CALLBACK(right_click_chat), b);
-	gtk_tree_view_append_column(GTK_TREE_VIEW(list), col);
-
-	gtk_widget_set_usize(list, 150, -1);
-
-	gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list), FALSE);
-	gtk_widget_show(list);
-	b->list = list;
-	
-	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw2), list);
-
-	bbox2 = gtk_hbox_new(TRUE, 5);
-	gtk_box_pack_start(GTK_BOX(lbox), bbox2, FALSE, FALSE, 0);
-	gtk_widget_show(bbox2);
-
-	button = gaim_pixbuf_button_from_stock(NULL, "gtk-redo", GAIM_BUTTON_VERTICAL);
-	gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
-	gtk_box_pack_start(GTK_BOX(bbox2), button, FALSE, FALSE, 0);
-	g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(im_callback), b);
-	gtk_widget_show(button);
-
-	button = gaim_pixbuf_button_from_stock(NULL, "gtk-dialog-error", GAIM_BUTTON_VERTICAL);
-	gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
-	gtk_box_pack_start(GTK_BOX(bbox2), button, FALSE, FALSE, 0);
-	g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(ignore_callback), b);
-	gtk_widget_show(button);
-
-	button = gaim_pixbuf_button_from_stock(NULL, "gtk-find", GAIM_BUTTON_VERTICAL);
-	gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
-	gtk_box_pack_start(GTK_BOX(bbox2), button, FALSE, FALSE, 0);
-	g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(info_callback), b);
-	gtk_widget_show(button);
-	b->info = button;
-
-	vbox = gtk_vbox_new(FALSE, 5);
-	gtk_paned_pack2(GTK_PANED(vpaned), vbox, TRUE, FALSE);
-	gtk_widget_show(vbox);
-
-	toolbar = build_conv_toolbar(b);
-	gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
-
-	frame = gtk_frame_new(NULL);
-	gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
-	gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(frame), TRUE, TRUE, 0);
-	gtk_widget_show(frame);
-	
-	b->entry_buffer = gtk_text_buffer_new(NULL);
-	g_object_set_data(G_OBJECT(b->entry_buffer), "user_data", b);
-	chatentry = gtk_text_view_new_with_buffer(b->entry_buffer);
-	b->entry = chatentry;
-	if (!(chat_options & OPT_CHAT_ONE_WINDOW)
-			|| ((gtk_notebook_get_current_page(GTK_NOTEBOOK(chat_notebook)) == 0)
-				&& (b == g_list_nth_data(chats, 0))))
-		gtk_widget_grab_focus(b->entry);
-
-
-	b->makesound = 1; /* Need to do this until we get a menu */
-
-	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(b->entry), GTK_WRAP_WORD);
-	g_signal_connect(G_OBJECT(b->entry), "key_press_event", G_CALLBACK(keypress_callback), b);
-	g_signal_connect_after(G_OBJECT(b->entry), "button_press_event", 
-			       G_CALLBACK(stop_rclick_callback), NULL);
-	g_signal_connect_swapped(G_OBJECT(chatentry), "key_press_event", 
-				 G_CALLBACK(entry_key_pressed), chatentry);
-	gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(chatentry));
-	gtk_widget_set_usize(chatentry, buddy_chat_size.width, MAX(buddy_chat_size.entry_height, 25));
-	gtk_window_set_focus(GTK_WINDOW(win), chatentry);
-	gtk_widget_show(chatentry);
-#ifdef USE_GTKSPELL
-	if (convo_options & OPT_CONVO_CHECK_SPELLING)
-		gtkspell_attach(GTK_TEXT_VIEW(chatentry));
-#endif
-	bbox = gtk_hbox_new(FALSE, 5);
-	gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
-	gtk_widget_show(bbox);
-
-	/* 
-	close = picture_button2(win, _("Close"), cancel_xpm, dispstyle);
-	b->close = close;
-	gtk_object_set_user_data(GTK_OBJECT(close), b);
-	g_signal_connect(GTK_OBJECT(close), "clicked", G_CALLBACK(close_callback), b);
-	gtk_box_pack_end(GTK_BOX(bbox), close, dispstyle, dispstyle, 0);
-	*/
-
-	/* Send */
-	button = gaim_pixbuf_button_from_stock(
-				(dispstyle == 0 ? NULL : _("Send")),
-				(dispstyle == 1 ? NULL : "gtk-convert"),
-				GAIM_BUTTON_VERTICAL);
-
-	gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
-	g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(send_callback), b);
-	gtk_widget_show(button);
-	gtk_box_pack_end(GTK_BOX(bbox), button, FALSE, FALSE, 0);
-	b->send = button;
-
-	/* Sep */
-	sep = gtk_vseparator_new();
-	gtk_box_pack_start(GTK_BOX(bbox), sep, FALSE, FALSE, 0);
-
-	/* Invite */
-	button = gaim_pixbuf_button_from_stock(
-				(dispstyle == 0 ? NULL : _("Invite")),
-				(dispstyle == 1 ? NULL : "gtk-jump-to"),
-				GAIM_BUTTON_VERTICAL);
-
-	g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(invite_callback), b);
-	gtk_widget_show(button);
-	gtk_box_pack_end(GTK_BOX(bbox), button, FALSE, FALSE, 0);
-	gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
-	b->invite = button;
-
-
-	b->font_dialog = NULL;
-	b->fg_color_dialog = NULL;
-	b->bg_color_dialog = NULL;
-	b->smiley_dialog = NULL;
-	b->link_dialog = NULL;
-	b->log_dialog = NULL;
-	sprintf(b->fontface, "%s", fontface);
-	b->hasfont = 0;
-	b->bgcol = bgcolor;
-	b->hasbg = 0;
-	b->fgcol = fgcolor;
-	b->hasfg = 0;
-
-	update_buttons_by_protocol(b);
-
-	gtk_widget_show(win);
-}
-
-void chat_set_topic(struct conversation *b, char *who, char *topic)
-{
-	gtk_entry_set_text(GTK_ENTRY(b->topic_text), topic);
-	if (b->topic)
-		g_free(b->topic);
-	b->topic = g_strdup(topic);
-}
-
-
-
-void delete_chat(struct conversation *b)
-{
-	while (b->in_room) {
-		g_free(b->in_room->data);
-		b->in_room = g_list_remove(b->in_room, b->in_room->data);
-	}
-	while (b->ignored) {
-		g_free(b->ignored->data);
-		b->ignored = g_list_remove(b->ignored, b->ignored->data);
-	}
-	g_string_free(b->history, TRUE);
-	if (b->topic)
-		g_free(b->topic);
-	g_free(b);
-}
-
-static GtkWidget *change_text(GtkWidget *win, char *text, GtkWidget *button, char *stock, int chat)
-{
-	int dispstyle = set_dispstyle(chat);
-	gtk_widget_destroy(button);
-	/* XXX button = picture_button2(win, text, xpm, dispstyle); */
-	button = gaim_pixbuf_button_from_stock((dispstyle == 0 ? NULL : text),
-										   (dispstyle == 1 ? NULL : stock),
-										   GAIM_BUTTON_VERTICAL);
-#if 0
-	if (chat == 1)
-		gtk_box_pack_start(GTK_BOX(parent), button, dispstyle, dispstyle, 5);
-	else
-		gtk_box_pack_end(GTK_BOX(parent), button, dispstyle, dispstyle, 0);
-
-	gtk_box_pack_start(GTK_BOX(parent), button, dispstyle, dispstyle, 0);
-#endif
-
-	gtk_widget_show(button);
-	return button;
-}
-
-void update_chat_button_pix()
-{
-	GSList *C = connections;
-	struct gaim_connection *g;
-	GtkWidget *parent;
-
-	while (C) {
-		GSList *bcs;
-		struct conversation *c;
-		int opt = 1;
-		g = (struct gaim_connection *)C->data;
-		bcs = g->buddy_chats;
-
-		while (bcs) {
-			c = (struct conversation *)bcs->data;
-			parent = c->send->parent;
-
-			c->send = change_text(c->window, _("Send"), c->send, "gtk-convert", opt);
-			c->invite = change_text(c->window, _("Invite"), c->invite, "gtk-jump-to", opt);
-			gtk_box_pack_end(GTK_BOX(parent), c->send, FALSE, FALSE, 0);
-			gtk_box_pack_end(GTK_BOX(parent), c->invite, FALSE, FALSE, 0);
-
-			g_signal_connect(GTK_OBJECT(c->send), "clicked",
-					   G_CALLBACK(send_callback), c);
-			g_signal_connect(GTK_OBJECT(c->invite), "clicked",
-					   G_CALLBACK(invite_callback), c);
-
-			gtk_button_set_relief(GTK_BUTTON(c->send), GTK_RELIEF_NONE);
-			gtk_button_set_relief(GTK_BUTTON(c->invite), GTK_RELIEF_NONE);
-
-			update_buttons_by_protocol(c);
-
-			bcs = bcs->next;
-		}
-		C = C->next;
-	}
-}
-
-void update_im_button_pix()
-{
-	GList *bcs = conversations;
-	struct conversation *c;
-	GtkWidget *parent;
-	int opt = 0;
-
-	while (bcs) {
-		c = (struct conversation *)bcs->data;
-		parent = c->send->parent;
-
-		c->send = change_text(c->window, _("Send"), c->send, "gtk-convert", opt);
-		gtk_box_pack_end(GTK_BOX(parent), c->send, FALSE, FALSE, 0);
-
-		gtk_widget_destroy(c->sep2);
-		c->sep2 = gtk_vseparator_new();
-		gtk_box_pack_end(GTK_BOX(parent), c->sep2, FALSE, TRUE, 0);
-		gtk_widget_show(c->sep2);
-
-		if (find_buddy(c->gc->user, c->name) == NULL)
-			c->add = change_text(c->window, _("Add"), c->add, "gtk-add", opt);
-		else
-			c->add = change_text(c->window, _("Remove"), c->add, "gtk-remove", opt);
-
-		gtk_box_pack_start(GTK_BOX(parent), c->add, FALSE, FALSE, 0);
-
-		c->warn = change_text(c->window, _("Warn"), c->warn, "gtk-dialog-warning", opt);
-		gtk_box_pack_start(GTK_BOX(parent), c->warn, FALSE, FALSE, 0);
-
-		c->info = change_text(c->window, _("Info"), c->info, "gtk-find", opt);
-		gtk_box_pack_start(GTK_BOX(parent), c->info, FALSE, FALSE, 0);
-
-		c->block = change_text(c->window, _("Block"), c->block, "gtk-stop", opt);
-		gtk_box_pack_start(GTK_BOX(parent), c->block, FALSE, FALSE, 0);
-
-		gtk_button_set_relief(GTK_BUTTON(c->info), GTK_RELIEF_NONE);
-		gtk_button_set_relief(GTK_BUTTON(c->add), GTK_RELIEF_NONE);
-		gtk_button_set_relief(GTK_BUTTON(c->warn), GTK_RELIEF_NONE);
-		gtk_button_set_relief(GTK_BUTTON(c->send), GTK_RELIEF_NONE);
-		gtk_button_set_relief(GTK_BUTTON(c->block), GTK_RELIEF_NONE);
-
-		gtk_size_group_add_widget(c->sg, c->info);
-		gtk_size_group_add_widget(c->sg, c->add);
-		gtk_size_group_add_widget(c->sg, c->warn);
-		gtk_size_group_add_widget(c->sg, c->send);
-		gtk_size_group_add_widget(c->sg, c->block);
-
-		gtk_box_reorder_child(GTK_BOX(parent), c->warn, 1);
-		gtk_box_reorder_child(GTK_BOX(parent), c->block, 2);
-		gtk_box_reorder_child(GTK_BOX(parent), c->info, 4);
-
-
-		update_buttons_by_protocol(c);
-
-		g_signal_connect(GTK_OBJECT(c->send), "clicked", G_CALLBACK(send_callback), c);
-		g_signal_connect(GTK_OBJECT(c->info), "clicked", G_CALLBACK(info_callback), c);
-		g_signal_connect(GTK_OBJECT(c->warn), "clicked", G_CALLBACK(warn_callback), c);
-		g_signal_connect(GTK_OBJECT(c->block), "clicked", G_CALLBACK(block_callback), c);
-		bcs = bcs->next;
-	}
-}
-
-void chat_tabize()
-{
-	int pos = 0;
-	char tmp[BUF_LONG];
-	/* evil, evil i tell you! evil! */
-	if (chat_options & OPT_CHAT_ONE_WINDOW) {
-		GList *x = chats;
-		if ((convo_options & OPT_CONVO_COMBINE) && (im_options & OPT_IM_ONE_WINDOW)) {
-			all_chats = all_convos;
-			chat_notebook = convo_notebook;
-		}
-		while (x) {
-			struct conversation *c = x->data;
-			GtkWidget *imhtml, *win;
-			GList *r = c->in_room;
-
-			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),
-						      G_CALLBACK(close_callback), c);
-			gtk_widget_destroy(win);
-
-			if (c->topic)
-				gtk_entry_set_text(GTK_ENTRY(c->topic_text), c->topic);
-
-			g_snprintf(tmp, sizeof(tmp), ngettext("%d person in room", "%d people in room",
-				    g_list_length(c->in_room)),  g_list_length(c->in_room));
-			gtk_label_set_text(GTK_LABEL(c->count), tmp);
-
-			while (r) {
-				char *name = r->data;
-
-				add_chat_buddy_common(c, name, pos);
-
-				r = r->next;
-				pos++;
-			}
-
-			x = x->next;
-		}
-	} else {
-		GList *x, *m;
-		x = m = chats;
-		chats = NULL;
-		while (x) {
-			struct conversation *c = x->data;
-			GtkWidget *imhtml;
-			GList *r = c->in_room;
-
-			imhtml = c->text;
-			show_new_buddy_chat(c);
-			gtk_widget_destroy(c->text);
-			gtk_widget_reparent(imhtml, c->sw);
-			c->text = imhtml;
-
-			if (c->topic)
-				gtk_entry_set_text(GTK_ENTRY(c->topic_text), c->topic);
-
-			g_snprintf(tmp, sizeof(tmp), ngettext("%d person in room", "%d people in room",
-				    g_list_length(c->in_room)),  g_list_length(c->in_room));
-			gtk_label_set_text(GTK_LABEL(c->count), tmp);
-
-			while (r) {
-				char *name = r->data;
-
-				add_chat_buddy_common(c, name, pos);
-
-				r = r->next;
-				pos++;
-			}
-
-			x = x->next;
-		}
-		chats = m;
-		if ((convo_options & OPT_CONVO_COMBINE) &&
-		    (im_options & OPT_IM_ONE_WINDOW) && conversations) {
-			while (m) {
-				gtk_notebook_remove_page(GTK_NOTEBOOK(chat_notebook),
-							 g_list_length(conversations));
-				m = m->next;
-			}
-		} else if (all_chats)
-			gtk_widget_destroy(all_chats);
-		all_chats = NULL;
-		chat_notebook = NULL;
-	}
-}
--- a/src/conversation.c	Mon Jan 20 07:00:10 2003 +0000
+++ b/src/conversation.c	Mon Jan 20 09:10:23 2003 +0000
@@ -1,7 +1,7 @@
 /*
  * gaim
  *
- * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
+ * Copyright (C) 2002-2003, Christian Hammond <chipx86@gnupdate.org>
  * 
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -22,1172 +22,355 @@
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
+
 #include <string.h>
-#ifndef _WIN32
-#include <sys/time.h>
-#include <unistd.h>
-#include <gdk/gdkx.h>
-#include <X11/Xlib.h>
-#else
-#ifdef small
-#undef small
-#endif
-#endif /*_WIN32*/
-#include <sys/types.h>
+#include <stdlib.h>
 #include <sys/stat.h>
-#include <stdio.h>
-#include <stdlib.h>
 #include <errno.h>
 #include <ctype.h>
-#include <gtk/gtk.h>
-#ifdef USE_GTKSPELL
-#include <gtkspell/gtkspell.h>
-#endif
-#include "gtkimhtml.h"
-#include <gdk/gdkkeysyms.h>
-#include "convo.h"
+#include "conversation.h"
+#include "gaim.h"
 #include "prpl.h"
 
-#ifdef _WIN32
-#include <process.h> /* for getpid() */
-#include <io.h>
-#include "win32dep.h"
-#endif
-
-int state_lock = 0;
-
-GdkPixmap *dark_icon_pm = NULL;
-GdkBitmap *dark_icon_bm = NULL;
-
-GtkWidget *all_convos = NULL;
-GtkWidget *convo_notebook = NULL;
-GtkWidget *convo_menubar = NULL;
-
-char fontface[128] = { 0 };
-int fontsize = 3;
+#define SEND_TYPED_TIMEOUT 5000
 
-extern GdkColor bgcolor;
-extern GdkColor fgcolor;
-
-void check_everything(GtkTextBuffer *buffer);
-gboolean keypress_callback(GtkWidget *entry, GdkEventKey * event, struct conversation *c);
-gboolean stop_rclick_callback(GtkWidget *widget, GdkEventButton *event, gpointer data);
-
-static void update_icon(struct conversation *);
-static void remove_icon(struct conversation *);
+static GList *conversations = NULL;
+static GList *ims = NULL;
+static GList *chats = NULL;
+static GList *windows = NULL;
 
-static void update_checkbox(struct conversation *);
-static void remove_checkbox(struct conversation *);
-
-
-
-/*------------------------------------------------------------------------*/
-/*  Helpers                                                               */
-/*------------------------------------------------------------------------*/
-
-
-
-void gaim_setup_imhtml(GtkWidget *imhtml)
+static gint
+insertname_compare(gconstpointer one, gconstpointer two)
 {
-	g_return_if_fail(imhtml != NULL);
-	g_return_if_fail(GTK_IS_IMHTML(imhtml));
-	if (!(convo_options & OPT_CONVO_SHOW_SMILEY))
-		gtk_imhtml_show_smileys(GTK_IMHTML(imhtml), FALSE);
-
-	g_signal_connect(GTK_OBJECT(imhtml), "url_clicked", G_CALLBACK(open_url), NULL);
-	smiley_themeize(imhtml);	
-}
-
-void quiet_set(GtkWidget *tb, int state)
-{
-	state_lock = 1;
-	gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(tb), state);
-	state_lock = 0;
-}
-
-
-void set_state_lock(int i)
-{
-	state_lock = i;
-}
-
-void toggle_sensitive(GtkWidget *widget, GtkWidget *to_toggle)
-{
-	gboolean sensitivity = GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(to_toggle));
-
-	if (sensitivity == TRUE)
-		gtk_widget_set_sensitive(GTK_WIDGET(to_toggle), FALSE);
-	else
-		gtk_widget_set_sensitive(GTK_WIDGET(to_toggle), TRUE);
-
-	return;
-}
-
-void set_convo_name(struct conversation *c, const char *nname)
-{
-
-	g_snprintf(c->name, sizeof(c->name), "%s", nname);
-
-	return;
-}
-
-struct conversation *new_conversation(char *name)
-{
-	struct conversation *c;
+	const char *a = (const char *)one;
+	const char *b = (const char *)two;
 
-	c = find_conversation(name);
-
-	if (c != NULL)
-		return c;
-
-	c = (struct conversation *)g_new0(struct conversation, 1);
-	g_snprintf(c->name, sizeof(c->name), "%s", name);
-
-	if ((logging_options & OPT_LOG_CONVOS) || find_log_info(c->name)) {
-		FILE *fd;
+	if (*a == '@') {
+		if (*b != '@') return -1;
 
-		fd = open_log_file(c->name, c->is_chat);
-		if (fd) {
-			if (!(logging_options & OPT_LOG_STRIP_HTML))
-				fprintf(fd,
-					"<HR><BR><H3 Align=Center> ---- New Conversation @ %s ----</H3><BR>\n",
-					full_date());
-			else
-				fprintf(fd, " ---- New Conversation @ %s ----\n", full_date());
-			fclose(fd);
-		} else
-			/* do we want to do something here? */ ;
-	}
-
-	if (connections)
-		c->gc = (struct gaim_connection *)connections->data;
-	c->history = g_string_new("");
-	c->send_history = g_list_append(NULL, NULL);
-	conversations = g_list_append(conversations, c);
-	show_conv(c);
-	update_icon(c);
-	update_checkbox(c);
-	plugin_event(event_new_conversation, name);
-	/*gtk_imhtml_to_bottom(c->text);*/
-	return c;
-}
-
-
-struct conversation *find_conversation(const char *name)
-{
-	char *cuser = g_malloc(BUF_LEN);
-	struct conversation *c;
-	GList *cnv = conversations;
+		return (strcasecmp(a + 1, b + 1));
 
-	strcpy(cuser, normalize(name));
-
-	while (cnv) {
-		c = (struct conversation *)cnv->data;
-		if (!g_strcasecmp(cuser, normalize(c->name))) {
-			g_free(cuser);
-			return c;
-		}
-		cnv = cnv->next;
-	}
-	g_free(cuser);
-	return NULL;
-}
+	} else if (*a == '+') {
+		if (*b == '@') return  1;
+		if (*b != '+') return -1;
+		
+		return (strcasecmp(a + 1, b + 1));
 
-void delete_conversation(struct conversation *c)
-{
-	plugin_event(event_del_conversation, c);
-	conversations = g_list_remove(conversations, c);
-	if (c->fg_color_dialog)
-		gtk_widget_destroy(c->fg_color_dialog);
-	if (c->bg_color_dialog)
-		gtk_widget_destroy(c->bg_color_dialog);
-	if (c->font_dialog)
-		gtk_widget_destroy(c->font_dialog);
-	if (c->smiley_dialog)
-		gtk_widget_destroy(c->smiley_dialog);
-	if (c->link_dialog)
-		gtk_widget_destroy(c->link_dialog);
-	if (c->log_dialog)
-		gtk_widget_destroy(c->log_dialog);
-	if (c->save_icon)
-		gtk_widget_destroy(c->save_icon);
-	c->send_history = g_list_first(c->send_history);
-	while (c->send_history) {
-		if (c->send_history->data)
-			g_free(c->send_history->data);
-		c->send_history = c->send_history->next;
-	}
-	g_list_free(c->send_history);
-	if (c->typing_timeout)
-		g_source_remove(c->typing_timeout);
-	if (c->type_again_timeout)
-		g_source_remove(c->type_again_timeout);
-	g_string_free(c->history, TRUE);
-	g_free(c);
+	} else if (*a == '@' || *b == '+')
+		return 1;
+
+	return (strcasecmp(a, b));
 }
 
-void update_font_buttons()
+static gboolean
+find_nick(struct gaim_connection *gc, const char *message)
 {
-	GList *cnv = conversations;
-	struct conversation *c;
-
-	while (cnv) {
-		c = (struct conversation *)cnv->data;
-
-		if (c->bold)
-			gtk_widget_set_sensitive(c->bold,
-						 ((font_options & OPT_FONT_BOLD)) ? FALSE : TRUE);
-
-		if (c->italic)
-			gtk_widget_set_sensitive(c->italic,
-						 ((font_options & OPT_FONT_ITALIC)) ? FALSE : TRUE);
-
-		if (c->underline)
-			gtk_widget_set_sensitive(c->underline,
-						 ((font_options & OPT_FONT_UNDERLINE)) ? FALSE : TRUE);
-
-		cnv = cnv->next;
-	}
-}
-
-/*
-void update_transparency()
-{
-	GList *cnv = conversations;
-	struct conversation *c;
-
-        This func should be uncalled!
-
-	while(cnv) {
-		c = (struct conversation *)cnv->data;
-
-		if (c->text)
-			gtk_html_set_transparent(GTK_HTML(c->text),
-        						  (transparent) ? TRUE : FALSE);
+	char *msg, *who, *p;
+	int n;
 
-		cnv = cnv->next;
-	}
-}
-*/
-
-
-/*------------------------------------------------------------------------*/
-/*  Callbacks                                                             */
-/*------------------------------------------------------------------------*/
-
-void toggle_loggle(GtkWidget *loggle, struct conversation *c)
-{
-	if (state_lock)
-		return;
-
-	if (find_log_info(c->name))
-		rm_log(find_log_info(c->name));
-	else if (GTK_CHECK_MENU_ITEM(c->log_button)->active)
-		show_log_dialog(c);
-	else
-		cancel_log(NULL, c);
-}
-
-void toggle_sound(GtkWidget *widget, struct conversation *c)
-{
-	if (state_lock)
-		return;
-
-	c->makesound = !c->makesound;
-}
-
-static void do_insert_image(GtkObject *obj, GtkWidget *wid)
-{
-	struct conversation *c = gtk_object_get_user_data(obj);
-	const char *name = gtk_file_selection_get_filename(GTK_FILE_SELECTION(wid));
-	const char *filename;
-	char *buf;
-	struct stat st;
-	int id = g_slist_length(c->images) + 1;
-	
-	if (file_is_dir(name, wid))
-		return;
-	if (!(!c->is_chat && g_list_find(conversations, c)))
-		name = NULL;
-	gtk_widget_destroy(wid);
-	if (!name)
-		return;
+	msg = g_strdup(message);
+	g_strdown(msg);
 
-	if (stat(name, &st) != 0) {
-		debug_printf("Could not stat %s\n", name);
-		return;
-	}
-	
-	filename = name;
-	while (strchr(filename, '/')) 
-		filename = strchr(filename, '/') + 1;
-		
-	buf = g_strdup_printf ("<IMG SRC=\"file://%s\" ID=\"%d\" DATASIZE=\"%d\">",
-			       filename, id, (int)st.st_size);
-	c->images = g_slist_append(c->images, g_strdup(name));
-	gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER(c->entry_buffer),
-					 buf, -1);
-	g_free(buf);
-}
-
-void insert_image(GtkWidget *save, struct conversation *c)
-{
-	char buf[BUF_LONG];
-	GtkWidget *window = gtk_file_selection_new(_("Gaim - Insert Image"));
-	g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S, gaim_home_dir());
-	gtk_file_selection_set_filename(GTK_FILE_SELECTION(window), buf);
-	gtk_object_set_user_data(GTK_OBJECT(GTK_FILE_SELECTION(window)->ok_button), c);
-	g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(window)->ok_button),
-			   "clicked", G_CALLBACK(do_insert_image), window);
-	g_signal_connect_swapped(GTK_OBJECT(GTK_FILE_SELECTION(window)->cancel_button),
-				  "clicked", G_CALLBACK(gtk_widget_destroy), (gpointer)window);
-	gtk_widget_show(window);
-}
-
-
-void insert_smiley(GtkWidget *smiley, struct conversation *c)
-{
-	if (state_lock)
-		return;
-
-	if (GTK_TOGGLE_BUTTON(smiley)->active)
-		show_smiley_dialog(c, smiley);
-	else if (c->smiley_dialog)
-		close_smiley_dialog(smiley, c);
-
-	gtk_widget_grab_focus(c->entry);
-
-	return;
-}
-
-int close_callback(GtkWidget *widget, struct conversation *c)
-{
-	if (c->is_chat && (widget == c->close) && !(chat_options & OPT_CHAT_ONE_WINDOW)) {
-		GtkWidget *tmp = c->window;
-		debug_printf("chat clicked close button\n");
-		c->window = NULL;
-		gtk_widget_destroy(tmp);
-		return FALSE;
-	}
-
-	debug_printf("conversation close callback\n");
+	who = g_strdup(gc->username);
+	g_strdown(who);
+	n = strlen(who);
 
-	if (!c->is_chat) {
-		GSList *cn = connections;
-		if (!(misc_options & OPT_MISC_STEALTH_TYPING))
-			serv_send_typing(c->gc, c->name, NOT_TYPING);
-		while (cn) {
-			struct gaim_connection *gc = cn->data;
-			cn = cn->next;
-			if (gc->prpl->convo_closed)
-				gc->prpl->convo_closed(gc, c->name);
-		}
-		remove_icon(c);
-		remove_checkbox(c);
-		if (im_options & OPT_IM_ONE_WINDOW) {
-			if ((g_list_length(conversations) > 1) ||
-					((convo_options & OPT_CONVO_COMBINE) &&
-					 (chat_options & OPT_CHAT_ONE_WINDOW) && chats)) {
-				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;
-				convo_notebook = NULL;
-				if (convo_options & OPT_CONVO_COMBINE) {
-					all_chats = NULL;
-					chat_notebook = NULL;
-				}
-			}
-		} else {
-			if (c->window)
-				gtk_widget_destroy(c->window);
-			c->window = NULL;
-		}
-	} else {
-		if (chat_options & OPT_CHAT_ONE_WINDOW) {
-			if ((convo_options & OPT_CONVO_COMBINE) && (im_options & OPT_IM_ONE_WINDOW)
-					&& (conversations || chats->next)) {
-				gtk_notebook_remove_page(GTK_NOTEBOOK(chat_notebook),
-							 g_list_index(chats, c) +
-								g_list_length(conversations));
-			} else 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;
-				chat_notebook = NULL;
-				if (convo_options & OPT_CONVO_COMBINE) {
-					all_convos = NULL;
-					convo_notebook = NULL;
-				}
-			}
-		} else {
-			if (c->window)
-				gtk_widget_destroy(c->window);
-			c->window = NULL;
+	if ((p = strstr(msg, who)) != NULL) {
+		if ((p == msg || !isalnum(*(p - 1))) && !isalnum(*(p + n))) {
+			g_free(who);
+			g_free(msg);
+
+			return TRUE;
 		}
 	}
 
-	if (c->fg_color_dialog)
-		gtk_widget_destroy(c->fg_color_dialog);
-	c->fg_color_dialog = NULL;
-	if (c->bg_color_dialog)
-		gtk_widget_destroy(c->bg_color_dialog);
-	c->bg_color_dialog = NULL;
-	if (c->font_dialog)
-		gtk_widget_destroy(c->font_dialog);
-	c->font_dialog = NULL;
-	if (c->smiley_dialog)
-		gtk_widget_destroy(c->smiley_dialog);
-	c->smiley_dialog = NULL;
-	if (c->link_dialog)
-		gtk_widget_destroy(c->link_dialog);
-	c->link_dialog = NULL;
-	if (c->log_dialog)
-		gtk_widget_destroy(c->log_dialog);
-	c->log_dialog = NULL;
+	g_free(who);
 
-	if (c->is_chat) {
-		chats = g_list_remove(chats, c);
-		if (c->gc)
-			serv_chat_leave(c->gc, c->id);
-		else
-			delete_chat(c);
-	} else {
-		delete_conversation(c);
+	if (!g_strcasecmp(gc->username, gc->displayname)) {
+		g_free(msg);
+
+		return FALSE;
 	}
 
-	return TRUE;
-}
-
-void set_font_face(char *newfont, struct conversation *c)
-{
-	char *pre_fontface;
-	
-	sprintf(c->fontface, "%s", newfont && *newfont ? newfont : DEFAULT_FONT_FACE);
-	c->hasfont = 1;
-
-	pre_fontface = g_strconcat("<FONT FACE=\"", c->fontface, "\">", NULL);
-	surround(c, pre_fontface, "</FONT>");
-	gtk_widget_grab_focus(c->entry);
-	g_free(pre_fontface);
-}
-
-gint delete_all_convo(GtkWidget *w, GdkEventAny *e, gpointer d)
-{
-	if (w == all_convos) {
-		while (conversations) {
-			struct conversation *c = conversations->data;
-			close_callback(c->close, c);
-		}
-	}
-	if (w == all_chats) {
-		while (chats) {
-			struct conversation *c = chats->data;
-			close_callback(c->close, c);
-		}
-	}
-	return FALSE;
-}
-
-static gint delete_event_convo(GtkWidget *w, GdkEventAny *e, struct conversation *c)
-{
-	delete_conversation(c);
-	return FALSE;
-}
-
-void add_callback(GtkWidget *widget, struct conversation *c)
-{
-	struct buddy *b = find_buddy(c->gc->user, c->name);
-	if (b) {
-		show_confirm_del(c->gc, c->name);
-	} else if (c->gc)
-		show_add_buddy(c->gc, c->name, NULL, NULL);
-
-	gtk_widget_grab_focus(c->entry);
-}
-
-
-void block_callback(GtkWidget *widget, struct conversation *c)
-{
-	if (c->gc)
-		show_add_perm(c->gc, c->name, FALSE);
-	gtk_widget_grab_focus(c->entry);
-}
-
-void warn_callback(GtkWidget *widget, struct conversation *c)
-{
-	show_warn_dialog(c->gc, c->name);
-	gtk_widget_grab_focus(c->entry);
-}
-
-void info_callback(GtkWidget *w, struct conversation *c)
-{
-	if (c->is_chat) {
-		GtkTreeIter iter;
-		GtkTreeModel *mod = gtk_tree_view_get_model(GTK_TREE_VIEW(c->list));
-		GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(c->list));
-		gchar *name;
-
-		if (gtk_tree_selection_get_selected(sel, NULL, &iter)) {
-			gtk_tree_model_get(GTK_TREE_MODEL(mod), &iter, 1, &name, -1);
-		} else {
-			return;
-		}
-
-		serv_get_info(c->gc, name);
-
-	} else {
-		serv_get_info(c->gc, c->name);
-		gtk_widget_grab_focus(c->entry);
-	}
-}
-
-static void move_next_tab(GtkNotebook *notebook, gboolean chat)
-{
-	int currpage = gtk_notebook_get_current_page(notebook);
-	int convlen;
-	GList *cnv;
-	struct conversation *d = NULL;
+	who = g_strdup(gc->displayname);
+	g_strdown(who);
+	n = strlen(who);
 
-	if ((convo_options & OPT_CONVO_COMBINE) &&
-	    (im_options & OPT_IM_ONE_WINDOW) &&
-	    (chat_options & OPT_CHAT_ONE_WINDOW))
-		convlen = g_list_length(conversations);
-	else
-		convlen = 0;
-
-	if (chat) {
-		/* if chat, find next unread chat */
-		cnv = g_list_nth(chats, currpage - convlen);
-		while (cnv) {
-			d = cnv->data;
-			if (d->unseen > 0)
-				break;
-			cnv = cnv->next;
-			d = NULL;
-		}
-		if (d) {
-			gtk_notebook_set_page(notebook, convlen + g_list_index(chats, d));
-			return;
-		}
-	} else {
-		/* else find next unread convo */
-		cnv = g_list_nth(conversations, currpage);
-		while (cnv) {
-			d = cnv->data;
-			if (d->unseen > 0)
-				break;
-			cnv = cnv->next;
-			d = NULL;
-		}
-		if (d) {
-			gtk_notebook_set_page(notebook, g_list_index(conversations, d));
-			return;
-		}
-	}
+	if (n > 0 && (p = strstr(msg, who)) != NULL) {
+		if ((p == msg || !isalnum(*(p - 1))) && !isalnum(*(p + n))) {
+			g_free(who);
+			g_free(msg);
 
-	if (convo_options & OPT_CONVO_COMBINE) {
-		if (chat && (im_options & OPT_IM_ONE_WINDOW)) {
-			/* if chat find next unread convo */
-			cnv = conversations;
-			while (cnv) {
-				d = cnv->data;
-				if (d->unseen > 0)
-					break;
-				cnv = cnv->next;
-				d = NULL;
-			}
-			if (d) {
-				gtk_notebook_set_page(notebook, g_list_index(conversations, d));
-				return;
-			}
-		} else if (!chat && (chat_options & OPT_CHAT_ONE_WINDOW)) {
-			/* else find next unread chat */
-			cnv = chats;
-			while (cnv) {
-				d = cnv->data;
-				if (d->unseen > 0)
-					break;
-				cnv = cnv->next;
-				d = NULL;
-			}
-			if (d) {
-				gtk_notebook_set_page(notebook, convlen + g_list_index(chats, d));
-				return;
-			}
-		}
-	}
-
-	if (chat) {
-		/* if chat find first unread chat */
-		cnv = chats;
-		while (cnv) {
-			d = cnv->data;
-			if (d->unseen > 0)
-				break;
-			cnv = cnv->next;
-			d = NULL;
-		}
-		if (d) {
-			gtk_notebook_set_page(notebook, convlen + g_list_index(chats, d));
-			return;
-		}
-	} else {
-		/* else find first unread convo */
-		cnv = conversations;
-		while (cnv) {
-			d = cnv->data;
-			if (d->unseen > 0)
-				break;
-			cnv = cnv->next;
-			d = NULL;
-		}
-		if (d) {
-			gtk_notebook_set_page(notebook, g_list_index(conversations, d));
-			return;
+			return TRUE;
 		}
 	}
 
-	/* go to next page */
-	if (currpage + 1 == g_list_length(notebook->children))
-		gtk_notebook_set_page(notebook, 0);
-	else
-		gtk_notebook_next_page(notebook);
-}
-
-#define SEND_TYPED_TIMEOUT 5000
+	g_free(who);
+	g_free(msg);
 
-gboolean send_typed(gpointer data)
-{
-	struct conversation *c = (struct conversation*)data;
-	if (c && c->gc && c->name) {
-		c->type_again = 1;
-		serv_send_typing(c->gc, c->name, TYPED);
-		debug_printf("typed...\n");
-	}
 	return FALSE;
 }
 
-gboolean keypress_callback(GtkWidget *entry, GdkEventKey *event, struct conversation *c)
+static gboolean
+reset_typing(gpointer data)
 {
-	if (event->keyval == GDK_Escape) {
-		if (convo_options & OPT_CONVO_ESC_CAN_CLOSE) {
-			gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-			close_callback(c->close, c);
-			c = NULL;
-		}
-	} else if (event->keyval == GDK_Page_Up) {
-		gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-		if(!(event->state & GDK_CONTROL_MASK))
-			gtk_imhtml_page_up(GTK_IMHTML(c->text));
-	} else if (event->keyval == GDK_Page_Down) {
-		gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-		if(!(event->state & GDK_CONTROL_MASK))
-			gtk_imhtml_page_down(GTK_IMHTML(c->text));
-	} else if ((event->keyval == GDK_F2) && (convo_options & OPT_CONVO_F2_TOGGLES)) {
-		gtk_imhtml_show_comments(GTK_IMHTML(c->text), !GTK_IMHTML(c->text)->show_comments);
-	} else if ((event->keyval == GDK_Return) || (event->keyval == GDK_KP_Enter)) {
-		if ((event->state & GDK_CONTROL_MASK) && (convo_options & OPT_CONVO_CTL_ENTER)) {
-			send_callback(NULL, c);
-			gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-			return TRUE;
-		} else if (!(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK)) && (convo_options & OPT_CONVO_ENTER_SENDS)) {
-			send_callback(NULL, c);
-			gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-			return TRUE;
-		} else {
-			return FALSE;
-		}
-	} else if ((event->state & GDK_CONTROL_MASK) && (event->keyval == 'm')) {
-		gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-		gtk_text_buffer_insert_at_cursor(c->entry_buffer, "\n", 1);
-	} else if (event->state & GDK_CONTROL_MASK) {
-		switch (event->keyval) {
-		case GDK_Up:
-			if (!c->send_history)
-				break;
-			if (!c->send_history->prev) {
-				GtkTextIter start, end;
-				if (c->send_history->data)
-					g_free(c->send_history->data);
-				gtk_text_buffer_get_start_iter(c->entry_buffer, &start);
-				gtk_text_buffer_get_end_iter(c->entry_buffer, &end);
-				c->send_history->data = gtk_text_buffer_get_text(c->entry_buffer,
-										 &start, &end, FALSE);
-			} 
-			if (c->send_history->next && c->send_history->next->data) {
-				c->send_history = c->send_history->next;
-				gtk_text_buffer_set_text(c->entry_buffer, c->send_history->data, -1);
-			}
-			
-			break;
-		case GDK_Down:
-		  if (!c->send_history) 
-				break;
-			if (c->send_history->prev) {
-			  c->send_history = c->send_history->prev;
-				if (c->send_history->data) {
-					gtk_text_buffer_set_text(c->entry_buffer, c->send_history->data, -1);
-				}
-			}
-			break;
-		}
-		if (convo_options & OPT_CONVO_CTL_CHARS) {
-			switch (event->keyval) {
-			case 'i':
-			case 'I':
-				quiet_set(c->italic,
-					  !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->italic)));
-				do_italic(c->italic, c);
-				gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-				break;
-			case 'u':	/* ctl-u is GDK_Clear, which clears the line */
-			case 'U':
-				quiet_set(c->underline,
-					  !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
-									(c->underline)));
-				do_underline(c->underline, c);
-				gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-				break;
-			case 'b':	/* ctl-b is GDK_Left, which moves backwards */
-			case 'B':
-				quiet_set(c->bold,
-					  !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->bold)));
-				do_bold(c->bold, c);
-				gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-				break;
-			case '-':
-				do_small(NULL, c);
-				gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-				break;
-			case '=':
-			case '+':
-				do_big(NULL, c);
-				gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-				break;	
-			case '0':
-				do_normal(NULL, c);
-				gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-				break;
-			case 'f':
-			case 'F':
-				quiet_set(c->font,
-					  !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->font)));
-				toggle_font(c->font, c);
-				gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-				break;
-			}
-		}
-		if (convo_options & OPT_CONVO_CTL_SMILEYS) {
-			char buf[7];
-			buf[0] = '\0';
-			switch (event->keyval) {
-			case '1':
-				sprintf(buf, ":-)");
-				break;
-			case '2':
-				sprintf(buf, ":-(");
-				break;
-			case '3':
-				sprintf(buf, ";-)");
-				break;
-			case '4':
-				sprintf(buf, ":-P");
-				break;
-			case '5':
-				sprintf(buf, "=-O");
-				break;
-			case '6':
-				sprintf(buf, ":-*");
-				break;
-			case '7':
-				sprintf(buf, ">:o");
-				break;
-			case '8':
-				sprintf(buf, "8-)");
-				break;
-			case '!':
-				sprintf(buf, ":-$");
-				break;
-			case '@':
-				sprintf(buf, ":-!");
-				break;
-			case '#':
-				sprintf(buf, ":-[");
-				break;
-			case '$':
-				sprintf(buf, "O:-)");
-				break;
-			case '%':
-				sprintf(buf, ":-/");
-				break;
-			case '^':
-				sprintf(buf, ":'(");
-				break;
-			case '&':
-				sprintf(buf, ":-X");
-				break;
-			case '*':
-				sprintf(buf, ":-D");
-				break;
-			}
-			if (buf[0]) {
-				gtk_text_buffer_insert_at_cursor(c->entry_buffer, buf, -1);
-				gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-			}
-		}
-		if (event->keyval == 'l') {
-			gtk_imhtml_clear(GTK_IMHTML(c->text));
-			g_string_free(c->history, TRUE);
-			c->history = g_string_new("");
-		} else if ((event->keyval == 'w') && (convo_options & OPT_CONVO_CTL_W_CLOSES)) {
-			gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-			close_callback(c->close, c);
-			c = NULL;
-			return TRUE;
-		} else if (event->keyval == 'n') {
-			gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-			show_im_dialog();
-		} else if (event->keyval == 'z') {
-			gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-#ifndef _WIN32
-			XIconifyWindow(GDK_DISPLAY(),
-				       GDK_WINDOW_XWINDOW(c->window->window),
-				       ((_XPrivDisplay)GDK_DISPLAY())->default_screen);		     
-#endif
-		}
-		
+	char *name = (char *)data;
+	struct gaim_conversation *c = gaim_find_conversation(name);
+	struct gaim_im *im;
+
+	if (!c)
+		return FALSE;
+
+	im = GAIM_IM(c);
+
+	gaim_im_set_typing_state(im, NOT_TYPING);
+	gaim_im_update_typing(im);
+	gaim_im_stop_typing_timeout(im);
+
+	return FALSE;
+}
 
-		if ((!c->is_chat && (im_options & OPT_IM_ONE_WINDOW)) ||
-		    (c->is_chat && (chat_options & OPT_CHAT_ONE_WINDOW))) {
-			GtkWidget *notebook = (c->is_chat ? chat_notebook : convo_notebook);
-			if (event->keyval == '[') {
-				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(notebook));
-				gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-			} else if (event->keyval == GDK_Tab) {
-				move_next_tab(GTK_NOTEBOOK(notebook), c->is_chat);
-				gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-				return TRUE;
-			}
-		}
-	} else if ((event->keyval == GDK_Tab) && c->is_chat && (chat_options & OPT_CHAT_TAB_COMPLETE)) {
-	        tab_complete(c);
-		gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event");
-		return TRUE;
-	} else if (((!c->is_chat && (im_options & OPT_IM_ONE_WINDOW)) ||
-		    (c->is_chat && (chat_options & OPT_CHAT_ONE_WINDOW))) &&
-		   (event->state & GDK_MOD1_MASK) && (event->keyval > '0') && (event->keyval <= '9')) {
-		GtkWidget *notebook = NULL;
-		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");
+static gboolean
+send_typed(gpointer data)
+{
+	struct gaim_conversation *conv = (struct gaim_conversation *)data;
+	struct gaim_connection *gc;
+	const char *name;
+
+	gc   = gaim_conversation_get_gc(conv);
+	name = gaim_conversation_get_name(conv);
+
+	if (conv != NULL && gc != NULL && name != NULL) {
+		gaim_im_set_type_again(GAIM_IM(conv), TRUE);
+
+		/* XXX Somebody add const stuff! */
+		serv_send_typing(gc, (char *)name, TYPED);
+
+		debug_printf("typed...\n");
 	}
 
 	return FALSE;
 }
 
-/* This guy just kills a single right click from being propagated any 
- * further.  I have no idea *why* we need this, but we do ...  It 
- * prevents right clicks on the GtkTextView in a convo dialog from
- * going all the way down to the notebook.  I suspect a bug in 
- * GtkTextView, but I'm not ready to point any fingers yet. */
-gboolean stop_rclick_callback(GtkWidget *widget, GdkEventButton *event, gpointer data)
+static void
+common_send(struct gaim_conversation *conv, const char *message)
 {
-	if (event->button == 3 && event->type == GDK_BUTTON_PRESS) {
-		/* right single click */
-		g_signal_stop_emission_by_name(G_OBJECT(widget), "button_press_event");
-		return TRUE;
-	}
-	return FALSE;
-}
+	GaimConversationType type;
+	struct gaim_connection *gc;
+	struct gaim_conversation_ops *ops;
+	char *buf, *buf2, *buffy;
+	gulong length = 0;
+	gboolean binary = FALSE;
+	int plugin_return;
+	int limit;
+	int err = 0;
+	GList *first;
 
-static void got_typing_keypress(struct conversation *c, gboolean first) {
-	/* we know we got something, so we at least have to make sure we don't send
-	 * TYPED any time soon */
-	if(c->type_again_timeout)
-		g_source_remove(c->type_again_timeout);
-	c->type_again_timeout = g_timeout_add(SEND_TYPED_TIMEOUT, send_typed, c);
-
-	/* we send typed if this is the first character typed, or if we're due
-	 * to send another one */
-	if(first || (c->type_again != 0 && time(NULL) > c->type_again)) {
-		int timeout = serv_send_typing(c->gc, c->name, TYPING);
-		if(timeout)
-			c->type_again = time(NULL) + timeout;
-		else
-			c->type_again = 0;
-	}
-}
-
-void delete_text_callback(GtkTextBuffer *textbuffer, GtkTextIter *start_pos, GtkTextIter *end_pos, gpointer user_data) {
-	struct conversation *c = user_data;
-
-	if(!c)
-		return;
-
-	if (misc_options & OPT_MISC_STEALTH_TYPING)
+	if ((gc = gaim_conversation_get_gc(conv)) == NULL)
 		return;
 
-	if(gtk_text_iter_is_start(start_pos) && gtk_text_iter_is_end(end_pos)) {
-		if(c->type_again_timeout) {
-			g_source_remove(c->type_again_timeout);
-			c->type_again_timeout = 0;
-		}
-		serv_send_typing(c->gc, c->name, NOT_TYPING);
-	} else {
-		/* we're deleting, but not all of it, so it counts as typing */
-		got_typing_keypress(c, FALSE);
+	type = gaim_conversation_get_type(conv);
+	ops  = gaim_conversation_get_ops(conv);
+
+	limit = 32 * 1024; /* You shouldn't be sending more than 32K in your
+						  messages. That's a book. */
+
+	buf = g_malloc(limit);
+	strncpy(buf, message, limit);
+
+	if (strlen(buf) == 0) {
+		g_free(buf);
+
+		return;
 	}
-}
 
-void insert_text_callback(GtkTextBuffer *textbuffer, GtkTextIter *position, gchar *new_text, gint new_text_length, gpointer user_data) {
-	struct conversation *c = user_data;
+	first = g_list_first(conv->send_history);
 
-	if(!c)
-		return;
+	if (first->data)
+		g_free(first->data);
 
-	if (misc_options & OPT_MISC_STEALTH_TYPING)
-		return;
+	first->data = g_strdup(buf);
+
+	conv->send_history = g_list_prepend(first, NULL);
 
-	got_typing_keypress(c, (gtk_text_iter_is_start(position) && gtk_text_iter_is_end(position)));
-}
+	buf2 = g_malloc(limit);
 
-void send_callback(GtkWidget *widget, struct conversation *c)
-{
-	char *buf, *buf2;
-	int limit;
-	gulong length=0;
-	int err = 0;
-	GList *first;
-	GtkTextIter start_iter, end_iter;
+	if (gc->flags & OPT_CONN_HTML) {
+		if (convo_options & OPT_CONVO_SEND_LINKS)
+			linkify_text(buf);
+	}
 
-	if (!c->gc)
-		return;
+	buffy = g_strdup(buf);
+	plugin_return = plugin_event(
+			(type == GAIM_CONV_IM ? event_im_send : event_chat_send),
+			gc,
+			(type == GAIM_CONV_IM
+			 ? gaim_conversation_get_name(conv)
+			 : (void *)gaim_chat_get_id(GAIM_CHAT(conv))),
+			&buffy);
 
-	gtk_text_buffer_get_start_iter(c->entry_buffer, &start_iter);
-	gtk_text_buffer_get_end_iter(c->entry_buffer, &end_iter);
-	buf2 = gtk_text_buffer_get_text(c->entry_buffer, &start_iter, &end_iter, FALSE);
-	limit = 32 * 1024;	/* you shouldn't be sending more than 32k in your messages. that's a book. */
-	buf = g_malloc(limit);
-	g_snprintf(buf, limit, "%s", buf2);
-	g_free(buf2);
-	if (!strlen(buf)) {
+	if (buffy == NULL) {
+		g_free(buf2);
+		g_free(buf);
+		return;
+	}
+
+	if (plugin_return) {
+		g_free(buffy);
+		g_free(buf2);
 		g_free(buf);
 		return;
 	}
 
-	first = g_list_first(c->send_history);
-	if (first->data)
-		g_free(first->data);
-	first->data = g_strdup(buf);
-	c->send_history = g_list_prepend(first, NULL);
-	
-	buf2 = g_malloc(limit);
-
-	if (c->gc->flags & OPT_CONN_HTML) {
-		if (convo_options & OPT_CONVO_SEND_LINKS)
-			linkify_text(buf);
-
-		if (font_options & OPT_FONT_BOLD) {
-			g_snprintf(buf2, limit, "<B>%s</B>", buf);
-			strcpy(buf, buf2);
-		}
-
-		if (font_options & OPT_FONT_ITALIC) {
-			g_snprintf(buf2, limit, "<I>%s</I>", buf);
-			strcpy(buf, buf2);
-		}
-
-		if (font_options & OPT_FONT_UNDERLINE) {
-			g_snprintf(buf2, limit, "<U>%s</U>", buf);
-			strcpy(buf, buf2);
-		}
-
-		if (font_options & OPT_FONT_STRIKE) {
-			g_snprintf(buf2, limit, "<STRIKE>%s</STRIKE>", buf);
-			strcpy(buf, buf2);
-		}
-
-		if ((font_options & OPT_FONT_FACE) || c->hasfont) {
-			g_snprintf(buf2, limit, "<FONT FACE=\"%s\">%s</FONT>", c->fontface, buf);
-			strcpy(buf, buf2);
-		}
-
-		if (font_options & OPT_FONT_SIZE) {
-			g_snprintf(buf2, limit, "<FONT SIZE=\"%d\">%s</FONT>", fontsize, buf);
-			strcpy(buf, buf2);
-		}
+	strncpy(buf, buffy, limit);
+	g_free(buffy);
 
-		if ((font_options & OPT_FONT_FGCOL) || c->hasfg) {
-			g_snprintf(buf2, limit, "<FONT COLOR=\"#%02X%02X%02X\">%s</FONT>", 
-				   c->fgcol.red/256, c->fgcol.green/256, c->fgcol.blue/256, buf);
-			strcpy(buf, buf2);
-		}
-
-		if ((font_options & OPT_FONT_BGCOL) || c->hasbg) {
-			g_snprintf(buf2, limit, "<BODY BGCOLOR=\"#%02X%02X%02X\">%s</BODY>",
-				   c->bgcol.red/256, c->bgcol.green/256, c->bgcol.blue/256, buf);
-			strcpy(buf, buf2);
-		}
-	}
-
-	quiet_set(c->bold, FALSE);
-	quiet_set(c->italic, FALSE);
-	quiet_set(c->underline, FALSE);
-	quiet_set(c->font, FALSE);
-	quiet_set(c->fgcolorbtn, FALSE);
-	quiet_set(c->bgcolorbtn, FALSE);
-	quiet_set(c->link, FALSE);
-	gtk_widget_grab_focus(c->entry);
-
-	{
-		char *buffy = g_strdup(buf);
-		enum gaim_event evnt = c->is_chat ? event_chat_send : event_im_send;
-		int plugin_return = plugin_event(evnt, c->gc,
-						 c->is_chat ? (void *)c->id : c->name,
-						 &buffy);
-		if (!buffy) {
-			g_free(buf2);
-			g_free(buf);
-			return;
-		}
-		if (plugin_return) {
-			gtk_text_buffer_set_text(c->entry_buffer, "", -1);
-			g_free(buffy);
-			g_free(buf2);
-			g_free(buf);
-			return;
-		}
-		g_snprintf(buf, limit, "%s", buffy);
-		g_free(buffy);
-	}
-	
-	if (!c->is_chat) {
-		char *buffy;
-		gboolean binary = FALSE;
+	if (type == GAIM_CONV_IM) {
+		struct gaim_im *im = GAIM_IM(conv);
 
 		buffy = g_strdup(buf);
-		plugin_event(event_im_displayed_sent, c->gc, c->name, &buffy);
-		if (buffy) {
+		plugin_event(event_im_displayed_sent, gc,
+					 gaim_conversation_get_name(conv), &buffy);
+
+		if (buffy != NULL) {
 			int imflags = 0;
-			if (c->check && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->check)))
-				imflags = IM_FLAG_CHECKBOX;
-			
-			if (c->images) {
-				int id = 0, offset = 0;
+
+			if (conv->u.im->images != NULL) {
+				int id = 1, offset = 0;
 				char *bigbuf = NULL;
-				GSList *tmplist = c->images;
-				id = 1;
-				
-				while (tmplist) {
+				GSList *tmplist;
+
+				for (tmplist = conv->u.im->images;
+					 tmplist != NULL;
+					 tmplist = tmplist->next) {
+
+					char *img_filename = (char *)tmplist->data;
 					FILE *imgfile;
-					char *filename;
+					char *filename, *c;
 					struct stat st;
 					char imgtag[1024];
-	
-					if (stat(tmplist->data, &st) != 0) {
-						debug_printf("Could not stat %s\n", (char *)tmplist->data);
-						tmplist = tmplist->next;
+
+					if (stat(img_filename, &st) != 0) {
+						debug_printf("Could not stat %s\n",
+									 (char *)img_filename);
 						continue;
 					}
-								
-					/* Here we check to make sure the user still wants to send the
-					 * image.  He may have deleted the <img> tag in which case we
-					 * don't want to send the binary data. */
-					filename = tmplist->data;
-					while (strchr(filename, '/')) 
-						filename = strchr(filename, '/') + 1;
+
+					/*
+					 * Here we check to make sure the user still wants to send
+					 * the image. He may have deleted the <img> tag in which
+					 * case we don't want to send the binary data.
+					 */
+					filename = img_filename;
+
+					while ((c = strchr(filename, '/')) != NULL)
+						filename = c + 1;
+					
 					g_snprintf(imgtag, sizeof(imgtag),
-						   "<IMG SRC=\"file://%s\" ID=\"%d\" DATASIZE=\"%d\">",
-						   filename, id, (int)st.st_size);
-				       	
+							   "<IMG SRC=\"file://%s\" ID=\"%d\" "
+							   "DATASIZE=\"%d\">",
+							   filename, id, (int)st.st_size);
+
 					if (strstr(buffy, imgtag) == 0) {
-						debug_printf("Not sending image: %s\n", (char *)tmplist->data);
-						tmplist = tmplist->next;
+						debug_printf("Not sending image: %s\n", img_filename);
 						continue;
 					}
+
 					if (!binary) {
 						length = strlen(buffy) + strlen("<BINARY></BINARY>");
 						bigbuf = g_malloc(length + 1);
-						g_snprintf(bigbuf, strlen(buffy) + strlen("<BINARY> ") + 1,
-							   "%s<BINARY>", buffy);
+						g_snprintf(bigbuf,
+								   strlen(buffy) + strlen("<BINARY> ") + 1,
+								   "%s<BINARY>", buffy);
+
 						offset = strlen(buffy) + strlen("<BINARY>");
 						binary = TRUE;
 					}
+
 					g_snprintf(imgtag, sizeof(imgtag),
-						   "<DATA ID=\"%d\" SIZE=\"%d\">",
-						   id, (int)st.st_size);
-					
-					length = length + strlen(imgtag) + st.st_size + strlen("</DATA>");;
+							   "<DATA ID=\"%d\" SIZE=\"%d\">",
+							   id, (int)st.st_size);
+
+					length += strlen(imgtag) + st.st_size + strlen("</DATA>");
+
 					bigbuf = g_realloc(bigbuf, length + 1);
-					if (!(imgfile = fopen(tmplist->data, "r"))) {
-						debug_printf("Could not open %s\n", (char *)tmplist->data);
-						tmplist = tmplist->next;
+
+					if ((imgfile = fopen(img_filename, "r")) == NULL) {
+						debug_printf("Could not open %s\n", img_filename);
 						continue;
 					}
-					g_snprintf(bigbuf + offset, strlen(imgtag) + 1, "%s", imgtag);
-					offset = offset + strlen(imgtag);
-					offset = offset + fread(bigbuf + offset, 1, st.st_size, imgfile);
+
+					strncpy(bigbuf + offset, imgtag, strlen(imgtag) + 1);
+
+					offset += strlen(imgtag);
+					offset += fread(bigbuf + offset, 1, st.st_size, imgfile);
+
 					fclose(imgfile);
-					g_snprintf(bigbuf + offset, strlen("</DATA>") + 1, "</DATA>");
-					offset= offset + strlen("</DATA>");
+
+					strncpy(bigbuf + offset, "</DATA>",
+							strlen("</DATA>") + 1);
+
+					offset += strlen("</DATA>");
 					id++;
-					tmplist = tmplist->next;
 				}
+
 				if (binary) {
-					g_snprintf(bigbuf + offset, strlen("</BINARY>") + 1, "</BINARY>"); 
-					err =serv_send_im(c->gc, c->name, bigbuf, length, imflags);
-				} else {
-					err = serv_send_im(c->gc, c->name, buffy, -1, imflags);
-				}					
+					strncpy(bigbuf + offset, "</BINARY>",
+							strlen("<BINARY>") + 1);
+
+					err = serv_send_im(gc,
+						(char *)gaim_conversation_get_name(conv),
+						bigbuf, length, imflags);
+				}
+				else
+					err = serv_send_im(gc,
+						(char *)gaim_conversation_get_name(conv),
+						buffy, -1, imflags);
+
 				if (err > 0) {
-					GSList *tempy = c->images;
-					while (tempy) {
+					GSList *tempy;
+
+					for (tempy = conv->u.im->images;
+						 tempy != NULL;
+						 tempy = tempy->next) {
+
 						g_free(tempy->data);
-						tempy = tempy->next;
 					}
+
 					g_slist_free(tempy);
-					c->images = NULL;
+					conv->u.im->images = NULL;
+
 					if (binary)
-						write_to_conv(c, bigbuf, WFLAG_SEND, NULL, time(NULL), length);
+						gaim_im_write(im, NULL, bigbuf, length,
+									  WFLAG_SEND, time(NULL));
 					else
-						write_to_conv(c, buffy, WFLAG_SEND, NULL, time(NULL), -1);
-					if (c->makesound)
-						play_sound(SND_SEND);
+						gaim_im_write(im, NULL, buffy, -1, WFLAG_SEND,
+									  time(NULL));
+
 					if (im_options & OPT_IM_POPDOWN)
-						gtk_widget_hide(c->window);
-					
-					
+						gaim_window_hide(gaim_conversation_get_window(conv));
 				}
+
 				if (binary)
 					g_free(bigbuf);
-			} else {
-				err =serv_send_im(c->gc, c->name, buffy, -1, imflags);
-				if (err > 0) { 
-					write_to_conv(c, buf, WFLAG_SEND, NULL, time(NULL), -1);
-					if (c->makesound)
-						play_sound(SND_SEND);
+			}
+			else {
+				err = serv_send_im(gc, (char *)gaim_conversation_get_name(conv),
+								   buffy, -1, imflags);
+
+				if (err > 0) {
+					gaim_im_write(im, NULL, buf, -1, WFLAG_SEND, time(NULL));
+
 					if (im_options & OPT_IM_POPDOWN)
-						gtk_widget_hide(c->window);
+						gaim_window_hide(gaim_conversation_get_window(conv));
 				}
 			}
+
 			g_free(buffy);
 		}
-		
-	} else {
-		err = serv_chat_send(c->gc, c->id, buf);
-
-		/* no sound because we do that when we receive our message */
+	}
+	else {
+		err = serv_chat_send(gc, gaim_chat_get_id(GAIM_CHAT(conv)), buf);
 	}
 
 	g_free(buf2);
@@ -1195,2357 +378,1556 @@
 
 	if (err < 0) {
 		if (err == -E2BIG)
-			do_error_dialog(_("Unable to send message.  The message is too large"), NULL, GAIM_ERROR);
+			do_error_dialog(_("Unable to send message. "
+							  "The message is too large."), NULL,
+							GAIM_ERROR);
 		else if (err == -ENOTCONN)
-			debug_printf("Not yet connected\n");
+			debug_printf("Not yet connected.\n");
 		else
-			do_error_dialog(_("Unable to send message"), NULL, GAIM_ERROR);
-	} else {
-		gtk_text_buffer_set_text(c->entry_buffer, "", -1);
-
-		if ((err > 0) && (away_options & OPT_AWAY_BACK_ON_IM)) {
+			do_error_dialog(_("Unable to send message."), NULL, GAIM_ERROR);
+	}
+	else {
+		if (err > 0 && (away_options & OPT_AWAY_BACK_ON_IM)) {
 			if (awaymessage != NULL) {
 				do_im_back();
-			} else if (c->gc->away) {
-				serv_set_away(c->gc, GAIM_AWAY_CUSTOM, NULL);
+			}
+			else if (gc->away) {
+				serv_set_away(gc, GAIM_AWAY_CUSTOM, NULL);
 			}
 		}
 	}
+
+}
+
+static void
+update_conv_indexes(struct gaim_window *win)
+{
+	GList *l;
+	int i;
+
+	for (l = gaim_window_get_conversations(win), i = 0;
+		 l != NULL;
+		 l = l->next, i++) {
+
+		struct gaim_conversation *conv = (struct gaim_conversation *)l->data;
+
+		conv->conversation_pos = i;
+	}
 }
 
-gboolean entry_key_pressed(GtkTextBuffer *buffer)
+struct gaim_window *
+gaim_window_new(void)
 {
-	check_everything(buffer);
-	return FALSE;
+	struct gaim_window *win;
+
+	win = g_malloc0(sizeof(struct gaim_window));
+
+	/* CONV XXX */
+	win->ops = gaim_get_gtk_window_ops();
+
+	if (win->ops != NULL && win->ops->new_window != NULL)
+		win->ops->new_window(win);
+
+	windows = g_list_append(windows, win);
+
+	return win;
 }
 
-/*------------------------------------------------------------------------*/
-/*  HTML-type stuff                                                       */
-/*------------------------------------------------------------------------*/
+void
+gaim_window_destroy(struct gaim_window *win)
+{
+	struct gaim_window_ops *ops;
+	GList *node;
+
+	if (win == NULL)
+		return;
+
+	ops = gaim_window_get_ops(win);
 
-int count_tag(GtkTextBuffer *buffer, char *s1, char *s2)
-{
-	char *p1, *p2;
-	int res = 0;
-	GtkTextIter start, end;
-	char *tmp, *tmpo;
+	if (ops != NULL && ops->destroy_window != NULL)
+		ops->destroy_window(win);
+
+	for (node = g_list_first(gaim_window_get_conversations(win));
+		 node != NULL;
+		 node = g_list_next(node))
+	{
+		struct gaim_conversation *conv;
+		
+		conv = (struct gaim_conversation *)node->data;
+
+		conv->window = NULL;
+		gaim_conversation_destroy(conv);
 
-	gtk_text_buffer_get_start_iter(buffer, &start);
-	gtk_text_buffer_get_iter_at_mark(buffer, &end,
-					 gtk_text_buffer_get_insert(buffer));
-  
-	tmp = tmpo = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
-	do {
-		p1 = strstr(tmp, s1);
-		p2 = strstr(tmp, s2);
-		if (p1 && p2) {
-			if (p1 < p2) {
-				res = 1;
-				tmp = p1 + strlen(s1);
-			} else if (p2 < p1) {
-				res = 0;
-				tmp = p2 + strlen(s2);
-			}
-		} else {
-			if (p1) {
-				res = 1;
-				tmp = p1 + strlen(s1);
-			} else if (p2) {
-				res = 0;
-				tmp = p2 + strlen(s2);
-			}
-		}
-	} while (p1 || p2);
-	g_free(tmpo);
-	return res;
+		node->data = NULL;
+	}
+
+	g_list_free(gaim_window_get_conversations(win));
+
+	windows = g_list_remove(windows, win);
+
+	g_free(win);
+}
+
+void
+gaim_window_show(struct gaim_window *win)
+{
+	struct gaim_window_ops *ops;
+
+	if (win == NULL)
+		return;
+
+	ops = gaim_window_get_ops(win);
+
+	if (ops == NULL || ops->show == NULL)
+		return;
+
+	ops->show(win);
 }
 
-
-gboolean invert_tags(GtkTextBuffer *buffer, char *s1, char *s2, gboolean really)
+void
+gaim_window_hide(struct gaim_window *win)
 {
-	GtkTextIter start1, start2, end1, end2;
-	char *b1, *b2;
+	struct gaim_window_ops *ops;
+
+	if (win == NULL)
+		return;
+
+	ops = gaim_window_get_ops(win);
+
+	if (ops == NULL || ops->hide == NULL)
+		return;
 
-	if (gtk_text_buffer_get_selection_bounds(buffer, &start1, &end2)) {
-		start2 = start1; end1 = end2;
-		if (!gtk_text_iter_forward_chars(&start2, strlen(s1)))
-			return FALSE;
-		if (!gtk_text_iter_backward_chars(&end1, strlen(s2)))
-			return FALSE;
-		b1 = gtk_text_buffer_get_text(buffer, &start1, &start2, FALSE);
-		b2 = gtk_text_buffer_get_text(buffer, &end1, &end2, FALSE);
-		if (!g_strncasecmp(b1, s1, strlen(s1)) &&
-		    !g_strncasecmp(b2, s2, strlen(s2))) {
-			if (really) {
-				GtkTextMark *m_end1, *m_end2;
- 
-				m_end1= gtk_text_buffer_create_mark(buffer, "m1", &end1, TRUE);
-				m_end2= gtk_text_buffer_create_mark(buffer, "m2", &end2, TRUE);
+	ops->hide(win);
+}
+
+void
+gaim_window_raise(struct gaim_window *win)
+{
+	struct gaim_window_ops *ops;
 
-				gtk_text_buffer_delete(buffer, &start1, &start2);
-				gtk_text_buffer_get_iter_at_mark(buffer, &end1, m_end1);
-				gtk_text_buffer_get_iter_at_mark(buffer, &end2, m_end2);
-				gtk_text_buffer_delete(buffer, &end1, &end2);
-				gtk_text_buffer_delete_mark(buffer, m_end1);
-				gtk_text_buffer_delete_mark(buffer, m_end2);
-			}
-			 g_free(b1); g_free(b2);
-			return TRUE;
-		}
-		g_free(b1);g_free(b2);
-	}
-	return FALSE;
+	if (win == NULL)
+		return;
+
+	ops = gaim_window_get_ops(win);
+
+	if (ops == NULL || ops->raise == NULL)
+		return;
+
+	ops->raise(win);
 }
 
-
-void remove_tags(struct conversation *c, char *tag)
+void
+gaim_window_flash(struct gaim_window *win)
 {
-	GtkTextIter start, end, m_start, m_end;
+	struct gaim_window_ops *ops;
+
+	if (win == NULL)
+		return;
+
+	ops = gaim_window_get_ops(win);
+
+	if (ops == NULL || ops->flash == NULL)
+		return;
 
-	if (!gtk_text_buffer_get_selection_bounds(c->entry_buffer,
-						  &start, &end))
+	ops->flash(win);
+}
+
+void
+gaim_window_set_ops(struct gaim_window *win, struct gaim_window_ops *ops)
+{
+	struct gaim_conversation_ops *convops = NULL;
+	GList *l;
+
+	if (win == NULL || win->ops == ops)
 		return;
 
-	/* FIXMEif (strstr(tag, "<FONT SIZE=")) {
-		while ((t = strstr(t, "<FONT SIZE="))) {
-			if (((t - s) < finish) && ((t - s) >= start)) {
-				gtk_editable_delete_text(GTK_EDITABLE(entry), (t - s),
-							 (t - s) + strlen(tag));
-				g_free(s);
-				s = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
-				t = s;
-			} else
-				t++;
-		}
-	} else*/ {
-		while (gtk_text_iter_forward_search(&start, tag, 0, &m_start, &m_end, &end)) {
-			gtk_text_buffer_delete(c->entry_buffer, &m_start, &m_end);
-			gtk_text_buffer_get_selection_bounds(c->entry_buffer, &start, &end);
-		}
+	if (ops != NULL) {
+		if (ops->get_conversation_ops != NULL)
+			convops = ops->get_conversation_ops();
+	}
+
+	if (win->ops != NULL) {
+		if (win->ops->destroy_window != NULL)
+			win->ops->destroy_window(win);
+	}
+
+	win->ops = ops;
+
+	if (win->ops != NULL) {
+		if (win->ops->new_window != NULL)
+			win->ops->new_window(win);
+	}
+
+	for (l = gaim_window_get_conversations(win);
+		 l != NULL;
+		 l = l->next) {
+
+		struct gaim_conversation *conv = (struct gaim_conversation *)l;
+
+		gaim_conversation_set_ops(conv, convops);
+
+		if (win->ops != NULL && win->ops->add_conversation != NULL)
+			win->ops->add_conversation(win, conv);
 	}
 }
 
-void surround(struct conversation *c, char *pre, char *post)
+struct gaim_window_ops *
+gaim_window_get_ops(const struct gaim_window *win)
 {
-	GtkTextIter start, end;
-	GtkTextMark *mark_start, *mark_end;
-
-	if (gtk_text_buffer_get_selection_bounds(c->entry_buffer, &start, &end)) {
-		remove_tags(c, pre);
-		remove_tags(c, post);
-
-		mark_start = gtk_text_buffer_create_mark(c->entry_buffer, "m1", &start, TRUE);
-		mark_end = gtk_text_buffer_create_mark(c->entry_buffer, "m2", &end, FALSE);
-		gtk_text_buffer_insert(c->entry_buffer, &start, pre, -1);
-		gtk_text_buffer_get_selection_bounds(c->entry_buffer, &start, &end);
-		gtk_text_buffer_insert(c->entry_buffer, &end, post, -1);
-		gtk_text_buffer_get_iter_at_mark(c->entry_buffer, &start, mark_start);
-		gtk_text_buffer_move_mark_by_name(c->entry_buffer, "selection_bound", &start);
-	} else {
-		gtk_text_buffer_insert(c->entry_buffer, &start, pre, -1);
-		gtk_text_buffer_insert(c->entry_buffer, &start, post, -1);
-		mark_start = gtk_text_buffer_get_insert(c->entry_buffer);
-		gtk_text_buffer_get_iter_at_mark(c->entry_buffer, &start, mark_start);
-		gtk_text_iter_backward_chars(&start, strlen(post));
-		gtk_text_buffer_place_cursor(c->entry_buffer, &start);
-	}
-
-	gtk_widget_grab_focus(c->entry);
-}
+	if (win == NULL)
+		return NULL;
 
-void advance_past(struct conversation *c, char *pre, char *post)
-{
-	GtkTextIter current_pos, start, end;
-
-	if (invert_tags(c->entry_buffer, pre, post, 1))
-		return;
-
-	gtk_text_buffer_get_iter_at_mark(c->entry_buffer, &current_pos,
-					 gtk_text_buffer_get_insert(c->entry_buffer));
-	if (gtk_text_iter_forward_search(&current_pos, post, 0, &start, &end, NULL))
-		gtk_text_buffer_place_cursor(c->entry_buffer, &end);
-	else
-		gtk_text_buffer_insert_at_cursor(c->entry_buffer, post, -1);
-
-	gtk_widget_grab_focus(c->entry);
-}
-
-void toggle_fg_color(GtkWidget *color, struct conversation *c)
-{
-	if (state_lock)
-		return;
-	if (GTK_TOGGLE_BUTTON(color)->active)
-		show_fgcolor_dialog(c, color);
-	else if (c->fg_color_dialog)
-		cancel_fgcolor(color, c);
-	else
-		advance_past(c, "<FONT COLOR>", "</FONT>");
+	return win->ops;
 }
 
-void toggle_bg_color(GtkWidget *color, struct conversation *c)
+int
+gaim_window_add_conversation(struct gaim_window *win,
+							 struct gaim_conversation *conv)
 {
-	if (state_lock)
-		return;
-	if (GTK_TOGGLE_BUTTON(color)->active)
-		show_bgcolor_dialog(c, color);
-	else if (c->bg_color_dialog)
-		cancel_bgcolor(color, c);
-	else
-		advance_past(c, "<BODY BGCOLOR>", "</BODY>");
-}
+	struct gaim_window_ops *ops;
+
+	if (win == NULL || conv == NULL) {
+		return -1;
+	}
+
+	if (gaim_conversation_get_window(conv) != NULL) {
+		gaim_window_remove_conversation(
+			gaim_conversation_get_window(conv),
+			gaim_conversation_get_index(conv));
+	}
+
+	ops = gaim_window_get_ops(win);
 
-void toggle_font(GtkWidget *font, struct conversation *c)
-{
-	if (state_lock)
-		return;
-	if (GTK_TOGGLE_BUTTON(font)->active)
-		show_font_dialog(c, font);
-	else if (c->font_dialog)
-		cancel_font(font, c);
-	else
-		advance_past(c, "<FONT FACE>", "</FONT>");
+	win->conversations = g_list_append(win->conversations, conv);
+	win->conversation_count++;
+
+	conv->conversation_pos = win->conversation_count - 1;
+
+	if (ops != NULL) {
+		if (ops->get_conversation_ops != NULL)
+			gaim_conversation_set_ops(conv, ops->get_conversation_ops());
+
+		if (ops->add_conversation != NULL)
+			ops->add_conversation(win, conv);
+
+		conv->window = win;
+	}
+
+	return win->conversation_count - 1;
 }
 
-void insert_link_cb(GtkWidget *w, struct conversation *c)
+struct gaim_conversation *
+gaim_window_remove_conversation(struct gaim_window *win, unsigned int index)
 {
-	show_insert_link(c->link, c);
-}
+	struct gaim_window_ops *ops;
+	struct gaim_conversation *conv;
+	GList *node;
 
-void toggle_link(GtkWidget *linky, struct conversation *c)
-{
-	if (state_lock)
-		return;
+	if (win == NULL || index >= gaim_window_get_conversation_count(win))
+		return NULL;
+
+	ops = gaim_window_get_ops(win);
 
-	if (GTK_TOGGLE_BUTTON(c->link)->active)
-		show_insert_link(c->link, c);
+	node = g_list_nth(gaim_window_get_conversations(win), index);
+	conv = (struct gaim_conversation *)node->data;
+
+	win->conversations = g_list_remove_link(win->conversations, node);
 
-	else if (c->link_dialog)
-		cancel_link(c->link, c);
-	else
-		advance_past(c, "<A HREF>", "</A>");
+	g_list_free_1(node);
+
+	win->conversation_count--;
 
-	gtk_widget_grab_focus(c->entry);
-}
+	if (ops != NULL && ops->remove_conversation != NULL)
+		ops->remove_conversation(win, conv);
+
+	conv->window = NULL;
 
-void do_strike(GtkWidget *strike, struct conversation *c)
-{
-	if (state_lock)
-		return;
+	if (gaim_window_get_conversation_count(win) == 0)
+		gaim_window_destroy(win);
+	else {
+		/* Change all the indexes. */
+		update_conv_indexes(win);
+	}
 
-	if (GTK_TOGGLE_BUTTON(strike)->active)
-		surround(c, "<STRIKE>", "</STRIKE>");
-	else
-		advance_past(c, "<STRIKE>", "</STRIKE>");
-
-	gtk_widget_grab_focus(c->entry);
+	return conv;
 }
 
-void do_bold(GtkWidget *bold, struct conversation *c)
+void
+gaim_window_move_conversation(struct gaim_window *win, unsigned int index,
+							  unsigned int new_index)
 {
-	if (state_lock)
+	struct gaim_window_ops *ops;
+	struct gaim_conversation *conv;
+	GList *l;
+
+	if (win == NULL || index >= gaim_window_get_conversation_count(win) ||
+		index == new_index)
 		return;
-	if (GTK_TOGGLE_BUTTON(bold)->active)
-		surround(c, "<B>", "</B>");
-	else
-		advance_past(c, "<B>", "</B>");
+
+	/* We can't move this past the last index. */
+	if (new_index >= gaim_window_get_conversation_count(win))
+		new_index = gaim_window_get_conversation_count(win) - 1;
+
+	/* Get the list item for this conversation at its current index. */
+	l = g_list_nth(gaim_window_get_conversations(win), index);
 
-	gtk_widget_grab_focus(c->entry);
-}
+	if (l == NULL) {
+		/* Should never happen. */
+		debug_printf("Misordered conversations list in window %p\n", win);
 
-void do_underline(GtkWidget *underline, struct conversation *c)
-{
-	if (state_lock)
 		return;
-	if (GTK_TOGGLE_BUTTON(underline)->active)
-		surround(c, "<U>", "</U>");
-	else
-		advance_past(c, "<U>", "</U>");
+	}
+
+	conv = (struct gaim_conversation *)l->data;
+
+	/* Update the UI part of this. */
+	ops = gaim_window_get_ops(win);
+
+	if (ops != NULL && ops->move_conversation != NULL)
+		ops->move_conversation(win, conv, new_index);
 
-	gtk_widget_grab_focus(c->entry);
+	/* Insert it where it should go. */
+	win->conversations = g_list_insert(win->conversations, conv,
+		(new_index > index ? new_index + 1 : new_index));
+
+	/* Remove the old one. */
+	l->data = NULL;
+	win->conversations = g_list_remove_link(win->conversations, l);
+	g_list_free_1(l);
+
+	update_conv_indexes(win);
 }
 
-void do_italic(GtkWidget *italic, struct conversation *c)
-{
-	if (state_lock)
-		return;
-	if (GTK_TOGGLE_BUTTON(italic)->active)
-		surround(c, "<I>", "</I>");
-	else
-		advance_past(c, "<I>", "</I>");
-
-	gtk_widget_grab_focus(c->entry);
-}
-
-/* html code to modify font sizes must all be the same length, */
-/* currently set to 15 chars */
-
-void do_small(GtkWidget *small, struct conversation *c)
+struct gaim_conversation *
+gaim_window_get_conversation_at(const struct gaim_window *win,
+								unsigned int index)
 {
-	if (state_lock)
-		return;
-
-	surround(c, "<FONT SIZE=\"1\">", "</FONT>");
-
-	gtk_widget_grab_focus(c->entry);
-}
+	if (win == NULL || index >= gaim_window_get_conversation_count(win))
+		return NULL;
 
-void do_normal(GtkWidget *normal, struct conversation *c)
-{
-	if (state_lock)
-		return;
-
-	surround(c, "<FONT SIZE=\"3\">", "</FONT>");
-
-	gtk_widget_grab_focus(c->entry);
+	return (struct gaim_conversation *)g_list_nth_data(
+		gaim_window_get_conversations(win), index);
 }
 
-void do_big(GtkWidget *big, struct conversation *c)
+size_t
+gaim_window_get_conversation_count(const struct gaim_window *win)
 {
-	if (state_lock)
+	if (win == NULL)
+		return 0;
+
+	return win->conversation_count;
+}
+
+void
+gaim_window_switch_conversation(struct gaim_window *win, unsigned int index)
+{
+	struct gaim_window_ops *ops;
+
+	if (win == NULL || index < 0 ||
+		index >= gaim_window_get_conversation_count(win))
 		return;
 
-	surround(c, "<FONT SIZE=\"5\">", "</FONT>");
+	ops = gaim_window_get_ops(win);
 
-	gtk_widget_grab_focus(c->entry);
+	if (ops != NULL && ops->switch_conversation != NULL)
+		ops->switch_conversation(win, index);
+
+	gaim_conversation_set_unseen(
+		gaim_window_get_conversation_at(win, index), 0);
 }
 
-void check_everything(GtkTextBuffer *buffer)
+struct gaim_conversation *
+gaim_window_get_active_conversation(const struct gaim_window *win)
 {
-	struct conversation *c;
+	struct gaim_window_ops *ops;
+
+	if (win == NULL)
+		return NULL;
 
-	c = (struct conversation *)g_object_get_data(G_OBJECT(buffer), "user_data");
-	if (!c)
-		return;
-	if (invert_tags(c->entry_buffer, "<B>", "</B>", 0))
-		quiet_set(c->bold, TRUE);
-	else if (count_tag(c->entry_buffer, "<B>", "</B>"))
-		quiet_set(c->bold, TRUE);
-	else
-		quiet_set(c->bold, FALSE);
-	if (invert_tags(c->entry_buffer, "<I>", "</I>", 0))
-		quiet_set(c->italic, TRUE);
-	else if (count_tag(c->entry_buffer, "<I>", "</I>"))
-		quiet_set(c->italic, TRUE);
-	else
-		quiet_set(c->italic, FALSE);
+	ops = gaim_window_get_ops(win);
 
-	if (invert_tags(c->entry_buffer, "<FONT COLOR", "</FONT>", 0))
-		quiet_set(c->fgcolorbtn, TRUE);
-	else if (count_tag(c->entry_buffer, "<FONT COLOR", "</FONT>"))
-		quiet_set(c->fgcolorbtn, TRUE);
-	else
-		quiet_set(c->fgcolorbtn, FALSE);
+	if (ops != NULL && ops->get_active_index != NULL)
+		debug_printf("Active index = %d\n", ops->get_active_index(win));
+
+	if (ops != NULL && ops->get_active_index != NULL)
+		return gaim_window_get_conversation_at(win, ops->get_active_index(win));
 
-	if (invert_tags(c->entry_buffer, "<BODY BGCOLOR", "</BODY>", 0))
-		quiet_set(c->bgcolorbtn, TRUE);
-	else if (count_tag(c->entry_buffer, "<BODY BGCOLOR", "</BODY>"))
-		quiet_set(c->bgcolorbtn, TRUE);
-	else
-		quiet_set(c->bgcolorbtn, FALSE);
-
-	if (invert_tags(c->entry_buffer, "<FONT FACE", "</FONT>", 0))
-		quiet_set(c->font, TRUE);
-	else if (count_tag(c->entry_buffer, "<FONT FACE", "</FONT>"))
-		quiet_set(c->font, TRUE);
-	else
-		quiet_set(c->font, FALSE);
+	return NULL;
+}
 
-	if (invert_tags(c->entry_buffer, "<A HREF", "</A>", 0))
-		quiet_set(c->link, TRUE);
-	else if (count_tag(c->entry_buffer, "<A HREF", "</A>"))
-		quiet_set(c->link, TRUE);
-	else
-		quiet_set(c->link, FALSE);
+GList *
+gaim_window_get_conversations(const struct gaim_window *win)
+{
+	if (win == NULL)
+		return NULL;
 
-	if (invert_tags(c->entry_buffer, "<U>", "</U>", 0))
-		quiet_set(c->underline, TRUE);
-	else if (count_tag(c->entry_buffer, "<U>", "</U>"))
-		quiet_set(c->underline, TRUE);
-	else
-		quiet_set(c->underline, FALSE);
+	return win->conversations;
+}
+
+GList *
+gaim_get_windows(void)
+{
+	return windows;
 }
 
 
-/*------------------------------------------------------------------------*/
-/*  Takin care of the window..                                            */
-/*------------------------------------------------------------------------*/
+/**************************************************************************
+ * Conversation API
+ **************************************************************************/
+struct gaim_conversation *
+gaim_conversation_new(GaimConversationType type, const char *name)
+{
+	struct gaim_conversation *conv;
+	struct gaim_window *window;
+
+	if (type == GAIM_CONV_UNKNOWN)
+		return NULL;
+
+	/* Check if this conversation already exists. */
+	if ((conv = gaim_find_conversation(name)) != NULL)
+		return conv;
+
+	conv = g_malloc0(sizeof(struct gaim_conversation));
+
+	conv->type         = type;
+	conv->name         = g_strdup(name);
+	conv->title        = g_strdup(name);
+	conv->send_history = g_list_append(NULL, NULL);
+	conv->history      = g_string_new("");
+
+	if (type == GAIM_CONV_IM)
+	{
+		conv->u.im = g_malloc0(sizeof(struct gaim_im));
+		conv->u.im->conv = conv;
+
+		ims = g_list_append(ims, conv);
+
+		gaim_conversation_set_logging(conv,
+									  (logging_options & OPT_LOG_CONVOS));
+	}
+	else if (type == GAIM_CONV_CHAT)
+	{
+		conv->u.chat = g_malloc0(sizeof(struct gaim_chat));
+		conv->u.chat->conv = conv;
+
+		chats = g_list_append(chats, conv);
+
+		gaim_conversation_set_logging(conv, (logging_options & OPT_LOG_CHATS));
+	}
+
+	conversations = g_list_append(conversations, conv);
+
+	/* Set the gc */
+	if (connections != NULL) {
+		gaim_conversation_set_user(conv,
+			((struct gaim_connection *)connections->data)->user);
+	}
+
+	/* Auto-set the title. */
+	gaim_conversation_autoset_title(conv);
+
+	/*
+	 * 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);
+
+	plugin_event(event_new_conversation, name);
+
+	return conv;
+}
+
+void
+gaim_conversation_destroy(struct gaim_conversation *conv)
+{
+	struct gaim_window *win;
+	struct gaim_conversation_ops *ops;
+	struct gaim_connection *gc;
+	const char *name;
+	GList *node;
+
+	if (conv == NULL)
+		return;
+
+	win  = gaim_conversation_get_window(conv);
+	ops  = gaim_conversation_get_ops(conv);
+	gc   = gaim_conversation_get_gc(conv);
+	name = gaim_conversation_get_name(conv);
+
+	if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) {
+		if (!(misc_options & OPT_MISC_STEALTH_TYPING))
+			serv_send_typing(gc, (char *)name, NOT_TYPING);
+
+		if (gc && gc->prpl->convo_closed != NULL)
+			gc->prpl->convo_closed(gc, (char *)name);
+	}
+	else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) {
+		/*
+		 * This is unfortunately necessary, because calling serv_chat_leave()
+		 * calls this gaim_conversation_destroy(), which leads to two calls
+		 * here.. We can't just return after this, because then it'll return
+		 * on the next pass. So, since serv_got_chat_left(), which is
+		 * eventually called from the prpl that serv_chat_leave() calls,
+		 * removes this conversation from the gc's buddy_chats list, we're
+		 * going to check to see if this exists in the list. If so, we want
+		 * to return after calling this, because it'll be called again. If not,
+		 * fall through, because it'll have already been removed, and we'd
+		 * be on the 2nd pass.
+		 *
+		 * Long paragraph. <-- Short sentence.
+		 *
+		 *   -- ChipX86
+		 */
+		if (g_slist_find(gc->buddy_chats, conv) != NULL) {
+			serv_chat_leave(gc, gaim_chat_get_id(GAIM_CHAT(conv)));
+
+			return;
+		}
+	}
+
+	plugin_event(event_del_conversation, conv);
+
+	if (conv->name  != NULL) g_free(conv->name);
+	if (conv->title != NULL) g_free(conv->title);
+
+	for (node = g_list_first(conv->send_history);
+		 node != NULL;
+		 node = g_list_next(node)) {
+
+		if (node->data != NULL)
+			g_free(node->data);
+	}
+
+	g_list_free(g_list_first(conv->send_history));
 
-static char* nick_colors[] = {
-	"#ba55d3",              /* Medium Orchid */
-	"#ee82ee",              /* Violet */
-	"#c715b4",              /* Medium Violet Red */
-	"#ff69b4",              /* Hot Pink */
-	"#ff6347",              /* Tomato */
-	"#fa8c00",              /* Dark Orange */
-	"#fa8072",               /* Salmon */
-	"#b22222",              /* Fire Brick */
-	"#f4a460",              /* Sandy Brown */
-	"#cd5c5c",              /* Indian Red */
-	"#bc8f8f",              /* Rosy Brown */
-	"#f0e68c",              /* Khaki */
-	"#bdb76b",              /* Dark Khaki */
-	"#228b22",              /* Forest Green */
-	"#9acd32",              /* Yellow Green */
-	"#32cd32",              /* Lime Green */
-	"#3cb371",              /* Medium Sea Green */
-	"#2e8b57",              /* Sea Green */
-	"#8fbc8f",              /* Dark Sea Green */
-	"#66cdaa",              /* Medium Aquamarine */
-	"#5f9ea0",              /* Cadet Blue */
-	"#48d1cc",              /* Medium Turquoise */
-	"#00ced1",              /* Dark Turquoise */
-	"#4682b4",              /* Stell Blue */
-	"#00bfff",              /* Deep Sky Blue */
-	"#1690ff",              /* Dodger Blue */
-	"#4169ff",              /* Royal Blue */
-	"#6a5acd",              /* Slate Blue */
-	"#6495ed",              /* Cornflower Blue */
-	"#708090",              /* Slate gray */
-	"#ffdead",              /* Navajo White */
-};
-#define NUM_NICK_COLORS (sizeof(nick_colors) / sizeof(char *)) 
+	if (conv->history != NULL)
+		g_string_free(conv->history, TRUE);
+
+	conversations = g_list_remove(conversations, conv);
+
+	if (conv->type == GAIM_CONV_IM) {
+		gaim_im_stop_typing_timeout(conv->u.im);
+		gaim_im_stop_type_again_timeout(conv->u.im);
+
+		g_slist_free(conv->u.im->images);
+
+		g_free(conv->u.im);
+
+		ims = g_list_remove(ims, conv);
+	}
+	else if (conv->type == GAIM_CONV_CHAT) {
+		g_list_free(conv->u.chat->in_room);
+		g_list_free(conv->u.chat->ignored);
+
+		if (conv->u.chat->who != NULL)
+			g_free(conv->u.chat->who);
+
+		if (conv->u.chat->topic != NULL)
+			g_free(conv->u.chat->topic);
+
+		g_free(conv->u.chat);
+
+		chats = g_list_remove(chats, conv);
+	}
+
+	if (win != NULL) {
+		gaim_window_remove_conversation(win,
+			gaim_conversation_get_index(conv));
+	}
+
+	if (ops != NULL && ops->destroy_conversation != NULL)
+		ops->destroy_conversation(conv);
+
+	g_free(conv);
+}
+
+GaimConversationType
+gaim_conversation_get_type(const struct gaim_conversation *conv)
+{
+	if (conv == NULL)
+		return GAIM_CONV_UNKNOWN;
+
+	return conv->type;
+}
+
+void
+gaim_conversation_set_ops(struct gaim_conversation *conv,
+						  struct gaim_conversation_ops *ops)
+{
+	if (conv == NULL || conv->ops == ops)
+		return;
+
+	if (conv->ops != NULL && conv->ops->destroy_conversation != NULL)
+		conv->ops->destroy_conversation(conv);
+
+	conv->ui_data = NULL;
+
+	conv->ops = ops;
+}
 
-/* this is going to be interesting since the conversation could either be a
- * normal IM conversation or a chat window. but hopefully it won't matter */
-void write_to_conv(struct conversation *c, char *what, int flags, char *who, time_t mtime, gint length)
+struct gaim_conversation_ops *
+gaim_conversation_get_ops(struct gaim_conversation *conv)
+{
+	if (conv == NULL)
+		return NULL;
+
+	return conv->ops;
+}
+
+void
+gaim_conversation_set_user(struct gaim_conversation *conv,
+						   struct aim_user *user)
+{
+	if (conv == NULL || user == gaim_conversation_get_user(conv))
+		return;
+
+	conv->user = user;
+
+	gaim_conversation_update(conv, GAIM_CONV_UPDATE_USER);
+}
+
+struct aim_user *
+gaim_conversation_get_user(const struct gaim_conversation *conv)
+{
+	if (conv == NULL)
+		return NULL;
+
+	return conv->user;
+}
+
+struct gaim_connection *
+gaim_conversation_get_gc(const struct gaim_conversation *conv)
 {
-	char buf[BUF_LONG];
-	char *str;
-	FILE *fd;
-	char colour[10];
+	if (conv == NULL)
+		return NULL;
+
+	return gaim_conversation_get_user(conv)->gc;
+}
+
+void
+gaim_conversation_set_title(struct gaim_conversation *conv, const char *title)
+{
+	struct gaim_conversation_ops *ops;
+
+	if (conv == NULL || title == NULL)
+		return;
+
+	if (conv->title != NULL)
+		g_free(conv->title);
+
+	conv->title = g_strdup(title);
+
+	ops = gaim_conversation_get_ops(conv);
+
+	if (ops != NULL && ops->set_title != NULL)
+		ops->set_title(conv, conv->title);
+}
+
+const char *
+gaim_conversation_get_title(const struct gaim_conversation *conv)
+{
+	if (conv == NULL)
+		return NULL;
+
+	return conv->title;
+}
+
+void
+gaim_conversation_autoset_title(struct gaim_conversation *conv)
+{
+	struct gaim_connection *gc;
 	struct buddy *b;
-	int gtk_font_options = 0;
-	GString *logstr;
-	char buf2[BUF_LONG];
-	char mdate[64];
-	int unhighlight = 0;
-	char *withfonttag;
+	const char *text, *name;
 
-	if (c->is_chat && (!c->gc || !g_slist_find(c->gc->buddy_chats, c)))
+	if (conv == NULL)
 		return;
 
-	if (!c->is_chat && !g_list_find(conversations, c))
+	gc   = gaim_conversation_get_gc(conv);
+	name = gaim_conversation_get_name(conv);
+
+	if (((im_options & OPT_IM_ALIAS_TAB) == OPT_IM_ALIAS_TAB) &&
+		gc != NULL && ((b = find_buddy(gc->user, name)) != NULL)) {
+
+		text = get_buddy_alias(b);
+	}
+	else
+		text = name;
+
+	gaim_conversation_set_title(conv, text);
+}
+
+int
+gaim_conversation_get_index(const struct gaim_conversation *conv)
+{
+	if (conv == NULL)
+		return 0;
+
+	return conv->conversation_pos;
+}
+
+void
+gaim_conversation_set_unseen(struct gaim_conversation *conv,
+							 GaimUnseenState state)
+{
+	if (conv == NULL)
+		return;
+
+	conv->unseen = state;
+
+	gaim_conversation_update(conv, GAIM_CONV_UPDATE_UNSEEN);
+}
+
+void
+gaim_conversation_foreach(void (*func)(struct gaim_conversation *conv))
+{
+	struct gaim_conversation *conv;
+	GList *l;
+
+	if (func == NULL)
+		return;
+
+	for (l = gaim_get_conversations(); l != NULL; l = l->next) {
+		conv = (struct gaim_conversation *)l->data;
+
+		func(conv);
+	}
+}
+
+GaimUnseenState
+gaim_conversation_get_unseen(const struct gaim_conversation *conv)
+{
+	if (conv == NULL)
+		return 0;
+
+	return conv->unseen;
+}
+
+const char *
+gaim_conversation_get_name(const struct gaim_conversation *conv)
+{
+	if (conv == NULL)
+		return NULL;
+
+	return conv->name;
+}
+
+void
+gaim_conversation_set_logging(struct gaim_conversation *conv, gboolean log)
+{
+	if (conv == NULL)
+		return;
+
+	conv->logging = log;
+
+	gaim_conversation_update(conv, GAIM_CONV_UPDATE_LOGGING);
+}
+
+gboolean
+gaim_conversation_is_logging(const struct gaim_conversation *conv)
+{
+	if (conv == NULL)
+		return FALSE;
+
+	return conv->logging;
+}
+
+GList *
+gaim_conversation_get_send_history(const struct gaim_conversation *conv)
+{
+	if (conv == NULL)
+		return NULL;
+
+	return conv->send_history;
+}
+
+void
+gaim_conversation_set_history(struct gaim_conversation *conv,
+							  GString *history)
+{
+	if (conv == NULL)
 		return;
 
-	gtk_widget_show(c->window);
+	conv->history = history;
+}
+
+GString *
+gaim_conversation_get_history(const struct gaim_conversation *conv)
+{
+	if (conv == NULL)
+		return NULL;
+
+	return conv->history;
+}
+
+struct gaim_window *
+gaim_conversation_get_window(const struct gaim_conversation *conv)
+{
+	if (conv == NULL)
+		return NULL;
+
+	return conv->window;
+}
+
+struct gaim_im *
+gaim_conversation_get_im_data(const struct gaim_conversation *conv)
+{
+	if (conv == NULL)
+		return NULL;
+
+	if (gaim_conversation_get_type(conv) != GAIM_CONV_IM)
+		return NULL;
+
+	return conv->u.im;
+}
+
+struct gaim_chat *
+gaim_conversation_get_chat_data(const struct gaim_conversation *conv)
+{
+	if (conv == NULL)
+		return NULL;
+
+	if (gaim_conversation_get_type(conv) != GAIM_CONV_CHAT)
+		return NULL;
+
+	return conv->u.chat;
+}
+
+GList *
+gaim_get_conversations(void)
+{
+	return conversations;
+}
+
+GList *
+gaim_get_ims(void)
+{
+	return ims;
+}
+
+GList *
+gaim_get_chats(void)
+{
+	return chats;
+}
+
+struct gaim_conversation *
+gaim_find_conversation(const char *name)
+{
+	struct gaim_conversation *c = NULL;
+	char *cuser;
+	GList *cnv;
+
+	if (name == NULL)
+		return NULL;
+
+	cuser = g_strdup(normalize(name));
+
+	for (cnv = gaim_get_conversations(); cnv != NULL; cnv = cnv->next) {
+		c = (struct gaim_conversation *)cnv->data;
+
+		if (!g_strcasecmp(cuser, normalize(gaim_conversation_get_name(c))))
+			break;
+
+		c = NULL;
+	}
 
-	if (!c->is_chat || !(c->gc->prpl->options & OPT_PROTO_UNIQUE_CHATNAME)) {
-		if (!who) {
-			if (flags & WFLAG_SEND) {
-				b = find_buddy(c->gc->user, c->gc->username);
-				if (get_buddy_alias_only(b))
-					 who = get_buddy_alias(b);
-				else if (c->gc->user->alias[0])
-					who = c->gc->user->alias;
-				else if (c->gc->displayname[0])
-					who = c->gc->displayname;
+	g_free(cuser);
+
+	return c;
+}
+
+struct gaim_conversation *
+gaim_find_conversation_with_user(const char *name, const struct aim_user *user)
+{
+	struct gaim_conversation *c = NULL;
+	char *cuser;
+	GList *cnv;
+
+	if (name == NULL || user == NULL)
+		return NULL;
+
+	cuser = g_strdup(normalize(name));
+
+	for (cnv = gaim_get_conversations(); cnv != NULL; cnv = cnv->next) {
+		c = (struct gaim_conversation *)cnv->data;
+
+		if (!g_strcasecmp(cuser, normalize(gaim_conversation_get_name(c))) &&
+			user == gaim_conversation_get_user(c)) {
+
+			break;
+		}
+
+		c = NULL;
+	}
+
+	g_free(cuser);
+
+	return c;
+}
+
+void
+gaim_conversation_write(struct gaim_conversation *conv, const char *who,
+						const char *message, size_t length, int flags,
+						time_t mtime)
+{
+	struct gaim_connection *gc;
+	struct gaim_conversation_ops *ops;
+	struct gaim_window *win;
+	struct buddy *b;
+	GaimUnseenState unseen;
+	/* int logging_font_options = 0; */
+
+	if (conv == NULL || message == NULL)
+		return;
+
+	ops = gaim_conversation_get_ops(conv);
+
+	if (ops == NULL || ops->write_conv == NULL)
+		return;
+
+	gc = gaim_conversation_get_gc(conv);
+
+	if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT &&
+		(gc == NULL || !g_slist_find(gc->buddy_chats, conv)))
+		return;
+
+	if (gaim_conversation_get_type(conv) == GAIM_CONV_IM &&
+		!g_list_find(gaim_get_conversations(), conv))
+		return;
+
+	if (gaim_conversation_get_type(conv) == GAIM_CONV_IM ||
+		!(gc->prpl->options & OPT_PROTO_UNIQUE_CHATNAME)) {
+
+		if (who == NULL) {
+			if ((flags & WFLAG_SEND) == WFLAG_SEND) {
+				b = find_buddy(gc->user, gc->username);
+
+				if (b != NULL && strcmp(b->name, get_buddy_alias(b)))
+					who = get_buddy_alias(b);
+				else if (*gc->user->alias)
+					who = gc->user->alias;
+				else if (*gc->displayname)
+					who = gc->displayname;
 				else
-					who = c->gc->username;
-			} else {
-				b = find_buddy(c->gc->user, c->name);
-				if (b)
+					who = gc->username;
+			}
+			else {
+				b = find_buddy(gc->user, gaim_conversation_get_name(conv));
+
+				if (b != NULL)
 					who = get_buddy_alias(b);
 				else
-					who = c->name;
+					who = gaim_conversation_get_name(conv);
 			}
-		} else {
-			b = find_buddy(c->gc->user, who);
-			if (b)
+		}
+		else {
+			b = find_buddy(gc->user, who);
+
+			if (b != NULL)
 				who = get_buddy_alias(b);
 		}
 	}
 
-	strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime));
-
-	gtk_font_options = gtk_font_options ^ GTK_IMHTML_NO_COMMENTS;
-
-	if (convo_options & OPT_CONVO_IGNORE_COLOUR)
-		gtk_font_options = gtk_font_options ^ GTK_IMHTML_NO_COLOURS;
-
-	if (convo_options & OPT_CONVO_IGNORE_FONTS)
-		gtk_font_options = gtk_font_options ^ GTK_IMHTML_NO_FONTS;
-
-	if (convo_options & OPT_CONVO_IGNORE_SIZES)
-		gtk_font_options = gtk_font_options ^ GTK_IMHTML_NO_SIZES;
-
-	if (!(logging_options & OPT_LOG_STRIP_HTML))
-		gtk_font_options = gtk_font_options ^ GTK_IMHTML_RETURN_LOG;
+	ops->write_conv(conv, who, message, length, flags, mtime);
 
-	if (flags & WFLAG_SYSTEM) {
-		if (convo_options & OPT_CONVO_SHOW_TIME)
-			g_snprintf(buf, BUF_LONG, "<FONT SIZE=\"2\">(%s) </FONT><B>%s</B>", mdate, what);
-		else
-			g_snprintf(buf, BUF_LONG, "<B>%s</B>", what);
-		g_snprintf(buf2, sizeof(buf2), "<FONT SIZE=\"2\"><!--(%s) --></FONT><B>%s</B><BR>",
-			   mdate, what);
-
-		gtk_imhtml_append_text(GTK_IMHTML(c->text), buf2, -1, 0);
+	/* TODO: Do logging fun stuff. */
 
-		if (logging_options & OPT_LOG_STRIP_HTML) {
-			char *t1 = strip_html(buf);
-			c->history = g_string_append(c->history, t1);
-			c->history = g_string_append(c->history, "\n");
-			g_free(t1);
-		} else {
-			c->history = g_string_append(c->history, buf);
-			c->history = g_string_append(c->history, "<BR>\n");
-		}
-
-		if (!(flags & WFLAG_NOLOG) && ((c->is_chat && (logging_options & OPT_LOG_CHATS))
-								               || (!c->is_chat && (logging_options & OPT_LOG_CONVOS))
-															 || find_log_info(c->name))) {
-			char *t1;
-			char nm[256];
+	win = gaim_conversation_get_window(conv);
 
-			if (logging_options & OPT_LOG_STRIP_HTML) {
-				t1 = strip_html(buf);
-			} else {
-				t1 = buf;
-			}
-			if (c->is_chat)
-				g_snprintf(nm, 256, "%s.chat", c->name);
-			else
-				g_snprintf(nm, 256, "%s", c->name);
-			fd = open_log_file(nm, c->is_chat);
-			if (fd) {
-				if (logging_options & OPT_LOG_STRIP_HTML) {
-					fprintf(fd, "%s\n", t1);
-				} else {
-					fprintf(fd, "%s<BR>\n", t1);
-				}
-				fclose(fd);
-			}
-			if (logging_options & OPT_LOG_STRIP_HTML) {
-				g_free(t1);
-			}
-		}
-	} else if (flags & WFLAG_NOLOG) {
-		g_snprintf(buf, BUF_LONG, "<B><FONT COLOR=\"#777777\">%s</FONT></B><BR>", what);
-		gtk_imhtml_append_text(GTK_IMHTML(c->text), buf, -1, 0);
-	} else {
-		if (flags & WFLAG_WHISPER) {
-			/* if we're whispering, it's not an autoresponse */
-			if (meify(what, length)) {
-				str = g_malloc(1024);
-				g_snprintf(str, 1024, "***%s", who);
-				strcpy(colour, "#6C2585");
-			} else {
-				str = g_malloc(1024);
-				g_snprintf(str, 1024, "*%s*:", who);
-				strcpy(colour, "#00ff00");
-			}
-		} else {
-			if (meify(what, length)) {
-				str = g_malloc(1024);
-				if (flags & WFLAG_AUTO)
-					g_snprintf(str, 1024, "%s ***%s", AUTO_RESPONSE, who);
-				else
-					g_snprintf(str, 1024, "***%s", who);
-				if (flags & WFLAG_NICK)
-					strcpy(colour, "#af7f00");
-				else
-					strcpy(colour, "#062585");
-			} else {
-				str = g_malloc(1024);
-				if (flags & WFLAG_AUTO)
-					g_snprintf(str, 1024, "%s %s", who, AUTO_RESPONSE);
-				else
-					g_snprintf(str, 1024, "%s:", who);
-				if (flags & WFLAG_NICK)
-					strcpy(colour, "#af7f00");
-				else if (flags & WFLAG_RECV) {
-					if (flags & WFLAG_COLORIZE) {
-						char *u = who;	
-						int m = 0;
-						while (*u) {
-							m = m + *u;
-							u++;
-						}
-						m = m % NUM_NICK_COLORS;
-						strcpy(colour, nick_colors[m]);
-					} else {
-						strcpy(colour, "#a82f2f");
-					}
-				} else if (flags & WFLAG_SEND)
-					strcpy(colour, "#16569e");
-			}
-		}
+	if (!(flags & WFLAG_NOLOG) &&
+		((gaim_conversation_get_type(conv) == GAIM_CONV_CHAT &&
+		  (chat_options & OPT_CHAT_POPUP)) ||
+		 (gaim_conversation_get_type(conv) == GAIM_CONV_IM &&
+		  (im_options & OPT_IM_POPUP)))) {
 
-		if (convo_options & OPT_CONVO_SHOW_TIME)
-			g_snprintf(buf, BUF_LONG, "<FONT COLOR=\"%s\"><FONT SIZE=\"2\">(%s) </FONT>"
-				   "<B>%s</B></FONT> ", colour, mdate, str);
-		else
-			g_snprintf(buf, BUF_LONG, "<FONT COLOR=\"%s\"><B>%s</B></FONT> ", colour, str);
-		g_snprintf(buf2, BUF_LONG, "<FONT COLOR=\"%s\"><FONT SIZE=\"2\"><!--(%s) --></FONT>"
-			   "<B>%s</B></FONT> ", colour, mdate, str);
-
-		g_free(str);
-
-		gtk_imhtml_append_text(GTK_IMHTML(c->text), buf2, -1, 0);
-		
-		withfonttag = g_strdup_printf("<font sml=\"%s\">%s</font>", c->gc->prpl->name, what);
-		logstr = gtk_imhtml_append_text(GTK_IMHTML(c->text), withfonttag, length, gtk_font_options);
-
-		gtk_imhtml_append_text(GTK_IMHTML(c->text), "<BR>", -1, 0);
+		gaim_window_show(win);
+	}
 
-		/* XXX this needs to be updated for the new length argument */
-		if (logging_options & OPT_LOG_STRIP_HTML) {
-			char *t1, *t2;
-			t1 = strip_html(buf);
-			t2 = strip_html(what);
-			c->history = g_string_append(c->history, t1);
-			c->history = g_string_append(c->history, t2);
-			c->history = g_string_append(c->history, "\n");
-			g_free(t1);
-			g_free(t2);
-		} else {
-			char *t1, *t2;
-			t1 = html_logize(buf);
-			t2 = html_logize(what);
-			c->history = g_string_append(c->history, t1);
-			c->history = g_string_append(c->history, t2);
-			c->history = g_string_append(c->history, "\n");
-			c->history = g_string_append(c->history, logstr->str);
-			c->history = g_string_append(c->history, "<BR>\n");
-			g_free(t1);
-			g_free(t2);
-		}
+	/* Tab highlighting */
+	if (!(flags & WFLAG_RECV) && !(flags & WFLAG_SYSTEM))
+		return;
 
-		/* XXX this needs to be updated for the new length argument */
-		if ((c->is_chat && (logging_options & OPT_LOG_CHATS))
-				|| (!c->is_chat && (logging_options & OPT_LOG_CONVOS)) || find_log_info(c->name)) {
-			char *t1, *t2;
-			char *nm = g_malloc(256);
-			if (c->is_chat)
-				g_snprintf(nm, 256, "%s.chat", c->name);
-			else
-				g_snprintf(nm, 256, "%s", c->name);
-
-			if (logging_options & OPT_LOG_STRIP_HTML) {
-				t1 = strip_html(buf);
-				t2 = strip_html(withfonttag);
-			} else {
-				t1 = html_logize(buf);
-				t2 = html_logize(withfonttag);
-			}
-			fd = open_log_file(nm, c->is_chat);
-			if (fd) {
-				if (logging_options & OPT_LOG_STRIP_HTML) {
-					fprintf(fd, "%s%s\n", t1, t2);
-				} else {
-					fprintf(fd, "%s%s%s<BR>\n", t1, t2, logstr->str);
-					g_string_free(logstr, TRUE);
-				}
-				fclose(fd);
-			}
-			g_free(t1);
-			g_free(t2);
-			g_free(nm);
-		}
-		
-		g_free(withfonttag);	
+	if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) {
+		if ((flags & WFLAG_RECV) == WFLAG_RECV)
+			gaim_im_set_typing_state(GAIM_IM(conv), NOT_TYPING);
 	}
 
-
-	if (!(flags & WFLAG_NOLOG) && ((c->is_chat && (chat_options & OPT_CHAT_POPUP)) ||
-								   (!c->is_chat && (im_options & OPT_IM_POPUP))))
-		gdk_window_show(c->window->window);
+	if (gaim_window_get_active_conversation(win) != conv) {
+		if ((flags & WFLAG_NICK) == WFLAG_NICK)
+			unseen = GAIM_UNSEEN_NICK;
+		else
+			unseen = GAIM_UNSEEN_TEXT;
+	}
+	else
+		unseen = GAIM_UNSEEN_NONE;
 
-	/* tab highlighting */
-	if (c->is_chat && !(chat_options & OPT_CHAT_ONE_WINDOW)) /* if chat but not tabbed chat */
-		return;
-	if (!(flags & WFLAG_RECV) && !(flags & WFLAG_SYSTEM))
-		return;
-	if (im_options & OPT_IM_ONE_WINDOW && ((c->unseen == 2) || ((c->unseen == 1) && !(flags & WFLAG_NICK))))
+	gaim_conversation_set_unseen(conv, unseen);
+}
+
+void
+gaim_conversation_update_progress(struct gaim_conversation *conv,
+								  float percent)
+{
+	struct gaim_conversation_ops *ops;
+
+	if (conv == NULL)
 		return;
 
-	if (flags & WFLAG_RECV)
-		c->typing_state = NOT_TYPING;
-
+	if (percent < 0)
+		percent = 0;
 
-	if (c->is_chat) {
-		int offs;
-		if ((convo_options & OPT_CONVO_COMBINE) && (im_options & OPT_IM_ONE_WINDOW))
-			offs = g_list_length(conversations);
-		else
-			offs = 0;
-		if (gtk_notebook_get_current_page(GTK_NOTEBOOK(chat_notebook)) ==
-				g_list_index(chats, c) + offs)
-			unhighlight = 1;
-	} else {
-		if (im_options & OPT_IM_ONE_WINDOW)
-			if (gtk_notebook_get_current_page(GTK_NOTEBOOK(convo_notebook)) ==
-					g_list_index(conversations, c))
-				unhighlight = 1;
-	}
+	/*
+	 * NOTE: A percent >= 1 indicates that the progress bar should be
+	 *       closed.
+	 */
+	ops = gaim_conversation_get_ops(conv);
 
-	if (!unhighlight && flags & WFLAG_NICK) {
-		c->unseen = 2;
-	} else if (!unhighlight) {
-		c->unseen = 1;
-	} else {
-		c->unseen = 0;
-	}
-	update_convo_status(c);
+	if (ops != NULL && ops->update_progress != NULL)
+		ops->update_progress(conv, percent);
 }
 
-void update_progress(struct conversation *c, float percent) {
-            
-       if (percent >= 1 && !(c->progress))
-	       return;
+void
+gaim_conversation_update(struct gaim_conversation *conv,
+						 GaimConvUpdateType type)
+{
+	struct gaim_conversation_ops *ops;
+
+	if (conv == NULL)
+		return;
+
+	ops = gaim_conversation_get_ops(conv);
+
+	if (ops != NULL && ops->updated != NULL)
+		ops->updated(conv, type);
+}
 
-       if (percent >= 1) {
-	       gtk_widget_destroy(c->progress);
-               c->progress = NULL;
-               return;
-       }
-       
-       if (!c->progress) {
-               GtkBox *box = GTK_BOX(c->text->parent->parent);
-               c->progress = gtk_progress_bar_new();
-               gtk_box_pack_end(box, c->progress, FALSE, FALSE, 0);
-               gtk_widget_set_size_request (c->progress, 1, 8);
-               gtk_widget_show (c->progress);
-       }
-       
-       if (percent < 1)
-               gtk_progress_set_percentage(GTK_PROGRESS(c->progress), percent);
+/**************************************************************************
+ * IM Conversation API
+ **************************************************************************/
+struct gaim_conversation *
+gaim_im_get_conversation(struct gaim_im *im)
+{
+	if (im == NULL)
+		return NULL;
+
+	return im->conv;
+}
+
+void
+gaim_im_set_typing_state(struct gaim_im *im, int state)
+{
+	if (im == NULL)
+		return;
+
+	im->typing_state = state;
 }
 
-GtkWidget *build_conv_menubar(struct conversation *c)
+int
+gaim_im_get_typing_state(const struct gaim_im *im)
 {
-	GtkWidget *hb;
-	GtkWidget *menubar;
-	GtkWidget *menu;
-	GtkWidget *menuitem;
+	if (im == NULL)
+		return 0;
 
+	return im->typing_state;
+}
 
-	hb = gtk_handle_box_new();
-		
-	menubar = gtk_menu_bar_new();
+void
+gaim_im_start_typing_timeout(struct gaim_im *im, int timeout)
+{
+	struct gaim_conversation *conv;
+	const char *name;
 
-	gtk_container_add(GTK_CONTAINER(hb), menubar);
-
-	menu = gtk_menu_new();
+	if (im == NULL)
+		return;
 
-	/* The file menu */
-	menuitem = gaim_new_item(NULL, _("File"));
-	gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menu);
-	gtk_menu_shell_append(GTK_MENU_SHELL(menubar), menuitem);
+	if (im->typing_timeout > 0)
+		gaim_im_stop_typing_timeout(im);
 
-	gaim_new_item_from_stock(menu, _("_Save Conversation"), "gtk-save-as", G_CALLBACK(save_convo), c, 0, 0, NULL); 
-
-	gaim_new_item_from_stock(menu, _("View _History"), NULL, G_CALLBACK(conv_show_log), GINT_TO_POINTER(c->name), 0, 0, NULL); 
+	conv = gaim_im_get_conversation(im);
+	name = gaim_conversation_get_name(conv);
 
-	menuitem = gtk_menu_item_new();
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
-/*
-	c->sendfile_btn = gaim_new_item_from_pixbuf(menu, _("Send File"), "send-file-small.png", NULL, NULL, 0, 0, NULL); */
-
-	gaim_new_item_from_pixbuf(menu, _("Insert _URL"), "insert-link-small.png", G_CALLBACK(insert_link_cb), c, 0, 0, NULL); 
-	c->image_menubtn = gaim_new_item_from_pixbuf(menu, _("Insert _Image"), "insert-image-small.png", G_CALLBACK(insert_image), c, 0, 0, NULL); 
+	im->typing_timeout = g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE,
+		timeout * 1000, reset_typing, g_strdup(name), g_free);
+}
 
-	menuitem = gtk_menu_item_new();
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+void
+gaim_im_stop_typing_timeout(struct gaim_im *im)
+{
+	if (im == NULL)
+		return;
 
-	gaim_new_item_from_stock(menu, _("_Close"), "gtk-close", G_CALLBACK(close_callback), c, 0, 0, NULL); 
-
-	/* The Options  menu */
-	menu = gtk_menu_new();
+	if (im->typing_timeout == 0)
+		return;
 
-	menuitem = gaim_new_item(NULL, _("Options"));
-	gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menu);
-	gtk_menu_shell_append(GTK_MENU_SHELL(menubar), menuitem);
+	g_source_remove(im->typing_timeout);
+	im->typing_timeout = 0;
+}
 
-	/* Logging */
-	menuitem = gtk_check_menu_item_new_with_mnemonic(_("Enable _Logging"));
-	c->log_button = menuitem;  /* We should save this */
-	
-	state_lock = 1;
+guint
+gaim_im_get_typing_timeout(const struct gaim_im *im)
+{
+	if (im == NULL)
+		return 0;
 
-	if (find_log_info(c->name))
-		gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);	
-	else
-		gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);	
+	return im->typing_timeout;
+}
 
-	state_lock = 0;
-
-	g_signal_connect(GTK_OBJECT(menuitem), "toggled", G_CALLBACK(toggle_loggle), c);
+void
+gaim_im_set_type_again(struct gaim_im *im, time_t val)
+{
+	if (im == NULL)
+		return;
 
-	/* Sounds */
+	im->type_again = val;
+}
 
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+time_t
+gaim_im_get_type_again(const struct gaim_im *im)
+{
+	if (im == NULL)
+		return 0;
 
-	menuitem = gtk_check_menu_item_new_with_mnemonic(_("Enable _Sounds"));
-	c->makesound = 1;
-	g_signal_connect(GTK_OBJECT(menuitem), "toggled", G_CALLBACK(toggle_sound), c);
-	state_lock = 1;
-	gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
-	state_lock = 0;
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
-
+	return im->type_again;
+}
 
-
-	/* Now set the current values or something */
-	gtk_widget_set_sensitive(GTK_WIDGET(c->log_button), (logging_options & OPT_LOG_CONVOS) ? FALSE : TRUE);
+void
+gaim_im_start_type_again_timeout(struct gaim_im *im)
+{
+	if (im == NULL)
+		return;
 
-	gtk_widget_show_all(hb);
-
-	return hb;
-
+	im->type_again_timeout = g_timeout_add(SEND_TYPED_TIMEOUT, send_typed,
+										   gaim_im_get_conversation(im));
 }
 
-GtkWidget *build_conv_toolbar(struct conversation *c)
+void
+gaim_im_stop_type_again_timeout(struct gaim_im *im)
 {
-		GtkWidget *vbox;
-		GtkWidget *hbox;
-		GtkWidget *button;
-		GtkWidget *sep;
-		GtkSizeGroup *sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
-		/*
-	c->toolbar = toolbar;
-	c->bold = bold;
-	c->strike = strike;
-	c->italic = italic;
-	c->underline = underline;
-	c->log_button = wood;
-	c->viewer_button = viewer;
-	c->fgcolorbtn = fgcolorbtn;
-	c->bgcolorbtn = bgcolorbtn;
-	c->link = link;
-	c->wood = wood;
-	c->font = font;
-	c->smiley = smiley;
-	c->imagebtn = image;
-	c->speaker = speaker;
-	c->speaker_p = speaker_p;
-	*/
+	if (im == NULL)
+		return;
 
-		vbox = gtk_vbox_new(FALSE, 0);
-		sep = gtk_hseparator_new();
-		gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0);
-		
-		hbox = gtk_hbox_new(FALSE, 5);
-		gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
-
-		/* Bold */
-		button = gaim_pixbuf_toolbar_button_from_stock("gtk-bold");
-		gtk_size_group_add_widget(sg, button);
-		gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
-		g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(do_bold), c);
-		c->bold = button; /* We should remember this */
+	if (im->type_again_timeout == 0)
+		return;
 
-		/* Italic */
-		button = gaim_pixbuf_toolbar_button_from_stock("gtk-italic");
-		gtk_size_group_add_widget(sg, button);
-		gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
-		g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(do_italic), c);
-		c->italic = button; /* We should remember this */
-
-		/* Underline */
-		button = gaim_pixbuf_toolbar_button_from_stock("gtk-underline");
-		gtk_size_group_add_widget(sg, button);
-		gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
-		g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(do_underline), c);
-		c->underline = button; /* We should remember this */
-
-		/* Sep */
-		sep = gtk_vseparator_new();
-		gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0);
+	g_source_remove(im->type_again_timeout);
+	im->type_again_timeout = 0;
+}
 
-		/* Increase font size */
-		button = gaim_pixbuf_toolbar_button_from_file("text_bigger.png");
-		gtk_size_group_add_widget(sg, button);
-		gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
-		g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(do_big), c);
-		
-		/* Normal Font Size */
-		button = gaim_pixbuf_toolbar_button_from_file("text_normal.png");
-		gtk_size_group_add_widget(sg, button);
-		gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
-		g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(do_normal), c);
-		c->font = button; /* We should remember this */
-		
-		/* Decrease font size */
-		button = gaim_pixbuf_toolbar_button_from_file("text_smaller.png");
-		gtk_size_group_add_widget(sg, button);
-		gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
-		g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(do_small), c);
+guint
+gaim_im_get_type_again_timeout(const struct gaim_im *im)
+{
+	if (im == NULL)
+		return 0;
 
-		/* Sep */
-		sep = gtk_vseparator_new();
-		gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0);
-
-		/* Font Color */
-		button = gaim_pixbuf_toolbar_button_from_file("change-fgcolor-small.png");
-		gtk_size_group_add_widget(sg, button);
-		gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
-		g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(toggle_fg_color), c);
-		c->fgcolorbtn = button; /* We should remember this */
+	return im->type_again_timeout;
+}
 
-		/* Font Color */
-		button = gaim_pixbuf_toolbar_button_from_file("change-bgcolor-small.png");
-		gtk_size_group_add_widget(sg, button);
-		gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
-		g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(toggle_bg_color), c);
-		c->bgcolorbtn = button; /* We should remember this */
-
-
-		/* Sep */
-		sep = gtk_vseparator_new();
-		gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0);
-
-		/* Insert IM Image  */
-		button = gaim_pixbuf_toolbar_button_from_file("insert-image-small.png");
-		g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(insert_image), c);
-		gtk_size_group_add_widget(sg, button);
-		gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
-		c->imagebtn = button;
+void
+gaim_im_update_typing(struct gaim_im *im)
+{
+	if (im == NULL)
+		return;
 
-		/* Insert Link  */
-		button = gaim_pixbuf_toolbar_button_from_file("insert-link-small.png");
-		g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(toggle_link), c);
-		gtk_size_group_add_widget(sg, button);
-		gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
-		c->link = button;
-
-		/* Insert Smiley */
-		button = gaim_pixbuf_toolbar_button_from_file("insert-smiley-small.png");
-		g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(insert_smiley), c);
-		gtk_size_group_add_widget(sg, button);
-		gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
-		c->smiley = button;
-
-		sep = gtk_hseparator_new();
-		gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0);
-
-		gtk_widget_show_all(vbox);
-
-		return vbox;
+	gaim_conversation_update(gaim_im_get_conversation(im),
+							 GAIM_CONV_UPDATE_TYPING);
 }
 
-static void convo_sel_send(GtkObject *m, struct gaim_connection *c)
+void
+gaim_im_write(struct gaim_im *im, const char *who, const char *message,
+			  size_t len, int flag, time_t mtime)
 {
-	struct conversation *cnv = gtk_object_get_user_data(m);
+	struct gaim_conversation *c;
 
-	if (cnv->gc == c)
+	if (im == NULL || message == NULL)
 		return;
 
-	cnv->gc = c;
-
-	set_convo_title(cnv);
+	c = gaim_im_get_conversation(im);
 
-	update_buttons_by_protocol(cnv);
-
-	update_icon(cnv);
-	update_checkbox(cnv);
+	if (c->ops != NULL && c->ops->write_im != NULL)
+		c->ops->write_im(c, who, message, len, flag, mtime);
+	else
+		gaim_conversation_write(c, who, message, -1, flag, mtime);
 }
 
-int set_dispstyle(int chat)
+void
+gaim_im_send(struct gaim_im *im, const char *message)
 {
-	int dispstyle;
+	if (im == NULL || message == NULL)
+		return;
+
+	common_send(gaim_im_get_conversation(im), message);
+}
+
+/**************************************************************************
+ * Chat Conversation API
+ **************************************************************************/
 
-	if (chat) {
-		switch (chat_options & (OPT_CHAT_BUTTON_TEXT | OPT_CHAT_BUTTON_XPM)) {
-		case OPT_CHAT_BUTTON_TEXT:
-			dispstyle = 1;
-			break;
-		case OPT_CHAT_BUTTON_XPM:
-			dispstyle = 0;
-			break;
-		default:	/* both or neither */
-			dispstyle = 2;
-			break;
-		}
-	} else {
-		switch (im_options & (OPT_IM_BUTTON_TEXT | OPT_IM_BUTTON_XPM)) {
-		case OPT_IM_BUTTON_TEXT:
-			dispstyle = 1;
-			break;
-		case OPT_IM_BUTTON_XPM:
-			dispstyle = 0;
-			break;
-		default:	/* both or neither */
-			dispstyle = 2;
-			break;
-		}
-	}
-	return dispstyle;
+struct gaim_conversation *
+gaim_chat_get_conversation(struct gaim_chat *chat)
+{
+	if (chat == NULL)
+		return NULL;
+
+	return chat->conv;
+}
+
+GList *
+gaim_chat_set_users(struct gaim_chat *chat, GList *users)
+{
+	if (chat == NULL)
+		return NULL;
+
+	chat->in_room = users;
+
+	return users;
 }
 
-void update_convo_add_button(struct conversation *c)
+GList *
+gaim_chat_get_users(const struct gaim_chat *chat)
 {
-	int dispstyle = set_dispstyle(0);
-	GtkWidget *parent = c->add->parent;
-	gboolean rebuild = FALSE;
+	if (chat == NULL)
+		return NULL;
 
-	if (find_buddy(c->gc->user, c->name)) {
-		if (!gtk_object_get_user_data(GTK_OBJECT(c->add))) {
-			gtk_widget_destroy(c->add);
-			c->add = gaim_pixbuf_button_from_stock(dispstyle == 0 ? NULL : _("Remove"),
-												   dispstyle == 1 ? NULL : "gtk-remove",
-												   GAIM_BUTTON_VERTICAL);
-			rebuild = TRUE;
-		}
-		if (c->gc) {
-			if (c->gc->prpl->remove_buddy == NULL)
-				gtk_widget_set_sensitive(c->add, FALSE);
-			else
-				gtk_widget_set_sensitive(c->add, TRUE);
-		} else
-			gtk_widget_set_sensitive(c->add, FALSE);
-		gtk_object_set_user_data(GTK_OBJECT(c->add), c);
-	} else {
-		if (gtk_object_get_user_data(GTK_OBJECT(c->add))) {
-			gtk_widget_destroy(c->add);
-			c->add = gaim_pixbuf_button_from_stock(dispstyle == 0 ? NULL : _("Add"),
-												   dispstyle == 1 ? NULL : "gtk-add",
-												   GAIM_BUTTON_VERTICAL);
-			rebuild = TRUE;
-		}
-		if (c->gc) {
-			if (c->gc->prpl->add_buddy == NULL)
-				gtk_widget_set_sensitive(c->add, FALSE);
-			else
-				gtk_widget_set_sensitive(c->add, TRUE);
-		} else
-			gtk_widget_set_sensitive(c->add, FALSE);
-	}
-
-	if (rebuild) {
-		g_signal_connect(GTK_OBJECT(c->add), "clicked", G_CALLBACK(add_callback), c);
-		gtk_box_pack_start(GTK_BOX(parent), c->add, FALSE, FALSE, 0);
-		gtk_box_reorder_child(GTK_BOX(parent), c->add, 3);
-		gtk_button_set_relief(GTK_BUTTON(c->add), GTK_RELIEF_NONE);
-		gtk_size_group_add_widget(c->sg, c->add);
-		gtk_widget_show(c->add);
-	}
+	return chat->in_room;
 }
 
-static void create_convo_menu(struct conversation *cnv)
+void
+gaim_chat_ignore(struct gaim_chat *chat, const char *name)
 {
-	GtkWidget *menu, *opt;
-	GSList *g = connections;
-	struct gaim_connection *c;
-	char buf[2048];
+	if (chat == NULL || name == NULL)
+		return;
 
-	if (g_slist_length(g) < 2)
-		gtk_widget_hide(cnv->menu->parent);
-	else {
-		menu = gtk_menu_new();
+	/* Make sure the user isn't already ignored. */
+	if (gaim_chat_is_user_ignored(chat, name))
+		return;
+
+	gaim_chat_set_ignored(chat,
+		g_list_append(gaim_chat_get_ignored(chat), g_strdup(name)));
+}
 
-		while (g) {
-			c = (struct gaim_connection *)g->data;
-			g_snprintf(buf, sizeof buf, "%s (%s)", c->username, c->prpl->name);
-			opt = gtk_menu_item_new_with_label(buf);
-			gtk_object_set_user_data(GTK_OBJECT(opt), cnv);
-			g_signal_connect(GTK_OBJECT(opt), "activate",
-					   G_CALLBACK(convo_sel_send), c);
-			gtk_widget_show(opt);
-			gtk_menu_shell_append(GTK_MENU_SHELL(menu), opt);
-			g = g->next;
-		}
+void
+gaim_chat_unignore(struct gaim_chat *chat, const char *name)
+{
+	GList *item;
+
+	if (chat == NULL || name == NULL)
+		return;
 
-		gtk_option_menu_remove_menu(GTK_OPTION_MENU(cnv->menu));
-		gtk_option_menu_set_menu(GTK_OPTION_MENU(cnv->menu), menu);
-		gtk_option_menu_set_history(GTK_OPTION_MENU(cnv->menu), 0);
+	/* Make sure the user is actually ignored. */
+	if (!gaim_chat_is_user_ignored(chat, name))
+		return;
 
-		gtk_widget_show(cnv->menu);
-		gtk_widget_show(cnv->menu->parent);
-	}
+	item = g_list_find(gaim_chat_get_ignored(chat),
+					   gaim_chat_get_ignored_user(chat, name));
+
+	gaim_chat_set_ignored(chat,
+		g_list_remove_link(gaim_chat_get_ignored(chat), item));
+
+	g_free(item->data);
+	g_list_free_1(item);
 }
 
-void redo_convo_menus()
+GList *
+gaim_chat_set_ignored(struct gaim_chat *chat, GList *ignored)
 {
-	GList *c = conversations;
-	struct conversation *C;
+	if (chat == NULL)
+		return NULL;
 
-	while (c) {
-		C = (struct conversation *)c->data;
-		c = c->next;
-
-		create_convo_menu(C);
+	chat->ignored = ignored;
 
-		if (g_slist_find(connections, C->gc))
-			set_convo_gc(C, C->gc);
-		else
-			set_convo_gc(C, connections ? connections->data : NULL);
-	}
+	return ignored;
 }
 
-void convo_menu_remove(struct gaim_connection *gc)
+GList *
+gaim_chat_get_ignored(const struct gaim_chat *chat)
 {
-	GList *c = conversations;
-	struct conversation *C;
-
-	while (c) {
-		C = (struct conversation *)c->data;
-		c = c->next;
-
-		remove_icon(C);
-		remove_checkbox(C);
-	}
-}
+	if (chat == NULL)
+		return NULL;
 
-void set_convo_gc(struct conversation *c, struct gaim_connection *gc)
-{
-	if (gc)
-		gtk_option_menu_set_history(GTK_OPTION_MENU(c->menu), g_slist_index(connections, gc));
-
-	if (c->gc == gc)
-		return;
-
-	c->gc = gc;
-
-	set_convo_title(c);
-	update_buttons_by_protocol(c);
-
-	update_icon(c);
-	update_checkbox(c);
+	return chat->ignored;
 }
 
-void update_buttons_by_protocol(struct conversation *c)
+const char *
+gaim_chat_get_ignored_user(const struct gaim_chat *chat, const char *user)
 {
-	if (!c->gc) {
-		if (c->info)
-			gtk_widget_set_sensitive(c->info, FALSE);
-		if (c->send)
-			gtk_widget_set_sensitive(c->send, FALSE);
-		if (c->warn)
-			gtk_widget_set_sensitive(c->warn, FALSE);
-		if (c->block)
-			gtk_widget_set_sensitive(c->block, FALSE);
-		if (c->add)
-			gtk_widget_set_sensitive(c->add, FALSE);
-		if (c->whisper)
-			gtk_widget_set_sensitive(c->whisper, FALSE);
-		if (c->invite)
-			gtk_widget_set_sensitive(c->invite, FALSE);
-		return;
-	}
+	GList *ignored;
+
+	if (chat == NULL || user == NULL)
+		return NULL;
+
+	for (ignored = gaim_chat_get_ignored(chat);
+		 ignored != NULL;
+		 ignored = ignored->next) {
 
-	if (c->gc->prpl->get_info == NULL && c->info)
-		gtk_widget_set_sensitive(c->info, FALSE);
-	else if (c->info)
-		gtk_widget_set_sensitive(c->info, TRUE);
-/*
-	if (!c->is_chat && c->gc->prpl->file_transfer_out)
-			gtk_widget_set_sensitive(c->sendfile_btn, TRUE);
-	else
-			gtk_widget_set_sensitive(c->sendfile_btn, FALSE);
-*/	
-	if (c->is_chat) {
-		if (c->gc->prpl->chat_send == NULL && c->send)
-			gtk_widget_set_sensitive(c->send, FALSE);
-		else
-			gtk_widget_set_sensitive(c->send, TRUE);
-		
-		gtk_widget_set_sensitive(c->imagebtn, FALSE);
-		gtk_widget_set_sensitive(c->image_menubtn, FALSE);
-	} else {
-		if (c->gc->prpl->send_im == NULL && c->send)
-			gtk_widget_set_sensitive(c->send, FALSE);
-		else
-			gtk_widget_set_sensitive(c->send, TRUE);
-		if (c->gc->prpl->options & OPT_PROTO_IM_IMAGE) {
-			if (c->imagebtn)
-				gtk_widget_set_sensitive(c->imagebtn, TRUE);
-			if (c->image_menubtn)
-				gtk_widget_set_sensitive(c->image_menubtn, TRUE);
-		}
-		else {
-			
-			if (c->image_menubtn)
-				gtk_widget_set_sensitive(c->image_menubtn, FALSE);
-			if (c->imagebtn)
-				gtk_widget_set_sensitive(c->imagebtn, FALSE);
+		const char *ign = (const char *)ignored->data;
+
+		if (!g_strcasecmp(user, ign) ||
+			(*ign == '+' && !g_strcasecmp(user, ign + 1)))
+			return ign;
+
+		if (*ign == '@') {
+			ign++;
+
+			if ((*ign == '+' && !g_strcasecmp(user, ign + 1)) ||
+				(*ign != '+' && !g_strcasecmp(user, ign)))
+				return ign;
 		}
 	}
 
-	if (c->gc->prpl->warn == NULL && c->warn)
-		gtk_widget_set_sensitive(c->warn, FALSE);
-	else if (c->warn)
-		gtk_widget_set_sensitive(c->warn, TRUE);
+	return NULL;
+}
 
-	if (c->gc->prpl->add_permit == NULL && c->block)
-		gtk_widget_set_sensitive(c->block, FALSE);
-	else if (c->block)
-		gtk_widget_set_sensitive(c->block, TRUE);
+gboolean
+gaim_chat_is_user_ignored(const struct gaim_chat *chat, const char *user)
+{
+	if (chat == NULL || user == NULL)
+		return FALSE;
 
-	if (c->add)
-		update_convo_add_button(c);
+	return (gaim_chat_get_ignored_user(chat, user) != NULL);
+}
 
-	if (c->whisper) {
-		if (c->gc->prpl->chat_whisper == NULL)
-			gtk_widget_set_sensitive(c->whisper, FALSE);
-		else
-			gtk_widget_set_sensitive(c->whisper, TRUE);
-	}
+void
+gaim_chat_set_topic(struct gaim_chat *chat, const char *who, const char *topic)
+{
+	if (chat == NULL)
+		return;
 
-	if (c->invite) {
-		if (c->gc->prpl->chat_invite == NULL)
-			gtk_widget_set_sensitive(c->invite, FALSE);
-		else
-			gtk_widget_set_sensitive(c->invite, TRUE);
-	}
+	if (chat->who   != NULL) free(chat->who);
+	if (chat->topic != NULL) free(chat->topic);
+
+	chat->who   = (who   == NULL ? NULL : g_strdup(who));
+	chat->topic = (topic == NULL ? NULL : g_strdup(topic));
+
+	gaim_conversation_update(gaim_chat_get_conversation(chat),
+							 GAIM_CONV_UPDATE_TOPIC);
 }
 
-void convo_switch(GtkNotebook *notebook, GtkWidget *page, gint page_num, gpointer data)
+const char *
+gaim_chat_get_topic(const struct gaim_chat *chat)
+{
+	if (chat == NULL)
+		return NULL;
+
+	return chat->topic;
+}
+
+void
+gaim_chat_set_id(struct gaim_chat *chat, int id)
 {
-	GtkWidget *label = NULL;
-	GtkStyle *style;
-	struct conversation *c;
-	
-	if ((convo_options & OPT_CONVO_COMBINE) &&
-	    (im_options & OPT_IM_ONE_WINDOW) &&
-	    (chat_options & OPT_CHAT_ONE_WINDOW)) {
-		int len = g_list_length(conversations);
-		if (page_num < len)
-			c = g_list_nth_data(conversations, page_num);
-		else
-			c = g_list_nth_data(chats, page_num - len);
-	} else if (GTK_WIDGET(notebook) == convo_notebook)
-		c = g_list_nth_data(conversations, page_num);
-	else
-		c = g_list_nth_data(chats, page_num);
+	if (chat == NULL)
+		return;
+
+	chat->id = id;
+}
+
+int
+gaim_chat_get_id(const struct gaim_chat *chat)
+{
+	if (chat == NULL)
+		return -1;
 
-	if (c && c->window && c->entry)
-		gtk_widget_grab_focus(c->entry);
+	return chat->id;
+}
 
-	label = c->tab_label;
+void
+gaim_chat_write(struct gaim_chat *chat, const char *who,
+				const char *message, int flag, time_t mtime)
+{
+	struct gaim_conversation *conv;
+	struct gaim_connection *gc;
 
-	if (!label)
+	if (chat == NULL || who == NULL || message == NULL)
 		return;
 
-	if (!GTK_WIDGET_REALIZED(label))
+	conv = gaim_chat_get_conversation(chat);
+	gc   = gaim_conversation_get_gc(conv);
+
+	/* Don't display this if the person who wrote it is ignored. */
+	if (gaim_chat_is_user_ignored(chat, who))
 		return;
-	style = gtk_style_new();
-	gtk_style_set_font(style, gdk_font_ref(gtk_style_get_font(label->style)));
-	gtk_widget_set_style(label, style);
-	gtk_style_unref(style);
-	if (c)
-		c->unseen = 0;
 
-	if (!c->is_chat) {
-			GtkWidget *menubar;
-			GtkWidget *parent = convo_notebook->parent;
+	if (!(flag & WFLAG_WHISPER)) {
+		char *str;
+
+		str = g_strdup(normalize(who));
 
-			gtk_widget_freeze_child_notify(GTK_WIDGET(c->window));
-
-			if (convo_menubar != NULL)
-					gtk_widget_destroy(convo_menubar);
+		if (!g_strcasecmp(str, normalize(gc->username)) ||
+			!g_strcasecmp(str, normalize(gc->displayname))) {
 
-			menubar = build_conv_menubar(c);
-			gtk_box_pack_start(GTK_BOX(parent), menubar, FALSE, TRUE, 0);
-			gtk_box_reorder_child(GTK_BOX(parent), menubar, 0);
-			convo_menubar = menubar;
+			flag |= WFLAG_SEND;
+		}
+		else {
+			flag |= WFLAG_RECV;
 
-			gtk_widget_thaw_child_notify(GTK_WIDGET(c->window));
-	} else {
-		gtk_widget_destroy(convo_menubar);
-		convo_menubar = NULL;
+			if (find_nick(gc, message))
+				flag |= WFLAG_NICK;
+		}
+		
+		g_free(str);
 	}
 
-	update_convo_status(c);
-
-	/*gtk_imhtml_to_bottom(c->text);*/
+	/* Pass this on to either the ops structure or the default write func. */
+	if (conv->ops != NULL && conv->ops->write_chat != NULL)
+		conv->ops->write_chat(conv, who, message, flag, mtime);
+	else
+		gaim_conversation_write(conv, who, message, -1, flag, mtime);
 }
 
-void update_convo_status(struct conversation *c) {
-	if(!c)
+void
+gaim_chat_send(struct gaim_chat *chat, const char *message)
+{
+	if (chat == NULL || message == NULL)
+		return;
+
+	common_send(gaim_chat_get_conversation(chat), message);
+}
+
+void
+gaim_chat_add_user(struct gaim_chat *chat, const char *user,
+				   const char *extra_msg)
+{
+	struct gaim_conversation *conv;
+	struct gaim_conversation_ops *ops;
+	char tmp[BUF_LONG];
+
+	if (chat == NULL || user == NULL)
 		return;
-	debug_printf("update_convo_status called for %s\n", c->name);
-	if (im_options & OPT_IM_ONE_WINDOW) { /* We'll make the tab green */
-		GtkStyle *style;
-		GtkWidget *label = c->tab_label;
-		style = gtk_style_new();
-		if (!GTK_WIDGET_REALIZED(label))
-			gtk_widget_realize(label);
-		gtk_style_set_font(style, gdk_font_ref(gtk_style_get_font(label->style)));
-		if(c->typing_state == TYPING) {
-			style->fg[0].red = 0x0000;
-			style->fg[0].green = 0x9999;
-			style->fg[0].blue = 0x0000;
-		} else if(c->typing_state == TYPED) {
-			style->fg[0].red = 0xffff;
-			style->fg[0].green = 0xbbbb;
-			style->fg[0].blue = 0x2222;
-		} else if(c->unseen == 2) {
-			style->fg[0].red = 0x0000;
-			style->fg[0].green = 0x0000;
-			style->fg[0].blue = 0xcccc;
-		} else if(c->unseen == 1) {
-			style->fg[0].red = 0xcccc;
-			style->fg[0].green = 0x0000;
-			style->fg[0].blue = 0x0000;
-		}
-		gtk_widget_set_style(label, style);
-			debug_printf("setting style\n");
-		gtk_style_unref(style);
-	} else {
-		GtkWindow *win = (GtkWindow *)c->window;
-		char *buf, *buf2;
-		int len;
-		if(strstr(win->title, _(" [TYPING]"))) {
-			debug_printf("title had TYPING in it\n");
-			len = strlen(win->title) - strlen(_(" [TYPING]"));
-		} else if(strstr(win->title, _(" [TYPED]"))) {
-			debug_printf("title had TYPED in it\n");
-			len = strlen(win->title) - strlen(_(" [TYPED]"));
-		} else {
-			debug_printf("title was free of typing information\n");
-			len = strlen(win->title);
-		}
-		buf = g_malloc(len+1);
-		g_snprintf(buf, len+1, win->title);
-		if(c->typing_state == TYPING) {
-			buf2 = g_strconcat(buf,_(" [TYPING]"), NULL);
-			g_free(buf);
-			buf = buf2;
-		} else if(c->typing_state == TYPED) {
-			buf2 = g_strconcat(buf,_(" [TYPED]"), NULL);
-			g_free(buf);
-			buf = buf2;
-		}
-		gtk_window_set_title(win, buf);
-		g_free(buf);
+
+	conv = gaim_chat_get_conversation(chat);
+	ops  = gaim_conversation_get_ops(conv);
+
+	gaim_chat_set_users(chat,
+		g_list_insert_sorted(gaim_chat_get_users(chat), g_strdup(user),
+							 insertname_compare));
+
+	plugin_event(event_chat_buddy_join,
+				 gaim_conversation_get_gc(conv), gaim_chat_get_id(chat),
+				 user);
+
+	if (ops != NULL && ops->chat_add_user != NULL)
+		ops->chat_add_user(conv, user);
+
+	if (chat_options & OPT_CHAT_LOGON) {
+		if (extra_msg == NULL)
+			g_snprintf(tmp, sizeof(tmp), _("%s entered the room."), user);
+		else
+			g_snprintf(tmp, sizeof(tmp),
+					   _("%s [<I>%s</I>] entered the room."),
+					   user, extra_msg);
+
+		gaim_conversation_write(conv, NULL, tmp, -1, WFLAG_SYSTEM, time(NULL));
 	}
 }
 
-/* This returns a boolean, so that it can timeout */
-gboolean reset_typing(gpointer data) {
-	char *name = data;
-	struct conversation *c = find_conversation(name);
-	if (!c)
-		return FALSE;
-
-	/* Reset the title (if necessary) */
-	c->typing_state = NOT_TYPING;
-	update_convo_status(c);
-
-	c->typing_timeout = 0;
-	return FALSE;
-}
-
-void show_conv(struct conversation *c)
+void
+gaim_chat_rename_user(struct gaim_chat *chat, const char *old_user,
+					  const char *new_user)
 {
-	GtkWidget *win;
-	GtkWidget *cont;
-	GtkWidget *text;
-	GtkWidget *sw;
-	GtkWidget *send;
-	GtkWidget *info;
-	GtkWidget *warn;
-	GtkWidget *block;
-	/*GtkWidget *close;*/
-	GtkWidget *frame;
-	GtkWidget *entry;
-	GtkWidget *bbox;
-	GtkWidget *vbox;
-	GtkWidget *vbox2;
-	GtkWidget *paned;
-	GtkWidget *add;
-	GtkWidget *toolbar;
-	GtkWidget *hbox;
-	GtkWidget *label;
-	GtkWidget *menubar;
-	GtkWidget *tabby;
-	int dispstyle = set_dispstyle(0);
-
-	c->sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
-
-	c->font_dialog = NULL;
-	c->fg_color_dialog = NULL;
-	c->bg_color_dialog = NULL;
-	c->smiley_dialog = NULL;
-	c->link_dialog = NULL;
-	c->log_dialog = NULL;
-	sprintf(c->fontface, "%s", fontface);
-	c->hasfont = 0;
-	c->bgcol = bgcolor;
-	c->hasbg = 0;
-	c->fgcol = fgcolor;
-	c->hasfg = 0;
-
-	if (im_options & OPT_IM_ONE_WINDOW) {
-		if (!all_convos) {
-			GtkWidget *testidea;
-			win = all_convos = c->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-			if ((convo_options & OPT_CONVO_COMBINE) && (chat_options & OPT_CHAT_ONE_WINDOW))
-				all_chats = all_convos;
-			gtk_window_set_role(GTK_WINDOW(win), "conversation");
-			gtk_window_set_policy(GTK_WINDOW(win), TRUE, TRUE, FALSE);
-			gtk_container_border_width(GTK_CONTAINER(win), 0);
-			gtk_widget_realize(win);
-			gtk_window_set_title(GTK_WINDOW(win), _("Gaim - Conversations"));
-			g_signal_connect(GTK_OBJECT(win), "delete_event",
-					   G_CALLBACK(delete_all_convo), NULL);
-
-			convo_notebook = gtk_notebook_new();
-			if ((convo_options & OPT_CONVO_COMBINE) && (chat_options & OPT_CHAT_ONE_WINDOW))
-				chat_notebook = convo_notebook;
-			if (im_options & OPT_IM_SIDE_TAB) {
-				if (im_options & OPT_IM_BR_TAB) {
-					gtk_notebook_set_tab_pos(GTK_NOTEBOOK(convo_notebook),
-								 GTK_POS_RIGHT);
-				} else {
-					gtk_notebook_set_tab_pos(GTK_NOTEBOOK(convo_notebook),
-								 GTK_POS_LEFT);
-				}
-			} else {
-				if (im_options & OPT_IM_BR_TAB) {
-					gtk_notebook_set_tab_pos(GTK_NOTEBOOK(convo_notebook),
-								 GTK_POS_BOTTOM);
-				} else {
-					gtk_notebook_set_tab_pos(GTK_NOTEBOOK(convo_notebook),
-								 GTK_POS_TOP);
-				}
-			}
-			gtk_notebook_set_scrollable(GTK_NOTEBOOK(convo_notebook), TRUE);
-			gtk_notebook_popup_enable(GTK_NOTEBOOK(convo_notebook));
-
-			testidea = gtk_vbox_new(FALSE, 0);
-			
-			menubar = build_conv_menubar(c);
-			gtk_box_pack_start(GTK_BOX(testidea), menubar, FALSE, TRUE, 0);
-			gtk_box_pack_start(GTK_BOX(testidea), convo_notebook, TRUE, TRUE, 0);
-			gtk_widget_show(testidea);
-			gtk_widget_show(convo_notebook);
-			convo_menubar = menubar;
-
-			gtk_container_add(GTK_CONTAINER(win), testidea);
-			g_signal_connect_after(GTK_OBJECT(convo_notebook), "switch-page",
-					   G_CALLBACK(convo_switch), NULL);
-		} else
-			win = c->window = all_convos;
-
-		cont = gtk_vbox_new(FALSE, 5);
-		gtk_container_set_border_width(GTK_CONTAINER(cont), 5);
-		/* this doesn't matter since we're resetting the name once we're out of the if */
-/*		gtk_notebook_insert_page(GTK_NOTEBOOK(convo_notebook), cont, gtk_label_new(c->name),*/
-		tabby = gtk_hbox_new(FALSE, 5);
-		c->close = gtk_button_new();
-		gtk_widget_set_size_request(GTK_WIDGET(c->close), 16, 16);
-		gtk_container_add(GTK_CONTAINER(c->close), gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU));
-		gtk_button_set_relief(GTK_BUTTON(c->close), GTK_RELIEF_NONE);
-		c->tab_label = gtk_label_new(c->name);
-
-		g_signal_connect(GTK_OBJECT(c->close), "clicked", G_CALLBACK(close_callback), c);
+	struct gaim_conversation *conv;
+	struct gaim_conversation_ops *ops;
+	char tmp[BUF_LONG];
 
-		gtk_box_pack_start(GTK_BOX(tabby), c->tab_label, FALSE, FALSE, 0);
-		gtk_box_pack_start(GTK_BOX(tabby), c->close, FALSE, FALSE, 0);
-		gtk_widget_show_all(tabby);
-		gtk_notebook_insert_page(GTK_NOTEBOOK(convo_notebook), cont, tabby,
-				g_list_index(conversations, c));
-		gtk_notebook_set_menu_label_text(GTK_NOTEBOOK(convo_notebook), cont,
-				c->name);
-
-		gtk_widget_show(cont);
-	} else {
-		cont = win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-		c->window = win;
-		gtk_object_set_user_data(GTK_OBJECT(win), c);
-		gtk_window_set_role(GTK_WINDOW(win), "conversation");
-		gtk_window_set_policy(GTK_WINDOW(win), TRUE, TRUE, TRUE);
-		gtk_container_border_width(GTK_CONTAINER(win), 0);
-		gtk_widget_realize(win);
-		g_signal_connect(GTK_OBJECT(win), "delete_event",
-				   G_CALLBACK(delete_event_convo), c);
-	}
-	set_convo_title(c);
-
-	paned = gtk_vpaned_new();
-	gtk_paned_set_gutter_size(GTK_PANED(paned), 15);
-	gtk_container_add(GTK_CONTAINER(cont), paned);
-	gtk_widget_show(paned);
-
-	vbox = gtk_vbox_new(FALSE, 5);
-	gtk_paned_pack1(GTK_PANED(paned), vbox, FALSE, TRUE);
-	gtk_widget_show(vbox);
-
-	if (!(im_options & OPT_IM_ONE_WINDOW)) {
-		menubar = build_conv_menubar(c);
-		gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
-	}
-
-	sw = gtk_scrolled_window_new(NULL, NULL);
-	c->sw = sw;
-	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
-	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN);
-	gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
-	gtk_widget_set_size_request(sw, conv_size.width, conv_size.height);
-	gtk_widget_show(sw);
-
-	text = gtk_imhtml_new(NULL, NULL);
-	c->text = text;
-	gtk_container_add(GTK_CONTAINER(sw), text);
-	if (convo_options & OPT_CONVO_SHOW_TIME)
-		gtk_imhtml_show_comments(GTK_IMHTML(text), TRUE);
-	else
-		gtk_imhtml_show_comments(GTK_IMHTML(text), FALSE);
-	gaim_setup_imhtml(text);
-	gtk_widget_show(text);
-
-	vbox2 = gtk_vbox_new(FALSE, 5);
-	gtk_paned_pack2(GTK_PANED(paned), vbox2, FALSE, FALSE);
-	gtk_widget_show(vbox2);
-
-	hbox = gtk_hbox_new(FALSE, 0);
-	gtk_box_pack_start(GTK_BOX(vbox2), hbox, FALSE, FALSE, 0);
-	gtk_widget_show(hbox);
-
-	label = gtk_label_new(_("Send message as: "));
-	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
-	gtk_widget_show(label);
+	if (chat == NULL || old_user == NULL || new_user == NULL)
+		return;
 
-	c->menu = gtk_option_menu_new();
-	gtk_box_pack_start(GTK_BOX(hbox), c->menu, FALSE, FALSE, 5);
-	gtk_widget_show(c->menu);
-
-	create_convo_menu(c);
-
-	c->lbox = gtk_hbox_new(FALSE, 0);
-	gtk_box_pack_start(GTK_BOX(vbox2), c->lbox, FALSE, FALSE, 0);
-	gtk_widget_show(c->lbox);
-
-	toolbar = build_conv_toolbar(c);
-	gtk_box_pack_start(GTK_BOX(vbox2), toolbar, FALSE, FALSE, 0);
-
-	frame = gtk_frame_new(NULL);
-	gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
-	gtk_box_pack_start(GTK_BOX(vbox2), frame, TRUE, TRUE, 0);
-	gtk_widget_show(frame);
-	
-	c->entry_buffer = gtk_text_buffer_new(NULL);
-	g_object_set_data(G_OBJECT(c->entry_buffer), "user_data", c);
-	entry = gtk_text_view_new_with_buffer(c->entry_buffer);
-	c->entry = entry;
-
-	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(c->entry), GTK_WRAP_WORD);
+	conv = gaim_chat_get_conversation(chat);
+	ops  = gaim_conversation_get_ops(conv);
 
-	gtk_widget_set_size_request(entry, conv_size.width - 20, MAX(conv_size.entry_height, 25));
-			
-	g_signal_connect_swapped(G_OBJECT(c->entry), "key_press_event",
-				 G_CALLBACK(entry_key_pressed), c->entry_buffer);
-	g_signal_connect(G_OBJECT(c->entry), "key_press_event", G_CALLBACK(keypress_callback), c);
-	g_signal_connect_after(G_OBJECT(c->entry), "button_press_event", 
-			       G_CALLBACK(stop_rclick_callback), NULL);
-	g_signal_connect(G_OBJECT(c->entry_buffer), "insert_text",
-			   G_CALLBACK(insert_text_callback), c);
-	g_signal_connect(G_OBJECT(c->entry_buffer), "delete_range",
-			   G_CALLBACK(delete_text_callback), c);
-
-#ifdef USE_GTKSPELL
-	if (convo_options & OPT_CONVO_CHECK_SPELLING)
-		gtkspell_new_attach(GTK_TEXT_VIEW(c->entry), NULL, NULL);
-#endif
-
-	gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(entry));
-	gtk_widget_show(entry);
-
-	c->bbox = bbox = gtk_hbox_new(FALSE, 5);
-	gtk_box_pack_start(GTK_BOX(vbox2), bbox, FALSE, FALSE, 0);
-	gtk_widget_show(bbox);
-
-/* I'm leaving this here just incase we want to bring this back. I'd rather not have the close
- * button any more.  If we do, though, it needs to be on the left side.  I might bring it back and put
- * it on that side.  */
-
-/*	
-	close = picture_button2(win, _("Close"), cancel_xpm, dispstyle);
-	c->close = close;
-	gtk_object_set_user_data(GTK_OBJECT(close), c);
-	g_signal_connect(GTK_OBJECT(close), "clicked", G_CALLBACK(close_callback), c);
-	gtk_box_pack_end(GTK_BOX(bbox), close, dispstyle, dispstyle, 0);
-	gtk_widget_show(close);
-	
-	c->sep1 = gtk_vseparator_new();
-	gtk_box_pack_end(GTK_BOX(bbox), c->sep1, dispstyle, dispstyle, 0);
-	gtk_widget_show(c->sep1);
-*/	
+	gaim_chat_set_users(chat,
+		g_list_insert_sorted(gaim_chat_get_users(chat), g_strdup(new_user),
+							 insertname_compare));
 
-	/* Put the send button on the right */
-	send = gaim_pixbuf_button_from_stock(
-				(dispstyle == 0 ? NULL : _("Send")),
-				(dispstyle == 1 ? NULL : "gtk-convert"),
-				GAIM_BUTTON_VERTICAL);
-	c->send = send;
-	g_signal_connect(GTK_OBJECT(send), "clicked", G_CALLBACK(send_callback), c);
-	gtk_box_pack_end(GTK_BOX(bbox), send, FALSE, FALSE, 0);
-	gtk_widget_show(send);
-
-	c->sep2 = gtk_vseparator_new();
-	gtk_box_pack_end(GTK_BOX(bbox), c->sep2, FALSE, TRUE, 0);
-	gtk_widget_show(c->sep2);
-	
-	/* And put the other buttons on the left */
-
-	if (c->gc && find_buddy(c->gc->user, c->name) != NULL) {
-		add = gaim_pixbuf_button_from_stock(
-				(dispstyle == 0 ? NULL : _("Remove")),
-				(dispstyle == 1 ? NULL : "gtk-remove"),
-				GAIM_BUTTON_VERTICAL);
-		gtk_object_set_user_data(GTK_OBJECT(add), c);
-	} else
-		add = gaim_pixbuf_button_from_stock(
-				(dispstyle == 0 ? NULL : _("Add")),
-				(dispstyle == 1 ? NULL : "gtk-add"),
-				GAIM_BUTTON_VERTICAL);
-
-	c->add = add;
-	g_signal_connect(GTK_OBJECT(add), "clicked", G_CALLBACK(add_callback), c);
-	gtk_box_pack_start(GTK_BOX(bbox), add, FALSE, FALSE, 0);
-	gtk_widget_show(add);
-
-	warn = gaim_pixbuf_button_from_stock(
-				(dispstyle == 0 ? NULL : _("Warn")),
-				(dispstyle == 1 ? NULL : "gtk-dialog-warning"),
-				GAIM_BUTTON_VERTICAL);
-	c->warn = warn;
-	g_signal_connect(GTK_OBJECT(warn), "clicked", G_CALLBACK(warn_callback), c);
-	gtk_box_pack_start(GTK_BOX(bbox), warn, FALSE, FALSE, 0);
-	gtk_widget_show(warn);
-
-	info = gaim_pixbuf_button_from_stock(
-				(dispstyle == 0 ? NULL : _("Info")),
-				(dispstyle == 1 ? NULL : "gtk-find"),
-				GAIM_BUTTON_VERTICAL);
-	c->info = info;
-	g_signal_connect(GTK_OBJECT(info), "clicked", G_CALLBACK(info_callback), c);
-	gtk_box_pack_start(GTK_BOX(bbox), info, FALSE, FALSE, 0);
-	gtk_widget_show(info);
-
-
-	block = gaim_pixbuf_button_from_stock(
-				(dispstyle == 0 ? NULL : _("Block")),
-				(dispstyle == 1 ? NULL : "gtk-stop"),
-				GAIM_BUTTON_VERTICAL);
-	c->block = block;
-	g_signal_connect(GTK_OBJECT(block), "clicked", G_CALLBACK(block_callback), c);
-	gtk_box_pack_start(GTK_BOX(bbox), block, FALSE, FALSE, 0);
-	gtk_widget_show(block);
+	if (ops != NULL && ops->chat_rename_user != NULL)
+		ops->chat_rename_user(conv, old_user, new_user);
 
-	/* I don't know if these should have borders.  They look kind of dumb
-	 * with borders.  */
-	gtk_button_set_relief(GTK_BUTTON(info), GTK_RELIEF_NONE);
-	gtk_button_set_relief(GTK_BUTTON(add), GTK_RELIEF_NONE);
-	gtk_button_set_relief(GTK_BUTTON(warn), GTK_RELIEF_NONE);
-	gtk_button_set_relief(GTK_BUTTON(send), GTK_RELIEF_NONE);
-	gtk_button_set_relief(GTK_BUTTON(block), GTK_RELIEF_NONE);
-
-	gtk_size_group_add_widget(c->sg, info);
-	gtk_size_group_add_widget(c->sg, add);
-	gtk_size_group_add_widget(c->sg, warn);
-	gtk_size_group_add_widget(c->sg, send);
-	gtk_size_group_add_widget(c->sg, block);
-
-	gtk_box_reorder_child(GTK_BOX(bbox), c->warn, 1);
-	gtk_box_reorder_child(GTK_BOX(bbox), c->block, 2);
-	gtk_box_reorder_child(GTK_BOX(bbox), c->add, 3);
-	gtk_box_reorder_child(GTK_BOX(bbox), c->info, 4);
-
-
-	update_buttons_by_protocol(c);
-
-	gtk_widget_show(win);
-	if (!(im_options & OPT_IM_ONE_WINDOW)
-			|| ((gtk_notebook_get_current_page(GTK_NOTEBOOK(convo_notebook)) == 0)
-				&& (c == g_list_nth_data(conversations, 0))))
-		gtk_widget_grab_focus(c->entry);
-}
-
-
-void toggle_spellchk()
-{
-#ifdef USE_GTKSPELL
-	GList *cnv = conversations;
-	GSList *cht;
-	struct conversation *c;
-	GSList *con = connections;
-	struct gaim_connection *gc;
-	GtkSpell *spell;
-	
-	while (cnv) {
-		c = (struct conversation *)cnv->data;
-		if (convo_options & OPT_CONVO_CHECK_SPELLING) {
-			gtkspell_new_attach(GTK_TEXT_VIEW(c->entry), NULL, NULL);
-		} else {
-			spell = gtkspell_get_from_text_view(GTK_TEXT_VIEW(c->entry));
-			gtkspell_detach(spell);
-		}
-		cnv = cnv->next;
-	}
-
-	while (con) {
-		gc = (struct gaim_connection *)con->data;
-		cht = gc->buddy_chats;
-		while (cht) {
-			c = (struct conversation *)cht->data;
-			if (convo_options & OPT_CONVO_CHECK_SPELLING) {
-				gtkspell_new_attach(GTK_TEXT_VIEW(c->entry), NULL, NULL);
-			} else {
-				spell = gtkspell_get_from_text_view(GTK_TEXT_VIEW(c->entry));
-				gtkspell_detach(spell);
-			}
-			cht = cht->next;
-		}
-		con = con->next;
-	}
-#endif
-}
+	gaim_chat_set_users(chat, g_list_remove(gaim_chat_get_users(chat),
+											old_user));
 
-void toggle_timestamps()
-{
-	GList *cnv = conversations;
-	GSList *cht;
-	struct conversation *c;
-	GSList *con = connections;
-	struct gaim_connection *gc;
-
-	while (cnv) {
-		c = (struct conversation *)cnv->data;
-		if (convo_options & OPT_CONVO_SHOW_TIME)
-			gtk_imhtml_show_comments(GTK_IMHTML(c->text), TRUE);
-		else
-			gtk_imhtml_show_comments(GTK_IMHTML(c->text), FALSE);
-		cnv = cnv->next;
-	}
-
-	while (con) {
-		gc = (struct gaim_connection *)con->data;
-		cht = gc->buddy_chats;
-		while (cht) {
-			c = (struct conversation *)cht->data;
-			if (convo_options & OPT_CONVO_SHOW_TIME)
-				gtk_imhtml_show_comments(GTK_IMHTML(c->text), TRUE);
-			else
-				gtk_imhtml_show_comments(GTK_IMHTML(c->text), FALSE);
-			cht = cht->next;
-		}
-		con = con->next;
+	if (gaim_chat_is_user_ignored(chat, old_user)) {
+		gaim_chat_unignore(chat, old_user);
+		gaim_chat_ignore(chat, new_user);
 	}
-}
-
-void toggle_smileys()
-{
-	GList *cnv = conversations;
-	GSList *cht;
-	struct conversation *c;
-	GSList *con = connections;
-	struct gaim_connection *gc;
-
-	while (cnv) {
-		c = (struct conversation *)cnv->data;
-		if (convo_options & OPT_CONVO_SHOW_SMILEY)
-			gtk_imhtml_show_smileys(GTK_IMHTML(c->text), TRUE);
-		else
-			gtk_imhtml_show_smileys(GTK_IMHTML(c->text), FALSE);
-		cnv = cnv->next;
-	}
-
-	while (con) {
-		gc = (struct gaim_connection *)con->data;
-		cht = gc->buddy_chats;
-		while (cht) {
-			c = (struct conversation *)cht->data;
-			if (convo_options & OPT_CONVO_SHOW_SMILEY)
-				gtk_imhtml_show_smileys(GTK_IMHTML(c->text), TRUE);
-			else
-				gtk_imhtml_show_smileys(GTK_IMHTML(c->text), FALSE);
-			cht = cht->next;
-		}
-		con = con->next;
-	}
-}
+	else if (gaim_chat_is_user_ignored(chat, new_user))
+		gaim_chat_unignore(chat, new_user);
 
-void im_tabize()
-{
-	/* evil, evil i tell you! evil! */
-	if (im_options & OPT_IM_ONE_WINDOW) {
-		GList *x = conversations;
-		if ((convo_options & OPT_CONVO_COMBINE) && (chat_options & OPT_CHAT_ONE_WINDOW)) {
-			all_convos = all_chats;
-			convo_notebook = chat_notebook;
-		}
-		while (x) {
-			struct conversation *c = x->data;
-			GtkWidget *imhtml, *win;
-
-			imhtml = c->text;
-			win = c->window;
-			remove_icon(c);
-			remove_checkbox(c);
-			show_conv(c);
-			gtk_widget_destroy(c->text);
-			gtk_widget_reparent(imhtml, c->sw);
-			c->text = imhtml;
-			gtk_widget_destroy(win);
-			update_icon(c);
-			update_checkbox(c);
-			set_convo_title(c);
+	if (chat_options & OPT_CHAT_LOGON) {
+		g_snprintf(tmp, sizeof(tmp),
+				   _("%s is now known as %s"), old_user, new_user);
 
-			x = x->next;
-		}
-	} else {
-		GList *x, *m;
-		x = m = conversations;
-		conversations = NULL;
-		while (x) {
-			struct conversation *c = x->data;
-			GtkWidget *imhtml;
-
-			imhtml = c->text;
-			remove_icon(c);
-			remove_checkbox(c);
-			show_conv(c);
-			gtk_container_remove(GTK_CONTAINER(c->sw), c->text);
-			gtk_widget_reparent(imhtml, c->sw);
-			c->text = imhtml;
-			update_icon(c);
-			update_checkbox(c);
-			set_convo_title(c);
-
-			x = x->next;
-		}
-		conversations = m;
-		if ((convo_options & OPT_CONVO_COMBINE) && (chat_options & OPT_CHAT_ONE_WINDOW)) {
-			if (chats) {
-				struct conversation *c;
-				while (m) {
-					gtk_notebook_remove_page(GTK_NOTEBOOK(chat_notebook), 0);
-					m = m->next;
-				}
-				c = chats->data;
-				gtk_widget_grab_focus(c->entry);
-			} else {
-				if (all_convos)
-					gtk_widget_destroy(all_convos);
-				all_chats = NULL;
-				chat_notebook = NULL;
-			}
-		} else if (all_convos)
-			gtk_widget_destroy(all_convos);
-		all_convos = NULL;
-		convo_notebook = NULL;
+		gaim_conversation_write(conv, NULL, tmp, -1, WFLAG_SYSTEM, time(NULL));
 	}
 }
 
-void convo_tabize()
+void
+gaim_chat_remove_user(struct gaim_chat *chat, const char *user,
+					  const char *reason)
 {
-	GList *x, *m;
-	GtkWidget *tmp;
+	struct gaim_conversation *conv;
+	struct gaim_conversation_ops *ops;
+	char tmp[BUF_LONG];
+	GList *names;
 
-	if (!chats && !conversations)
+	if (chat == NULL || user == NULL)
 		return;
 
-	if (convo_options & OPT_CONVO_COMBINE) {
-		if (!chats) {
-			all_chats = all_convos;
-			chat_notebook = convo_notebook;
-			return;
-		} else if (!conversations) {
-			all_convos = all_chats;
-			convo_notebook = chat_notebook;
-			return;
-		}
-	} else {
-		if (!chats) {
-			all_chats = NULL;
-			chat_notebook = NULL;
-			return;
-		} else if (!conversations) {
-			all_convos = NULL;
-			convo_notebook = NULL;
-			return;
+	conv = gaim_chat_get_conversation(chat);
+	ops  = gaim_conversation_get_ops(conv);
+
+	plugin_event(event_chat_buddy_leave, gaim_conversation_get_gc(conv),
+				 gaim_chat_get_id(chat), user);
+
+	if (ops != NULL && ops->chat_remove_user != NULL)
+		ops->chat_remove_user(conv, user);
+
+	for (names = gaim_chat_get_users(chat);
+		 names != NULL;
+		 names = names->next) {
+
+		if (!g_strcasecmp((char *)names->data, user)) {
+			gaim_chat_set_users(chat,
+					g_list_remove(gaim_chat_get_users(chat), names->data));
+			break;
 		}
 	}
 
-	tmp = all_convos;
-	if (convo_options & OPT_CONVO_COMBINE) {
-		all_convos = all_chats;
-		convo_notebook = chat_notebook;
-	} else {
-		all_convos = NULL;
-		convo_notebook = NULL;
-	}
-	x = m = conversations;
-	while (x) {
-		struct conversation *c = x->data;
-		GtkWidget *imhtml;
-
-		imhtml = c->text;
-		remove_icon(c);
-		remove_checkbox(c);
-		show_conv(c);
-		gtk_container_remove(GTK_CONTAINER(c->sw), c->text);
-		gtk_widget_reparent(imhtml, c->sw);
-		c->text = imhtml;
-		update_icon(c);
-		update_checkbox(c);
-
-		x = x->next;
-	}
-
-	conversations = m;
-	if (convo_options & OPT_CONVO_COMBINE) {
-		if (tmp)
-			gtk_widget_destroy(tmp);
-	} else {
-		while (m) {
-			gtk_notebook_remove_page(GTK_NOTEBOOK(chat_notebook), 0);
-			m = m->next;
-		}
-	}
-	m = conversations;
-	while (m) {
-		set_convo_title(m->data);
-		m = m->next;
-	}
-}
-
-void set_convo_title(struct conversation *c)
-{
-	struct buddy *b;
-	char *text;
-	int index;
-	GtkNotebook *nb;
-
-	if ((im_options & OPT_IM_ALIAS_TAB) && c->gc && ((b = find_buddy(c->gc->user, c->name)) != NULL))
-		text = get_buddy_alias(b);
-	else
-		text = c->name;
-
-	if (im_options & OPT_IM_ONE_WINDOW) {
-		nb = GTK_NOTEBOOK(convo_notebook);
-		index = g_list_index(conversations, c);
-		gtk_label_set_text(GTK_LABEL(c->tab_label), text);
-	} else {
-		char buf[256];
-		if ((find_log_info(c->name)) || (c->is_chat && (logging_options & OPT_LOG_CHATS))
-				|| (!c->is_chat && (logging_options & OPT_LOG_CONVOS)))
-			g_snprintf(buf, sizeof(buf), LOG_CONVERSATION_TITLE, text);
-		else
-			g_snprintf(buf, sizeof(buf), CONVERSATION_TITLE, text);
-		gtk_window_set_title(GTK_WINDOW(c->window), buf);
-	}
-}
+	/* NOTE: Don't remove them from ignored in case they re-enter. */
 
-void set_convo_titles()
-{
-	GList *c = conversations;
-	while (c) {
-		set_convo_title(c->data);
-		c = c->next;
-	}
-}
-
-void raise_convo_tab(struct conversation *c)
-{
-	gtk_notebook_set_page(GTK_NOTEBOOK(convo_notebook), g_list_index(conversations, c));
-	gdk_window_show(c->window->window);
-}
-
-void update_im_tabs()
-{
-	if (!convo_notebook || !all_convos)
-		return;
-	if (im_options & OPT_IM_SIDE_TAB) {
-		if (im_options & OPT_IM_BR_TAB) {
-			gtk_notebook_set_tab_pos(GTK_NOTEBOOK(convo_notebook), GTK_POS_RIGHT);
-		} else {
-			gtk_notebook_set_tab_pos(GTK_NOTEBOOK(convo_notebook), GTK_POS_LEFT);
-		}
-	} else {
-		if (im_options & OPT_IM_BR_TAB) {
-			gtk_notebook_set_tab_pos(GTK_NOTEBOOK(convo_notebook), GTK_POS_BOTTOM);
-		} else {
-			gtk_notebook_set_tab_pos(GTK_NOTEBOOK(convo_notebook), GTK_POS_TOP);
-		}
-	}
-}
+	if (chat_options & OPT_CHAT_LOGON) {
+		if (reason != NULL && *reason != '\0')
+			g_snprintf(tmp, sizeof(tmp),
+					   _("%s left the room (%s)."), user, reason);
+		else
+			g_snprintf(tmp, sizeof(tmp), _("%s left the room."), user);
 
-void update_chat_tabs()
-{
-	if (!chat_notebook || !all_chats)
-		return;
-	if (chat_options & OPT_CHAT_SIDE_TAB) {
-		if (chat_options & OPT_CHAT_BR_TAB) {
-			gtk_notebook_set_tab_pos(GTK_NOTEBOOK(chat_notebook), GTK_POS_RIGHT);
-		} else {
-			gtk_notebook_set_tab_pos(GTK_NOTEBOOK(chat_notebook), GTK_POS_LEFT);
-		}
-	} else {
-		if (chat_options & OPT_CHAT_BR_TAB) {
-			gtk_notebook_set_tab_pos(GTK_NOTEBOOK(chat_notebook), GTK_POS_BOTTOM);
-		} else {
-			gtk_notebook_set_tab_pos(GTK_NOTEBOOK(chat_notebook), GTK_POS_TOP);
-		}
-	}
-}
-
-void update_convo_color(gboolean fg)
-{
-	GList *c = conversations;
-	struct conversation *b;
-
-	while (c) {
-		b = c->data;
-		c = c->next;
-		if (fg) {
-			if (b->hasfg)
-				continue;
-			b->fgcol = fgcolor;
-		} else {
-			if (b->hasbg)
-				continue;
-			b->bgcol = bgcolor;
-		}
-	}
-}
-
-void update_convo_font()
-{
-	GList *c = conversations;
-	struct conversation *b;
-
-	while (c) {
-		b = c->data;
-		c = c->next;
-		if (b->hasfont)
-			continue;
-		sprintf(b->fontface, "%s", fontface);
+		gaim_conversation_write(conv, NULL, tmp, -1, WFLAG_SYSTEM, time(NULL));
 	}
 }
 
-#include <gdk-pixbuf/gdk-pixbuf.h>
-
-#define SCALE(x) ((gdk_pixbuf_animation_get_width(x) <= 48 && gdk_pixbuf_animation_get_height(x) <= 48) \
-		 ? 48 : 50)
-
-static gboolean redraw_icon(gpointer data)
+struct gaim_conversation *
+gaim_find_chat(struct gaim_connection *gc, int id)
 {
-	struct conversation *c = data;
-
-	GdkPixbuf *buf;
-	GdkPixbuf *scale;
-	GdkPixmap *pm;
-	GdkBitmap *bm;
-	gint delay;
-
-	if (!g_list_find(conversations, c)) {
-		debug_printf("I think this is a bug.\n");
-		return FALSE;
-	}
-
-	gdk_pixbuf_animation_iter_advance(c->iter, NULL);
-	buf = gdk_pixbuf_animation_iter_get_pixbuf(c->iter);
-	scale = gdk_pixbuf_scale_simple(buf,
-					MAX(gdk_pixbuf_get_width(buf) * SCALE(c->anim) /
-					    gdk_pixbuf_animation_get_width(c->anim), 1),
-					MAX(gdk_pixbuf_get_height(buf) * SCALE(c->anim) /
-					    gdk_pixbuf_animation_get_height(c->anim), 1),
-					GDK_INTERP_NEAREST);
-	gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100);
-	gdk_pixbuf_unref(scale);
-	gtk_pixmap_set(GTK_PIXMAP(c->icon), pm, bm);
-	gdk_pixmap_unref(pm);
-	gtk_widget_queue_draw(c->icon);
-	if (bm)
-		gdk_bitmap_unref(bm);
-	delay = gdk_pixbuf_animation_iter_get_delay_time(c->iter) / 10;
-
-	c->icon_timer = g_timeout_add(delay * 10, redraw_icon, c);
-	return FALSE;
-}
-
-static void stop_anim(GtkObject *obj, struct conversation *c)
-{
-	if (c->icon_timer)
-		g_source_remove(c->icon_timer);
-	c->icon_timer = 0;
-}
-
-static void start_anim(GtkObject *obj, struct conversation *c)
-{
-	int delay;
-	delay = gdk_pixbuf_animation_iter_get_delay_time(c->iter) / 10;
-	if (c->anim)
-	    c->icon_timer = g_timeout_add(delay * 10, redraw_icon, c);
-}
-
-static int des_save_icon(GtkObject *obj, GdkEvent *e, struct conversation *c)
-{
-	gtk_widget_destroy(c->save_icon);
-	c->save_icon = NULL;
-	return TRUE;
-}
-
-static void do_save_icon(GtkObject *obj, struct conversation *c)
-{
-	FILE *file;
-	const char *f = gtk_file_selection_get_filename(GTK_FILE_SELECTION(c->save_icon));
-	if (file_is_dir(f, c->save_icon))
-		return;
+	GList *l;
+	struct gaim_conversation *conv;
 
-	file = fopen(f, "w");
-	if (file) {
-		int len;
-		void *data = get_icon_data(c->gc, normalize(c->name), &len);
-		if (data)
-			fwrite(data, 1, len, file);
-		fclose(file);
-	} else {
-		do_error_dialog("Can't save icon file to disk", strerror(errno), GAIM_ERROR);
-	}
-
-	gtk_widget_destroy(c->save_icon);
-	c->save_icon = NULL;
-}
-
-static void cancel_save_icon(GtkObject *obj, struct conversation *c)
-{
-	gtk_widget_destroy(c->save_icon);
-	c->save_icon = NULL;
-}
-
-static void save_icon(GtkObject *obj, struct conversation *c)
-{
-	char buf[BUF_LEN];
-
-	if (c->save_icon) {
-		gdk_window_raise(c->save_icon->window);
-		return;
-	}
+	for (l = gaim_get_chats(); l != NULL; l = l->next) {
+		conv = (struct gaim_conversation *)l->data;
 
-	c->save_icon = gtk_file_selection_new(_("Gaim - Save Icon"));
-	gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(c->save_icon));
-	g_snprintf(buf, BUF_LEN - 1, "%s" G_DIR_SEPARATOR_S "%s.icon", gaim_home_dir(), c->name);
-	gtk_file_selection_set_filename(GTK_FILE_SELECTION(c->save_icon), buf);
-	g_signal_connect(GTK_OBJECT(c->save_icon), "delete_event",
-			   G_CALLBACK(des_save_icon), c);
-	g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(c->save_icon)->ok_button), "clicked",
-			   G_CALLBACK(do_save_icon), c);
-	g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(c->save_icon)->cancel_button), "clicked",
-			   G_CALLBACK(cancel_save_icon), c);
-
-	gtk_widget_show(c->save_icon);
-}
-
-static gboolean icon_menu(GtkObject *obj, GdkEventButton *e, struct conversation *c)
-{
-	static GtkWidget *menu = NULL;
-	GtkWidget *button;
-
-	if (e->button != 3)
-		return FALSE;
-	if (e->type != GDK_BUTTON_PRESS)
-		return FALSE;
-
-	/*
-	 * If a menu already exists, destroy it before creating a new one,
-	 * thus freeing-up the memory it occupied.
-	 */
-	if(menu)
-		gtk_widget_destroy(menu);
-
-	menu = gtk_menu_new();
-
-	if (c->icon_timer) {
-		button = gtk_menu_item_new_with_label(_("Disable Animation"));
-		g_signal_connect(GTK_OBJECT(button), "activate", G_CALLBACK(stop_anim), c);
-		gtk_menu_shell_append(GTK_MENU_SHELL(menu), button);
-		gtk_widget_show(button);
-	}
-	 else if (c->anim && !(gdk_pixbuf_animation_is_static_image(c->anim))) 
-	{
-		button = gtk_menu_item_new_with_label(_("Enable Animation"));
-		g_signal_connect(GTK_OBJECT(button), "activate", G_CALLBACK(start_anim), c);
-		gtk_menu_shell_append(GTK_MENU_SHELL(menu), button);
-		gtk_widget_show(button);
+		if (gaim_chat_get_id(GAIM_CHAT(conv)) == id &&
+			gaim_conversation_get_gc(conv) == gc)
+			return conv;
 	}
 
-	button = gtk_menu_item_new_with_label(_("Hide Icon"));
-	g_signal_connect_swapped(GTK_OBJECT(button), "activate",
-				  G_CALLBACK(remove_icon), (void *)c);
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu), button);
-	gtk_widget_show(button);
-
-	button = gtk_menu_item_new_with_label(_("Save Icon As..."));
-	g_signal_connect(GTK_OBJECT(button), "activate", G_CALLBACK(save_icon), c);
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu), button);
-	gtk_widget_show(button);
-
-	gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, e->button, e->time);
-
-	return TRUE;
-}
-
-void remove_icon(struct conversation *c)
-{
-	if (c->icon)
-		gtk_container_remove(GTK_CONTAINER(c->bbox), c->icon->parent->parent);
-	c->icon = NULL;
-	if (c->anim)
-		gdk_pixbuf_animation_unref(c->anim);
-	c->anim = NULL;
-	if (c->icon_timer)
-		g_source_remove(c->icon_timer);
-	c->icon_timer = 0;
-	if(c->iter)
-		g_object_unref(G_OBJECT(c->iter));
+	return NULL;
 }
-
-void update_icon(struct conversation *c)
-{
-	char filename[256];
-	FILE *file;
-	GError *err = NULL;
-
-	void *data;
-	int len, delay;
-
-	GdkPixbuf *buf;
-
-	GtkWidget *event;
-	GtkWidget *frame;
-	GdkPixbuf *scale;
-	GdkPixmap *pm;
-	GdkBitmap *bm;
-	int sf = 0;
-
-	if (!c)
-		return;
-
-	remove_icon(c);
-
-	if (im_options & OPT_IM_HIDE_ICONS)
-		return;
-
-	if (!c->gc)
-		return;
-
-	data = get_icon_data(c->gc, normalize(c->name), &len);
-	if (!data)
-		return;
-
-	/* this is such an evil hack, i don't know why i'm even considering it.
-	 * we'll do it differently when gdk-pixbuf-loader isn't leaky anymore. */
-	g_snprintf(filename, sizeof(filename), "%s" G_DIR_SEPARATOR_S "gaimicon-%s.%d", g_get_tmp_dir(), c->name, getpid());
-	file = fopen(filename, "w");
-	if (!file)
-		return;
-	fwrite(data, 1, len, file);
-	fclose(file);
-
-	c->anim = gdk_pixbuf_animation_new_from_file(filename, &err);
-	if (err) {
-		debug_printf("Buddy icon error: %s\n", err->message);
-		g_error_free(err);
-	}
-	/* make sure we remove the file as soon as possible */
-	unlink(filename);
-
-	if (!c->anim)
-		return;
-
-	if (gdk_pixbuf_animation_is_static_image(c->anim)) {
-		c->iter = NULL;
-		delay = 0;
-		buf = gdk_pixbuf_animation_get_static_image(c->anim);
-	} else {
-		c->iter = gdk_pixbuf_animation_get_iter(c->anim, NULL);
-		buf = gdk_pixbuf_animation_iter_get_pixbuf(c->iter);
-		delay = gdk_pixbuf_animation_iter_get_delay_time(c->iter);
-		delay = delay / 10;
-	}
-		sf = SCALE(c->anim);
-		scale = gdk_pixbuf_scale_simple(buf,
-						MAX(gdk_pixbuf_get_width(buf) * sf /
-						    gdk_pixbuf_animation_get_width(c->anim), 1),
-						MAX(gdk_pixbuf_get_height(buf) * sf /
-						    gdk_pixbuf_animation_get_height(c->anim), 1),
-						GDK_INTERP_NEAREST);
-	
-	if (delay)
-		c->icon_timer = g_timeout_add(delay * 10, redraw_icon, c);
-	
-
-	gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100);
-	gdk_pixbuf_unref(scale);
-
-	frame = gtk_frame_new(NULL);
-	gtk_frame_set_shadow_type(GTK_FRAME(frame), bm ? GTK_SHADOW_NONE : GTK_SHADOW_IN);
-	gtk_box_pack_start(GTK_BOX(c->bbox), frame, FALSE, FALSE, 5);
-	gtk_box_reorder_child(GTK_BOX(c->bbox), frame, 0);
-	gtk_widget_show(frame);
-
-	event = gtk_event_box_new();
-	gtk_container_add(GTK_CONTAINER(frame), event);
-	g_signal_connect(GTK_OBJECT(event), "button-press-event", G_CALLBACK(icon_menu), c);
-	gtk_widget_show(event);
-
-	c->icon = gtk_pixmap_new(pm, bm);
-	gtk_widget_set_size_request(c->icon, sf, sf);
-	gtk_container_add(GTK_CONTAINER(event), c->icon);
-	gtk_widget_show(c->icon);
-	if(im_options & OPT_IM_NO_ANIMATION)
-		stop_anim(NULL, c);		
-	gdk_pixmap_unref(pm);
-	if (bm)
-		gdk_bitmap_unref(bm);
-}
-
-void got_new_icon(struct gaim_connection *gc, char *who)
-{
-	struct conversation *c = find_conversation(who);
-	if (c && (c->gc == gc))
-		update_icon(c);
-}
-
-void set_hide_icons()
-{
-	GList *c = conversations;
-	while (c) {
-		update_icon(c->data);
-		c = c->next;
-	}
-}
-
-void set_anim()
-{
-	GList *c = conversations;
-	if (im_options & OPT_IM_HIDE_ICONS)
-		return;
-	while (c) {
-		if(im_options & OPT_IM_NO_ANIMATION)
-			stop_anim(NULL, c->data);
-		else 
-			start_anim(NULL, c->data);
-		c = c->next;
-	}
-}
-
-static void remove_checkbox(struct conversation *c)
-{
-	if (c->check)
-		gtk_container_remove(GTK_CONTAINER(c->lbox), c->check);
-	c->check = NULL;
-}
-
-static void update_checkbox(struct conversation *c)
-{
-	if (!c)
-		return;
-
-	remove_checkbox(c);
-
-	if (!c->gc)
-		return;
-
-	if (!c->gc->checkbox)
-		return;
-
-	c->check = gtk_check_button_new_with_label(c->gc->checkbox);
-	gtk_box_pack_start(GTK_BOX(c->lbox), c->check, FALSE, FALSE, 5);
-	gtk_widget_show(c->check);
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/conversation.h	Mon Jan 20 09:10:23 2003 +0000
@@ -0,0 +1,1066 @@
+/**
+ * @file conversation.h Conversation API
+ *
+ * gaim
+ *
+ * Copyright (C) 2002-2003, Christian Hammond <chipx86@gnupdate.org>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef _CONVERSATION_H_
+#define _CONVERSATION_H_
+
+/**************************************************************************/
+/** Data Structures                                                       */
+/**************************************************************************/
+
+typedef enum _GaimConversationType GaimConversationType;
+typedef enum _GaimUnseenState      GaimUnseenState;
+typedef enum _GaimConvUpdateType   GaimConvUpdateType;
+struct gaim_window_ops;
+struct gaim_window;
+struct gaim_conversation;
+struct gaim_im;
+struct gaim_chat;
+
+/**
+ * A type of conversation.
+ */
+enum _GaimConversationType
+{
+	GAIM_CONV_UNKNOWN = 0, /**< Unknown conversation type. */
+	GAIM_CONV_IM,          /**< Instant Message.           */
+	GAIM_CONV_CHAT         /**< Chat room.                 */
+};
+
+/**
+ * Unseen text states.
+ */
+enum _GaimUnseenState
+{
+	GAIM_UNSEEN_NONE = 0,  /**< No unseen text in the conversation. */
+	GAIM_UNSEEN_TEXT,      /**< Unseen text in the conversation.    */
+	GAIM_UNSEEN_NICK,      /**< Unseen text and the nick was said.  */
+};
+
+/**
+ * Conversation update type.
+ */
+enum _GaimConvUpdateType
+{
+	GAIM_CONV_UPDATE_ADD = 0, /**< The buddy associated with the conversation
+							       was added.   */
+	GAIM_CONV_UPDATE_REMOVE,  /**< The buddy associated with the conversation
+								   was removed. */
+	GAIM_CONV_UPDATE_USER,    /**< The aim_user was changed. */
+	GAIM_CONV_UPDATE_TYPING,  /**< The typing state was updated. */
+	GAIM_CONV_UPDATE_UNSEEN,  /**< The unseen state was updated. */
+	GAIM_CONV_UPDATE_LOGGING, /**< Logging for this conversation was
+								   enabled or disabled. */
+	GAIM_CONV_UPDATE_TOPIC,   /**< The topic for a chat was updated. */
+
+	/*
+	 * XXX These need to go when we implement a more generic core/UI event
+	 * system.
+	 */
+	GAIM_CONV_ACCOUNT_ONLINE, /**< One of the user's accounts went online.  */
+	GAIM_CONV_ACCOUNT_OFFLINE /**< One of the user's accounts went offline. */
+};
+
+/* Yeah, this has to be included here. Ugh. */
+#include "gaim.h"
+
+/**
+ * Conversation window operations.
+ *
+ * Any UI representing a window must assign a filled-out gaim_window_ops
+ * structure to the gaim_window.
+ */
+struct gaim_window_ops
+{
+	struct gaim_conversation_ops *(*get_conversation_ops)(void);
+
+	void (*new_window)(struct gaim_window *win);
+	void (*destroy_window)(struct gaim_window *win);
+
+	void (*show)(struct gaim_window *win);
+	void (*hide)(struct gaim_window *win);
+	void (*raise)(struct gaim_window *win);
+	void (*flash)(struct gaim_window *win);
+
+	void (*switch_conversation)(struct gaim_window *win, unsigned int index);
+	void (*add_conversation)(struct gaim_window *win,
+							 struct gaim_conversation *conv);
+	void (*remove_conversation)(struct gaim_window *win,
+								struct gaim_conversation *conv);
+	void (*move_conversation)(struct gaim_window *win,
+							  struct gaim_conversation *conv,
+							  unsigned int newIndex);
+	int (*get_active_index)(const struct gaim_window *win);
+};
+
+/**
+ * Conversation operations and events.
+ *
+ * Any UI representing a conversation must assign a filled-out
+ * gaim_conversation_ops structure to the gaim_conversation.
+ */
+struct gaim_conversation_ops
+{
+	void (*destroy_conversation)(struct gaim_conversation *conv);
+	void (*write_chat)(struct gaim_conversation *conv, const char *who,
+					   const char *message, int flags, time_t mtime);
+	void (*write_im)(struct gaim_conversation *conv, const char *who,
+					 const char *message, size_t len, int flags, time_t mtime);
+	void (*write_conv)(struct gaim_conversation *conv, const char *who,
+					   const char *message, size_t length, int flags,
+					   time_t mtime);
+
+	void (*chat_add_user)(struct gaim_conversation *conv, const char *user);
+	void (*chat_rename_user)(struct gaim_conversation *conv,
+							 const char *old_name, const char *new_name);
+	void (*chat_remove_user)(struct gaim_conversation *conv, const char *user);
+
+	void (*set_title)(struct gaim_conversation *conv,
+					  const char *title);
+	void (*update_progress)(struct gaim_conversation *conv, float percent);
+
+	/* Events */
+	void (*updated)(struct gaim_conversation *conv, GaimConvUpdateType type);
+};
+
+/**
+ * A core representation of a graphical window containing one or more
+ * conversations.
+ */
+struct gaim_window
+{
+	GList *conversations;        /**< The conversations in the window. */
+	size_t conversation_count;   /**< The number of conversations.     */
+
+	struct gaim_window_ops *ops; /**< UI-specific window operations.   */
+
+	void *ui_data;               /**< UI-specific data.                */
+};
+
+/**
+ * Data specific to Instant Messages.
+ */
+struct gaim_im
+{
+	struct gaim_conversation *conv;
+
+	int    typing_state;
+	guint  typing_timeout;
+	time_t type_again;
+	guint  type_again_timeout;
+
+	GSList *images;
+};
+
+/**
+ * Data specific to Chats.
+ */
+struct gaim_chat
+{
+	struct gaim_conversation *conv;
+
+	GList *in_room;
+	GList *ignored;
+	char  *who;
+	char  *topic;
+	int    id;
+};
+
+/**
+ * A core representation of a conversation between two or more people.
+ *
+ * The conversation can be an IM or a chat. Each conversation is kept
+ * in a gaim_window and has a UI representation.
+ */
+struct gaim_conversation
+{
+	GaimConversationType type;  /**< The type of conversation.          */
+
+	struct aim_user *user;      /**< The user using this conversation.  */
+	struct gaim_window *window; /**< The parent window.                 */
+
+	/** UI-specific conversation operations.*/
+	struct gaim_conversation_ops *ops; 
+
+	int conversation_pos;       /**< The position in the window's list. */
+
+	char *name;                 /**< The name of the conversation.      */
+	char *title;                /**< The window title.                  */
+
+	gboolean logging;           /**< The status of logging.             */
+
+	GList *send_history;        /**< The send history.                  */
+	GString *history;           /**< The conversation history.          */
+
+	GaimUnseenState unseen;     /**< The unseen tab state.              */
+
+	void *ui_data;              /**< UI-specific data.                  */
+
+	union
+	{
+		struct gaim_im   *im;   /**< IM-specific data.                  */
+		struct gaim_chat *chat; /**< Chat-specific data.                */
+
+	} u;
+};
+
+
+/**************************************************************************/
+/** @name Conversation Window API                                         */
+/**************************************************************************/
+/*@{*/
+
+/**
+ * Creates a new conversation window.
+ *
+ * This window is added to the list of windows, but is not shown until
+ * gaim_window_show() is called.
+ *
+ * @return The new conversation window.
+ */
+struct gaim_window *gaim_window_new(void);
+
+/**
+ * Destroys the specified conversation window and all conversations in it.
+ *
+ * @param win The window to destroy.
+ */
+void gaim_window_destroy(struct gaim_window *win);
+
+/**
+ * Shows the specified conversation window.
+ *
+ * @param win The window.
+ */
+void gaim_window_show(struct gaim_window *win);
+
+/**
+ * Hides the specified conversation window.
+ *
+ * @param win The window.
+ */
+void gaim_window_hide(struct gaim_window *win);
+
+/**
+ * Raises the specified conversation window.
+ *
+ * @param win The window.
+ */
+void gaim_window_raise(struct gaim_window *win);
+
+/**
+ * Causes the window to flash for IM notification, if the UI supports this.
+ * 
+ * @param win The window.
+ */
+void gaim_window_flash(struct gaim_window *win);
+
+/**
+ * Sets the specified window's UI window operations structure.
+ *
+ * @param win The window.
+ * @param ops The UI window operations structure.
+ */
+void gaim_window_set_ops(struct gaim_window *win,
+						 struct gaim_window_ops *ops);
+
+/**
+ * Returns the specified window's UI window operations structure.
+ *
+ * @param win The window.
+ *
+ * @return The UI window operations structure.
+ */
+struct gaim_window_ops *gaim_window_get_ops(const struct gaim_window *win);
+
+/**
+ * Adds a conversation to this window.
+ *
+ * If the conversation already has a parent window, this will do nothing.
+ *
+ * @param win  The window.
+ * @param conv The conversation.
+ *
+ * @return The new index of the conversation in the window.
+ */
+int gaim_window_add_conversation(struct gaim_window *win,
+								 struct gaim_conversation *conv);
+
+/**
+ * Removes the conversation at the specified index from the window.
+ *
+ * If there is no conversation at this index, this will do nothing.
+ *
+ * @param win   The window.
+ * @param index The index of the conversation.
+ *
+ * @return The conversation removed.
+ */
+struct gaim_conversation *gaim_window_remove_conversation(
+		struct gaim_window *win, unsigned int index);
+
+/**
+ * Moves the conversation at the specified index in a window to a new index.
+ *
+ * @param win      The window.
+ * @param index     The index of the conversation to move.
+ * @param new_index The new index.
+ */
+void gaim_window_move_conversation(struct gaim_window *win,
+								   unsigned int index, unsigned int new_index);
+
+/**
+ * Returns the conversation in the window at the specified index.
+ *
+ * If the index is out of range, this returns @c NULL.
+ *
+ * @param win   The window.
+ * @param index The index containing a conversation.
+ *
+ * @return The conversation at the specified index.
+ */
+struct gaim_conversation *gaim_window_get_conversation_at(
+		const struct gaim_window *win, unsigned int index);
+
+/**
+ * Returns the number of conversations in the window.
+ *
+ * @param win The window.
+ *
+ * @return The number of conversations.
+ */
+size_t gaim_window_get_conversation_count(const struct gaim_window *win);
+
+/**
+ * Switches the active conversation to the one at the specified index.
+ *
+ * If @a index is out of range, this does nothing.
+ *
+ * @param win   The window.
+ * @param index The new index.
+ */
+void gaim_window_switch_conversation(struct gaim_window *win,
+									 unsigned int index);
+
+/**
+ * Returns the active conversation in the window.
+ *
+ * @param win The window.
+ *
+ * @return The active conversation.
+ */
+struct gaim_conversation *gaim_window_get_active_conversation(
+		const struct gaim_window *win);
+
+/**
+ * Returns the list of conversations in the specified window.
+ *
+ * @param win The window.
+ *
+ * @return The list of conversations.
+ */
+GList *gaim_window_get_conversations(const struct gaim_window *win);
+
+/**
+ * Returns a list of all windows.
+ *
+ * @return A list of windows.
+ */
+GList *gaim_get_windows(void);
+
+/*@}*/
+
+/**************************************************************************/
+/** @name Conversation API                                                */
+/**************************************************************************/
+/*@{*/
+
+/**
+ * Creates a new conversation of the specified type.
+ *
+ * @param type The type of conversation.
+ * @param name The name of the conversation.
+ *
+ * @return The new conversation.
+ */
+struct gaim_conversation *gaim_conversation_new(GaimConversationType type,
+												const char *name);
+
+/**
+ * Destroys the specified conversation and removes it from the parent
+ * window.
+ *
+ * If this conversation is the only one contained in the parent window,
+ * that window is also destroyed.
+ *
+ * @param conv The conversation to destroy.
+ */
+void gaim_conversation_destroy(struct gaim_conversation *conv);
+
+/**
+ * Returns the specified conversation's type.
+ *
+ * @param conv The conversation.
+ *
+ * @return The conversation's type.
+ */
+GaimConversationType gaim_conversation_get_type(
+		const struct gaim_conversation *conv);
+
+/**
+ * Sets the specified conversation's UI operations structure.
+ *
+ * @param conv The conversation.
+ * @param ops  The UI conversation operations structure.
+ */
+void gaim_conversation_set_ops(struct gaim_conversation *conv,
+							   struct gaim_conversation_ops *ops);
+
+/**
+ * Returns the specified conversation's UI operations structure.
+ * 
+ * @param conv The conversation.
+ *
+ * @return The operations structure.
+ */
+struct gaim_conversation_ops *gaim_conversation_get_ops(
+		struct gaim_conversation *conv);
+
+/**
+ * Sets the specified conversation's aim_user.
+ *
+ * This aim_user represents the user using gaim, not the person the user
+ * is having a conversation/chat/flame with.
+ *
+ * @param conv The conversation.
+ * @param user The aim_user.
+ */
+void gaim_conversation_set_user(struct gaim_conversation *conv,
+								struct aim_user *user);
+
+/**
+ * Returns the specified conversation's aim_user.
+ *
+ * This aim_user represents the user using gaim, not the person the user
+ * is having a conversation/chat/flame with.
+ *
+ * @param conv The conversation.
+ *
+ * @return The conversation's aim_user.
+ */
+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.
+ *
+ * This is the same as gaim_conversation_get_user(conv)->gc.
+ *
+ * @param conv The conversation.
+ *
+ * @return The conversation's gaim_connection.
+ */
+struct gaim_connection *gaim_conversation_get_gc(
+		const struct gaim_conversation *conv);
+
+/**
+ * Sets the specified conversation's title.
+ *
+ * @param conv  The conversation.
+ * @param title The title.
+ */
+void gaim_conversation_set_title(struct gaim_conversation *conv,
+								 const char *title);
+
+/**
+ * Returns the specified conversation's title.
+ *
+ * @param win The conversation.
+ *
+ * @return The title.
+ */
+const char *gaim_conversation_get_title(const struct gaim_conversation *conv);
+
+/**
+ * Automatically sets the specified conversation's title.
+ *
+ * This function takes OPT_IM_ALIAS_TAB into account, as well as the
+ * user's alias.
+ *
+ * @param conv The conversation.
+ */
+void gaim_conversation_autoset_title(struct gaim_conversation *conv);
+
+/**
+ * Returns the specified conversation's index in the parent window.
+ *
+ * @param conv The conversation.
+ *
+ * @return The current index in the parent window.
+ */
+int gaim_conversation_get_index(const struct gaim_conversation *conv);
+
+/**
+ * Sets the conversation's unseen state.
+ *
+ * @param conv  The conversation.
+ * @param state The new unseen state.
+ */
+void gaim_conversation_set_unseen(struct gaim_conversation *conv,
+								  GaimUnseenState state);
+
+/**
+ * Returns the conversation's unseen state.
+ *
+ * @param conv The conversation.
+ *
+ * @param The conversation's unseen state.
+ */
+GaimUnseenState gaim_conversation_get_unseen(
+		const struct gaim_conversation *conv);
+
+/**
+ * Returns the specified conversation's name.
+ *
+ * @param conv The conversation.
+ *
+ * @return The conversation's name.
+ */
+const char *gaim_conversation_get_name(const struct gaim_conversation *conv);
+
+/**
+ * Enables or disables logging for this conversation.
+ *
+ * @param log @c TRUE if logging should be enabled, or @c FALSE otherwise.
+ */
+void gaim_conversation_set_logging(struct gaim_conversation *conv,
+								   gboolean log);
+
+/**
+ * Returns whether or not logging is enabled for this conversation.
+ *
+ * @return @c TRUE if logging is enabled, or @c FALSE otherwise.
+ */
+gboolean gaim_conversation_is_logging(const struct gaim_conversation *conv);
+
+/**
+ * Returns the specified conversation's send history.
+ *
+ * @param conv The conversation.
+ *
+ * @return The conversation's send history.
+ */
+GList *gaim_conversation_get_send_history(
+		const struct gaim_conversation *conv);
+
+/**
+ * Sets the specified conversation's history.
+ *
+ * @param conv    The conversation.
+ * @param history The history.
+ */
+void gaim_conversation_set_history(struct gaim_conversation *conv,
+								   GString *history);
+
+/**
+ * Returns the specified conversation's history.
+ *
+ * @param conv The conversation.
+ *
+ * @return The conversation's history.
+ */
+GString *gaim_conversation_get_history(const struct gaim_conversation *conv);
+
+/**
+ * Returns the specified conversation's parent window.
+ *
+ * @param conv The conversation.
+ *
+ * @return The conversation's parent window.
+ */
+struct gaim_window *gaim_conversation_get_window(
+		const struct gaim_conversation *conv);
+
+/**
+ * Returns the specified conversation's IM-specific data.
+ *
+ * If the conversation type is not GAIM_CONV_IM, this will return @c NULL.
+ *
+ * @param conv The conversation.
+ *
+ * @return The IM-specific data.
+ */
+struct gaim_im *gaim_conversation_get_im_data(
+		const struct gaim_conversation *conv);
+
+#define GAIM_IM(c) (gaim_conversation_get_im_data(c))
+
+/**
+ * Returns the specified conversation's chat-specific data.
+ *
+ * If the conversation type is not GAIM_CONV_CHAT, this will return @c NULL.
+ *
+ * @param conv The conversation.
+ *
+ * @return The chat-specific data.
+ */
+struct gaim_chat *gaim_conversation_get_chat_data(
+		const struct gaim_conversation *conv);
+
+#define GAIM_CHAT(c) (gaim_conversation_get_chat_data(c))
+
+/**
+ * Returns a list of all conversations.
+ *
+ * This list includes both IMs and chats.
+ *
+ * @return A GList of all conversations.
+ */
+GList *gaim_get_conversations(void);
+
+/**
+ * Returns a list of all IMs.
+ *
+ * @return A GList of all IMs.
+ */
+GList *gaim_get_ims(void);
+
+/**
+ * Returns a list of all chats.
+ *
+ * @return A GList of all chats.
+ */
+GList *gaim_get_chats(void);
+
+/**
+ * Finds the conversation with the specified name.
+ *
+ * @param name The name of the conversation.
+ *
+ * @return The conversation if found, or @c NULL otherwise.
+ */
+struct gaim_conversation *gaim_find_conversation(const char *name);
+
+/**
+ * Finds a conversation with the specified name and user.
+ *
+ * @param name The name of the conversation.
+ * @param user The aim_user associated with the conversation.
+ *
+ * @return The conversation if found, or @c NULL otherwise.
+ */
+struct gaim_conversation *gaim_find_conversation_with_user(
+		const char *name, const struct aim_user *user);
+
+/**
+ * Writes to a conversation window.
+ *
+ * This function should not be used to write IM or chat messages. Use
+ * gaim_im_write() and gaim_chat_write() instead. Those functions will
+ * most likely call this anyway, but they may do their own formatting,
+ * sound playback, etc.
+ *
+ * This can be used to write generic messages, such as "so and so closed
+ * the conversation window."
+ *
+ * @param conv    The conversation.
+ * @param who     The user who sent the message.
+ * @param message The message.
+ * @param length  The length of the message.
+ * @param flags   The flags.
+ * @param mtime   The time the message was sent.
+ *
+ * @see gaim_im_write()
+ * @see gaim_chat_write()
+ */
+void gaim_conversation_write(struct gaim_conversation *conv, const char *who,
+							 const char *message, size_t length, int flags,
+							 time_t mtime);
+
+/**
+ * Updates the progress bar on a conversation window
+ * (if one exists in the UI).
+ *
+ * This is used for loading images typically.
+ *
+ * @param conv    The conversation.
+ * @param percent The percentage.
+ */
+void gaim_conversation_update_progress(struct gaim_conversation *conv,
+									   float percent);
+
+/**
+ * Updates the visual status and UI of a conversation.
+ *
+ * @param conv The conversation.
+ * @param type The update type.
+ */
+void gaim_conversation_update(struct gaim_conversation *conv,
+							  GaimConvUpdateType type);
+
+/**
+ * Calls a function on each conversation.
+ *
+ * @param func The function.
+ */
+void gaim_conversation_foreach(void (*func)(struct gaim_conversation *conv));
+
+/*@}*/
+
+
+/**************************************************************************/
+/** @name IM Conversation API                                             */
+/**************************************************************************/
+/*@{*/
+
+/**
+ * Gets an IM's parent conversation.
+ *
+ * @param im The IM.
+ *
+ * @return The parent conversation.
+ */
+struct gaim_conversation *gaim_im_get_conversation(struct gaim_im *im);
+
+/**
+ * Sets the IM's typing state.
+ *
+ * @param im    The IM.
+ * @param state The typing state.
+ */
+void gaim_im_set_typing_state(struct gaim_im *im, int state);
+
+/**
+ * Returns the IM's typing state.
+ *
+ * @param im The IM.
+ *
+ * @return The IM's typing state.
+ */
+int gaim_im_get_typing_state(const struct gaim_im *im);
+
+/**
+ * Starts the IM's typing timeout.
+ *
+ * @param im      The IM.
+ * @param timeout The timeout.
+ */
+void gaim_im_start_typing_timeout(struct gaim_im *im, int timeout);
+
+/**
+ * Stops the IM's typing timeout.
+ *
+ * @param im The IM.
+ */
+void gaim_im_stop_typing_timeout(struct gaim_im *im);
+
+/**
+ * Returns the IM's typing timeout.
+ *
+ * @param im The IM.
+ *
+ * @return The timeout.
+ */
+guint gaim_im_get_typing_timeout(const struct gaim_im *im);
+
+/**
+ * Sets the IM's time until it should send another typing notification.
+ *
+ * @param im  The IM.
+ * @param val The time.
+ */
+void gaim_im_set_type_again(struct gaim_im *im, time_t val);
+
+/**
+ * Returns the IM's time until it should send another typing notification.
+ *
+ * @param im The IM.
+ *
+ * @return The time.
+ */
+time_t gaim_im_get_type_again(const struct gaim_im *im);
+
+/**
+ * Starts the IM's type again timeout.
+ *
+ * @param im      The IM.
+ */
+void gaim_im_start_type_again_timeout(struct gaim_im *im);
+
+/**
+ * Stops the IM's type again timeout.
+ *
+ * @param im The IM.
+ */
+void gaim_im_stop_type_again_timeout(struct gaim_im *im);
+
+/**
+ * Returns the IM's type again timeout interval.
+ *
+ * @param im The IM.
+ *
+ * @return The type again timeout interval.
+ */
+guint gaim_im_get_type_again_timeout(const struct gaim_im *im);
+
+/**
+ * Updates the visual typing notification for an IM conversation.
+ *
+ * @param im The IM.
+ */
+void gaim_im_update_typing(struct gaim_im *im);
+
+/**
+ * Writes to an IM.
+ *
+ * The @a len parameter is used for writing binary data, such as an
+ * image. If @c message is text, specify -1 for @a len.
+ *
+ * @param im      The IM.
+ * @param who     The user who sent the message.
+ * @param message The message to write.
+ * @param len     The length of the message, or -1 to specify the length
+ *                of @a message.
+ * @param flag    The flags.
+ * @param mtime   The time the message was sent.
+ */
+void gaim_im_write(struct gaim_im *im, const char *who,
+				   const char *message, size_t len, int flag, time_t mtime);
+
+/**
+ * Sends a message to this IM conversation.
+ *
+ * @param im      The IM.
+ * @param message The message to send.
+ */
+void gaim_im_send(struct gaim_im *im, const char *message);
+
+/*@}*/
+
+
+/**************************************************************************/
+/** @name Chat Conversation API                                           */
+/**************************************************************************/
+/*@{*/
+
+/**
+ * Gets a chat's parent conversation.
+ *
+ * @param chat The chat.
+ *
+ * @return The parent conversation.
+ */
+struct gaim_conversation *gaim_chat_get_conversation(struct gaim_chat *chat);
+
+/**
+ * Sets the list of users in the chat room.
+ *
+ * @param chat  The chat.
+ * @param users The list of users.
+ *
+ * @return The list passed.
+ */
+GList *gaim_chat_set_users(struct gaim_chat *chat, GList *users);
+
+/**
+ * Returns a list of users in the chat room.
+ *
+ * @param chat The chat.
+ *
+ * @return The list of users.
+ */
+GList *gaim_chat_get_users(const struct gaim_chat *chat);
+
+/**
+ * Ignores a user in a chat room.
+ *
+ * @param chat The chat.
+ * @param name The name of the user.
+ */
+void gaim_chat_ignore(struct gaim_chat *chat, const char *name);
+
+/**
+ * Unignores a user in a chat room.
+ *
+ * @param chat The chat.
+ * @param name The name of the user.
+ */
+void gaim_chat_unignore(struct gaim_chat *chat, const char *name);
+
+/**
+ * Sets the list of ignored users in the chat room.
+ *
+ * @param chat    The chat.
+ * @param ignored The list of ignored users.
+ *
+ * @return The list passed.
+ */
+GList *gaim_chat_set_ignored(struct gaim_chat *chat, GList *ignored);
+
+/**
+ * Returns the list of ignored users in the chat room.
+ *
+ * @param chat The chat.
+ *
+ * @return The list of ignored users.
+ */
+GList *gaim_chat_get_ignored(const struct gaim_chat *chat);
+
+/**
+ * Returns the actual name of the specified ignored user, if it exists in
+ * the ignore list.
+ *
+ * If the user found contains a prefix, such as '+' or '\@', this is also
+ * returned. The username passed to the function does not have to have this
+ * formatting.
+ *
+ * @param chat The chat.
+ * @param user The user to check in the ignore list.
+ *
+ * @return The ignored user if found, complete with prefixes, or @c NULL
+ *         if not found.
+ */
+const char *gaim_chat_get_ignored_user(const struct gaim_chat *chat,
+									   const char *user);
+
+/**
+ * Returns @c TRUE if the specified user is ignored.
+ *
+ * @param chat The chat.
+ * @param user The user.
+ *
+ * @return @c TRUE if the user is in the ignore list; @c FALSE otherwise.
+ */
+gboolean gaim_chat_is_user_ignored(const struct gaim_chat *chat,
+								   const char *user);
+
+/**
+ * Sets the chat room's topic.
+ *
+ * @param chat  The chat.
+ * @param who   The user that set the topic.
+ * @param topic The topic.
+ */
+void gaim_chat_set_topic(struct gaim_chat *chat, const char *who,
+						 const char *topic);
+
+/**
+ * Returns the chat room's topic.
+ *
+ * @param chat The chat.
+ *
+ * @return The chat's topic.
+ */
+const char *gaim_chat_get_topic(const struct gaim_chat *chat);
+
+/**
+ * Sets the chat room's ID.
+ *
+ * @param chat The chat.
+ * @param id   The ID.
+ */
+void gaim_chat_set_id(struct gaim_chat *chat, int id);
+
+/**
+ * Returns the chat room's ID.
+ *
+ * @param chat The chat.
+ *
+ * @return The ID.
+ */
+int gaim_chat_get_id(const struct gaim_chat *chat);
+
+/**
+ * Writes to a chat.
+ *
+ * @param chat    The chat.
+ * @param who     The user who sent the message.
+ * @param message The message to write.
+ * @param flag    The flags.
+ * @param mtime   The time the message was sent.
+ */
+void gaim_chat_write(struct gaim_chat *chat, const char *who,
+					 const char *message, int flag, time_t mtime);
+
+/**
+ * Sends a message to this chat conversation.
+ *
+ * @param chat    The chat.
+ * @param message The message to send.
+ */
+void gaim_chat_send(struct gaim_chat *chat, const char *message);
+
+/**
+ * Adds a user to a chat.
+ *
+ * @param chat      The chat.
+ * @param user      The user to add.
+ * @param extra_msg An extra message to display with the join message.
+ */
+void gaim_chat_add_user(struct gaim_chat *chat, const char *user,
+						const char *extra_msg);
+
+/**
+ * Renames a user in a chat.
+ *
+ * @param chat     The chat.
+ * @param old_user The old username.
+ * @param new_user The new username.
+ */
+void gaim_chat_rename_user(struct gaim_chat *chat, const char *old_user,
+						   const char *new_user);
+
+/**
+ * Removes a user from a chat, optionally with a reason.
+ *
+ * @param chat   The chat.
+ * @param user   The user that is being removed.
+ * @param reason The optional reason given for the removal. Can be @c NULL.
+ */
+void gaim_chat_remove_user(struct gaim_chat *chat, const char *user,
+						   const char *reason);
+
+/**
+ * Finds a chat with the specified chat ID.
+ *
+ * @param gc The gaim_connection.
+ * @param id The chat ID.
+ *
+ * @return The chat conversation.
+ */
+struct gaim_conversation *gaim_find_chat(struct gaim_connection *gc, int id);
+
+/*@}*/
+
+#endif /* _CONVERSATION_H_ */
--- a/src/convo.h	Mon Jan 20 07:00:10 2003 +0000
+++ b/src/convo.h	Mon Jan 20 09:10:23 2003 +0000
@@ -23,6 +23,8 @@
 #define _CONVO_H_
 
 #include <gtk/gtk.h>
+#include "conversation.h"
+#include "gtkconv.h"
 #include "gaim.h"
 
 #if 0
@@ -42,33 +44,33 @@
  * that it's easy to keep them merged. */
 
 /* chat first */
-extern void im_callback(GtkWidget *, struct conversation *);
-extern void ignore_callback(GtkWidget *, struct conversation *);
-extern void whisper_callback(GtkWidget *, struct conversation *);
-extern void invite_callback(GtkWidget *, struct conversation *);
-extern void tab_complete(struct conversation *c);
+extern void im_callback(GtkWidget *, struct gaim_conversation *);
+extern void ignore_callback(GtkWidget *, struct gaim_conversation *);
+extern void whisper_callback(GtkWidget *, struct gaim_conversation *);
+extern void invite_callback(GtkWidget *, struct gaim_conversation *);
+extern void tab_complete(struct gaim_conversation *c);
 
 /* now IM */
-extern void warn_callback(GtkWidget *, struct conversation *);
-extern void block_callback(GtkWidget *, struct conversation *);
-extern void add_callback(GtkWidget *, struct conversation *);
+extern void warn_callback(GtkWidget *, struct gaim_conversation *);
+extern void block_callback(GtkWidget *, struct gaim_conversation *);
+extern void add_callback(GtkWidget *, struct gaim_conversation *);
 
 /* now both */
 extern int set_dispstyle (int);
-extern void info_callback(GtkWidget *, struct conversation *);
-extern void do_bold(GtkWidget *, struct conversation *);
-extern void do_italic(GtkWidget *, struct conversation *);
-extern void do_underline(GtkWidget *, struct conversation *);
-extern void do_strike(GtkWidget *, struct conversation *);
-extern void do_small(GtkWidget *, struct conversation *);
-extern void do_normal(GtkWidget *, struct conversation *);
-extern void do_big(GtkWidget *, struct conversation *);
-extern void toggle_font(GtkWidget *, struct conversation *);
-extern void toggle_color(GtkWidget *, struct conversation *);
-extern void toggle_loggle(GtkWidget *, struct conversation *);
-extern void insert_smiley(GtkWidget *, struct conversation *);
+extern void info_callback(GtkWidget *, struct gaim_conversation *);
+extern void do_bold(GtkWidget *, struct gaim_conversation *);
+extern void do_italic(GtkWidget *, struct gaim_conversation *);
+extern void do_underline(GtkWidget *, struct gaim_conversation *);
+extern void do_strike(GtkWidget *, struct gaim_conversation *);
+extern void do_small(GtkWidget *, struct gaim_conversation *);
+extern void do_normal(GtkWidget *, struct gaim_conversation *);
+extern void do_big(GtkWidget *, struct gaim_conversation *);
+extern void toggle_font(GtkWidget *, struct gaim_conversation *);
+extern void toggle_color(GtkWidget *, struct gaim_conversation *);
+extern void toggle_loggle(GtkWidget *, struct gaim_conversation *);
+extern void insert_smiley(GtkWidget *, struct gaim_conversation *);
 /* sound is handled by set_option */
-extern gboolean keypress_callback(GtkWidget *, GdkEventKey *, struct conversation *);
+extern gboolean keypress_callback(GtkWidget *, GdkEventKey *, struct gaim_conversation *);
 extern gboolean stop_rclick_callback(GtkWidget *, GdkEventButton *, gpointer);
 extern void check_spelling( GtkEditable *, gchar *, gint, gint *, gpointer);
 extern int entry_key_pressed(GtkTextBuffer *);
@@ -76,10 +78,10 @@
 extern void convo_switch(GtkNotebook *, GtkWidget *, gint, gpointer);
 extern gint delete_all_convo(GtkWidget *, GdkEventAny *, gpointer);
 
-extern GtkWidget *build_conv_toolbar(struct conversation *);
+extern GtkWidget *build_conv_toolbar(struct gaim_conversation *);
 
-extern void send_callback(GtkWidget *, struct conversation *);
-extern int close_callback(GtkWidget *, struct conversation *);
+extern void send_callback(GtkWidget *, struct gaim_conversation *);
+extern int close_callback(GtkWidget *, struct gaim_conversation *);
 
 extern gboolean meify(char *, int);
 
--- a/src/core.h	Mon Jan 20 07:00:10 2003 +0000
+++ b/src/core.h	Mon Jan 20 09:10:23 2003 +0000
@@ -42,7 +42,13 @@
 #include <gmodule.h>
 #endif
 
+struct aim_user;
+struct group;
+struct buddy;
+
+
 #include "multi.h"
+#include "conversation.h"
 
 /* Really user states are controlled by the PRPLs now. We just use this for event_away */
 #define UC_UNAVAILABLE  1
@@ -254,7 +260,7 @@
 extern void serv_got_typing_stopped(struct gaim_connection *, char *);
 extern void serv_got_eviled(struct gaim_connection *, char *, int);
 extern void serv_got_chat_invite(struct gaim_connection *, char *, char *, char *, GList *);
-extern struct conversation *serv_got_joined_chat(struct gaim_connection *, int, char *);
+extern struct gaim_conversation *serv_got_joined_chat(struct gaim_connection *, int, char *);
 extern void serv_got_chat_left(struct gaim_connection *, int);
 extern void serv_got_chat_in(struct gaim_connection *, int, char *, int, char *, time_t);
 extern void serv_got_alias(struct gaim_connection *, char *, char *);
--- a/src/dialogs.c	Mon Jan 20 07:00:10 2003 +0000
+++ b/src/dialogs.c	Mon Jan 20 09:10:23 2003 +0000
@@ -240,7 +240,7 @@
 	GtkWidget *text;
 	GtkWidget *toggle;
 	GtkWidget *entry;
-	struct conversation *c;
+	struct gaim_conversation *c;
 };
 
 struct passwddlg {
@@ -279,36 +279,45 @@
 /*  Destroys                                                              */
 /*------------------------------------------------------------------------*/
 
-static gint delete_event_dialog(GtkWidget *w, GdkEventAny *e, struct conversation *c)
+static gint delete_event_dialog(GtkWidget *w, GdkEventAny *e, struct gaim_conversation *c)
 {
+	struct gaim_gtk_conversation *gtkconv;
 	gchar *object_data;
+
 	object_data = gtk_object_get_user_data(GTK_OBJECT(w));
 
+	gtkconv = GAIM_GTK_CONVERSATION(c);
+
 	if (GTK_IS_COLOR_SELECTION_DIALOG(w)) {
-		set_state_lock(1);
-		if (w == c->fg_color_dialog) {
-			gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(c->fgcolorbtn), FALSE);
-			c->fg_color_dialog = NULL;
+		gaim_gtk_set_state_lock(TRUE);
+		if (w == gtkconv->dialogs.fg_color) {
+			gtk_toggle_button_set_state(
+				GTK_TOGGLE_BUTTON(gtkconv->toolbar.fgcolor), FALSE);
+			gtkconv->dialogs.fg_color = NULL;
 		} else {
-			gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(c->bgcolorbtn), FALSE);
-			c->bg_color_dialog = NULL;
+			gtk_toggle_button_set_state(
+				GTK_TOGGLE_BUTTON(gtkconv->toolbar.bgcolor), FALSE);
+			gtkconv->dialogs.bg_color = NULL;
 		}
-		set_state_lock(0);
+		gaim_gtk_set_state_lock(FALSE);
 	} else if (GTK_IS_FONT_SELECTION_DIALOG(w)) {
-		set_state_lock(1);
-		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(c->font), FALSE);
-		set_state_lock(0);
-		c->font_dialog = NULL;
+		gaim_gtk_set_state_lock(TRUE);
+		gtk_toggle_button_set_state(
+			GTK_TOGGLE_BUTTON(gtkconv->toolbar.normal_size), FALSE);
+		gaim_gtk_set_state_lock(FALSE);
+		gtkconv->dialogs.font = NULL;
 	} else if (!g_strcasecmp(object_data, "smiley dialog")) {
-		set_state_lock(1);
-		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(c->smiley), FALSE);
-		set_state_lock(0);
-		c->smiley_dialog = NULL;
+		gaim_gtk_set_state_lock(TRUE);
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(gtkconv->toolbar.smiley),
+									FALSE);
+		gaim_gtk_set_state_lock(FALSE);
+		gtkconv->dialogs.smiley = NULL;
 	} else if (!g_strcasecmp(object_data, "log dialog")) {
-		set_state_lock(1);
-		gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(c->log_button), FALSE);
-		set_state_lock(0);
-		c->log_dialog = NULL;
+		gaim_gtk_set_state_lock(TRUE);
+		gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtkconv->toolbar.log),
+									   FALSE);
+		gaim_gtk_set_state_lock(FALSE);
+		gtkconv->dialogs.log = NULL;
 	}
 
 	dialogwindows = g_list_remove(dialogwindows, w);
@@ -395,7 +404,7 @@
 	GtkWidget *hbox, *vbox;
 	GtkWidget *label;
 	GtkWidget *img = gtk_image_new_from_file(filename);
-	struct conversation *c = find_conversation(who);
+	struct gaim_conversation *c = gaim_find_conversation(who);
 
 	struct warning *w = g_new0(struct warning, 1);
 	w->who = who;
@@ -450,21 +459,22 @@
 void do_remove_buddy(struct buddy *b)
 {
 	struct group *g = find_group_by_buddy(b);
-	struct conversation *cv;
+	struct gaim_conversation *c;
 
 	if (!b)
 		return;
 
+	g = find_group_by_buddy(b);
+
 	debug_printf(_("Removing '%s' from buddy list.\n"), b->name);
 	serv_remove_buddy(b->user->gc, b->name, g->name);
 	remove_buddy(b);
 	gaim_blist_save();
 
-	cv = find_conversation(b->name);
-
-	if (cv)
-		update_convo_add_button(cv);
-
+	c = gaim_find_conversation(b->name);
+
+	if (c != NULL)
+		gaim_conversation_update(c, GAIM_CONV_UPDATE_REMOVE);
 }
 
 void show_confirm_del(struct gaim_connection *gc, gchar *name)
@@ -554,30 +564,28 @@
 
 static void do_im(GtkWidget *widget, int resp, struct getuserinfo *info)
 {
-	char *who;
-	struct conversation *c;
+	const char *who;
+	struct gaim_conversation *conv;
 
 	if (resp == GTK_RESPONSE_OK) {
-		who = g_strdup(gtk_entry_get_text(GTK_ENTRY(info->entry)));
-		
+		who = gtk_entry_get_text(GTK_ENTRY(info->entry));
+	
 		if (!g_strcasecmp(who, "")) {
-			g_free(who);
+			g_free(info);
 			return;
 		}
-		
-		c = find_conversation(who);
-		
-		if (c == NULL) {
-			c = new_conversation(who);
-		} else {
-			gdk_window_raise(c->window->window);
-			}
+
+		conv = gaim_find_conversation(who);
+
+		if (conv == NULL)
+			conv = gaim_conversation_new(GAIM_CONV_IM, who);
+		else
+			gaim_window_raise(gaim_conversation_get_window(conv));
+
 		if (info->gc)
-			set_convo_gc(c, info->gc);
-		
-		g_free(who);
+			gaim_conversation_set_user(conv, info->gc->user);
 	}
-	
+
 	destroy_dialog(NULL, imdialog);
 	imdialog = NULL;
 	g_free(info);
@@ -868,12 +876,12 @@
 /*  The dialog for adding buddies                                         */
 /*------------------------------------------------------------------------*/
 
-extern void add_callback(GtkWidget *, struct conversation *);
+extern void add_callback(GtkWidget *, struct gaim_conversation *);
 
 void do_add_buddy(GtkWidget *w, int resp, struct addbuddy *a)
 {
 	const char *grp, *who, *whoalias;
-	struct conversation *c;
+	struct gaim_conversation *c;
 
 	if (resp == GTK_RESPONSE_OK) {
 
@@ -881,14 +889,13 @@
 		grp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(a->combo)->entry));
 		whoalias = gtk_entry_get_text(GTK_ENTRY(a->entry_for_alias));
 
-		c = find_conversation(who);
+		c = gaim_find_conversation(who);
 
 		add_buddy(a->gc->user, grp, who, whoalias);
 		serv_add_buddy(a->gc, who);
 
-		if (c != NULL) {
-			update_buttons_by_protocol(c);
-		}
+		if (c != NULL)
+			gaim_conversation_update(c, GAIM_CONV_UPDATE_ADD);
 
 		gaim_blist_save();
 	}
@@ -1898,7 +1905,8 @@
 	}
 	gtk_widget_show(b->messentry);
 
-	g_signal_connect(GTK_OBJECT(b->sendim), "clicked", G_CALLBACK(toggle_sensitive),	b->messentry);
+	g_signal_connect(GTK_OBJECT(b->sendim), "clicked",
+					 G_CALLBACK(gaim_gtk_toggle_sensitive), b->messentry);
 
 	b->command = gtk_check_button_new_with_label(_("Execute command on pounce"));
 	gtk_table_attach(GTK_TABLE(table), b->command, 0, 1, 2, 3, GTK_FILL, 0, 0, 0);
@@ -1920,7 +1928,8 @@
 	else
 		gtk_widget_set_sensitive(GTK_WIDGET(b->commentry), FALSE);
 	gtk_widget_show(b->commentry);
-	g_signal_connect(GTK_OBJECT(b->command), "clicked", G_CALLBACK(toggle_sensitive), b->commentry);
+	g_signal_connect(GTK_OBJECT(b->command), "clicked",
+					 G_CALLBACK(gaim_gtk_toggle_sensitive), b->commentry);
 	
 	b->sound = gtk_check_button_new_with_label(_("Play sound on pounce"));
 	if(edit_bp)
@@ -1941,7 +1950,8 @@
 	} else 
 		gtk_widget_set_sensitive(GTK_WIDGET(b->soundentry), FALSE);
 	gtk_widget_show(b->soundentry);
-	g_signal_connect(GTK_OBJECT(b->sound), "clicked", G_CALLBACK(toggle_sensitive), b->soundentry);
+	g_signal_connect(GTK_OBJECT(b->sound), "clicked",
+					 G_CALLBACK(gaim_gtk_toggle_sensitive), b->soundentry);
 	/* </pounce type="action"> */
 
 	b->save = gtk_check_button_new_with_label(_("Save this pounce after activation"));
@@ -2600,71 +2610,86 @@
 /*  Functions Called To Add A Log                                          */
 /*------------------------------------------------------------------------*/
 
-void cancel_log(GtkWidget *widget, struct conversation *c)
+void cancel_log(GtkWidget *widget, struct gaim_conversation *c)
 {
-	if (c->log_button) {
-		set_state_lock(1);
-		gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(c->log_button), FALSE);
-		set_state_lock(0);
+	struct gaim_gtk_conversation *gtkconv;
+
+	gtkconv = GAIM_GTK_CONVERSATION(c);
+
+	if (gtkconv->toolbar.log) {
+		gaim_gtk_set_state_lock(TRUE);
+		gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtkconv->toolbar.log),
+									   FALSE);
+		gaim_gtk_set_state_lock(FALSE);
 	}
-	dialogwindows = g_list_remove(dialogwindows, c->log_dialog);
-	gtk_widget_destroy(c->log_dialog);
-	c->log_dialog = NULL;
+
+	dialogwindows = g_list_remove(dialogwindows, gtkconv->dialogs.log);
+	gtk_widget_destroy(gtkconv->dialogs.log);
+	gtkconv->dialogs.log = NULL;
 }
 
-void do_log(GtkWidget *w, struct conversation *c)
+void do_log(GtkWidget *w, struct gaim_conversation *c)
 {
+	struct gaim_gtk_conversation *gtkconv;
 	struct log_conversation *l;
-	char buf[128];
 	const char *file;
 	char path[PATHSIZE];
 
+	gtkconv = GAIM_GTK_CONVERSATION(c);
+
 	if (!find_log_info(c->name)) {
-		file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(c->log_dialog));
+		file = gtk_file_selection_get_filename(
+			GTK_FILE_SELECTION(gtkconv->dialogs.log));
+
 		strncpy(path, file, PATHSIZE - 1);
-		if (file_is_dir(path, c->log_dialog)) {
+
+		if (file_is_dir(path, gtkconv->dialogs.log))
 			return;
-		}
 
 		l = (struct log_conversation *)g_new0(struct log_conversation, 1);
-		strcpy(l->name, c->name);
+		strcpy(l->name, gaim_conversation_get_name(c));
 		strcpy(l->filename, file);
 		log_conversations = g_list_append(log_conversations, l);
 
-		if (c != NULL) {
-			g_snprintf(buf, sizeof(buf), LOG_CONVERSATION_TITLE, c->name);
-			gtk_window_set_title(GTK_WINDOW(c->window), buf);
-		}
+		if (c != NULL)
+			gaim_conversation_set_logging(c, TRUE);
 	}
 
 	save_prefs();
 	cancel_log(NULL, c);
 }
 
-void show_log_dialog(struct conversation *c)
+void show_log_dialog(struct gaim_conversation *c)
 {
+	struct gaim_gtk_conversation *gtkconv;
 	char *buf = g_malloc(BUF_LEN);
 
-	if (!c->log_dialog) {
-		c->log_dialog = gtk_file_selection_new(_("Gaim - Log Conversation"));
-
-		gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(c->log_dialog));
-
-		g_snprintf(buf, BUF_LEN - 1, "%s" G_DIR_SEPARATOR_S "%s.log", gaim_home_dir(), normalize(c->name));
-		gtk_object_set_user_data(GTK_OBJECT(c->log_dialog), "log dialog");
-		gtk_file_selection_set_filename(GTK_FILE_SELECTION(c->log_dialog), buf);
-		g_signal_connect(GTK_OBJECT(c->log_dialog), "delete_event",
-				   G_CALLBACK(delete_event_dialog), c);
-		g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(c->log_dialog)->ok_button), "clicked",
-				   G_CALLBACK(do_log), c);
-		g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(c->log_dialog)->cancel_button),
-				   "clicked", G_CALLBACK(cancel_log), c);
+	gtkconv = GAIM_GTK_CONVERSATION(c);
+
+	if (!gtkconv->dialogs.log) {
+		gtkconv->dialogs.log = gtk_file_selection_new(_("Gaim - Log Conversation"));
+
+		gtk_file_selection_hide_fileop_buttons(
+			GTK_FILE_SELECTION(gtkconv->dialogs.log));
+
+		g_snprintf(buf, BUF_LEN - 1, "%s" G_DIR_SEPARATOR_S "%s.log",
+				   gaim_home_dir(), normalize(c->name));
+		gtk_object_set_user_data(GTK_OBJECT(gtkconv->dialogs.log),
+								 "log dialog");
+		gtk_file_selection_set_filename(GTK_FILE_SELECTION(gtkconv->dialogs.log),
+										buf);
+		g_signal_connect(G_OBJECT(gtkconv->dialogs.log), "delete_event",
+						 G_CALLBACK(delete_event_dialog), c);
+		g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(gtkconv->dialogs.log)->ok_button), "clicked",
+						 G_CALLBACK(do_log), c);
+		g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(gtkconv->dialogs.log)->cancel_button), "clicked",
+						 G_CALLBACK(cancel_log), c);
 	}
 
 	g_free(buf);
 
-	gtk_widget_show(c->log_dialog);
-	gdk_window_raise(c->log_dialog->window);
+	gtk_widget_show(gtkconv->dialogs.log);
+	gdk_window_raise(gtkconv->dialogs.log->window);
 }
 
 /*------------------------------------------------------*/
@@ -2918,22 +2943,31 @@
 /* Link Dialog                                          */
 /*------------------------------------------------------*/
 
-void cancel_link(GtkWidget *widget, struct conversation *c)
+void cancel_link(GtkWidget *widget, struct gaim_conversation *c)
 {
-	if (c->link) {
-		set_state_lock(1);
-		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(c->link), FALSE);
-		set_state_lock(0);
+	struct gaim_gtk_conversation *gtkconv;
+
+	gtkconv = GAIM_GTK_CONVERSATION(c);
+
+	if (gtkconv->toolbar.link) {
+		gaim_gtk_set_state_lock(TRUE);
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(gtkconv->toolbar.link),
+									FALSE);
+		gaim_gtk_set_state_lock(FALSE);
 	}
-	destroy_dialog(NULL, c->link_dialog);
-	c->link_dialog = NULL;
+
+	destroy_dialog(NULL, gtkconv->toolbar.link);
+	gtkconv->toolbar.link = NULL;
 }
 
 void do_insert_link(GtkWidget *w, int resp, struct linkdlg *b)
 {
+	struct gaim_gtk_conversation *gtkconv;
 	char *open_tag;
 	const char *urltext, *showtext;
 
+	gtkconv = GAIM_GTK_CONVERSATION(b->c);
+
 	if (resp == GTK_RESPONSE_OK) {
 
 		open_tag = g_malloc(2048);
@@ -2945,46 +2979,54 @@
 			showtext = urltext;
 
 		g_snprintf(open_tag, 2048, "<A HREF=\"%s\">%s", urltext, showtext);
-		surround(b->c, open_tag, "</A>");
+		gaim_gtk_surround(gtkconv, open_tag, "</A>");
 
 		g_free(open_tag);
 	}
 
-	if (b->c->link) {
-		set_state_lock(1);
-		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(b->c->link), FALSE);
-		set_state_lock(0);
+	if (gtkconv->toolbar.link) {
+		gaim_gtk_set_state_lock(TRUE);
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(gtkconv->toolbar.link),
+									FALSE);
+		gaim_gtk_set_state_lock(FALSE);
 	}
 
-	b->c->link_dialog = NULL;
+	gtkconv->dialogs.link = NULL;
 	destroy_dialog(NULL, b->window);
 }
 
-void show_insert_link(GtkWidget *linky, struct conversation *c)
+void show_insert_link(GtkWidget *linky, struct gaim_conversation *c)
 {
+	struct gaim_gtk_conversation *gtkconv;
+	struct gaim_gtk_window *gtkwin;
 	GtkWidget *table;
 	GtkWidget *label;
 	GtkWidget *hbox;
 	GtkWidget *vbox;
 
-	if (!c->link_dialog) {
+	gtkconv = GAIM_GTK_CONVERSATION(c);
+	gtkwin  = GAIM_GTK_WINDOW(gaim_conversation_get_window(c));
+
+	if (gtkconv->dialogs.link == NULL) {
 		struct linkdlg *a = g_new0(struct linkdlg, 1);
-		char *filename = g_build_filename(DATADIR, "pixmaps", "gaim", "dialogs", "gaim_question.png", NULL);
+		char *filename = g_build_filename(DATADIR, "pixmaps", "gaim",
+										  "dialogs", "gaim_question.png", NULL);
 		GtkWidget *img = gtk_image_new_from_file(filename);
 
 		g_free(filename);
 
 		a->c = c;
-		GAIM_DIALOG(a->window);
-		a->window = gtk_dialog_new_with_buttons(_("Gaim - Insert Link"), GTK_WINDOW(c->window), GTK_DIALOG_MODAL,
-						GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, _("Insert"), GTK_RESPONSE_OK, NULL);
+		a->window = gtk_dialog_new_with_buttons(_("Gaim - Insert Link"),
+				GTK_WINDOW(gtkwin->window), GTK_DIALOG_MODAL, GTK_STOCK_CANCEL,
+				GTK_RESPONSE_CANCEL, _("Insert"), GTK_RESPONSE_OK, NULL);
 
 		gtk_dialog_set_default_response(GTK_DIALOG(a->window), GTK_RESPONSE_OK);
 		gtk_container_set_border_width(GTK_CONTAINER(a->window), 6);
 		gtk_window_set_resizable(GTK_WINDOW(a->window), FALSE);
 		gtk_dialog_set_has_separator(GTK_DIALOG(a->window), FALSE);
 		gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(a->window)->vbox), 12);
-		gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(a->window)->vbox), 6);
+		gtk_container_set_border_width(
+			GTK_CONTAINER(GTK_DIALOG(a->window)->vbox), 6);
 		gtk_window_set_role(GTK_WINDOW(a->window), "insert_link");
 	
 		hbox = gtk_hbox_new(FALSE, 12);
@@ -2995,7 +3037,9 @@
 		vbox = gtk_vbox_new(FALSE, 0);
 		gtk_container_add(GTK_CONTAINER(hbox), vbox);
 	
-		label = gtk_label_new(_("Please enter the URL and description of the link that you want to insert.  The description is optional.\n"));
+		label = gtk_label_new(_("Please enter the URL and description of "
+								"the link that you want to insert.  The "
+								"description is optional.\n"));
 	
 		gtk_widget_set_size_request(GTK_WIDGET(label), 335, -1);
 		gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
@@ -3005,8 +3049,10 @@
 		hbox = gtk_hbox_new(FALSE, 6);
 		gtk_container_add(GTK_CONTAINER(vbox), hbox);
 	
-		g_signal_connect(GTK_OBJECT(a->window), "destroy", G_CALLBACK(destroy_dialog), a->window);
-		g_signal_connect(GTK_OBJECT(a->window), "destroy", G_CALLBACK(free_dialog), a);
+		g_signal_connect(G_OBJECT(a->window), "destroy",
+						 G_CALLBACK(destroy_dialog), a->window);
+		g_signal_connect(G_OBJECT(a->window), "destroy",
+						 G_CALLBACK(free_dialog), a);
 		dialogwindows = g_list_prepend(dialogwindows, a->window);
 	
 		table = gtk_table_new(4, 2, FALSE);
@@ -3033,14 +3079,15 @@
 		gtk_table_attach_defaults(GTK_TABLE(table), a->text, 1, 2, 1, 2);
 		gtk_entry_set_activates_default (GTK_ENTRY(a->text), TRUE);
 
-		g_signal_connect(G_OBJECT(a->window), "response", G_CALLBACK(do_insert_link), a);
+		g_signal_connect(G_OBJECT(a->window), "response",
+						 G_CALLBACK(do_insert_link), a);
 
 		a->toggle = linky;
-		c->link_dialog = a->window;
+		gtkconv->dialogs.link = a->window;
 	}
 
-	gtk_widget_show_all(GTK_WIDGET(c->link_dialog));
-	gdk_window_raise(c->link_dialog->window);
+	gtk_widget_show_all(gtkconv->dialogs.link);
+	gdk_window_raise(gtkconv->dialogs.link->window);
 }
 
 /*------------------------------------------------------*/
@@ -3050,34 +3097,47 @@
 GtkWidget *fgcseld = NULL;
 GtkWidget *bgcseld = NULL;
 
-void cancel_fgcolor(GtkWidget *widget, struct conversation *c)
+void cancel_fgcolor(GtkWidget *widget, struct gaim_conversation *c)
 {
-	if (c->fgcolorbtn && widget) {
-		set_state_lock(1);
-		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(c->fgcolorbtn), FALSE);
-		set_state_lock(0);
+	struct gaim_gtk_conversation *gtkconv;
+
+	gtkconv = GAIM_GTK_CONVERSATION(c);
+
+	if (gtkconv->toolbar.fgcolor && widget) {
+		gaim_gtk_set_state_lock(TRUE);
+		gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(gtkconv->toolbar.fgcolor),
+									FALSE);
+		gaim_gtk_set_state_lock(FALSE);
 	}
-	dialogwindows = g_list_remove(dialogwindows, c->fg_color_dialog);
-	gtk_widget_destroy(c->fg_color_dialog);