# HG changeset patch # User Christian Hammond # Date 1043053823 0 # Node ID 5fb47ec9bfe4ba8005d46bd8681990e3e9036b60 # Parent 2b8abf7f9cc13b26b9ba364bb9ead5667fa4d63d [gaim-migrate @ 4625] Wow, okay, where to begin with this one ;) I rewrote the whole conversation backend. It is now core/UI split. Here's how it works.. Every conversation is represented by a gaim_conversation structure. This branches out into gaim_im and gaim_chat structures. Every conversation lives in (well, normally, but it doesn't have to) a gaim_window structure. This is a _CORE_ representation of a window. There can be multiple gaim_window structures around. The gaim_window and gaim_conversation structures have UI-specific operation structures associated with them. At the moment, the only UI is GTK+, and this will be for some time. Don't start thinking you can write a QT UI now. It's just not going to happen. Everything that is done on a conversation is done through the core API. This API does core processing and then calls the UI operations for the rendering and anything else. Now, what does this give the user? - Multiple windows. - Multiple tabs per window. - Draggable tabs. - Send As menu is moved to the menubar. - Menubar for chats. - Some very cool stuff in the future, like replacing, say, IRC chat windows with an X-Chat interface, or whatever. - Later on, customizable window/conversation positioning. For developers: - Fully documented API - Core/UI split - Variable checking and mostly sane handling of incorrect variables. - Logical structure to conversations, both core and UI. - Some very cool stuff in the future, like replacing, say, IRC chat windows with an X-Chat interface, or whatever. - Later on, customizable window/conversation positioning. - Oh yeah, and the beginning of a stock icon system. Now, there are things that aren't there yet. You will see tabs even if you have them turned off. This will be fixed in time. Also, the preferences will change to work with the new structure. I'm starting school in 2 days, so it may not be done immediately, but hopefully in the next week. Enjoy! committer: Tailor Script diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 ChangeLog --- 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) diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 pixmaps/Makefile.am --- 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 diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 pixmaps/tb_drag_arrow_down.xpm --- /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", +" ... ", +" ... ", +" ... ", +" ... ", +" ... ", +" ... ", +" ... ", +" ... ", +" ... ", +".............", +" ........... ", +" ......... ", +" ....... ", +" ..... ", +" ... ", +" . "}; diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 pixmaps/tb_drag_arrow_left.xpm --- /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", +" . ", +" .. ", +" ... ", +" .... ", +" ..... ", +" ...............", +"................", +" ...............", +" ..... ", +" .... ", +" ... ", +" .. ", +" . "}; diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 pixmaps/tb_drag_arrow_right.xpm --- /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", +" . ", +" .. ", +" ... ", +" .... ", +" ..... ", +"............... ", +"................", +"............... ", +" ..... ", +" .... ", +" ... ", +" .. ", +" . "}; diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 pixmaps/tb_drag_arrow_up.xpm --- /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", +" . ", +" ... ", +" ..... ", +" ....... ", +" ......... ", +" ........... ", +".............", +" ... ", +" ... ", +" ... ", +" ... ", +" ... ", +" ... ", +" ... ", +" ... ", +" ... "}; diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 plugins/filectl.c --- 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); diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 plugins/history.c --- 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); diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 plugins/iconaway.c --- 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)); + } + } } /* diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 plugins/notify.c --- 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; } diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 plugins/ticker/ticker.c --- 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; } diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 plugins/timestamp.c --- 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) { diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/Makefile.am --- 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) - diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/Makefile.mingw --- 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 \ diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/aim.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); diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/away.c --- 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); diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/buddy.c --- 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", diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/buddy_chat.c --- 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 -#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 */ -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 */ - 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 [%s] 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; - } -} diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/conversation.c --- 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 + * Copyright (C) 2002-2003, Christian Hammond * * 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 #endif + #include -#ifndef _WIN32 -#include -#include -#include -#include -#else -#ifdef small -#undef small -#endif -#endif /*_WIN32*/ -#include +#include #include -#include -#include #include #include -#include -#ifdef USE_GTKSPELL -#include -#endif -#include "gtkimhtml.h" -#include -#include "convo.h" +#include "conversation.h" +#include "gaim.h" #include "prpl.h" -#ifdef _WIN32 -#include /* for getpid() */ -#include -#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, - "

---- New Conversation @ %s ----


