gee
oldstatus
2005-09-19, Nathan Walp
* @file gtkconv.h GTK+ Conversation API * Gaim is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * 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 <gtkspell/gtkspell.h> #include <gdk/gdkkeysyms.h> #include "gtkimhtmltoolbar.h" #define AUTO_RESPONSE "<AUTO-REPLY> : " #define SEND_COLOR "#16569E" #define RECV_COLOR "#A82F2F" static char nick_colors[][8] = { "#ba55d3", /* Medium Orchid */ "#c715b4", /* Medium Violet Red */ "#ff69b4", /* Hot Pink */ "#fa8c00", /* Dark Orange */ "#b22222", /* Fire Brick */ "#f4a460", /* Sandy Brown */ "#cd5c5c", /* Indian Red */ "#bc8f8f", /* Rosy Brown */ "#bdb76b", /* Dark Khaki */ "#228b22", /* Forest Green */ "#9acd32", /* Yellow Green */ "#32cd32", /* Lime Green */ "#3cb371", /* Medium Sea Green (Medium Sea Green?! What are we women?!) */ "#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 */ "#2f4f4f", /* Dark Slate Gray */ "#ff8c00", /* Dark Orange */ "#006400", /* DarkGreen */ "#8b4513", /* SaddleBrown */ #define NUM_NICK_COLORS (sizeof(nick_colors) / sizeof(*nick_colors)) static GtkWidget *invite_dialog = NULL; /* Prototypes. <-- because Paco-Paco hates this comment. */ static void got_typing_keypress(GaimConversation *conv, gboolean first); static GList *generate_invite_user_names(GaimConnection *gc); static void add_chat_buddy_common(GaimConversation *conv, static gboolean tab_complete(GaimConversation *conv); static void update_typing_icon(GaimConversation *conv); static gboolean update_send_as_selection(GaimConvWindow *win); static char *item_factory_translate_func (const char *path, gpointer func_data); /************************************************************************** **************************************************************************/ close_win_cb(GtkWidget *w, GdkEventAny *e, gpointer d) GaimConvWindow *win = (GaimConvWindow *)d; gaim_conv_window_destroy(win); * When a conversation window is focused, we know the user * has looked at it so we know there are no longer unseen focus_win_cb(GtkWidget *w, GdkEventFocus *e, gpointer d) GaimConvWindow *win = (GaimConvWindow *)d; GaimConversation *conv = gaim_conv_window_get_active_conversation(win); gaim_conversation_set_unseen(conv, GAIM_UNSEEN_NONE); close_conv_cb(GtkWidget *w, gpointer d) GaimConversation *conv = (GaimConversation *)d; gaim_conversation_destroy(conv); size_allocate_cb(GtkWidget *w, GtkAllocation *allocation, GaimConversation *conv) GaimGtkConversation *gtkconv; GaimConvWindow *win = gaim_conversation_get_window(conv); if (!GTK_WIDGET_VISIBLE(w)) if (!GAIM_IS_GTK_CONVERSATION(conv)) gtkconv = GAIM_GTK_CONVERSATION(conv); /* we only save the new height if the formatting toolbar visibility matches the pref */ saveheight = (gtkconv->show_formatting_toolbar == gaim_prefs_get_bool("/gaim/gtk/conversations/show_formatting_toolbar")); /* I find that I resize the window when it has a bunch of conversations in it, mostly so that the tab bar * will fit, but then I don't want new windows taking up the entire screen. I check to see if there is only one * conversation in the window. This way we'll be setting new windows to the size of the last resized new window. */ if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) if (w == gtkconv->sw && (gaim_conv_window_get_conversation_count(win) == 1)) gaim_prefs_set_int("/gaim/gtk/conversations/im/default_width", allocation->width); gaim_prefs_set_int("/gaim/gtk/conversations/im/default_height", allocation->height); gaim_prefs_set_int("/gaim/gtk/conversations/im/entry_height", allocation->height); else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) if (w == gtkconv->sw && (gaim_conv_window_get_conversation_count(win) == 1)) gaim_prefs_set_int("/gaim/gtk/conversations/chat/default_width", allocation->width); gaim_prefs_set_int("/gaim/gtk/conversations/chat/default_height", allocation->height); gaim_prefs_set_int("/gaim/gtk/conversations/chat/entry_height", allocation->height); /* Courtesy of Galeon! */ tab_close_button_state_changed_cb(GtkWidget *widget, GtkStateType prev_state) if (GTK_WIDGET_STATE(widget) == GTK_STATE_ACTIVE) gtk_widget_set_state(widget, GTK_STATE_NORMAL); default_formatize(GaimConversation *conv) GaimGtkConversation *c = GAIM_GTK_CONVERSATION(conv); if (conv->features & GAIM_CONNECTION_HTML) if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_formatting")) GdkColor fg_color, bg_color; if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_bold")) gtk_imhtml_toggle_bold(GTK_IMHTML(c->entry)); if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_italic")) gtk_imhtml_toggle_italic(GTK_IMHTML(c->entry)); if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_underline")) gtk_imhtml_toggle_underline(GTK_IMHTML(c->entry)); gtk_imhtml_toggle_fontface(GTK_IMHTML(c->entry), gaim_prefs_get_string("/gaim/gtk/conversations/font_face")); if (!(conv->features & GAIM_CONNECTION_NO_FONTSIZE)) gtk_imhtml_font_set_size(GTK_IMHTML(c->entry), gaim_prefs_get_int("/gaim/gtk/conversations/font_size")); if(strcmp(gaim_prefs_get_string("/gaim/gtk/conversations/fgcolor"), "") != 0) gdk_color_parse(gaim_prefs_get_string("/gaim/gtk/conversations/fgcolor"), color = g_strdup_printf("#%02x%02x%02x", gtk_imhtml_toggle_forecolor(GTK_IMHTML(c->entry), color); if(!(conv->features & GAIM_CONNECTION_NO_BGCOLOR) && strcmp(gaim_prefs_get_string("/gaim/gtk/conversations/bgcolor"), "") != 0) gdk_color_parse(gaim_prefs_get_string("/gaim/gtk/conversations/bgcolor"), color = g_strdup_printf("#%02x%02x%02x", gtk_imhtml_toggle_backcolor(GTK_IMHTML(c->entry), color); if (conv->features & GAIM_CONNECTION_FORMATTING_WBFO) gtk_imhtml_set_whole_buffer_formatting_only(GTK_IMHTML(c->entry), TRUE); gtk_imhtml_set_whole_buffer_formatting_only(GTK_IMHTML(c->entry), FALSE); gaim_gtk_get_cmd_prefix(void) say_command_cb(GaimConversation *conv, const char *cmd, char **args, char **error, void *data) if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) gaim_conv_im_send(GAIM_CONV_IM(conv), args[0]); else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) gaim_conv_chat_send(GAIM_CONV_CHAT(conv), args[0]); me_command_cb(GaimConversation *conv, const char *cmd, char **args, char **error, void *data) tmp = g_strdup_printf("/me %s", args[0]); if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) gaim_conv_im_send(GAIM_CONV_IM(conv), tmp); else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) gaim_conv_chat_send(GAIM_CONV_CHAT(conv), tmp); debug_command_cb(GaimConversation *conv, const char *cmd, char **args, char **error, void *data) if (!g_ascii_strcasecmp(args[0], "version")) { tmp = g_strdup_printf(_("me is using Gaim v%s."), VERSION); markup = gaim_escape_html(tmp); status = gaim_cmd_do_command(conv, tmp, markup, error); gaim_conversation_write(conv, NULL, _("Supported debug options are: version"), GAIM_MESSAGE_NO_LOG|GAIM_MESSAGE_ERROR, time(NULL)); return GAIM_CMD_STATUS_OK; clear_command_cb(GaimConversation *conv, const char *cmd, char **args, char **error, void *data) GaimGtkConversation *gtkconv = NULL; gtkconv = GAIM_GTK_CONVERSATION(conv); gtk_imhtml_clear(GTK_IMHTML(gtkconv->imhtml)); g_string_free(conv->history, TRUE); conv->history = g_string_new(""); return GAIM_CMD_STATUS_OK; help_command_cb(GaimConversation *conv, const char *cmd, char **args, char **error, void *data) text = gaim_cmd_help(conv, args[0]); for (l = text; l; l = l->next) g_string_append_printf(s, "%s\n", (char *)l->data); g_string_append_printf(s, "%s", (char *)l->data); g_string_append(s, _("No such command (in this context).")); s = g_string_new(_("Use \"/help <command>\" for help on a specific command.\n" "The following commands are available in this context:\n")); text = gaim_cmd_list(conv); for (l = text; l; l = l->next) g_string_append_printf(s, "%s, ", (char *)l->data); g_string_append_printf(s, "%s.", (char *)l->data); gaim_conversation_write(conv, NULL, s->str, GAIM_MESSAGE_NO_LOG, time(NULL)); return GAIM_CMD_STATUS_OK; send_history_add(GaimConversation *conv, const char *message) first = g_list_first(conv->send_history); first->data = g_strdup(message); conv->send_history = g_list_prepend(first, NULL); check_for_and_do_command(GaimConversation *conv) GaimGtkConversation *gtkconv; gtkconv = GAIM_GTK_CONVERSATION(conv); account = gaim_conversation_get_account(conv); prefix = gaim_gtk_get_cmd_prefix(); cmd = gtk_imhtml_get_text(GTK_IMHTML(gtkconv->entry), NULL, NULL); gtk_text_buffer_get_start_iter(GTK_IMHTML(gtkconv->entry)->text_buffer, &start); if (cmd && (strncmp(cmd, prefix, strlen(prefix)) == 0) && !gtk_text_iter_get_child_anchor(&start)) { char *error, *cmdline, *markup, *send_history; send_history = gtk_imhtml_get_markup(GTK_IMHTML(gtkconv->entry)); send_history_add(conv, send_history); cmdline = cmd + strlen(prefix); gtk_text_iter_forward_chars(&start, g_utf8_strlen(prefix, -1)); gtk_text_buffer_get_end_iter(GTK_IMHTML(gtkconv->entry)->text_buffer, &end); markup = gtk_imhtml_get_markup_range(GTK_IMHTML(gtkconv->entry), &start, &end); status = gaim_cmd_do_command(conv, cmdline, markup, &error); case GAIM_CMD_STATUS_NOT_FOUND: if (!gaim_prefs_get_bool("/gaim/gtk/conversations/passthrough_unknown_commands")) { gaim_conversation_write(conv, "", _("No such command."), GAIM_MESSAGE_NO_LOG, time(NULL)); case GAIM_CMD_STATUS_WRONG_ARGS: gaim_conversation_write(conv, "", _("Syntax Error: You typed the wrong number of arguments " GAIM_MESSAGE_NO_LOG, time(NULL)); case GAIM_CMD_STATUS_FAILED: gaim_conversation_write(conv, "", error ? error : _("Your command failed for an unknown reason."), GAIM_MESSAGE_NO_LOG, time(NULL)); case GAIM_CMD_STATUS_WRONG_TYPE: if(gaim_conversation_get_type(conv) == GAIM_CONV_IM) gaim_conversation_write(conv, "", _("That command only works in Chats, not IMs."), GAIM_MESSAGE_NO_LOG, time(NULL)); gaim_conversation_write(conv, "", _("That command only works in IMs, not Chats."), GAIM_MESSAGE_NO_LOG, time(NULL)); case GAIM_CMD_STATUS_WRONG_PRPL: gaim_conversation_write(conv, "", _("That command doesn't work on this protocol."), GAIM_MESSAGE_NO_LOG, time(NULL)); send_cb(GtkWidget *widget, GaimConversation *conv) GaimGtkConversation *gtkconv; gtkconv = GAIM_GTK_CONVERSATION(conv); account = gaim_conversation_get_account(conv); if (!gaim_account_is_connected(account)) if ((gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) && gaim_conv_chat_has_left(GAIM_CONV_CHAT(conv))) if (check_for_and_do_command(conv)) { gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry)); buf = gtk_imhtml_get_markup(GTK_IMHTML(gtkconv->entry)); clean = gtk_imhtml_get_text(GTK_IMHTML(gtkconv->entry), NULL, NULL); gtk_widget_grab_focus(gtkconv->entry); if (strlen(clean) == 0) { gc = gaim_account_get_connection(account); if (gc && (conv->features & GAIM_CONNECTION_NO_NEWLINES)) { bufs = gtk_imhtml_get_markup_lines(GTK_IMHTML(gtkconv->entry)); for (i = 0; bufs[i]; i++) { send_history_add(conv, bufs[i]); if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) gaim_conv_im_send(GAIM_CONV_IM(conv), bufs[i]); else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) gaim_conv_chat_send(GAIM_CONV_CHAT(conv), bufs[i]); send_history_add(conv, buf); if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) gaim_conv_im_send(GAIM_CONV_IM(conv), buf); else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) gaim_conv_chat_send(GAIM_CONV_CHAT(conv), buf); gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry)); add_remove_cb(GtkWidget *widget, GaimConversation *conv) account = gaim_conversation_get_account(conv); name = gaim_conversation_get_name(conv); if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { b = gaim_find_buddy(account, name); gaim_gtkdialogs_remove_buddy(b); else if (account != NULL && gaim_account_is_connected(account)) gaim_blist_request_add_buddy(account, (char *)name, NULL, NULL); } else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { c = gaim_blist_find_chat(account, name); gaim_gtkdialogs_remove_chat(c); else if (account != NULL && gaim_account_is_connected(account)) gaim_blist_request_add_chat(account, NULL, NULL, name); gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); static void chat_do_info(GaimConversation *conv, const char *who) GaimPluginProtocolInfo *prpl_info = NULL; if ((gc = gaim_conversation_get_gc(conv))) { prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); * If there are special needs for getting info on users in if (prpl_info->get_cb_info != NULL) prpl_info->get_cb_info(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), who); prpl_info->get_info(gc, who); info_cb(GtkWidget *widget, GaimConversation *conv) GaimGtkConversation *gtkconv; gtkconv = GAIM_GTK_CONVERSATION(conv); if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { serv_get_info(gaim_conversation_get_gc(conv), gaim_conversation_get_name(conv)); gtk_widget_grab_focus(gtkconv->entry); } else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { /* Get info of the person currently selected in the GtkTreeView */ GaimGtkChatPane *gtkchat; 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, CHAT_USERS_NAME_COLUMN, &name, -1); chat_do_info(conv, name); warn_cb(GtkWidget *widget, GaimConversation *conv) gaim_gtkdialogs_warn(gaim_conversation_get_gc(conv), gaim_conversation_get_name(conv)); gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); block_cb(GtkWidget *widget, GaimConversation *conv) account = gaim_conversation_get_account(conv); if (account != NULL && gaim_account_is_connected(account)) gaim_gtk_request_add_block(account, gaim_conversation_get_name(conv)); gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); send_file_cb(GtkWidget *widget, GaimConversation *conv) serv_send_file(gaim_conversation_get_gc(conv), gaim_conversation_get_name(conv), NULL); do_invite(GtkWidget *w, int resp, InviteBuddyInfo *info) const char *buddy, *message; GaimGtkConversation *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_ascii_strcasecmp(buddy, "")) serv_chat_invite(gaim_conversation_get_gc(info->conv), gaim_conv_chat_get_id(GAIM_CONV_CHAT(info->conv)), gtk_widget_destroy(invite_dialog); invite_dnd_recv(GtkWidget *widget, GdkDragContext *dc, gint x, gint y, GtkSelectionData *sd, guint inf, guint t, gpointer data) InviteBuddyInfo *info = (InviteBuddyInfo *)data; const char *convprotocol; convprotocol = gaim_account_get_protocol_id(gaim_conversation_get_account(info->conv)); if (sd->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE)) GaimBlistNode *node = NULL; memcpy(&node, sd->data, sizeof(node)); if (GAIM_BLIST_NODE_IS_CONTACT(node)) buddy = gaim_contact_get_priority_buddy((GaimContact *)node); else if (GAIM_BLIST_NODE_IS_BUDDY(node)) buddy = (GaimBuddy *)node; if (strcmp(convprotocol, gaim_account_get_protocol_id(buddy->account))) gaim_notify_error(NULL, NULL, _("That buddy is not on the same protocol as this " gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(info->entry)->entry), buddy->name); gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); else if (sd->target == gdk_atom_intern("application/x-im-contact", FALSE)) if (gaim_gtk_parse_x_im_contact(sd->data, FALSE, &account, &protocol, &username, NULL)) gaim_notify_error(NULL, NULL, _("You are not currently signed on with an account that " "can invite that buddy."), NULL); else if (strcmp(convprotocol, gaim_account_get_protocol_id(account))) gaim_notify_error(NULL, NULL, _("That buddy is not on the same protocol as this " gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(info->entry)->entry), username); if (username != NULL) g_free(username); if (protocol != NULL) g_free(protocol); gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); static const GtkTargetEntry dnd_targets[] = {"GAIM_BLIST_NODE", GTK_TARGET_SAME_APP, 0}, {"application/x-im-contact", 0, 1} invite_cb(GtkWidget *widget, GaimConversation *conv) InviteBuddyInfo *info = NULL; if (invite_dialog == NULL) { img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, info = g_new0(InviteBuddyInfo, 1); 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( _("Invite Buddy Into Chat Room"), GTK_WINDOW(gtkwin->window), 0, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GAIM_STOCK_INVITE, GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response(GTK_DIALOG(invite_dialog), 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); info->window = GTK_WIDGET(invite_dialog); /* 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 " 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); 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); /* Setup drag-and-drop */ gtk_drag_dest_set(info->window, GTK_DEST_DEFAULT_MOTION | sizeof(dnd_targets) / sizeof(GtkTargetEntry), gtk_drag_dest_set(info->entry, GTK_DEST_DEFAULT_MOTION | sizeof(dnd_targets) / sizeof(GtkTargetEntry), g_signal_connect(G_OBJECT(info->window), "drag_data_received", G_CALLBACK(invite_dnd_recv), info); g_signal_connect(G_OBJECT(info->entry), "drag_data_received", G_CALLBACK(invite_dnd_recv), info); gtk_widget_show_all(invite_dialog); gtk_widget_grab_focus(GTK_COMBO(info->entry)->entry); menu_new_conv_cb(gpointer data, guint action, GtkWidget *widget) savelog_writefile_cb(void *user_data, const char *filename) GaimConversation *conv = (GaimConversation *)user_data; if ((fp = g_fopen(filename, "w+")) == NULL) { gaim_notify_error(conv, NULL, _("Unable to open file."), NULL); name = gaim_conversation_get_name(conv); fprintf(fp, _("<h1>Conversation with %s</h1>\n"), name); fprintf(fp, "%s", conv->history->str); menu_save_as_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; GaimConversation *conv = gaim_conv_window_get_active_conversation(win); buf = g_strdup_printf("%s.html", gaim_normalize(conv->account, conv->name)); gaim_request_file(conv, _("Save Conversation"), buf, TRUE, G_CALLBACK(savelog_writefile_cb), NULL, conv); menu_view_log_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; conv = gaim_conv_window_get_active_conversation(win); if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) gaim_gtk_log_show(type, gaim_conversation_get_name(conv), gaim_conversation_get_account(conv)); menu_clear_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; GaimGtkConversation *gtkconv; conv = gaim_conv_window_get_active_conversation(win); gtkconv = GAIM_GTK_CONVERSATION(conv); gtk_imhtml_clear(GTK_IMHTML(gtkconv->imhtml)); g_string_free(conv->history, TRUE); conv->history = g_string_new(""); GaimGtkConversation *gtkconv; static void do_search_cb(GtkWidget *widget, gint resp, struct _search *s) gtk_imhtml_search_find(GTK_IMHTML(s->gtkconv->imhtml), gtk_entry_get_text(GTK_ENTRY(s->entry))); case GTK_RESPONSE_DELETE_EVENT: gtk_imhtml_search_clear(GTK_IMHTML(s->gtkconv->imhtml)); gtk_widget_destroy(s->gtkconv->dialogs.search); s->gtkconv->dialogs.search = NULL; menu_find_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; GaimConversation *conv = gaim_conv_window_get_active_conversation(win); GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(win); GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv); GtkWidget *img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, if (gtkconv->dialogs.search) { gtk_window_present(GTK_WINDOW(gtkconv->dialogs.search)); s = g_malloc(sizeof(struct _search)); gtkconv->dialogs.search = gtk_dialog_new_with_buttons(_("Find"), GTK_WINDOW(gtkwin->window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, GTK_STOCK_FIND, GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response(GTK_DIALOG(gtkconv->dialogs.search), g_signal_connect(G_OBJECT(gtkconv->dialogs.search), "response", G_CALLBACK(do_search_cb), s); gtk_container_set_border_width(GTK_CONTAINER(gtkconv->dialogs.search), 6); gtk_window_set_resizable(GTK_WINDOW(gtkconv->dialogs.search), FALSE); gtk_dialog_set_has_separator(GTK_DIALOG(gtkconv->dialogs.search), FALSE); gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(gtkconv->dialogs.search)->vbox), 12); gtk_container_set_border_width( GTK_CONTAINER(GTK_DIALOG(gtkconv->dialogs.search)->vbox), 6); hbox = gtk_hbox_new(FALSE, 12); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(gtkconv->dialogs.search)->vbox), gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); gtk_misc_set_alignment(GTK_MISC(img), 0, 0); gtk_dialog_set_response_sensitive(GTK_DIALOG(gtkconv->dialogs.search), label = gtk_label_new(NULL); gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Search for:")); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); s->entry = gtk_entry_new(); gtk_entry_set_activates_default(GTK_ENTRY(s->entry), TRUE); gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(s->entry)); g_signal_connect(G_OBJECT(s->entry), "changed", G_CALLBACK(gaim_gtk_set_sensitive_if_input), gtkconv->dialogs.search); gtk_box_pack_start(GTK_BOX(hbox), s->entry, FALSE, FALSE, 0); gtk_widget_show_all(gtkconv->dialogs.search); gtk_widget_grab_focus(s->entry); menu_send_file_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; GaimConversation *conv = gaim_conv_window_get_active_conversation(win); if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { serv_send_file(gaim_conversation_get_gc(conv), gaim_conversation_get_name(conv), NULL); menu_add_pounce_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; conv = gaim_conv_window_get_active_conversation(win); gaim_gtkpounce_dialog_show(gaim_conversation_get_account(conv), gaim_conversation_get_name(conv), NULL); menu_insert_link_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; GaimGtkConversation *gtkconv; GtkIMHtmlToolbar *toolbar; conv = gaim_conv_window_get_active_conversation(win); gtkconv = GAIM_GTK_CONVERSATION(conv); toolbar = GTK_IMHTMLTOOLBAR(gtkconv->toolbar); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->link), !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->link))); menu_insert_image_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; GaimGtkConversation *gtkconv; GtkIMHtmlToolbar *toolbar; conv = gaim_conv_window_get_active_conversation(win); gtkconv = GAIM_GTK_CONVERSATION(gaim_conv_window_get_active_conversation(win)); toolbar = GTK_IMHTMLTOOLBAR(gtkconv->toolbar); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image), !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->image))); menu_alias_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; conv = gaim_conv_window_get_active_conversation(win); account = gaim_conversation_get_account(conv); name = gaim_conversation_get_name(conv); if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { b = gaim_find_buddy(account, name); gaim_gtkdialogs_alias_buddy(b); } else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { c = gaim_blist_find_chat(account, name); gaim_gtkdialogs_alias_chat(c); menu_get_info_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; conv = gaim_conv_window_get_active_conversation(win); menu_invite_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; conv = gaim_conv_window_get_active_conversation(win); menu_warn_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; conv = gaim_conv_window_get_active_conversation(win); menu_block_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; conv = gaim_conv_window_get_active_conversation(win); menu_add_remove_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; conv = gaim_conv_window_get_active_conversation(win); add_remove_cb(NULL, conv); menu_close_conv_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; close_conv_cb(NULL, gaim_conv_window_get_active_conversation(win)); menu_logging_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; conv = gaim_conv_window_get_active_conversation(win); gaim_conversation_set_logging(conv, gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))); menu_toolbar_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; GaimGtkConversation *gtkconv; conv = gaim_conv_window_get_active_conversation(win); gtkconv = GAIM_GTK_CONVERSATION(conv); gtkconv->show_formatting_toolbar = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); if (gtkconv->show_formatting_toolbar) gtk_widget_show(gtkconv->toolbar); gtk_widget_hide(gtkconv->toolbar); menu_sounds_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; GaimGtkConversation *gtkconv; conv = gaim_conv_window_get_active_conversation(win); gtkconv = GAIM_GTK_CONVERSATION(conv); gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); menu_timestamps_cb(gpointer data, guint action, GtkWidget *widget) GaimConvWindow *win = (GaimConvWindow *)data; GaimGtkConversation *gtkconv; conv = gaim_conv_window_get_active_conversation(win); gtkconv = GAIM_GTK_CONVERSATION(conv); gtkconv->show_timestamps = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))); chat_do_im(GaimConversation *conv, const char *who) GaimPluginProtocolInfo *prpl_info = NULL; account = gaim_conversation_get_account(conv); if(account && account->gc) prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(account->gc->prpl); if(prpl_info && prpl_info->get_cb_real_name) real_who = prpl_info->get_cb_real_name(account->gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), who); real_who = g_strdup(who); conv2 = gaim_find_conversation_with_account(real_who, account); gaim_conv_window_show(gaim_conversation_get_window(conv2)); conv2 = gaim_conversation_new(GAIM_CONV_IM, account, real_who); chat_im_button_cb(GtkWidget *widget, GaimConversation *conv) GaimGtkConversation *gtkconv; GaimGtkChatPane *gtkchat; 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, CHAT_USERS_NAME_COLUMN, &name, -1); ignore_cb(GtkWidget *w, GaimConversation *conv) GaimGtkConversation *gtkconv; GaimGtkChatPane *gtkchat; chat = GAIM_CONV_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, CHAT_USERS_NAME_COLUMN, &name, -1); gtk_list_store_remove(GTK_LIST_STORE(model), &iter); if (gaim_conv_chat_is_user_ignored(chat, name)) gaim_conv_chat_unignore(chat, name); gaim_conv_chat_ignore(chat, name); add_chat_buddy_common(conv, name); menu_chat_im_cb(GtkWidget *w, GaimConversation *conv) const char *who = g_object_get_data(G_OBJECT(w), "user_data"); menu_chat_send_file_cb(GtkWidget *w, GaimConversation *conv) const char *who = g_object_get_data(G_OBJECT(w), "user_data"); GaimConnection *gc = gaim_conversation_get_gc(conv); serv_send_file(gc, who, NULL); menu_chat_info_cb(GtkWidget *w, GaimConversation *conv) who = g_object_get_data(G_OBJECT(w), "user_data"); menu_chat_get_away_cb(GtkWidget *w, GaimConversation *conv) GaimPluginProtocolInfo *prpl_info = NULL; gc = gaim_conversation_get_gc(conv); who = g_object_get_data(G_OBJECT(w), "user_data"); prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); * May want to expand this to work similarly to menu_info_cb? if (prpl_info->get_cb_away != NULL) prpl_info->get_cb_away(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), who); menu_chat_add_remove_cb(GtkWidget *w, GaimConversation *conv) account = gaim_conversation_get_account(conv); name = g_object_get_data(G_OBJECT(w), "user_data"); b = gaim_find_buddy(account, name); gaim_gtkdialogs_remove_buddy(b); else if (account != NULL && gaim_account_is_connected(account)) gaim_blist_request_add_buddy(account, name, NULL, NULL); gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); create_chat_menu(GaimConversation *conv, const char *who, GaimPluginProtocolInfo *prpl_info, GaimConnection *gc) static GtkWidget *menu = NULL; * If a menu already exists, destroy it before creating a new one, * thus freeing-up the memory it occupied. gtk_widget_destroy(menu); button = gtk_menu_item_new_with_label(_("IM")); g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(menu_chat_im_cb), conv); g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); gtk_menu_shell_append(GTK_MENU_SHELL(menu), button); if (gc && prpl_info && prpl_info->send_file && (!prpl_info->can_receive_file || prpl_info->can_receive_file(gc, who))) { button = gtk_menu_item_new_with_label(_("Send File")); g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(menu_chat_send_file_cb), conv); g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); gtk_menu_shell_append(GTK_MENU_SHELL(menu), button); if (gaim_conv_chat_is_user_ignored(GAIM_CONV_CHAT(conv), who)) button = gtk_menu_item_new_with_label(_("Un-Ignore")); button = gtk_menu_item_new_with_label(_("Ignore")); g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(ignore_cb), conv); g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); gtk_menu_shell_append(GTK_MENU_SHELL(menu), button); if (gc && (prpl_info->get_info || prpl_info->get_cb_info)) { button = gtk_menu_item_new_with_label(_("Info")); g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(menu_chat_info_cb), conv); g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); gtk_menu_shell_append(GTK_MENU_SHELL(menu), button); if (gc && prpl_info->get_cb_away) { button = gtk_menu_item_new_with_label(_("Get Away Msg")); g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(menu_chat_get_away_cb), conv); g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); gtk_menu_shell_append(GTK_MENU_SHELL(menu), button); /* Added by Jonas <jonas@birme.se> */ /* XXX: jabber can add here sometimes, but we have to assume not * so we don't confuse anyone. we'll need to do a prpl-specific add * or some way to ask the prpl for the "real" buddy name for someone * in a chat when the prpl has UNIQUE_CHATNAME set if (gc && prpl_info && !(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) { if (gaim_find_buddy(gc->account, who)) button = gtk_menu_item_new_with_label(_("Remove")); button = gtk_menu_item_new_with_label(_("Add")); g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(menu_chat_add_remove_cb), conv); g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); gtk_menu_shell_append(GTK_MENU_SHELL(menu), button); gtkconv_chat_popup_menu_cb(GtkWidget *widget, GaimConversation *conv) GaimGtkConversation *gtkconv; GaimPluginProtocolInfo *prpl_info = NULL; GaimGtkChatPane *gtkchat; gtkconv = GAIM_GTK_CONVERSATION(conv); gtkchat = gtkconv->u.chat; account = gaim_conversation_get_account(conv); model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); 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, CHAT_USERS_NAME_COLUMN, &who, -1); menu = create_chat_menu (conv, who, prpl_info, gc); gtk_menu_popup(GTK_MENU(menu), NULL, NULL, gaim_gtk_treeview_popup_menu_position_func, widget, right_click_chat_cb(GtkWidget *widget, GdkEventButton *event, GaimGtkConversation *gtkconv; GaimPluginProtocolInfo *prpl_info = NULL; GaimGtkChatPane *gtkchat; GtkTreeViewColumn *column; gtkconv = GAIM_GTK_CONVERSATION(conv); gtkchat = gtkconv->u.chat; account = gaim_conversation_get_account(conv); 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); prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); 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, CHAT_USERS_NAME_COLUMN, &who, -1); if (event->button == 1 && event->type == GDK_2BUTTON_PRESS) { } else if (event->button == 3 && event->type == GDK_BUTTON_PRESS) { GtkWidget *menu = create_chat_menu (conv, who, prpl_info, gc); gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time); gtk_tree_path_free(path); move_to_next_unread_tab(GaimConversation *conv) GaimConversation *next_conv = NULL; 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_conv_window_get_conversations(win), index); next_conv = (GaimConversation *)l->data; if (gaim_conversation_get_unseen(next_conv) > 0) /* Now check before this position. */ for (l = gaim_conv_window_get_conversations(win), i = 0; next_conv = (GaimConversation *)l->data; if (gaim_conversation_get_unseen(next_conv) > 0) /* Okay, just grab the next conversation tab. */ if (index == gaim_conv_window_get_conversation_count(win) - 1) next_conv = gaim_conv_window_get_conversation_at(win, 0); next_conv = gaim_conv_window_get_conversation_at(win, if (next_conv != NULL && next_conv != conv) { gaim_conv_window_switch_conversation(win, gaim_conversation_get_index(next_conv)); entry_key_press_cb(GtkWidget *entry, GdkEventKey *event, gpointer data) GaimGtkConversation *gtkconv; conv = (GaimConversation *)data; gtkconv = GAIM_GTK_CONVERSATION(conv); win = gaim_conversation_get_window(conv); gtkwin = GAIM_GTK_WINDOW(win); numconvs = gaim_conv_window_get_conversation_count(win); curconv = gaim_conversation_get_index(conv); /* If CTRL was held down... */ if (event->state & GDK_CONTROL_MASK) { "/gaim/gtk/conversations/ctrl_enter_sends")) if (!conv->send_history->prev) { if (conv->send_history->data) g_free(conv->send_history->data); gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, gtk_text_buffer_get_end_iter(gtkconv->entry_buffer, &end); conv->send_history->data = gtk_imhtml_get_markup(GTK_IMHTML(gtkconv->entry)); if (conv->send_history->next && conv->send_history->next->data) { GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry)); conv->send_history = conv->send_history->next; gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry)); gtk_imhtml_append_text_with_images( GTK_IMHTML(gtkconv->entry), conv->send_history->data, /* this is mainly just a hack so the formatting at the * cursor gets picked up. */ gtk_text_buffer_get_end_iter(buffer, &iter); gtk_text_buffer_move_mark_by_name(buffer, "insert", &iter); if (conv->send_history->prev && conv->send_history->prev->data) { GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry)); conv->send_history = conv->send_history->prev; gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry)); gtk_imhtml_append_text_with_images( GTK_IMHTML(gtkconv->entry), conv->send_history->data, /* this is mainly just a hack so the formatting at the * cursor gets picked up. */ gtk_text_buffer_get_end_iter(buffer, &iter); gtk_text_buffer_move_mark_by_name(buffer, "insert", &iter); gaim_conv_window_switch_conversation(win, (curconv + 1) % numconvs); gaim_conv_window_switch_conversation(win, (curconv + numconvs - 1) % numconvs); move_to_next_unread_tab(conv); gtk_window_iconify(GTK_WINDOW(gtkwin->window)); /* If ALT (or whatever) was held down... */ else if (event->state & GDK_MOD1_MASK) /* XXX - Make sure the conv exists before switching to it */ if (event->keyval > '0' && event->keyval <= '9') { int switchto = event->keyval - '1'; gaim_conv_window_switch_conversation(win, switchto); /* If neither CTRL nor ALT were held down... */ if (!(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK)) && gaim_prefs_get_bool("/gaim/gtk/conversations/enter_sends")) return tab_complete(conv); gtk_imhtml_page_up(GTK_IMHTML(gtkconv->imhtml)); gtk_imhtml_page_down(GTK_IMHTML(gtkconv->imhtml)); * 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. entry_stop_rclick_cb(GtkWidget *widget, GdkEventButton *event, gpointer data) if (event->button == 3 && event->type == GDK_BUTTON_PRESS) { g_signal_stop_emission_by_name(G_OBJECT(widget), "button_press_event"); * If someone tries to type into the conversation backlog of a * conversation window then we yank focus from the conversation backlog * and give it to the text entry box so that people can type * all the live long day and it will get entered into the entry box. refocus_entry_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) GaimGtkConversation *gtkconv = data; /* If we have a valid key for the conversation display, then exit */ if ((event->state & GDK_CONTROL_MASK) || (event->keyval == GDK_F10) || (event->keyval == GDK_Shift_L) || (event->keyval == GDK_Shift_R) || (event->keyval == GDK_Escape) || (event->keyval == GDK_Up) || (event->keyval == GDK_Down) || (event->keyval == GDK_Left) || (event->keyval == GDK_Right) || (event->keyval == GDK_Home) || (event->keyval == GDK_End) || (event->keyval == GDK_Tab) || (event->keyval == GDK_ISO_Left_Tab)) if (event->type == GDK_KEY_RELEASE) gtk_widget_grab_focus(gtkconv->entry); gtk_widget_event(gtkconv->entry, (GdkEvent *)event); menu_conv_sel_send_cb(GObject *m, gpointer data) GaimConvWindow *win = g_object_get_data(m, "user_data"); GaimAccount *account = g_object_get_data(m, "gaim_account"); GaimGtkConversation *gtkconv; if (gtk_check_menu_item_get_active((GtkCheckMenuItem*) m) == FALSE) conv = gaim_conv_window_get_active_conversation(win); gaim_conversation_set_account(conv, account); gtkconv = GAIM_GTK_CONVERSATION(conv); gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->entry), gaim_account_get_protocol_name(conv->account)); insert_text_cb(GtkTextBuffer *textbuffer, GtkTextIter *position, gchar *new_text, gint new_text_length, gpointer user_data) GaimConversation *conv = (GaimConversation *)user_data; g_return_if_fail(conv != NULL); if (!gaim_prefs_get_bool("/core/conversations/im/send_typing")) got_typing_keypress(conv, (gtk_text_iter_is_start(position) && gtk_text_iter_is_end(position))); delete_text_cb(GtkTextBuffer *textbuffer, GtkTextIter *start_pos, GtkTextIter *end_pos, gpointer user_data) GaimConversation *conv = (GaimConversation *)user_data; g_return_if_fail(conv != NULL); if (!gaim_prefs_get_bool("/core/conversations/im/send_typing")) 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_conv_im_get_type_again_timeout(im)) gaim_conv_im_stop_type_again_timeout(im); serv_send_typing(gaim_conversation_get_gc(conv), gaim_conversation_get_name(conv), /* We're deleting, but not all of it, so it counts as typing. */ got_typing_keypress(conv, FALSE); notebook_init_grab(GaimGtkWindow *gtkwin, GtkWidget *widget) static GdkCursor *cursor = NULL; if (gtkwin->drag_leave_signal) { g_signal_handler_disconnect(G_OBJECT(widget), gtkwin->drag_leave_signal); gtkwin->drag_leave_signal = 0; cursor = gdk_cursor_new(GDK_FLEUR); gtk_grab_add(gtkwin->notebook); /* Currently for win32 GTK+ (as of 2.2.1), gdk_pointer_is_grabbed will always be true after a button press. */ if (!gdk_pointer_is_grabbed()) gdk_pointer_grab(gtkwin->notebook->window, FALSE, GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, NULL, cursor, GDK_CURRENT_TIME); notebook_motion_cb(GtkWidget *widget, GdkEventButton *e, GaimConvWindow *win) gtkwin = GAIM_GTK_WINDOW(win); * Make sure the user moved the mouse far enough for the 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. */ GaimConvWindow *dest_win; GaimGtkWindow *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; /* Get the window that the cursor is over. */ dest_win = gaim_gtkwin_get_at_xy(e->x_root, e->y_root); 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, if (gtk_notebook_get_tab_pos(dest_notebook) == GTK_POS_TOP || gtk_notebook_get_tab_pos(dest_notebook) == GTK_POS_BOTTOM) { /* Find out where to put the arrows. */ for (l = gaim_conv_window_get_conversations(dest_win), i = 0; GaimConversation *conv = l->data; tab = GAIM_GTK_CONVERSATION(conv)->tabby; * If this is the correct tab, record the positions arrow1_x = arrow2_x = nb_x + tab->allocation.x; arrow1_y = nb_y + tab->allocation.y; arrow2_y = nb_y + tab->allocation.y + arrow1_x = nb_x + tab->allocation.x; arrow2_x = nb_x + tab->allocation.x + arrow1_y = arrow2_y = nb_y + tab->allocation.y; else { /* Keep track of the right-most tab that we see. */ if (horiz_tabs && tab->allocation.x > last_vis_tab_loc) { last_vis_tab_loc = tab->allocation.x; else if (!horiz_tabs && tab->allocation.y > last_vis_tab_loc) { 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) { 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; 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; dnd_hints_show(HINT_ARROW_DOWN, arrow1_x, arrow1_y); dnd_hints_show(HINT_ARROW_UP, arrow2_x, arrow2_y); dnd_hints_show(HINT_ARROW_RIGHT, arrow1_x, arrow1_y); dnd_hints_show(HINT_ARROW_LEFT, arrow2_x, arrow2_y); notebook_leave_cb(GtkWidget *widget, GdkEventCrossing *e, GaimConvWindow *win) gtkwin = GAIM_GTK_WINDOW(win); 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); notebook_press_cb(GtkWidget *widget, GdkEventButton *e, GaimConvWindow *win) gint nb_x, nb_y, x_rel, y_rel; if (e->button != 1 || e->type != GDK_BUTTON_PRESS) gtkwin = GAIM_GTK_WINDOW(win); gaim_debug(GAIM_DEBUG_WARNING, "gtkconv", "Already in the middle of a window drag at tab_press_cb\n"); * Make sure a tab was actually clicked. The arrow buttons tab_clicked = gaim_gtkconv_get_tab_at_xy(win, e->x_root, e->y_root); * 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 */ /* Find out which tab was dragged. */ for (l = gaim_conv_window_get_conversations(win); l != NULL; l = l->next) { GaimConversation *conv = l->data; GtkWidget *tab = GAIM_GTK_CONVERSATION(conv)->tabby; if (!GTK_WIDGET_VISIBLE(tab)) if (tab->allocation.x > x_rel || tab->allocation.y > y_rel) /* 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; /* 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) { 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); notebook_release_cb(GtkWidget *widget, GdkEventButton *e, GaimConvWindow *win) GaimConvWindow *dest_win; GaimGtkWindow *dest_gtkwin; GtkNotebook *dest_notebook; * 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 if (e->button != 1 && e->type != GDK_BUTTON_RELEASE) if (gdk_pointer_is_grabbed()) { gdk_pointer_ungrab(GDK_CURRENT_TIME); gtkwin = GAIM_GTK_WINDOW(win); if (!gtkwin->in_predrag && !gtkwin->in_drag) /* 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 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! */ dest_win = gaim_gtkwin_get_at_xy(e->x_root, e->y_root); conv = gaim_conv_window_get_active_conversation(win); if (gaim_conv_window_get_conversation_count(win) < 2) if (gaim_conv_window_get_conversation_count(win) > 1) { /* Make a new window to stick this to. */ GaimGtkConversation *gtkconv; gint win_width, win_height; gtkconv = GAIM_GTK_CONVERSATION(conv); dest_win = gaim_conv_window_new(); gaim_conv_window_add_conversation(dest_win, gaim_conv_window_remove_conversation(win, gaim_conversation_get_index(conv))); dest_gtkwin = GAIM_GTK_WINDOW(dest_win); gtk_window_get_size(GTK_WINDOW(dest_gtkwin->window), &win_width, &win_height); gtk_window_move(GTK_WINDOW(dest_gtkwin->window), e->x_root - (win_width / 2), e->y_root - (win_height / 2)); gaim_conv_window_show(dest_win); dest_gtkwin = GAIM_GTK_WINDOW(dest_win); /* 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, gaim_conv_window_move_conversation(win, gaim_conversation_get_index(conv), dest_page_num); gaim_conv_window_remove_conversation(win, gaim_conversation_get_index(conv)); pos = gaim_conv_window_add_conversation(dest_win, conv); if (pos != dest_page_num) gaim_conv_window_move_conversation(dest_win, pos, dest_page_num); gaim_conv_window_switch_conversation(dest_win, dest_page_num); gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); gaim_signal_emit(gaim_gtk_conversations_get_handle(), "conversation-drag-ended", /************************************************************************** * A bunch of buddy icon functions **************************************************************************/ get_tab_icon(GaimConversation *conv, gboolean small_icon) GaimAccount *account = NULL; GdkPixbuf *status = NULL; g_return_val_if_fail( conv != NULL, NULL); account = gaim_conversation_get_account(conv); g_return_val_if_fail( account != NULL, NULL); name = g_strdup(gaim_normalize(account, gaim_conversation_get_name(conv))); g_return_val_if_fail( name != NULL, NULL); if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { GaimBuddy *b = gaim_find_buddy(account, name); status = gaim_gtk_blist_get_status_icon((GaimBlistNode*)b, (small_icon ? GAIM_STATUS_ICON_SMALL : GAIM_STATUS_ICON_LARGE)); pixbuf = create_prpl_icon(account); if (small_icon && pixbuf != NULL) status = gdk_pixbuf_scale_simple(pixbuf, 15, 15, update_tab_icon(GaimConversation *conv) GaimGtkConversation *gtkconv; GaimConvWindow *win = gaim_conversation_get_window(conv); GdkPixbuf *status = NULL; g_return_if_fail(conv != NULL); gtkconv = GAIM_GTK_CONVERSATION(conv); name = gaim_conversation_get_name(conv); account = gaim_conversation_get_account(conv); status = get_tab_icon(conv, TRUE); g_return_if_fail(status != NULL); gtk_image_set_from_pixbuf(GTK_IMAGE(gtkconv->icon), status); gtk_image_set_from_pixbuf(GTK_IMAGE(gtkconv->menu_icon), status); if (gaim_conv_window_get_active_conversation(win) == conv && (gaim_conversation_get_type(conv) != GAIM_CONV_IM || gtkconv->u.im->anim == NULL)) status = get_tab_icon(conv, FALSE); gtk_window_set_icon(GTK_WINDOW(GAIM_GTK_WINDOW(win)->window), status); get_icon_scale_size(GdkPixbufAnimation *icon, GaimBuddyIconSpec *spec, int *width, int *height) *width = gdk_pixbuf_animation_get_width(icon); *height = gdk_pixbuf_animation_get_height(icon); /* this should eventually get smarter about preserving the aspect * ratio when scaling, but gimmie a break, I just woke up */ if(spec && spec->scale_rules & GAIM_ICON_SCALE_DISPLAY) { if(*width < spec->min_width) *width = spec->min_width; else if(*width > spec->max_width) *width = spec->max_width; if(*height < spec->min_height) *height = spec->min_height; else if(*height > spec->max_height) *height = spec->max_height; /* and now for some arbitrary sanity checks */ redraw_icon(gpointer data) GaimConversation *conv = (GaimConversation *)data; GaimGtkConversation *gtkconv; GaimPluginProtocolInfo *prpl_info = NULL; int scale_width, scale_height; if (!g_list_find(gaim_get_ims(), conv)) { gaim_debug(GAIM_DEBUG_WARNING, "gtkconv", "Conversation not found in redraw_icon. I think this " gtkconv = GAIM_GTK_CONVERSATION(conv); account = gaim_conversation_get_account(conv); if(account && account->gc) prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(account->gc->prpl); gdk_pixbuf_animation_iter_advance(gtkconv->u.im->iter, NULL); buf = gdk_pixbuf_animation_iter_get_pixbuf(gtkconv->u.im->iter); get_icon_scale_size(gtkconv->u.im->anim, prpl_info ? &prpl_info->icon_spec : NULL, &scale_width, &scale_height); /* this code is ugly, and scares me */ scale = gdk_pixbuf_scale_simple(buf, MAX(gdk_pixbuf_get_width(buf) * scale_width / gdk_pixbuf_animation_get_width(gtkconv->u.im->anim), 1), MAX(gdk_pixbuf_get_height(buf) * scale_height / gdk_pixbuf_animation_get_height(gtkconv->u.im->anim), 1), gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100); g_object_unref(G_OBJECT(scale)); gtk_image_set_from_pixmap(GTK_IMAGE(gtkconv->u.im->icon), pm, bm); g_object_unref(G_OBJECT(pm)); gtk_widget_queue_draw(gtkconv->u.im->icon); g_object_unref(G_OBJECT(bm)); delay = gdk_pixbuf_animation_iter_get_delay_time(gtkconv->u.im->iter); /* Limit animations to at most 10 frames per second */ gtkconv->u.im->icon_timer = g_timeout_add(delay, redraw_icon, conv); start_anim(GtkObject *obj, GaimConversation *conv) GaimGtkConversation *gtkconv; if (!GAIM_IS_GTK_CONVERSATION(conv)) gtkconv = GAIM_GTK_CONVERSATION(conv); if (gtkconv->u.im->anim == NULL) if (gtkconv->u.im->icon_timer != 0) if (gdk_pixbuf_animation_is_static_image(gtkconv->u.im->anim)) delay = gdk_pixbuf_animation_iter_get_delay_time(gtkconv->u.im->iter); /* Limit animations to at most 10 frames per second */ gtkconv->u.im->icon_timer = g_timeout_add(delay, redraw_icon, conv); stop_anim(GtkObject *obj, GaimConversation *conv) GaimGtkConversation *gtkconv; if (!GAIM_IS_GTK_CONVERSATION(conv)) 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; toggle_icon_animate_cb(GtkWidget *w, GaimConversation *conv) GaimGtkConversation *gtkconv; if (!GAIM_IS_GTK_CONVERSATION(conv)) gtkconv = GAIM_GTK_CONVERSATION(conv); gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w)); if (gtkconv->u.im->animate) remove_icon(GaimGtkConversation *gtkconv) g_return_if_fail(gtkconv != NULL); if (gtkconv->u.im->icon_container != NULL) gtk_widget_destroy(gtkconv->u.im->icon_container); if (gtkconv->u.im->anim != NULL) g_object_unref(G_OBJECT(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; gtkconv->u.im->show_icon = FALSE; saveicon_writefile_cb(void *user_data, const char *filename) GaimConversation *conv = (GaimConversation *)user_data; if ((fp = g_fopen(filename, "wb")) == NULL) { gaim_notify_error(conv, NULL, _("Unable to open file."), NULL); icon = gaim_conv_im_get_icon(GAIM_CONV_IM(conv)); data = gaim_buddy_icon_get_data(icon, &len); if ((len <= 0) || (data == NULL)) { gaim_notify_error(conv, NULL, _("Unable to save icon file to disk."), NULL); fwrite(data, 1, len, fp); icon_menu_save_cb(GtkWidget *widget, GaimConversation *conv) g_return_if_fail(conv != NULL); ext = gaim_buddy_icon_get_type(gaim_conv_im_get_icon(GAIM_CONV_IM(conv))); buf = g_strdup_printf("%s.%s", gaim_normalize(conv->account, conv->name), ext); gaim_request_file(conv, _("Save Icon"), buf, TRUE, G_CALLBACK(saveicon_writefile_cb), NULL, conv); icon_menu(GtkObject *obj, GdkEventButton *e, GaimConversation *conv) GaimGtkConversation *gtkconv; static GtkWidget *menu = NULL; if (e->button != 3 || e->type != GDK_BUTTON_PRESS) gtkconv = GAIM_GTK_CONVERSATION(conv); * If a menu already exists, destroy it before creating a new one, * thus freeing-up the memory it occupied. gtk_widget_destroy(menu); if (gtkconv->u.im->anim && !(gdk_pixbuf_animation_is_static_image(gtkconv->u.im->anim))) gaim_new_check_item(menu, _("Animate"), G_CALLBACK(toggle_icon_animate_cb), conv, gtkconv->u.im->icon_timer); button = gtk_menu_item_new_with_label(_("Hide Icon")); g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(remove_icon), gtkconv); gtk_menu_shell_append(GTK_MENU_SHELL(menu), button); gaim_new_item_from_stock(menu, _("Save Icon As..."), GTK_STOCK_SAVE_AS, G_CALLBACK(icon_menu_save_cb), conv, gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, e->button, e->time); /************************************************************************** * End of the bunch of buddy icon functions **************************************************************************/ * Makes sure all the menu items and all the buttons are hidden/shown and * sensitive/insensitive. This is called after changing tabs and when an * account signs on or off. gray_stuff_out(GaimConversation *conv) GaimGtkConversation *gtkconv; GaimPluginProtocolInfo *prpl_info = NULL; GdkPixbuf *window_icon = NULL; GtkIMHtmlButtons buttons; win = gaim_conversation_get_window(conv); gtkwin = GAIM_GTK_WINDOW(win); gtkconv = GAIM_GTK_CONVERSATION(conv); gc = gaim_conversation_get_gc(conv); account = gaim_conversation_get_account(conv); prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); if (gtkwin->menu.send_as != NULL) g_timeout_add(0, (GSourceFunc)update_send_as_selection, win); * Handle hiding and showing stuff based on what type of conv this is. * Stuff that Gaim IMs support in general should be shown for IM * conversations. Stuff that Gaim chats support in general should be * shown for chat conversations. It doesn't matter whether the PRPL * supports it or not--that only affects if the button or menu item if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { /* Show stuff that applies to IMs, hide stuff that applies to chats */ gtk_widget_show(gtkconv->info); gtk_widget_show(gtkconv->send); gtk_widget_show(gtkconv->u.im->warn); gtk_widget_show(gtkconv->u.im->block); gtk_widget_show(gtkconv->u.im->send_file); /* Deal with menu items */ gtk_widget_show(gtkwin->menu.view_log); gtk_widget_show(gtkwin->menu.send_file); gtk_widget_show(gtkwin->menu.add_pounce); gtk_widget_show(gtkwin->menu.get_info); gtk_widget_show(gtkwin->menu.warn); gtk_widget_hide(gtkwin->menu.invite); gtk_widget_show(gtkwin->menu.alias); gtk_widget_show(gtkwin->menu.block); if (gaim_find_buddy(account, gaim_conversation_get_name(conv)) == NULL) { gtk_widget_show(gtkwin->menu.add); gtk_widget_hide(gtkwin->menu.remove); gtk_widget_show(gtkconv->add); gtk_widget_hide(gtkconv->remove); gtk_widget_show(gtkwin->menu.remove); gtk_widget_hide(gtkwin->menu.add); gtk_widget_hide(gtkconv->add); gtk_widget_show(gtkconv->remove); gtk_widget_show(gtkwin->menu.insert_link); gtk_widget_show(gtkwin->menu.insert_image); } else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { /* Show stuff that applies to Chats, hide stuff that applies to IMs */ gtk_widget_show(gtkconv->info); gtk_widget_show(gtkconv->send); gtk_widget_show(gtkconv->u.chat->invite); /* Deal with menu items */ gtk_widget_show(gtkwin->menu.view_log); gtk_widget_hide(gtkwin->menu.send_file); gtk_widget_hide(gtkwin->menu.add_pounce); gtk_widget_hide(gtkwin->menu.get_info); gtk_widget_hide(gtkwin->menu.warn); gtk_widget_show(gtkwin->menu.invite); gtk_widget_show(gtkwin->menu.alias); gtk_widget_hide(gtkwin->menu.block); if (gaim_blist_find_chat(account, gaim_conversation_get_name(conv)) == NULL) { /* If the chat is NOT in the buddy list */ gtk_widget_show(gtkwin->menu.add); gtk_widget_hide(gtkwin->menu.remove); gtk_widget_show(gtkconv->add); gtk_widget_hide(gtkconv->remove); /* If the chat IS in the buddy list */ gtk_widget_hide(gtkwin->menu.add); gtk_widget_show(gtkwin->menu.remove); gtk_widget_hide(gtkconv->add); gtk_widget_show(gtkconv->remove); gtk_widget_show(gtkwin->menu.insert_link); gtk_widget_hide(gtkwin->menu.insert_image); * Handle graying stuff out based on whether an account is connected * and what features that account supports. ( (gaim_conversation_get_type(conv) != GAIM_CONV_CHAT) || !gaim_conv_chat_has_left(GAIM_CONV_CHAT(conv)) )) { gtk_widget_set_sensitive(gtkconv->info, (prpl_info->get_info != NULL)); if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) gtk_widget_set_sensitive(gtkconv->add, (prpl_info->add_buddy != NULL)); gtk_widget_set_sensitive(gtkconv->remove, (prpl_info->remove_buddy != NULL)); gtk_widget_set_sensitive(gtkconv->send, (prpl_info->send_im != NULL)); gtk_widget_set_sensitive(gtkconv->u.im->warn, (prpl_info->warn != NULL)); gtk_widget_set_sensitive(gtkconv->u.im->block, (prpl_info->add_deny != NULL)); gtk_widget_set_sensitive(gtkconv->u.im->send_file, (prpl_info->send_file && (!prpl_info->can_receive_file || prpl_info->can_receive_file(gc, gaim_conversation_get_name(conv))))); else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) /* Only allow adding/removing if this is a chat and not a conference */ gtk_widget_set_sensitive(gtkconv->add, (prpl_info->join_chat != NULL)); gtk_widget_set_sensitive(gtkconv->remove, (prpl_info->join_chat != NULL)); gtk_widget_set_sensitive(gtkconv->send, (prpl_info->chat_send != NULL)); gtk_widget_set_sensitive(gtkconv->u.chat->invite, (prpl_info->chat_invite != NULL)); /* Deal with the toolbar */ if (conv->features & GAIM_CONNECTION_HTML) { buttons = GTK_IMHTML_ALL; /* Everything on */ if (!(prpl_info->options & OPT_PROTO_IM_IMAGE) || (conv->features & GAIM_CONNECTION_NO_IMAGES)) buttons &= ~GTK_IMHTML_IMAGE; if (conv->features & GAIM_CONNECTION_NO_BGCOLOR) buttons &= ~GTK_IMHTML_BACKCOLOR; if (conv->features & GAIM_CONNECTION_NO_FONTSIZE) { buttons &= ~GTK_IMHTML_GROW; buttons &= ~GTK_IMHTML_SHRINK; if (conv->features & GAIM_CONNECTION_NO_URLDESC) buttons &= ~GTK_IMHTML_LINKDESC; buttons = GTK_IMHTML_SMILEY; gtk_imhtml_set_format_functions(GTK_IMHTML(gtkconv->entry), buttons); gtk_imhtmltoolbar_associate_smileys(GTK_IMHTMLTOOLBAR(gtkconv->toolbar), gaim_account_get_protocol_id(account)); /* Deal with menu items */ gtk_widget_set_sensitive(gtkwin->menu.view_log, TRUE); gtk_widget_set_sensitive(gtkwin->menu.add_pounce, TRUE); gtk_widget_set_sensitive(gtkwin->menu.get_info, (prpl_info->get_info != NULL)); gtk_widget_set_sensitive(gtkwin->menu.warn, (prpl_info->warn != NULL)); gtk_widget_set_sensitive(gtkwin->menu.invite, (prpl_info->chat_invite != NULL)); gtk_widget_set_sensitive(gtkwin->menu.block, (prpl_info->add_deny != NULL)); gtk_widget_set_sensitive(gtkwin->menu.insert_link, (conv->features & GAIM_CONNECTION_HTML)); gtk_widget_set_sensitive(gtkwin->menu.insert_image, (prpl_info->options & OPT_PROTO_IM_IMAGE)); if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { gtk_widget_set_sensitive(gtkwin->menu.add, (prpl_info->add_buddy != NULL)); gtk_widget_set_sensitive(gtkwin->menu.remove, (prpl_info->remove_buddy != NULL)); gtk_widget_set_sensitive(gtkwin->menu.send_file, (prpl_info->send_file != NULL && (!prpl_info->can_receive_file || prpl_info->can_receive_file(gc, gaim_conversation_get_name(conv))))); gtk_widget_set_sensitive(gtkwin->menu.alias, (gaim_find_buddy(account, gaim_conversation_get_name(conv)) != NULL)); } else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { gtk_widget_set_sensitive(gtkwin->menu.add, (prpl_info->join_chat != NULL)); gtk_widget_set_sensitive(gtkwin->menu.remove, (prpl_info->join_chat != NULL)); gtk_widget_set_sensitive(gtkwin->menu.alias, (gaim_blist_find_chat(account, gaim_conversation_get_name(conv)) != NULL)); /* Or it's a chat that we've left. */ gtk_widget_set_sensitive(gtkconv->add, FALSE); gtk_widget_set_sensitive(gtkconv->remove, FALSE); gtk_widget_set_sensitive(gtkconv->info, FALSE); gtk_widget_set_sensitive(gtkconv->send, FALSE); if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { 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->send_file, FALSE); } else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { gtk_widget_set_sensitive(gtkconv->u.chat->invite, FALSE); /* Then deal with menu items */ gtk_widget_set_sensitive(gtkwin->menu.view_log, TRUE); gtk_widget_set_sensitive(gtkwin->menu.send_file, FALSE); gtk_widget_set_sensitive(gtkwin->menu.add_pounce, TRUE); gtk_widget_set_sensitive(gtkwin->menu.get_info, FALSE); gtk_widget_set_sensitive(gtkwin->menu.warn, FALSE); gtk_widget_set_sensitive(gtkwin->menu.invite, FALSE); gtk_widget_set_sensitive(gtkwin->menu.alias, FALSE); gtk_widget_set_sensitive(gtkwin->menu.block, FALSE); gtk_widget_set_sensitive(gtkwin->menu.add, FALSE); gtk_widget_set_sensitive(gtkwin->menu.remove, FALSE); gtk_widget_set_sensitive(gtkwin->menu.insert_link, TRUE); gtk_widget_set_sensitive(gtkwin->menu.insert_image, FALSE); * Update the window's icon if ((gaim_conversation_get_type(conv) == GAIM_CONV_IM) && gdk_pixbuf_animation_get_static_image(gtkconv->u.im->anim); g_object_ref(window_icon); window_icon = get_tab_icon(conv, FALSE); gtk_window_set_icon(GTK_WINDOW(gtkwin->window), window_icon); g_object_unref(G_OBJECT(window_icon)); before_switch_conv_cb(GtkNotebook *notebook, GtkWidget *page, gint page_num, GaimGtkConversation *gtkconv; win = (GaimConvWindow *)user_data; conv = gaim_conv_window_get_active_conversation(win); g_return_if_fail(conv != NULL); if (gaim_conversation_get_type(conv) != GAIM_CONV_IM) gtkconv = GAIM_GTK_CONVERSATION(conv); switch_conv_cb(GtkNotebook *notebook, GtkWidget *page, gint page_num, GaimGtkConversation *gtkconv; win = (GaimConvWindow *)user_data; conv = gaim_conv_window_get_conversation_at(win, page_num); g_return_if_fail(conv != NULL); gtkwin = GAIM_GTK_WINDOW(win); gtkconv = GAIM_GTK_CONVERSATION(conv); * Only set "unseen" to "none" if the window has focus if (gaim_conv_window_has_focus(win)) gaim_conversation_set_unseen(conv, GAIM_UNSEEN_NONE); update_typing_icon(conv); 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), gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(gtkwin->menu.show_formatting_toolbar), gtkconv->show_formatting_toolbar); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtkwin->menu.show_timestamps), gtkconv->show_timestamps); * We pause icons when they are not visible. If this icon should * be animated then start it back up again. if ((gaim_conversation_get_type(conv) == GAIM_CONV_IM) && (gtkconv->u.im->animate)) gtk_window_set_title(GTK_WINDOW(gtkwin->window), gtk_label_get_text(GTK_LABEL(gtkconv->tab_label))); /************************************************************************** **************************************************************************/ got_typing_keypress(GaimConversation *conv, gboolean first) * We know we got something, so we at least have to make sure we don't * send GAIM_TYPED any time soon. if (gaim_conv_im_get_type_again_timeout(im)) gaim_conv_im_stop_type_again_timeout(im); gaim_conv_im_start_type_again_timeout(im); if (first || (gaim_conv_im_get_type_again(im) != 0 && time(NULL) > gaim_conv_im_get_type_again(im))) { int timeout = serv_send_typing(gaim_conversation_get_gc(conv), (char *)gaim_conversation_get_name(conv), gaim_conv_im_set_type_again(im, time(NULL) + timeout); gaim_conv_im_set_type_again(im, 0); update_typing_icon(GaimConversation *conv) GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv); gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(conv)); if(gaim_conversation_get_type(conv) == GAIM_CONV_IM) if(gtkwin->menu.typing_icon) { gtk_widget_destroy(gtkwin->menu.typing_icon); gtkwin->menu.typing_icon = NULL; if(im && gaim_conv_im_get_typing_state(im) == GAIM_TYPING) { gtkwin->menu.typing_icon = gtk_image_menu_item_new(); gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(gtkwin->menu.typing_icon), gtk_image_new_from_stock(GAIM_STOCK_TYPING, gtk_tooltips_set_tip(gtkconv->tooltips, gtkwin->menu.typing_icon, _("User is typing..."), NULL); } else if(im && gaim_conv_im_get_typing_state(im) == GAIM_TYPED) { gtkwin->menu.typing_icon = gtk_image_menu_item_new(); gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(gtkwin->menu.typing_icon), gtk_image_new_from_stock(GAIM_STOCK_TYPED, gtk_tooltips_set_tip(gtkconv->tooltips, gtkwin->menu.typing_icon, _("User has typed something and paused"), NULL); if(gtkwin->menu.typing_icon) { gtk_menu_item_set_right_justified( GTK_MENU_ITEM(gtkwin->menu.typing_icon), TRUE); gtk_widget_show_all(gtkwin->menu.typing_icon); gtk_menu_shell_append(GTK_MENU_SHELL(gtkwin->menu.menubar), gtkwin->menu.typing_icon); update_send_as_selection(GaimConvWindow *win) if (g_list_find(gaim_get_windows(), win) == NULL) conv = gaim_conv_window_get_active_conversation(win); account = gaim_conversation_get_account(conv); gtkwin = GAIM_GTK_WINDOW(win); if (gtkwin->menu.send_as == NULL) gtk_widget_show(gtkwin->menu.send_as); menu = gtk_menu_item_get_submenu( GTK_MENU_ITEM(gtkwin->menu.send_as)); for (child = gtk_container_get_children(GTK_CONTAINER(menu)); GtkWidget *item = child->data; GaimAccount *item_account = g_object_get_data(G_OBJECT(item), if (account == item_account) { gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE); generate_send_as_items(GaimConvWindow *win, GaimConversation *deleted_conv) gboolean first_offline = TRUE; gboolean found_online = FALSE; GtkSizeGroup *sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); 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_list_length(gaim_connections_get_all()) < 2) { /* Now make sure we don't have any Offline entries. */ gboolean found_offline = FALSE; for (convs = gaim_get_conversations(); conv = (GaimConversation *)convs->data; account = gaim_conversation_get_account(conv); if (account != NULL && account->gc == NULL) { gtkwin->menu.send_as = NULL; /* Build the Send As menu */ gtkwin->menu.send_as = gtk_menu_item_new_with_mnemonic(_("_Send As")); gtk_widget_show(gtkwin->menu.send_as); gtk_menu_shell_insert(GTK_MENU_SHELL(gtkwin->menu.menubar), gtkwin->menu.send_as, 2); gtk_menu_item_set_submenu(GTK_MENU_ITEM(gtkwin->menu.send_as), menu); /* Fill it with entries. */ for (gcs = gaim_connections_get_all(); gcs != NULL; gcs = gcs->next) { GdkPixbuf *pixbuf, *scale; gc = (GaimConnection *)gcs->data; /* Create a pixmap for the protocol icon. */ pixbuf = create_prpl_icon(gc->account); scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR); /* Now convert it to GtkImage */ image = gtk_image_new_from_pixbuf(scale); gtk_size_group_add_widget(sg, image); g_object_unref(G_OBJECT(scale)); g_object_unref(G_OBJECT(pixbuf)); account = gaim_connection_get_account(gc); menuitem = gtk_radio_menu_item_new_with_label(group, gaim_account_get_username(account)); group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(menuitem)); /* Do some evil, see some evil, speak some evil. */ box = gtk_hbox_new(FALSE, 0); label = gtk_bin_get_child(GTK_BIN(menuitem)); gtk_container_remove(GTK_CONTAINER(menuitem), label); gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 4); gtk_container_add(GTK_CONTAINER(menuitem), box); /* Set our data and callbacks. */ g_object_set_data(G_OBJECT(menuitem), "user_data", win); g_object_set_data(G_OBJECT(menuitem), "gaim_account", gc->account); g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(menu_conv_sel_send_cb), NULL); 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(); GdkPixbuf *pixbuf, *scale; conv = (GaimConversation *)convs->data; if (conv == deleted_conv) account = gaim_conversation_get_account(conv); if (account != NULL && account->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); /* Create a pixmap for the protocol icon. */ pixbuf = create_prpl_icon(account); scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, /* Now convert it to GtkImage */ image = gtk_image_new_from_pixbuf(scale); gtk_size_group_add_widget(sg, image); if (scale != NULL) g_object_unref(scale); if (pixbuf != NULL) g_object_unref(pixbuf); menuitem = gtk_radio_menu_item_new_with_label(group, group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(menuitem)); /* Do some evil, see some evil, speak some evil. */ box = gtk_hbox_new(FALSE, 0); label = gtk_bin_get_child(GTK_BIN(menuitem)); gtk_container_remove(GTK_CONTAINER(menuitem), label); gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 4); gtk_container_add(GTK_CONTAINER(menuitem), box); gtk_widget_set_sensitive(menuitem, FALSE); g_object_set_data(G_OBJECT(menuitem), "user_data", win); g_object_set_data(G_OBJECT(menuitem), "gaim_account", account); g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(menu_conv_sel_send_cb), NULL); 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); generate_invite_user_names(GaimConnection *gc) GaimBlistNode *gnode,*cnode,*bnode; static GList *tmp = NULL; tmp = g_list_append(NULL, ""); for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) for(cnode = gnode->child; cnode; cnode = cnode->next) { if(!GAIM_BLIST_NODE_IS_CONTACT(cnode)) for(bnode = cnode->child; bnode; bnode = bnode->next) { if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) buddy = (GaimBuddy *)bnode; if (buddy->account == gc->account && GAIM_BUDDY_IS_ONLINE(buddy)) tmp = g_list_append(tmp, buddy->name); get_chat_buddy_status_icon(GaimConvChat *chat, const char *name, GaimConvChatBuddyFlags flags) GdkPixbuf *pixbuf, *scale, *scale2; const char *image = NULL; if (flags & GAIM_CBFLAGS_FOUNDER) { } else if (flags & GAIM_CBFLAGS_OP) { } else if (flags & GAIM_CBFLAGS_HALFOP) { } else if (flags & GAIM_CBFLAGS_VOICE) { } else if ((!flags) && gaim_conv_chat_is_user_ignored(chat, name)) { filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); pixbuf = gdk_pixbuf_new_from_file(filename, NULL); scale = gdk_pixbuf_scale_simple(pixbuf, 15, 15, GDK_INTERP_BILINEAR); if (flags && gaim_conv_chat_is_user_ignored(chat, name)) { filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "ignored.png", NULL); pixbuf = gdk_pixbuf_new_from_file(filename, NULL); scale2 = gdk_pixbuf_scale_simple(pixbuf, 15, 15, GDK_INTERP_BILINEAR); gdk_pixbuf_composite(scale2, scale, 0, 0, 15, 15, 0, 0, 1, 1, GDK_INTERP_BILINEAR, 192); add_chat_buddy_common(GaimConversation *conv, const char *name) GaimGtkConversation *gtkconv; GaimGtkChatPane *gtkchat; GaimConvChatBuddyFlags flags; chat = GAIM_CONV_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))); flags = gaim_conv_chat_user_get_flags(chat, name); pixbuf = get_chat_buddy_status_icon(chat, name, flags); gtk_list_store_append(ls, &iter); gtk_list_store_set(ls, &iter, CHAT_USERS_ICON_COLUMN, pixbuf, CHAT_USERS_NAME_COLUMN, name, CHAT_USERS_FLAGS_COLUMN, flags, -1); gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(ls), CHAT_USERS_NAME_COLUMN, tab_complete(GaimConversation *conv) GaimGtkConversation *gtkconv; GtkTextIter cursor, word_start, start_buffer; char *entered, *partial = NULL; gboolean command = FALSE; gtkconv = GAIM_GTK_CONVERSATION(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)); /* if there's nothing there just return */ if (!gtk_text_iter_compare(&cursor, &start_buffer)) return (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) ? TRUE : FALSE; text = gtk_text_buffer_get_text(gtkconv->entry_buffer, &start_buffer, /* 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); prefix = gaim_gtk_get_cmd_prefix(); if (start == -1 && (strlen(text) >= strlen(prefix)) && !strncmp(text, prefix, strlen(prefix))) { gtk_text_iter_forward_chars(&word_start, strlen(prefix)); entered = gtk_text_buffer_get_text(gtkconv->entry_buffer, &word_start, if (!g_utf8_strlen(entered, -1)) { return (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) ? TRUE : FALSE; nick_partial = g_malloc(strlen(entered)+1); list = gaim_cmd_list(conv); } else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { chat = GAIM_CONV_CHAT(conv); list = gaim_conv_chat_get_users(chat); for (l = list; l; l = l->next) { GaimConvChatBuddy *cb = l->data; strncpy(nick_partial, name, strlen(entered)); nick_partial[strlen(entered)] = '\0'; if(gaim_utf8_strcasecmp(nick_partial, entered)) /* if we're here, it's a possible completion */ if (most_matched == -1) { * this will only get called once, since from now * on most_matched is >= 0 most_matched = strlen(name); partial = g_strdup(name); char *tmp = g_strdup(name); while (gaim_utf8_strcasecmp(tmp, partial)) { partial[most_matched] = '\0'; if(most_matched < strlen(tmp)) tmp[most_matched] = '\0'; matches = g_list_insert_sorted(matches, name, (GCompareFunc)gaim_utf8_strcasecmp); /* we're only here if we're doing new style */ /* if there weren't any matches, return */ /* if matches isn't set partials won't be either */ return (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) ? TRUE : FALSE; gtk_text_buffer_delete(gtkconv->entry_buffer, &word_start, &cursor); /* 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); gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, matches = g_list_remove(matches, matches->data); * there were lots of matches, fill in as much as possible * and display all of them char *addthis = g_malloc0(1); addthis = g_strconcat(tmp, matches->data, " ", NULL); matches = g_list_remove(matches, matches->data); gaim_conversation_write(conv, NULL, addthis, GAIM_MESSAGE_NO_LOG, gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, partial, -1); static GtkItemFactoryEntry menu_items[] = { N_("/_Conversation"), NULL, NULL, 0, "<Branch>" }, { N_("/Conversation/New Instant _Message..."), "<CTL>M", menu_new_conv_cb, 0, "<StockItem>", GAIM_STOCK_IM }, { "/Conversation/sep0", NULL, NULL, 0, "<Separator>" }, { N_("/Conversation/_Find..."), NULL, menu_find_cb, 0, "<StockItem>", GTK_STOCK_FIND }, { N_("/Conversation/View _Log"), NULL, menu_view_log_cb, 0, NULL }, { N_("/Conversation/_Save As..."), NULL, menu_save_as_cb, 0, "<StockItem>", GTK_STOCK_SAVE_AS }, { N_("/Conversation/Clear"), "<CTL>L", menu_clear_cb, 0, "<StockItem>", GTK_STOCK_CLEAR }, { "/Conversation/sep1", NULL, NULL, 0, "<Separator>" }, { N_("/Conversation/Se_nd File..."), NULL, menu_send_file_cb, 0, "<StockItem>", GAIM_STOCK_FILE_TRANSFER }, { N_("/Conversation/Add Buddy _Pounce..."), NULL, menu_add_pounce_cb, { N_("/Conversation/_Get Info"), "<CTL>O", menu_get_info_cb, 0, "<StockItem>", GAIM_STOCK_INFO }, { N_("/Conversation/_Warn..."), NULL, menu_warn_cb, 0, "<StockItem>", GAIM_STOCK_WARN }, { N_("/Conversation/In_vite..."), NULL, menu_invite_cb, 0, "<StockItem>", GAIM_STOCK_INVITE }, { "/Conversation/sep2", NULL, NULL, 0, "<Separator>" }, { N_("/Conversation/Al_ias..."), NULL, menu_alias_cb, 0, "<StockItem>", GAIM_STOCK_EDIT }, { N_("/Conversation/_Block..."), NULL, menu_block_cb, 0, "<StockItem>", GAIM_STOCK_BLOCK }, { N_("/Conversation/_Add..."), NULL, menu_add_remove_cb, 0, "<StockItem>", GTK_STOCK_ADD }, { N_("/Conversation/_Remove..."), NULL, menu_add_remove_cb, 0, "<StockItem>", GTK_STOCK_REMOVE }, { "/Conversation/sep3", NULL, NULL, 0, "<Separator>" }, { N_("/Conversation/Insert Lin_k..."), NULL, menu_insert_link_cb, 0, "<StockItem>", GAIM_STOCK_LINK }, { N_("/Conversation/Insert Imag_e..."), NULL, menu_insert_image_cb, 0, "<StockItem>", GAIM_STOCK_IMAGE }, { "/Conversation/sep4", NULL, NULL, 0, "<Separator>" }, { N_("/Conversation/_Close"), NULL, menu_close_conv_cb, 0, "<StockItem>", GTK_STOCK_CLOSE }, { N_("/_Options"), NULL, NULL, 0, "<Branch>" }, { N_("/Options/Enable _Logging"), NULL, menu_logging_cb, 0, "<CheckItem>" }, { N_("/Options/Enable _Sounds"), NULL, menu_sounds_cb, 0, "<CheckItem>" }, { N_("/Options/Show Formatting _Toolbar"), NULL, menu_toolbar_cb, 0, "<CheckItem>" }, { N_("/Options/Show Ti_mestamps"), "F2", menu_timestamps_cb, 0, "<CheckItem>" }, static const int menu_item_count = sizeof(menu_items) / sizeof(*menu_items); item_factory_translate_func (const char *path, gpointer func_data) setup_menubar(GaimConvWindow *win) GtkAccelGroup *accel_group; gtkwin = GAIM_GTK_WINDOW(win); accel_group = gtk_accel_group_new (); gtk_window_add_accel_group (GTK_WINDOW (gtkwin->window), accel_group); g_object_unref (accel_group); gtkwin->menu.item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", accel_group); gtk_item_factory_set_translate_func(gtkwin->menu.item_factory, item_factory_translate_func, gtk_item_factory_create_items(gtkwin->menu.item_factory, menu_item_count, g_signal_connect(G_OBJECT(accel_group), "accel-changed", G_CALLBACK(gaim_gtk_save_accels_cb), NULL); gtk_item_factory_get_widget(gtkwin->menu.item_factory, "<main>"); gtk_item_factory_get_widget(gtkwin->menu.item_factory, N_("/Conversation/View Log")); gtk_item_factory_get_widget(gtkwin->menu.item_factory, N_("/Conversation/Send File...")); gtkwin->menu.add_pounce = gtk_item_factory_get_widget(gtkwin->menu.item_factory, N_("/Conversation/Add Buddy Pounce...")); gtk_item_factory_get_widget(gtkwin->menu.item_factory, N_("/Conversation/Get Info")); gtk_item_factory_get_widget(gtkwin->menu.item_factory, N_("/Conversation/Warn...")); gtk_item_factory_get_widget(gtkwin->menu.item_factory, N_("/Conversation/Invite...")); gtk_item_factory_get_widget(gtkwin->menu.item_factory, N_("/Conversation/Alias...")); gtk_item_factory_get_widget(gtkwin->menu.item_factory, N_("/Conversation/Block...")); gtk_item_factory_get_widget(gtkwin->menu.item_factory, N_("/Conversation/Add...")); gtk_item_factory_get_widget(gtkwin->menu.item_factory, N_("/Conversation/Remove...")); gtkwin->menu.insert_link = gtk_item_factory_get_widget(gtkwin->menu.item_factory, N_("/Conversation/Insert Link...")); gtkwin->menu.insert_image = gtk_item_factory_get_widget(gtkwin->menu.item_factory, N_("/Conversation/Insert Image...")); gtk_item_factory_get_widget(gtkwin->menu.item_factory, N_("/Options/Enable Logging")); gtk_item_factory_get_widget(gtkwin->menu.item_factory, N_("/Options/Enable Sounds")); gtkwin->menu.show_formatting_toolbar = gtk_item_factory_get_widget(gtkwin->menu.item_factory, N_("/Options/Show Formatting Toolbar")); gtkwin->menu.show_timestamps = gtk_item_factory_get_widget(gtkwin->menu.item_factory, N_("/Options/Show Timestamps")); generate_send_as_items(win, NULL); gtk_widget_show(gtkwin->menu.menubar); return gtkwin->menu.menubar; gaim_gtkconv_button_new(const char *icon, const char *text, const char *tooltip, GtkTooltips *tooltips, void *callback, void *data) buttons = gaim_prefs_get_int("/gaim/gtk/conversations/button_type"); button = gaim_pixbuf_button_from_stock( (buttons == GAIM_BUTTON_IMAGE ? NULL : text), (buttons == GAIM_BUTTON_TEXT ? NULL : icon), gtk_tooltips_set_tip(tooltips, button, tooltip, NULL); gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(callback), data); setup_im_buttons(GaimConversation *conv, GtkWidget *parent) GaimGtkConversation *gtkconv; GaimButtonStyle button_type; gtkconv = GAIM_GTK_CONVERSATION(conv); gc = gaim_conversation_get_gc(conv); /* Remove anything else in our parent */ children = gtk_container_get_children(GTK_CONTAINER(parent)); while (children != NULL) { if(children->data != gtkim->icon_container) gtk_container_remove(GTK_CONTAINER(parent), children->data); children = g_list_remove(children, children->data); /* The buttons, from left to right */ gtkim->warn = gaim_gtkconv_button_new(GAIM_STOCK_WARN, _("Warn"), gtkconv->tooltips, warn_cb, conv); gtk_box_pack_start(GTK_BOX(parent), gtkim->warn, TRUE, TRUE, 0); gtk_size_group_add_widget(gtkconv->sg, gtkim->warn); gtkim->block = gaim_gtkconv_button_new(GAIM_STOCK_BLOCK, _("Block"), gtkconv->tooltips, block_cb, conv); gtk_box_pack_start(GTK_BOX(parent), gtkim->block, TRUE, TRUE, 0); gtk_size_group_add_widget(gtkconv->sg, gtkim->block); gtkim->send_file = gaim_gtkconv_button_new(GAIM_STOCK_FILE_TRANSFER, _("Send File"), _("Send a file to the user"), gtkconv->tooltips, send_file_cb, conv); gtk_box_pack_start(GTK_BOX(parent), gtkim->send_file, TRUE, TRUE, 0); gtk_size_group_add_widget(gtkconv->sg, gtkim->send_file); gtkconv->add = gaim_gtkconv_button_new(GTK_STOCK_ADD, _("Add"), _("Add the user to your buddy list"), gtkconv->tooltips, add_remove_cb, conv); gtk_box_pack_start(GTK_BOX(parent), gtkconv->add, TRUE, TRUE, 0); gtk_size_group_add_widget(gtkconv->sg, gtkconv->add); gtkconv->remove = gaim_gtkconv_button_new(GTK_STOCK_REMOVE, _("Remove"), _("Remove the user from your buddy list"), gtkconv->tooltips, add_remove_cb, conv); gtk_box_pack_start(GTK_BOX(parent), gtkconv->remove, TRUE, TRUE, 0); gtk_size_group_add_widget(gtkconv->sg, gtkconv->remove); gtkconv->info = gaim_gtkconv_button_new(GAIM_STOCK_INFO, _("Info"), _("Get the user's information"), gtkconv->tooltips, info_cb, conv); gtk_box_pack_start(GTK_BOX(parent), gtkconv->info, TRUE, TRUE, 0); gtk_size_group_add_widget(gtkconv->sg, gtkconv->info); gtkconv->send = gaim_gtkconv_button_new(GAIM_STOCK_SEND, _("Send"), gtkconv->tooltips, send_cb, conv); gtk_box_pack_end(GTK_BOX(parent), gtkconv->send, FALSE, FALSE, 0); gtkim->sep2 = gtk_vseparator_new(); gtk_box_pack_end(GTK_BOX(parent), gtkim->sep2, FALSE, TRUE, 0); gtk_widget_show(gtkim->sep2); gaim_gtkconv_update_buttons_by_protocol(conv); /* Check if the buttons should be visible or not */ button_type = gaim_prefs_get_int("/gaim/gtk/conversations/button_type"); if (button_type == GAIM_BUTTON_NONE) setup_chat_buttons(GaimConversation *conv, GtkWidget *parent) GaimGtkConversation *gtkconv; GaimGtkChatPane *gtkchat; GaimButtonStyle button_type; gtkconv = GAIM_GTK_CONVERSATION(conv); gtkchat = gtkconv->u.chat; gc = gaim_conversation_get_gc(conv); /* Remove anything else in our parent */ children = gtk_container_get_children(GTK_CONTAINER(parent)); while (children != NULL) { gtk_container_remove(GTK_CONTAINER(parent), children->data); children = g_list_remove(children, children->data); /* The buttons, from left to right */ gtkchat->invite = gaim_gtkconv_button_new(GAIM_STOCK_INVITE, _("Invite"), gtkconv->tooltips, invite_cb, conv); gtk_box_pack_start(GTK_BOX(parent), gtkchat->invite, TRUE, TRUE, 0); gtk_size_group_add_widget(gtkconv->sg, gtkchat->invite); gtkconv->add = gaim_gtkconv_button_new(GTK_STOCK_ADD, _("Add"), _("Add the chat to your buddy list"), gtkconv->tooltips, add_remove_cb, conv); gtk_box_pack_start(GTK_BOX(parent), gtkconv->add, TRUE, TRUE, 0); gtk_size_group_add_widget(gtkconv->sg, gtkconv->add); gtkconv->remove = gaim_gtkconv_button_new(GTK_STOCK_REMOVE, _("Remove"), _("Remove the chat from your buddy list"), gtkconv->tooltips, add_remove_cb, conv); gtk_box_pack_start(GTK_BOX(parent), gtkconv->remove, TRUE, TRUE, 0); gtk_size_group_add_widget(gtkconv->sg, gtkconv->remove); gtkconv->send = gaim_gtkconv_button_new(GAIM_STOCK_SEND, _("Send"), gtkconv->tooltips, send_cb, conv); gtk_box_pack_end(GTK_BOX(parent), gtkconv->send, FALSE, FALSE, 0); gtk_size_group_add_widget(gtkconv->sg, gtkconv->send); gtkchat->sep = gtk_vseparator_new(); gtk_box_pack_end(GTK_BOX(parent), gtkchat->sep, FALSE, TRUE, 0); gtk_widget_show(gtkchat->sep); gaim_gtkconv_update_buttons_by_protocol(conv); /* Check if the buttons should be visible or not */ button_type = gaim_prefs_get_int("/gaim/gtk/conversations/button_type"); if (button_type == GAIM_BUTTON_NONE) gtk_widget_hide(gtkconv->bbox); gtk_widget_show(gtkconv->bbox); static void topic_callback(GtkWidget *w, GaimConversation *conv) GaimPluginProtocolInfo *prpl_info = NULL; GaimGtkConversation *gtkconv; GaimGtkChatPane *gtkchat; const char *current_topic; gc = gaim_conversation_get_gc(conv); if(!gc || !(prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl))) if(prpl_info->set_chat_topic == NULL) gtkconv = GAIM_GTK_CONVERSATION(conv); gtkchat = gtkconv->u.chat; new_topic = gtk_entry_get_text(GTK_ENTRY(gtkchat->topic_text)); current_topic = gaim_conv_chat_get_topic(GAIM_CONV_CHAT(conv)); if(current_topic && !g_utf8_collate(new_topic, current_topic)) prpl_info->set_chat_topic(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), sort_chat_users(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer userdata) GaimConvChatBuddyFlags f1 = 0, f2 = 0; char *user1 = NULL, *user2 = NULL; gtk_tree_model_get(model, a, CHAT_USERS_NAME_COLUMN, &user1, CHAT_USERS_FLAGS_COLUMN, &f1, -1); gtk_tree_model_get(model, b, CHAT_USERS_NAME_COLUMN, &user2, CHAT_USERS_FLAGS_COLUMN, &f2, -1); if (user1 == NULL || user2 == NULL) { if (!(user1 == NULL && user2 == NULL)) ret = (user1 == NULL) ? -1: 1; /* sort more important users first */ ret = (f1 > f2) ? -1 : 1; ret = gaim_utf8_strcasecmp(user1, user2); setup_chat_pane(GaimConversation *conv) GaimPluginProtocolInfo *prpl_info = NULL; GaimGtkConversation *gtkconv; GaimGtkChatPane *gtkchat; GtkWidget *vpaned, *hpaned; GList *focus_chain = NULL; gtkconv = GAIM_GTK_CONVERSATION(conv); gtkchat = gtkconv->u.chat; gc = gaim_conversation_get_gc(conv); /* Setup the outer pane. */ vpaned = gtk_vpaned_new(); /* Setup the top part of the pane. */ vbox = gtk_vbox_new(FALSE, 6); gtk_paned_pack1(GTK_PANED(vpaned), vbox, TRUE, TRUE); prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); if (prpl_info->options & OPT_PROTO_CHAT_TOPIC) hbox = gtk_hbox_new(FALSE, 6); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); label = gtk_label_new(_("Topic:")); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); gtkchat->topic_text = gtk_entry_new(); if(prpl_info->set_chat_topic == NULL) { gtk_editable_set_editable(GTK_EDITABLE(gtkchat->topic_text), FALSE); g_signal_connect(GTK_OBJECT(gtkchat->topic_text), "activate", G_CALLBACK(topic_callback), conv); gtk_box_pack_start(GTK_BOX(hbox), gtkchat->topic_text, TRUE, TRUE, 0); gtk_widget_show(gtkchat->topic_text); /* Setup the horizontal pane. */ hpaned = gtk_hpaned_new(); gtk_box_pack_start(GTK_BOX(vbox), hpaned, TRUE, TRUE, 0); /* 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_AUTOMATIC, GTK_POLICY_ALWAYS); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(gtkconv->sw), gtk_paned_pack1(GTK_PANED(hpaned), gtkconv->sw, TRUE, TRUE); gtk_widget_set_size_request(gtkconv->sw, gaim_prefs_get_int("/gaim/gtk/conversations/chat/default_width"), gaim_prefs_get_int("/gaim/gtk/conversations/chat/default_height")); g_signal_connect(G_OBJECT(gtkconv->sw), "size-allocate", G_CALLBACK(size_allocate_cb), conv); gtk_widget_show(gtkconv->sw); gtkconv->imhtml = gtk_imhtml_new(NULL, NULL); gtk_widget_set_name(gtkconv->imhtml, "gaim_gtkconv_imhtml"); gtk_container_add(GTK_CONTAINER(gtkconv->sw), gtkconv->imhtml); gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), gaim_prefs_get_bool("/gaim/gtk/conversations/show_timestamps")); g_signal_connect_after(G_OBJECT(gtkconv->imhtml), "button_press_event", G_CALLBACK(entry_stop_rclick_cb), NULL); g_signal_connect(G_OBJECT(gtkconv->imhtml), "key_press_event", G_CALLBACK(refocus_entry_cb), gtkconv); g_signal_connect(G_OBJECT(gtkconv->imhtml), "key_release_event", G_CALLBACK(refocus_entry_cb), gtkconv); gaim_setup_imhtml(gtkconv->imhtml); gtk_widget_show(gtkconv->imhtml); /* Build the right pane. */ lbox = gtk_vbox_new(FALSE, 6); gtk_paned_pack2(GTK_PANED(hpaned), lbox, FALSE, TRUE); /* 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. */ sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(lbox), sw, TRUE, TRUE, 0); ls = gtk_list_store_new(CHAT_USERS_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(ls), CHAT_USERS_NAME_COLUMN, sort_chat_users, NULL, NULL); gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(ls), CHAT_USERS_NAME_COLUMN, list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ls)); rend = gtk_cell_renderer_pixbuf_new(); col = gtk_tree_view_column_new_with_attributes(NULL, rend, "pixbuf", CHAT_USERS_ICON_COLUMN, NULL); gtk_tree_view_column_set_clickable(GTK_TREE_VIEW_COLUMN(col), TRUE); gtk_tree_view_append_column(GTK_TREE_VIEW(list), col); g_signal_connect(G_OBJECT(list), "button_press_event", G_CALLBACK(right_click_chat_cb), conv); g_signal_connect(G_OBJECT(list), "popup-menu", G_CALLBACK(gtkconv_chat_popup_menu_cb), conv); rend = gtk_cell_renderer_text_new(); col = gtk_tree_view_column_new_with_attributes(NULL, rend, "text", CHAT_USERS_NAME_COLUMN, NULL); gtk_tree_view_column_set_clickable(GTK_TREE_VIEW_COLUMN(col), TRUE); 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_container_add(GTK_CONTAINER(sw), list); /* Setup the user list toolbar. */ bbox = gtk_hbox_new(TRUE, 6); gtk_box_pack_start(GTK_BOX(lbox), bbox, FALSE, FALSE, 0); button = gaim_pixbuf_button_from_stock(NULL, GTK_STOCK_REDO, 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 the user"), NULL); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(chat_im_button_cb), conv); button = gaim_pixbuf_button_from_stock(NULL, GAIM_STOCK_IGNORE, 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 the user"), NULL); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(ignore_cb), conv); button = gaim_pixbuf_button_from_stock(NULL, GAIM_STOCK_INFO, 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 the user's information"), NULL); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(info_cb), conv); vbox = gtk_vbox_new(FALSE, 6); gtk_paned_pack2(GTK_PANED(vpaned), vbox, FALSE, TRUE); gtkconv->toolbar = gtk_imhtmltoolbar_new(); gtk_box_pack_start(GTK_BOX(vbox), gtkconv->toolbar, FALSE, FALSE, 0); gtkconv->lower_hbox = gtk_hbox_new(FALSE, 6); gtk_box_pack_start(GTK_BOX(vbox), gtkconv->lower_hbox, TRUE, TRUE, 0); gtk_widget_show(gtkconv->lower_hbox); vbox = gtk_vbox_new(FALSE, 6); gtk_box_pack_end(GTK_BOX(gtkconv->lower_hbox), vbox, TRUE, TRUE, 0); /* Setup the entry widget. * We never show the horizontal scrollbar because it was causing weird * lockups when typing text just as you type the character that would * cause both scrollbars to appear. Definitely seems like a gtk bug. sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); gtkconv->entry = gtk_imhtml_new(NULL, NULL); gtk_widget_set_name(gtkconv->entry, "gaim_gtkconv_entry"); gtk_imhtml_smiley_shortcuts(GTK_IMHTML(gtkconv->entry), gaim_prefs_get_bool("/gaim/gtk/conversations/smiley_shortcuts")); gtk_imhtml_html_shortcuts(GTK_IMHTML(gtkconv->entry), gaim_prefs_get_bool("/gaim/gtk/conversations/html_shortcuts")); gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->entry), gaim_account_get_protocol_name(conv->account)); gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry)); gaim_setup_imhtml(gtkconv->entry); gtk_imhtml_set_editable(GTK_IMHTML(gtkconv->entry), TRUE); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(gtkconv->entry), gtk_widget_set_size_request(gtkconv->entry, -1, gaim_prefs_get_int("/gaim/gtk/conversations/chat/entry_height")); g_object_set_data(G_OBJECT(gtkconv->entry_buffer), "user_data", conv); g_signal_connect(G_OBJECT(gtkconv->entry), "key_press_event", G_CALLBACK(entry_key_press_cb), 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), "size-allocate", G_CALLBACK(size_allocate_cb), conv); if (gaim_prefs_get_bool("/gaim/gtk/conversations/spellcheck")) gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(gtkconv->entry)); gtk_imhtmltoolbar_attach(GTK_IMHTMLTOOLBAR(gtkconv->toolbar), gtk_container_add(GTK_CONTAINER(sw), GTK_WIDGET(gtkconv->entry)); gtk_widget_show(gtkconv->entry); /* Setup the bottom button box. */ gtkconv->bbox = gtk_hbox_new(FALSE, 6); gtk_box_pack_start(GTK_BOX(vbox), gtkconv->bbox, FALSE, FALSE, 0); setup_chat_buttons(conv, gtkconv->bbox); * Focus for chat windows should be as follows: * Tab title -> chat topic -> conversation scrollback -> user list -> * user list buttons -> entry -> buttons at bottom focus_chain = g_list_prepend(focus_chain, gtkconv->bbox); focus_chain = g_list_prepend(focus_chain, gtkconv->entry); gtk_container_set_focus_chain(GTK_CONTAINER(vbox), focus_chain); setup_im_pane(GaimConversation *conv) GaimGtkConversation *gtkconv; GList *focus_chain = NULL; gtkconv = GAIM_GTK_CONVERSATION(conv); /* Setup the outer pane. */ paned = gtk_vpaned_new(); /* Setup the top part of the pane. */ vbox = gtk_vbox_new(FALSE, 6); gtk_paned_pack1(GTK_PANED(paned), vbox, TRUE, TRUE); /* Setup the gtkimhtml widget. */ gtkconv->sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkconv->sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(gtkconv->sw), gtk_box_pack_start(GTK_BOX(vbox), gtkconv->sw, TRUE, TRUE, 0); gtk_widget_set_size_request(gtkconv->sw, gaim_prefs_get_int("/gaim/gtk/conversations/im/default_width"), gaim_prefs_get_int("/gaim/gtk/conversations/im/default_height")); g_signal_connect(G_OBJECT(gtkconv->sw), "size-allocate", G_CALLBACK(size_allocate_cb), conv); gtk_widget_show(gtkconv->sw); gtkconv->imhtml = gtk_imhtml_new(NULL, NULL); gtk_widget_set_name(gtkconv->imhtml, "gaim_gtkconv_imhtml"); 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); g_signal_connect(G_OBJECT(gtkconv->imhtml), "key_press_event", G_CALLBACK(refocus_entry_cb), gtkconv); g_signal_connect(G_OBJECT(gtkconv->imhtml), "key_release_event", G_CALLBACK(refocus_entry_cb), gtkconv); gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), gaim_prefs_get_bool("/gaim/gtk/conversations/show_timestamps")); gaim_setup_imhtml(gtkconv->imhtml); gtk_widget_show(gtkconv->imhtml); vbox2 = gtk_vbox_new(FALSE, 6); gtk_paned_pack2(GTK_PANED(paned), vbox2, FALSE, TRUE); gtkconv->toolbar = gtk_imhtmltoolbar_new(); gtk_box_pack_start(GTK_BOX(vbox2), gtkconv->toolbar, FALSE, FALSE, 0); /* Setup the entry widget. * We never show the horizontal scrollbar because it was causing weird * lockups when typing text just as you type the character that would * cause both scrollbars to appear. Definitely seems like a gtk bug. gtkconv->lower_hbox = gtk_hbox_new(FALSE, 6); gtk_box_pack_start(GTK_BOX(vbox2), gtkconv->lower_hbox, TRUE, TRUE, 0); gtk_widget_show(gtkconv->lower_hbox); vbox2 = gtk_vbox_new(FALSE, 6); gtk_box_pack_end(GTK_BOX(gtkconv->lower_hbox), vbox2, TRUE, TRUE, 0); sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), gtk_box_pack_start(GTK_BOX(vbox2), sw, TRUE, TRUE, 0); gtkconv->entry = gtk_imhtml_new(NULL, NULL); gtk_widget_set_name(gtkconv->entry, "gaim_gtkconv_entry"); gtk_imhtml_smiley_shortcuts(GTK_IMHTML(gtkconv->entry), gaim_prefs_get_bool("/gaim/gtk/conversations/smiley_shortcuts")); gtk_imhtml_html_shortcuts(GTK_IMHTML(gtkconv->entry), gaim_prefs_get_bool("/gaim/gtk/conversations/html_shortcuts")); gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->entry), gaim_account_get_protocol_name(conv->account)); gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry)); gaim_setup_imhtml(gtkconv->entry); gtk_imhtml_set_editable(GTK_IMHTML(gtkconv->entry), TRUE); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(gtkconv->entry), gtk_widget_set_size_request(gtkconv->entry, -1, gaim_prefs_get_int("/gaim/gtk/conversations/im/entry_height")); g_object_set_data(G_OBJECT(gtkconv->entry_buffer), "user_data", conv); g_signal_connect(G_OBJECT(gtkconv->entry), "key_press_event", G_CALLBACK(entry_key_press_cb), 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), "size-allocate", G_CALLBACK(size_allocate_cb), conv); 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); if (gaim_prefs_get_bool("/gaim/gtk/conversations/spellcheck")) gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(gtkconv->entry)); gtk_container_add(GTK_CONTAINER(sw), GTK_WIDGET(gtkconv->entry)); gtk_widget_show(gtkconv->entry); gtk_imhtmltoolbar_attach(GTK_IMHTMLTOOLBAR(gtkconv->toolbar), /* had to move this after the imtoolbar is attached so that the * signals get fired to toggle the buttons on the toolbar as well. /* Setup the bottom button box. */ gtkconv->bbox = gtk_hbox_new(FALSE, 6); gtk_box_pack_start(GTK_BOX(vbox2), gtkconv->bbox, FALSE, FALSE, 0); setup_im_buttons(conv, gtkconv->bbox); gtkconv->u.im->animate = gaim_prefs_get_bool("/gaim/gtk/conversations/im/animate_buddy_icons"); gtkconv->u.im->show_icon = TRUE; * Focus for IM windows should be as follows: * Tab title -> conversation scrollback -> entry -> buttons at bottom focus_chain = g_list_prepend(focus_chain, gtkconv->bbox); focus_chain = g_list_prepend(focus_chain, gtkconv->entry); gtk_container_set_focus_chain(GTK_CONTAINER(vbox2), focus_chain); conv_dnd_recv(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, GtkSelectionData *sd, guint info, guint t, GaimConvWindow *win = conv->window; if (sd->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE)) memcpy(&n, sd->data, sizeof(n)); if (GAIM_BLIST_NODE_IS_CONTACT(n)) b = gaim_contact_get_priority_buddy((GaimContact*)n); else if (GAIM_BLIST_NODE_IS_BUDDY(n)) * If we already have an open conversation with this buddy, then * just move the conv to this window. Otherwise, create a new * conv and add it to this window. c = gaim_find_conversation(b->name); oldwin = gaim_conversation_get_window(c); index = gaim_conversation_get_index(c); gaim_conv_window_remove_conversation(oldwin, index); gaim_conv_window_add_conversation(win, c); c = gaim_conversation_new(GAIM_CONV_IM, b->account, b->name); gaim_conv_window_add_conversation(win, c); /* Make this conversation the active conversation */ index = gaim_conversation_get_index(c); gaim_conv_window_switch_conversation(win, index); gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); else if (sd->target == gdk_atom_intern("application/x-im-contact", FALSE)) if (gaim_gtk_parse_x_im_contact(sd->data, FALSE, &account, &protocol, &username, NULL)) gaim_notify_error(NULL, NULL, _("You are not currently signed on with an account that " "can add that buddy."), NULL); c = gaim_conversation_new(GAIM_CONV_IM, account, username); gaim_conv_window_add_conversation(win, c); if (username != NULL) g_free(username); if (protocol != NULL) g_free(protocol); gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); else if (sd->target == gdk_atom_intern("text/uri-list", FALSE)) { GList *files = gaim_uri_list_extract_filenames(sd->data); for(tmp = files; tmp != NULL ; tmp = g_list_next(tmp)) { gchar *filename = tmp->data; /* XXX - Make ft API support creating a transfer with more than one file */ if (g_file_test(filename, G_FILE_TEST_EXISTS) && !g_file_test(filename, G_FILE_TEST_IS_DIR) && gaim_conversation_get_type(conv) == GAIM_CONV_IM) { serv_send_file(gaim_conversation_get_gc(conv), gaim_conversation_get_name(conv), filename); /* XXX - Attempt to load this file into gdk_pixbuf, or otherwise determine if it is an image. If it is, offer * the choice of a) sending this file b) inserting this file as an IM image or c) setting this file as a custom * buddy icon for this buddy */ gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); gtk_drag_finish(dc, FALSE, FALSE, t); /************************************************************************** **************************************************************************/ gaim_gtk_new_window(GaimConvWindow *win) gtkwin = g_malloc0(sizeof(GaimGtkWindow)); gtkwin->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_role(GTK_WINDOW(gtkwin->window), "conversation"); gtk_window_set_resizable(GTK_WINDOW(gtkwin->window), TRUE); gtk_container_set_border_width(GTK_CONTAINER(gtkwin->window), 0); GTK_WINDOW(gtkwin->window)->allow_shrink = TRUE; g_signal_connect(G_OBJECT(gtkwin->window), "delete_event", G_CALLBACK(close_win_cb), win); g_signal_connect(G_OBJECT(gtkwin->window), "focus_in_event", G_CALLBACK(focus_win_cb), win); /* Create the notebook. */ gtkwin->notebook = gtk_notebook_new(); pos = gaim_prefs_get_int("/gaim/gtk/conversations/tab_side"); gtk_notebook_set_tab_hborder(GTK_NOTEBOOK(gtkwin->notebook), 0); gtk_notebook_set_tab_vborder(GTK_NOTEBOOK(gtkwin->notebook), 0); 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_notebook_set_show_tabs(GTK_NOTEBOOK(gtkwin->notebook), FALSE); gtk_notebook_set_show_border(GTK_NOTEBOOK(gtkwin->notebook), FALSE); gtk_widget_show(gtkwin->notebook); g_signal_connect(G_OBJECT(gtkwin->notebook), "switch_page", G_CALLBACK(before_switch_conv_cb), win); 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); 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); gaim_gtk_destroy_window(GaimConvWindow *win) GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(win); gtk_widget_destroy(gtkwin->window); g_object_unref(G_OBJECT(gtkwin->menu.item_factory)); gaim_gtk_show(GaimConvWindow *win) GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(win); gtk_widget_show(gtkwin->window); gaim_gtk_hide(GaimConvWindow *win) GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(win); gtk_widget_hide(gtkwin->window); gaim_gtk_raise(GaimConvWindow *win) GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(win); gtk_widget_show(gtkwin->window); gtk_window_deiconify(GTK_WINDOW(gtkwin->window)); gdk_window_raise(gtkwin->window->window); gaim_gtk_flash(GaimConvWindow *win) GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(win); wgaim_conv_im_blink(gtkwin->window); gaim_gtk_switch_conversation(GaimConvWindow *win, unsigned int index) gtkwin = GAIM_GTK_WINDOW(win); gtk_notebook_set_current_page(GTK_NOTEBOOK(gtkwin->notebook), index); static const GtkTargetEntry te[] = {"GAIM_BLIST_NODE", GTK_TARGET_SAME_APP, GTK_IMHTML_DRAG_NUM}, {"application/x-im-contact", 0, GTK_IMHTML_DRAG_NUM + 1} gaim_gtk_add_conversation(GaimConvWindow *win, GaimConversation *conv) GaimGtkConversation *gtkconv, *focus_gtkconv; GaimConversation *focus_conv; GtkWidget *tabby, *menu_tabby; GaimConversationType conv_type; name = gaim_conversation_get_name(conv); conv_type = gaim_conversation_get_type(conv); gtkwin = GAIM_GTK_WINDOW(win); if (conv->ui_data != NULL) { gtkconv = (GaimGtkConversation *)conv->ui_data; tab_cont = gtkconv->tab_cont; gtkconv = g_malloc0(sizeof(GaimGtkConversation)); /* Setup some initial variables. */ gtkconv->sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); gtkconv->tooltips = gtk_tooltips_new(); if (conv_type == GAIM_CONV_IM) { gtkconv->u.im = g_malloc0(sizeof(GaimGtkImPane)); gtkconv->u.im->a_virgin = TRUE; pane = setup_im_pane(conv); else if (conv_type == GAIM_CONV_CHAT) { gtkconv->u.chat = g_malloc0(sizeof(GaimGtkChatPane)); pane = setup_chat_pane(conv); if (conv_type == GAIM_CONV_CHAT) g_free(gtkconv->u.chat); else if (conv_type == GAIM_CONV_IM) g_free(gtkconv->u.im); /* Setup drag-and-drop */ GTK_DEST_DEFAULT_MOTION | te, sizeof(te) / sizeof(GtkTargetEntry), GTK_DEST_DEFAULT_MOTION | te, sizeof(te) / sizeof(GtkTargetEntry), gtk_drag_dest_set(gtkconv->imhtml, 0, te, sizeof(te) / sizeof(GtkTargetEntry), gtk_drag_dest_set(gtkconv->entry, 0, te, sizeof(te) / sizeof(GtkTargetEntry), g_signal_connect(G_OBJECT(pane), "drag_data_received", G_CALLBACK(conv_dnd_recv), conv); g_signal_connect(G_OBJECT(gtkconv->imhtml), "drag_data_received", G_CALLBACK(conv_dnd_recv), conv); g_signal_connect(G_OBJECT(gtkconv->entry), "drag_data_received", G_CALLBACK(conv_dnd_recv), conv); /* Setup the container for the tab. */ gtkconv->tab_cont = tab_cont = gtk_vbox_new(FALSE, 6); gtk_container_set_border_width(GTK_CONTAINER(tab_cont), 6); gtk_container_add(GTK_CONTAINER(tab_cont), pane); gtkconv->make_sound = TRUE; gtkconv->show_formatting_toolbar = gaim_prefs_get_bool( "/gaim/gtk/conversations/show_formatting_toolbar"); if (gtkconv->show_formatting_toolbar) gtk_widget_show(gtkconv->toolbar); gtkconv->show_timestamps = gaim_prefs_get_bool( "/gaim/gtk/conversations/show_timestamps"); gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), gtkconv->show_timestamps); g_signal_connect_swapped(G_OBJECT(pane), "focus", G_CALLBACK(gtk_widget_grab_focus), gtkconv->tabby = tabby = gtk_hbox_new(FALSE, 6); gtkconv->menu_tabby = menu_tabby = gtk_hbox_new(FALSE, 6); gtkconv->close = gtk_button_new(); gtk_widget_set_size_request(GTK_WIDGET(gtkconv->close), 16, 16); gtk_button_set_relief(GTK_BUTTON(gtkconv->close), GTK_RELIEF_NONE); close_image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU); gtk_widget_show(close_image); gtk_container_add(GTK_CONTAINER(gtkconv->close), close_image); 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); * I love Galeon. They have a fix for that stupid annoying visible * border bug. I love you guys! -- ChipX86 g_signal_connect(G_OBJECT(gtkconv->close), "state_changed", G_CALLBACK(tab_close_button_state_changed_cb), NULL); gtkconv->icon = gtk_image_new(); gtkconv->menu_icon = gtk_image_new(); gtkconv->tab_label = gtk_label_new(gaim_conversation_get_title(conv)); gtkconv->menu_label = gtk_label_new(gaim_conversation_get_title(conv)); gtk_misc_set_alignment(GTK_MISC(gtkconv->tab_label), 0.00, 0.5); gtk_misc_set_padding(GTK_MISC(gtkconv->tab_label), 4, 0); /* Pack it all together. */ gtk_box_pack_start(GTK_BOX(tabby), gtkconv->icon, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(menu_tabby), gtkconv->menu_icon, gtk_widget_show_all(gtkconv->icon); gtk_widget_show_all(gtkconv->menu_icon); gtk_box_pack_start(GTK_BOX(tabby), gtkconv->tab_label, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(menu_tabby), gtkconv->menu_label, TRUE, TRUE, 0); gtk_widget_show(gtkconv->tab_label); gtk_widget_show(gtkconv->menu_label); gtk_misc_set_alignment(GTK_MISC(gtkconv->menu_label), 0, 0); gtk_box_pack_start(GTK_BOX(tabby), gtkconv->close, FALSE, FALSE, 0); if (gaim_prefs_get_bool("/gaim/gtk/conversations/close_on_tabs")) gtk_widget_show(gtkconv->close); gtk_widget_show(menu_tabby); if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) gaim_gtkconv_update_buddy_icon(conv); /* Add this pane to the conversation's notebook. */ gtk_notebook_append_page_menu(GTK_NOTEBOOK(gtkwin->notebook), tab_cont, tabby, menu_tabby); gtk_widget_show(tab_cont); if (gaim_conv_window_get_conversation_count(win) == 1) { /* Er, bug in notebooks? Switch to the page manually. */ gtk_notebook_set_current_page(GTK_NOTEBOOK(gtkwin->notebook), 0); gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gtkwin->notebook), gaim_prefs_get_bool("/gaim/gtk/conversations/tabs")); gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gtkwin->notebook), TRUE); focus_conv = g_list_nth_data(gaim_conv_window_get_conversations(win), gtk_notebook_get_current_page(GTK_NOTEBOOK(gtkwin->notebook))); focus_gtkconv = GAIM_GTK_CONVERSATION(focus_conv); gtk_widget_grab_focus(focus_gtkconv->entry); g_object_unref(gtkconv->tab_cont); if (gaim_conv_window_get_conversation_count(win) == 1) g_timeout_add(0, (GSourceFunc)update_send_as_selection, win); gaim_gtk_remove_conversation(GaimConvWindow *win, GaimConversation *conv) GaimGtkConversation *gtkconv; GaimConversationType conv_type; conv_type = gaim_conversation_get_type(conv); 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)); gtk_notebook_remove_page(GTK_NOTEBOOK(gtkwin->notebook), index); /* go back to tabless if need be */ if (gaim_conv_window_get_conversation_count(win) <= 2) { gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gtkwin->notebook), gaim_prefs_get_bool("/gaim/gtk/conversations/tabs")); /* If this window is setup with an inactive gc, regenerate the menu. */ if (conv_type == GAIM_CONV_IM && gaim_conversation_get_gc(conv) == NULL) { generate_send_as_items(win, conv); gaim_gtk_move_conversation(GaimConvWindow *win, GaimConversation *conv, GaimGtkConversation *gtkconv; gtkwin = GAIM_GTK_WINDOW(win); gtkconv = GAIM_GTK_CONVERSATION(conv); if (new_index > gaim_conversation_get_index(conv)) gtk_notebook_reorder_child(GTK_NOTEBOOK(gtkwin->notebook), gtkconv->tab_cont, new_index); gaim_gtk_get_active_index(const GaimConvWindow *win) gtkwin = GAIM_GTK_WINDOW(win); index = gtk_notebook_get_current_page(GTK_NOTEBOOK(gtkwin->notebook)); * A fix, because the first conversation may be active, but not * appear in the notebook just yet. -- ChipX86 return (index == -1 ? 0 : index); gaim_gtk_has_focus(GaimConvWindow *win) gboolean has_focus = FALSE; gtkwin = GAIM_GTK_WINDOW(win); g_object_get(G_OBJECT(gtkwin->window), "has-toplevel-focus", &has_focus, NULL); static GaimConvWindowUiOps window_ui_ops = gaim_gtk_conversations_get_conv_ui_ops, gaim_gtk_switch_conversation, gaim_gtk_add_conversation, gaim_gtk_remove_conversation, gaim_gtk_move_conversation, gaim_gtk_get_active_index, gaim_gtk_conversations_get_win_ui_ops(void) /************************************************************************** * Conversation UI operations **************************************************************************/ gaim_gtkconv_destroy(GaimConversation *conv) GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv); /* If the "Save Conversation" or "Save Icon" dialogs are open then close them */ gaim_request_close_with_handle(conv); gtk_widget_destroy(gtkconv->tab_cont); g_object_unref(gtkconv->tab_cont); if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { if (gtkconv->u.im->icon_timer != 0) g_source_remove(gtkconv->u.im->icon_timer); if (gtkconv->u.im->anim != NULL) g_object_unref(G_OBJECT(gtkconv->u.im->anim)); else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { gtk_object_sink(GTK_OBJECT(gtkconv->tooltips)); gaim_gtkconv_write_im(GaimConversation *conv, const char *who, const char *message, GaimMessageFlags flags, GaimGtkConversation *gtkconv; gtkconv = GAIM_GTK_CONVERSATION(conv); gaimwin = gaim_conversation_get_window(conv); gtkwin = GAIM_GTK_WINDOW(gaimwin); g_object_get(G_OBJECT(gtkwin->window), "has-toplevel-focus", &has_focus, NULL); if (!(flags & GAIM_MESSAGE_NO_LOG) && gaim_prefs_get_bool("/gaim/gtk/conversations/im/raise_on_events")) { gaim_conv_window_raise(gaim_conversation_get_window(conv)); /* Play a sound, if specified in prefs. */ if (gtkconv->make_sound && !((gaim_conv_window_get_active_conversation(gaimwin) == conv) && !gaim_prefs_get_bool("/gaim/gtk/sound/conv_focus") && has_focus)) { if (flags & GAIM_MESSAGE_RECV) { if (gtkconv->u.im->a_virgin && gaim_prefs_get_bool("/gaim/gtk/sound/enabled/first_im_recv")) { gaim_sound_play_event(GAIM_SOUND_FIRST_RECEIVE); gaim_sound_play_event(GAIM_SOUND_RECEIVE); gaim_sound_play_event(GAIM_SOUND_SEND); gtkconv->u.im->a_virgin = FALSE; gaim_conversation_write(conv, who, message, flags, mtime); gaim_gtkconv_write_chat(GaimConversation *conv, const char *who, const char *message, GaimMessageFlags flags, time_t mtime) GaimGtkConversation *gtkconv; gtkconv = GAIM_GTK_CONVERSATION(conv); gaimwin = gaim_conversation_get_window(conv); gtkwin = GAIM_GTK_WINDOW(gaimwin); g_object_get(G_OBJECT(gtkwin->window), "has-toplevel-focus", &has_focus, NULL); /* Play a sound, if specified in prefs. */ if (gtkconv->make_sound && !((gaim_conv_window_get_active_conversation(gaimwin) == conv) && !gaim_prefs_get_bool("/gaim/gtk/sound/conv_focus") && has_focus) && !(flags & GAIM_MESSAGE_DELAYED) && !(flags & GAIM_MESSAGE_SYSTEM)) { if (!(flags & GAIM_MESSAGE_WHISPER) && (flags & GAIM_MESSAGE_SEND)) gaim_sound_play_event(GAIM_SOUND_CHAT_YOU_SAY); else if (flags & GAIM_MESSAGE_RECV) { if ((flags & GAIM_MESSAGE_NICK) && gaim_prefs_get_bool("/gaim/gtk/sound/enabled/nick_said")) { gaim_sound_play_event(GAIM_SOUND_CHAT_NICK); gaim_sound_play_event(GAIM_SOUND_CHAT_SAY); if (gaim_prefs_get_bool("/gaim/gtk/conversations/chat/color_nicks")) flags |= GAIM_MESSAGE_COLORIZE; /* Raise the window, if specified in prefs. */ if (!(flags & GAIM_MESSAGE_NO_LOG) && /* we may want to change this */ gaim_prefs_get_bool("/gaim/gtk/conversations/chat/raise_on_events")) { gaim_conv_window_raise(gaim_conversation_get_window(conv)); gaim_conversation_write(conv, who, message, flags, mtime); gaim_gtkconv_write_conv(GaimConversation *conv, const char *who, const char *message, GaimMessageFlags flags, GaimGtkConversation *gtkconv; int gtk_font_options = 0; size_t length = strlen(message) + 1; gtkconv = GAIM_GTK_CONVERSATION(conv); gc = gaim_conversation_get_gc(conv); win = gaim_conversation_get_window(conv); if (!(flags & GAIM_MESSAGE_NO_LOG) && ((gaim_conversation_get_type(conv) == GAIM_CONV_CHAT && gaim_prefs_get_bool("/gaim/gtk/conversations/chat/raise_on_events")) || (gaim_conversation_get_type(conv) == GAIM_CONV_IM && gaim_prefs_get_bool("/gaim/gtk/conversations/im/raise_on_events")))) { gaim_conv_window_show(win); if (gtk_text_buffer_get_char_count(gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->imhtml)))) gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR>", 0); if(time(NULL) > mtime + 20*60) /* show date if older than 20 minutes */ strftime(mdate, sizeof(mdate), "%Y-%m-%d %H:%M:%S", localtime(&mtime)); strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime)); sml_attrib = g_strdup_printf("sml=\"%s\"", gaim_account_get_protocol_name(conv->account)); gtk_font_options ^= GTK_IMHTML_NO_COMMENTS; if (gaim_prefs_get_bool("/gaim/gtk/conversations/ignore_colors")) gtk_font_options ^= GTK_IMHTML_NO_COLOURS; if (gaim_prefs_get_bool("/gaim/gtk/conversations/ignore_fonts")) gtk_font_options ^= GTK_IMHTML_NO_FONTS; if (gaim_prefs_get_bool("/gaim/gtk/conversations/ignore_font_sizes")) gtk_font_options ^= GTK_IMHTML_NO_SIZES; /* this is gonna crash one day, I can feel it. */ if (GAIM_PLUGIN_PROTOCOL_INFO(gaim_find_prpl(gaim_account_get_protocol_id(conv->account)))->options & OPT_PROTO_USE_POINTSIZE) { gtk_font_options ^= GTK_IMHTML_USE_POINTSIZE; if (flags & GAIM_MESSAGE_SYSTEM) { if (gaim_prefs_get_bool("/gaim/gtk/conversations/show_timestamps")) g_snprintf(buf, BUF_LONG, "<FONT SIZE=\"2\">(%s)</FONT> <B>%s</B>", g_snprintf(buf, BUF_LONG, "<B>%s</B>", message); g_snprintf(buf2, sizeof(buf2), "<FONT %s><FONT SIZE=\"2\"><!--(%s) --></FONT><B>%s</B></FONT>", sml_attrib ? sml_attrib : "", mdate, message); gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, 0); /* Add the message to a conversations scrollback buffer */ conv->history = g_string_append(conv->history, buf); conv->history = g_string_append(conv->history, "<BR>\n"); } else if (flags & GAIM_MESSAGE_ERROR) { if (gaim_prefs_get_bool("/gaim/gtk/conversations/show_timestamps")) g_snprintf(buf, BUF_LONG, "<FONT COLOR=\"#ff0000\"><FONT SIZE=\"2\">(%s)</FONT> <B>%s</B></FONT>", g_snprintf(buf, BUF_LONG, "<FONT COLOR=\"#ff0000\"><B>%s</B></FONT>", message); g_snprintf(buf2, sizeof(buf2), "<FONT COLOR=\"#ff0000\"><FONT %s><FONT SIZE=\"2\"><!--(%s) --></FONT><B>%s</B></FONT></FONT>", sml_attrib ? sml_attrib : "", mdate, message); gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, 0); /* Add the message to a conversations scrollback buffer */ conv->history = g_string_append(conv->history, buf); conv->history = g_string_append(conv->history, "<BR>\n"); } else if (flags & GAIM_MESSAGE_NO_LOG) { g_snprintf(buf, BUF_LONG, "<B><FONT %s COLOR=\"#777777\">%s</FONT></B>", sml_attrib ? sml_attrib : "", message); gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf, 0); char *new_message = g_memdup(message, length); char *who_escaped = (who ? g_markup_escape_text(who, strlen(who)) : g_strdup("")); if (flags & GAIM_MESSAGE_WHISPER) { /* If we're whispering, it's not an autoresponse. */ if (gaim_message_meify(new_message, -1)) { g_snprintf(str, 1024, "***%s", who_escaped); strcpy(color, "#6C2585"); g_snprintf(str, 1024, "*%s*:", who_escaped); strcpy(color, "#00FF00"); if (gaim_message_meify(new_message, -1)) { if (flags & GAIM_MESSAGE_AUTO_RESP) g_snprintf(str, 1024, "%s ***%s", AUTO_RESPONSE, who_escaped); g_snprintf(str, 1024, "***%s", who_escaped); if (flags & GAIM_MESSAGE_NICK) strcpy(color, "#AF7F00"); strcpy(color, "#062585"); if (flags & GAIM_MESSAGE_AUTO_RESP) g_snprintf(str, 1024, "%s %s", who_escaped, AUTO_RESPONSE); g_snprintf(str, 1024, "%s:", who_escaped); if (flags & GAIM_MESSAGE_NICK) strcpy(color, "#AF7F00"); else if (flags & GAIM_MESSAGE_RECV) { if (flags & GAIM_MESSAGE_COLORIZE) { for (u = who; *u != '\0'; u++) strcpy(color, nick_colors[m]); strcpy(color, RECV_COLOR); else if (flags & GAIM_MESSAGE_SEND) strcpy(color, SEND_COLOR); gaim_debug_error("gtkconv", "message missing flags\n"); strcpy(color, "#000000"); if (gaim_prefs_get_bool("/gaim/gtk/conversations/show_timestamps")) g_snprintf(buf, BUF_LONG, "<FONT COLOR=\"%s\" %s><FONT SIZE=\"2\">(%s)</FONT> " "<B>%s</B></FONT> ", color, sml_attrib ? sml_attrib : "", mdate, str); g_snprintf(buf, BUF_LONG, "<FONT COLOR=\"%s\" %s><B>%s</B></FONT> ", color, sml_attrib ? sml_attrib : "", str); g_snprintf(buf2, BUF_LONG, "<FONT COLOR=\"%s\" %s><FONT SIZE=\"2\"><!--(%s) --></FONT>" color, sml_attrib ? sml_attrib : "", mdate, str); gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), char *pre = g_strdup_printf("<font %s>", sml_attrib ? sml_attrib : ""); int pre_len = strlen(pre); int post_len = strlen(post); with_font_tag = g_malloc(length + pre_len + post_len + 1); strcpy(with_font_tag, pre); memcpy(with_font_tag + pre_len, new_message, length); strcpy(with_font_tag + pre_len + length, post); length += pre_len + post_len; with_font_tag = g_memdup(new_message, length); gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), with_font_tag, gtk_font_options); conv->history = g_string_append(conv->history, buf); conv->history = g_string_append(conv->history, new_message); conv->history = g_string_append(conv->history, "<BR>\n"); gaim_gtkconv_chat_add_user(GaimConversation *conv, const char *user, gboolean new_arrival) GaimGtkConversation *gtkconv; GaimGtkChatPane *gtkchat; chat = GAIM_CONV_CHAT(conv); gtkconv = GAIM_GTK_CONVERSATION(conv); gtkchat = gtkconv->u.chat; num_users = g_list_length(gaim_conv_chat_get_users(chat)); g_snprintf(tmp, sizeof(tmp), ngettext("%d person in room", "%d people in room", gtk_label_set_text(GTK_LABEL(gtkchat->count), tmp); if (gtkconv->make_sound && new_arrival) gaim_sound_play_event(GAIM_SOUND_CHAT_JOIN); add_chat_buddy_common(conv, user); gaim_gtkconv_chat_add_users(GaimConversation *conv, GList *users) GaimGtkConversation *gtkconv; GaimGtkChatPane *gtkchat; chat = GAIM_CONV_CHAT(conv); gtkconv = GAIM_GTK_CONVERSATION(conv); gtkchat = gtkconv->u.chat; num_users = g_list_length(gaim_conv_chat_get_users(chat)); g_snprintf(tmp, sizeof(tmp), ngettext("%d person in room", "%d people in room", gtk_label_set_text(GTK_LABEL(gtkchat->count), tmp); for (l = users; l != NULL; l = l->next) { add_chat_buddy_common(conv, (char *)l->data); gaim_gtkconv_chat_rename_user(GaimConversation *conv, const char *old_name, GaimGtkConversation *gtkconv; GaimGtkChatPane *gtkchat; chat = GAIM_CONV_CHAT(conv); gtkconv = GAIM_GTK_CONVERSATION(conv); gtkchat = gtkconv->u.chat; model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CHAT_USERS_NAME_COLUMN, &val, -1); if (!gaim_utf8_strcasecmp(old_name, val)) { gtk_list_store_remove(GTK_LIST_STORE(model), &iter); f = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter); if (!gaim_conv_chat_find_user(chat, old_name)) add_chat_buddy_common(conv, new_name); gaim_gtkconv_chat_remove_user(GaimConversation *conv, const char *user) GaimGtkConversation *gtkconv; GaimGtkChatPane *gtkchat; chat = GAIM_CONV_CHAT(conv); gtkconv = GAIM_GTK_CONVERSATION(conv); gtkchat = gtkconv->u.chat; num_users = g_list_length(gaim_conv_chat_get_users(chat)) - 1; model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CHAT_USERS_NAME_COLUMN, &val, -1); if (!gaim_utf8_strcasecmp(user, val)) { gtk_list_store_remove(GTK_LIST_STORE(model), &iter); f = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter); if (!gaim_conv_chat_find_user(chat, user)) g_snprintf(tmp, sizeof(tmp), ngettext("%d person in room", "%d people in room", gtk_label_set_text(GTK_LABEL(gtkchat->count), tmp); gaim_sound_play_event(GAIM_SOUND_CHAT_LEAVE); gaim_gtkconv_chat_remove_users(GaimConversation *conv, GList *users) GaimGtkConversation *gtkconv; GaimGtkChatPane *gtkchat; chat = GAIM_CONV_CHAT(conv); gtkconv = GAIM_GTK_CONVERSATION(conv); gtkchat = gtkconv->u.chat; num_users = g_list_length(gaim_conv_chat_get_users(chat)) - for (l = users; l != NULL; l = l->next) { model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CHAT_USERS_NAME_COLUMN, &val, -1); if (!gaim_utf8_strcasecmp((char *)l->data, val)) { #if GTK_CHECK_VERSION(2,2,0) f = gtk_list_store_remove(GTK_LIST_STORE(model), &iter); gtk_list_store_remove(GTK_LIST_STORE(model), &iter); f = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter); f = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter); g_snprintf(tmp, sizeof(tmp), ngettext("%d person in room", "%d people in room", gtk_label_set_text(GTK_LABEL(gtkchat->count), tmp); gaim_gtkconv_chat_update_user(GaimConversation *conv, const char *user) GaimGtkConversation *gtkconv; GaimGtkChatPane *gtkchat; chat = GAIM_CONV_CHAT(conv); gtkconv = GAIM_GTK_CONVERSATION(conv); gtkchat = gtkconv->u.chat; model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CHAT_USERS_NAME_COLUMN, &val, -1); if (!gaim_utf8_strcasecmp(user, val)) { gtk_list_store_remove(GTK_LIST_STORE(model), &iter); f = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter); if (!gaim_conv_chat_find_user(chat, user)) add_chat_buddy_common(conv, user); gaim_gtkconv_has_focus(GaimConversation *conv) win = gaim_conversation_get_window(conv); gtkwin = GAIM_GTK_WINDOW(win); g_object_get(G_OBJECT(gtkwin->window), "has-toplevel-focus", &has_focus, NULL); gaim_gtkconv_updated(GaimConversation *conv, GaimConvUpdateType type) GaimGtkConversation *gtkconv; GaimGtkChatPane *gtkchat; g_return_if_fail( conv != NULL ); win = gaim_conversation_get_window(conv); gtkwin = GAIM_GTK_WINDOW(win); gtkconv = GAIM_GTK_CONVERSATION(conv); if (type == GAIM_CONV_UPDATE_ACCOUNT) gaim_conversation_autoset_title(conv); if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) gaim_gtkconv_update_buddy_icon(conv); gaim_gtkconv_update_buttons_by_protocol(conv); g_timeout_add(0, (GSourceFunc)update_send_as_selection, win); smiley_themeize(gtkconv->imhtml); else if (type == GAIM_CONV_UPDATE_TYPING || type == GAIM_CONV_UPDATE_UNSEEN || type == GAIM_CONV_UPDATE_TITLE) GaimConnection *gc = gaim_conversation_get_gc(conv); if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) if (!gc || ((gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) && gaim_conv_chat_has_left(GAIM_CONV_CHAT(conv)))) title = g_strdup_printf("(%s)", gaim_conversation_get_title(conv)); title = g_strdup(gaim_conversation_get_title(conv)); if (!GTK_WIDGET_REALIZED(gtkconv->tab_label)) gtk_widget_realize(gtkconv->tab_label); if (im != NULL && gaim_conv_im_get_typing_state(im) == GAIM_TYPING) strcpy(color, "#47A046"); else if (im != NULL && gaim_conv_im_get_typing_state(im) == GAIM_TYPED) strcpy(color, "#D1940C"); else if (gaim_conversation_get_unseen(conv) == GAIM_UNSEEN_NICK) strcpy(color, "#0D4E91"); else if (gaim_conversation_get_unseen(conv) == GAIM_UNSEEN_TEXT) strcpy(color, "#DF421E"); else if (gaim_conversation_get_unseen(conv) == GAIM_UNSEEN_EVENT) strcpy(color, "#868272"); html_title = gaim_escape_html(title); label = g_strdup_printf("<span color=\"%s\">%s</span>", gtk_label_set_markup(GTK_LABEL(gtkconv->tab_label), label); gtk_label_set_text(GTK_LABEL(gtkconv->tab_label), title); if (conv == gaim_conv_window_get_active_conversation(win)) update_typing_icon(conv); if (type == GAIM_CONV_UPDATE_TITLE) { gtk_label_set_text(GTK_LABEL(gtkconv->menu_label), title); if (conv == gaim_conv_window_get_active_conversation(win)) gtk_window_set_title(GTK_WINDOW(gtkwin->window), title); else if (type == GAIM_CONV_UPDATE_TOPIC) chat = GAIM_CONV_CHAT(conv); gtkchat = gtkconv->u.chat; topic = gaim_conv_chat_get_topic(chat); gtk_entry_set_text(GTK_ENTRY(gtkchat->topic_text), topic ? topic : ""); gtk_tooltips_set_tip(gtkconv->tooltips, gtkchat->topic_text, topic ? topic : "", NULL); else if (type == GAIM_CONV_ACCOUNT_ONLINE || type == GAIM_CONV_ACCOUNT_OFFLINE) gray_stuff_out(gaim_conv_window_get_active_conversation(win)); generate_send_as_items(win, NULL); gaim_conversation_autoset_title(conv); else if (type == GAIM_CONV_UPDATE_AWAY) else if (type == GAIM_CONV_UPDATE_ADD || type == GAIM_CONV_UPDATE_REMOVE || type == GAIM_CONV_UPDATE_CHATLEFT) gaim_conversation_autoset_title(conv); else if (type == GAIM_CONV_UPDATE_ICON) gaim_gtkconv_update_buddy_icon(conv); else if (type == GAIM_CONV_UPDATE_FEATURES) static GaimConversationUiOps conversation_ui_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_add_users, /* chat_add_users */ gaim_gtkconv_chat_rename_user, /* chat_rename_user */ gaim_gtkconv_chat_remove_user, /* chat_remove_user */ gaim_gtkconv_chat_remove_users, /* chat_remove_users */ gaim_gtkconv_chat_update_user, /* chat_update_user */ NULL, /* update_progress */ gaim_gtkconv_has_focus, /* has_focus */ gaim_gtkconv_updated /* updated */ gaim_gtk_conversations_get_conv_ui_ops(void) return &conversation_ui_ops; /************************************************************************** * Public conversation utility functions **************************************************************************/ gaim_gtkconv_update_buddy_icon(GaimConversation *conv) GaimGtkConversation *gtkconv; GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(conv)); int scale_width, scale_height; GtkRequisition requisition; GaimPluginProtocolInfo *prpl_info = NULL; GaimButtonStyle button_type; g_return_if_fail(conv != NULL); g_return_if_fail(GAIM_IS_GTK_CONVERSATION(conv)); g_return_if_fail(gaim_conversation_get_type(conv) == GAIM_CONV_IM); gtkconv = GAIM_GTK_CONVERSATION(conv); if (!gtkconv->u.im->show_icon) account = gaim_conversation_get_account(conv); if(account && account->gc) prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(account->gc->prpl); /* Remove the current icon stuff */ if (gtkconv->u.im->icon_container != NULL) gtk_widget_destroy(gtkconv->u.im->icon_container); gtkconv->u.im->icon_container = NULL; if (gtkconv->u.im->anim != NULL) g_object_unref(G_OBJECT(gtkconv->u.im->anim)); gtkconv->u.im->anim = NULL; if (gtkconv->u.im->icon_timer != 0) g_source_remove(gtkconv->u.im->icon_timer); gtkconv->u.im->icon_timer = 0; if (gtkconv->u.im->iter != NULL) g_object_unref(G_OBJECT(gtkconv->u.im->iter)); gtkconv->u.im->iter = NULL; if (!gaim_prefs_get_bool("/gaim/gtk/conversations/im/show_buddy_icons")) if (gaim_conversation_get_gc(conv) == NULL) icon = gaim_conv_im_get_icon(GAIM_CONV_IM(conv)); data = gaim_buddy_icon_get_data(icon, &len); /* 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. */ /* gdk-pixbuf-loader was leaky? is it still? */ 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 = g_fopen(filename, "wb"))) fwrite(data, 1, len, file); gtkconv->u.im->anim = gdk_pixbuf_animation_new_from_file(filename, &err); /* make sure we remove the file as soon as possible */ gaim_debug(GAIM_DEBUG_ERROR, "gtkconv", "Buddy icon error: %s\n", err->message); if (!gtkconv->u.im->anim) if (gdk_pixbuf_animation_is_static_image(gtkconv->u.im->anim)) { gtkconv->u.im->iter = NULL; buf = gdk_pixbuf_animation_get_static_image(gtkconv->u.im->anim); gdk_pixbuf_animation_get_iter(gtkconv->u.im->anim, NULL); /* LEAK */ buf = gdk_pixbuf_animation_iter_get_pixbuf(gtkconv->u.im->iter); if (gtkconv->u.im->animate) get_icon_scale_size(gtkconv->u.im->anim, prpl_info ? &prpl_info->icon_spec : NULL, &scale_width, &scale_height); scale = gdk_pixbuf_scale_simple(buf, MAX(gdk_pixbuf_get_width(buf) * scale_width / gdk_pixbuf_animation_get_width(gtkconv->u.im->anim), 1), MAX(gdk_pixbuf_get_height(buf) * scale_height / gdk_pixbuf_animation_get_height(gtkconv->u.im->anim), 1), gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100); g_object_unref(G_OBJECT(scale)); gtkconv->u.im->icon_container = gtk_vbox_new(FALSE, 0); 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->u.im->icon_container), frame, event = gtk_event_box_new(); gtk_container_add(GTK_CONTAINER(frame), event); g_signal_connect(G_OBJECT(event), "button-press-event", G_CALLBACK(icon_menu), conv); gtkconv->u.im->icon = gtk_image_new_from_pixmap(pm, bm); gtk_widget_set_size_request(gtkconv->u.im->icon, scale_width, scale_height); gtk_container_add(GTK_CONTAINER(event), gtkconv->u.im->icon); gtk_widget_show(gtkconv->u.im->icon); g_object_unref(G_OBJECT(pm)); g_object_unref(G_OBJECT(bm)); button_type = gaim_prefs_get_int("/gaim/gtk/conversations/button_type"); /* the button seems to get its size before the box, so... */ gtk_widget_size_request(gtkconv->send, &requisition); if (button_type == GAIM_BUTTON_NONE || requisition.height * 1.5 < scale_height) { gtk_box_pack_start(GTK_BOX(gtkconv->lower_hbox), gtkconv->u.im->icon_container, FALSE, FALSE, 0); /* gtk_box_reorder_child(GTK_BOX(gtkconv->lower_hbox), vbox, 0); */ gtk_box_pack_start(GTK_BOX(gtkconv->bbox), gtkconv->u.im->icon_container, FALSE, FALSE, 0); gtk_box_reorder_child(GTK_BOX(gtkconv->bbox), gtkconv->u.im->icon_container, 0); gtk_widget_show(gtkconv->u.im->icon_container); /* The buddy icon code needs badly to be fixed. */ buf = gdk_pixbuf_animation_get_static_image(gtkconv->u.im->anim); if(conv == gaim_conv_window_get_active_conversation(gaim_conversation_get_window(conv))) gtk_window_set_icon(GTK_WINDOW(gtkwin->window), buf); gaim_gtkconv_update_buttons_by_protocol(GaimConversation *conv) if (!GAIM_IS_GTK_CONVERSATION(conv)) win = gaim_conversation_get_window(conv); if (win != NULL && gaim_conv_window_get_active_conversation(win) == conv) gaim_gtkwin_get_at_xy(int x, int y) GaimConvWindow *win = NULL; gdkwin = gdk_window_at_pointer(&x, &y); gdkwin = gdk_window_get_toplevel(gdkwin); for (l = gaim_get_windows(); l != NULL; l = l->next) { win = (GaimConvWindow *)l->data; if (!GAIM_IS_GTK_WINDOW(win)) gtkwin = GAIM_GTK_WINDOW(win); if (gdkwin == gtkwin->window->window) gaim_gtkconv_get_tab_at_xy(GaimConvWindow *win, int x, int y) gint nb_x, nb_y, x_rel, y_rel; gboolean first_visible = TRUE; if (!GAIM_IS_GTK_WINDOW(win)) gtkwin = GAIM_GTK_WINDOW(win); notebook = GTK_NOTEBOOK(gtkwin->notebook); gdk_window_get_origin(gtkwin->notebook->window, &nb_x, &nb_y); for (l = gaim_conv_window_get_conversations(win), i = 0; GaimConversation *conv = l->data; tab = GAIM_GTK_CONVERSATION(conv)->tab_label; if (!GTK_WIDGET_MAPPED(tab)) 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) if (tab->allocation.y <= y_rel) { if (tab->allocation.y + tab->allocation.height <= y_rel) if (i == gaim_conv_window_get_conversation_count(win) + 1) gaim_gtkconv_get_dest_tab_at_xy(GaimConvWindow *win, int x, int y) gint nb_x, nb_y, x_rel, y_rel; if (!GAIM_IS_GTK_WINDOW(win)) gtkwin = GAIM_GTK_WINDOW(win); notebook = GTK_NOTEBOOK(gtkwin->notebook); gdk_window_get_origin(gtkwin->notebook->window, &nb_x, &nb_y); for (l = gaim_conv_window_get_conversations(win), i = 0; GaimConversation *conv = l->data; tab = GAIM_GTK_CONVERSATION(conv)->tab_label; if (!GTK_WIDGET_MAPPED(tab)) 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) if (tab->allocation.y <= y_rel) { if (tab->allocation.y + (tab->allocation.height / 2) <= y_rel) if (i == gaim_conv_window_get_conversation_count(win) + 1) escape_closes_pref_cb(const char *name, GaimPrefType type, gpointer value, gtk_accel_map_change_entry(N_("<main>/Conversation/Close"), gtk_accel_map_change_entry(N_("<main>/Conversation/Close"), GDK_W, GDK_CONTROL_MASK, TRUE); close_on_tabs_pref_cb(const char *name, GaimPrefType type, gpointer value, GaimGtkConversation *gtkconv; for (l = gaim_get_conversations(); l != NULL; l = l->next) { conv = (GaimConversation *)l->data; if (!GAIM_IS_GTK_CONVERSATION(conv)) gtkconv = GAIM_GTK_CONVERSATION(conv); gtk_widget_show(gtkconv->close); gtk_widget_hide(gtkconv->close); show_timestamps_pref_cb(const char *name, GaimPrefType type, gpointer value, GaimGtkConversation *gtkconv; for (l = gaim_get_conversations(); l != NULL; l = l->next) { conv = (GaimConversation *)l->data; if (!GAIM_IS_GTK_CONVERSATION(conv)) gtkconv = GAIM_GTK_CONVERSATION(conv); gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), (gboolean)GPOINTER_TO_INT(value)); spellcheck_pref_cb(const char *name, GaimPrefType type, gpointer value, GaimGtkConversation *gtkconv; for (cl = gaim_get_conversations(); cl != NULL; cl = cl->next) { conv = (GaimConversation *)cl->data; if (!GAIM_IS_GTK_CONVERSATION(conv)) gtkconv = GAIM_GTK_CONVERSATION(conv); gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(gtkconv->entry)); spell = gtkspell_get_from_text_view(GTK_TEXT_VIEW(gtkconv->entry)); tab_side_pref_cb(const char *name, GaimPrefType type, gpointer value, pos = GPOINTER_TO_INT(value); for (l = gaim_get_windows(); l != NULL; l = l->next) { win = (GaimConvWindow *)l->data; if (!GAIM_IS_GTK_WINDOW(win)) gtkwin = GAIM_GTK_WINDOW(win); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(gtkwin->notebook), pos); html_shortcuts_pref_cb(const char *name, GaimPrefType type, gpointer value, gpointer data) GaimGtkConversation *gtkconv; for(l = gaim_get_conversations(); l != NULL; l = l->next) { conv = (GaimConversation *)l->data; if(!GAIM_IS_GTK_CONVERSATION(conv)) gtkconv = GAIM_GTK_CONVERSATION(conv); gtk_imhtml_html_shortcuts(GTK_IMHTML(gtkconv->entry), (gboolean)GPOINTER_TO_INT(value)); smiley_shortcuts_pref_cb(const char *name, GaimPrefType type, gpointer value, gpointer data) GaimGtkConversation *gtkconv; for(l = gaim_get_conversations(); l != NULL; l = l->next) { conv = (GaimConversation *)l->data; if(!GAIM_IS_GTK_CONVERSATION(conv)) gtkconv = GAIM_GTK_CONVERSATION(conv); gtk_imhtml_smiley_shortcuts(GTK_IMHTML(gtkconv->entry), (gboolean)GPOINTER_TO_INT(value)); show_formatting_toolbar_pref_cb(const char *name, GaimPrefType type, gpointer value, gpointer data) GaimGtkConversation *gtkconv; for (l = gaim_get_conversations(); l != NULL; l = l->next) conv = (GaimConversation *)l->data; if (!GAIM_IS_GTK_CONVERSATION(conv)) gtkconv = GAIM_GTK_CONVERSATION(conv); win = gaim_conversation_get_window(conv); gtkwin = GAIM_GTK_WINDOW(win); gtkconv->show_formatting_toolbar = (gboolean)GPOINTER_TO_INT(value); gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(gtkwin->menu.show_formatting_toolbar), gtkconv->show_formatting_toolbar); if (gtkconv->show_formatting_toolbar) gtk_widget_show(gtkconv->toolbar); gtk_widget_hide(gtkconv->toolbar); button_type_pref_cb(const char *name, GaimPrefType type, gpointer value, gpointer data) GaimGtkConversation *gtkconv; for (l = gaim_get_conversations(); l != NULL; l = l->next) { conv = (GaimConversation *)l->data; gtkconv = GAIM_GTK_CONVERSATION(conv); setup_im_buttons(conv, gtkconv->bbox); gaim_gtkconv_update_buddy_icon(conv); setup_chat_buttons(conv, gtkconv->bbox); animate_buddy_icons_pref_cb(const char *name, GaimPrefType type, gpointer value, gpointer data) GaimGtkConversation *gtkconv; if (!gaim_prefs_get_bool("/gaim/gtk/conversations/im/show_buddy_icons")) /* Set the "animate" flag for each icon based on the new preference */ for (l = gaim_get_ims(); l != NULL; l = l->next) { conv = (GaimConversation *)l->data; gtkconv = GAIM_GTK_CONVERSATION(conv); gtkconv->u.im->animate = GPOINTER_TO_INT(value); /* Now either stop or start animation for the active conversation in each window */ for (l = gaim_get_windows(); l != NULL; l = l->next) { win = (GaimConvWindow *)l->data; conv = gaim_conv_window_get_active_conversation(win); gaim_gtkconv_update_buddy_icon(conv); show_buddy_icons_pref_cb(const char *name, GaimPrefType type, gpointer value, for (l = gaim_get_conversations(); l != NULL; l = l->next) { GaimConversation *conv = l->data; if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) gaim_conversation_foreach(gaim_gtkconv_update_buddy_icon); conv_placement_pref_cb(const char *name, GaimPrefType type, gpointer value, gpointer data) GaimConvPlacementFunc func; if (strcmp(name, "/gaim/gtk/conversations/placement")) func = gaim_conv_placement_get_fnc(value); gaim_conv_placement_set_current_func(func); gaim_gtk_conversations_get_handle(void) gaim_gtk_conversations_init(void) void *handle = gaim_gtk_conversations_get_handle(); gaim_prefs_add_none("/gaim/gtk/conversations"); gaim_prefs_add_bool("/gaim/gtk/conversations/close_on_tabs", TRUE); gaim_prefs_add_bool("/gaim/gtk/conversations/ctrl_enter_sends", FALSE); gaim_prefs_add_bool("/gaim/gtk/conversations/enter_sends", TRUE); gaim_prefs_add_bool("/gaim/gtk/conversations/escape_closes", FALSE); gaim_prefs_add_bool("/gaim/gtk/conversations/send_formatting", FALSE); gaim_prefs_add_bool("/gaim/gtk/conversations/send_bold", FALSE); gaim_prefs_add_bool("/gaim/gtk/conversations/send_italic", FALSE); gaim_prefs_add_bool("/gaim/gtk/conversations/send_underline", FALSE); gaim_prefs_add_bool("/gaim/gtk/conversations/show_timestamps", TRUE); gaim_prefs_add_bool("/gaim/gtk/conversations/spellcheck", TRUE); gaim_prefs_add_bool("/gaim/gtk/conversations/ignore_colors", FALSE); gaim_prefs_add_bool("/gaim/gtk/conversations/ignore_fonts", FALSE); gaim_prefs_add_bool("/gaim/gtk/conversations/ignore_font_sizes", FALSE); gaim_prefs_add_bool("/gaim/gtk/conversations/ignore_formatting", FALSE); gaim_prefs_add_bool("/gaim/gtk/conversations/html_shortcuts", TRUE); gaim_prefs_add_bool("/gaim/gtk/conversations/smiley_shortcuts", FALSE); gaim_prefs_add_bool("/gaim/gtk/conversations/show_formatting_toolbar", TRUE); gaim_prefs_add_bool("/gaim/gtk/conversations/passthrough_unknown_commands", FALSE); gaim_prefs_add_string("/gaim/gtk/conversations/placement", "last"); gaim_prefs_add_int("/gaim/gtk/conversations/placement_number", 1); gaim_prefs_add_string("/gaim/gtk/conversations/bgcolor", ""); gaim_prefs_add_string("/gaim/gtk/conversations/fgcolor", ""); gaim_prefs_add_string("/gaim/gtk/conversations/font_face", ""); gaim_prefs_add_int("/gaim/gtk/conversations/font_size", 3); gaim_prefs_add_bool("/gaim/gtk/conversations/tabs", TRUE); gaim_prefs_add_int("/gaim/gtk/conversations/tab_side", GTK_POS_TOP); gaim_prefs_add_int("/gaim/gtk/conversations/button_type", /* Conversations -> Chat */ gaim_prefs_add_none("/gaim/gtk/conversations/chat"); gaim_prefs_add_bool("/gaim/gtk/conversations/chat/color_nicks", TRUE); gaim_prefs_add_int("/gaim/gtk/conversations/chat/default_width", 410); gaim_prefs_add_int("/gaim/gtk/conversations/chat/default_height", 160); gaim_prefs_add_int("/gaim/gtk/conversations/chat/entry_height", 50); gaim_prefs_add_bool("/gaim/gtk/conversations/chat/raise_on_events", FALSE); /* Conversations -> IM */ gaim_prefs_add_none("/gaim/gtk/conversations/im"); gaim_prefs_add_bool("/gaim/gtk/conversations/im/animate_buddy_icons", TRUE); gaim_prefs_add_int("/gaim/gtk/conversations/im/default_width", 410); gaim_prefs_add_int("/gaim/gtk/conversations/im/default_height", 160); gaim_prefs_add_int("/gaim/gtk/conversations/im/entry_height", 50); gaim_prefs_add_bool("/gaim/gtk/conversations/im/raise_on_events", FALSE); gaim_prefs_add_bool("/gaim/gtk/conversations/im/show_buddy_icons", TRUE); gaim_prefs_connect_callback("/gaim/gtk/conversations/escape_closes", escape_closes_pref_cb, NULL); gaim_prefs_connect_callback("/gaim/gtk/conversations/close_on_tabs", close_on_tabs_pref_cb, NULL); gaim_prefs_connect_callback("/gaim/gtk/conversations/show_timestamps", show_timestamps_pref_cb, NULL); gaim_prefs_connect_callback("/gaim/gtk/conversations/html_shortcuts", html_shortcuts_pref_cb, NULL); gaim_prefs_connect_callback("/gaim/gtk/conversations/smiley_shortcuts", smiley_shortcuts_pref_cb, NULL); gaim_prefs_connect_callback("/gaim/gtk/conversations/show_formatting_toolbar", show_formatting_toolbar_pref_cb, NULL); gaim_prefs_connect_callback("/gaim/gtk/conversations/spellcheck", spellcheck_pref_cb, NULL); gaim_prefs_connect_callback("/gaim/gtk/conversations/tab_side", gaim_prefs_connect_callback("/gaim/gtk/conversations/placement", conv_placement_pref_cb, NULL); gaim_prefs_trigger_callback("/gaim/gtk/conversations/placement"); gaim_prefs_connect_callback("/gaim/gtk/conversations/button_type", button_type_pref_cb, NULL); gaim_prefs_connect_callback("/gaim/gtk/conversations/im/animate_buddy_icons", animate_buddy_icons_pref_cb, NULL); gaim_prefs_connect_callback("/gaim/gtk/conversations/im/show_buddy_icons", show_buddy_icons_pref_cb, NULL); /********************************************************************** **********************************************************************/ gaim_signal_register(handle, "conversation-drag-ended", gaim_marshal_VOID__POINTER_POINTER, NULL, 2, gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_CONV_WINDOW), gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_CONV_WINDOW)); /********************************************************************** **********************************************************************/ gaim_cmd_register("say", "S", GAIM_CMD_P_DEFAULT, GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, say_command_cb, _("say <message>: Send a message normally as if you weren't using a command."), NULL); gaim_cmd_register("me", "S", GAIM_CMD_P_DEFAULT, GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, me_command_cb, _("me <action>: Send an IRC style action to a buddy or chat."), NULL); gaim_cmd_register("debug", "w", GAIM_CMD_P_DEFAULT, GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, debug_command_cb, _("debug <option>: Send various debug information to the current conversation."), NULL); gaim_cmd_register("clear", "", GAIM_CMD_P_DEFAULT, GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, clear_command_cb, _("clear: Clears the conversation scrollback."), NULL); gaim_cmd_register("help", "w", GAIM_CMD_P_DEFAULT, GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, NULL, help_command_cb, _("help <command>: Help on a specific command."), NULL); gaim_gtk_conversations_uninit(void) gaim_signals_unregister_by_instance(gaim_gtk_conversations_get_handle());