\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 ("", - 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("fontface, "\">", NULL); - surround(c, pre_fontface, ""); - 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, "%s", buf); - strcpy(buf, buf2); - } - - if (font_options & OPT_FONT_ITALIC) { - g_snprintf(buf2, limit, "%s", buf); - strcpy(buf, buf2); - } - - if (font_options & OPT_FONT_UNDERLINE) { - g_snprintf(buf2, limit, "%s", buf); - strcpy(buf, buf2); - } - - if (font_options & OPT_FONT_STRIKE) { - g_snprintf(buf2, limit, "%s", buf); - strcpy(buf, buf2); - } - - if ((font_options & OPT_FONT_FACE) || c->hasfont) { - g_snprintf(buf2, limit, "%s", c->fontface, buf); - strcpy(buf, buf2); - } - - if (font_options & OPT_FONT_SIZE) { - g_snprintf(buf2, limit, "%s", fontsize, buf); - strcpy(buf, buf2); - } + strncpy(buf, buffy, limit); + g_free(buffy); - if ((font_options & OPT_FONT_FGCOL) || c->hasfg) { - g_snprintf(buf2, limit, "%s", - 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, "%s", - 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 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 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), - "", - filename, id, (int)st.st_size); - + "", + 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(""); bigbuf = g_malloc(length + 1); - g_snprintf(bigbuf, strlen(buffy) + strlen(" ") + 1, - "%s", buffy); + g_snprintf(bigbuf, + strlen(buffy) + strlen(" ") + 1, + "%s", buffy); + offset = strlen(buffy) + strlen(""); binary = TRUE; } + g_snprintf(imgtag, sizeof(imgtag), - "", - id, (int)st.st_size); - - length = length + strlen(imgtag) + st.st_size + strlen("");; + "", + id, (int)st.st_size); + + length += strlen(imgtag) + st.st_size + strlen(""); + 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("") + 1, ""); - offset= offset + strlen(""); + + strncpy(bigbuf + offset, "", + strlen("") + 1); + + offset += strlen(""); id++; - tmplist = tmplist->next; } + if (binary) { - g_snprintf(bigbuf + offset, strlen("") + 1, ""); - 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, "", + strlen("") + 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, "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, ¤t_pos, - gtk_text_buffer_get_insert(c->entry_buffer)); - if (gtk_text_iter_forward_search(¤t_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, "", ""); + 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, "", ""); -} + 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, "", ""); + 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, "", ""); + 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, "", ""); - else - advance_past(c, "", ""); - - 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, "", ""); - else - advance_past(c, "", ""); + + /* 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, "", ""); - else - advance_past(c, "", ""); + } + + 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, "", ""); - else - advance_past(c, "", ""); - - 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, "", ""); - - 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, "", ""); - - 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, "", ""); + 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, "", "", 0)) - quiet_set(c->bold, TRUE); - else if (count_tag(c->entry_buffer, "", "")) - quiet_set(c->bold, TRUE); - else - quiet_set(c->bold, FALSE); - if (invert_tags(c->entry_buffer, "", "", 0)) - quiet_set(c->italic, TRUE); - else if (count_tag(c->entry_buffer, "", "")) - quiet_set(c->italic, TRUE); - else - quiet_set(c->italic, FALSE); + ops = gaim_window_get_ops(win); - if (invert_tags(c->entry_buffer, "", 0)) - quiet_set(c->fgcolorbtn, TRUE); - else if (count_tag(c->entry_buffer, "")) - 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, "", 0)) - quiet_set(c->bgcolorbtn, TRUE); - else if (count_tag(c->entry_buffer, "")) - quiet_set(c->bgcolorbtn, TRUE); - else - quiet_set(c->bgcolorbtn, FALSE); - - if (invert_tags(c->entry_buffer, "", 0)) - quiet_set(c->font, TRUE); - else if (count_tag(c->entry_buffer, "")) - quiet_set(c->font, TRUE); - else - quiet_set(c->font, FALSE); + return NULL; +} - if (invert_tags(c->entry_buffer, "", 0)) - quiet_set(c->link, TRUE); - else if (count_tag(c->entry_buffer, "")) - 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, "", "", 0)) - quiet_set(c->underline, TRUE); - else if (count_tag(c->entry_buffer, "", "")) - 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, "(%s) %s", mdate, what); - else - g_snprintf(buf, BUF_LONG, "%s", what); - g_snprintf(buf2, sizeof(buf2), "%s
", - 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, "
\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
\n", t1); - } - fclose(fd); - } - if (logging_options & OPT_LOG_STRIP_HTML) { - g_free(t1); - } - } - } else if (flags & WFLAG_NOLOG) { - g_snprintf(buf, BUF_LONG, "%s
", 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, "(%s) " - "%s ", colour, mdate, str); - else - g_snprintf(buf, BUF_LONG, "%s ", colour, str); - g_snprintf(buf2, BUF_LONG, "" - "%s ", colour, mdate, str); - - g_free(str); - - gtk_imhtml_append_text(GTK_IMHTML(c->text), buf2, -1, 0); - - withfonttag = g_strdup_printf("%s", 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), "
", -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, "
\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
\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 [%s] 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 - -#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); -} diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/conversation.h --- /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 + * + * 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_ */ diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/convo.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 +#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); diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/core.h --- 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 #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 *); diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/dialogs.c --- 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); /* */ 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, "
%s", urltext, showtext); - surround(b->c, open_tag, ""); + gaim_gtk_surround(gtkconv, open_tag, ""); 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); - c->fg_color_dialog = NULL; + + dialogwindows = g_list_remove(dialogwindows, gtkconv->dialogs.fg_color); + gtk_widget_destroy(gtkconv->dialogs.fg_color); + gtkconv->dialogs.fg_color = NULL; } -void cancel_bgcolor(GtkWidget *widget, struct conversation *c) +void cancel_bgcolor(GtkWidget *widget, struct gaim_conversation *c) { - if (c->bgcolorbtn && widget) { - set_state_lock(1); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(c->bgcolorbtn), FALSE); - set_state_lock(0); + struct gaim_gtk_conversation *gtkconv; + + gtkconv = GAIM_GTK_CONVERSATION(c); + + if (gtkconv->toolbar.bgcolor && widget) { + gaim_gtk_set_state_lock(TRUE); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(gtkconv->toolbar.bgcolor), + FALSE); + gaim_gtk_set_state_lock(FALSE); } - dialogwindows = g_list_remove(dialogwindows, c->bg_color_dialog); - gtk_widget_destroy(c->bg_color_dialog); - c->bg_color_dialog = NULL; + + dialogwindows = g_list_remove(dialogwindows, gtkconv->dialogs.bg_color); + gtk_widget_destroy(gtkconv->dialogs.bg_color); + gtkconv->dialogs.bg_color = NULL; } void do_fgcolor(GtkWidget *widget, GtkColorSelection *colorsel) { GdkColor text_color; - struct conversation *c; + struct gaim_conversation *c; + struct gaim_gtk_conversation *gtkconv; char *open_tag; open_tag = g_malloc(30); @@ -3087,12 +3147,19 @@ c = gtk_object_get_user_data(GTK_OBJECT(colorsel)); /* GTK_IS_EDITABLE(c->entry); huh? */ - c->fgcol = text_color; - c->hasfg = 1; - g_snprintf(open_tag, 23, "", text_color.red/256, - text_color.green/256, text_color.blue/256); - surround(c, open_tag, ""); - debug_printf("#%02X%02X%02X\n", text_color.red/256, text_color.green/256, text_color.blue/256); + gtkconv = GAIM_GTK_CONVERSATION(c); + + gtkconv->fg_color = text_color; + gtkconv->has_fg = TRUE; + g_snprintf(open_tag, 23, "", + text_color.red / 256, + text_color.green / 256, + text_color.blue / 256); + gaim_gtk_surround(gtkconv, open_tag, ""); + debug_printf("#%02X%02X%02X\n", + text_color.red / 256, + text_color.green / 256, + text_color.blue / 256); g_free(open_tag); cancel_fgcolor(NULL, c); } @@ -3100,7 +3167,8 @@ void do_bgcolor(GtkWidget *widget, GtkColorSelection *colorsel) { GdkColor text_color; - struct conversation *c; + struct gaim_conversation *c; + struct gaim_gtk_conversation *gtkconv; char *open_tag; open_tag = g_malloc(30); @@ -3110,20 +3178,30 @@ c = gtk_object_get_user_data(GTK_OBJECT(colorsel)); /* GTK_IS_EDITABLE(c->entry); huh? */ - c->bgcol = text_color; - c->hasbg = 1; - g_snprintf(open_tag, 25, "", text_color.red/256, - text_color.green/256, text_color.blue/256); - surround(c, open_tag, ""); - debug_printf("#%02X%02X%02X\n", text_color.red/256, text_color.green/256, text_color.blue/256); + gtkconv = GAIM_GTK_CONVERSATION(c); + + gtkconv->bg_color = text_color; + gtkconv->has_bg = TRUE; + g_snprintf(open_tag, 25, "", + text_color.red / 256, + text_color.green / 256, + text_color.blue / 256); + gaim_gtk_surround(gtkconv, open_tag, ""); + debug_printf("#%02X%02X%02X\n", + text_color.red / 256, + text_color.green / 256, + text_color.blue / 256); g_free(open_tag); cancel_bgcolor(NULL, c); } -void show_fgcolor_dialog(struct conversation *c, GtkWidget *color) +void show_fgcolor_dialog(struct gaim_conversation *c, GtkWidget *color) { + struct gaim_gtk_conversation *gtkconv; GtkWidget *colorsel; + gtkconv = GAIM_GTK_CONVERSATION(c); + if (color == NULL) { /* we came from the prefs */ if (fgcseld) return; @@ -3143,32 +3221,35 @@ return; } - if (!c->fg_color_dialog) { - - c->fg_color_dialog = gtk_color_selection_dialog_new(_("Select Text Color")); - colorsel = GTK_COLOR_SELECTION_DIALOG(c->fg_color_dialog)->colorsel; + if (!gtkconv->dialogs.fg_color) { + + gtkconv->dialogs.fg_color = gtk_color_selection_dialog_new(_("Select Text Color")); + colorsel = GTK_COLOR_SELECTION_DIALOG(gtkconv->dialogs.fg_color)->colorsel; gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), &fgcolor); gtk_object_set_user_data(GTK_OBJECT(colorsel), c); - g_signal_connect(GTK_OBJECT(c->fg_color_dialog), "delete_event", + g_signal_connect(GTK_OBJECT(gtkconv->dialogs.fg_color), "delete_event", G_CALLBACK(delete_event_dialog), c); - g_signal_connect(GTK_OBJECT(GTK_COLOR_SELECTION_DIALOG(c->fg_color_dialog)->ok_button), + g_signal_connect(GTK_OBJECT(GTK_COLOR_SELECTION_DIALOG(gtkconv->dialogs.fg_color)->ok_button), "clicked", G_CALLBACK(do_fgcolor), colorsel); g_signal_connect(GTK_OBJECT - (GTK_COLOR_SELECTION_DIALOG(c->fg_color_dialog)->cancel_button), + (GTK_COLOR_SELECTION_DIALOG(gtkconv->dialogs.fg_color)->cancel_button), "clicked", G_CALLBACK(cancel_fgcolor), c); - gtk_widget_realize(c->fg_color_dialog); + gtk_widget_realize(gtkconv->dialogs.fg_color); } - gtk_widget_show(c->fg_color_dialog); - gdk_window_raise(c->fg_color_dialog->window); + gtk_widget_show(gtkconv->dialogs.fg_color); + gdk_window_raise(gtkconv->dialogs.fg_color->window); } -void show_bgcolor_dialog(struct conversation *c, GtkWidget *color) +void show_bgcolor_dialog(struct gaim_conversation *c, GtkWidget *color) { + struct gaim_gtk_conversation *gtkconv; GtkWidget *colorsel; + gtkconv = GAIM_GTK_CONVERSATION(c); + if (color == NULL) { /* we came from the prefs */ if (bgcseld) return; @@ -3188,42 +3269,48 @@ return; } - if (!c->bg_color_dialog) { - - c->bg_color_dialog = gtk_color_selection_dialog_new(_("Select Background Color")); - colorsel = GTK_COLOR_SELECTION_DIALOG(c->bg_color_dialog)->colorsel; + if (!gtkconv->dialogs.bg_color) { + + gtkconv->dialogs.bg_color = gtk_color_selection_dialog_new(_("Select Background Color")); + colorsel = GTK_COLOR_SELECTION_DIALOG(gtkconv->dialogs.bg_color)->colorsel; gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), &bgcolor); gtk_object_set_user_data(GTK_OBJECT(colorsel), c); - g_signal_connect(GTK_OBJECT(c->bg_color_dialog), "delete_event", + g_signal_connect(GTK_OBJECT(gtkconv->dialogs.bg_color), "delete_event", G_CALLBACK(delete_event_dialog), c); - g_signal_connect(GTK_OBJECT(GTK_COLOR_SELECTION_DIALOG(c->bg_color_dialog)->ok_button), + g_signal_connect(GTK_OBJECT(GTK_COLOR_SELECTION_DIALOG(gtkconv->dialogs.bg_color)->ok_button), "clicked", G_CALLBACK(do_bgcolor), colorsel); g_signal_connect(GTK_OBJECT - (GTK_COLOR_SELECTION_DIALOG(c->bg_color_dialog)->cancel_button), + (GTK_COLOR_SELECTION_DIALOG(gtkconv->dialogs.bg_color)->cancel_button), "clicked", G_CALLBACK(cancel_bgcolor), c); - gtk_widget_realize(c->bg_color_dialog); + gtk_widget_realize(gtkconv->dialogs.bg_color); } - gtk_widget_show(c->bg_color_dialog); - gdk_window_raise(c->bg_color_dialog->window); + gtk_widget_show(gtkconv->dialogs.bg_color); + gdk_window_raise(gtkconv->dialogs.bg_color->window); } /*------------------------------------------------------------------------*/ /* Font Selection Dialog */ /*------------------------------------------------------------------------*/ -void cancel_font(GtkWidget *widget, struct conversation *c) +void cancel_font(GtkWidget *widget, struct gaim_conversation *c) { - if (c->font && widget) { - set_state_lock(1); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(c->font), FALSE); - set_state_lock(0); + struct gaim_gtk_conversation *gtkconv; + + gtkconv = GAIM_GTK_CONVERSATION(c); + + if (gtkconv->toolbar.normal_size && widget) { + 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); } - dialogwindows = g_list_remove(dialogwindows, c->font_dialog); - gtk_widget_destroy(c->font_dialog); - c->font_dialog = NULL; + + dialogwindows = g_list_remove(dialogwindows, gtkconv->dialogs.font); + gtk_widget_destroy(gtkconv->dialogs.font); + gtkconv->dialogs.font = NULL; } void apply_font(GtkWidget *widget, GtkFontSelection *fontsel) @@ -3232,7 +3319,7 @@ but for now only works with font face */ int i = 0; char *fontname; - struct conversation *c = gtk_object_get_user_data(GTK_OBJECT(fontsel)); + struct gaim_conversation *c = gtk_object_get_user_data(GTK_OBJECT(fontsel)); if (c) { fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(fontsel)); @@ -3240,7 +3327,7 @@ i++; } fontname[i] = 0; - set_font_face(fontname, c); + gaim_gtk_set_font_face(GAIM_GTK_CONVERSATION(c), fontname); } else { fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(fontsel)); while(fontface[i] && !isdigit(fontname[i]) && i < sizeof(fontface)) { @@ -3259,9 +3346,13 @@ fontseld = NULL; } -void show_font_dialog(struct conversation *c, GtkWidget *font) +void show_font_dialog(struct gaim_conversation *c, GtkWidget *font) { + struct gaim_gtk_conversation *gtkconv; char fonttif[128]; + + gtkconv = GAIM_GTK_CONVERSATION(c); + if (!font) { /* we came from the prefs dialog */ if (fontseld) return; @@ -3288,35 +3379,36 @@ return; } - if (!c->font_dialog) { - c->font_dialog = gtk_font_selection_dialog_new(_("Select Font")); + if (!gtkconv->dialogs.font) { + gtkconv->dialogs.font = gtk_font_selection_dialog_new(_("Select Font")); if (font) - gtk_object_set_user_data(GTK_OBJECT(c->font_dialog), c); + gtk_object_set_user_data(GTK_OBJECT(gtkconv->dialogs.font), c); else - gtk_object_set_user_data(GTK_OBJECT(c->font_dialog), NULL); - - if (c->fontface[0]) { - g_snprintf(fonttif, sizeof(fonttif), "%s 12", c->fontface); - gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(c->font_dialog), + gtk_object_set_user_data(GTK_OBJECT(gtkconv->dialogs.font), NULL); + + if (gtkconv->fontface[0]) { + g_snprintf(fonttif, sizeof(fonttif), "%s 12", gtkconv->fontface); + gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(gtkconv->dialogs.font), fonttif); } else { - gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(c->font_dialog), + gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(gtkconv->dialogs.font), DEFAULT_FONT_FACE); } - g_signal_connect(GTK_OBJECT(c->font_dialog), "delete_event", + g_signal_connect(GTK_OBJECT(gtkconv->dialogs.font), "delete_event", G_CALLBACK(delete_event_dialog), c); - g_signal_connect(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(c->font_dialog)->ok_button), - "clicked", G_CALLBACK(apply_font), c->font_dialog); - g_signal_connect(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(c->font_dialog)->cancel_button), + g_signal_connect(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(gtkconv->dialogs.font)->ok_button), + "clicked", G_CALLBACK(apply_font), gtkconv->dialogs.font); + g_signal_connect(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(gtkconv->dialogs.font)->cancel_button), "clicked", G_CALLBACK(cancel_font), c); - gtk_widget_realize(c->font_dialog); + gtk_widget_realize(gtkconv->dialogs.font); } - gtk_widget_show(c->font_dialog); - gdk_window_raise(c->font_dialog->window); + + gtk_widget_show(gtkconv->dialogs.font); + gdk_window_raise(gtkconv->dialogs.font->window); } /*------------------------------------------------------------------------*/ @@ -3612,16 +3704,21 @@ /* smiley dialog */ -void close_smiley_dialog(GtkWidget *widget, struct conversation *c) +void close_smiley_dialog(GtkWidget *widget, struct gaim_conversation *c) { - if (c->smiley) { - set_state_lock(1); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(c->smiley), FALSE); - set_state_lock(0); + struct gaim_gtk_conversation *gtkconv; + + gtkconv = GAIM_GTK_CONVERSATION(c); + + if (gtkconv->toolbar.smiley) { + gaim_gtk_set_state_lock(TRUE); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(gtkconv->toolbar.smiley), + FALSE); + gaim_gtk_set_state_lock(FALSE); } - dialogwindows = g_list_remove(dialogwindows, c->smiley_dialog); - gtk_widget_destroy(c->smiley_dialog); - c->smiley_dialog = NULL; + dialogwindows = g_list_remove(dialogwindows, gtkconv->dialogs.smiley); + gtk_widget_destroy(gtkconv->dialogs.smiley); + gtkconv->dialogs.smiley = NULL; } void set_smiley(GtkWidget *w, char *face) @@ -3641,14 +3738,17 @@ return; } -void insert_smiley_text(GtkWidget *widget, struct conversation *c) +void insert_smiley_text(GtkWidget *widget, struct gaim_conversation *c) { - gtk_text_buffer_insert_at_cursor(c->entry_buffer, - current_smiley, -1); + struct gaim_gtk_conversation *gtkconv; + + gtkconv = GAIM_GTK_CONVERSATION(c); + + gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, current_smiley, -1); close_smiley_dialog(NULL, c); } -static void toolbar_add_smiley(struct conversation *c, GtkWidget *bar, char* path, char *filename, char *face) +static void toolbar_add_smiley(struct gaim_conversation *c, GtkWidget *bar, char* path, char *filename, char *face) { GtkWidget *image; GtkWidget *button; @@ -3666,18 +3766,21 @@ gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); } -void show_smiley_dialog(struct conversation *c, GtkWidget *widget) +void show_smiley_dialog(struct gaim_conversation *c, GtkWidget *widget) { + struct gaim_gtk_conversation *gtkconv; GtkWidget *dialog; GtkWidget *vbox, *smiley_box = NULL; GtkWidget *win; GtkWidget *bbox; char *smiley_path = 0; - if (c->smiley_dialog) + gtkconv = GAIM_GTK_CONVERSATION(c); + + if (gtkconv->dialogs.smiley) return; - win = c->window; + win = GAIM_GTK_WINDOW(gaim_conversation_get_window(c))->window; GAIM_DIALOG(dialog); gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, TRUE); @@ -3730,13 +3833,14 @@ /* connect signals */ gtk_object_set_user_data(GTK_OBJECT(dialog), "smiley dialog"); - g_signal_connect(GTK_OBJECT(dialog), "delete_event", G_CALLBACK(delete_event_dialog), c); + g_signal_connect(G_OBJECT(dialog), "delete_event", + G_CALLBACK(delete_event_dialog), c); /* show everything */ gtk_window_set_title(GTK_WINDOW(dialog), _("Smile!")); gtk_widget_show_all(dialog); - c->smiley_dialog = dialog; + gtkconv->dialogs.smiley = dialog; return; } @@ -4595,7 +4699,9 @@ } -GtkWidget *gaim_pixbuf_button_from_stock(char *text, char *icon, GaimButtonStyle style) +GtkWidget * +gaim_pixbuf_button_from_stock(const char *text, const char *icon, + GaimButtonStyle style) { GtkWidget *button, *image, *label, *bbox; button = gtk_button_new(); @@ -5291,3 +5397,4 @@ /*------------------------------------------------------------------------*/ /* End dialog for setting v-card info */ /*------------------------------------------------------------------------*/ + diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/dnd-hints.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dnd-hints.c Mon Jan 20 09:10:23 2003 +0000 @@ -0,0 +1,196 @@ +/* + * Copyright (C) 2002-2003, Christian Hammond + * + * Copyright (C) 2001 Ricardo Fernández Pascual + * + * 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, 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. + */ + +#include "dnd-hints.h" + +#include +#include +#include + +typedef struct +{ + GtkWidget *widget; + gchar *filename; + gint ox; + gint oy; + +} HintWindowInfo; + +/** + * Info about each hint widget. See DndHintWindowId enum. + */ +HintWindowInfo hint_windows[] = { + { NULL, "tb_drag_arrow_up.xpm", -13/2, 0 }, + { NULL, "tb_drag_arrow_down.xpm", -13/2, -16 }, + { NULL, "tb_drag_arrow_left.xpm", 0, -13/2 }, + { NULL, "tb_drag_arrow_right.xpm", -16, -13/2 }, + { NULL, NULL, 0, 0 } +}; + +static GtkWidget * +dnd_hints_init_window(const gchar *fname) +{ + GdkPixbuf *pixbuf; + GdkPixmap *pixmap; + GdkBitmap *bitmap; + GtkWidget *pix; + GtkWidget *win; + + pixbuf = gdk_pixbuf_new_from_file(fname, NULL); + g_return_val_if_fail(pixbuf, NULL); + + gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, &bitmap, 128); + gdk_pixbuf_unref(pixbuf); + + gtk_widget_push_visual(gdk_rgb_get_visual()); + gtk_widget_push_colormap(gdk_rgb_get_cmap()); + win = gtk_window_new(GTK_WINDOW_POPUP); + pix = gtk_pixmap_new(pixmap, bitmap); + gtk_widget_realize(win); + gtk_container_add(GTK_CONTAINER(win), pix); + gtk_widget_shape_combine_mask(win, bitmap, 0, 0); + gtk_widget_pop_visual(); + gtk_widget_pop_colormap(); + + gdk_pixmap_unref(pixmap); + gdk_bitmap_unref(bitmap); + + gtk_widget_show_all(pix); + + return win; +} + +static void +get_widget_coords(GtkWidget *w, gint *x1, gint *y1, gint *x2, gint *y2) +{ + gint ox, oy, width, height; + + if (w->parent && w->parent->window == w->window) + { + get_widget_coords(w->parent, &ox, &oy, NULL, NULL); + ox += w->allocation.x; + oy += w->allocation.y; + height = w->allocation.height; + width = w->allocation.width; + } + else + { + gdk_window_get_origin(w->window, &ox, &oy); + gdk_window_get_size(w->window, &width, &height); + } + + if (x1) *x1 = ox; + if (y1) *y1 = oy; + if (x2) *x2 = ox + width; + if (y2) *y2 = oy + height; +} + +static void +dnd_hints_init(void) +{ + static gboolean done = FALSE; + gint i; + + if (done) + return; + + done = TRUE; + + for (i = 0; hint_windows[i].filename != NULL; i++) { + gchar *fname; + + fname = g_build_filename(DATADIR, "pixmaps", "gaim", + hint_windows[i].filename, NULL); + + hint_windows[i].widget = dnd_hints_init_window(fname); + + g_free(fname); + } +} + +void +dnd_hints_hide_all(void) +{ + gint i; + + for (i = 0; hint_windows[i].filename != NULL; i++) + dnd_hints_hide(i); +} + +void +dnd_hints_hide(DndHintWindowId i) +{ + GtkWidget *w = hint_windows[i].widget; + + if (w && GTK_IS_WIDGET(w)) + gtk_widget_hide(w); +} + +void +dnd_hints_show(DndHintWindowId id, gint x, gint y) +{ + GtkWidget *w; + + dnd_hints_init(); + + w = hint_windows[id].widget; + + if (w && GTK_IS_WIDGET(w)) + { + gtk_widget_set_uposition(w, hint_windows[id].ox + x, + hint_windows[id].oy + y); + gtk_widget_show(w); + } +} + +void +dnd_hints_show_relative(DndHintWindowId id, GtkWidget *widget, + DndHintPosition horiz, DndHintPosition vert) +{ + gint x1, x2, y1, y2; + gint x = 0, y = 0; + + get_widget_coords(widget, &x1, &y1, &x2, &y2); + + switch (horiz) + { + case HINT_POSITION_RIGHT: x = x2; break; + case HINT_POSITION_LEFT: x = x1; break; + case HINT_POSITION_CENTER: x = (x1 + x2) / 2; break; + default: + /* should not happen */ + g_warning("Invalid parameter to dnd_hints_show_relative"); + break; + } + + switch (vert) + { + case HINT_POSITION_TOP: y = y1; break; + case HINT_POSITION_BOTTOM: y = y2; break; + case HINT_POSITION_CENTER: y = (y1 + y2) / 2; break; + default: + /* should not happen */ + g_warning("Invalid parameter to dnd_hints_show_relative"); + break; + } + + dnd_hints_show(id, x, y); +} + diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/dnd-hints.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dnd-hints.h Mon Jan 20 09:10:23 2003 +0000 @@ -0,0 +1,85 @@ +/** + * @file dnd-hints.h Drag-and-Drop arrow hints + * + * Copyright (C) 2002-2003, Christian Hammond + * + * Copyright (C) 2001 Ricardo Fernández Pascual + * + * 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, 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 _GAIM_DND_HINTS_H_ +#define _GAIM_DND_HINTS_H_ + +#include +#include + +/** + * Conversation drag-and-drop arrow types. + */ +typedef enum +{ + HINT_ARROW_UP, /**< Up arrow. */ + HINT_ARROW_DOWN, /**< Down arrow. */ + HINT_ARROW_LEFT, /**< Left arrow. */ + HINT_ARROW_RIGHT /**< Right arrow. */ + +} DndHintWindowId; + +/** + * Conversation drag-and-drop arrow positions. + */ +typedef enum { + + HINT_POSITION_RIGHT, /**< Position to the right of a tab. */ + HINT_POSITION_LEFT, /**< Position to the left of a tab. */ + HINT_POSITION_TOP, /**< Position above a tab. */ + HINT_POSITION_BOTTOM, /**< Position below a tab. */ + HINT_POSITION_CENTER /**< Position in the center of a tab. */ + +} DndHintPosition; + +/** + * Shows a drag-and-drop hint at the specified location. + * + * @param id The ID of the hint to show. + * @param x The X location to show it at. + * @param y The Y location to show it at. + */ +void dnd_hints_show(DndHintWindowId id, gint x, gint y); + +/** + * Hides the specified drag-and-drop hint. + * + * @param id The ID of the hint to hide. + */ +void dnd_hints_hide(DndHintWindowId id); + +/** + * Hides all drag-and-drop hints. + */ +void dnd_hints_hide_all(void); + +/** + * Shows a drag-and-drop hint relative to a widget. + * + * @param id The ID of the hint. + * @param widget The widget that the hint is relative to. + * @param horiz The horizontal relative position. + * @param vert The vertical relative position. + */ +void dnd_hints_show_relative(DndHintWindowId id, GtkWidget *widget, + DndHintPosition horiz, DndHintPosition vert); + +#endif /* _GAIM_DND_HINTS_H_ */ diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/gaim.h --- a/src/gaim.h Mon Jan 20 07:00:10 2003 +0000 +++ b/src/gaim.h Mon Jan 20 09:10:23 2003 +0000 @@ -368,16 +368,16 @@ GdkPixmap **pixmap, GdkBitmap **mask); /* Functions in buddy_chat.c */ -extern void show_new_buddy_chat(struct conversation *); -extern void chat_set_topic(struct conversation*, char*, char*); -/*extern void add_chat_buddy(struct conversation *, char *);*/ -extern void add_chat_buddy(struct conversation *, char *, char *); -extern void rename_chat_buddy(struct conversation *, char *, char *); -extern void remove_chat_buddy(struct conversation *, char *, char *); +#if 0 +extern void show_new_buddy_chat(struct gaim_conversation *); +extern void chat_set_topic(struct gaim_conversation*, char*, char*); +/*extern void add_chat_buddy(struct gaim_conversation *, char *);*/ +extern void add_chat_buddy(struct gaim_conversation *, char *, char *); +extern void rename_chat_buddy(struct gaim_conversation *, char *, char *); +extern void remove_chat_buddy(struct gaim_conversation *, char *, char *); +#endif /* Functions in conversation.c */ -extern void write_to_conv(struct conversation *, char *, int, char *, time_t, int); -extern struct conversation *find_conversation(const char *); extern void set_anim(); extern void set_blist_tab(); @@ -402,7 +402,7 @@ }; extern void grab_url(char *, gboolean, void (*callback)(gpointer, char *, unsigned long), gpointer); -extern gchar *strip_html(gchar *); +extern gchar *strip_html(const gchar *); struct g_url *parse_url(char *url); /* Functions in idle.c */ @@ -481,8 +481,8 @@ extern void rm_log(struct log_conversation *); extern struct log_conversation *find_log_info(const char *); extern void update_log_convs(); -extern void save_convo(GtkWidget *save, struct conversation *c); -extern char *html_logize(char *p); +extern void save_convo(GtkWidget *save, struct gaim_conversation *c); +extern char *html_logize(const char *p); /*------------------------------------------------------------------------*/ /* Multi-Entry dialog and vCard dialog support */ diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/gtkconv.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gtkconv.c Mon Jan 20 09:10:23 2003 +0000 @@ -0,0 +1,4905 @@ +/* + * gaim + * + * Copyright (C) 2002-2003, Christian Hammond + * + * 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 + * + */ +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#ifndef _WIN32 +#include +#include +#include +#include +#else +#ifdef small +#undef small +#endif +#endif /*_WIN32*/ +#include +#include +#include +#include +#include +#include +#include +#ifdef USE_GTKSPELL +#include +#endif +#include "gtkimhtml.h" +#include +#include "prpl.h" +#include "gtkimhtml.h" +#include "dnd-hints.h" + +static char nick_colors[][8] = { + "#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(*nick_colors)) + +#define SCALE(x) \ + ((gdk_pixbuf_animation_get_width(x) <= 48 && \ + gdk_pixbuf_animation_get_height(x) <= 48) ? 48 : 50) + +struct InviteBuddyInfo +{ + GtkWidget *window; + + GtkWidget *entry; + GtkWidget *message; + + struct gaim_conversation *conv; +}; + +char fontface[128] = { 0 }; +int fontsize = 3; + +static GtkWidget *invite_dialog = NULL; +#if 0 +static GtkWidget *invite_entry; +static GtkWidget *invite_mess; +#endif + +static volatile gboolean state_lock = FALSE; + +/* Prototypes. <-- because Paco-Paco hates this comment. */ +static void check_everything(GtkTextBuffer *buffer); +static void quiet_set(GtkWidget *tb, gboolean active); +static void move_next_tab(struct gaim_conversation *conv); +static void do_bold(GtkWidget *bold, struct gaim_gtk_conversation *gtkconv); +static void do_italic(GtkWidget *italic, struct gaim_gtk_conversation *gtkconv); +static void do_underline(GtkWidget *underline, struct gaim_gtk_conversation *gtkconv); +static void do_small(GtkWidget *small, struct gaim_gtk_conversation *gtkconv); +static void do_normal(GtkWidget *small, struct gaim_gtk_conversation *gtkconv); +static void do_big(GtkWidget *small, struct gaim_gtk_conversation *gtkconv); +static void toggle_font(GtkWidget *font, struct gaim_conversation *conv); +static void toggle_fg_color(GtkWidget *color, struct gaim_conversation *conv); +static void toggle_bg_color(GtkWidget *color, struct gaim_conversation *conv); +static void got_typing_keypress(struct gaim_conversation *conv, gboolean first); +static GList *generate_invite_user_names(struct gaim_connection *gc); +static void add_chat_buddy_common(struct gaim_conversation *conv, + const char *name, int pos); +static void tab_complete(struct gaim_conversation *conv); +static void update_send_as_selection(struct gaim_window *win); + +/************************************************************************** + * Callbacks + **************************************************************************/ +static void +do_insert_image_cb(GObject *obj, GtkWidget *wid) +{ + struct gaim_conversation *conv; + struct gaim_gtk_conversation *gtkconv; + struct gaim_im *im; + const char *name; + const char *filename; + char *buf; + struct stat st; + int id; + + conv = g_object_get_data(obj, "user_data"); + gtkconv = GAIM_GTK_CONVERSATION(conv); + im = GAIM_IM(conv); + name = gtk_file_selection_get_filename(GTK_FILE_SELECTION(wid)); + id = g_slist_length(im->images) + 1; + + if (file_is_dir(name, wid)) + return; + + gtk_widget_destroy(wid); + + if (!name) + return; + + 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("", + filename, id, (int)st.st_size); + im->images = g_slist_append(im->images, g_strdup(name)); + gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER(gtkconv->entry_buffer), + buf, -1); + g_free(buf); +} + +static gint +close_win_cb(GtkWidget *w, GdkEventAny *e, gpointer d) +{ + struct gaim_window *win = (struct gaim_window *)d; + + gaim_window_destroy(win); +} + +static gint +close_conv_cb(GtkWidget *w, gpointer d) +{ + struct gaim_conversation *conv = (struct gaim_conversation *)d; + + gaim_conversation_destroy(conv); +} + +static void +insert_image_cb(GtkWidget *save, struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + char buf[BUF_LONG]; + GtkWidget *window; + + if (gaim_gtk_is_state_locked()) + return; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + 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); + + g_object_set_data(G_OBJECT(GTK_FILE_SELECTION(window)->ok_button), + "user_data", conv); + g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(window)->ok_button), + "clicked", G_CALLBACK(do_insert_image_cb), window); + g_signal_connect_swapped( + G_OBJECT(GTK_FILE_SELECTION(window)->cancel_button), + "clicked", G_CALLBACK(gtk_widget_destroy), window); + + gtk_widget_show(window); + + gaim_gtk_set_state_lock(TRUE); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(gtkconv->toolbar.image), + FALSE); + gaim_gtk_set_state_lock(FALSE); +} + +static void +insert_link_cb(GtkWidget *w, struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + + if (gaim_gtk_is_state_locked()) + return; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gtkconv->toolbar.link))) + show_insert_link(gtkconv->toolbar.link, conv); + else if (gtkconv->dialogs.link) + cancel_link(gtkconv->toolbar.link, conv); + else + gaim_gtk_advance_past(gtkconv, "", ""); + + gtk_widget_grab_focus(gtkconv->entry); +} + +static void +insert_smiley_cb(GtkWidget *smiley, struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + + if (gaim_gtk_is_state_locked()) + return; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(smiley))) + show_smiley_dialog(conv, smiley); + else if (gtkconv->dialogs.smiley) + close_smiley_dialog(smiley, conv); + + gtk_widget_grab_focus(gtkconv->entry); +} + +static void +menu_save_as_cb(gpointer data, guint action, GtkWidget *widget) +{ + struct gaim_window *win = (struct gaim_window *)data; + + save_convo(NULL, gaim_window_get_active_conversation(win)); +} + +static void +menu_view_history_cb(gpointer data, guint action, GtkWidget *widget) +{ + struct gaim_window *win = (struct gaim_window *)data; + + conv_show_log(NULL, gaim_window_get_active_conversation(win)); +} +static void +menu_insert_link_cb(gpointer data, guint action, GtkWidget *widget) +{ + struct gaim_window *win = (struct gaim_window *)data; + struct gaim_conversation *conv; + struct gaim_gtk_conversation *gtkconv; + + conv = gaim_window_get_active_conversation(win); + gtkconv = GAIM_GTK_CONVERSATION(conv); + + show_insert_link(gtkconv->toolbar.link, conv); +} + +static void +menu_insert_image_cb(gpointer data, guint action, GtkWidget *widget) +{ + struct gaim_window *win = (struct gaim_window *)data; + + insert_image_cb(NULL, gaim_window_get_active_conversation(win)); +} + +static void +menu_close_conv_cb(gpointer data, guint action, GtkWidget *widget) +{ + struct gaim_window *win = (struct gaim_window *)data; + + close_conv_cb(NULL, gaim_window_get_active_conversation(win)); +} + +static void +menu_logging_cb(gpointer data, guint action, GtkWidget *widget) +{ + struct gaim_window *win = (struct gaim_window *)data; + struct gaim_conversation *conv; + + if (gaim_gtk_is_state_locked()) + return; + + conv = gaim_window_get_active_conversation(win); + + gaim_conversation_set_logging(conv, !gaim_conversation_is_logging(conv)); +} + +static void +menu_sounds_cb(gpointer data, guint action, GtkWidget *widget) +{ + struct gaim_window *win = (struct gaim_window *)data; + struct gaim_conversation *conv; + struct gaim_gtk_conversation *gtkconv; + + if (gaim_gtk_is_state_locked()) + return; + + conv = gaim_window_get_active_conversation(win); + gtkconv = GAIM_GTK_CONVERSATION(conv); + + gtkconv->make_sound = !gtkconv->make_sound; +} + +static gboolean +entry_key_pressed_cb_1(GtkTextBuffer *buffer) +{ + check_everything(buffer); + + return FALSE; +} + +static void +send_cb(GtkWidget *widget, struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + char *buf, *buf2; + GtkTextIter start_iter, end_iter; + int limit; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, &start_iter); + gtk_text_buffer_get_end_iter(gtkconv->entry_buffer, &end_iter); + buf2 = gtk_text_buffer_get_text(gtkconv->entry_buffer, + &start_iter, &end_iter, FALSE); + + quiet_set(gtkconv->toolbar.bold, FALSE); + quiet_set(gtkconv->toolbar.italic, FALSE); + quiet_set(gtkconv->toolbar.underline, FALSE); + quiet_set(gtkconv->toolbar.normal_size, FALSE); + quiet_set(gtkconv->toolbar.fgcolor, FALSE); + quiet_set(gtkconv->toolbar.bgcolor, FALSE); + quiet_set(gtkconv->toolbar.link, FALSE); + + gtk_widget_grab_focus(gtkconv->entry); + + limit = 32 * 1024; /* This will be done again in gaim_im_send. *shrug* */ + + buf = g_malloc(limit); + strncpy(buf, buf2, limit); + + g_free(buf2); + + if (strlen(buf) == 0) { + g_free(buf); + + return; + } + + buf2 = g_malloc(limit); + + if (gaim_conversation_get_gc(conv)->flags & OPT_CONN_HTML) { + if (font_options & OPT_FONT_BOLD) { + g_snprintf(buf2, limit, "%s", buf); + strcpy(buf, buf2); + } + + if (font_options & OPT_FONT_ITALIC) { + g_snprintf(buf2, limit, "%s", buf); + strcpy(buf, buf2); + } + + if (font_options & OPT_FONT_UNDERLINE) { + g_snprintf(buf2, limit, "%s", buf); + strcpy(buf, buf2); + } + + if (font_options & OPT_FONT_STRIKE) { + g_snprintf(buf2, limit, "%s", buf); + strcpy(buf, buf2); + } + + if ((font_options & OPT_FONT_FACE) || gtkconv->has_font) { + g_snprintf(buf2, limit, + "%s", gtkconv->fontface, buf); + strcpy(buf, buf2); + } + + if (font_options & OPT_FONT_SIZE) { + g_snprintf(buf2, limit, + "%s", fontsize, buf); + strcpy(buf, buf2); + } + + if ((font_options & OPT_FONT_FGCOL) || gtkconv->has_fg) { + g_snprintf(buf2, limit, + "%s", + gtkconv->fg_color.red / 256, + gtkconv->fg_color.green / 256, + gtkconv->fg_color.blue / 256, buf); + strcpy(buf, buf2); + } + + if ((font_options & OPT_FONT_BGCOL) || gtkconv->has_bg) { + g_snprintf(buf2, limit, + "%s", + gtkconv->fg_color.red / 256, + gtkconv->fg_color.green / 256, + gtkconv->fg_color.blue / 256, buf); + strcpy(buf, buf2); + } + } + + g_free(buf2); + + if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) + gaim_im_send(GAIM_IM(conv), buf); + else + gaim_chat_send(GAIM_CHAT(conv), buf); + + g_free(buf); + + gtk_text_buffer_set_text(gtkconv->entry_buffer, "", -1); +} + +static void +add_cb(GtkWidget *widget, struct gaim_conversation *conv) +{ + struct gaim_connection *gc; + struct buddy *b; + const char *name; + + gc = gaim_conversation_get_gc(conv); + name = gaim_conversation_get_name(conv); + b = find_buddy(gc->user, name); + + if (b != NULL) + show_confirm_del(gc, (char *)name); + else if (gc != NULL) + show_add_buddy(gc, (char *)name, NULL, NULL); + + gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); +} + +static void +info_cb(GtkWidget *widget, struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { + struct gaim_gtk_chat_pane *gtkchat; + GtkTreeIter iter; + GtkTreeModel *model; + GtkTreeSelection *sel; + const char *name; + + gtkchat = gtkconv->u.chat; + + model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkchat->list)); + + if (gtk_tree_selection_get_selected(sel, NULL, &iter)) + gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &name, -1); + else + return; + + serv_get_info(gaim_conversation_get_gc(conv), (char *)name); + } + else { + serv_get_info(gaim_conversation_get_gc(conv), + (char *)gaim_conversation_get_name(conv)); + + gtk_widget_grab_focus(gtkconv->entry); + } +} + +static void +warn_cb(GtkWidget *widget, struct gaim_conversation *conv) +{ + show_warn_dialog(gaim_conversation_get_gc(conv), + (char *)gaim_conversation_get_name(conv)); + + gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); +} + +static void +block_cb(GtkWidget *widget, struct gaim_conversation *conv) +{ + struct gaim_connection *gc; + + gc = gaim_conversation_get_gc(conv); + + if (gc != NULL) + show_add_perm(gc, (char *)gaim_conversation_get_name(conv), FALSE); + + gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); +} + +void +im_cb(GtkWidget *widget, struct gaim_conversation *conv) +{ + struct gaim_conversation *conv2; + struct gaim_gtk_conversation *gtkconv; + struct gaim_gtk_chat_pane *gtkchat; + GtkTreeIter iter; + GtkTreeModel *model; + GtkTreeSelection *sel; + const char *name; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + gtkchat = gtkconv->u.chat; + + model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkchat->list)); + + if (gtk_tree_selection_get_selected(sel, NULL, &iter)) + gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &name, -1); + else + return; + + if (*name == '@') name++; + if (*name == '+') name++; + + conv2 = gaim_find_conversation(name); + + if (conv2 != NULL) + gaim_window_raise(gaim_conversation_get_window(conv2)); + else + conv2 = gaim_conversation_new(GAIM_CONV_IM, name); + + gaim_conversation_set_user(conv2, gaim_conversation_get_user(conv)); +} + +static void +ignore_cb(GtkWidget *w, struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + struct gaim_gtk_chat_pane *gtkchat; + struct gaim_chat *chat; + GtkTreeIter iter; + GtkTreeModel *model; + GtkTreeSelection *sel; + const char *name; + int pos; + + chat = GAIM_CHAT(conv); + gtkconv = GAIM_GTK_CONVERSATION(conv); + gtkchat = gtkconv->u.chat; + + model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkchat->list)); + + if (gtk_tree_selection_get_selected(sel, NULL, &iter)) { + gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &name, -1); + gtk_list_store_remove(GTK_LIST_STORE(model), &iter); + } + else + return; + + pos = g_list_index(gaim_chat_get_users(chat), name); + + if (gaim_chat_is_user_ignored(chat, name)) + gaim_chat_unignore(chat, name); + else + gaim_chat_ignore(chat, name); + + add_chat_buddy_common(conv, name, pos); +} + +static void +menu_im_cb(GtkWidget *w, struct gaim_conversation *conv) +{ + const char *who; + struct gaim_conversation *conv2; + + who = g_object_get_data(G_OBJECT(w), "user_data"); + + conv2 = gaim_find_conversation(who); + + if (conv2 != NULL) + gaim_window_show(gaim_conversation_get_window(conv2)); + else { + conv2 = gaim_conversation_new(GAIM_CONV_IM, who); + gaim_conversation_set_user(conv2, gaim_conversation_get_user(conv)); + } +} + +static void +menu_info_cb(GtkWidget *w, struct gaim_conversation *conv) +{ + struct gaim_connection *gc; + char *who; + + gc = gaim_conversation_get_gc(conv); + who = g_object_get_data(G_OBJECT(w), "user_data"); + + if (gc != NULL) { + /* + * If there are special needs for getting info on users in + * buddy chat "rooms"... + */ + if (gc->prpl->get_cb_info != NULL) + gc->prpl->get_cb_info(gc, gaim_chat_get_id(GAIM_CHAT(conv)), who); + else + gc->prpl->get_info(gc, who); + } +} + +static void +menu_away_cb(GtkWidget *w, struct gaim_conversation *conv) +{ + struct gaim_connection *gc; + char *who; + + gc = gaim_conversation_get_gc(conv); + who = g_object_get_data(G_OBJECT(w), "user_data"); + + if (gc != NULL) { + /* + * May want to expand this to work similarly to menu_info_cb? + */ + + if (gc->prpl->get_cb_away != NULL) + gc->prpl->get_cb_away(gc, gaim_chat_get_id(GAIM_CHAT(conv)), who); + } +} + +static void +menu_add_cb(GtkWidget *w, struct gaim_conversation *conv) +{ + struct gaim_connection *gc; + struct buddy *b; + char *name; + + gc = gaim_conversation_get_gc(conv); + name = g_object_get_data(G_OBJECT(w), "user_data"); + b = find_buddy(gc->user, name); + + if (b != NULL) + show_confirm_del(gc, name); + else if (gc != NULL) + show_add_buddy(gc, name, NULL, NULL); + + gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); +} + +static gint +right_click_chat_cb(GtkWidget *widget, GdkEventButton *event, + struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + struct gaim_gtk_chat_pane *gtkchat; + struct gaim_connection *gc; + struct aim_user *user; + GtkTreePath *path; + GtkTreeIter iter; + GtkTreeModel *model; + GtkTreeViewColumn *column; + gchar *who; + int x, y; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + gtkchat = gtkconv->u.chat; + user = gaim_conversation_get_user(conv); + gc = user->gc; + + model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); + + gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(gtkchat->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(gtkchat->list))), path); + + gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path); + gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &who, -1); + + if (event->button == 1 && event->type == GDK_2BUTTON_PRESS) { + struct gaim_conversation *c; + + if ((c = gaim_find_conversation(who)) == NULL) + c = gaim_conversation_new(GAIM_CONV_IM, who); + + gaim_conversation_set_user(c, user); + } + 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(G_OBJECT(button), "activate", + G_CALLBACK(menu_im_cb), conv); + g_object_set_data(G_OBJECT(button), "user_data", who); + gtk_menu_append(GTK_MENU(menu), button); + gtk_widget_show(button); + + if (gaim_chat_is_user_ignored(GAIM_CHAT(conv), who)) + button = gtk_menu_item_new_with_label(_("Un-Ignore")); + else + button = gtk_menu_item_new_with_label(_("Ignore")); + + g_signal_connect(G_OBJECT(button), "activate", + G_CALLBACK(ignore_cb), conv); + g_object_set_data(G_OBJECT(button), "user_data", who); + gtk_menu_append(GTK_MENU(menu), button); + gtk_widget_show(button); + + if (gc && gc->prpl->get_info) { + button = gtk_menu_item_new_with_label(_("Info")); + g_signal_connect(G_OBJECT(button), "activate", + G_CALLBACK(menu_info_cb), conv); + g_object_set_data(G_OBJECT(button), "user_data", who); + gtk_menu_append(GTK_MENU(menu), button); + gtk_widget_show(button); + } + + if (gc && gc->prpl->get_cb_away) { + button = gtk_menu_item_new_with_label(_("Get Away Msg")); + g_signal_connect(G_OBJECT(button), "activate", + G_CALLBACK(menu_away_cb), conv); + g_object_set_data(G_OBJECT(button), "user_data", who); + gtk_menu_append(GTK_MENU(menu), button); + gtk_widget_show(button); + } + + /* Added by Jonas */ + if (gc) { + if (find_buddy(gc->user, who)) + button = gtk_menu_item_new_with_label(_("Remove")); + else + button = gtk_menu_item_new_with_label(_("Add")); + + g_signal_connect(G_OBJECT(button), "activate", + G_CALLBACK(menu_add_cb), conv); + + g_object_set_data(G_OBJECT(button), "user_data", 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; +} + +static void +do_invite(GtkWidget *w, int resp, struct InviteBuddyInfo *info) +{ + const char *buddy, *message; + struct gaim_gtk_conversation *gtkconv; + + gtkconv = GAIM_GTK_CONVERSATION(info->conv); + + if (resp == GTK_RESPONSE_OK) { + buddy = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(info->entry)->entry)); + message = gtk_entry_get_text(GTK_ENTRY(info->message)); + + if (!g_strcasecmp(buddy, "")) { + g_free(info); + + return; + } + + serv_chat_invite(gaim_conversation_get_gc(info->conv), + gaim_chat_get_id(GAIM_CHAT(info->conv)), + message, buddy); + } + + gtk_widget_destroy(invite_dialog); + invite_dialog = NULL; + + g_free(info); +} + +static void +invite_cb(GtkWidget *widget, struct gaim_conversation *conv) +{ + struct InviteBuddyInfo *info = NULL; + + if (invite_dialog == NULL) { + struct gaim_connection *gc; + struct gaim_window *win; + struct gaim_gtk_window *gtkwin; + char *filename; + GtkWidget *label; + GtkWidget *vbox, *hbox; + GtkWidget *table; + GtkWidget *img; + + filename = g_build_filename(DATADIR, "pixmaps", "gaim", "dialogs", + "gaim_question.png", NULL); + + img = gtk_image_new_from_file(filename); + + g_free(filename); + + + info = g_new0(struct InviteBuddyInfo, 1); + info->conv = conv; + + gc = gaim_conversation_get_gc(conv); + win = gaim_conversation_get_window(conv); + gtkwin = GAIM_GTK_WINDOW(win); + + /* Create the new dialog. */ + invite_dialog = gtk_dialog_new_with_buttons( + _("Gaim - Invite Buddy Into Chat Room"), + GTK_WINDOW(gtkwin->window), + GTK_DIALOG_MODAL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); + + gtk_dialog_set_default_response(GTK_DIALOG(invite_dialog), + GTK_RESPONSE_OK); + gtk_container_set_border_width(GTK_CONTAINER(invite_dialog), 6); + gtk_window_set_resizable(GTK_WINDOW(invite_dialog), FALSE); + gtk_dialog_set_has_separator(GTK_DIALOG(invite_dialog), FALSE); + + /* Setup the outside spacing. */ + vbox = GTK_DIALOG(invite_dialog)->vbox; + + gtk_box_set_spacing(GTK_BOX(vbox), 12); + gtk_container_set_border_width(GTK_CONTAINER(vbox), 6); + + /* Setup the inner hbox and put the dialog's icon in it. */ + hbox = gtk_hbox_new(FALSE, 12); + gtk_container_add(GTK_CONTAINER(vbox), hbox); + gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); + gtk_misc_set_alignment(GTK_MISC(img), 0, 0); + + /* Setup the right vbox. */ + vbox = gtk_vbox_new(FALSE, 0); + gtk_container_add(GTK_CONTAINER(hbox), vbox); + + /* Put our happy label in it. */ + label = gtk_label_new(_("Please enter the name of the user you wish " + "to invite, along with an optional invite " + "message.")); + gtk_widget_set_size_request(label, 350, -1); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); + + /* hbox for the table, and to give it some spacing on the left. */ + hbox = gtk_hbox_new(FALSE, 6); + gtk_container_add(GTK_CONTAINER(vbox), hbox); + + /* Setup the table we're going to use to lay stuff out. */ + table = gtk_table_new(2, 2, FALSE); + gtk_table_set_row_spacings(GTK_TABLE(table), 6); + gtk_table_set_col_spacings(GTK_TABLE(table), 6); + gtk_container_set_border_width(GTK_CONTAINER(table), 12); + gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); + + /* Now the Buddy label */ + label = gtk_label_new(NULL); + gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Buddy:")); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); + + /* Now the Buddy drop-down entry field. */ + info->entry = gtk_combo_new(); + gtk_combo_set_case_sensitive(GTK_COMBO(info->entry), FALSE); + gtk_entry_set_activates_default( + GTK_ENTRY(GTK_COMBO(info->entry)->entry), TRUE); + + gtk_table_attach_defaults(GTK_TABLE(table), info->entry, 1, 2, 0, 1); + gtk_label_set_mnemonic_widget(GTK_LABEL(label), info->entry); + + /* Fill in the names. */ + gtk_combo_set_popdown_strings(GTK_COMBO(info->entry), + generate_invite_user_names(gc)); + + + /* Now the label for "Message" */ + label = gtk_label_new(NULL); + gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Message:")); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2); + + + /* And finally, the Message entry field. */ + info->message = gtk_entry_new(); + gtk_entry_set_activates_default(GTK_ENTRY(info->message), TRUE); + + gtk_table_attach_defaults(GTK_TABLE(table), info->message, 1, 2, 1, 2); + gtk_label_set_mnemonic_widget(GTK_LABEL(label), info->message); + + /* Connect the signals. */ + g_signal_connect(G_OBJECT(invite_dialog), "response", + G_CALLBACK(do_invite), info); + } + + gtk_widget_show_all(invite_dialog); + + if (info != NULL) + gtk_widget_grab_focus(GTK_COMBO(info->entry)->entry); +} + +static gboolean +entry_key_pressed_cb_2(GtkWidget *entry, GdkEventKey *event, gpointer data) +{ + struct gaim_window *win; + struct gaim_conversation *conv; + struct gaim_gtk_conversation *gtkconv; + + conv = (struct gaim_conversation *)data; + gtkconv = GAIM_GTK_CONVERSATION(conv); + win = gaim_conversation_get_window(conv); + + if (event->keyval == GDK_Escape) { + if (convo_options & OPT_CONVO_ESC_CAN_CLOSE) { + g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); + gaim_conversation_destroy(conv); + } + } + else if (event->keyval == GDK_Page_Up) { + g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); + + if (!(event->state & GDK_CONTROL_MASK)) + gtk_imhtml_page_up(GTK_IMHTML(gtkconv->imhtml)); + } + else if (event->keyval == GDK_Page_Down) { + g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); + + if (!(event->state & GDK_CONTROL_MASK)) + gtk_imhtml_page_down(GTK_IMHTML(gtkconv->imhtml)); + } + else if ((event->keyval == GDK_F2) && + (convo_options & OPT_CONVO_F2_TOGGLES)) { + gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), + !GTK_IMHTML(gtkconv->imhtml)->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_cb(NULL, conv); + g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); + + return TRUE; + } + else if (!(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK)) && + (convo_options & OPT_CONVO_ENTER_SENDS)) { + + send_cb(NULL, conv); + g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); + + return TRUE; + } + + return FALSE; + } + else if ((event->state & GDK_CONTROL_MASK) && (event->keyval == 'm')) { + g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); + gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, "\n", 1); + } + else if (event->state & GDK_CONTROL_MASK) { + switch (event->keyval) { + case GDK_Up: + if (!conv->send_history) + break; + + if (!conv->send_history->prev) { + GtkTextIter start, end; + + if (conv->send_history->data) + g_free(conv->send_history->data); + + gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, + &start); + gtk_text_buffer_get_end_iter(gtkconv->entry_buffer, &end); + + conv->send_history->data = + gtk_text_buffer_get_text(gtkconv->entry_buffer, + &start, &end, FALSE); + } + + if (conv->send_history->next && + conv->send_history->next->data) { + + conv->send_history = conv->send_history->next; + gtk_text_buffer_set_text(gtkconv->entry_buffer, + conv->send_history->data, -1); + } + + break; + + case GDK_Down: + if (!conv->send_history) + break; + + if (conv->send_history->prev) { + conv->send_history = conv->send_history->prev; + + if (conv->send_history->data) + gtk_text_buffer_set_text(gtkconv->entry_buffer, + conv->send_history->data, -1); + } + + break; + } + + if (convo_options & OPT_CONVO_CTL_CHARS) { + switch (event->keyval) { + case 'i': + case 'I': + quiet_set(gtkconv->toolbar.italic, + !gtk_toggle_button_get_active( + GTK_TOGGLE_BUTTON(gtkconv->toolbar.italic))); + + do_italic(gtkconv->toolbar.italic, gtkconv); + + g_signal_stop_emission_by_name(G_OBJECT(entry), + "key_press_event"); + break; + + case 'u': /* ctrl-u is GDK_Clear, which clears the line. */ + case 'U': + quiet_set(gtkconv->toolbar.underline, + !gtk_toggle_button_get_active( + GTK_TOGGLE_BUTTON(gtkconv->toolbar.underline))); + + do_underline(gtkconv->toolbar.underline, gtkconv); + + g_signal_stop_emission_by_name(G_OBJECT(entry), + "key_press_event"); + break; + + case 'b': /* ctrl-b is GDK_Left, which moves backwards. */ + case 'B': + quiet_set(gtkconv->toolbar.bold, + !gtk_toggle_button_get_active( + GTK_TOGGLE_BUTTON(gtkconv->toolbar.bold))); + + do_bold(gtkconv->toolbar.bold, gtkconv); + + g_signal_stop_emission_by_name(G_OBJECT(entry), + "key_press_event"); + break; + + case '-': + do_small(NULL, gtkconv); + + g_signal_stop_emission_by_name(G_OBJECT(entry), + "key_press_event"); + break; + + case '=': + case '+': + do_big(NULL, gtkconv); + + g_signal_stop_emission_by_name(G_OBJECT(entry), + "key_press_event"); + break; + + case '0': + do_normal(NULL, gtkconv); + + g_signal_stop_emission_by_name(G_OBJECT(entry), + "key_press_event"); + break; + + case 'f': + case 'F': + quiet_set(gtkconv->toolbar.normal_size, + !gtk_toggle_button_get_active( + GTK_TOGGLE_BUTTON(gtkconv->toolbar.normal_size))); + + toggle_font(gtkconv->toolbar.normal_size, conv); + + g_signal_stop_emission_by_name(G_OBJECT(entry), + "key_press_event"); + break; + } + } + + if (convo_options & OPT_CONVO_CTL_SMILEYS) { + char buf[7]; + + *buf = '\0'; + + switch (event->keyval) { + case '1': strcpy(buf, ":-)"); break; + case '2': strcpy(buf, ":-("); break; + case '3': strcpy(buf, ";-)"); break; + case '4': strcpy(buf, ":-P"); break; + case '5': strcpy(buf, "=-O"); break; + case '6': strcpy(buf, ":-*"); break; + case '7': strcpy(buf, ">:o"); break; + case '8': strcpy(buf, "8-)"); break; + case '!': strcpy(buf, ":-$"); break; + case '@': strcpy(buf, ":-!"); break; + case '#': strcpy(buf, ":-["); break; + case '$': strcpy(buf, "O:-)"); break; + case '%': strcpy(buf, ":-/"); break; + case '^': strcpy(buf, ":'("); break; + case '&': strcpy(buf, ":-X"); break; + case '*': strcpy(buf, ":-D"); break; + default: break; + } + + if (*buf) { + gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, + buf, -1); + g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); + } + } + + if (event->keyval == 'l') { + gtk_imhtml_clear(GTK_IMHTML(gtkconv->imhtml)); + g_string_free(conv->history, TRUE); + conv->history = g_string_new(""); + } + else if ((event->keyval == 'w') && + (convo_options & OPT_CONVO_CTL_W_CLOSES)) { + + g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); + gaim_conversation_destroy(conv); + return TRUE; + } + else if (event->keyval == 'n') { + g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); + + show_im_dialog(); + } + else if (event->keyval == 'z') { + g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); + +#ifdef _WIN32 + XIconifyWindow(GDK_DISPLAY(), + GDK_WINDOW_XWINDOW(gtkwin->window->window), + ((_XPrivDisplay)GDK_DISPALY())->default_screen); +#endif + } + else if (event->keyval == '[') { + gaim_window_switch_conversation(win, + gaim_conversation_get_index(conv) - 1); + + g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); + } + else if (event->keyval == ']') { + gaim_window_switch_conversation(win, + gaim_conversation_get_index(conv) + 1); + + g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); + } + else if (event->keyval == GDK_Tab) { + move_next_tab(conv); + + g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); + + return TRUE; + } + } + else if ((event->keyval == GDK_Tab) && + gaim_conversation_get_type(conv) == GAIM_CONV_CHAT && + (chat_options & OPT_CHAT_TAB_COMPLETE)) { + + tab_complete(conv); + + g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); + + return TRUE; + } + else if ((event->state & GDK_MOD1_MASK) && + event->keyval > '0' && event->keyval <= '9') { + + gaim_window_switch_conversation(win, event->keyval - '1'); + + g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); + } + + return FALSE; +} + +/* + * NOTE: + * 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. + */ +static gboolean +entry_stop_rclick_cb(GtkWidget *widget, GdkEventButton *event, gpointer data) +{ + 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; +} + +static void +menu_conv_sel_send_cb(GObject *m, struct aim_user *user) +{ + struct gaim_window *win = g_object_get_data(m, "user_data"); + struct gaim_conversation *conv; + + if (gaim_gtk_is_state_locked()) + return; + + conv = gaim_window_get_active_conversation(win); + + gaim_conversation_set_user(conv, user); +} + +static void +insert_text_cb(GtkTextBuffer *textbuffer, GtkTextIter *position, + gchar *new_text, gint new_text_length, gpointer user_data) +{ + struct gaim_conversation *conv = (struct gaim_conversation *)user_data; + + if (conv == NULL) + return; + + if (misc_options & OPT_MISC_STEALTH_TYPING) + return; + + got_typing_keypress(conv, (gtk_text_iter_is_start(position) && + gtk_text_iter_is_end(position))); +} + +static void +delete_text_cb(GtkTextBuffer *textbuffer, GtkTextIter *start_pos, + GtkTextIter *end_pos, gpointer user_data) +{ + struct gaim_conversation *conv = (struct gaim_conversation *)user_data; + struct gaim_im *im; + + if (conv == NULL) + return; + + if (misc_options & OPT_MISC_STEALTH_TYPING) + return; + + im = GAIM_IM(conv); + + if (gtk_text_iter_is_start(start_pos) && gtk_text_iter_is_end(end_pos)) { + + /* We deleted all the text, so turn off typing. */ + if (gaim_im_get_type_again_timeout(im)) + gaim_im_stop_type_again_timeout(im); + + /* XXX The (char *) should go away! Somebody add consts to stuff! */ + serv_send_typing(gaim_conversation_get_gc(conv), + (char *)gaim_conversation_get_name(conv), + NOT_TYPING); + } + else { + /* We're deleting, but not all of it, so it counts as typing. */ + got_typing_keypress(conv, FALSE); + } +} + +static void +notebook_init_grab(struct gaim_gtk_window *gtkwin, GtkWidget *widget) +{ + static GdkCursor *cursor = NULL; + + gtkwin->in_drag = TRUE; + + if (gtkwin->drag_leave_signal) { + g_signal_handler_disconnect(G_OBJECT(widget), + gtkwin->drag_leave_signal); + + gtkwin->drag_leave_signal = 0; + } + + if (cursor == NULL) + cursor = gdk_cursor_new(GDK_FLEUR); + + /* Grab the pointer */ + gtk_grab_add(gtkwin->notebook); + gdk_pointer_grab(gtkwin->notebook->window, FALSE, + GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, + NULL, cursor, GDK_CURRENT_TIME); +} + +static gboolean +notebook_motion_cb(GtkWidget *widget, GdkEventButton *e, + struct gaim_window *win) +{ + struct gaim_gtk_window *gtkwin; + + gtkwin = GAIM_GTK_WINDOW(win); + + /* + * Make sure the user moved the mouse far enough for the + * drag to be initiated. + */ + if (gtkwin->in_predrag) { + if (e->x_root < gtkwin->drag_min_x || + e->x_root >= gtkwin->drag_max_x || + e->y_root < gtkwin->drag_min_y || + e->y_root >= gtkwin->drag_max_y) { + + gtkwin->in_predrag = FALSE; + notebook_init_grab(gtkwin, widget); + } + } + else { /* Otherwise, draw the arrows. */ + struct gaim_window *dest_win; + struct gaim_gtk_window *dest_gtkwin; + GtkNotebook *dest_notebook; + GtkWidget *tab, *last_vis_tab = NULL; + gint nb_x, nb_y, page_num, i, last_vis_tab_loc = -1; + gint arrow1_x, arrow1_y, arrow2_x, arrow2_y; + gboolean horiz_tabs = FALSE, tab_found = FALSE; + GList *l; + + /* Get the window that the cursor is over. */ + dest_win = gaim_gtkwin_get_at_xy(e->x_root, e->y_root); + + if (dest_win == NULL) { + dnd_hints_hide_all(); + + return TRUE; + } + + dest_gtkwin = GAIM_GTK_WINDOW(dest_win); + + dest_notebook = GTK_NOTEBOOK(dest_gtkwin->notebook); + + gdk_window_get_origin(GTK_WIDGET(dest_notebook)->window, &nb_x, &nb_y); + + arrow1_x = arrow2_x = nb_x; + arrow1_y = arrow2_y = nb_y; + + page_num = gaim_gtkconv_get_dest_tab_at_xy(dest_win, + e->x_root, e->y_root); + + if (gtk_notebook_get_tab_pos(dest_notebook) == GTK_POS_TOP || + gtk_notebook_get_tab_pos(dest_notebook) == GTK_POS_BOTTOM) { + + horiz_tabs = TRUE; + } + + /* Find out where to put the arrows. */ + for (l = gaim_window_get_conversations(dest_win), i = 0; + l != NULL; + l = l->next, i++) { + + struct gaim_conversation *conv = l->data; + + tab = GAIM_GTK_CONVERSATION(conv)->tabby; + + /* + * If this is the correct tab, record the positions + * for the arrows. + */ + if (i == page_num) { + if (horiz_tabs) { + arrow1_x = arrow2_x = nb_x + tab->allocation.x; + arrow1_y = nb_y + tab->allocation.y; + arrow2_y = nb_y + tab->allocation.y + + tab->allocation.height; + } + else { + arrow1_x = nb_x + tab->allocation.x; + arrow2_x = nb_x + tab->allocation.x + + tab->allocation.width; + arrow1_y = arrow2_y = nb_y + tab->allocation.y; + } + + tab_found = TRUE; + break; + } + else { /* Keep track of the right-most tab that we see. */ + if (horiz_tabs && tab->allocation.x > last_vis_tab_loc) { + last_vis_tab = tab; + last_vis_tab_loc = tab->allocation.x; + } + else if (!horiz_tabs && tab->allocation.y > last_vis_tab_loc) { + last_vis_tab = tab; + last_vis_tab_loc = tab->allocation.y; + } + } + } + + /* + * If we didn't find the tab, then we'll just place the + * arrows to the right/bottom of the last visible tab. + */ + if (!tab_found && last_vis_tab) { + if (horiz_tabs) { + arrow1_x = arrow2_x = nb_x + last_vis_tab->allocation.x + + last_vis_tab->allocation.width; + arrow1_y = nb_y + last_vis_tab->allocation.y; + arrow2_y = nb_y + last_vis_tab->allocation.y + + last_vis_tab->allocation.height; + } + else { + arrow1_x = nb_x + last_vis_tab->allocation.x; + arrow2_x = nb_x + last_vis_tab->allocation.x + + last_vis_tab->allocation.width; + arrow1_y = arrow2_y = nb_y + last_vis_tab->allocation.y + + last_vis_tab->allocation.height; + } + } + + if (horiz_tabs) { + dnd_hints_show(HINT_ARROW_DOWN, arrow1_x, arrow1_y); + dnd_hints_show(HINT_ARROW_UP, arrow2_x, arrow2_y); + } + else { + dnd_hints_show(HINT_ARROW_RIGHT, arrow1_x, arrow1_y); + dnd_hints_show(HINT_ARROW_LEFT, arrow2_x, arrow2_y); + } + } + + return TRUE; +} + +static gboolean +notebook_leave_cb(GtkWidget *widget, GdkEventCrossing *e, + struct gaim_window *win) +{ + struct gaim_gtk_window *gtkwin; + + gtkwin = GAIM_GTK_WINDOW(win); + + if (gtkwin->in_drag) + return FALSE; + + if (e->x_root < gtkwin->drag_min_x || + e->x_root >= gtkwin->drag_max_x || + e->y_root < gtkwin->drag_min_y || + e->y_root >= gtkwin->drag_max_y) { + + gtkwin->in_predrag = FALSE; + notebook_init_grab(gtkwin, widget); + } + + return TRUE; +} + +/* + * THANK YOU GALEON! + */ +static gboolean +notebook_press_cb(GtkWidget *widget, GdkEventButton *e, + struct gaim_window *win) +{ + struct gaim_gtk_window *gtkwin; + gint nb_x, nb_y, x_rel, y_rel; + GList *l; + int tab_clicked; + + debug_printf("notebook_press_cb\n"); + if (e->button != 1 || e->type != GDK_BUTTON_PRESS) + return FALSE; + + gtkwin = GAIM_GTK_WINDOW(win); + + debug_printf("notebook_press_cb: 1\n"); + if (gtkwin->in_drag) { + debug_printf("Already in the middle of a window " + "drag at tab_press_cb\n"); + return FALSE; + } + + /* + * Make sure a tab was actually clicked. The arrow buttons + * mess things up. + */ + tab_clicked = gaim_gtkconv_get_tab_at_xy(win, e->x_root, e->y_root); + + printf("tab_clicked == %d\n", tab_clicked); + + if (tab_clicked == -1) + return FALSE; + + /* + * Get the relative position of the press event, with regards to + * the position of the notebook. + */ + gdk_window_get_origin(gtkwin->notebook->window, &nb_x, &nb_y); + + x_rel = e->x_root - nb_x; + y_rel = e->y_root - nb_y; + + /* Reset the min/max x/y */ + gtkwin->drag_min_x = 0; + gtkwin->drag_min_y = 0; + gtkwin->drag_max_x = 0; + gtkwin->drag_max_y = 0; + + /* Find out which tab was dragged. */ + for (l = gaim_window_get_conversations(win); l != NULL; l = l->next) { + struct gaim_conversation *conv = l->data; + GtkWidget *tab = GAIM_GTK_CONVERSATION(conv)->tabby; + + debug_printf("Tab: %d\n", gaim_conversation_get_index(conv)); + if (!GTK_WIDGET_VISIBLE(tab)) + continue; + + debug_printf("Tab Visible.\n"); + if (tab->allocation.x > x_rel || tab->allocation.y > y_rel) + break; + + /* Save the borders of the tab. */ + gtkwin->drag_min_x = tab->allocation.x + nb_x; + gtkwin->drag_min_y = tab->allocation.y + nb_y; + gtkwin->drag_max_x = tab->allocation.width + gtkwin->drag_min_x; + gtkwin->drag_max_y = tab->allocation.height + gtkwin->drag_min_y; + } + + debug_printf("notebook_press_cb: 3\n"); + + /* Make sure the click occurred in the tab. */ + if (e->x_root < gtkwin->drag_min_x || + e->x_root >= gtkwin->drag_max_x || + e->y_root < gtkwin->drag_min_y || + e->y_root >= gtkwin->drag_max_y) { + + debug_printf("Passing this down.\n"); + return FALSE; + } + + debug_printf("notebook_press_cb: 4\n"); + gtkwin->in_predrag = TRUE; + + /* Connect the new motion signals. */ + gtkwin->drag_motion_signal = + g_signal_connect(G_OBJECT(widget), "motion_notify_event", + G_CALLBACK(notebook_motion_cb), win); + + gtkwin->drag_leave_signal = + g_signal_connect(G_OBJECT(widget), "leave_notify_event", + G_CALLBACK(notebook_leave_cb), win); + + debug_printf("notebook_press_cb: 5\n"); + return FALSE; +} + +static gboolean +notebook_release_cb(GtkWidget *widget, GdkEventButton *e, + struct gaim_window *win) +{ + struct gaim_window *dest_win; + struct gaim_gtk_window *gtkwin; + struct gaim_gtk_window *dest_gtkwin; + struct gaim_conversation *conv; + GtkNotebook *dest_notebook; + gint dest_page_num; + + /* + * Don't check to make sure that the event's window matches the + * widget's, because we may be getting an event passed on from the + * close button. + */ + if (e->button != 1 && e->type != GDK_BUTTON_RELEASE) + return FALSE; + + if (gdk_pointer_is_grabbed()) { + gdk_pointer_ungrab(GDK_CURRENT_TIME); + gtk_grab_remove(widget); + } + + gtkwin = GAIM_GTK_WINDOW(win); + + if (!gtkwin->in_predrag && !gtkwin->in_drag) { + printf("Not in predrag.\n"); + return TRUE; + } + + /* Disconnect the motion signal. */ + if (gtkwin->drag_motion_signal) { + g_signal_handler_disconnect(G_OBJECT(widget), + gtkwin->drag_motion_signal); + + gtkwin->drag_motion_signal = 0; + } + + /* + * If we're in a pre-drag, we'll also need to disconnect the leave + * signal. + */ + if (gtkwin->in_predrag) { + gtkwin->in_predrag = FALSE; + + if (gtkwin->drag_leave_signal) { + g_signal_handler_disconnect(G_OBJECT(widget), + gtkwin->drag_leave_signal); + + gtkwin->drag_leave_signal = 0; + } + } + + /* If we're not in drag... */ + /* We're perfectly normal people! */ + if (!gtkwin->in_drag) { + debug_printf("Not in drag.\n"); + return FALSE; + } + + gtkwin->in_drag = FALSE; + + dnd_hints_hide_all(); + + dest_win = gaim_gtkwin_get_at_xy(e->x_root, e->y_root); + dest_gtkwin = GAIM_GTK_WINDOW(dest_win); + + conv = gaim_window_get_active_conversation(win); + + if (dest_win == NULL) { + if (gaim_window_get_conversation_count(win) < 2) + return FALSE; + + if (gaim_window_get_conversation_count(win) > 1) { + /* Make a new window to stick this to. */ + struct gaim_window *new_win; + + new_win = gaim_window_new(); + gaim_window_remove_conversation(win, + gaim_conversation_get_index(conv)); + gaim_window_add_conversation(new_win, conv); + gaim_window_show(new_win); + } + + return TRUE; + } + + /* Get the destination notebook. */ + dest_notebook = GTK_NOTEBOOK(gtkwin->notebook); + + /* Get the destination page number. */ + dest_page_num = gaim_gtkconv_get_dest_tab_at_xy(dest_win, + e->x_root, e->y_root); + + if (win == dest_win) { + gaim_window_move_conversation(win, + gaim_conversation_get_index(conv), dest_page_num); + } + else { + size_t pos; + + gaim_window_remove_conversation(win, + gaim_conversation_get_index(conv)); + + pos = gaim_window_add_conversation(dest_win, conv); + + gaim_window_move_conversation(dest_win, pos, dest_page_num); + + gaim_window_switch_conversation(dest_win, dest_page_num); + } + + gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); + + debug_printf("release cb returning.\n"); + return TRUE; +} + +static void +switch_conv_cb(GtkNotebook *notebook, GtkWidget *page, gint page_num, + gpointer user_data) +{ + struct gaim_window *win; + struct gaim_conversation *conv; + struct gaim_gtk_conversation *gtkconv; + struct gaim_gtk_window *gtkwin; + struct gaim_connection *gc; + + if (gaim_gtk_is_state_locked()) + return; + + debug_printf("Switching conversation\n"); + + win = (struct gaim_window *)user_data; + + conv = gaim_window_get_conversation_at(win, page_num); + gc = gaim_conversation_get_gc(conv); + gtkwin = GAIM_GTK_WINDOW(win); + gtkconv = GAIM_GTK_CONVERSATION(conv); + + gaim_conversation_set_unseen(conv, GAIM_UNSEEN_NONE); + + /* Update the menubar */ + if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { + gtk_widget_set_sensitive(gtkwin->menu.view_history, TRUE); + gtk_widget_set_sensitive(gtkwin->menu.insert_image, + (gc && gc->prpl->options & OPT_PROTO_IM_IMAGE)); + + if (gtkwin->menu.send_as != NULL) + update_send_as_selection(win); + } + else { + gtk_widget_set_sensitive(gtkwin->menu.view_history, FALSE); + gtk_widget_set_sensitive(gtkwin->menu.insert_image, FALSE); + + if (gtkwin->menu.send_as != NULL) + gtk_widget_hide(gtkwin->menu.send_as); + } + + gaim_gtk_set_state_lock(TRUE); + + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtkwin->menu.logging), + gaim_conversation_is_logging(conv)); + + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtkwin->menu.sounds), + gtkconv->make_sound); + + gaim_gtk_set_state_lock(FALSE); + + gtk_widget_grab_focus(gtkconv->entry); +} + +/************************************************************************** + * Utility functions + **************************************************************************/ +static void +do_bold(GtkWidget *bold, struct gaim_gtk_conversation *gtkconv) +{ + if (gaim_gtk_is_state_locked()) + return; + + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(bold))) + gaim_gtk_surround(gtkconv, "", ""); + else + gaim_gtk_advance_past(gtkconv, "", ""); + + gtk_widget_grab_focus(gtkconv->entry); +} + +static void +do_italic(GtkWidget *italic, struct gaim_gtk_conversation *gtkconv) +{ + if (gaim_gtk_is_state_locked()) + return; + + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(italic))) + gaim_gtk_surround(gtkconv, "", ""); + else + gaim_gtk_advance_past(gtkconv, "", ""); + + gtk_widget_grab_focus(gtkconv->entry); +} + +static void +do_underline(GtkWidget *underline, struct gaim_gtk_conversation *gtkconv) +{ + if (gaim_gtk_is_state_locked()) + return; + + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(underline))) + gaim_gtk_surround(gtkconv, "", ""); + else + gaim_gtk_advance_past(gtkconv, "", ""); + + gtk_widget_grab_focus(gtkconv->entry); +} + +static void +do_small(GtkWidget *small, struct gaim_gtk_conversation *gtkconv) +{ + if (gaim_gtk_is_state_locked()) + return; + + gaim_gtk_surround(gtkconv, "", ""); + + gtk_widget_grab_focus(gtkconv->entry); +} + +static void +do_normal(GtkWidget *small, struct gaim_gtk_conversation *gtkconv) +{ + if (gaim_gtk_is_state_locked()) + return; + + gaim_gtk_surround(gtkconv, "", ""); + + gtk_widget_grab_focus(gtkconv->entry); +} + +static void +do_big(GtkWidget *small, struct gaim_gtk_conversation *gtkconv) +{ + if (gaim_gtk_is_state_locked()) + return; + + gaim_gtk_surround(gtkconv, "", ""); + + gtk_widget_grab_focus(gtkconv->entry); +} + +static void +toggle_font(GtkWidget *font, struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + + if (gaim_gtk_is_state_locked()) + return; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(font))) + show_font_dialog(conv, font); + else if (gtkconv->dialogs.fg_color != NULL) + cancel_font(font, conv); + else + gaim_gtk_advance_past(gtkconv, "", ""); +} + +static void +toggle_fg_color(GtkWidget *color, struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + + if (gaim_gtk_is_state_locked()) + return; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(color))) + show_fgcolor_dialog(conv, color); + else if (gtkconv->dialogs.fg_color != NULL) + cancel_fgcolor(color, conv); + else + gaim_gtk_advance_past(gtkconv, "", ""); +} + +static void +toggle_bg_color(GtkWidget *color, struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + + if (gaim_gtk_is_state_locked()) + return; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(color))) + show_bgcolor_dialog(conv, color); + else if (gtkconv->dialogs.bg_color != NULL) + cancel_bgcolor(color, conv); + else + gaim_gtk_advance_past(gtkconv, "", ""); +} + +static void +check_everything(GtkTextBuffer *buffer) +{ + struct gaim_conversation *conv; + struct gaim_gtk_conversation *gtkconv; + + conv = (struct gaim_conversation *)g_object_get_data(G_OBJECT(buffer), + "user_data"); + + if (conv == NULL) + return; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + /* CONV TODO */ +} + +static void +quiet_set(GtkWidget *tb, gboolean active) +{ + gaim_gtk_set_state_lock(TRUE); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tb), active); + gaim_gtk_set_state_lock(FALSE); +} + +static void +got_typing_keypress(struct gaim_conversation *conv, gboolean first) +{ + struct gaim_im *im; + + /* + * We know we got something, so we at least have to make sure we don't + * send TYPED any time soon. + */ + + im = GAIM_IM(conv); + + if (gaim_im_get_type_again_timeout(im)) + gaim_im_stop_type_again_timeout(im); + + gaim_im_start_type_again_timeout(im); + + if (first || (gaim_im_get_type_again(im) != 0 && + time(NULL) > gaim_im_get_type_again(im))) { + + int timeout = serv_send_typing(gaim_conversation_get_gc(conv), + (char *)gaim_conversation_get_name(conv), + TYPING); + + if (timeout) + gaim_im_set_type_again(im, time(NULL) + timeout); + else + gaim_im_set_type_again(im, 0); + } +} + +static void +update_send_as_selection(struct gaim_window *win) +{ + struct aim_user *user; + struct gaim_conversation *conv; + struct gaim_gtk_window *gtkwin; + const char *username; + GtkWidget *menu; + GList *child; + + conv = gaim_window_get_active_conversation(win); + + if (conv == NULL) + return; + + user = gaim_conversation_get_user(conv); + gtkwin = GAIM_GTK_WINDOW(win); + + username = (user->gc == NULL ? user->username : user->gc->username); + + gtk_widget_show(gtkwin->menu.send_as); + + menu = gtk_menu_item_get_submenu( + GTK_MENU_ITEM(gtkwin->menu.send_as)); + + gaim_gtk_set_state_lock(TRUE); + + for (child = gtk_container_get_children(GTK_CONTAINER(menu)); + child != NULL; + child = child->next) { + + GtkWidget *item = child->data; + GtkWidget *label; + const char *title; + + label = gtk_bin_get_child(GTK_BIN(item)); + + if (!GTK_IS_LABEL(label)) + continue; + + title = gtk_label_get_text(GTK_LABEL(label)); + + if (!strcmp(title, username)) { + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE); + break; + } + } + + gaim_gtk_set_state_lock(FALSE); +} + +static void +generate_send_as_items(struct gaim_window *win) +{ + struct gaim_gtk_window *gtkwin; + GtkWidget *menu; + GtkWidget *menuitem; + GSList *gcs; + GList *convs; + GSList *group = NULL; + gboolean first_offline = TRUE; + gboolean found_online = FALSE; + + gtkwin = GAIM_GTK_WINDOW(win); + + if (gtkwin->menu.send_as != NULL) + gtk_widget_destroy(gtkwin->menu.send_as); + + /* See if we have > 1 connection active. */ + if (g_slist_length(connections) < 2) { + /* Now make sure we don't have any Offline entries. */ + gboolean found_offline = FALSE; + + for (convs = gaim_get_conversations(); + convs != NULL; + convs = convs->next) { + + struct gaim_conversation *conv; + struct aim_user *user; + + conv = (struct gaim_conversation *)convs->data; + user = gaim_conversation_get_user(conv); + + if (user->gc == NULL) { + found_offline = TRUE; + break; + } + } + + if (!found_offline) { + gtkwin->menu.send_as = NULL; + return; + } + } + + /* Build the Send As menu */ + gtkwin->menu.send_as = gtk_menu_item_new_with_mnemonic(_("_Send As")); + gtk_widget_show(gtkwin->menu.send_as); + + menu = gtk_menu_new(); + + gtk_menu_shell_append(GTK_MENU_SHELL(gtkwin->menu.menubar), + gtkwin->menu.send_as); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(gtkwin->menu.send_as), menu); + + gtk_widget_show(menu); + + /* Fill it with entries. */ + for (gcs = connections; gcs != NULL; gcs = gcs->next) { + struct gaim_connection *gc; + + found_online = TRUE; + + gc = (struct gaim_connection *)gcs->data; + + menuitem = gtk_radio_menu_item_new_with_label(group, gc->username); + group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(menuitem)); + + g_object_set_data(G_OBJECT(menuitem), "user_data", win); + + g_signal_connect(G_OBJECT(menuitem), "activate", + G_CALLBACK(menu_conv_sel_send_cb), gc->user); + + gtk_widget_show(menuitem); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + } + + /* + * Fill it with any accounts that still has an open (yet disabled) window + * (signed off accounts with a window open). + */ + for (convs = gaim_get_conversations(); + convs != NULL; + convs = convs->next) { + + struct gaim_conversation *conv; + struct aim_user *user; + + conv = (struct gaim_conversation *)convs->data; + user = gaim_conversation_get_user(conv); + + if (user->gc == NULL) { + if (first_offline && found_online) { + menuitem = gtk_separator_menu_item_new(); + gtk_widget_show(menuitem); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + + first_offline = FALSE; + } + + printf("Adding '%s'\n", user->username); + + menuitem = gtk_radio_menu_item_new_with_label(group, + user->username); + group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(menuitem)); + + gtk_widget_set_sensitive(menuitem, FALSE); + + gtk_widget_show(menuitem); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + } + } + + gtk_widget_show(gtkwin->menu.send_as); + update_send_as_selection(win); +} + +static 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 = g_list_append(NULL, ""); + + if (gc != NULL) { + for (grp = groups; grp != NULL; grp = grp->next) { + g = (struct group *)grp->data; + + for (bl = g->members; bl != NULL; bl = bl->next) { + buddy = (struct buddy *)bl->data; + + if (buddy->present) + tmp = g_list_append(tmp, buddy->name); + } + } + } + + return tmp; +} + +static void +add_chat_buddy_common(struct gaim_conversation *conv, const char *name, + int pos) +{ + struct gaim_gtk_conversation *gtkconv; + struct gaim_gtk_chat_pane *gtkchat; + struct gaim_chat *chat; + GtkTreeIter iter; + GtkListStore *ls; + + chat = GAIM_CHAT(conv); + gtkconv = GAIM_GTK_CONVERSATION(conv); + gtkchat = gtkconv->u.chat; + + ls = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list))); + + gtk_list_store_append(ls, &iter); + gtk_list_store_set(ls, &iter, 0, + (gaim_chat_is_user_ignored(chat, name) ? "X" : " "), + 1, name, -1); + gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(ls), 1, + GTK_SORT_ASCENDING); +} + +static void +tab_complete(struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + struct gaim_chat *chat; + GtkTextIter cursor, word_start, start_buffer; + int start; + int most_matched = -1; + char *entered, *partial = NULL; + char *text; + GList *matches = NULL; + GList *nicks = NULL; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + chat = GAIM_CHAT(conv); + + gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, &start_buffer); + gtk_text_buffer_get_iter_at_mark(gtkconv->entry_buffer, &cursor, + gtk_text_buffer_get_insert(gtkconv->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(gtkconv->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(gtkconv->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; + } + + for (nicks = gaim_chat_get_users(chat); + nicks != NULL; + nicks = nicks->next) { + + 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] != '@') + continue; + + if (g_strncasecmp(nick + 1, entered, strlen(entered))) { + if (nick[0] != '@' || nick[1] != '+') + continue; + + if (g_strncasecmp(nick + 2, entered, strlen(entered))) + continue; + else + nick += 2; + } + else + nick++; + } + + /* if we're here, it's a possible completion */ + + /* if we're doing old-style, just fill in the completion */ + if (chat_options & OPT_CHAT_OLD_STYLE_TAB) { + gtk_text_buffer_delete(gtkconv->entry_buffer, + &word_start, &cursor); + + if (strlen(nick) == strlen(entered)) { + nicks = (nicks->next + ? nicks->next + : gaim_chat_get_users(chat)); + + nick = nicks->data; + + if (*nick == '@') nick++; + if (*nick == '+') nick++; + } + + gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, + &start_buffer); + gtk_text_buffer_get_iter_at_mark(gtkconv->entry_buffer, &cursor, + gtk_text_buffer_get_insert(gtkconv->entry_buffer)); + + if (!gtk_text_iter_compare(&cursor, &start_buffer)) { + char *tmp = g_strdup_printf("%s: ", nick); + gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, + tmp, -1); + g_free(tmp); + } + else + gtk_text_buffer_insert_at_cursor(gtkconv->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); + } + + /* 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(gtkconv->entry_buffer, &word_start, &cursor); + + if (!matches->next) { + /* there was only one match. fill it in. */ + gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, &start_buffer); + gtk_text_buffer_get_iter_at_mark(gtkconv->entry_buffer, &cursor, + gtk_text_buffer_get_insert(gtkconv->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(gtkconv->entry_buffer, tmp, -1); + g_free(tmp); + } + else + gtk_text_buffer_insert_at_cursor(gtkconv->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); + } + + gaim_conversation_write(conv, NULL, addthis, -1, WFLAG_NOLOG, + time(NULL)); + gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, partial, -1); + g_free(addthis); + } + + g_free(entered); + g_free(partial); +} + +static gboolean +meify(char *message, size_t 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; + gboolean inside_html = 0; + + if (message == NULL) + return FALSE; /* Umm.. this would be very bad if this happens. */ + + if (len == -1) + len = strlen(message); + + for (c = message; *c != '\0'; c++, len--) { + if (inside_html) { + if (*c == '>') + inside_html = FALSE; + } + else { + if (*c == '<') + inside_html = TRUE; + else + break; + } + } + + if (*c != '\0' && !g_strncasecmp(c, "/me ", 4)) { + memmove(c, c + 4, len - 3); + + return TRUE; + } + + return FALSE; +} + +static GtkItemFactoryEntry menu_items[] = +{ + /* Conversation menu */ + { "/_Conversation", NULL, NULL, 0, "" }, + { "/Conversation/_Save As...", NULL, menu_save_as_cb, 0, + "", GTK_STOCK_SAVE_AS }, + { "/Conversation/View _History...", NULL, menu_view_history_cb, 0, NULL }, + { "/Conversation/sep1", NULL, NULL, 0, "" }, + { "/Conversation/Insert _URL...", NULL, menu_insert_link_cb, 0, + "", GAIM_STOCK_LINK }, + { "/Conversation/Insert _Image...", NULL, menu_insert_image_cb, 0, + "", GAIM_STOCK_IMAGE }, + { "/Conversation/sep2", NULL, NULL, 0, "" }, + { "/Conversation/_Close", NULL, menu_close_conv_cb, 0, + "", GTK_STOCK_CLOSE }, + + /* Options */ + { "/_Options", NULL, NULL, 0, "" }, + { "/Options/Enable _Logging", NULL, menu_logging_cb, 0, "" }, + { "/Options/Enable _Sounds", NULL, menu_sounds_cb, 0, "" }, +}; + +static const int menu_item_count = + sizeof(menu_items) / sizeof(*menu_items); + +static GtkWidget * +setup_menubar(struct gaim_window *win) +{ + struct gaim_gtk_window *gtkwin; + GtkWidget *hb; + GtkItemFactory *item_factory; + + gtkwin = GAIM_GTK_WINDOW(win); + + /* Create the handle box. */ + hb = gtk_handle_box_new(); + + item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "
", NULL); + + gtk_item_factory_create_items(item_factory, menu_item_count, + menu_items, win); + + gtkwin->menu.menubar = gtk_item_factory_get_widget(item_factory, "
"); + gtkwin->menu.view_history = gtk_item_factory_get_widget(item_factory, + "/Conversation/View History..."); + gtkwin->menu.insert_link = gtk_item_factory_get_widget(item_factory, + "/Conversation/Insert URL..."); + gtkwin->menu.insert_image = gtk_item_factory_get_widget(item_factory, + "/Conversation/Insert Image..."); + gtkwin->menu.logging = gtk_item_factory_get_widget(item_factory, + "/Options/Enable Logging"); + gtkwin->menu.sounds = gtk_item_factory_get_widget(item_factory, + "/Options/Enable Sounds"); + + generate_send_as_items(win); + + gtk_container_add(GTK_CONTAINER(hb), gtkwin->menu.menubar); + + gtk_widget_show(gtkwin->menu.menubar); + gtk_widget_show(hb); + + return hb; +} + +static void +setup_im_buttons(struct gaim_conversation *conv, GtkWidget *parent) +{ + struct gaim_connection *gc; + struct gaim_gtk_conversation *gtkconv; + struct gaim_gtk_im_pane *gtkim; + struct gaim_gtk_window *gtkwin; + GaimConversationType type = GAIM_CONV_IM; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + gtkim = gtkconv->u.im; + gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(conv)); + gc = gaim_conversation_get_gc(conv); + + /* From right to left... */ + + /* Send button */ + gtkconv->send = gaim_gtk_change_text(_("Send"), gtkconv->send, + GAIM_STOCK_SEND, type); + gtk_tooltips_set_tip(gtkconv->tooltips, gtkconv->send, _("Send"), NULL); + + gtk_box_pack_end(GTK_BOX(parent), gtkconv->send, FALSE, FALSE, 0); + + /* Separator */ + if (gtkim->sep2 != NULL) + gtk_widget_destroy(gtkim->sep2); + + gtkim->sep2 = gtk_vseparator_new(); + gtk_box_pack_end(GTK_BOX(parent), gtkim->sep2, FALSE, TRUE, 0); + gtk_widget_show(gtkim->sep2); + + /* Now, um, just kind of all over the place. Huh? */ + + /* Add button */ + if (find_buddy(gaim_conversation_get_gc(conv)->user, + gaim_conversation_get_name(conv)) == NULL) { + gtkim->add = gaim_gtk_change_text(_("Add"), gtkim->add, + GTK_STOCK_ADD, type); + gtk_tooltips_set_tip(gtkconv->tooltips, gtkim->add, + _("Add buddy"), NULL); + } + else { + gtkim->add = gaim_gtk_change_text(_("Remove"), gtkim->add, + GTK_STOCK_REMOVE, type); + gtk_tooltips_set_tip(gtkconv->tooltips, gtkim->add, + _("Remove buddy"), NULL); + } + + gtk_box_pack_start(GTK_BOX(parent), gtkim->add, + FALSE, FALSE, 0); + + /* Warn button */ + gtkim->warn = gaim_gtk_change_text(_("Warn"), gtkim->warn, + GAIM_STOCK_WARN, type); + gtk_box_pack_start(GTK_BOX(parent), gtkim->warn, FALSE, FALSE, 0); + gtk_tooltips_set_tip(gtkconv->tooltips, gtkim->add, + _("Remove buddy"), NULL); + + /* Info button */ + gtkconv->info = gaim_gtk_change_text(_("Info"), gtkconv->info, + GAIM_STOCK_INFO, type); + gtk_box_pack_start(GTK_BOX(parent), gtkconv->info, FALSE, FALSE, 0); + gtk_tooltips_set_tip(gtkconv->tooltips, gtkconv->info, + _("Get user information"), NULL); + + /* Block button */ + gtkim->block = gaim_gtk_change_text(_("Block"), gtkim->block, + GAIM_STOCK_BLOCK, type); + gtk_box_pack_start(GTK_BOX(parent), gtkim->block, FALSE, FALSE, 0); + gtk_tooltips_set_tip(gtkconv->tooltips, gtkim->block, + _("Block user"), NULL); + + gtk_button_set_relief(GTK_BUTTON(gtkconv->info), GTK_RELIEF_NONE); + gtk_button_set_relief(GTK_BUTTON(gtkim->add), GTK_RELIEF_NONE); + gtk_button_set_relief(GTK_BUTTON(gtkim->warn), GTK_RELIEF_NONE); + gtk_button_set_relief(GTK_BUTTON(gtkconv->send), GTK_RELIEF_NONE); + gtk_button_set_relief(GTK_BUTTON(gtkim->block), GTK_RELIEF_NONE); + + gtk_size_group_add_widget(gtkconv->sg, gtkconv->info); + gtk_size_group_add_widget(gtkconv->sg, gtkim->add); + gtk_size_group_add_widget(gtkconv->sg, gtkim->warn); + gtk_size_group_add_widget(gtkconv->sg, gtkconv->send); + gtk_size_group_add_widget(gtkconv->sg, gtkim->block); + + gtk_box_reorder_child(GTK_BOX(parent), gtkim->warn, 1); + gtk_box_reorder_child(GTK_BOX(parent), gtkim->block, 2); + gtk_box_reorder_child(GTK_BOX(parent), gtkconv->info, 4); + + gaim_gtkconv_update_buttons_by_protocol(conv); + + g_signal_connect(G_OBJECT(gtkconv->send), "clicked", + G_CALLBACK(send_cb), conv); + g_signal_connect(G_OBJECT(gtkconv->info), "clicked", + G_CALLBACK(info_cb), conv); + g_signal_connect(G_OBJECT(gtkim->warn), "clicked", + G_CALLBACK(warn_cb), conv); + g_signal_connect(G_OBJECT(gtkim->block), "clicked", + G_CALLBACK(block_cb), conv); +} + +static void +setup_chat_buttons(struct gaim_conversation *conv, GtkWidget *parent) +{ + struct gaim_connection *gc; + struct gaim_gtk_conversation *gtkconv; + struct gaim_gtk_chat_pane *gtkchat; + struct gaim_gtk_window *gtkwin; + GtkWidget *sep; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + gtkchat = gtkconv->u.chat; + gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(conv)); + gc = gaim_conversation_get_gc(conv); + + /* Send button */ + gtkconv->send = gaim_gtk_change_text(_("Send"), gtkconv->send, + GAIM_STOCK_SEND, GAIM_CONV_CHAT); + gtk_tooltips_set_tip(gtkconv->tooltips, gtkconv->send, _("Send"), NULL); + + gtk_box_pack_end(GTK_BOX(parent), gtkconv->send, FALSE, FALSE, 0); + + /* Separator */ + sep = gtk_vseparator_new(); + gtk_box_pack_end(GTK_BOX(parent), sep, FALSE, TRUE, 0); + gtk_widget_show(sep); + + /* Invite */ + gtkchat->invite = gaim_gtk_change_text(_("Invite"), gtkchat->invite, + GAIM_STOCK_INVITE, GAIM_CONV_CHAT); + gtk_tooltips_set_tip(gtkconv->tooltips, gtkchat->invite, + _("Invite a user"), NULL); + gtk_box_pack_end(GTK_BOX(parent), gtkchat->invite, FALSE, FALSE, 0); + + /* Set the relief on these. */ + gtk_button_set_relief(GTK_BUTTON(gtkchat->invite), GTK_RELIEF_NONE); + gtk_button_set_relief(GTK_BUTTON(gtkconv->send), GTK_RELIEF_NONE); + + /* Callbacks */ + g_signal_connect(G_OBJECT(gtkconv->send), "clicked", + G_CALLBACK(send_cb), conv); + g_signal_connect(G_OBJECT(gtkchat->invite), "clicked", + G_CALLBACK(invite_cb), conv); +} + +static GtkWidget * +build_conv_toolbar(struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + GtkWidget *vbox; + GtkWidget *hbox; + GtkWidget *button; + GtkWidget *sep; + GtkSizeGroup *sg; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); + + 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_STOCK_BOLD); + gtk_size_group_add_widget(sg, button); + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); + gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Bold"), NULL); + + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(do_bold), gtkconv); + + gtkconv->toolbar.bold = button; + + /* Italic */ + button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_ITALIC); + gtk_size_group_add_widget(sg, button); + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); + gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Italic"), NULL); + + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(do_italic), gtkconv); + + gtkconv->toolbar.italic = button; + + /* Underline */ + button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_UNDERLINE); + gtk_size_group_add_widget(sg, button); + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); + gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Underline"), NULL); + + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(do_underline), gtkconv); + + gtkconv->toolbar.underline = button; + + /* Sep */ + sep = gtk_vseparator_new(); + gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); + + /* Increase font size */ + button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_BIGGER); + gtk_size_group_add_widget(sg, button); + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); + gtk_tooltips_set_tip(gtkconv->tooltips, button, + _("Larger font size"), NULL); + + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(do_big), gtkconv); + + /* Normal font size */ + button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_NORMAL); + gtk_size_group_add_widget(sg, button); + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); + gtk_tooltips_set_tip(gtkconv->tooltips, button, + _("Normal font size"), NULL); + + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(do_normal), gtkconv); + + gtkconv->toolbar.normal_size = button; + + /* Decrease font size */ + button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_SMALLER); + gtk_size_group_add_widget(sg, button); + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); + gtk_tooltips_set_tip(gtkconv->tooltips, button, + _("Smaller font size"), NULL); + + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(do_small), gtkconv); + + /* Sep */ + sep = gtk_vseparator_new(); + gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); + + /* Foreground Color */ + button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_FGCOLOR); + gtk_size_group_add_widget(sg, button); + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); + gtk_tooltips_set_tip(gtkconv->tooltips, button, + _("Foreground font color"), NULL); + + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(toggle_fg_color), conv); + + gtkconv->toolbar.fgcolor = button; + + /* Background Color */ + button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_BGCOLOR); + gtk_size_group_add_widget(sg, button); + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); + gtk_tooltips_set_tip(gtkconv->tooltips, button, + _("Background color"), NULL); + + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(toggle_bg_color), conv); + + gtkconv->toolbar.bgcolor = button; + + /* 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_stock(GAIM_STOCK_IMAGE); + gtk_size_group_add_widget(sg, button); + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); + gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Insert image"), NULL); + + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(insert_image_cb), conv); + + gtkconv->toolbar.image = button; + + /* Insert Link */ + button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_LINK); + gtk_size_group_add_widget(sg, button); + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); + gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Insert link"), NULL); + + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(insert_link_cb), conv); + + gtkconv->toolbar.link = button; + + /* Insert Smiley */ + button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_SMILEY); + gtk_size_group_add_widget(sg, button); + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); + gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Insert smiley"), NULL); + + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(insert_smiley_cb), conv); + + gtkconv->toolbar.smiley = button; + + + sep = gtk_hseparator_new(); + gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); + + gtk_widget_show_all(vbox); + + return vbox; +} + +static GtkWidget * +setup_chat_pane(struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + struct gaim_gtk_chat_pane *gtkchat; + struct gaim_connection *gc; + GtkWidget *vpaned, *hpaned; + GtkWidget *vbox, *hbox; + GtkWidget *lbox, *bbox; + GtkWidget *label; + GtkWidget *sw2; + GtkWidget *list; + GtkWidget *button; + GtkWidget *frame; + GtkListStore *ls; + GtkCellRenderer *rend; + GtkTreeViewColumn *col; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + gtkchat = gtkconv->u.chat; + gc = gaim_conversation_get_gc(conv); + + /* Setup the outer pane. */ + vpaned = gtk_vpaned_new(); + gtk_paned_set_gutter_size(GTK_PANED(vpaned), 15); + gtk_widget_show(vpaned); + + /* Setup the top part of the pane. */ + vbox = gtk_vbox_new(FALSE, 5); + gtk_paned_pack1(GTK_PANED(vpaned), vbox, TRUE, FALSE); + gtk_widget_show(vbox); + + if (gc->prpl->options & OPT_PROTO_CHAT_TOPIC) + { + hbox = gtk_hbox_new(FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), 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); + + gtkchat->topic_text = gtk_entry_new(); + gtk_entry_set_editable(GTK_ENTRY(gtkchat->topic_text), FALSE); + gtk_box_pack_start(GTK_BOX(hbox), gtkchat->topic_text, TRUE, TRUE, 5); + gtk_widget_show(gtkchat->topic_text); + } + + /* Setup the horizontal pane. */ + hpaned = gtk_hpaned_new(); + gtk_paned_set_gutter_size(GTK_PANED(hpaned), 15); + gtk_box_pack_start(GTK_BOX(vbox), hpaned, TRUE, TRUE, 5); + gtk_widget_show(hpaned); + + /* Setup the scrolled window to put gtkimhtml in. */ + gtkconv->sw = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkconv->sw), + GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(gtkconv->sw), + GTK_SHADOW_IN); + gtk_paned_pack1(GTK_PANED(hpaned), gtkconv->sw, TRUE, TRUE); + + gtk_widget_set_size_request(gtkconv->sw, + buddy_chat_size.width, buddy_chat_size.height); + gtk_widget_show(gtkconv->sw); + + /* Setup gtkihmtml. */ + gtkconv->imhtml = gtk_imhtml_new(NULL, NULL); + gtk_container_add(GTK_CONTAINER(gtkconv->sw), gtkconv->imhtml); + + gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), + (convo_options & OPT_CONVO_SHOW_TIME)); + + g_signal_connect_after(G_OBJECT(gtkconv->imhtml), "button_press_event", + G_CALLBACK(entry_stop_rclick_cb), NULL); + + gaim_setup_imhtml(gtkconv->imhtml); + + gtk_widget_show(gtkconv->imhtml); + + /* Build the right pane. */ + lbox = gtk_vbox_new(FALSE, 5); + gtk_paned_pack2(GTK_PANED(hpaned), lbox, TRUE, TRUE); + gtk_widget_show(lbox); + + /* Setup the label telling how many people are in the room. */ + gtkchat->count = gtk_label_new(_("0 people in room")); + gtk_box_pack_start(GTK_BOX(lbox), gtkchat->count, FALSE, FALSE, 0); + gtk_widget_show(gtkchat->count); + + /* Setup the list of users. */ + 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(G_OBJECT(list), "button_press_event", + G_CALLBACK(right_click_chat_cb), conv); + + 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); + +#if 0 + g_signal_connect(G_OBJECT(list), "button_press_event", + G_CALLBACK(right_click_chat), conv); +#endif + + gtk_tree_view_append_column(GTK_TREE_VIEW(list), col); + + gtk_widget_set_size_request(list, 150, -1); + + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list), FALSE); + gtk_widget_show(list); + + gtkchat->list = list; + + gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw2), list); + + /* Setup the user list toolbar. */ + bbox = gtk_hbox_new(TRUE, 5); + gtk_box_pack_start(GTK_BOX(lbox), bbox, FALSE, FALSE, 0); + gtk_widget_show(bbox); + + /* IM */ + button = gaim_pixbuf_button_from_stock(NULL, GTK_STOCK_REDO, + GAIM_BUTTON_VERTICAL); + gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); + gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); + gtk_tooltips_set_tip(gtkconv->tooltips, button, _("IM"), NULL); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(im_cb), conv); + + gtk_widget_show(button); + + /* Ignore */ + button = gaim_pixbuf_button_from_stock(NULL, GAIM_STOCK_IGNORE, + GAIM_BUTTON_VERTICAL); + gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); + gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); + gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Ignore user"), NULL); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(ignore_cb), conv); + gtk_widget_show(button); + + /* Info */ + button = gaim_pixbuf_button_from_stock(NULL, GAIM_STOCK_INFO, + GAIM_BUTTON_VERTICAL); + gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); + gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); + gtk_tooltips_set_tip(gtkconv->tooltips, button, + _("Get user information"), NULL); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(info_cb), conv); + + gtk_widget_show(button); + + gtkconv->info = button; + + /* Build the toolbar. */ + vbox = gtk_vbox_new(FALSE, 5); + gtk_paned_pack2(GTK_PANED(vpaned), vbox, TRUE, FALSE); + gtk_widget_show(vbox); + + gtkconv->toolbar.toolbar = build_conv_toolbar(conv); + gtk_box_pack_start(GTK_BOX(vbox), gtkconv->toolbar.toolbar, + FALSE, FALSE, 0); + + /* Setup the entry widget. */ + frame = gtk_frame_new(NULL); + gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); + gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); + gtk_widget_show(frame); + + gtkconv->entry_buffer = gtk_text_buffer_new(NULL); + g_object_set_data(G_OBJECT(gtkconv->entry_buffer), "user_data", conv); + gtkconv->entry = gtk_text_view_new_with_buffer(gtkconv->entry_buffer); + + gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(gtkconv->entry), GTK_WRAP_WORD); + gtk_widget_set_size_request(gtkconv->entry, buddy_chat_size.width, + MAX(buddy_chat_size.entry_height, 25)); + + /* Connect the signal handlers. */ + g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "key_press_event", + G_CALLBACK(entry_key_pressed_cb_1), + gtkconv->entry_buffer); + g_signal_connect_after(G_OBJECT(gtkconv->entry), "button_press_event", + G_CALLBACK(entry_stop_rclick_cb), NULL); + g_signal_connect(G_OBJECT(gtkconv->entry), "key_press_event", + G_CALLBACK(entry_key_pressed_cb_2), conv); + +#ifdef USE_GTKSPELL + if (convo_options & OPT_CONVO_CHECK_SPELLING) + gtkspell_new_attach(GTK_TEXT_VIEW(gtkconv->entry), NULL, NULL); +#endif + + gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(gtkconv->entry)); + gtk_widget_show(gtkconv->entry); + + /* Setup the bottom button box. */ + gtkconv->bbox = gtk_hbox_new(FALSE, 5); + gtk_box_pack_start(GTK_BOX(vbox), gtkconv->bbox, FALSE, FALSE, 0); + gtk_widget_show(gtkconv->bbox); + + setup_chat_buttons(conv, gtkconv->bbox); + + return vpaned; +} + +static GtkWidget * +setup_im_pane(struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + struct gaim_gtk_im_pane *gtkim; + GtkWidget *paned; + GtkWidget *vbox; + GtkWidget *vbox2; + GtkWidget *frame; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + gtkim = gtkconv->u.im; + + /* Setup the outer pane. */ + paned = gtk_vpaned_new(); + gtk_paned_set_gutter_size(GTK_PANED(paned), 15); + gtk_widget_show(paned); + + /* Setup the top part of the pane. */ + vbox = gtk_vbox_new(FALSE, 5); + gtk_paned_pack1(GTK_PANED(paned), vbox, FALSE, TRUE); + gtk_widget_show(vbox); + + /* Setup the gtkimhtml widget. */ + gtkconv->sw = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkconv->sw), + GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(gtkconv->sw), + GTK_SHADOW_IN); + gtk_box_pack_start(GTK_BOX(vbox), gtkconv->sw, TRUE, TRUE, 0); + gtk_widget_set_size_request(gtkconv->sw, conv_size.width, conv_size.height); + gtk_widget_show(gtkconv->sw); + + gtkconv->imhtml = gtk_imhtml_new(NULL, NULL); + gtk_container_add(GTK_CONTAINER(gtkconv->sw), gtkconv->imhtml); + + g_signal_connect_after(G_OBJECT(gtkconv->imhtml), "button_press_event", + G_CALLBACK(entry_stop_rclick_cb), NULL); + + gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), + (convo_options & OPT_CONVO_SHOW_TIME)); + + gaim_setup_imhtml(gtkconv->imhtml); + + gtk_widget_show(gtkconv->imhtml); + + vbox2 = gtk_vbox_new(FALSE, 5); + gtk_paned_pack2(GTK_PANED(paned), vbox2, FALSE, FALSE); + gtk_widget_show(vbox2); + + /* Build the toolbar. */ + gtkconv->toolbar.toolbar = build_conv_toolbar(conv); + gtk_box_pack_start(GTK_BOX(vbox2), gtkconv->toolbar.toolbar, + FALSE, FALSE, 0); + + /* Setup the entry widget. */ + 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); + + gtkconv->entry_buffer = gtk_text_buffer_new(NULL); + g_object_set_data(G_OBJECT(gtkconv->entry_buffer), "user_data", conv); + gtkconv->entry = gtk_text_view_new_with_buffer(gtkconv->entry_buffer); + + gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(gtkconv->entry), GTK_WRAP_WORD); + gtk_widget_set_size_request(gtkconv->entry, conv_size.width - 20, + MAX(conv_size.entry_height, 25)); + + /* Connect the signal handlers. */ + g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "key_press_event", + G_CALLBACK(entry_key_pressed_cb_1), + gtkconv->entry_buffer); + g_signal_connect(G_OBJECT(gtkconv->entry), "key_press_event", + G_CALLBACK(entry_key_pressed_cb_2), conv); + g_signal_connect_after(G_OBJECT(gtkconv->entry), "button_press_event", + G_CALLBACK(entry_stop_rclick_cb), NULL); + + g_signal_connect(G_OBJECT(gtkconv->entry_buffer), "insert_text", + G_CALLBACK(insert_text_cb), conv); + g_signal_connect(G_OBJECT(gtkconv->entry_buffer), "delete_range", + G_CALLBACK(delete_text_cb), conv); + +#ifdef USE_GTKSPELL + if (convo_options & OPT_CONVO_CHECK_SPELLING) + gtkspell_new_attach(GTK_TEXT_VIEW(gtkconv->entry), NULL, NULL); +#endif + + gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(gtkconv->entry)); + gtk_widget_show(gtkconv->entry); + + gtkconv->bbox = gtk_hbox_new(FALSE, 5); + gtk_box_pack_start(GTK_BOX(vbox2), gtkconv->bbox, FALSE, FALSE, 0); + gtk_widget_show(gtkconv->bbox); + + setup_im_buttons(conv, gtkconv->bbox); + + return paned; +} + +static void +move_next_tab(struct gaim_conversation *conv) +{ + struct gaim_conversation *next_conv = NULL; + struct gaim_window *win; + GList *l; + int index, i; + + win = gaim_conversation_get_window(conv); + index = gaim_conversation_get_index(conv); + + /* First check the tabs after this position. */ + for (l = g_list_nth(gaim_window_get_conversations(win), index); + l != NULL; + l = l->next) { + + next_conv = (struct gaim_conversation *)l->data; + + if (gaim_conversation_get_unseen(next_conv) > 0) + break; + + next_conv = NULL; + } + + if (next_conv == NULL) { + + /* Now check before this position. */ + for (l = gaim_window_get_conversations(win), i = 0; + l != NULL && i < index; + l = l->next) { + + next_conv = (struct gaim_conversation *)l->data; + + if (gaim_conversation_get_unseen(next_conv) > 0) + break; + + next_conv = NULL; + } + + if (next_conv == NULL) { + /* Okay, just grab the next conversation tab. */ + if (index == gaim_window_get_conversation_count(win) - 1) + next_conv = gaim_window_get_conversation_at(win, 0); + else + next_conv = gaim_window_get_conversation_at(win, index + 1); + } + } + + if (next_conv != NULL && next_conv != conv) { + gaim_window_switch_conversation(win, + gaim_conversation_get_index(next_conv)); + } +} + + +/************************************************************************** + * GTK+ window ops + **************************************************************************/ +static struct gaim_conversation_ops * +gaim_gtk_get_conversation_ops(void) +{ + return gaim_get_gtk_conversation_ops(); +} + +static void +gaim_gtk_new_window(struct gaim_window *win) +{ + struct gaim_gtk_window *gtkwin; + GtkPositionType pos; + GtkWidget *testidea; + GtkWidget *menubar; + + gtkwin = g_malloc0(sizeof(struct gaim_gtk_window)); + + win->ui_data = gtkwin; + + /* Create the window. */ + gtkwin->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_role(GTK_WINDOW(gtkwin->window), "conversation"); + gtk_window_set_policy(GTK_WINDOW(gtkwin->window), TRUE, TRUE, FALSE); + gtk_container_border_width(GTK_CONTAINER(gtkwin->window), 0); + gtk_widget_realize(gtkwin->window); + gtk_window_set_title(GTK_WINDOW(gtkwin->window), _("Gaim - Conversations")); + + g_signal_connect(G_OBJECT(gtkwin->window), "delete_event", + G_CALLBACK(close_win_cb), win); + + /* Create the notebook. */ + gtkwin->notebook = gtk_notebook_new(); + + pos = ((im_options & OPT_IM_SIDE_TAB) + ? ((im_options & OPT_IM_BR_TAB) ? GTK_POS_RIGHT : GTK_POS_LEFT) + : ((im_options & OPT_IM_BR_TAB) ? GTK_POS_BOTTOM : GTK_POS_TOP)); + +#if 0 + gtk_notebook_set_tab_hborder(GTK_NOTEBOOK(gtkwin->notebook), 0); + gtk_notebook_set_tab_vborder(GTK_NOTEBOOK(gtkwin->notebook), 0); +#endif + gtk_notebook_set_tab_pos(GTK_NOTEBOOK(gtkwin->notebook), pos); + gtk_notebook_set_scrollable(GTK_NOTEBOOK(gtkwin->notebook), TRUE); + gtk_notebook_popup_enable(GTK_NOTEBOOK(gtkwin->notebook)); + gtk_widget_show(gtkwin->notebook); + + g_signal_connect_after(G_OBJECT(gtkwin->notebook), "switch_page", + G_CALLBACK(switch_conv_cb), win); + + /* Setup the tab drag and drop signals. */ + gtk_widget_add_events(gtkwin->notebook, + GDK_BUTTON1_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK); + g_signal_connect(G_OBJECT(gtkwin->notebook), "button_press_event", + G_CALLBACK(notebook_press_cb), win); + g_signal_connect(G_OBJECT(gtkwin->notebook), "button_release_event", + G_CALLBACK(notebook_release_cb), win); + + testidea = gtk_vbox_new(FALSE, 0); + + /* Setup the menubar. */ + menubar = setup_menubar(win); + gtk_box_pack_start(GTK_BOX(testidea), menubar, FALSE, TRUE, 0); + + gtk_box_pack_start(GTK_BOX(testidea), gtkwin->notebook, TRUE, TRUE, 0); + + gtk_container_add(GTK_CONTAINER(gtkwin->window), testidea); + + gtk_widget_show(testidea); +} + +static void +gaim_gtk_destroy_window(struct gaim_window *win) +{ + struct gaim_gtk_window *gtkwin = GAIM_GTK_WINDOW(win); + + gtk_widget_destroy(gtkwin->window); + + g_free(gtkwin); + win->ui_data = NULL; +} + +static void +gaim_gtk_show(struct gaim_window *win) +{ + struct gaim_gtk_window *gtkwin = GAIM_GTK_WINDOW(win); + + gtk_widget_show(gtkwin->window); +} + +static void +gaim_gtk_hide(struct gaim_window *win) +{ + struct gaim_gtk_window *gtkwin = GAIM_GTK_WINDOW(win); + + gtk_widget_hide(gtkwin->window); +} + +static void +gaim_gtk_raise(struct gaim_window *win) +{ + struct gaim_gtk_window *gtkwin = GAIM_GTK_WINDOW(win); + + gdk_window_raise(gtkwin->window->window); +} + +static void +gaim_gtk_flash(struct gaim_window *win) +{ +#ifdef _WIN32 + struct gaim_gtk_window *gtkwin = GAIM_GTK_WINDOW(win); + + wgaim_im_blink(gtkwin->window); +#endif +} + +static void +gaim_gtk_switch_conversation(struct gaim_window *win, unsigned int index) +{ + struct gaim_gtk_window *gtkwin; + + gtkwin = GAIM_GTK_WINDOW(win); + + gtk_notebook_set_current_page(GTK_NOTEBOOK(gtkwin->notebook), index); +} + +static void +gaim_gtk_add_conversation(struct gaim_window *win, + struct gaim_conversation *conv) +{ + struct gaim_gtk_window *gtkwin; + struct gaim_gtk_conversation *gtkconv; + GtkWidget *pane = NULL; + GtkWidget *tab_cont; + GtkWidget *tabby; + gboolean new_ui; + + gtkwin = GAIM_GTK_WINDOW(win); + + if (conv->ui_data != NULL) { + gtkconv = (struct gaim_gtk_conversation *)conv->ui_data; + + tab_cont = gtkconv->tab_cont; + + new_ui = FALSE; + } + else { + gtkconv = g_malloc0(sizeof(struct gaim_gtk_conversation)); + conv->ui_data = gtkconv; + + /* Setup some initial variables. */ + gtkconv->sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); + gtkconv->tooltips = gtk_tooltips_new(); + + if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { + gtkconv->u.chat = g_malloc0(sizeof(struct gaim_gtk_chat_pane)); + + pane = setup_chat_pane(conv); + } + else if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { + gtkconv->u.im = g_malloc0(sizeof(struct gaim_gtk_im_pane)); + gtkconv->u.im->a_virgin = TRUE; + + pane = setup_im_pane(conv); + } + + if (pane == NULL) { + if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { + g_free(gtkconv->u.chat); + } + else if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { + g_free(gtkconv->u.im); + }; + + g_free(gtkconv); + conv->ui_data = NULL; + + return; + } + + /* Setup the container for the tab. */ + gtkconv->tab_cont = tab_cont = gtk_vbox_new(FALSE, 5); + gtk_container_set_border_width(GTK_CONTAINER(tab_cont), 5); + gtk_container_add(GTK_CONTAINER(tab_cont), pane); + gtk_widget_show(pane); + + new_ui = TRUE; + + gtkconv->make_sound = TRUE; + } + + gtkconv->tabby = tabby = gtk_hbox_new(FALSE, 5); + + /* Close button. */ + gtkconv->close = gtk_button_new(); + gtk_widget_set_size_request(GTK_WIDGET(gtkconv->close), 16, 16); + gtk_container_add(GTK_CONTAINER(gtkconv->close), + gtk_image_new_from_stock(GTK_STOCK_CLOSE, + GTK_ICON_SIZE_MENU)); + gtk_button_set_relief(GTK_BUTTON(gtkconv->close), GTK_RELIEF_NONE); + gtk_tooltips_set_tip(gtkconv->tooltips, gtkconv->close, + _("Close conversation"), NULL); + + g_signal_connect(G_OBJECT(gtkconv->close), "clicked", + G_CALLBACK(close_conv_cb), conv); + + /* Tab label. */ + gtkconv->tab_label = gtk_label_new(gaim_conversation_get_title(conv)); +#if 0 + gtk_misc_set_alignment(GTK_MISC(gtkconv->tab_label), 0.00, 0.5); + gtk_misc_set_padding(GTK_MISC(gtkconv->tab_label), 4, 0); +#endif + + /* Pack it all together. */ + gtk_box_pack_start(GTK_BOX(tabby), gtkconv->tab_label, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(tabby), gtkconv->close, FALSE, FALSE, 0); + gtk_widget_show_all(tabby); + + + /* Add this pane to the conversations notebook. */ + gtk_notebook_append_page(GTK_NOTEBOOK(gtkwin->notebook), tab_cont, tabby); + gtk_notebook_set_menu_label_text(GTK_NOTEBOOK(gtkwin->notebook), tab_cont, + gaim_conversation_get_title(conv)); + + gtk_widget_show(tab_cont); + + /* Er, bug in notebooks? Switch to the page manually. */ + if (gaim_window_get_conversation_count(win) == 1) + gtk_notebook_set_current_page(GTK_NOTEBOOK(gtkwin->notebook), 0); + + debug_printf("*** Current page = %d\n", + gtk_notebook_get_current_page(GTK_NOTEBOOK(gtkwin->notebook))); + + if ((gtk_notebook_get_current_page(GTK_NOTEBOOK(gtkwin->notebook)) == 0) || + (conv == g_list_nth_data(gaim_window_get_conversations(win), 0))) { + + gtk_widget_grab_focus(gtkconv->entry); + } + + gaim_gtkconv_update_buddy_icon(conv); + + if (!new_ui) + g_object_unref(gtkconv->tab_cont); + + if (gaim_window_get_conversation_count(win) == 1) + update_send_as_selection(win); +} + +static void +gaim_gtk_remove_conversation(struct gaim_window *win, + struct gaim_conversation *conv) +{ + struct gaim_gtk_window *gtkwin; + struct gaim_gtk_conversation *gtkconv; + unsigned int index; + + index = gaim_conversation_get_index(conv); + + gtkwin = GAIM_GTK_WINDOW(win); + gtkconv = GAIM_GTK_CONVERSATION(conv); + + g_object_ref(gtkconv->tab_cont); + gtk_object_sink(GTK_OBJECT(gtkconv->tab_cont)); + + gaim_gtk_set_state_lock(TRUE); + + gtk_notebook_remove_page(GTK_NOTEBOOK(gtkwin->notebook), index); + + gaim_gtk_set_state_lock(FALSE); + + /* If this window is setup with an inactive gc, regenerate the menu. */ + debug_printf("remove_conv: user == %p\n", gaim_conversation_get_user(conv)); + debug_printf("remove_conv: user->gc == %p\n", gaim_conversation_get_user(conv)->gc); + debug_printf("remove_conv: gc == %p\n", gaim_conversation_get_gc(conv)); + if (gaim_conversation_get_type(conv) == GAIM_CONV_IM && + gaim_conversation_get_gc(conv) == NULL) { + + debug_printf("Going to generate send as items.\n"); + generate_send_as_items(win); + } +} + +static void +gaim_gtk_move_conversation(struct gaim_window *win, + struct gaim_conversation *conv, + unsigned int new_index) +{ + struct gaim_gtk_window *gtkwin; + struct gaim_gtk_conversation *gtkconv; + + gtkwin = GAIM_GTK_WINDOW(win); + gtkconv = GAIM_GTK_CONVERSATION(conv); + + gtk_notebook_reorder_child(GTK_NOTEBOOK(gtkwin->notebook), + gtkconv->tab_cont, new_index); +} + +static int +gaim_gtk_get_active_index(const struct gaim_window *win) +{ + struct gaim_gtk_window *gtkwin; + + gtkwin = GAIM_GTK_WINDOW(win); + + return gtk_notebook_get_current_page(GTK_NOTEBOOK(gtkwin->notebook)); +} + +static struct gaim_window_ops window_ops = +{ + gaim_gtk_get_conversation_ops, + gaim_gtk_new_window, + gaim_gtk_destroy_window, + gaim_gtk_show, + gaim_gtk_hide, + gaim_gtk_raise, + gaim_gtk_flash, + gaim_gtk_switch_conversation, + gaim_gtk_add_conversation, + gaim_gtk_remove_conversation, + gaim_gtk_move_conversation, + gaim_gtk_get_active_index +}; + +static void +update_convo_add_button(struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + struct gaim_connection *gc; + GaimConversationType type; + GtkWidget *parent; + gboolean rebuild = FALSE; + + type = gaim_conversation_get_type(conv); + gc = gaim_conversation_get_gc(conv); + gtkconv = GAIM_GTK_CONVERSATION(conv); + parent = gtk_widget_get_parent(gtkconv->u.im->add); + + if (find_buddy(gc->user, gaim_conversation_get_name(conv))) { + if (!g_object_get_data(G_OBJECT(gtkconv->u.im->add), "user_data")) { + gtkconv->u.im->add = + gaim_gtk_change_text(_("Remove"), gtkconv->u.im->add, + GTK_STOCK_REMOVE, type); + + rebuild = TRUE; + } + + gtk_widget_set_sensitive(gtkconv->u.im->add, + (gc != NULL && gc->prpl->remove_buddy != NULL)); + + g_object_set_data(G_OBJECT(gtkconv->u.im->add), "user_data", conv); + + } else { + if (g_object_get_data(G_OBJECT(gtkconv->u.im->add), "user_data")) { + gtkconv->u.im->add = + gaim_gtk_change_text(_("Add"), gtkconv->u.im->add, + GTK_STOCK_ADD, type); + + rebuild = TRUE; + } + + gtk_widget_set_sensitive(gtkconv->u.im->add, + (gc != NULL && gc->prpl->add_buddy != NULL)); + } + + if (rebuild) { + g_signal_connect(G_OBJECT(gtkconv->u.im->add), "clicked", + G_CALLBACK(add_cb), conv); + + gtk_box_pack_start(GTK_BOX(parent), gtkconv->u.im->add, + FALSE, FALSE, 0); + gtk_box_reorder_child(GTK_BOX(parent), gtkconv->u.im->add, 3); + gtk_button_set_relief(GTK_BUTTON(gtkconv->u.im->add), GTK_RELIEF_NONE); + gtk_size_group_add_widget(gtkconv->sg, gtkconv->u.im->add); + } +} + +struct gaim_window_ops * +gaim_get_gtk_window_ops(void) +{ + return &window_ops; +} + +/************************************************************************** + * Conversation ops + **************************************************************************/ +static void +gaim_gtkconv_destroy(struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv = GAIM_GTK_CONVERSATION(conv); + + if (gtkconv->dialogs.fg_color != NULL) + gtk_widget_destroy(gtkconv->dialogs.fg_color); + + if (gtkconv->dialogs.bg_color != NULL) + gtk_widget_destroy(gtkconv->dialogs.bg_color); + + if (gtkconv->dialogs.font != NULL) + gtk_widget_destroy(gtkconv->dialogs.font); + + if (gtkconv->dialogs.smiley != NULL) + gtk_widget_destroy(gtkconv->dialogs.smiley); + + if (gtkconv->dialogs.link != NULL) + gtk_widget_destroy(gtkconv->dialogs.link); + + if (gtkconv->dialogs.log != NULL) + gtk_widget_destroy(gtkconv->dialogs.log); + + if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { + if (gtkconv->u.im->save_icon != NULL) + gtk_widget_destroy(gtkconv->u.im->save_icon); + + if (gtkconv->u.im->anim != NULL) + gdk_pixbuf_animation_unref(gtkconv->u.im->anim); + + g_free(gtkconv->u.im); + } + else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { + g_free(gtkconv->u.chat); + } + + g_free(gtkconv); +} + +static void +gaim_gtkconv_write_im(struct gaim_conversation *conv, const char *who, + const char *message, size_t len, int flags, time_t mtime) +{ + struct gaim_gtk_conversation *gtkconv; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + debug_printf("Write IM\n"); + + if (gtkconv->make_sound) { + if (flags & WFLAG_RECV) { + if (gtkconv->u.im->a_virgin && + (sound_options & OPT_SOUND_FIRST_RCV)) { + + play_sound(SND_FIRST_RECEIVE); + } + else + play_sound(SND_RECEIVE); + } + else { + debug_printf("Playing SND_SEND\n"); + play_sound(SND_SEND); + } + } + + gtkconv->u.im->a_virgin = FALSE; + + gaim_conversation_write(conv, who, message, len, flags, mtime); +} + +static void +gaim_gtkconv_write_chat(struct gaim_conversation *conv, const char *who, + const char *message, int flags, time_t mtime) +{ + struct gaim_gtk_conversation *gtkconv; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + if (gtkconv->make_sound) { + if (!(flags & WFLAG_WHISPER) && (flags & WFLAG_SEND)) + play_sound(SND_CHAT_YOU_SAY); + else if (flags & WFLAG_RECV) { + if ((flags & 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) + flags |= WFLAG_COLORIZE; + + gaim_conversation_write(conv, who, message, -1, flags, mtime); +} + +static void +gaim_gtkconv_write_conv(struct gaim_conversation *conv, const char *who, + const char *message, size_t length, int flags, + time_t mtime) +{ + struct gaim_gtk_conversation *gtkconv; + struct gaim_connection *gc; + int gtk_font_options = 0; + GString *log_str; + FILE *fd; + char buf[BUF_LONG]; + char buf2[BUF_LONG]; + char mdate[64]; + char color[10]; + char *str; + char *with_font_tag; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + gc = gaim_conversation_get_gc(conv); + + strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime)); + + gtk_font_options ^= GTK_IMHTML_NO_COMMENTS; + + if (convo_options & OPT_CONVO_IGNORE_COLOUR) + gtk_font_options ^= GTK_IMHTML_NO_COLOURS; + + if (convo_options & OPT_CONVO_IGNORE_FONTS) + gtk_font_options ^= GTK_IMHTML_NO_FONTS; + + if (convo_options & OPT_CONVO_IGNORE_SIZES) + gtk_font_options ^= GTK_IMHTML_NO_SIZES; + + if (!(logging_options & OPT_LOG_STRIP_HTML)) + gtk_font_options ^= GTK_IMHTML_RETURN_LOG; + + if (flags & WFLAG_SYSTEM) { + if (convo_options & OPT_CONVO_SHOW_TIME) + g_snprintf(buf, BUF_LONG, "(%s) %s", + mdate, message); + else + g_snprintf(buf, BUF_LONG, "%s", message); + + g_snprintf(buf2, sizeof(buf2), + "%s
", + mdate, message); + + gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, -1, 0); + + if (logging_options & OPT_LOG_STRIP_HTML) { + char *t1 = strip_html(buf); + + conv->history = g_string_append(conv->history, t1); + conv->history = g_string_append(conv->history, "\n"); + + g_free(t1); + } + else { + conv->history = g_string_append(conv->history, buf); + conv->history = g_string_append(conv->history, "
\n"); + } + + if (!(flags & WFLAG_NOLOG) && gaim_conversation_is_logging(conv)) { +/* + XXX + ((gaim_conversation_get_type(conv) == GAIM_CONV_CHAT && + (logging_options & OPT_LOG_CHATS)) || + (gaim_conversation_get_type(conv) == GAIM_CONV_IM && + (logging_options & OPT_LOG_CONVOS)) || + find_log_info(gaim_conversation_get_name(conv)))) { +*/ + + char *t1; + char nm[256]; + + if (logging_options & OPT_LOG_STRIP_HTML) + t1 = strip_html(buf); + else + t1 = buf; + + if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) + g_snprintf(nm, sizeof(nm), "%s.chat", + gaim_conversation_get_name(conv)); + else + strncpy(nm, gaim_conversation_get_name(conv), sizeof(nm)); + + fd = open_log_file(nm, + (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT)); + + if (fd) { + if (logging_options & OPT_LOG_STRIP_HTML) + fprintf(fd, "%s\n", t1); + else + fprintf(fd, "%s
\n", t1); + + fclose(fd); + } + + if (logging_options & OPT_LOG_STRIP_HTML) + g_free(t1); + } + } + else if (flags & WFLAG_NOLOG) { + g_snprintf(buf, BUF_LONG, + "%s
", + message); + + gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf, -1, 0); + } + else { + char *new_message = g_strdup(message); + + if (flags & WFLAG_WHISPER) { + str = g_malloc(1024); + + /* If we're whispering, it's not an autoresponse. */ + if (meify(new_message, length)) { + g_snprintf(str, 1024, "***%s", who); + strcpy(color, "#6C2585"); + } + else { + g_snprintf(str, 1024, "*%s*:", who); + strcpy(color, "#00FF00"); + } + } + else { + if (meify(new_message, 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(color, "#AF7F00"); + else + strcpy(color, "#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(color, "#AF7F00"); + else if (flags & WFLAG_RECV) { + if (flags & WFLAG_COLORIZE) { + const char *u; + int m = 0; + + for (u = who; *u != '\0'; u++) + m += *u; + + m = m % NUM_NICK_COLORS; + + strcpy(color, nick_colors[m]); + } + else + strcpy(color, "#A82F2F"); + } + else if (flags & WFLAG_SEND) + strcpy(color, "#16569E"); + } + } + + if (convo_options & OPT_CONVO_SHOW_TIME) + g_snprintf(buf, BUF_LONG, + "(%s) " + "%s ", color, mdate, str); + else + g_snprintf(buf, BUF_LONG, + "%s ", color, str); + + g_snprintf(buf2, BUF_LONG, + "" + "%s ", + color, mdate, str); + + g_free(str); + + gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, -1, 0); + + with_font_tag = g_strdup_printf("%s", + gc->prpl->name, new_message); + + log_str = gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), + with_font_tag, length, + gtk_font_options); + + gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "
", -1, 0); + + /* 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(new_message); + + conv->history = g_string_append(conv->history, t1); + conv->history = g_string_append(conv->history, t2); + conv->history = g_string_append(conv->history, "\n"); + + g_free(t1); + g_free(t2); + } + else { + char *t1, *t2; + + t1 = html_logize(buf); + t2 = html_logize(new_message); + + conv->history = g_string_append(conv->history, t1); + conv->history = g_string_append(conv->history, t2); + conv->history = g_string_append(conv->history, "\n"); + conv->history = g_string_append(conv->history, log_str->str); + conv->history = g_string_append(conv->history, "
\n"); + + g_free(t1); + g_free(t2); + } + + /* XXX This needs to be updated for the new length argument. */ + if (gaim_conversation_is_logging(conv)) { +/* + XXX + if ((gaim_conversation_get_type(conv) == GAIM_CONV_CHAT && + (logging_options & OPT_LOG_CHATS)) || + (gaim_conversation_get_type(conv) == GAIM_CONV_IM && + (logging_options & OPT_LOG_CONVOS)) || + find_log_info(gaim_conversation_get_name(conv))) { +*/ + + char *t1, *t2; + char nm[256]; + + if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) + g_snprintf(nm, sizeof(nm), "%s.chat", + gaim_conversation_get_name(conv)); + else + strncpy(nm, gaim_conversation_get_name(conv), sizeof(nm)); + + if (logging_options & OPT_LOG_STRIP_HTML) { + t1 = strip_html(buf); + t2 = strip_html(with_font_tag); + } + else { + t1 = html_logize(buf); + t2 = html_logize(with_font_tag); + } + + fd = open_log_file(nm, + (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT)); + + if (fd) { + if (logging_options & OPT_LOG_STRIP_HTML) + fprintf(fd, "%s%s\n", t1, t2); + else { + fprintf(fd, "%s%s%s
\n", t1, t2, log_str->str); + g_string_free(log_str, TRUE); + } + + fclose(fd); + } + + g_free(t1); + g_free(t2); + } + + g_free(with_font_tag); + g_free(new_message); + } +} + +static void +gaim_gtkconv_chat_add_user(struct gaim_conversation *conv, const char *user) +{ + struct gaim_chat *chat; + struct gaim_gtk_conversation *gtkconv; + struct gaim_gtk_chat_pane *gtkchat; + char tmp[BUF_LONG]; + int num_users; + int pos; + + chat = GAIM_CHAT(conv); + gtkconv = GAIM_GTK_CONVERSATION(conv); + gtkchat = gtkconv->u.chat; + + num_users = g_list_length(gaim_chat_get_users(chat)); + + g_snprintf(tmp, sizeof(tmp), + ngettext("%d person in room", "%d people in room", + num_users), + num_users); + + gtk_label_set_text(GTK_LABEL(gtkchat->count), tmp); + + if (gtkconv->make_sound) + play_sound(SND_CHAT_JOIN); + + pos = g_list_index(gaim_chat_get_users(chat), user); + + add_chat_buddy_common(conv, user, pos); +} + +static void +gaim_gtkconv_chat_rename_user(struct gaim_conversation *conv, + const char *old_name, const char *new_name) +{ + struct gaim_chat *chat; + struct gaim_gtk_conversation *gtkconv; + struct gaim_gtk_chat_pane *gtkchat; + GtkTreeIter iter; + GtkTreeModel *model; + GList *names; + int pos; + int f = 1; + + chat = GAIM_CHAT(conv); + gtkconv = GAIM_GTK_CONVERSATION(conv); + gtkchat = gtkconv->u.chat; + + for (names = gaim_chat_get_users(chat); + names != NULL; + names = names->next) { + + char *u = (char *)names->data; + + if (!g_strcasecmp(u, old_name)) { + model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); + + if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) + break; + + while (f != 0) { + char *val; + + gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &val, -1); + + if (!g_strcasecmp(old_name, val)) + gtk_list_store_remove(GTK_LIST_STORE(model), &iter); + + f = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter); + + g_free(val); + } + + break; + } + } + + if (!names) + return; + + pos = g_list_index(gaim_chat_get_users(chat), new_name); + + add_chat_buddy_common(conv, new_name, pos); +} + +static void +gaim_gtkconv_chat_remove_user(struct gaim_conversation *conv, const char *user) +{ + struct gaim_chat *chat; + struct gaim_gtk_conversation *gtkconv; + struct gaim_gtk_chat_pane *gtkchat; + GtkTreeIter iter; + GtkTreeModel *model; + GList *names; + char tmp[BUF_LONG]; + int num_users; + int f = 1; + + chat = GAIM_CHAT(conv); + gtkconv = GAIM_GTK_CONVERSATION(conv); + gtkchat = gtkconv->u.chat; + + num_users = g_list_length(gaim_chat_get_users(chat)) - 1; + + for (names = gaim_chat_get_users(chat); + names != NULL; + names = names->next) { + + char *u = (char *)names->data; + + if (!g_strcasecmp(u, user)) { + model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); + + if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) + break; + + while (f != 0) { + char *val; + + gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &val, -1); + + if (!g_strcasecmp(user, val)) + gtk_list_store_remove(GTK_LIST_STORE(model), &iter); + + f = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter); + + g_free(val); + } + + break; + } + } + + if (names == NULL) + return; + + g_snprintf(tmp, sizeof(tmp), + ngettext("%d person in room", "%d people in room", + num_users), num_users); + + gtk_label_set_text(GTK_LABEL(gtkchat->count), tmp); + + if (gtkconv->make_sound) + play_sound(SND_CHAT_LEAVE); +} + +static void +gaim_gtkconv_set_title(struct gaim_conversation *conv, const char *title) +{ + struct gaim_gtk_conversation *gtkconv; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + gtk_label_set_text(GTK_LABEL(gtkconv->tab_label), title); +} + +static void +gaim_gtkconv_updated(struct gaim_conversation *conv, GaimConvUpdateType type) +{ + struct gaim_window *win; + struct gaim_gtk_conversation *gtkconv; + struct gaim_gtk_chat_pane *gtkchat; + struct gaim_chat *chat; + + win = gaim_conversation_get_window(conv); + gtkconv = GAIM_GTK_CONVERSATION(conv); + + if (type == GAIM_CONV_UPDATE_USER) { + gaim_conversation_autoset_title(conv); + gaim_gtkconv_update_buddy_icon(conv); + gaim_gtkconv_update_buttons_by_protocol(conv); + + update_send_as_selection(win); + + smiley_themeize(gtkconv->imhtml); + } + else if (type == GAIM_CONV_UPDATE_TYPING || + type == GAIM_CONV_UPDATE_UNSEEN) { + + GtkStyle *style; + struct gaim_im *im = NULL; + + if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) + im = GAIM_IM(conv); + + style = gtk_style_new(); + + if (!GTK_WIDGET_REALIZED(gtkconv->tab_label)) + gtk_widget_realize(gtkconv->tab_label); + + gtk_style_set_font(style, + gdk_font_ref(gtk_style_get_font(gtk_widget_get_style( + gtkconv->tab_label)))); + + if (im != NULL && gaim_im_get_typing_state(im) == TYPING) { + style->fg[0].red = 0x0000; + style->fg[0].green = 0x9999; + style->fg[0].blue = 0x0000; + } + else if (im != NULL && gaim_im_get_typing_state(im) == TYPED) { + style->fg[0].red = 0xFFFF; + style->fg[0].green = 0xBBBB; + style->fg[0].blue = 0x2222; + } + else if (gaim_conversation_get_unseen(conv) == GAIM_UNSEEN_NICK) { + style->fg[0].red = 0x0000; + style->fg[0].green = 0x0000; + style->fg[0].blue = 0xCCCC; + } + else if (gaim_conversation_get_unseen(conv) == GAIM_UNSEEN_TEXT) { + style->fg[0].red = 0xCCCC; + style->fg[0].green = 0x0000; + style->fg[0].blue = 0x0000; + } + + gtk_widget_set_style(gtkconv->tab_label, style); + gtk_style_unref(style); + } + else if (type == GAIM_CONV_UPDATE_TOPIC) { + chat = GAIM_CHAT(conv); + gtkchat = gtkconv->u.chat; + + gtk_entry_set_text(GTK_ENTRY(gtkchat->topic_text), + gaim_chat_get_topic(chat)); + } + else if (type == GAIM_CONV_ACCOUNT_ONLINE || + type == GAIM_CONV_ACCOUNT_OFFLINE) { + + generate_send_as_items(win); + } +} + +static struct gaim_conversation_ops conversation_ops = +{ + gaim_gtkconv_destroy, /* destroy_conversation */ + gaim_gtkconv_write_chat, /* write_chat */ + gaim_gtkconv_write_im, /* write_im */ + gaim_gtkconv_write_conv, /* write_conv */ + gaim_gtkconv_chat_add_user, /* chat_add_user */ + gaim_gtkconv_chat_rename_user, /* chat_rename_user */ + gaim_gtkconv_chat_remove_user, /* chat_remove_user */ + gaim_gtkconv_set_title, /* set_title */ + NULL, /* update_progress */ + gaim_gtkconv_updated /* updated */ +}; + +struct gaim_conversation_ops * +gaim_get_gtk_conversation_ops(void) +{ + return &conversation_ops;; +} + +/************************************************************************** + * Public conversation utility functions + **************************************************************************/ +void +gaim_gtk_set_state_lock(gboolean lock) +{ + state_lock = lock; +} + +gboolean +gaim_gtk_is_state_locked(void) +{ + return state_lock; +} + +void +gaim_gtkconv_toggle_smileys(void) +{ + GList *cl; + struct gaim_conversation *conv; + struct gaim_gtk_conversation *gtkconv; + + for (cl = gaim_get_conversations(); cl != NULL; cl = cl->next) { + + conv = (struct gaim_conversation *)cl->data; + + if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) + continue; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + gtk_imhtml_show_smileys(GTK_IMHTML(gtkconv->imhtml), + (convo_options & OPT_CONVO_SHOW_SMILEY)); + } +} + +void +gaim_gtkconv_toggle_timestamps(void) +{ + GList *cl; + struct gaim_conversation *conv; + struct gaim_gtk_conversation *gtkconv; + + for (cl = gaim_get_conversations(); cl != NULL; cl = cl->next) { + + conv = (struct gaim_conversation *)cl->data; + + if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) + continue; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), + (convo_options & OPT_CONVO_SHOW_TIME)); + } +} + +void +gaim_gtkconv_toggle_spellchk(void) +{ +#ifdef USE_GTKSPELL + GList *cl; + struct gaim_conversation *conv; + struct gaim_gtk_conversation *gtkconv; + GtkSpell *spell; + + for (cl = gaim_get_conversations(); cl != NULL; cl = cl->next) { + + conv = (struct gaim_conversation *)cl->data; + + if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) + continue; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + if (convo_options & OPT_CONVO_CHECK_SPELLING) + gtkspell_new_attach(GTK_TEXT_VIEW(gtkconv->entry), NULL, NULL); + else { + spell = gtkspell_get_from_text_view(GTK_TEXT_VIEW(gtkconv->entry)); + gtkspell_detach(spell); + } + } +#endif +} + +static void +remove_icon(struct gaim_gtk_conversation *gtkconv) +{ + if (gtkconv == NULL) + return; + + if (gtkconv->u.im->icon != NULL) + gtk_container_remove(GTK_CONTAINER(gtkconv->bbox), + gtkconv->u.im->icon->parent->parent); + + if (gtkconv->u.im->anim != NULL) + gdk_pixbuf_animation_unref(gtkconv->u.im->anim); + + if (gtkconv->u.im->icon_timer != 0) + g_source_remove(gtkconv->u.im->icon_timer); + + if (gtkconv->u.im->iter != NULL) + g_object_unref(G_OBJECT(gtkconv->u.im->iter)); + + gtkconv->u.im->icon_timer = 0; + gtkconv->u.im->icon = NULL; + gtkconv->u.im->anim = NULL; + gtkconv->u.im->iter = NULL; +} + +static gboolean +redraw_icon(gpointer data) +{ + struct gaim_conversation *conv = (struct gaim_conversation *)data; + struct gaim_gtk_conversation *gtkconv; + + GdkPixbuf *buf; + GdkPixbuf *scale; + GdkPixmap *pm; + GdkBitmap *bm; + gint delay; + + if (!g_list_find(gaim_get_ims(), conv)) { + debug_printf("I think this is a bug.\n"); + return FALSE; + } + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + gdk_pixbuf_animation_iter_advance(gtkconv->u.im->iter, NULL); + buf = gdk_pixbuf_animation_iter_get_pixbuf(gtkconv->u.im->iter); + + scale = gdk_pixbuf_scale_simple(buf, + MAX(gdk_pixbuf_get_width(buf) * SCALE(gtkconv->u.im->anim) / + gdk_pixbuf_animation_get_width(gtkconv->u.im->anim), 1), + MAX(gdk_pixbuf_get_height(buf) * SCALE(gtkconv->u.im->anim) / + gdk_pixbuf_animation_get_height(gtkconv->u.im->anim), 1), + GDK_INTERP_NEAREST); + + gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100); + gdk_pixbuf_unref(scale); + gtk_pixmap_set(GTK_PIXMAP(gtkconv->u.im->icon), pm, bm); + gdk_pixmap_unref(pm); + gtk_widget_queue_draw(gtkconv->u.im->icon); + + if (bm) + gdk_bitmap_unref(bm); + + delay = gdk_pixbuf_animation_iter_get_delay_time(gtkconv->u.im->iter) / 10; + + gtkconv->u.im->icon_timer = g_timeout_add(delay * 10, redraw_icon, conv); + + return FALSE; +} + +static void +start_anim(GtkObject *obj, struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + int delay; + + if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) + return; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + delay = gdk_pixbuf_animation_iter_get_delay_time(gtkconv->u.im->iter) / 10; + + if (gtkconv->u.im->anim) + gtkconv->u.im->icon_timer = g_timeout_add(delay * 10, redraw_icon, + conv); +} + +static void +stop_anim(GtkObject *obj, struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + + if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) + return; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + if (gtkconv->u.im->icon_timer != 0) + g_source_remove(gtkconv->u.im->icon_timer); + + gtkconv->u.im->icon_timer = 0; +} + +static gboolean +icon_menu(GtkObject *obj, GdkEventButton *e, struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + static GtkWidget *menu = NULL; + GtkWidget *button; + + if (e->button != 3 || e->type != GDK_BUTTON_PRESS) + return FALSE; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + /* + * If a menu already exists, destroy it before creating a new one, + * thus freeing-up the memory it occupied. + */ + if (menu != NULL) + gtk_widget_destroy(menu); + + menu = gtk_menu_new(); + + if (gtkconv->u.im->icon_timer) { + button = gtk_menu_item_new_with_label(_("Disable Animation")); + g_signal_connect(GTK_OBJECT(button), "activate", + G_CALLBACK(stop_anim), conv); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), button); + gtk_widget_show(button); + } + else if (gtkconv->u.im->anim && + !(gdk_pixbuf_animation_is_static_image(gtkconv->u.im->anim))) + { + button = gtk_menu_item_new_with_label(_("Enable Animation")); + g_signal_connect(GTK_OBJECT(button), "activate", + G_CALLBACK(start_anim), conv); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), button); + gtk_widget_show(button); + } + + button = gtk_menu_item_new_with_label(_("Hide Icon")); + g_signal_connect_swapped(GTK_OBJECT(button), "activate", + G_CALLBACK(remove_icon), conv); + 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(gaim_gtk_save_icon_dialog), conv); + 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 +gaim_gtkconv_update_buddy_icon(struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + + 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 (conv == NULL || + gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops() || + gaim_conversation_get_type(conv) != GAIM_CONV_IM) { + + return; + } + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + remove_icon(gtkconv); + + if (im_options & OPT_IM_HIDE_ICONS) + return; + + if (gaim_conversation_get_gc(conv) == NULL) + return; + + data = get_icon_data(gaim_conversation_get_gc(conv), + normalize(gaim_conversation_get_name(conv)), + &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(), gaim_conversation_get_name(conv), getpid()); + + if (!(file = fopen(filename, "w"))) + return; + + fwrite(data, 1, len, file); + fclose(file); + + gtkconv->u.im->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 (!gtkconv->u.im->anim) + return; + + if (gdk_pixbuf_animation_is_static_image(gtkconv->u.im->anim)) { + gtkconv->u.im->iter = NULL; + delay = 0; + buf = gdk_pixbuf_animation_get_static_image(gtkconv->u.im->anim); + } else { + gtkconv->u.im->iter = + gdk_pixbuf_animation_get_iter(gtkconv->u.im->anim, NULL); + buf = gdk_pixbuf_animation_iter_get_pixbuf(gtkconv->u.im->iter); + delay = gdk_pixbuf_animation_iter_get_delay_time(gtkconv->u.im->iter); + delay = delay / 10; + } + + sf = SCALE(gtkconv->u.im->anim); + scale = gdk_pixbuf_scale_simple(buf, + MAX(gdk_pixbuf_get_width(buf) * sf / + gdk_pixbuf_animation_get_width(gtkconv->u.im->anim), 1), + MAX(gdk_pixbuf_get_height(buf) * sf / + gdk_pixbuf_animation_get_height(gtkconv->u.im->anim), 1), + GDK_INTERP_NEAREST); + + if (delay) + gtkconv->u.im->icon_timer = g_timeout_add(delay * 10, redraw_icon, + conv); + + 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(gtkconv->bbox), frame, FALSE, FALSE, 5); + gtk_box_reorder_child(GTK_BOX(gtkconv->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), conv); + gtk_widget_show(event); + + gtkconv->u.im->icon = gtk_pixmap_new(pm, bm); + gtk_widget_set_size_request(gtkconv->u.im->icon, sf, sf); + gtk_container_add(GTK_CONTAINER(event), gtkconv->u.im->icon); + gtk_widget_show(gtkconv->u.im->icon); + + if(im_options & OPT_IM_NO_ANIMATION) + stop_anim(NULL, conv); + + gdk_pixmap_unref(pm); + + if (bm) + gdk_bitmap_unref(bm); +} + +void +gaim_gtkconv_hide_buddy_icons(void) +{ + gaim_conversation_foreach(gaim_gtkconv_update_buddy_icon); +} + +void +gaim_gtkconv_set_anim(void) +{ + GList *l; + + if (im_options & OPT_IM_HIDE_ICONS) + return; + + if (im_options & OPT_IM_NO_ANIMATION) { + for (l = gaim_get_ims(); l != NULL; l = l->next) + stop_anim(NULL, (struct gaim_conversation *)l->data); + } else { + for (l = gaim_get_ims(); l != NULL; l = l->next) + start_anim(NULL, (struct gaim_conversation *)l->data); + } +} + +void +gaim_gtkconv_update_font_buttons(void) +{ + GList *l; + struct gaim_conversation *conv; + struct gaim_gtk_conversation *gtkconv; + + for (l = gaim_get_ims(); l != NULL; l = l->next) { + conv = (struct gaim_conversation *)l->data; + + if (gaim_conversation_get_ops(conv) != + gaim_get_gtk_conversation_ops()) + continue; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + if (gtkconv->toolbar.bold != NULL) + gtk_widget_set_sensitive(gtkconv->toolbar.bold, + (!(font_options & OPT_FONT_BOLD))); + + if (gtkconv->toolbar.italic != NULL) + gtk_widget_set_sensitive(gtkconv->toolbar.italic, + (!(font_options & OPT_FONT_ITALIC))); + + if (gtkconv->toolbar.underline != NULL) + gtk_widget_set_sensitive(gtkconv->toolbar.underline, + (!(font_options & OPT_FONT_UNDERLINE))); + } +} + +void +gaim_gtkconv_update_tabs(void) +{ + GList *l; + GtkPositionType pos; + struct gaim_window *win; + struct gaim_gtk_window *gtkwin; + + pos = ((im_options & OPT_IM_SIDE_TAB) + ? ((im_options & OPT_IM_BR_TAB) ? GTK_POS_RIGHT : GTK_POS_LEFT) + : ((im_options & OPT_IM_BR_TAB) ? GTK_POS_BOTTOM : GTK_POS_TOP)); + + for (l = gaim_get_windows(); l != NULL; l = l->next) { + win = (struct gaim_window *)l->data; + + if (gaim_window_get_ops(win) != gaim_get_gtk_window_ops()) + continue; + + gtkwin = GAIM_GTK_WINDOW(win); + + gtk_notebook_set_tab_pos(GTK_NOTEBOOK(gtkwin->notebook), pos); + } +} + +void +gaim_gtkconv_update_chat_button_style() +{ + GSList *l; + struct gaim_connection *g; + GtkWidget *parent; + GaimConversationType type = GAIM_CONV_CHAT; + + for (l = connections; l != NULL; l = l->next) { + GSList *bcs; + struct gaim_conversation *conv; + struct gaim_gtk_conversation *gtkconv; + struct gaim_gtk_window *gtkwin; + + g = (struct gaim_connection *)l->data; + + for (bcs = g->buddy_chats; bcs != NULL; bcs = bcs->next) { + conv = (struct gaim_conversation *)bcs->data; + + if (gaim_conversation_get_type(conv) != GAIM_CONV_CHAT) + continue; + + if (gaim_conversation_get_ops(conv) != + gaim_get_gtk_conversation_ops()) + continue; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(conv)); + parent = gtk_widget_get_parent(gtkconv->send); + + gtkconv->send = + gaim_gtk_change_text(_("Send"), + gtkconv->send, GAIM_STOCK_SEND, type); + gtkconv->u.chat->invite = + gaim_gtk_change_text(_("Invite"), + gtkconv->u.chat->invite, + GAIM_STOCK_INVITE, type); + + gtk_box_pack_end(GTK_BOX(parent), gtkconv->send, FALSE, FALSE, + type); + gtk_box_pack_end(GTK_BOX(parent), gtkconv->u.chat->invite, + FALSE, FALSE, 0); + + g_signal_connect(G_OBJECT(gtkconv->send), "clicked", + G_CALLBACK(send_cb), conv); + g_signal_connect(G_OBJECT(gtkconv->u.chat->invite), "clicked", + G_CALLBACK(invite_cb), conv); + + gtk_button_set_relief(GTK_BUTTON(gtkconv->send), + GTK_RELIEF_NONE); + gtk_button_set_relief(GTK_BUTTON(gtkconv->u.chat->invite), + GTK_RELIEF_NONE); + + gaim_gtkconv_update_buttons_by_protocol(conv); + } + } +} + +void +gaim_gtkconv_update_im_button_style() +{ + GList *l; + struct gaim_conversation *conv; + struct gaim_gtk_conversation *gtkconv; + + for (l = gaim_get_ims(); l != NULL; l = l->next) { + conv = (struct gaim_conversation *)l->data; + gtkconv = GAIM_GTK_CONVERSATION(conv); + + setup_im_buttons(conv, gtk_widget_get_parent(gtkconv->send)); + } +} + +void +gaim_gtkconv_update_buttons_by_protocol(struct gaim_conversation *conv) +{ + struct gaim_window *win; + struct gaim_gtk_window *gtkwin = NULL; + struct gaim_gtk_conversation *gtkconv; + struct gaim_connection *gc; + + if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) + return; + + gc = gaim_conversation_get_gc(conv); + win = gaim_conversation_get_window(conv); + gtkconv = GAIM_GTK_CONVERSATION(conv); + + if (win != NULL) + gtkwin = GAIM_GTK_WINDOW(win); + + if (gc == NULL) { + gtk_widget_set_sensitive(gtkconv->send, FALSE); + + if (gaim_window_get_active_conversation(win) == conv) { + gtk_widget_set_sensitive(gtkwin->menu.insert_link, FALSE); + } + } + + if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { + if (gc == NULL) { + gtk_widget_set_sensitive(gtkconv->info, FALSE); + gtk_widget_set_sensitive(gtkconv->u.im->warn, FALSE); + gtk_widget_set_sensitive(gtkconv->u.im->block, FALSE); + gtk_widget_set_sensitive(gtkconv->u.im->add, FALSE); + + if (win != NULL && + gaim_window_get_active_conversation(win) == conv) { + + gtk_widget_set_sensitive(gtkwin->menu.insert_image, FALSE); + } + + return; + } + + gtk_widget_set_sensitive(gtkconv->info, + (gc->prpl->get_info != NULL)); + + gtk_widget_set_sensitive(gtkconv->toolbar.image, + (gc->prpl->options & OPT_PROTO_IM_IMAGE)); + + if (win != NULL && gaim_window_get_active_conversation(win) == conv) { + gtk_widget_set_sensitive(gtkwin->menu.insert_image, + (gc->prpl->options & OPT_PROTO_IM_IMAGE)); + } + + gtk_widget_set_sensitive(gtkconv->u.im->warn, + (gc->prpl->warn != NULL)); + + gtk_widget_set_sensitive(gtkconv->u.im->block, + (gc->prpl->add_permit != NULL)); + + update_convo_add_button(conv); + } + else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { + if (gc == NULL) { + gtk_widget_set_sensitive(gtkconv->u.chat->whisper, FALSE); + gtk_widget_set_sensitive(gtkconv->u.chat->invite, FALSE); + + return; + } + + gtk_widget_set_sensitive(gtkconv->send, (gc->prpl->chat_send != NULL)); + + gtk_widget_set_sensitive(gtkconv->toolbar.image, FALSE); + /* gtk_widget_set_sensitive(gtkwin->menu.insert_image, FALSE); */ + + gtk_widget_set_sensitive(gtkconv->u.chat->whisper, + (gc->prpl->chat_whisper != NULL)); + + gtk_widget_set_sensitive(gtkconv->u.chat->invite, + (gc->prpl->chat_invite != NULL)); + } +} + +struct gaim_window * +gaim_gtkwin_get_at_xy(int x, int y) +{ + struct gaim_window *win = NULL; + struct gaim_gtk_window *gtkwin; + GdkWindow *gdkwin; + GList *l; + + gdkwin = gdk_window_at_pointer(&x, &y); + + if (gdkwin) + gdkwin = gdk_window_get_toplevel(gdkwin); + + for (l = gaim_get_windows(); l != NULL; l = l->next) { + win = (struct gaim_window *)l->data; + + if (gaim_window_get_ops(win) != gaim_get_gtk_window_ops()) + continue; + + gtkwin = GAIM_GTK_WINDOW(win); + + if (gdkwin == gtkwin->window->window) + return win; + } + + return NULL; +} + +int +gaim_gtkconv_get_tab_at_xy(struct gaim_window *win, int x, int y) +{ + struct gaim_gtk_window *gtkwin; + GList *l; + gint nb_x, nb_y, x_rel, y_rel; + GtkNotebook *notebook; + GtkWidget *tab; + gint i, page_num = 0; + gboolean first_visible = TRUE; + + if (gaim_window_get_ops(win) != gaim_get_gtk_window_ops()) + return -1; + + gtkwin = GAIM_GTK_WINDOW(win); + notebook = GTK_NOTEBOOK(gtkwin->notebook); + + gdk_window_get_origin(gtkwin->notebook->window, &nb_x, &nb_y); + x_rel = x - nb_x; + y_rel = y - nb_y; + + for (l = gaim_window_get_conversations(win), i = 0; + l != NULL; + l = l->next, i++) { + + struct gaim_conversation *conv = l->data; + tab = GAIM_GTK_CONVERSATION(conv)->tab_label; + + if (!GTK_WIDGET_MAPPED(tab)) + continue; + + if (first_visible) { + first_visible = FALSE; + + if (x_rel < tab->allocation.x) x_rel = tab->allocation.x; + if (y_rel < tab->allocation.y) y_rel = tab->allocation.y; + } + + if (gtk_notebook_get_tab_pos(notebook) == GTK_POS_TOP || + gtk_notebook_get_tab_pos(notebook) == GTK_POS_BOTTOM) { + + if (tab->allocation.x <= x_rel) { + if (tab->allocation.x + tab->allocation.width <= x_rel) + page_num = i + 1; + else + page_num = i; + } + else + break; + } + else { + if (tab->allocation.y <= y_rel) { + if (tab->allocation.y + tab->allocation.height <= y_rel) + page_num = i + 1; + else + page_num = i; + } + else + break; + } + } + + if (i == gaim_window_get_conversation_count(win) + 1) + return -1; + + return page_num; +} + +int +gaim_gtkconv_get_dest_tab_at_xy(struct gaim_window *win, int x, int y) +{ + struct gaim_gtk_window *gtkwin; + GList *l; + gint nb_x, nb_y, x_rel, y_rel; + GtkNotebook *notebook; + GtkWidget *tab; + gint i, page_num = 0; + + if (gaim_window_get_ops(win) != gaim_get_gtk_window_ops()) + return -1; + + gtkwin = GAIM_GTK_WINDOW(win); + notebook = GTK_NOTEBOOK(gtkwin->notebook); + + gdk_window_get_origin(gtkwin->notebook->window, &nb_x, &nb_y); + x_rel = x - nb_x; + y_rel = y - nb_y; + + for (l = gaim_window_get_conversations(win), i = 0; + l != NULL; + l = l->next, i++) { + + struct gaim_conversation *conv = l->data; + tab = GAIM_GTK_CONVERSATION(conv)->tab_label; + + if (!GTK_WIDGET_MAPPED(tab)) + continue; + + if (gtk_notebook_get_tab_pos(notebook) == GTK_POS_TOP || + gtk_notebook_get_tab_pos(notebook) == GTK_POS_BOTTOM) { + + if (tab->allocation.x <= x_rel) { + if (tab->allocation.x + (tab->allocation.width / 2) <= x_rel) + page_num = i + 1; + else + page_num = i; + } + else + break; + } + else { + if (tab->allocation.y <= y_rel) { + if (tab->allocation.y + (tab->allocation.height / 2) <= y_rel) + page_num = i + 1; + else + page_num = i; + } + else + break; + } + } + + if (i == gaim_window_get_conversation_count(win) + 1) + return -1; + + return page_num; +} diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/gtkconv.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gtkconv.h Mon Jan 20 09:10:23 2003 +0000 @@ -0,0 +1,313 @@ +/** + * @file gtkconv.h GTK+ Conversation API + * + * gaim + * + * Copyright (C) 2002-2003, Christian Hammond + * + * 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 _GAIM_GTK_CONVERSATION_H_ +#define _GAIM_GTK_CONVERSATION_H_ + +/************************************************************************** + * @name Structures + **************************************************************************/ + +struct gaim_gtk_window; +struct gaim_gtk_conversation; +struct gaim_gtk_im_pane; +struct gaim_gtk_chat_pane; + +/** + * A GTK+ representation of a graphical window containing one or more + * conversations. + */ +struct gaim_gtk_window +{ + GtkWidget *window; /**< The window. */ + GtkWidget *notebook; /**< The notebook of conversations. */ + + struct + { + GtkWidget *menubar; + + GtkWidget *view_history; + GtkWidget *insert_link; + GtkWidget *insert_image; + GtkWidget *logging; + GtkWidget *sounds; + GtkWidget *send_as; + + } menu; + + /* Tab dragging stuff. */ + gboolean in_drag; + gboolean in_predrag; + + gint drag_min_x, drag_max_x, drag_min_y, drag_max_y; + + gint drag_motion_signal; + gint drag_leave_signal; +}; + +/** + * GTK+ Instant Message panes. + */ +struct gaim_gtk_im_pane +{ + GtkWidget *warn; + GtkWidget *block; + GtkWidget *add; + GtkWidget *sep1; + GtkWidget *sep2; + GtkWidget *check; + GtkWidget *progress; + + gboolean a_virgin; + + /* Buddy icon stuff */ + GtkWidget *icon; + GdkPixbufAnimation *anim; + GdkPixbufAnimationIter *iter; + guint32 icon_timer; + GtkWidget *save_icon; +}; + +/** + * GTK+ Chat panes. + */ +struct gaim_gtk_chat_pane +{ + GtkWidget *count; + GtkWidget *list; + GtkWidget *whisper; + GtkWidget *invite; + GtkWidget *topic_text; +}; + +/** + * A GTK+ conversation pane. + */ +struct gaim_gtk_conversation +{ + gboolean make_sound; + gboolean has_font; + gboolean has_fg; + gboolean has_bg; + char fontface[128]; + GdkColor fg_color; + GdkColor bg_color; + + GtkTooltips *tooltips; + + GtkWidget *tab_cont; + GtkWidget *tabby; + + GtkWidget *imhtml; + GtkTextBuffer *entry_buffer; + GtkWidget *entry; + + GtkWidget *send; + GtkWidget *info; + GtkWidget *close; + GtkWidget *tab_label; + GtkSizeGroup *sg; + + GtkWidget *bbox; + GtkWidget *sw; + + struct + { + GtkWidget *toolbar; + + GtkWidget *bold; + GtkWidget *italic; + GtkWidget *underline; + + GtkWidget *normal_size; + + GtkWidget *fgcolor; + GtkWidget *bgcolor; + + GtkWidget *image; + GtkWidget *link; + GtkWidget *smiley; + GtkWidget *log; + + } toolbar; + + struct + { + GtkWidget *fg_color; + GtkWidget *bg_color; + GtkWidget *font; + GtkWidget *smiley; + GtkWidget *link; + GtkWidget *log; + + } dialogs; + + union + { + struct gaim_gtk_im_pane *im; + struct gaim_gtk_chat_pane *chat; + + } u; +}; + +#define GAIM_GTK_WINDOW(win) \ + ((struct gaim_gtk_window *)(win)->ui_data) + +#define GAIM_GTK_CONVERSATION(conv) \ + ((struct gaim_gtk_conversation *)(conv)->ui_data) + + +/************************************************************************** + * @name GTK+ Conversation API + **************************************************************************/ +/** + * Returns the UI operations structure for GTK windows. + * + * @return The GTK window operations structure. + */ +struct gaim_window_ops *gaim_get_gtk_window_ops(void); + +/** + * Returns the UI operations structure for GTK conversations. + * + * @return The GTK conversation operations structure. + */ +struct gaim_conversation_ops *gaim_get_gtk_conversation_ops(void); + +/** + * Sets a lock on the update state. + * + * @param lock The lock state. + */ +void gaim_gtk_set_state_lock(gboolean lock); + +/** + * Returns the lock state. + * + * @return The lock state. + */ +gboolean gaim_gtk_is_state_locked(void); + +/** + * Toggles the display of smileys. + */ +void gaim_gtkconv_toggle_smileys(void); + +/** + * Toggles the display of timestamps. + */ +void gaim_gtkconv_toggle_timestamps(void); + +/** + * Toggles spell checking. + */ +void gaim_gtkconv_toggle_spellchk(void); + +/** + * Updates the buddy icon on a conversation. + * + * @param conv The conversation. + */ +void gaim_gtkconv_update_buddy_icon(struct gaim_conversation *conv); + +/** + * Hides buddy icons on all conversations. + */ +void gaim_gtkconv_hide_buddy_icons(void); + +/** + * Enables or disables animation on all conversations, based off + * preferences. + */ +void gaim_gtkconv_set_anim(void); + +/** + * Updates the font buttons on all conversations to reflect any changed + * preferences. + */ +void gaim_gtkconv_update_font_buttons(void); + +/** + * Updates the tab positions on all conversation windows to reflect any + * changed preferences. + */ +void gaim_gtkconv_update_tabs(void); + +/** + * Updates the button style on chat windows to reflect any + * changed preferences. + */ +void gaim_gtkconv_update_chat_button_style(); + +/** + * Updates the button style on IM windows to reflect any + * changed preferences. + */ +void gaim_gtkconv_update_im_button_style(); + +/** + * Updates conversation buttons by protocol. + * + * @param conv The conversation. + */ +void gaim_gtkconv_update_buttons_by_protocol(struct gaim_conversation *conv); + +/** + * Returns the window at the specified X, Y location. + * + * If the window is not a GTK+ window, @c NULL is returned. + * + * @param x The X coordinate. + * @param y The Y coordinate. + * + * @return The GTK+ window at the location, if it exists, or @c NULL otherwise. + */ +struct gaim_window *gaim_gtkwin_get_at_xy(int x, int y); + +/** + * Returns the index of the tab at the specified X, Y location in a notebook. + * + * @param win The GTK+ window containing the notebook. + * @param x The X coordinate. + * @param y The Y coordinate. + * + * @return The index of the tab at the location. + */ +int gaim_gtkconv_get_tab_at_xy(struct gaim_window *win, int x, int y); + +/** + * Returns the index of the destination tab at the + * specified X, Y location in a notebook. + * + * This is used for drag-and-drop functions when the tab at the index + * is a destination tab. + * + * @param win The GTK+ window containing the notebook. + * @param x The X coordinate. + * @param y The Y coordinate. + * + * @return The index of the tab at the location. + */ +int gaim_gtkconv_get_dest_tab_at_xy(struct gaim_window *win, int x, int y); + +#endif /* _GAIM_GTK_CONVERSATION_H_ */ diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/gtkutils.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gtkutils.c Mon Jan 20 09:10:23 2003 +0000 @@ -0,0 +1,392 @@ +/* + * gaim + * + * Copyright (C) 2002-2003, Christian Hammond + * + * 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 + * + */ +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#ifndef _WIN32 +#include +#include +#include +#include +#else +#ifdef small +#undef small +#endif +#endif /*_WIN32*/ +#include +#include +#include +#include +#include +#include +#include +#ifdef USE_GTKSPELL +#include +#endif +#include "gtkimhtml.h" +#include +#include "prpl.h" +#include "ui.h" + + +void +gaim_setup_imhtml(GtkWidget *imhtml) +{ + 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(G_OBJECT(imhtml), "url_clicked", + G_CALLBACK(open_url), NULL); + + smiley_themeize(imhtml); +} + +void +toggle_sensitive(GtkWidget *widget, GtkWidget *to_toggle) +{ + gboolean sensitivity = GTK_WIDGET_IS_SENSITIVE(to_toggle); + + gtk_widget_set_sensitive(to_toggle, !sensitivity); +} + +static void +gaim_gtk_remove_tags(struct gaim_gtk_conversation *gtkconv, const char *tag) +{ + GtkTextIter start, end, m_start, m_end; + + if (gtkconv == NULL || tag == NULL) + return; + + if (!gtk_text_buffer_get_selection_bounds(gtkconv->entry_buffer, + &start, &end)) + return; + + /* FIXMEif (strstr(tag, "entry); +} + +static gboolean +invert_tags(GtkTextBuffer *buffer, const char *s1, const char *s2, + gboolean really) +{ + GtkTextIter start1, start2, end1, end2; + char *b1, *b2; + + 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); + + 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; +} + +void +gaim_gtk_advance_past(struct gaim_gtk_conversation *gtkconv, + const char *pre, const char *post) +{ + GtkTextIter current_pos, start, end; + + if (invert_tags(gtkconv->entry_buffer, pre, post, TRUE)) + return; + + gtk_text_buffer_get_iter_at_mark(gtkconv->entry_buffer, ¤t_pos, + gtk_text_buffer_get_insert(gtkconv->entry_buffer)); + + if (gtk_text_iter_forward_search(¤t_pos, post, 0, + &start, &end, NULL)) + gtk_text_buffer_place_cursor(gtkconv->entry_buffer, &end); + else + gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, post, -1); + + gtk_widget_grab_focus(gtkconv->entry); +} + +void +gaim_gtk_set_font_face(struct gaim_gtk_conversation *gtkconv, + const char *font) +{ + char *pre_fontface; + + if (gtkconv == NULL || font == NULL) + return; + + strncpy(gtkconv->fontface, + (font && *font ? font : DEFAULT_FONT_FACE), + sizeof(gtkconv->fontface)); + + gtkconv->has_font = TRUE; + + pre_fontface = g_strconcat("fontface, "\">", NULL); + gaim_gtk_surround(gtkconv, pre_fontface, ""); + + gtk_widget_grab_focus(gtkconv->entry); + + g_free(pre_fontface); +} + +static int +des_save_icon(GtkObject *obj, GdkEvent *e, + struct gaim_gtk_conversation *gtkconv) +{ + gtk_widget_destroy(gtkconv->u.im->save_icon); + gtkconv->u.im->save_icon = NULL; + + return TRUE; +} + +static void +do_save_icon(GtkObject *obj, struct gaim_conversation *c) +{ + struct gaim_gtk_conversation *gtkconv; + FILE *file; + const char *f; + + gtkconv = GAIM_GTK_CONVERSATION(c); + + f = gtk_file_selection_get_filename( + GTK_FILE_SELECTION(gtkconv->u.im->save_icon)); + + if (file_is_dir(f, gtkconv->u.im->save_icon)) + return; + + if ((file = fopen(f, "w")) != NULL) { + int len; + void *data = get_icon_data(gaim_conversation_get_gc(c), + normalize(gaim_conversation_get_name(c)), + &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(gtkconv->u.im->save_icon); + gtkconv->u.im->save_icon = NULL; +} + +static void +cancel_save_icon(GtkObject *obj, struct gaim_gtk_conversation *gtkconv) +{ + gtk_widget_destroy(gtkconv->u.im->save_icon); + gtkconv->u.im->save_icon = NULL; +} + + +void +gaim_gtk_save_icon_dialog(GtkObject *obj, struct gaim_conversation *conv) +{ + struct gaim_gtk_conversation *gtkconv; + char buf[BUF_LEN]; + + if (conv == NULL || gaim_conversation_get_type(conv) != GAIM_CONV_IM) + return; + + if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) + return; + + gtkconv = GAIM_GTK_CONVERSATION(conv); + + if (gtkconv->u.im->save_icon != NULL) + { + gdk_window_raise(gtkconv->u.im->save_icon->window); + return; + } + + gtkconv->u.im->save_icon = gtk_file_selection_new(_("Gaim - Save Icon")); + + gtk_file_selection_hide_fileop_buttons( + GTK_FILE_SELECTION(gtkconv->u.im->save_icon)); + + g_snprintf(buf, BUF_LEN - 1, + "%s" G_DIR_SEPARATOR_S "%s.icon", + gaim_home_dir(), gaim_conversation_get_name(conv)); + + gtk_file_selection_set_filename( + GTK_FILE_SELECTION(gtkconv->u.im->save_icon), buf); + + g_signal_connect(GTK_OBJECT(gtkconv->u.im->save_icon), "delete_event", + G_CALLBACK(des_save_icon), gtkconv); + g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(gtkconv->u.im->save_icon)->ok_button), "clicked", + G_CALLBACK(do_save_icon), conv); + g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(gtkconv->u.im->save_icon)->cancel_button), "clicked", + G_CALLBACK(cancel_save_icon), gtkconv); + + gtk_widget_show(gtkconv->u.im->save_icon); +} + +int +gaim_gtk_get_dispstyle(GaimConversationType type) +{ + int dispstyle = 2; + + if (type == GAIM_CONV_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: dispstyle = 2; break; /* both/neither */ + } + } + else if (type == GAIM_CONV_IM) { + 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: dispstyle = 2; break; /* both/neither */ + } + } + + return dispstyle; +} + +GtkWidget * +gaim_gtk_change_text(const char *text, GtkWidget *button, + const char *stock, GaimConversationType type) +{ + int dispstyle = gaim_gtk_get_dispstyle(type); + + if (button != NULL) + gtk_widget_destroy(button); + + button = gaim_pixbuf_button_from_stock((dispstyle == 0 ? NULL : text), + (dispstyle == 1 ? NULL : stock), + GAIM_BUTTON_VERTICAL); + + gtk_widget_show(button); + + return button; +} + +void +gaim_gtk_toggle_sensitive(GtkWidget *widget, GtkWidget *to_toggle) +{ + gboolean sensitivity; + + if (to_toggle == NULL) + return; + + sensitivity = GTK_WIDGET_IS_SENSITIVE(to_toggle); + + gtk_widget_set_sensitive(to_toggle, !sensitivity); +} + diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/gtkutils.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gtkutils.h Mon Jan 20 09:10:23 2003 +0000 @@ -0,0 +1,111 @@ +/** + * @file gtkutils.h GTK+ utility functions + * + * gaim + * + * Copyright (C) 2002-2003, Christian Hammond + * + * 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 _GAIM_GTK_UTILS_H_ +#define _GAIM_GTK_UTILS_H_ + +#include "gaim.h" +#include "conversation.h" + +/** + * Sets up a gtkimhtml widget, loads it with smileys, and sets the + * default signal handlers. + * + * @param imhtml The gtkimhtml widget to setup. + */ +void gaim_setup_imhtml(GtkWidget *imhtml); + +/** + * Surrounds the selected text in a conversation with the specified + * pre and post strings. + * + * @param gtkconv The GTK+ conversation. + * @param pre The prefix string. + * @param post The postfix string. + */ +void gaim_gtk_surround(struct gaim_gtk_conversation *gtkconv, + const char *pre, const char *post); + +/** + * Advances the cursor past the position of the specified tags. + * + * @param gtkconv The GTK+ conversation. + * @param pre The prefix string. + * @param post The postfix string. + */ +void gaim_gtk_advance_past(struct gaim_gtk_conversation *gtkconv, + const char *pre, const char *post); + +/** + * Surrounds the selected text with the specified font. + * + * @param conv The conversation. + * @param font The new font. + */ +void gaim_gtk_set_font_face(struct gaim_gtk_conversation *gtkconv, + const char *font); + +/** + * Displays a dialog for saving the buddy icon in a conversation. + * + * @param obj @c NULL + * @param conv The conversation. + */ +void gaim_gtk_save_icon_dialog(GtkObject *obj, struct gaim_conversation *conv); + +/** + * Returns the display style for buttons for the specified conversation + * type. + * + * @param type The conversation type. + * + * @return The display style. + */ +int gaim_gtk_get_dispstyle(GaimConversationType type); + +/** + * Changes a button to be either text or image, depending on + * preferences. + * + * This function destroys the old button pointed to by @a button and + * returns the new replacement button. + * + * @param text The text for the button. + * @param button The button widget. + * @param stock The stock image. + * @param type The conversation type the button belongs to. + * + * @return The new button widget to replace the old one. + */ +GtkWidget *gaim_gtk_change_text(const char *text, GtkWidget *button, + const char *stock, GaimConversationType type); + +/** + * Toggles the sensitivity of a widget. + * + * @param widget @c NULL. Used for signal handlers. + * @param to_toggle The widget to toggle. + */ +void gaim_gtk_toggle_sensitive(GtkWidget *widget, GtkWidget *to_toggle); + +#endif /* _GAIM_GTK_UTILS_H_ */ diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/html.c --- a/src/html.c Mon Jan 20 07:00:10 2003 +0000 +++ b/src/html.c Mon Jan 20 09:10:23 2003 +0000 @@ -44,7 +44,7 @@ #include "win32dep.h" #endif -gchar *strip_html(gchar *text) +gchar *strip_html(const gchar *text) { int i, j, k; int visible = 1; diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/log.c --- a/src/log.c Mon Jan 20 07:00:10 2003 +0000 +++ b/src/log.c Mon Jan 20 09:10:23 2003 +0000 @@ -15,7 +15,9 @@ #include "core.h" #include "multi.h" #include "prpl.h" +#include #include +#include #ifdef _WIN32 #include "win32dep.h" @@ -23,14 +25,14 @@ void rm_log(struct log_conversation *a) { - struct conversation *cnv = find_conversation(a->name); + struct gaim_conversation *cnv = gaim_find_conversation(a->name); log_conversations = g_list_remove(log_conversations, a); save_prefs(); if (cnv && !(im_options & OPT_IM_ONE_WINDOW)) - set_convo_title(cnv); + gaim_conversation_autoset_title(cnv); } struct log_conversation *find_log_info(const char *name) @@ -56,70 +58,61 @@ void update_log_convs() { - GSList *C = connections; - struct gaim_connection *g; - GSList *bcs; - GList *cnv = conversations; - struct conversation *c; + GList *cnv; + struct gaim_conversation *c; + struct gaim_gtk_conversation *gtkconv; + + for (cnv = gaim_get_conversations(); cnv != NULL; cnv = cnv->next) { + + c = (struct gaim_conversation *)cnv->data; - while (cnv) { - c = (struct conversation *)cnv->data; - if (c->log_button) { - if (c->is_chat) - gtk_widget_set_sensitive(GTK_WIDGET(c->log_button), + if (gaim_conversation_get_ops(c) != gaim_get_gtk_conversation_ops()) + continue; + + gtkconv = GAIM_GTK_CONVERSATION(c); + + if (gtkconv->toolbar.log) { + if (gaim_conversation_get_type(c) == GAIM_CONV_CHAT) + gtk_widget_set_sensitive(GTK_WIDGET(gtkconv->toolbar.log), ((logging_options & OPT_LOG_CHATS)) ? FALSE : TRUE); else - gtk_widget_set_sensitive(GTK_WIDGET(c->log_button), + gtk_widget_set_sensitive(GTK_WIDGET(gtkconv->toolbar.log), ((logging_options & OPT_LOG_CONVOS)) ? FALSE : TRUE); } - - cnv = cnv->next; - } - - while (C) { - g = (struct gaim_connection *)C->data; - bcs = g->buddy_chats; - while (bcs) { - c = (struct conversation *)bcs->data; - if (c->log_button) { - if (c->is_chat) - gtk_widget_set_sensitive(GTK_WIDGET(c->log_button), - ((logging_options & OPT_LOG_CHATS)) ? FALSE : - TRUE); - else - gtk_widget_set_sensitive(GTK_WIDGET(c->log_button), - ((logging_options & OPT_LOG_CONVOS)) ? FALSE : - TRUE); - } - - bcs = bcs->next; - } - C = C->next; } } static void do_save_convo(GtkObject *obj, GtkWidget *wid) { - struct conversation *c = gtk_object_get_user_data(obj); + struct gaim_conversation *c = gtk_object_get_user_data(obj); const char *filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(wid)); FILE *f; + if (file_is_dir(filename, wid)) return; - if (!((!c->is_chat && g_list_find(conversations, c)) || - (c->is_chat && g_slist_find(connections, c->gc) && g_slist_find(c->gc->buddy_chats, c)))) + + if (!((gaim_conversation_get_type(c) != GAIM_CONV_CHAT && + g_list_find(gaim_get_ims(), c)) || + (gaim_conversation_get_type(c) == GAIM_CONV_CHAT && + g_list_find(gaim_get_chats(), c)))) filename = NULL; + gtk_widget_destroy(wid); + if (!filename) return; + f = fopen(filename, "w+"); + if (!f) return; + fprintf(f, "%s", c->history->str); fclose(f); } -void save_convo(GtkWidget *save, struct conversation *c) +void save_convo(GtkWidget *save, struct gaim_conversation *c) { char buf[BUF_LONG]; GtkWidget *window = gtk_file_selection_new(_("Gaim - Save Conversation")); @@ -133,46 +126,6 @@ gtk_widget_show(window); } -char *html_logize(char *p) -{ - char *temp_p = p; - char *buffer_p; - char *buffer_start; - int num_cr = 0; - int char_len = 0; - - while (*temp_p != '\0') { - char_len++; - if ((*temp_p == '\n') || ((*temp_p == '<') && (*(temp_p + 1) == '!'))) - num_cr++; - ++temp_p; - } - - temp_p = p; - buffer_p = g_malloc(char_len + (4 * num_cr) + 1); - buffer_start = buffer_p; - - while (*temp_p != '\0') { - if (*temp_p == '\n') { - *buffer_p++ = '<'; - *buffer_p++ = 'B'; - *buffer_p++ = 'R'; - *buffer_p++ = '>'; - *buffer_p++ = '\n'; - } else if ((*temp_p == '<') && (*(temp_p + 1) == '!')) { - *buffer_p++ = '&'; - *buffer_p++ = 'l'; - *buffer_p++ = 't'; - *buffer_p++ = ';'; - } else - *buffer_p++ = *temp_p; - ++temp_p; - } - *buffer_p = '\0'; - - return buffer_start; -} - static FILE *open_gaim_log_file(const char *name, int *flag) { char *buf; @@ -463,3 +416,46 @@ fclose(fd); } + +char *html_logize(const char *p) +{ + const char *temp_p; + char *buffer_p; + char *buffer_start; + int num_cr = 0; + int char_len = 0; + + for (temp_p = p; *temp_p != '\0'; temp_p++) { + char_len++; + + if ((*temp_p == '\n') || ((*temp_p == '<') && (*(temp_p + 1) == '!'))) + num_cr++; + } + + buffer_p = g_malloc(char_len + (4 * num_cr) + 1); + + for (temp_p = p, buffer_start = buffer_p; + *temp_p != '\0'; + temp_p++) { + + if (*temp_p == '\n') { + *buffer_p++ = '<'; + *buffer_p++ = 'B'; + *buffer_p++ = 'R'; + *buffer_p++ = '>'; + *buffer_p++ = '\n'; + + } else if ((*temp_p == '<') && (*(temp_p + 1) == '!')) { + *buffer_p++ = '&'; + *buffer_p++ = 'l'; + *buffer_p++ = 't'; + *buffer_p++ = ';'; + + } else + *buffer_p++ = *temp_p; + } + + *buffer_p = '\0'; + + return buffer_start; +} diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/multi.c --- a/src/multi.c Mon Jan 20 07:00:10 2003 +0000 +++ b/src/multi.c Mon Jan 20 09:10:23 2003 +0000 @@ -25,6 +25,7 @@ #include "prpl.h" #include "multi.h" #include "gaim.h" +#include "conversation.h" #include "pixmaps/cancel.xpm" #include "pixmaps/ok.xpm" @@ -1332,9 +1333,11 @@ void account_online(struct gaim_connection *gc) { struct signon_meter *meter = find_signon_meter(gc); + GList *wins; GtkTreeIter iter; GSList *grps, *buds; GList *add_buds=NULL; + GList *l; /* Set the time the account came online */ time(&gc->login_time); @@ -1355,7 +1358,17 @@ update_privacy_connections(); do_away_menu(); do_proto_menu(); - redo_convo_menus(); + + /* + * XXX This is a hack! Remove this and replace it with a better event + * notification system. + */ + for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) { + struct gaim_window *win = (struct gaim_window *)wins->data; + gaim_conversation_update(gaim_window_get_conversation_at(win, 0), + GAIM_CONV_ACCOUNT_ONLINE); + } + redo_buddy_list(); gaim_setup(gc); @@ -1409,19 +1422,29 @@ -1); } - return; + /* Update the conversation windows that use this account. */ + for (l = gaim_get_conversations(); l != NULL; l = l->next) { + struct gaim_conversation *conv = (struct gaim_conversation *)l->data; + + if (gaim_conversation_get_user(conv) == gc->user) { + gaim_conversation_update(conv, GAIM_CONV_UPDATE_USER); + } + } } void account_offline(struct gaim_connection *gc) { struct signon_meter *meter = find_signon_meter(gc); GtkTreeIter iter; + GList *l; if (meter) { kill_meter(meter); meters = g_slist_remove(meters, meter); g_free(meter); } + debug_printf("Disconnecting. user = %p, gc = %p (%p)\n", + gc->user, gc->user->gc, gc); gc->user->gc = NULL; /* wasn't that awkward? */ if (!acctedit) return; @@ -1429,6 +1452,15 @@ if (get_iter_from_data(GTK_TREE_VIEW(treeview), gc->user, &iter)) { gtk_list_store_set(model, &iter, COLUMN_ONLINE, FALSE, -1); } + + /* Update the conversation windows that use this account. */ + for (l = gaim_get_conversations(); l != NULL; l = l->next) { + struct gaim_conversation *conv = (struct gaim_conversation *)l->data; + + if (gaim_conversation_get_user(conv) == gc->user) { + gaim_conversation_update(conv, GAIM_CONV_UPDATE_USER); + } + } } void auto_login() @@ -1671,9 +1703,13 @@ void signoff(struct gaim_connection *gc) { + GList *wins; + /* UI stuff */ + /* CONV XXX convo_menu_remove(gc); remove_icon_data(gc); + */ /* core stuff */ /* remove this here so plugins get a sensible count of connections */ @@ -1695,7 +1731,17 @@ redo_buddy_list(); do_away_menu(); do_proto_menu(); - redo_convo_menus(); + + /* + * XXX This is a hack! Remove this and replace it with a better event + * notification system. + */ + for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) { + struct gaim_window *win = (struct gaim_window *)wins->data; + gaim_conversation_update(gaim_window_get_conversation_at(win, 0), + GAIM_CONV_ACCOUNT_OFFLINE); + } + update_privacy_connections(); /* in, out, shake it all about */ diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/perl.c --- a/src/perl.c Mon Jan 20 07:00:10 2003 +0000 +++ b/src/perl.c Mon Jan 20 09:10:23 2003 +0000 @@ -762,7 +762,7 @@ XS (XS_GAIM_write_to_conv) { char *nick, *who, *what; - struct conversation *c; + struct gaim_conversation *c; int junk; int send, wflags; dXSARGS; @@ -782,11 +782,12 @@ default: wflags=WFLAG_RECV; } - c = find_conversation(nick); + c = gaim_find_conversation(nick); + if (!c) - c = new_conversation(nick); + c = gaim_conversation_new(GAIM_CONV_IM, nick); - write_to_conv(c, what, wflags, who, time(NULL), -1); + gaim_conversation_write(c, who, what, -1, wflags, time(NULL)); XSRETURN(0); } @@ -817,7 +818,7 @@ struct gaim_connection *gc; char *nick, *what; int isauto; - struct conversation *c; + struct gaim_conversation *c; unsigned int junk; dXSARGS; items = 0; @@ -830,12 +831,14 @@ XSRETURN(0); return; } - c = find_conversation(nick); + c = gaim_find_conversation(nick); if (!c) - c = new_conversation(nick); - set_convo_gc(c, gc); - write_to_conv(c, what, WFLAG_SEND | (isauto ? WFLAG_AUTO : 0), NULL, time(NULL), -1); - serv_send_im(c->gc, nick, what, -1, isauto ? IM_FLAG_AWAY : 0); + c = gaim_conversation_new(GAIM_CONV_IM, nick); + gaim_conversation_set_user(c, gc->user); + gaim_conversation_write(c, NULL, what, -1, + (WFLAG_SEND | (isauto ? WFLAG_AUTO : 0)), + time(NULL)); + serv_send_im(gc, nick, what, -1, isauto ? IM_FLAG_AWAY : 0); XSRETURN(0); } @@ -846,7 +849,7 @@ struct gaim_connection *gc; int id; char *what; - struct conversation *b = NULL; + struct gaim_conversation *b = NULL; GSList *bcs; unsigned int junk; dXSARGS; @@ -862,8 +865,9 @@ } bcs = gc->buddy_chats; while (bcs) { - b = (struct conversation *)bcs->data; - if (b->id == id) + b = (struct gaim_conversation *)bcs->data; + + if (gaim_chat_get_id(gaim_conversation_get_chat_data(b)) == id) break; bcs = bcs->next; b = NULL; diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/prefs.c --- a/src/prefs.c Mon Jan 20 07:00:10 2003 +0000 +++ b/src/prefs.c Mon Jan 20 09:10:23 2003 +0000 @@ -434,8 +434,10 @@ if (!(font_options & OPT_FONT_FACE)) gtk_widget_set_sensitive(GTK_WIDGET(select), FALSE); - g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(toggle_sensitive), select); - g_signal_connect(GTK_OBJECT(select), "clicked", G_CALLBACK(show_font_dialog), NULL); + g_signal_connect(GTK_OBJECT(button), "clicked", + G_CALLBACK(gaim_gtk_toggle_sensitive), select); + g_signal_connect(GTK_OBJECT(select), "clicked", + G_CALLBACK(show_font_dialog), NULL); gtk_box_pack_start(GTK_BOX(hbox), select, FALSE, FALSE, 0); hbox = gtk_hbox_new(FALSE, 5); @@ -445,7 +447,8 @@ select = gaim_labeled_spin_button(hbox, NULL, &fontsize, 1, 7, NULL); if (!(font_options & OPT_FONT_SIZE)) gtk_widget_set_sensitive(GTK_WIDGET(select), FALSE); - g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(toggle_sensitive), select); + g_signal_connect(GTK_OBJECT(button), "clicked", + G_CALLBACK(gaim_gtk_toggle_sensitive), select); vbox = make_frame(ret, _("Color")); hbox = gtk_hbox_new(FALSE, 5); @@ -463,7 +466,8 @@ if (!(font_options & OPT_FONT_FGCOL)) gtk_widget_set_sensitive(GTK_WIDGET(select), FALSE); - g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(toggle_sensitive), select); + g_signal_connect(GTK_OBJECT(button), "clicked", + G_CALLBACK(gaim_gtk_toggle_sensitive), select); g_signal_connect(GTK_OBJECT(select), "clicked", G_CALLBACK(show_fgcolor_dialog), NULL); hbox = gtk_hbox_new(FALSE, 5); gtk_container_add(GTK_CONTAINER(vbox), hbox); @@ -479,7 +483,8 @@ if (!(font_options & OPT_FONT_BGCOL)) gtk_widget_set_sensitive(GTK_WIDGET(select), FALSE); g_signal_connect(GTK_OBJECT(select), "clicked", G_CALLBACK(show_bgcolor_dialog), NULL); - g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(toggle_sensitive), select); + g_signal_connect(GTK_OBJECT(button), "clicked", + G_CALLBACK(gaim_gtk_toggle_sensitive), select); gtk_widget_show_all(ret); return ret; @@ -987,7 +992,8 @@ select = gaim_labeled_spin_button(vbox, _("_Minutes before setting away:"), &auto_away, 1, 24 * 60, sg); if (!(away_options & OPT_AWAY_AUTO)) gtk_widget_set_sensitive(GTK_WIDGET(select), FALSE); - g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(toggle_sensitive), select); + g_signal_connect(GTK_OBJECT(button), "clicked", + G_CALLBACK(gaim_gtk_toggle_sensitive), select); label = gtk_label_new_with_mnemonic(_("Away m_essage:")); gtk_size_group_add_widget(sg, label); @@ -999,7 +1005,8 @@ gtk_label_set_mnemonic_widget(GTK_LABEL(label), prefs_away_menu); if (!(away_options & OPT_AWAY_AUTO)) gtk_widget_set_sensitive(GTK_WIDGET(prefs_away_menu), FALSE); - g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(toggle_sensitive), prefs_away_menu); + g_signal_connect(GTK_OBJECT(button), "clicked", + G_CALLBACK(gaim_gtk_toggle_sensitive), prefs_away_menu); default_away_menu_init(prefs_away_menu); gtk_widget_show(prefs_away_menu); gtk_box_pack_start(GTK_BOX(hbox), prefs_away_menu, FALSE, FALSE, 0); @@ -1860,7 +1867,7 @@ else if(option == OPT_MISC_USE_SERVER_ALIAS) { redo_buddy_list(); build_edit_tree(); - set_convo_titles(); + gaim_conversation_foreach(gaim_conversation_autoset_title); } } @@ -1904,39 +1911,42 @@ convo_options ^= option; if (option == OPT_CONVO_SHOW_SMILEY) - toggle_smileys(); + gaim_gtkconv_toggle_smileys(); if (option == OPT_CONVO_SHOW_TIME) - toggle_timestamps(); + gaim_gtkconv_toggle_timestamps(); if (option == OPT_CONVO_CHECK_SPELLING) - toggle_spellchk(); + gaim_gtkconv_toggle_spellchk(); } static void set_im_option(GtkWidget *w, int option) { im_options ^= option; +#if 0 if (option == OPT_IM_ONE_WINDOW) im_tabize(); +#endif if (option == OPT_IM_HIDE_ICONS) - set_hide_icons(); + gaim_gtkconv_hide_buddy_icons(); - if (option == OPT_IM_ALIAS_TAB) { - set_convo_titles(); - } + if (option == OPT_IM_ALIAS_TAB) + gaim_conversation_foreach(gaim_conversation_autoset_title); if (option == OPT_IM_NO_ANIMATION) - set_anim(); + gaim_gtkconv_set_anim(); } static void set_chat_option(GtkWidget *w, int option) { chat_options ^= option; +#if 0 if (option == OPT_CHAT_ONE_WINDOW) chat_tabize(); +#endif } void set_sound_option(GtkWidget *w, int option) @@ -1948,7 +1958,7 @@ { font_options ^= option; - update_font_buttons(); + gaim_gtkconv_update_font_buttons(); } static void set_away_option(GtkWidget *w, int option) @@ -2178,14 +2188,16 @@ gtk_widget_set_sensitive(sndcmd, FALSE); } else if (option == (int*)&im_options) { if (clear == (OPT_IM_SIDE_TAB | OPT_IM_BR_TAB)) - update_im_tabs(); + gaim_gtkconv_update_tabs(); + /* CONV XXX update_im_tabs(); */ else if (clear == (OPT_IM_BUTTON_TEXT | OPT_IM_BUTTON_XPM)) - update_im_button_pix(); + gaim_gtkconv_update_im_button_style(); } else if (option == (int*)&chat_options) { if (clear == (OPT_CHAT_SIDE_TAB | OPT_CHAT_BR_TAB)) - update_chat_tabs(); + gaim_gtkconv_update_tabs(); + /* CONV XXX update_chat_tabs(); */ else if (clear == (OPT_CHAT_BUTTON_TEXT | OPT_CHAT_BUTTON_XPM)) - update_chat_button_pix(); + gaim_gtkconv_update_chat_button_style(); } else if (option == (int*)&blist_options) { set_blist_tab(); } diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/protocols/irc/irc.c --- a/src/protocols/irc/irc.c Mon Jan 20 07:00:10 2003 +0000 +++ b/src/protocols/irc/irc.c Mon Jan 20 09:10:23 2003 +0000 @@ -204,13 +204,13 @@ return (utf8); } -static struct conversation * +static struct gaim_conversation * irc_find_chat(struct gaim_connection *gc, char *name) { GSList *bcs = gc->buddy_chats; while (bcs) { - struct conversation *b = bcs->data; + struct gaim_conversation *b = bcs->data; if (!g_strcasecmp(b->name, name)) return b; bcs = bcs->next; @@ -218,20 +218,6 @@ return NULL; } -static struct conversation * -irc_find_chat_by_id(struct gaim_connection *gc, int id) -{ - GSList *bcs = gc->buddy_chats; - - while (bcs) { - struct conversation *b = bcs->data; - if (b->id == id) - return b; - bcs = bcs->next; - } - return NULL; -} - static void process_data_init(char *buf, char *cmd, char *word[], char *eol[], gboolean quotes) { @@ -496,7 +482,7 @@ gchar buffer[IRC_BUF_LEN]; gchar buf[128]; int n = 0; - struct conversation *convo; + struct gaim_conversation *convo; debug_printf("THIS IS TOO MUCH EFFORT\n"); n = read (chat->fd, buffer, IRC_BUF_LEN); if (n > 0) { @@ -514,9 +500,9 @@ else { g_snprintf (buf, sizeof buf, _("DCC Chat with %s closed"), chat->nick); - convo = new_conversation (chat->nick); - write_to_conv (convo, buf, WFLAG_SYSTEM, NULL, - time ((time_t) NULL), -1); + convo = gaim_conversation_new(GAIM_CONV_IM, chat->nick); + gaim_conversation_write(convo, NULL, buf, -1, WFLAG_SYSTEM, + time(NULL)); dcc_chat_cancel (chat); } } @@ -573,14 +559,16 @@ void dcc_chat_callback (gpointer data, gint source, GaimInputCondition condition) { struct dcc_chat *chat = data; - struct conversation *convo = new_conversation (chat->nick); + struct gaim_conversation *convo; char buf[IRC_BUF_LEN]; + + convo = gaim_conversation_new(GAIM_CONV_IM, chat->nick); + chat->fd = source; g_snprintf (buf, sizeof buf, _("DCC Chat with %s established"), chat->nick); - write_to_conv (convo, buf, WFLAG_SYSTEM, NULL, - time ((time_t) NULL), -1); + gaim_conversation_write(convo, NULL, buf, -1, WFLAG_SYSTEM, time(NULL)); debug_printf ("Chat with %s established\n", chat->nick); dcc_chat_list = g_slist_append (dcc_chat_list, chat); gaim_input_remove(chat->inpa); @@ -676,31 +664,41 @@ static void handle_names(struct gaim_connection *gc, char *chan, char *names) { - struct conversation *c = irc_find_chat(gc, chan); + struct gaim_conversation *c = irc_find_chat(gc, chan); + struct gaim_chat *chat; char **buf, **tmp; + if (!c) return; if (*names == ':') names++; + + chat = GAIM_CHAT(c); + buf = g_strsplit(names, " ", -1); + for (tmp = buf; *tmp; tmp++) - add_chat_buddy(c, *tmp, NULL); + gaim_chat_add_user(chat, *tmp, NULL); + g_strfreev(buf); } static void handle_notopic(struct gaim_connection *gc, char *text) { - struct conversation *c; + struct gaim_conversation *c; + if ((c = irc_find_chat(gc, text))) { char buf[IRC_BUF_LEN]; + g_snprintf(buf, sizeof(buf), _("No topic is set")); - chat_set_topic(c, NULL, buf); + + gaim_chat_set_topic(GAIM_CHAT(c), NULL, buf); } } static void handle_topic(struct gaim_connection *gc, char *text) { - struct conversation *c; + struct gaim_conversation *c; char *po = strchr(text, ' '); if (!po) @@ -711,10 +709,11 @@ if ((c = irc_find_chat(gc, text))) { char buf[IRC_BUF_LEN]; - chat_set_topic(c, NULL, po); + gaim_chat_set_topic(GAIM_CHAT(c), NULL, po); g_snprintf(buf, sizeof(buf), _("%s has changed the topic to: %s"), text, po); - write_to_conv(c, buf, WFLAG_SYSTEM, NULL, time(NULL), -1); + + gaim_conversation_write(c, NULL, buf, -1, WFLAG_SYSTEM, time(NULL)); } } @@ -752,7 +751,7 @@ static void irc_chan_mode(struct gaim_connection *gc, char *room, char sign, char mode, char *argstr, char *who) { - struct conversation *c = irc_find_chat(gc, room); + struct gaim_conversation *c = irc_find_chat(gc, room); char buf[IRC_BUF_LEN]; char *nick = g_strndup(who, strchr(who, '!') - who); @@ -760,13 +759,14 @@ room, sign, mode, strlen(argstr) ? argstr : "", nick); g_free(nick); - write_to_conv(c, buf, WFLAG_SYSTEM, NULL, time((time_t)NULL), -1); + + gaim_conversation_write(c, NULL, buf, -1, WFLAG_SYSTEM, time(NULL)); } static void irc_user_mode(struct gaim_connection *gc, char *room, char sign, char mode, char *nick) { - struct conversation *c = irc_find_chat(gc, room); + struct gaim_conversation *c = irc_find_chat(gc, room); GList *r; if (mode != 'o' && mode != 'v') @@ -775,7 +775,7 @@ if (!c) return; - r = c->in_room; + r = gaim_chat_get_users(GAIM_CHAT(c)); while (r) { gboolean op = FALSE, voice = FALSE; char *who = r->data; @@ -804,7 +804,7 @@ tmp = g_strdup(r->data); g_snprintf(buf, sizeof(buf), "%s%s%s", op ? "@" : "", voice ? "+" : "", nick); - rename_chat_buddy(c, tmp, buf); + gaim_chat_rename_user(GAIM_CHAT(c), tmp, buf); g_free(tmp); return; } @@ -818,7 +818,7 @@ struct irc_data *id = gc->proto_data; int offset = n324 ? 4 : 3; char *chan = word[offset]; - struct conversation *c = irc_find_chat(gc, chan); + struct gaim_conversation *c = irc_find_chat(gc, chan); char *modes = word[offset + 1]; int len = strlen(word_eol[offset]) - 1; char sign = *modes++; @@ -1101,11 +1101,18 @@ } static void -irc_rem_chat_bud(struct gaim_connection *gc, char *nick, struct conversation *b, char *reason) +irc_rem_chat_bud(struct gaim_connection *gc, char *nick, struct gaim_conversation *b, char *reason) { + struct gaim_chat *chat; + if (b) { - GList *r = b->in_room; + GList *r; + + chat = GAIM_CHAT(b); + + r = gaim_chat_get_users(chat); + while (r) { char *who = r->data; if (*who == '@') @@ -1114,7 +1121,7 @@ who++; if (!g_strcasecmp(who, nick)) { char *tmp = g_strdup(r->data); - remove_chat_buddy(b, tmp, reason); + gaim_chat_remove_user(chat, tmp, reason); g_free(tmp); break; } @@ -1123,7 +1130,7 @@ } else { GSList *bcs = gc->buddy_chats; while (bcs) { - struct conversation *bc = bcs->data; + struct gaim_conversation *bc = bcs->data; irc_rem_chat_bud(gc, nick, bc, reason); bcs = bcs->next; } @@ -1137,9 +1144,14 @@ char buf[IRC_BUF_LEN]; while (bcs) { - struct conversation *b = bcs->data; + struct gaim_conversation *b = bcs->data; + struct gaim_chat *chat; + GList *r; - GList *r = b->in_room; + chat = GAIM_CHAT(b); + + r = gaim_chat_get_users(chat); + while (r) { char *who = r->data; int n = 0; @@ -1150,8 +1162,8 @@ g_snprintf(buf + n, sizeof(buf) - n, "%s", new); if (!strcmp(who, old)) { char *tmp = g_strdup(r->data); - rename_chat_buddy(b, tmp, buf); - r = b->in_room; + gaim_chat_rename_user(chat, tmp, buf); + r = gaim_chat_get_users(chat); g_free(tmp); break; } else @@ -1165,18 +1177,19 @@ handle_privmsg(struct gaim_connection *gc, char *to, char *nick, char *msg) { if (is_channel(gc, to)) { - struct conversation *c = irc_find_chat(gc, to); + struct gaim_conversation *c = irc_find_chat(gc, to); if (!c) return; - irc_got_chat_in(gc, c->id, nick, 0, msg, time(NULL)); + irc_got_chat_in(gc, gaim_chat_get_id(GAIM_CHAT(c)), + nick, 0, msg, time(NULL)); } else { char *tmp = g_malloc(strlen(nick) + 2); g_snprintf(tmp, strlen(nick) + 2, "@%s", nick); - if (find_conversation(tmp)) + if (gaim_find_conversation(tmp)) irc_got_im(gc, tmp, msg, 0, time(NULL)); else { *tmp = '+'; - if (find_conversation(tmp)) + if (gaim_find_conversation(tmp)) irc_got_im(gc, tmp, msg, 0, time(NULL)); else irc_got_im(gc, nick, msg, 0, time(NULL)); @@ -1364,18 +1377,18 @@ irc_parse_join(gc, nick, word, word_eol); } else if (!strcmp(cmd, "KICK")) { if (!strcmp(gc->displayname, word[4])) { - struct conversation *c = irc_find_chat(gc, word[3]); + struct gaim_conversation *c = irc_find_chat(gc, word[3]); if (!c) return FALSE; gc->buddy_chats = g_slist_remove(gc->buddy_chats, c); - c->gc = NULL; + gaim_conversation_set_user(c, NULL); g_snprintf(outbuf, sizeof(outbuf), _("You have been kicked from %s: %s"), word[3], *word_eol[5] == ':' ? word_eol[5] + 1 : word_eol[5]); do_error_dialog(outbuf, _("IRC Error"), GAIM_ERROR); } else { char *reason = *word_eol[5] == ':' ? word_eol[5] + 1 : word_eol[5]; char *msg = g_strdup_printf(_("Kicked by %s: %s"), nick, reason); - struct conversation *c = irc_find_chat(gc, word[3]); + struct gaim_conversation *c = irc_find_chat(gc, word[3]); irc_rem_chat_bud(gc, word[4], c, msg); g_free(msg); } @@ -1485,9 +1498,9 @@ { char *chan = *word[3] == ':' ? word[3] + 1 : word[3]; static int id = 1; - struct conversation *c; + struct gaim_conversation *c; char *hostmask, *p; - + if (!g_strcasecmp(gc->displayname, nick)) { serv_got_joined_chat(gc, id++, chan); } else { @@ -1500,7 +1513,9 @@ if (pend) { *pend = 0; } - add_chat_buddy(c, nick, p+1); + + gaim_chat_add_user(GAIM_CHAT(c), nick, p + 1); + g_free(hostmask); } } @@ -1511,15 +1526,16 @@ irc_parse_topic(struct gaim_connection *gc, char *nick, char *word[], char *word_eol[]) { - struct conversation *c = irc_find_chat(gc, word[3]); + struct gaim_conversation *c = irc_find_chat(gc, word[3]); char *topic = *word_eol[4] == ':' ? word_eol[4] + 1 : word_eol[4]; char buf[IRC_BUF_LEN]; if (c) { - chat_set_topic(c, nick, topic); + gaim_chat_set_topic(GAIM_CHAT(c), nick, topic); g_snprintf(buf, sizeof(buf), _("%s has changed the topic to: %s"), nick, topic); - write_to_conv(c, buf, WFLAG_SYSTEM, NULL, time(NULL), -1); + + gaim_conversation_write(c, NULL, buf, -1, WFLAG_SYSTEM, time(NULL)); } } @@ -1528,7 +1544,8 @@ char *word[], char *word_eol[]) { char *chan = cmd + 5; - struct conversation *c; + struct gaim_conversation *c; + struct gaim_chat *chat; char *reason = word_eol[4]; GList *r; @@ -1539,10 +1556,14 @@ if (!(c = irc_find_chat(gc, chan))) return FALSE; if (!strcmp(nick, gc->displayname)) { - serv_got_chat_left(gc, c->id); + serv_got_chat_left(gc, gaim_chat_get_id(GAIM_CHAT(c))); return FALSE; } - r = c->in_room; + + chat = GAIM_CHAT(c); + + r = gaim_chat_get_users(GAIM_CHAT(c)); + while (r) { char *who = r->data; if (*who == '@') @@ -1551,13 +1572,13 @@ who++; if (!g_strcasecmp(who, nick)) { char *tmp = g_strdup(r->data); - remove_chat_buddy(c, tmp, reason); + gaim_chat_remove_user(chat, tmp, reason); g_free(tmp); break; } r = r->next; } - return TRUE; + return TRUE; } static void @@ -1909,8 +1930,10 @@ int len; struct dcc_chat *dccchat = find_dcc_chat(gc, who); struct irc_data *id = gc->proto_data; + g_free(tmp); what = str->str; + if (*what != '/') { if (dccchat) { intl = irc_send_convert(gc, what, sizeof(buf), &len); @@ -1946,10 +1969,19 @@ irc_write(id->fd, buf, strlen(buf)); } else if (!g_strcasecmp(pdibuf, "TOPIC")) { if (!*word_eol[2]) { - struct conversation *c; + struct gaim_conversation *c; + struct gaim_chat *chat; + c = irc_find_chat(gc, who); - g_snprintf(buf, sizeof(buf), _("Topic for %s is %s"), who, c->topic ? c->topic : "(no topic set)"); - write_to_conv(c, buf, WFLAG_SYSTEM | WFLAG_NOLOG, NULL, time(NULL), -1); + chat = GAIM_CHAT(c); + + g_snprintf(buf, sizeof(buf), _("Topic for %s is %s"), + who, (gaim_chat_get_topic(chat) + ? gaim_chat_get_topic(chat) + : "(no topic set)")); + + gaim_conversation_write(c, NULL, buf, -1, + WFLAG_SYSTEM | WFLAG_NOLOG, time(NULL)); } else { /* This could be too long */ intl = irc_send_convert(gc, word_eol[2], sizeof(buf), &len); @@ -2024,7 +2056,7 @@ } else if (!g_strcasecmp(pdibuf, "PART")) { char *chan = *word[2] ? word[2] : who; char *reason = word_eol[3]; - struct conversation *c; + struct gaim_conversation *c; if (!is_channel(gc, chan)) { g_free(what); return -EINVAL; @@ -2039,7 +2071,7 @@ irc_write(id->fd, buf, strlen(buf)); if (c) { gc->buddy_chats = g_slist_remove(gc->buddy_chats, c); - c->gc = NULL; + gaim_conversation_set_user(c, NULL); g_snprintf(buf, sizeof(buf), _("You have left %s"), chan); do_error_dialog(buf, _("IRC Part"), GAIM_INFO); } @@ -2084,7 +2116,7 @@ irc_ctcp_ping(gc, word[3]); } } else if (!g_strcasecmp(pdibuf, "DCC")) { - struct conversation *c = NULL; + struct gaim_conversation *c = NULL; if (!g_strcasecmp(word[2], "CHAT")) { if (word[3]) irc_start_chat(gc, word[3]); @@ -2092,64 +2124,70 @@ if (is_channel(gc, who)) { c = irc_find_chat(gc, who); } else { - c = find_conversation(who); + c = gaim_find_conversation(who); } if (c) { - write_to_conv(c, _("Requesting DCC CHAT"), - WFLAG_SYSTEM, NULL, - time(NULL), -1); + gaim_conversation_write(c, NULL, + _("Requesting DCC CHAT"), + -1, WFLAG_SYSTEM, time(NULL)); } } } else if (!g_strcasecmp(pdibuf, "HELP")) { - struct conversation *c = NULL; + struct gaim_conversation *c = NULL; if (is_channel(gc, who)) { c = irc_find_chat(gc, who); } else { - c = find_conversation(who); + c = gaim_find_conversation(who); } if (!c) { g_free(what); return -EINVAL; } if (!g_strcasecmp(word[2], "OPER")) { - write_to_conv(c, _("Operator commands:
" - "REHASH RESTART
"), - WFLAG_NOLOG, NULL, time(NULL), -1); + gaim_conversation_write(c, NULL, + _("Operator commands:
" + "REHASH RESTART
"), + -1, WFLAG_NOLOG, time(NULL)); } else if (!g_strcasecmp(word[2], "CTCP")) { - write_to_conv(c, _("CTCP commands:
" - "CLIENTINFO
" - "USERINFO
" - "VERSION
" - "PING

"), - WFLAG_NOLOG, NULL, time(NULL), -1); + gaim_conversation_write(c, NULL, + _("CTCP commands:
" + "CLIENTINFO
" + "USERINFO
" + "VERSION
" + "PING

"), + -1, WFLAG_NOLOG, time(NULL)); } else if (!g_strcasecmp(word[2], "DCC")) { - write_to_conv(c, _("DCC commands:
" - "CHAT
"), - WFLAG_NOLOG, NULL, time(NULL), -1); + gaim_conversation_write(c, NULL, + _("DCC commands:
" + "CHAT
"), + -1, WFLAG_NOLOG, time(NULL)); } else { - write_to_conv(c, _("Currently supported commands:
" - "WHOIS INVITE NICK LIST
" - "JOIN PART TOPIC KICK
" - "OP DEOP VOICE DEVOICE
" - "ME MSG QUOTE SAY QUIT
" - "MODE VERSION W WHOWAS
" - "Type /HELP OPER for operator commands
" - "Type /HELP CTCP for CTCP commands
" - "Type /HELP DCC for DCC commands"), - WFLAG_NOLOG, NULL, time(NULL), -1); + gaim_conversation_write(c, NULL, + _("Currently supported commands:
" + "WHOIS INVITE NICK LIST
" + "JOIN PART TOPIC KICK
" + "OP DEOP VOICE DEVOICE
" + "ME MSG QUOTE SAY QUIT
" + "MODE VERSION W WHOWAS
" + "Type /HELP OPER for operator commands
" + "Type /HELP CTCP for CTCP commands
" + "Type /HELP DCC for DCC commands"), + -1, WFLAG_NOLOG, time(NULL)); } } else { - struct conversation *c = NULL; + struct gaim_conversation *c = NULL; if (is_channel(gc, who)) { c = irc_find_chat(gc, who); } else { - c = find_conversation(who); + c = gaim_find_conversation(who); } if (!c) { g_free(what); return -EINVAL; } - write_to_conv(c, _("Unknown command"), WFLAG_NOLOG, NULL, time(NULL), -1); + + gaim_conversation_write(c, NULL, _("Unknown command"), + -1, WFLAG_NOLOG, time(NULL)); } g_free(what); return 0; @@ -2182,7 +2220,7 @@ irc_chat_invite(struct gaim_connection *gc, int idn, const char *message, const char *name) { char buf[IRC_BUF_LEN]; struct irc_data *id = gc->proto_data; - struct conversation *c = irc_find_chat_by_id(gc, idn); + struct gaim_conversation *c = gaim_find_chat(gc, idn); g_snprintf(buf, sizeof(buf), "INVITE %s %s\r\n", name, c->name); irc_write(id->fd, buf, strlen(buf)); } @@ -2240,7 +2278,7 @@ irc_chat_leave(struct gaim_connection *gc, int id) { struct irc_data *idata = gc->proto_data; - struct conversation *c = irc_find_chat_by_id(gc, id); + struct gaim_conversation *c = gaim_find_chat(gc, id); char buf[IRC_BUF_LEN]; if (!c) return; @@ -2252,11 +2290,12 @@ static int irc_chat_send(struct gaim_connection *gc, int id, char *what) { - struct conversation *c = irc_find_chat_by_id(gc, id); + struct gaim_conversation *c = gaim_find_chat(gc, id); if (!c) return -EINVAL; if (send_msg(gc, c->name, what) > 0) - serv_got_chat_in(gc, c->id, gc->displayname, 0, what, time(NULL)); + serv_got_chat_in(gc, gaim_chat_get_id(GAIM_CHAT(c)), + gc->displayname, 0, what, time(NULL)); return 0; } @@ -2319,7 +2358,7 @@ dcc_chat_connected(gpointer data, gint source, GdkInputCondition condition) { struct dcc_chat *chat = data; - struct conversation *convo; + struct gaim_conversation *convo; char buf[128]; struct sockaddr_in addr; int addrlen = sizeof (addr); @@ -2329,19 +2368,19 @@ chat->fd = accept (chat->fd, (struct sockaddr *) (&addr), &addrlen); if (!chat->fd) { dcc_chat_cancel (chat); - convo = new_conversation (chat->nick); + convo = gaim_conversation_new(GAIM_CONV_IM, chat->nick); g_snprintf (buf, sizeof buf, _("DCC Chat with %s closed"), chat->nick); - write_to_conv (convo, buf, WFLAG_SYSTEM, NULL, - time ((time_t) NULL), -1); + gaim_conversation_write(convo, NULL, buf, -1, + WFLAG_SYSTEM, time(NULL)); return; } chat->inpa = gaim_input_add (chat->fd, GAIM_INPUT_READ, dcc_chat_in, chat); - convo = new_conversation (chat->nick); + convo = gaim_conversation_new(GAIM_CONV_IM, chat->nick); g_snprintf (buf, sizeof buf, _("DCC Chat with %s established"), - chat->nick); - write_to_conv (convo, buf, WFLAG_SYSTEM, NULL, time ((time_t) NULL), -1); + chat->nick); + gaim_conversation_write(convo, NULL, buf, -1, WFLAG_SYSTEM, time(NULL)); debug_printf ("Chat with %s established\n", chat->nick); dcc_chat_list = g_slist_append (dcc_chat_list, chat); } diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/protocols/jabber/jabber.c --- a/src/protocols/jabber/jabber.c Mon Jan 20 07:00:10 2003 +0000 +++ b/src/protocols/jabber/jabber.c Mon Jan 20 09:10:23 2003 +0000 @@ -219,7 +219,7 @@ struct jabber_chat { gaim_jid gjid; struct gaim_connection *gc; - struct conversation *b; + struct gaim_conversation *b; int id; int state; }; @@ -821,10 +821,10 @@ /* * Find chat by chat group name */ -static struct conversation *find_chat(struct gaim_connection *gc, char *name) +static struct gaim_conversation *find_chat(struct gaim_connection *gc, char *name) { GSList *bcs = gc->buddy_chats; - struct conversation *b = NULL; + struct gaim_conversation *b = NULL; char *chat = g_strdup(normalize(name)); while (bcs) { @@ -854,14 +854,14 @@ static int jabber_find_chat_by_convo_id(struct gaim_connection *gc, int id, struct jabber_chat **jc) { GSList *bcs = gc->buddy_chats; - struct conversation *b = NULL; + struct gaim_conversation *b = NULL; struct jabber_data *jd = gc->proto_data; *jc = NULL; while(bcs != NULL) { b = bcs->data; - if (id == b->id) + if (id == gaim_chat_get_id(GAIM_CHAT(b))) break; bcs = bcs->next; } @@ -937,9 +937,9 @@ return jc; } -static gboolean find_chat_buddy(struct conversation *b, char *name) +static gboolean find_chat_buddy(struct gaim_conversation *b, char *name) { - GList *m = b->in_room; + GList *m = gaim_chat_get_users(GAIM_CHAT(b)); while (m) { if (!strcmp(m->data, name)) @@ -1324,8 +1324,9 @@ struct jabber_chat *jc; g_snprintf(m, sizeof(m), "%s", msg); if (((jc = find_existing_chat(GJ_GC(gjc), p->from)) != NULL) && jc->b) - serv_got_chat_in(GJ_GC(gjc), jc->b->id, p->from->resource, 1, m, - time_sent); + serv_got_chat_in(GJ_GC(gjc), + gaim_chat_get_id(GAIM_CHAT(jc->b)), + p->from->resource, 1, m, time_sent); else { int flags = 0; jab_res_info jri = jabber_find_resource(GJ_GC(gjc), from); @@ -1334,7 +1335,7 @@ if (xmlnode_get_tag(p->x, "gaim")) flags = IM_FLAG_GAIMUSER; jabber_track_convo_thread(gjc, from, thread_id); - if (find_conversation(from)) + if (gaim_find_conversation(from)) serv_got_im(GJ_GC(gjc), from, m, flags, time_sent, -1); else { @@ -1393,7 +1394,7 @@ if ((jc = find_pending_chat(GJ_GC(gjc), p->from)) != NULL) { /* yes, we're supposed to be. so now we are. */ jc->b = serv_got_joined_chat(GJ_GC(gjc), i++, p->from->user); - jc->id = jc->b->id; + jc->id = gaim_chat_get_id(GAIM_CHAT(jc->b)); jc->state = JCS_ACTIVE; } else { /* no, we're not supposed to be. */ @@ -1404,7 +1405,8 @@ if (p->from->resource) { if (!y) { if (!find_chat_buddy(jc->b, p->from->resource)) { - add_chat_buddy(jc->b, p->from->resource, NULL); + gaim_chat_add_user(GAIM_CHAT(jc->b), + p->from->resource, NULL); } else if ((y = xmlnode_get_tag(p->x, "status"))) { jabber_track_away(gjc, p, NULL); } @@ -1414,18 +1416,20 @@ if (topic) { char tbuf[8192]; g_snprintf(tbuf, sizeof(tbuf), "%s", topic); - chat_set_topic(jc->b, p->from->resource, tbuf); + gaim_chat_set_topic(GAIM_CHAT(jc->b), + p->from->resource, tbuf); } g_snprintf(buf, sizeof(buf), "%s", msg); - serv_got_chat_in(GJ_GC(gjc), jc->b->id, p->from->resource, 0, buf, - time_sent); + serv_got_chat_in(GJ_GC(gjc), + gaim_chat_get_id(GAIM_CHAT(jc->b)), + p->from->resource, 0, buf, time_sent); } } else { /* message from the server */ if(jc->b && topic) { char tbuf[8192]; g_snprintf(tbuf, sizeof(tbuf), "%s", topic); - chat_set_topic(jc->b, "", tbuf); + gaim_chat_set_topic(GAIM_CHAT(jc->b), "", tbuf); } } @@ -1443,7 +1447,7 @@ xmlnode y; char *show; int state = 0; - struct conversation *cnv = NULL; + struct gaim_conversation *cnv = NULL; struct jabber_chat *jc = NULL; int priority = 0; struct jabber_buddy_data *jbd; @@ -1506,7 +1510,7 @@ static int i = 0x70; if ((jc = find_pending_chat(GJ_GC(gjc), gjid)) != NULL) { jc->b = cnv = serv_got_joined_chat(GJ_GC(gjc), i++, gjid->user); - jc->id = jc->b->id; + jc->id = gaim_chat_get_id(GAIM_CHAT(jc->b)); jc->state = JCS_ACTIVE; } else if ((b = find_buddy(GJ_GC(gjc)->user, buddy)) == NULL) { g_free(buddy); @@ -1545,7 +1549,8 @@ jd = jc->gc->proto_data; /* if it's not ourselves...*/ if (strcmp(gjid->resource, jc->gjid->resource) && jc->b) { - remove_chat_buddy(jc->b, gjid->resource, NULL); + gaim_chat_remove_user(GAIM_CHAT(jc->b), gjid->resource, + NULL); g_free(buddy); gaim_jid_free(gjid); return; @@ -1565,7 +1570,7 @@ return; } if (!find_chat_buddy(jc->b, gjid->resource)) { - add_chat_buddy(jc->b, gjid->resource, NULL); + gaim_chat_add_user(GAIM_CHAT(jc->b), gjid->resource, NULL); } } } diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/protocols/msn/msn.c --- a/src/protocols/msn/msn.c Mon Jan 20 07:00:10 2003 +0000 +++ b/src/protocols/msn/msn.c Mon Jan 20 09:10:23 2003 +0000 @@ -118,7 +118,7 @@ struct msn_switchboard { struct gaim_connection *gc; - struct conversation *chat; + struct gaim_conversation *chat; int fd; int inpa; @@ -415,7 +415,7 @@ while (m) { struct msn_switchboard *ms = m->data; m = m->next; - if (ms->chat && (ms->chat->id == id)) + if (ms->chat && gaim_chat_get_id(GAIM_CHAT(ms->chat)) == id) return ms; } @@ -458,7 +458,7 @@ ms->txqueue = g_slist_remove(ms->txqueue, ms->txqueue->data); } if (ms->chat) - serv_got_chat_left(gc, ms->chat->id); + serv_got_chat_left(gc, gaim_chat_get_id(GAIM_CHAT(ms->chat))); md->switches = g_slist_remove(md->switches, ms); @@ -474,18 +474,18 @@ if (!g_strncasecmp(buf, "ACK", 3)) { } else if (!g_strncasecmp(buf, "ANS", 3)) { if (ms->chat) - add_chat_buddy(ms->chat, gc->username, NULL); + gaim_chat_add_user(GAIM_CHAT(ms->chat), gc->username, NULL); } else if (!g_strncasecmp(buf, "BYE", 3)) { char *user, *tmp = buf; GET_NEXT(tmp); user = tmp; if (ms->chat) { - remove_chat_buddy(ms->chat, user, NULL); + gaim_chat_remove_user(GAIM_CHAT(ms->chat), user, NULL); } else { char msgbuf[256]; const char *username; - struct conversation *cnv; + struct gaim_conversation *cnv; struct buddy *b; if ((b = find_buddy(gc->user, user)) != NULL) @@ -496,8 +496,9 @@ g_snprintf(msgbuf, sizeof(msgbuf), _("%s has closed the conversation window"), username); - if ((cnv = find_conversation(user))) - write_to_conv(cnv, msgbuf, WFLAG_SYSTEM, NULL, time(NULL), -1); + if ((cnv = gaim_find_conversation(user))) + gaim_conversation_write(cnv, NULL, msgbuf, -1, + WFLAG_SYSTEM, time(NULL)); msn_kill_switch(ms); return 0; @@ -518,7 +519,8 @@ if (ms->total > 1) { if (!ms->chat) ms->chat = serv_got_joined_chat(gc, ++id, "MSN Chat"); - add_chat_buddy(ms->chat, user, NULL); + + gaim_chat_add_user(GAIM_CHAT(ms->chat), user, NULL); } } else if (!g_strncasecmp(buf, "JOI", 3)) { char *user, *tmp = buf; @@ -528,13 +530,13 @@ if (ms->total == 1) { ms->chat = serv_got_joined_chat(gc, ++id, "MSN Chat"); - add_chat_buddy(ms->chat, ms->user, NULL); - add_chat_buddy(ms->chat, gc->username, NULL); + gaim_chat_add_user(GAIM_CHAT(ms->chat), ms->user, NULL); + gaim_chat_add_user(GAIM_CHAT(ms->chat), gc->username, NULL); g_free(ms->user); ms->user = NULL; } if (ms->chat) - add_chat_buddy(ms->chat, user, NULL); + gaim_chat_add_user(GAIM_CHAT(ms->chat), user, NULL); ms->total++; while (ms->txqueue) { char *send = add_cr(ms->txqueue->data); @@ -569,7 +571,7 @@ } else if (!g_strncasecmp(buf, "NLN", 3)) { } else if (!g_strncasecmp(buf, "OUT", 3)) { if (ms->chat) - serv_got_chat_left(gc, ms->chat->id); + serv_got_chat_left(gc, gaim_chat_get_id(GAIM_CHAT(ms->chat))); msn_kill_switch(ms); return 0; } else if (!g_strncasecmp(buf, "USR", 3)) { @@ -915,7 +917,8 @@ } if (ms->chat) - serv_got_chat_in(ms->gc, ms->chat->id, ms->msguser, flags, message, time(NULL)); + serv_got_chat_in(ms->gc, gaim_chat_get_id(GAIM_CHAT(ms->chat)), + ms->msguser, flags, message, time(NULL)); else serv_got_im(ms->gc, ms->msguser, message, flags, time(NULL), -1); diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/protocols/napster/napster.c --- a/src/protocols/napster/napster.c Mon Jan 20 07:00:10 2003 +0000 +++ b/src/protocols/napster/napster.c Mon Jan 20 09:10:23 2003 +0000 @@ -141,16 +141,16 @@ return NULL; } -static struct conversation *find_conversation_by_id(struct gaim_connection *gc, int id) +static struct gaim_conversation *find_conversation_by_id(struct gaim_connection *gc, int id) { GSList *bc = gc->buddy_chats; - struct conversation *b = NULL; + struct gaim_conversation *b = NULL; while (bc) { - b = (struct conversation *)bc->data; - if (id == b->id) { + b = (struct gaim_conversation *)bc->data; + if (id == gaim_chat_get_id(GAIM_CHAT(b))) break; - } + bc = bc->next; b = NULL; } @@ -243,7 +243,7 @@ if (command == 0x198 || command == 0x196) { struct nap_channel *channel; - struct conversation *convo; + struct gaim_conversation *convo; gchar **res; res = g_strsplit(buf, " ", 0); @@ -251,7 +251,7 @@ channel = find_channel_by_name(gc, res[0]); convo = find_conversation_by_id(gc, channel->id); - add_chat_buddy(convo, res[1], NULL); + gaim_chat_add_user(GAIM_CHAT(convo), res[1], NULL); g_strfreev(res); @@ -261,7 +261,7 @@ if (command == 0x197) { struct nap_channel *channel; - struct conversation *convo; + struct gaim_conversation *convo; gchar **res; res = g_strsplit(buf, " ", 0); @@ -269,7 +269,7 @@ channel = find_channel_by_name(gc, res[0]); convo = find_conversation_by_id(gc, channel->id); - remove_chat_buddy(convo, res[1], NULL); + gaim_chat_remove_user(GAIM_CHAT(convo), res[1], NULL); g_strfreev(res); g_free(buf); diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/protocols/oscar/oscar.c --- a/src/protocols/oscar/oscar.c Mon Jan 20 07:00:10 2003 +0000 +++ b/src/protocols/oscar/oscar.c Mon Jan 20 09:10:23 2003 +0000 @@ -156,7 +156,7 @@ int inpa; int id; struct gaim_connection *gc; /* i hate this. */ - struct conversation *cnv; /* bah. */ + struct gaim_conversation *cnv; /* bah. */ int maxlen; int maxvis; }; @@ -458,7 +458,7 @@ static void gaim_directim_disconnect(aim_session_t *sess, aim_conn_t *conn) { struct gaim_connection *gc = sess->aux_data; struct oscar_data *od = (struct oscar_data *)gc->proto_data; - struct conversation *cnv; + struct gaim_conversation *cnv; struct direct_im *dim; char *sn; char buf[256]; @@ -476,9 +476,10 @@ else g_snprintf(buf, sizeof buf, _("Direct IM with %s failed"), sn); - if ((cnv = find_conversation(sn))) - write_to_conv(cnv, buf, WFLAG_SYSTEM, NULL, time(NULL), -1); - update_progress(cnv, 100); + if ((cnv = gaim_find_conversation(sn))) + gaim_conversation_write(cnv, NULL, buf, -1, WFLAG_SYSTEM, time(NULL)); + + gaim_conversation_update_progress(cnv, 100); g_free(dim); /* I guess? I don't see it anywhere else... -- mid */ g_free(sn); @@ -1487,7 +1488,7 @@ struct direct_im *dim = data; struct gaim_connection *gc = dim->gc; struct oscar_data *od = gc->proto_data; - struct conversation *cnv; + struct gaim_conversation *cnv; char buf[256]; struct sockaddr name; socklen_t name_len = 1; @@ -1505,14 +1506,14 @@ if (dim->conn->fd != source) dim->conn->fd = source; aim_conn_completeconnect(od->sess, dim->conn); - if (!(cnv = find_conversation(dim->name))) - cnv = new_conversation(dim->name); + if (!(cnv = gaim_find_conversation(dim->name))) + cnv = gaim_conversation_new(GAIM_CONV_IM, dim->name); /* This is the best way to see if we're connected or not */ if (getpeername(source, &name, &name_len) == 0) { g_snprintf(buf, sizeof buf, _("Direct IM with %s established"), dim->name); dim->connected = TRUE; - write_to_conv(cnv, buf, WFLAG_SYSTEM, NULL, time(NULL), -1); + gaim_conversation_write(cnv, NULL, buf, -1, WFLAG_SYSTEM, time(NULL)); } od->direct_ims = g_slist_append(od->direct_ims, dim); @@ -2956,7 +2957,7 @@ return 1; for (i = 0; i < count; i++) - add_chat_buddy(c->cnv, info[i].sn, NULL); + gaim_chat_add_user(GAIM_CHAT(c->cnv), info[i].sn, NULL); return 1; } @@ -2979,7 +2980,7 @@ return 1; for (i = 0; i < count; i++) - remove_chat_buddy(c->cnv, info[i].sn, NULL); + gaim_chat_remove_user(GAIM_CHAT(c->cnv), info[i].sn, NULL); return 1; } @@ -4507,14 +4508,14 @@ static void oscar_chat_leave(struct gaim_connection *g, int id) { struct oscar_data *odata = g ? (struct oscar_data *)g->proto_data : NULL; GSList *bcs = g->buddy_chats; - struct conversation *b = NULL; + struct gaim_conversation *b = NULL; struct chat_connection *c = NULL; int count = 0; while (bcs) { count++; - b = (struct conversation *)bcs->data; - if (id == b->id) + b = (struct gaim_conversation *)bcs->data; + if (id == gaim_chat_get_id(GAIM_CHAT(b))) break; bcs = bcs->next; b = NULL; @@ -4525,7 +4526,7 @@ debug_printf("Attempting to leave room %s (currently in %d rooms)\n", b->name, count); - c = find_oscar_chat(g, b->id); + c = find_oscar_chat(g, gaim_chat_get_id(GAIM_CHAT(b))); if (c != NULL) { if (odata) odata->oscar_chats = g_slist_remove(odata->oscar_chats, c); @@ -4538,20 +4539,20 @@ g_free(c); } /* we do this because with Oscar it doesn't tell us we left */ - serv_got_chat_left(g, b->id); + serv_got_chat_left(g, gaim_chat_get_id(GAIM_CHAT(b))); } static int oscar_chat_send(struct gaim_connection *g, int id, char *message) { struct oscar_data *odata = (struct oscar_data *)g->proto_data; GSList *bcs = g->buddy_chats; - struct conversation *b = NULL; + struct gaim_conversation *b = NULL; struct chat_connection *c = NULL; char *buf, *buf2; int i, j; while (bcs) { - b = (struct conversation *)bcs->data; - if (id == b->id) + b = (struct gaim_conversation *)bcs->data; + if (id == gaim_chat_get_id(GAIM_CHAT(b))) break; bcs = bcs->next; b = NULL; @@ -4730,7 +4731,7 @@ struct gaim_connection *gc = sess->aux_data; struct oscar_data *od = (struct oscar_data *)gc->proto_data; aim_conn_t *newconn, *listenerconn; - struct conversation *cnv; + struct gaim_conversation *cnv; struct direct_im *dim; char buf[256]; char *sn; @@ -4748,8 +4749,8 @@ debug_printf("DirectIM: initiate success to %s\n", sn); dim = find_direct_im(od, sn); - if (!(cnv = find_conversation(sn))) - cnv = new_conversation(sn); + if (!(cnv = gaim_find_conversation(sn))) + cnv = gaim_conversation_new(GAIM_CONV_IM, sn); gaim_input_remove(dim->watcher); dim->conn = newconn; dim->watcher = gaim_input_add(dim->conn->fd, GAIM_INPUT_READ, @@ -4757,7 +4758,7 @@ dim->connected = TRUE; g_snprintf(buf, sizeof buf, _("Direct IM with %s established"), sn); g_free(sn); - write_to_conv(cnv, buf, WFLAG_SYSTEM, NULL, time(NULL), -1); + gaim_conversation_write(cnv, NULL, buf, -1, WFLAG_SYSTEM, time(NULL)); aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, gaim_directim_incoming, 0); @@ -4774,7 +4775,7 @@ double percent; struct gaim_connection *gc = sess->aux_data; struct oscar_data *od = (struct oscar_data *)gc->proto_data; - struct conversation *c; + struct gaim_conversation *c; struct direct_im *dim; va_start(ap, fr); @@ -4791,8 +4792,8 @@ while (gtk_events_pending()) gtk_main_iteration(); - if ((c = find_conversation(sn))) - update_progress(c, percent); + if ((c = gaim_find_conversation(sn))) + gaim_conversation_update_progress(c, percent); dim->watcher = gaim_input_add(dim->conn->fd, GAIM_INPUT_READ, oscar_callback, dim->conn); diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/protocols/toc/toc.c --- a/src/protocols/toc/toc.c Mon Jan 20 07:00:10 2003 +0000 +++ b/src/protocols/toc/toc.c Mon Jan 20 09:10:23 2003 +0000 @@ -745,14 +745,17 @@ int id; char *in, *buddy; GSList *bcs = gc->buddy_chats; - struct conversation *b = NULL; + struct gaim_conversation *b = NULL; + struct gaim_chat *chat; sscanf(strtok(NULL, ":"), "%d", &id); in = strtok(NULL, ":"); + chat = GAIM_CHAT(b); + while (bcs) { - b = (struct conversation *)bcs->data; - if (id == b->id) + b = (struct gaim_conversation *)bcs->data; + if (id == gaim_chat_get_id(chat)) break; bcs = bcs->next; b = NULL; @@ -763,10 +766,10 @@ if (in && (*in == 'T')) while ((buddy = strtok(NULL, ":")) != NULL) - add_chat_buddy(b, buddy, NULL); + gaim_chat_add_user(chat, buddy, NULL); else while ((buddy = strtok(NULL, ":")) != NULL) - remove_chat_buddy(b, buddy, NULL); + gaim_chat_remove_user(chat, buddy, NULL); } else if (!strcasecmp(c, "CHAT_INVITE")) { char *name, *who, *message; int *id = g_new0(int, 1); @@ -779,14 +782,14 @@ serv_got_chat_invite(gc, name, who, message, g_list_append(NULL, id)); } else if (!strcasecmp(c, "CHAT_LEFT")) { GSList *bcs = gc->buddy_chats; - struct conversation *b = NULL; + struct gaim_conversation *b = NULL; int id; sscanf(strtok(NULL, ":"), "%d", &id); while (bcs) { - b = (struct conversation *)bcs->data; - if (id == b->id) + b = (struct gaim_conversation *)bcs->data; + if (id == gaim_chat_get_id(GAIM_CHAT(b))) break; b = NULL; bcs = bcs->next; @@ -797,7 +800,7 @@ if (b->window) { char error_buf[BUF_LONG]; - b->gc = NULL; + gaim_conversation_set_user(b, NULL); g_snprintf(error_buf, sizeof error_buf, _("You have been disconnected" " from chat room %s."), b->name); do_error_dialog(error_buf, NULL, GAIM_ERROR); @@ -1183,12 +1186,12 @@ static void toc_chat_leave(struct gaim_connection *g, int id) { GSList *bcs = g->buddy_chats; - struct conversation *b = NULL; + struct gaim_conversation *b = NULL; char buf[BUF_LEN * 2]; while (bcs) { - b = (struct conversation *)bcs->data; - if (id == b->id) + b = (struct gaim_conversation *)bcs->data; + if (id == gaim_chat_get_id(GAIM_CHAT(b))) break; b = NULL; bcs = bcs->next; @@ -1197,8 +1200,10 @@ if (!b) return; /* can this happen? */ - if (!b->gc) /* TOC already kicked us out of this room */ + if (gaim_conversation_get_user(b) == NULL) { + /* TOC already kicked us out of this room */ serv_got_chat_left(g, id); + } else { g_snprintf(buf, 255, "toc_chat_leave %d", id); sflap_send(g, buf, -1, TYPE_DATA); diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/prpl.c --- a/src/prpl.c Mon Jan 20 07:00:10 2003 +0000 +++ b/src/prpl.c Mon Jan 20 09:10:23 2003 +0000 @@ -553,6 +553,7 @@ void set_icon_data(struct gaim_connection *gc, char *who, void *data, int len) { + struct gaim_conversation *conv; struct icon_data tmp; GList *l; struct icon_data *id; @@ -585,7 +586,11 @@ id->data = g_memdup(data, len); id->len = len; - got_new_icon(gc, who); + /* Update the buddy icon for this user. */ + conv = gaim_find_conversation(who); + + if (conv != NULL && gaim_conversation_get_gc(conv) == gc) + gaim_gtkconv_update_buddy_icon(conv); } void remove_icon_data(struct gaim_connection *gc) diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/server.c --- a/src/server.c Mon Jan 20 07:00:10 2003 +0000 +++ b/src/server.c Mon Jan 20 09:10:23 2003 +0000 @@ -90,10 +90,13 @@ { struct prpl *prpl; while (gc->buddy_chats) { - struct conversation *b = gc->buddy_chats->data; + struct gaim_conversation *b = gc->buddy_chats->data; + gc->buddy_chats = g_slist_remove(gc->buddy_chats, b); - b->gc = NULL; - update_buttons_by_protocol(b); + + /* TODO: Nuke the UI-specific code here. */ + if (gaim_conversation_get_ops(b) == gaim_get_gtk_conversation_ops()) + gaim_gtkconv_update_buttons_by_protocol(b); } if (gc->idle_timer > 0) @@ -162,10 +165,14 @@ struct queued_away_response *find_queued_away_response_by_name(char *name); -int serv_send_im(struct gaim_connection *gc, char *name, char *message, int len, int flags) +int serv_send_im(struct gaim_connection *gc, char *name, char *message, + int len, int flags) { + struct gaim_conversation *c; int val = -EINVAL; - struct conversation *cnv = find_conversation(name); + + c = gaim_find_conversation(name); + if (gc->prpl && gc->prpl->send_im) val = gc->prpl->send_im(gc, name, message, len, flags); @@ -187,8 +194,8 @@ qar->sent_away = t; } - if (cnv && cnv->type_again_timeout) - g_source_remove(cnv->type_again_timeout); + if (c && gaim_im_get_type_again_timeout(GAIM_IM(c))) + gaim_im_stop_type_again_timeout(GAIM_IM(c)); return val; } @@ -211,18 +218,24 @@ g->prpl->get_dir(g, name); } -void serv_set_dir(struct gaim_connection *g, const char *first, const char *middle, const char *last, const char *maiden, - const char *city, const char *state, const char *country, int web) +void serv_set_dir(struct gaim_connection *g, const char *first, + const char *middle, const char *last, const char *maiden, + const char *city, const char *state, const char *country, + int web) { if (g && g_slist_find(connections, g) && g->prpl && g->prpl->set_dir) - g->prpl->set_dir(g, first, middle, last, maiden, city, state, country, web); + g->prpl->set_dir(g, first, middle, last, maiden, city, state, + country, web); } -void serv_dir_search(struct gaim_connection *g, const char *first, const char *middle, const char *last, const char *maiden, - const char *city, const char *state, const char *country, const char *email) +void serv_dir_search(struct gaim_connection *g, const char *first, + const char *middle, const char *last, const char *maiden, + const char *city, const char *state, const char *country, + const char *email) { if (g && g_slist_find(connections, g) && g->prpl && g->prpl->dir_search) - g->prpl->dir_search(g, first, middle, last, maiden, city, state, country, email); + g->prpl->dir_search(g, first, middle, last, maiden, city, state, + country, email); } @@ -532,39 +545,47 @@ return NULL; } -/* woo. i'm actually going to comment this function. isn't that fun. make sure to follow along, kids */ -void serv_got_im(struct gaim_connection *gc, char *name, char *message, guint32 flags, time_t mtime, gint len) +/* + * woo. i'm actually going to comment this function. isn't that fun. make + * sure to follow along, kids + */ +void serv_got_im(struct gaim_connection *gc, char *name, char *message, + guint32 flags, time_t mtime, gint len) { char *buffy; char *angel; int plugin_return; int away = 0; - struct conversation *cnv; - int new_conv = 0; + struct gaim_conversation *cnv; - /* pay no attention to the man behind the curtain. + /* + * Pay no attention to the man behind the curtain. * - * the reason i feel okay with this is because it's useful to some plugins. - * Gaim doesn't ever use it itself. Besides, it's not entirely accurate; it's - * possible to have false negatives with most protocols. Also with some it's - * easy to have false positives as well. So if you're a plugin author, don't - * rely on this, still do your own checks. but uh. it's a start. */ + * The reason i feel okay with this is because it's useful to some + * plugins. Gaim doesn't ever use it itself. Besides, it's not entirely + * accurate; it's possible to have false negatives with most protocols. + * Also with some it's easy to have false positives as well. So if you're + * a plugin author, don't rely on this, still do your own checks. But uh. + * It's a start. + */ + if (flags & IM_FLAG_GAIMUSER) debug_printf("%s is a gaim user.\n", name); - /* we should update the conversation window buttons and menu, if it exists. */ - cnv = find_conversation(name); - if (cnv) - set_convo_gc(cnv, gc); - /* we do the new_conv check here in case any plugins decide to create it */ - else - new_conv = 1; + /* + * We should update the conversation window buttons and menu, + * if it exists. + */ + cnv = gaim_find_conversation_with_user(name, gc->user); - /* plugin stuff. we pass a char ** but we don't want to pass what's been given us - * by the prpls. so we create temp holders and pass those instead. it's basically - * just to avoid segfaults. of course, if the data is binary, plugins don't see it. - * bitch all you want; i really don't want you to be dealing with it. */ + /* + * Plugin stuff. we pass a char ** but we don't want to pass what's + * been given us by the prpls. So we create temp holders and pass + * those instead. It's basically just to avoid segfaults. Of course, + * if the data is binary, plugins don't see it. Bitch all you want; + * I really don't want you to be dealing with it. + */ if (len < 0) { buffy = g_malloc(MAX(strlen(message) + 1, BUF_LONG)); strcpy(buffy, message); @@ -586,10 +607,15 @@ } #if 0 - /* TiK, using TOC, sends an automated message in order to get your away message. Now, - * this is one of the biggest hacks I think I've seen. But, in order to be nice to - * TiK, we're going to give users the option to ignore it. */ - if ((away_options & OPT_AWAY_TIK_HACK) && gc->away && strlen(gc->away) && (len < 0) && + /* + * TiK, using TOC, sends an automated message in order to get your + * away message. Now, this is one of the biggest hacks I think I've + * seen. But, in order to be nice to TiK, we're going to give users + * the option to ignore it. + */ + if ((away_options & OPT_AWAY_TIK_HACK) && gc->away && + strlen(gc->away) && (len < 0) && + !strcmp(message, ">>>Automated Message: Getting Away Message<<<")) { char *tmpmsg = stylize(awaymessage->message, MSG_LEN); serv_send_im(gc, name, tmpmsg, -1, IM_FLAG_AWAY); @@ -600,20 +626,28 @@ } #endif - /* if you can't figure this out, stop reading right now. - * "we're not worthy! we're not worthy!" */ + /* + * If you can't figure this out, stop reading right now. + * "We're not worthy! We're not worthy!" + */ if ((len < 0) && (convo_options & OPT_CONVO_SEND_LINKS)) linkify_text(message); - /* um. when we call write_to_conv with the message we received, it's nice to pass whether - * or not it was an auto-response. so if it was an auto-response, we set the appropriate - * flag. this is just so prpls don't have to know about WFLAG_* (though some do anyway) */ + /* + * Um. When we call gaim_conversation_write with the message we received, + * it's nice to pass whether or not it was an auto-response. So if it + * was an auto-response, we set the appropriate flag. This is just so + * prpls don't have to know about WFLAG_* (though some do anyway) + */ if (flags & IM_FLAG_AWAY) away = WFLAG_AUTO; - /* alright. two cases for how to handle this. either we're away or we're not. if we're not, - * then it's easy. if we are, then there are three or four different ways of handling it - * and different things we have to do for each. */ + /* + * Alright. Two cases for how to handle this. Either we're away or + * we're not. If we're not, then it's easy. If we are, then there + * are three or four different ways of handling it and different + * things we have to do for each. + */ if (gc->away) { time_t t; char *tmpmsg; @@ -624,15 +658,22 @@ time(&t); - /* either we're going to queue it or not. Because of the way awayness currently - * works, this is fucked up. it's possible for an account to be away without the - * imaway dialog being shown. in fact, it's possible for *all* the accounts to be - * away without the imaway dialog being shown. so in order for this to be queued - * properly, we have to make sure that the imaway dialog actually exists, first. */ + /* + * Either we're going to queue it or not. Because of the way + * awayness currently works, this is fucked up. It's possible + * for an account to be away without the imaway dialog being + * shown. In fact, it's possible for *all* the accounts to be + * away without the imaway dialog being shown. So in order for + * this to be queued properly, we have to make sure that the + * imaway dialog actually exists, first. + */ if (!cnv && clistqueue && (away_options & OPT_AWAY_QUEUE)) { - /* alright, so we're going to queue it. neat, eh? :) so first we create - * something to store the message, and add it to our queue. Then we update - * the away dialog to indicate that we've queued something. */ + /* + * Alright, so we're going to queue it. Neat, eh? :) + * So first we create something to store the message, and add + * it to our queue. Then we update the away dialog to indicate + * that we've queued something. + */ struct queued_message *qm; qm = g_new0(struct queued_message, 1); @@ -661,50 +702,62 @@ gtk_clist_append(GTK_CLIST(clistqueue), heh); } } else { - /* ok, so we're not queuing it. well then, we'll try to handle it normally. - * Some people think that ignoring it is a perfectly acceptible way to handle - * it. i think they're on crack, but hey, that's why it's optional. */ + /* + * Ok, so we're not queuing it. Well then, we'll try to handle + * it normally. Some people think that ignoring it is a perfectly + * acceptible way to handle it. I think they're on crack, but + * hey, that's why it's optional. + */ if (away_options & OPT_AWAY_DISCARD) { g_free(name); g_free(message); return; } - /* ok, so we're not ignoring it. make sure the conversation exists and is - * updated (partly handled above already), play the receive sound (sound.c - * will take care of not playing while away), and then write it to the - * convo window. */ + /* + * Ok, so we're not ignoring it. Make sure the conversation + * exists and is updated (partly handled above already), play + * the receive sound (sound.c will take care of not playing + * while away), and then write it to the convo window. + */ if (cnv == NULL) { - cnv = new_conversation(name); - set_convo_gc(cnv, gc); + cnv = gaim_conversation_new(GAIM_CONV_IM, name); + gaim_conversation_set_user(cnv, gc->user); } - if (new_conv && (sound_options & OPT_SOUND_FIRST_RCV)) - play_sound(SND_FIRST_RECEIVE); - else if (cnv->makesound) - play_sound(SND_RECEIVE); - write_to_conv(cnv, message, away | WFLAG_RECV, NULL, mtime, len); + gaim_im_write(GAIM_IM(cnv), NULL, message, len, + away | WFLAG_RECV, mtime); } - /* regardless of whether we queue it or not, we should send an auto-response. - * that is, of course, unless the horse.... no wait. don't autorespond if: + /* + * Regardless of whether we queue it or not, we should send an + * auto-response. That is, of course, unless the horse.... no wait. + * Don't autorespond if: + * * - it's not supported on this connection * - or it's disabled * - or the away message is empty - * - or we're not idle and the 'only auto respond if idle' pref is set + * - or we're not idle and the 'only auto respond if idle' pref + * is set */ - if (!(gc->flags & OPT_CONN_AUTO_RESP) || (away_options & OPT_AWAY_NO_AUTO_RESP) || - !strlen(gc->away) || ((away_options & OPT_AWAY_IDLE_RESP) && !gc->is_idle)) { + if (!(gc->flags & OPT_CONN_AUTO_RESP) || + (away_options & OPT_AWAY_NO_AUTO_RESP) || !strlen(gc->away) || + ((away_options & OPT_AWAY_IDLE_RESP) && !gc->is_idle)) { + g_free(name); g_free(message); return; } - /* this used to be based on the conversation window. but um, if you went away, and - * someone sent you a message and got your auto-response, and then you closed the - * window, and then the sent you another one, they'd get the auto-response back - * too soon. besides that, we need to keep track of this even if we've got a queue. - * so the rest of this block is just the auto-response, if necessary */ + /* + * This used to be based on the conversation window. But um, if + * you went away, and someone sent you a message and got your + * auto-response, and then you closed the window, and then the + * sent you another one, they'd get the auto-response back too + * soon. Besides that, we need to keep track of this even if we've + * got a queue. So the rest of this block is just the auto-response, + * if necessary + */ qar = find_queued_away_response_by_name(name); if (!qar) { qar = (struct queued_away_response *)g_new0(struct queued_away_response, 1); @@ -733,22 +786,24 @@ qm->len = -1; message_queue = g_slist_append(message_queue, qm); } else if (cnv != NULL) - write_to_conv(cnv, away_subs(tmpmsg, alias), WFLAG_SEND | WFLAG_AUTO, NULL, - mtime, len); + gaim_im_write(GAIM_IM(cnv), NULL, away_subs(tmpmsg, alias), + len, WFLAG_SEND | WFLAG_AUTO, mtime); + g_free(tmpmsg); } else { - /* we're not away. this is easy. if the convo window doesn't exist, create and update - * it (if it does exist it was updated earlier), then play a sound indicating we've - * received it and then display it. easy. */ - - if (new_conv && (sound_options & OPT_SOUND_FIRST_RCV)) - play_sound(SND_FIRST_RECEIVE); - else if (new_conv || cnv->makesound) - play_sound(SND_RECEIVE); - - if (away_options & OPT_AWAY_QUEUE_UNREAD && !find_conversation(name) && docklet_count) { - /* We're gonna queue it up and wait for the user to ask for it... probably - * by clicking the docklet or windows tray icon. */ + /* + * We're not away. This is easy. If the convo window doesn't + * exist, create and update it (if it does exist it was updated + * earlier), then play a sound indicating we've received it and + * then display it. Easy. + */ + if (away_options & OPT_AWAY_QUEUE_UNREAD && + !gaim_find_conversation(name) && docklet_count) { + + /* + * We're gonna queue it up and wait for the user to ask for + * it... probably by clicking the docklet or windows tray icon. + */ struct queued_message *qm; qm = g_new0(struct queued_message, 1); g_snprintf(qm->name, sizeof(qm->name), "%s", name); @@ -760,18 +815,18 @@ unread_message_queue = g_slist_append(unread_message_queue, qm); } else { if (cnv == NULL) { - cnv = new_conversation(name); - set_convo_gc(cnv, gc); + cnv = gaim_conversation_new(GAIM_CONV_IM, name); + gaim_conversation_set_user(cnv, gc->user); } - - set_convo_name(cnv, name); - - write_to_conv(cnv, message, away | WFLAG_RECV, NULL, mtime, len); -#ifdef _WIN32 - wgaim_im_blink(cnv->window); -#endif + + /* CONV XXX gaim_conversation_set_name(cnv, name); */ + + gaim_im_write(GAIM_IM(cnv), NULL, message, len, + away | WFLAG_RECV, mtime); + gaim_window_flash(gaim_conversation_get_window(cnv)); } } + plugin_event(event_im_displayed_rcvd, gc, name, message, flags, mtime); g_free(name); g_free(message); @@ -779,8 +834,8 @@ -void serv_got_update(struct gaim_connection *gc, char *name, int loggedin, int evil, time_t signon, - time_t idle, int type, guint caps) +void serv_got_update(struct gaim_connection *gc, char *name, int loggedin, + int evil, time_t signon, time_t idle, int type, guint caps) { struct buddy *b = find_buddy(gc->user, name); @@ -870,39 +925,50 @@ gc->evil = lev; - g_snprintf(buf2, sizeof(buf2), _("%s has just been warned by %s.\nYour new warning level is %d%%"), - gc->username, ((name == NULL)? _("an anonymous person") : name), lev); + g_snprintf(buf2, sizeof(buf2), + _("%s has just been warned by %s.\n" + "Your new warning level is %d%%"), + gc->username, + ((name == NULL)? _("an anonymous person") : name), lev); do_error_dialog(buf2, NULL, GAIM_INFO); } -void serv_got_typing(struct gaim_connection *gc, char *name, int timeout, int state) { - struct conversation *cnv = find_conversation(name); - if (cnv) { - set_convo_gc(cnv, gc); - cnv->typing_state = state; - update_convo_status(cnv); - } else return; - plugin_event(event_got_typing, gc, name); - do_pounce(gc, name, OPT_POUNCE_TYPING); - if (timeout > 0) { - if (cnv->typing_timeout) - g_source_remove (cnv->typing_timeout); - cnv->typing_timeout = g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE, - timeout * 1000, reset_typing, g_strdup(name), g_free); - } +void serv_got_typing(struct gaim_connection *gc, char *name, int timeout, + int state) { + + struct gaim_conversation *cnv = gaim_find_conversation(name); + struct gaim_im *im; + + if (!cnv) + return; + + im = GAIM_IM(cnv); + + gaim_conversation_set_user(cnv, gc->user); + gaim_im_set_typing_state(im, state); + gaim_im_update_typing(im); + + plugin_event(event_got_typing, gc, name); + do_pounce(gc, name, OPT_POUNCE_TYPING); + + if (timeout > 0) + gaim_im_start_typing_timeout(im, timeout); } void serv_got_typing_stopped(struct gaim_connection *gc, char *name) { - struct conversation *c = find_conversation(name); - if(!c) + + struct gaim_conversation *c = gaim_find_conversation(name); + struct gaim_im *im; + + if (!c) return; - if (c->typing_timeout) { - g_source_remove(c->typing_timeout); - c->typing_timeout=0; - } - c->typing_state = NOT_TYPING; - update_convo_status(c); + + im = GAIM_IM(c); + + gaim_im_stop_typing_timeout(im); + gaim_im_set_typing_state(im, NOT_TYPING); + gaim_im_update_typing(im); } static void close_invite(GtkWidget *w, GtkWidget *w2) @@ -945,7 +1011,8 @@ -void serv_got_chat_invite(struct gaim_connection *g, char *name, char *who, char *message, GList *data) +void serv_got_chat_invite(struct gaim_connection *g, char *name, + char *who, char *message, GList *data) { GtkWidget *d; GtkWidget *label; @@ -958,11 +1025,13 @@ plugin_event(event_chat_invited, g, who, name, message); if (message) - g_snprintf(buf2, sizeof(buf2), _("User '%s' invites %s to buddy chat room: '%s'\n%s"), who, - g->username, name, message); + g_snprintf(buf2, sizeof(buf2), + _("User '%s' invites %s to buddy chat room: '%s'\n%s"), + who, g->username, name, message); else - g_snprintf(buf2, sizeof(buf2), _("User '%s' invites %s to buddy chat room: '%s'\n"), who, - g->username, name); + g_snprintf(buf2, sizeof(buf2), + _("User '%s' invites %s to buddy chat room: '%s'\n"), + who, g->username, name); d = gtk_dialog_new(); gtk_widget_realize(d); @@ -982,38 +1051,39 @@ gtk_window_set_title(GTK_WINDOW(d), _("Buddy chat invite")); - g_signal_connect(GTK_OBJECT(nobtn), "clicked", G_CALLBACK(close_invite), d); - g_signal_connect(GTK_OBJECT(yesbtn), "clicked", G_CALLBACK(chat_invite_callback), d); - + g_signal_connect(G_OBJECT(nobtn), "clicked", + G_CALLBACK(close_invite), d); + g_signal_connect(G_OBJECT(yesbtn), "clicked", + G_CALLBACK(chat_invite_callback), d); gtk_widget_show(d); } -struct conversation *serv_got_joined_chat(struct gaim_connection *gc, int id, char *name) +struct gaim_conversation *serv_got_joined_chat(struct gaim_connection *gc, + int id, char *name) { - struct conversation *b; + struct gaim_conversation *b; + struct gaim_chat *chat; - b = (struct conversation *)g_new0(struct conversation, 1); - gc->buddy_chats = g_slist_append(gc->buddy_chats, b); - chats = g_list_append(chats, b); + b = gaim_conversation_new(GAIM_CONV_CHAT, name); + chat = GAIM_CHAT(b); - b->is_chat = TRUE; - b->ignored = NULL; - b->in_room = NULL; - b->id = id; - b->gc = gc; - b->send_history = g_list_append(NULL, NULL); - b->history = g_string_new(""); - g_snprintf(b->name, 80, "%s", name); + gc->buddy_chats = g_slist_append(gc->buddy_chats, b); + + gaim_chat_set_id(chat, id); + gaim_conversation_set_user(b, gc->user); - if ((logging_options & OPT_LOG_CHATS) || find_log_info(b->name)) { + if ((logging_options & OPT_LOG_CHATS) || + find_log_info(gaim_conversation_get_name(b))) { + FILE *fd; char *filename; filename = (char *)malloc(100); - g_snprintf(filename, 100, "%s.chat", b->name); + g_snprintf(filename, 100, "%s.chat", gaim_conversation_get_name(b)); - fd = open_log_file(filename, b->is_chat); + fd = open_log_file(filename, TRUE); + if (fd) { if (!(logging_options & OPT_LOG_STRIP_HTML)) fprintf(fd, @@ -1027,7 +1097,9 @@ free(filename); } - show_new_buddy_chat(b); + gaim_window_show(gaim_conversation_get_window(b)); + gaim_window_switch_conversation(gaim_conversation_get_window(b), + gaim_conversation_get_index(b)); plugin_event(event_chat_join, gc, id, name); @@ -1036,62 +1108,71 @@ void serv_got_chat_left(struct gaim_connection *g, int id) { - GSList *bcs = g->buddy_chats; - struct conversation *b = NULL; + GSList *bcs; + struct gaim_conversation *conv = NULL; + struct gaim_chat *chat = NULL; + for (bcs = g->buddy_chats; bcs != NULL; bcs = bcs->next) { + conv = (struct gaim_conversation *)bcs->data; - while (bcs) { - b = (struct conversation *)bcs->data; - if (id == b->id) { + chat = GAIM_CHAT(conv); + + if (gaim_chat_get_id(chat) == id) break; - } - b = NULL; - bcs = bcs->next; + + conv = NULL; } - if (!b) + if (!conv) return; - plugin_event(event_chat_leave, g, b->id); + plugin_event(event_chat_leave, g, gaim_chat_get_id(chat)); - debug_printf("Leaving room %s.\n", b->name); + debug_printf("Leaving room %s.\n", gaim_conversation_get_name(conv)); - g->buddy_chats = g_slist_remove(g->buddy_chats, b); + g->buddy_chats = g_slist_remove(g->buddy_chats, conv); - delete_chat(b); + gaim_conversation_destroy(conv); } -void serv_got_chat_in(struct gaim_connection *g, int id, char *who, int whisper, char *message, - time_t mtime) +void serv_got_chat_in(struct gaim_connection *g, int id, char *who, + int whisper, char *message, time_t mtime) { int w; - GSList *bcs = g->buddy_chats; - struct conversation *b = NULL; + GSList *bcs; + struct gaim_conversation *conv = NULL; + struct gaim_chat *chat = NULL; char *buf; char *buffy, *angel; int plugin_return; - while (bcs) { - b = (struct conversation *)bcs->data; - if (id == b->id) + for (bcs = g->buddy_chats; bcs != NULL; bcs = bcs->next) { + conv = (struct gaim_conversation *)bcs->data; + + chat = GAIM_CHAT(conv); + + if (gaim_chat_get_id(chat) == id) break; - bcs = bcs->next; - b = NULL; + conv = NULL; } - if (!b) + + if (!conv) return; - - /* plugin stuff. we pass a char ** but we don't want to pass what's been given us - * by the prpls. so we create temp holders and pass those instead. it's basically - * just to avoid segfaults. of course, if the data is binary, plugins don't see it. - * bitch all you want; i really don't want you to be dealing with it. */ - + /* + * Plugin stuff. We pass a char ** but we don't want to pass what's + * been given us by the prpls. so we create temp holders and pass those + * instead. It's basically just to avoid segfaults. Of course, if the + * data is binary, plugins don't see it. Bitch all you want; i really + * don't want you to be dealing with it. + */ + buffy = g_malloc(MAX(strlen(message) + 1, BUF_LONG)); strcpy(buffy, message); angel = g_strdup(who); - plugin_return = plugin_event(event_chat_recv, g, b->id, &angel, &buffy); + plugin_return = plugin_event(event_chat_recv, g, gaim_chat_get_id(chat), + &angel, &buffy); if (!buffy || !angel || plugin_return) { if (buffy) @@ -1114,7 +1195,8 @@ else w = 0; - chat_write(b, who, w, buf, mtime); + gaim_chat_write(chat, who, buf, w, mtime); + g_free(who); g_free(message); g_free(buf); diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/stock.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/stock.c Mon Jan 20 09:10:23 2003 +0000 @@ -0,0 +1,119 @@ +/** + * @file stock.c GTK+ Stock resources + * + * gaim + * + * Copyright (C) 2002-2003, Christian Hammond + * + * 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 + * + */ +#include "stock.h" +#include "core.h" +#include +#include + +static struct StockIcon +{ + const char *name; + const char *dir; + const char *filename; + +} const stock_icons[] = +{ + { GAIM_STOCK_BGCOLOR, "buttons", "change-bgcolor-small.png" }, + { GAIM_STOCK_BLOCK, NULL, GTK_STOCK_STOP }, + { GAIM_STOCK_FGCOLOR, "buttons", "change-fgcolor-small.png" }, + { GAIM_STOCK_IGNORE, NULL, GTK_STOCK_DIALOG_ERROR }, + { GAIM_STOCK_IMAGE, "menus", "insert-image-small.png" }, + { GAIM_STOCK_INFO, NULL, GTK_STOCK_FIND }, + { GAIM_STOCK_INVITE, NULL, GTK_STOCK_JUMP_TO }, + { GAIM_STOCK_LINK, "menus", "insert-link-small.png" }, + { GAIM_STOCK_SEND, NULL, GTK_STOCK_CONVERT }, + { GAIM_STOCK_SMILEY, "buttons", "insert-smiley-small.png" }, + { GAIM_STOCK_TEXT_BIGGER, "buttons", "text_bigger.png" }, + { GAIM_STOCK_TEXT_NORMAL, "buttons", "text_normal.png" }, + { GAIM_STOCK_TEXT_SMALLER, "buttons", "text_smaller.png" }, + { GAIM_STOCK_WARN, NULL, GTK_STOCK_DIALOG_WARNING } +}; + +static gint stock_icon_count = sizeof(stock_icons) / sizeof(*stock_icons); + +static gchar * +find_file(const char *dir, const char *base) +{ + char *filename; + + if (base == NULL) + return NULL; + + if (!strcmp(dir, "gaim")) + filename = g_build_filename(DATADIR, "pixmaps", "gaim", base, NULL); + else + filename = g_build_filename(DATADIR, "pixmaps", "gaim", + dir, base, NULL); + + if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { + debug_printf("Unable to load stock pixmap %s\n", base); + + g_free(filename); + + return NULL; + } + + return filename; +} + +void +setup_stock() +{ + GtkIconFactory *icon_factory; + int i; + + /* Setup the icon factory. */ + icon_factory = gtk_icon_factory_new(); + + gtk_icon_factory_add_default(icon_factory); + + for (i = 0; i < stock_icon_count; i++) { + GdkPixbuf *pixbuf; + GtkIconSet *iconset; + gchar *filename; + + if (stock_icons[i].dir == NULL) { + /* GTK+ Stock icon */ + + iconset = gtk_icon_factory_lookup_default(stock_icons[i].filename); + } + else { + filename = find_file(stock_icons[i].dir, stock_icons[i].filename); + + if (filename == NULL) + continue; + + pixbuf = gdk_pixbuf_new_from_file(filename, NULL); + + g_free(filename); + + iconset = gtk_icon_set_new_from_pixbuf(pixbuf); + } + + gtk_icon_factory_add(icon_factory, stock_icons[i].name, iconset); + + gtk_icon_set_unref(iconset); + } + + g_object_unref(G_OBJECT(icon_factory)); +} diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/stock.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/stock.h Mon Jan 20 09:10:23 2003 +0000 @@ -0,0 +1,51 @@ +/** + * @file stock.h GTK+ Stock resources + * + * gaim + * + * Copyright (C) 2002-2003, Christian Hammond + * + * 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 _STOCK_H_ +#define _STOCK_H_ + +/**************************************************************************/ +/** @name Stock images */ +/**************************************************************************/ +/*@{*/ +#define GAIM_STOCK_BGCOLOR "gaim-bgcolor" +#define GAIM_STOCK_BLOCK "gaim-block" +#define GAIM_STOCK_FGCOLOR "gaim-fgcolor" +#define GAIM_STOCK_IGNORE "gaim-ignore" +#define GAIM_STOCK_IMAGE "gaim-image" +#define GAIM_STOCK_INFO "gaim-info" +#define GAIM_STOCK_INVITE "gaim-invite" +#define GAIM_STOCK_LINK "gaim-link" +#define GAIM_STOCK_SEND "gaim-send" +#define GAIM_STOCK_SMILEY "gaim-smiley" +#define GAIM_STOCK_TEXT_BIGGER "gaim-text-bigger" +#define GAIM_STOCK_TEXT_NORMAL "gaim-text-normal" +#define GAIM_STOCK_TEXT_SMALLER "gaim-text-smaller" +#define GAIM_STOCK_WARN "gaim-warn" +/*@}*/ + +/** + * Sets up the gaim stock repository. + */ +void setup_stock(void); + +#endif /* _STOCK_H_ */ diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/themes.c --- a/src/themes.c Mon Jan 20 07:00:10 2003 +0000 +++ b/src/themes.c Mon Jan 20 09:10:23 2003 +0000 @@ -179,20 +179,17 @@ } if (load) { - GList *cnv = conversations; - while (cnv) { - struct conversation *c = cnv->data; - smiley_themeize(c->text); - cnv=cnv->next; - } + GList *cnv; + + for (cnv = conversations; cnv != NULL; cnv = cnv->next) { + struct gaim_conversation *conv = cnv->data; + + if (gaim_conversation_get_ops(conv) == + gaim_get_gtk_conversation_ops()) { - cnv = chats; - while (cnv) { - struct conversation *c = cnv->data; - smiley_themeize(c->text); - cnv=cnv->next; + smiley_themeize(GAIM_GTK_CONVERSATION(conv)->imhtml); + } } - } g_free(dirname); diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/ui.h --- a/src/ui.h Mon Jan 20 07:00:10 2003 +0000 +++ b/src/ui.h Mon Jan 20 09:10:23 2003 +0000 @@ -29,6 +29,10 @@ #include #include +#include "gtkconv.h" +#include "gtkutils.h" +#include "stock.h" + #define GAIM_DIALOG(x) x = gtk_window_new(GTK_WINDOW_TOPLEVEL); \ gtk_window_set_type_hint(GTK_WINDOW(x), GDK_WINDOW_TYPE_HINT_DIALOG) #define GAIM_WINDOW_ICONIFIED(x) (gdk_window_get_state(GTK_WIDGET(x)->window) & GDK_WINDOW_STATE_ICONIFIED) @@ -94,7 +98,8 @@ }; /* struct buddy_chat went away and got merged with this. */ -struct conversation { +#if 0 +struct gaim_conversation { struct gaim_connection *gc; /* stuff used for both IM and chat */ @@ -187,6 +192,7 @@ GtkWidget *tab_label; }; +#endif struct log_conversation { char name[80]; @@ -300,12 +306,16 @@ extern int docklet_count; /* Globals in buddy_chat.c */ +#if 0 extern GList *chats; /* list of all chats (only use for tabbing!) */ extern GtkWidget *all_chats; extern GtkWidget *joinchat; +#endif /* Globals in conversation.c */ +#if 0 extern GtkWidget *all_convos; +#endif /* Globals in dialog.c */ extern char fontface[128]; @@ -385,51 +395,44 @@ extern void docklet_remove(); extern void docklet_toggle(); extern GtkWidget *gaim_new_item(GtkWidget *, const char *); +extern void update_idle_times(); +extern void build_imchat_box(gboolean); /* Functions in buddy_chat.c */ -extern void join_chat(); -extern void chat_write(struct conversation *, char *, int, char *, time_t); -extern void delete_chat(struct conversation *); -extern void build_imchat_box(gboolean); +#if 0 +extern void chat_write(struct gaim_conversation *, char *, int, char *, time_t); +extern void delete_chat(struct gaim_conversation *); extern void update_chat_button_pix(); extern void update_im_button_pix(); extern void update_chat_tabs(); extern void update_im_tabs(); -extern void update_idle_times(); extern void do_join_chat(); +#endif /* Functions in conversation.c */ -extern void gaim_setup_imhtml(GtkWidget *); -extern void update_convo_add_button(struct conversation *); -extern void raise_convo_tab(struct conversation *); -extern void set_convo_title(struct conversation *); -extern void show_conv(struct conversation *); -void set_convo_name(struct conversation *c, const char *nname); -extern struct conversation *new_conversation(char *); -extern void delete_conversation(struct conversation *); -extern void surround(struct conversation *, char *, char *); +#if 0 +extern void update_convo_add_button(struct gaim_conversation *); +extern void raise_convo_tab(struct gaim_conversation *); +extern void set_convo_title(struct gaim_conversation *); +extern void show_conv(struct gaim_conversation *); +void set_convo_name(struct gaim_conversation *c, const char *nname); +extern struct gaim_conversation *new_conversation(char *); +extern void delete_conversation(struct gaim_conversation *); +extern void surround(struct gaim_conversation *, char *, char *); extern int is_logging(char *); extern void set_state_lock(int); -extern void remove_tags(struct conversation *, char *); +extern void remove_tags(struct gaim_conversation *, char *); extern void update_transparency(); extern void update_font_buttons(); -extern void toggle_sensitive(GtkWidget *widget, GtkWidget *to_toggle); -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 set_font_face(char *, struct conversation *); +extern void set_font_face(char *, struct gaim_conversation *); extern void redo_convo_menus(); extern void convo_menu_remove(struct gaim_connection *); extern void remove_icon_data(struct gaim_connection *); extern void got_new_icon(struct gaim_connection *, char *); extern void toggle_spellchk(); -extern void set_convo_gc(struct conversation *, struct gaim_connection *); -extern void update_buttons_by_protocol(struct conversation *); -extern void toggle_fg_color(GtkWidget *, struct conversation *); +extern void set_convo_gc(struct gaim_conversation *, struct gaim_connection *); +extern void update_buttons_by_protocol(struct gaim_conversation *); +extern void toggle_fg_color(GtkWidget *, struct gaim_conversation *); extern void toggle_smileys(); extern void toggle_timestamps(); extern void update_pixmaps(); @@ -440,10 +443,10 @@ extern void update_convo_font(); extern void set_hide_icons(); extern void set_convo_titles(); -extern void update_progress(struct conversation *, float); -extern void update_convo_status(struct conversation *); -extern gboolean reset_typing(gpointer); +extern void update_progress(struct gaim_conversation *, float); +extern void update_convo_status(struct gaim_conversation *); extern void set_anim(); +#endif /* Functions in dialogs.c */ extern void alias_dialog_bud(struct buddy *); @@ -460,22 +463,22 @@ extern void conv_show_log(GtkWidget *, gpointer); extern void chat_show_log(GtkWidget *, gpointer); extern void show_log(char *); -extern void show_log_dialog(struct conversation *); -extern void show_fgcolor_dialog(struct conversation *c, GtkWidget *color); -extern void show_bgcolor_dialog(struct conversation *c, GtkWidget *color); -extern void cancel_fgcolor(GtkWidget *widget, struct conversation *c); -extern void cancel_bgcolor(GtkWidget *widget, struct conversation *c); +extern void show_log_dialog(struct gaim_conversation *); +extern void show_fgcolor_dialog(struct gaim_conversation *c, GtkWidget *color); +extern void show_bgcolor_dialog(struct gaim_conversation *c, GtkWidget *color); +extern void cancel_fgcolor(GtkWidget *widget, struct gaim_conversation *c); +extern void cancel_bgcolor(GtkWidget *widget, struct gaim_conversation *c); extern void create_away_mess(GtkWidget *, void *); extern void show_ee_dialog(int); -extern void show_insert_link(GtkWidget *,struct conversation *); -extern void show_smiley_dialog(struct conversation *, GtkWidget *); -extern void close_smiley_dialog(GtkWidget *widget, struct conversation *c); +extern void show_insert_link(GtkWidget *,struct gaim_conversation *); +extern void show_smiley_dialog(struct gaim_conversation *, GtkWidget *); +extern void close_smiley_dialog(GtkWidget *widget, struct gaim_conversation *c); extern void set_smiley_array(GtkWidget *widget, int smiley_type); -extern void insert_smiley_text(GtkWidget *widget, struct conversation *c); -extern void cancel_log(GtkWidget *, struct conversation *); -extern void cancel_link(GtkWidget *, struct conversation *); -extern void show_font_dialog(struct conversation *c, GtkWidget *font); -extern void cancel_font(GtkWidget *widget, struct conversation *c); +extern void insert_smiley_text(GtkWidget *widget, struct gaim_conversation *c); +extern void cancel_log(GtkWidget *, struct gaim_conversation *); +extern void cancel_link(GtkWidget *, struct gaim_conversation *); +extern void show_font_dialog(struct gaim_conversation *c, GtkWidget *font); +extern void cancel_font(GtkWidget *widget, struct gaim_conversation *c); extern void apply_font(GtkWidget *widget, GtkFontSelection *fontsel); extern void set_color_selection(GtkWidget *selection, GdkColor color); extern void show_rename_group(GtkWidget *, struct group *); @@ -484,7 +487,7 @@ extern GtkWidget *picture_button(GtkWidget *, char *, char **); extern GtkWidget *picture_button2(GtkWidget *, char *, char **, short); extern GtkWidget *gaim_pixbuf_button(char *, char *, GaimButtonStyle); -extern GtkWidget *gaim_pixbuf_button_from_stock(char *, char *, GaimButtonStyle); +extern GtkWidget *gaim_pixbuf_button_from_stock(const char *, const char *, GaimButtonStyle); extern GtkWidget *gaim_pixbuf_toolbar_button_from_stock(char *); extern GtkWidget *gaim_pixbuf_toolbar_button_from_file(char *); extern int file_is_dir(const char *, GtkWidget *); @@ -493,6 +496,7 @@ extern void build_allow_list(); extern void build_block_list(); extern void destroy_fontsel(GtkWidget *w, gpointer d); +extern void join_chat(); /* Functions in multi.c */ extern void account_editor(GtkWidget *, GtkWidget *); diff -r 2b8abf7f9cc1 -r 5fb47ec9bfe4 src/util.c --- a/src/util.c Mon Jan 20 07:00:10 2003 +0000 +++ b/src/util.c Mon Jan 20 09:10:23 2003 +0000 @@ -972,7 +972,7 @@ /* aim:goim?screenname=screenname&message=message */ if (!g_strncasecmp(uri, "aim:goim?", strlen("aim:goim?"))) { char *who, *what; - struct conversation *c; + struct gaim_conversation *c; uri = uri + strlen("aim:goim?"); if (!(who = strstr(uri, "screenname="))) { @@ -1000,11 +1000,14 @@ g_string_free(str, TRUE); } - c = new_conversation(who); - set_convo_gc(c, gc); + c = gaim_conversation_new(GAIM_CONV_IM, who); + gaim_conversation_set_user(c, gc->user); g_free(who); + if (what) { - gtk_text_buffer_insert_at_cursor(c->entry_buffer, what, -1); + struct gaim_gtk_conversation *gtkconv = GAIM_GTK_CONVERSATION(c); + + gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, what, -1); g_free(what); } } else if (!g_strncasecmp(uri, "aim:addbuddy?", strlen("aim:addbuddy?"))) {