Yo.
gtk1-stable
v0_59_9
2003-03-01, Sean Egan
* Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> * 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 <gdk/gdkkeysyms.h> #include "pixmaps/bold.xpm" #include "pixmaps/italic.xpm" #include "pixmaps/underline.xpm" #include "pixmaps/strike.xpm" #include "pixmaps/small.xpm" #include "pixmaps/normal.xpm" #include "pixmaps/big.xpm" #include "pixmaps/fontface.xpm" #include "pixmaps/fgcolor.xpm" #include "pixmaps/bgcolor.xpm" #include "pixmaps/link.xpm" #include "pixmaps/smile_icon.xpm" #include "pixmaps/wood.xpm" #include "pixmaps/save_small.xpm" #include "pixmaps/speaker.xpm" #include "pixmaps/speaker_mute.xpm" #include "pixmaps/image_icon.xpm" #include "pixmaps/luke03.xpm" #include "pixmaps/oneeye.xpm" #include "pixmaps/crazy4.xpm" #include "pixmaps/mrt.xpm" #include "pixmaps/download.xpm" #include "pixmaps/farted.xpm" static gchar *ispell_cmd[] = { "ispell", "-a", NULL }; static gchar *aspell_cmd[] = { "aspell", "--sug-mode=fast","-a", NULL }; GdkPixmap *dark_icon_pm = NULL; GdkBitmap *dark_icon_bm = NULL; GtkWidget *all_convos = NULL; GtkWidget *convo_notebook = NULL; char fontface[128] = { 0 }; char fontxfld[256] = { 0 }; void check_everything(GtkWidget *entry); gboolean keypress_callback(GtkWidget *entry, GdkEventKey * event, struct conversation *c); static void update_icon(struct conversation *); static void remove_icon(struct conversation *); static void update_checkbox(struct conversation *); static void remove_checkbox(struct conversation *); static void update_smilies(struct conversation *c); static void update_fontmode(struct conversation *c); /*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/ void gaim_setup_imhtml_smileys(GtkWidget *imhtml) gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), "C:)", luke03_xpm); gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), "C:-)", luke03_xpm); gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), "O-)", oneeye_xpm); gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ">:)", crazy4_xpm); gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ">:-)", crazy4_xpm); gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-o)))", mrt_xpm); gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-O)))", mrt_xpm); gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), "8-|)", download_xpm); gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), ":-]", farted_xpm); void gaim_setup_imhtml(GtkWidget *imhtml) g_return_if_fail(imhtml != NULL); g_return_if_fail(GTK_IS_IMHTML(imhtml)); if (!(convo_options & OPT_CONVO_SHOW_SMILEY)) gtk_imhtml_show_smileys(GTK_IMHTML(imhtml), FALSE); gtk_signal_connect(GTK_OBJECT(imhtml), "url_clicked", GTK_SIGNAL_FUNC(open_url), NULL); gaim_setup_imhtml_smileys(imhtml); void quiet_set(GtkWidget *tb, int state) gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(tb), state); void set_state_lock(int i) void toggle_sensitive(GtkWidget *widget, GtkWidget *to_toggle) gboolean sensitivity = GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(to_toggle)); gtk_widget_set_sensitive(GTK_WIDGET(to_toggle), FALSE); gtk_widget_set_sensitive(GTK_WIDGET(to_toggle), TRUE); void set_convo_name(struct conversation *c, const char *nname) g_snprintf(c->name, sizeof(c->name), "%s", nname); struct conversation *new_conversation(char *name) c = find_conversation(name); c = (struct conversation *)g_new0(struct conversation, 1); g_snprintf(c->name, sizeof(c->name), "%s", name); if ((logging_options & OPT_LOG_ALL) || find_log_info(c->name)) { fd = open_log_file(c->name); if (!(logging_options & OPT_LOG_STRIP_HTML)) "<HR><BR><H3 Align=Center> ---- New Conversation @ %s ----</H3><BR>\n", fprintf(fd, " ---- New Conversation @ %s ----\n", full_date()); /* do we want to do something here? */ ; c->gc = (struct gaim_connection *)connections->data; c->history = g_string_new(""); c->send_history = g_list_append(NULL, NULL); conversations = g_list_append(conversations, c); plugin_event(event_new_conversation, name, 0, 0, 0); struct conversation *find_conversation(char *name) char *cuser = g_malloc(1024); GList *cnv = conversations; strcpy(cuser, normalize(name)); c = (struct conversation *)cnv->data; if (!g_strcasecmp(cuser, normalize(c->name))) { /* --------------------------------------------------- * Function to remove a log file entry * --------------------------------------------------- void rm_log(struct log_conversation *a) struct conversation *cnv = find_conversation(a->name); log_conversations = g_list_remove(log_conversations, a); if (cnv && !(im_options & OPT_IM_ONE_WINDOW)) struct log_conversation *find_log_info(char *name) char *pname = g_malloc(1024); GList *lc = log_conversations; struct log_conversation *l; strcpy(pname, normalize(name)); l = (struct log_conversation *)lc->data; if (!g_strcasecmp(pname, normalize(l->name))) { void delete_conversation(struct conversation *c) conversations = g_list_remove(conversations, c); gtk_widget_destroy(c->fg_color_dialog); gtk_widget_destroy(c->bg_color_dialog); gtk_widget_destroy(c->font_dialog); gtk_widget_destroy(c->smiley_dialog); gtk_widget_destroy(c->link_dialog); gtk_widget_destroy(c->log_dialog); gtk_widget_destroy(c->save_icon); c->send_history = g_list_first(c->send_history); while (c->send_history) { if (c->send_history->data) g_free(c->send_history->data); c->send_history = c->send_history->next; g_list_free(c->send_history); gtk_timeout_remove(c->typing_timeout); g_string_free(c->history, TRUE); struct gaim_connection *g; GList *cnv = conversations; c = (struct conversation *)cnv->data; gtk_widget_set_sensitive(c->log_button, ((logging_options & OPT_LOG_ALL)) ? FALSE : TRUE); g = (struct gaim_connection *)C->data; c = (struct conversation *)bcs->data; gtk_widget_set_sensitive(c->log_button, ((logging_options & OPT_LOG_ALL)) ? FALSE : void update_font_buttons() GList *cnv = conversations; c = (struct conversation *)cnv->data; gtk_widget_set_sensitive(c->bold, ((font_options & OPT_FONT_BOLD)) ? FALSE : TRUE); gtk_widget_set_sensitive(c->italic, ((font_options & OPT_FONT_ITALIC)) ? FALSE : TRUE); gtk_widget_set_sensitive(c->underline, ((font_options & OPT_FONT_UNDERLINE)) ? FALSE : TRUE); gtk_widget_set_sensitive(c->strike, ((font_options & OPT_FONT_STRIKE)) ? FALSE : TRUE); void update_transparency() GList *cnv = conversations; This func should be uncalled! c = (struct conversation *)cnv->data; gtk_html_set_transparent(GTK_HTML(c->text), (transparent) ? TRUE : FALSE); /*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/ void toggle_loggle(GtkWidget *loggle, struct conversation *c) if (find_log_info(c->name)) rm_log(find_log_info(c->name)); else if (GTK_TOGGLE_BUTTON(loggle)->active) void toggle_sound(GtkWidget *widget, struct conversation *c) c->makesound = !c->makesound; pm = gdk_pixmap_create_from_xpm_d(c->window->window, &bm, &c->window->style->white, c->makesound ? speaker_xpm : speaker_mute_xpm); gtk_pixmap_set(GTK_PIXMAP(c->speaker_p), pm, bm); static void do_save_convo(GtkObject *obj, GtkWidget *wid) struct conversation *c = gtk_object_get_user_data(obj); char *filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(wid)); if (file_is_dir(filename, wid)) if ((!c->is_chat && g_list_find(conversations, c)) || (c->is_chat && g_slist_find(connections, c->gc) && g_slist_find(c->gc->buddy_chats, c))) filename = g_strdup(filename); f = fopen(filename, "w+"); fprintf(f, "%s", c->history->str); void save_convo(GtkWidget *save, struct conversation *c) GtkWidget *window = gtk_file_selection_new(_("Gaim - Save Conversation")); g_snprintf(buf, sizeof(buf), "%s/%s.log", g_get_home_dir(), normalize(c->name)); gtk_file_selection_set_filename(GTK_FILE_SELECTION(window), buf); gtk_object_set_user_data(GTK_OBJECT(GTK_FILE_SELECTION(window)->ok_button), c); gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(window)->ok_button), "clicked", GTK_SIGNAL_FUNC(do_save_convo), window); gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(window)->cancel_button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), (gpointer)window); static void do_insert_image(GtkObject *obj, GtkWidget *wid) struct conversation *c = gtk_object_get_user_data(obj); char *name = gtk_file_selection_get_filename(GTK_FILE_SELECTION(wid)); int id = g_slist_length(c->images) + 1; if (file_is_dir(name, wid)) if ((!c->is_chat && g_list_find(conversations, c))) if (stat(name, &st) != 0) { debug_printf("Could not stat %s\n", name); while (strchr(filename, '/')) filename = strchr(filename, '/') + 1; g_snprintf(buf, sizeof(buf), "<IMG SRC=\"file://%s\" ID=\"%d\" DATASIZE=\"%d\">", filename, id, (int)st.st_size); c->images = g_slist_append(c->images, g_strdup(name)); if (GTK_OLD_EDITABLE(c->entry)->has_selection) { int finish = GTK_OLD_EDITABLE(c->entry)->selection_end_pos; gtk_editable_insert_text(GTK_EDITABLE(c->entry), buf, strlen(buf), &finish); pos = GTK_OLD_EDITABLE(c->entry)->current_pos; gtk_editable_insert_text(GTK_EDITABLE(c->entry), void insert_image(GtkWidget *save, struct conversation *c) GtkWidget *window = gtk_file_selection_new(_("Gaim - Insert Image")); g_snprintf(buf, sizeof(buf), "%s/", g_get_home_dir()); gtk_file_selection_set_filename(GTK_FILE_SELECTION(window), buf); gtk_object_set_user_data(GTK_OBJECT(GTK_FILE_SELECTION(window)->ok_button), c); gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(window)->ok_button), "clicked", GTK_SIGNAL_FUNC(do_insert_image), window); gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(window)->cancel_button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), (gpointer)window); void insert_smiley(GtkWidget *smiley, struct conversation *c) if (GTK_TOGGLE_BUTTON(smiley)->active) show_smiley_dialog(c, smiley); else if (c->smiley_dialog) close_smiley_dialog(smiley, c); int close_callback(GtkWidget *widget, struct conversation *c) if (c->is_chat && (widget == c->close) && !(chat_options & OPT_CHAT_ONE_WINDOW)) { GtkWidget *tmp = c->window; debug_printf("chat clicked close button\n"); debug_printf("conversation close callback\n"); if (convo_options & OPT_CONVO_CHECK_SPELLING) gtkspell_detach(GTK_TEXT(c->entry)); GSList *cn = connections; serv_send_typing(c->gc, c->name, FALSE); struct gaim_connection *gc = cn->data; if (gc->prpl->convo_closed) gc->prpl->convo_closed(gc, c->name); if (im_options & OPT_IM_ONE_WINDOW) { if ((g_list_length(conversations) > 1) || ((convo_options & OPT_CONVO_COMBINE) && (chat_options & OPT_CHAT_ONE_WINDOW) && chats)) { gtk_notebook_remove_page(GTK_NOTEBOOK(convo_notebook), g_list_index(conversations, c)); gtk_widget_destroy(c->window); if (convo_options & OPT_CONVO_COMBINE) { gtk_widget_destroy(c->window); if (chat_options & OPT_CHAT_ONE_WINDOW) { if ((convo_options & OPT_CONVO_COMBINE) && (im_options & OPT_IM_ONE_WINDOW) && (conversations || chats->next)) { gtk_notebook_remove_page(GTK_NOTEBOOK(chat_notebook), g_list_length(conversations)); } else if (g_list_length(chats) > 1) { gtk_notebook_remove_page(GTK_NOTEBOOK(chat_notebook), gtk_widget_destroy(c->window); if (convo_options & OPT_CONVO_COMBINE) { gtk_widget_destroy(c->window); gtk_widget_destroy(c->fg_color_dialog); c->fg_color_dialog = NULL; gtk_widget_destroy(c->bg_color_dialog); c->bg_color_dialog = NULL; gtk_widget_destroy(c->font_dialog); gtk_widget_destroy(c->smiley_dialog); gtk_widget_destroy(c->link_dialog); gtk_widget_destroy(c->log_dialog); chats = g_list_remove(chats, c); serv_chat_leave(c->gc, c->id); void set_font_face(char *newfont, struct conversation *c) sprintf(c->fontxfld, "%s", newfont && *newfont ? newfont : DEFAULT_FONT_XFLD); for (i = 0; i < strlen(c->fontxfld); i++) { if (c->fontxfld[i] == '-') { c->fontface[k++] = c->fontxfld[i]; pre_fontface = g_strconcat("<FONT FACE=\"", c->fontface, "\">", NULL); surround(c->entry, pre_fontface, "</FONT>"); gtk_widget_grab_focus(c->entry); gint delete_all_convo(GtkWidget *w, GdkEventAny *e, gpointer d) struct conversation *c = conversations->data; close_callback(c->close, c); struct conversation *c = chats->data; close_callback(c->close, c); static gint delete_event_convo(GtkWidget *w, GdkEventAny *e, struct conversation *c) void add_callback(GtkWidget *widget, struct conversation *c) struct buddy *b = find_buddy(c->gc, c->name); show_confirm_del(c->gc, c->name); show_add_buddy(c->gc, c->name, NULL, NULL); gtk_widget_grab_focus(c->entry); void block_callback(GtkWidget *widget, struct conversation *c) show_add_perm(c->gc, c->name, FALSE); gtk_widget_grab_focus(c->entry); void warn_callback(GtkWidget *widget, struct conversation *c) show_warn_dialog(c->gc, c->name); gtk_widget_grab_focus(c->entry); void info_callback(GtkWidget *w, struct conversation *c) i = GTK_LIST(c->list)->selection; name = (char *)gtk_object_get_user_data(GTK_OBJECT(i->data)); serv_get_info(c->gc, name); serv_get_info(c->gc, c->name); gtk_widget_grab_focus(c->entry); static void move_next_tab(GtkNotebook *notebook, gboolean chat) int currpage = gtk_notebook_get_current_page(notebook); struct conversation *d = NULL; if ((convo_options & OPT_CONVO_COMBINE) && (im_options & OPT_IM_ONE_WINDOW) && (chat_options & OPT_CHAT_ONE_WINDOW)) convlen = g_list_length(conversations); /* if chat, find next unread chat */ cnv = g_list_nth(chats, currpage - convlen); gtk_notebook_set_page(notebook, convlen + g_list_index(chats, d)); /* else find next unread convo */ cnv = g_list_nth(conversations, currpage); gtk_notebook_set_page(notebook, g_list_index(conversations, d)); if (convo_options & OPT_CONVO_COMBINE) { if (chat && (im_options & OPT_IM_ONE_WINDOW)) { /* if chat find next unread convo */ gtk_notebook_set_page(notebook, g_list_index(conversations, d)); } else if (!chat && (chat_options & OPT_CHAT_ONE_WINDOW)) { /* else find next unread chat */ gtk_notebook_set_page(notebook, convlen + g_list_index(chats, d)); /* if chat find first unread chat */ gtk_notebook_set_page(notebook, convlen + g_list_index(chats, d)); /* else find first unread convo */ gtk_notebook_set_page(notebook, g_list_index(conversations, d)); if (currpage + 1 == g_list_length(notebook->children)) gtk_notebook_set_page(notebook, 0); gtk_notebook_next_page(notebook); gboolean keypress_callback(GtkWidget *entry, GdkEventKey * event, struct conversation *c) if (event->keyval == GDK_Escape) { if (convo_options & OPT_CONVO_ESC_CAN_CLOSE) { gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); close_callback(c->close, c); } else if (event->keyval == GDK_Page_Up) { gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); if(!(event->state & GDK_CONTROL_MASK)) gtk_imhtml_page_up(GTK_IMHTML(c->text)); } else if (event->keyval == GDK_Page_Down) { gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); if(!(event->state & GDK_CONTROL_MASK)) gtk_imhtml_page_down(GTK_IMHTML(c->text)); } else if ((event->keyval == GDK_F2) && (convo_options & OPT_CONVO_F2_TOGGLES)) { gtk_imhtml_show_comments(GTK_IMHTML(c->text), !GTK_IMHTML(c->text)->comments); } else if ((event->keyval == GDK_Return) || (event->keyval == GDK_KP_Enter)) { if ((event->state & GDK_CONTROL_MASK) && (convo_options & OPT_CONVO_CTL_ENTER)) { gtk_signal_emit_by_name(GTK_OBJECT(entry), "activate", c); gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); } else if (!(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK)) && (convo_options & OPT_CONVO_ENTER_SENDS)) { gtk_signal_emit_by_name(GTK_OBJECT(entry), "activate", c); gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); oldpos = pos = gtk_editable_get_position(GTK_EDITABLE(entry)); gtk_editable_insert_text(GTK_EDITABLE(entry), "\n", 1, &pos); gtk_editable_set_position(GTK_EDITABLE(entry), pos + 1); } else if ((event->state & GDK_CONTROL_MASK) && (event->keyval == 'm')) { gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); oldpos = pos = gtk_editable_get_position(GTK_EDITABLE(entry)); gtk_editable_insert_text(GTK_EDITABLE(entry), "\n", 1, &pos); gtk_editable_set_position(GTK_EDITABLE(entry), pos + 1); } else if (event->state & GDK_CONTROL_MASK) { if (!c->send_history->prev) { if (c->send_history->data) g_free(c->send_history->data); c->send_history->data = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1); if (c->send_history->next && c->send_history->next->data) { c->send_history = c->send_history->next; gtk_editable_delete_text (GTK_EDITABLE(entry),0,-1); gtk_editable_insert_text(GTK_EDITABLE(entry), strlen(c->send_history->data), if (c->send_history->prev) { c->send_history = c->send_history->prev; if (c->send_history->data) { gtk_editable_delete_text (GTK_EDITABLE(entry),0,-1); gtk_editable_insert_text (GTK_EDITABLE(entry), c->send_history->data, strlen(c->send_history->data), &pos); if (convo_options & OPT_CONVO_CTL_CHARS) { !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->italic))); do_italic(c->italic, c->entry); gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); case 'u': /* ctl-u is GDK_Clear, which clears the line */ !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON do_underline(c->underline, c->entry); gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); case 'b': /* ctl-b is GDK_Left, which moves backwards */ !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->bold))); do_bold(c->bold, c->entry); gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->strike))); do_strike(c->strike, c->entry); gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); do_small(NULL, c->entry); gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); do_normal(NULL, c->entry); gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->font))); gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); if (convo_options & OPT_CONVO_CTL_SMILEYS) { if (GTK_OLD_EDITABLE(c->entry)->has_selection) { int finish = GTK_OLD_EDITABLE(c->entry)->selection_end_pos; gtk_editable_insert_text(GTK_EDITABLE(c->entry), buf, strlen(buf), &finish); pos = GTK_OLD_EDITABLE(c->entry)->current_pos; gtk_editable_insert_text(GTK_EDITABLE(c->entry), gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); if (event->keyval == 'l') { gtk_imhtml_clear(GTK_IMHTML(c->text)); g_string_free(c->history, TRUE); c->history = g_string_new(""); } else if ((event->keyval == 'w') && (convo_options & OPT_CONVO_CTL_W_CLOSES)) { gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); close_callback(c->close, c); } else if (event->keyval == 'n') { gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); } else if (event->keyval == 'z') { gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); XIconifyWindow(GDK_DISPLAY(), GDK_WINDOW_XWINDOW(c->window->window), ((_XPrivDisplay)GDK_DISPLAY())->default_screen); if ((!c->is_chat && (im_options & OPT_IM_ONE_WINDOW)) || (c->is_chat && (chat_options & OPT_CHAT_ONE_WINDOW))) { GtkWidget *notebook = (c->is_chat ? chat_notebook : convo_notebook); if (event->keyval == '[') { gtk_notebook_prev_page(GTK_NOTEBOOK(notebook)); gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); } else if (event->keyval == ']') { gtk_notebook_next_page(GTK_NOTEBOOK(notebook)); gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); } else if (event->keyval == GDK_Tab) { move_next_tab(GTK_NOTEBOOK(notebook), c->is_chat); gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); } else if ((event->keyval == GDK_Tab) && c->is_chat && (chat_options & OPT_CHAT_TAB_COMPLETE)) { gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); } else if (((!c->is_chat && (im_options & OPT_IM_ONE_WINDOW)) || (c->is_chat && (chat_options & OPT_CHAT_ONE_WINDOW))) && (event->state & GDK_MOD1_MASK) && (event->keyval > '0') && (event->keyval <= '9')) { GtkWidget *notebook = (c->is_chat ? chat_notebook : convo_notebook); gtk_notebook_set_page(GTK_NOTEBOOK(notebook), event->keyval - '1'); gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key_press_event"); if (c && (!(misc_options & OPT_MISC_STEALTH_TYPING)) && !c->is_chat) { char *txt = gtk_editable_get_chars(GTK_EDITABLE(c->entry), 0, -1); if ((strlen(txt) == 0 && event->keyval < 256 && isprint(event->keyval)) || (c->type_again != 0 && time(NULL) > c->type_again)) { int timeout = serv_send_typing(c->gc, c->name, TRUE); c->type_again = time(NULL) + timeout; else if (strlen(txt) == 1) { if ((GTK_OLD_EDITABLE(c->entry)->current_pos == 1 && event->keyval == GDK_BackSpace) || (GTK_OLD_EDITABLE(c->entry)->current_pos == 0 && event->keyval == GDK_Delete)) serv_send_typing(c->gc, c->name, FALSE); } else if (GTK_OLD_EDITABLE(c->entry)->selection_start_pos == 0) { if (GTK_OLD_EDITABLE(c->entry)->selection_end_pos == strlen(txt) && (event->keyval == GDK_BackSpace || event->keyval == GDK_Delete)) serv_send_typing(c->gc, c->name, FALSE); void send_callback(GtkWidget *widget, struct conversation *c) buf2 = gtk_editable_get_chars(GTK_EDITABLE(c->entry), 0, -1); limit = 32 * 1024; /* you shouldn't be sending more than 32k in your messages. that's a book. */ g_snprintf(buf, limit, "%s", buf2); first = g_list_first(c->send_history); first->data = g_strdup(buf); c->send_history = g_list_prepend(first, NULL); if (c->gc->flags & OPT_CONN_HTML) { if (convo_options & OPT_CONVO_SEND_LINKS) if (font_options & OPT_FONT_BOLD) { g_snprintf(buf2, limit, "<B>%s</B>", buf); if (font_options & OPT_FONT_ITALIC) { g_snprintf(buf2, limit, "<I>%s</I>", buf); if (font_options & OPT_FONT_UNDERLINE) { g_snprintf(buf2, limit, "<U>%s</U>", buf); if (font_options & OPT_FONT_STRIKE) { g_snprintf(buf2, limit, "<STRIKE>%s</STRIKE>", buf); if ((font_options & OPT_FONT_FACE) || c->hasfont) { g_snprintf(buf2, limit, "<FONT FACE=\"%s\">%s</FONT>", c->fontface, buf); if (font_options & OPT_FONT_SIZE) { g_snprintf(buf2, limit, "<FONT SIZE=\"%d\">%s</FONT>", fontsize, buf); if ((font_options & OPT_FONT_FGCOL) || c->hasfg) { g_snprintf(buf2, limit, "<FONT COLOR=\"#%02X%02X%02X\">%s</FONT>", c->fgcol.red, c->fgcol.green, c->fgcol.blue, buf); if ((font_options & OPT_FONT_BGCOL) || c->hasbg) { g_snprintf(buf2, limit, "<BODY BGCOLOR=\"#%02X%02X%02X\">%s</BODY>", c->bgcol.red, c->bgcol.green, c->bgcol.blue, buf); quiet_set(c->bold, FALSE); quiet_set(c->strike, FALSE); quiet_set(c->italic, FALSE); quiet_set(c->underline, FALSE); quiet_set(c->font, FALSE); quiet_set(c->fgcolorbtn, FALSE); quiet_set(c->bgcolorbtn, FALSE); quiet_set(c->link, FALSE); gtk_widget_grab_focus(c->entry); char *buffy = g_strdup(buf); enum gaim_event evnt = c->is_chat ? event_chat_send : event_im_send; int plugin_return = plugin_event(evnt, c->gc, c->is_chat ? (void *)c->id : c->name, gtk_editable_delete_text(GTK_EDITABLE(c->entry), 0, -1); g_snprintf(buf, limit, "%s", buffy); plugin_event(event_im_displayed_sent, c->gc, c->name, &buffy, 0); if (c->check && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->check))) imflags = IM_FLAG_CHECKBOX; GSList *tmplist = c->images; if (stat(tmplist->data, &st) != 0) { debug_printf("Could not stat %s\n", tmplist->data); /* Here we check to make sure the user still wants to send the * image. He may have deleted the <img> tag in which case we * don't want to send the binary data. */ filename = tmplist->data; while (strchr(filename, '/')) filename = strchr(filename, '/') + 1; g_snprintf(imgtag, sizeof(imgtag), "<IMG SRC=\"file://%s\" ID=\"%d\" DATASIZE=\"%d\">", filename, id, (int)st.st_size); if (strstr(buffy, imgtag) == 0) { debug_printf("Not sending image: %s\n", tmplist->data); length = strlen(buffy) + strlen("<BINARY></BINARY>"); bigbuf = g_malloc(length + 1); g_snprintf(bigbuf, strlen(buffy) + strlen("<BINARY> ") + 1, offset = strlen(buffy) + strlen("<BINARY>"); g_snprintf(imgtag, sizeof(imgtag), "<DATA ID=\"%d\" SIZE=\"%d\">", length = length + strlen(imgtag) + st.st_size + strlen("</DATA>");; bigbuf = g_realloc(bigbuf, length + 1); if (!(imgfile = fopen(tmplist->data, "r"))) { debug_printf("Could not open %s\n", tmplist->data); g_snprintf(bigbuf + offset, strlen(imgtag) + 1, "%s", imgtag); offset = offset + strlen(imgtag); offset = offset + fread(bigbuf + offset, 1, st.st_size, imgfile); g_snprintf(bigbuf + offset, strlen("</DATA>") + 1, "</DATA>"); offset= offset + strlen("</DATA>"); g_snprintf(bigbuf + offset, strlen("</BINARY>") + 1, "</BINARY>"); err =serv_send_im(c->gc, c->name, bigbuf, length, imflags); err = serv_send_im(c->gc, c->name, buffy, -1, imflags); GSList *tempy = c->images; write_to_conv(c, bigbuf, WFLAG_SEND, NULL, time(NULL), length); write_to_conv(c, buffy, WFLAG_SEND, NULL, time(NULL), -1); if (im_options & OPT_IM_POPDOWN) gtk_widget_hide(c->window); err =serv_send_im(c->gc, c->name, buffy, -1, imflags); write_to_conv(c, buf, WFLAG_SEND, NULL, time(NULL), -1); if (im_options & OPT_IM_POPDOWN) gtk_widget_hide(c->window); err = serv_chat_send(c->gc, c->id, buf); /* no sound because we do that when we receive our message */ do_error_dialog(_("Unable to send message: too large"), _("Message Error")); else if (err == -ENOTCONN) debug_printf("Not yet connected\n"); do_error_dialog(_("Unable to send message: Unknown reason"), _("Message Error")); gtk_editable_delete_text(GTK_EDITABLE(c->entry), 0, -1); if ((err > 0) && (away_options & OPT_AWAY_BACK_ON_IM)) { if (awaymessage != NULL) { } else if (c->gc->away) { serv_set_away(c->gc, GAIM_AWAY_CUSTOM, NULL); int entry_key_pressed(GtkWidget *w, GtkWidget *entry) /*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/ int count_tag(GtkWidget *entry, char *s1, char *s2) tmpo = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1); h = tmpo[GTK_OLD_EDITABLE(entry)->current_pos]; tmpo[GTK_OLD_EDITABLE(entry)->current_pos] = '\0'; tmpo[GTK_OLD_EDITABLE(entry)->current_pos] = h; int invert_tags(GtkWidget *entry, char *s1, char *s2, int really) int start = GTK_OLD_EDITABLE(entry)->selection_start_pos; int finish = GTK_OLD_EDITABLE(entry)->selection_end_pos; s = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1); if (!g_strncasecmp(&s[start], s1, strlen(s1)) && !g_strncasecmp(&s[finish - strlen(s2)], s2, strlen(s2))) { gtk_editable_delete_text(GTK_EDITABLE(entry), start, start + strlen(s1)); gtk_editable_delete_text(GTK_EDITABLE(entry), finish - strlen(s2) - strlen(s1), void remove_tags(GtkWidget *entry, char *tag) int start = GTK_OLD_EDITABLE(entry)->selection_start_pos; int finish = GTK_OLD_EDITABLE(entry)->selection_end_pos; s = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1); if (strstr(tag, "<FONT SIZE=")) { while ((t = strstr(t, "<FONT SIZE="))) { if (((t - s) < finish) && ((t - s) >= start)) { gtk_editable_delete_text(GTK_EDITABLE(entry), (t - s), s = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1); while ((t = strstr(t, tag))) { if (((t - s) < finish) && ((t - s) >= start)) { gtk_editable_delete_text(GTK_EDITABLE(entry), (t - s), s = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1); static char *html_logize(char *p) while (*temp_p != '\0') { if ((*temp_p == '\n') || ((*temp_p == '<') && (*(temp_p + 1) == '!'))) buffer_p = g_malloc(char_len + (4 * num_cr) + 1); while (*temp_p != '\0') { } else if ((*temp_p == '<') && (*(temp_p + 1) == '!')) { void surround(GtkWidget *entry, char *pre, char *post) int temp, pos = GTK_OLD_EDITABLE(entry)->current_pos; if (convo_options & OPT_CONVO_CHECK_SPELLING) { gtkspell_detach(GTK_TEXT(entry)); if (GTK_OLD_EDITABLE(entry)->has_selection) { remove_tags(entry, post); start = GTK_OLD_EDITABLE(entry)->selection_start_pos; finish = GTK_OLD_EDITABLE(entry)->selection_end_pos; gtk_editable_insert_text(GTK_EDITABLE(entry), pre, strlen(pre), &dummy); dummy = finish + strlen(pre); gtk_editable_insert_text(GTK_EDITABLE(entry), post, strlen(post), &dummy); gtk_editable_select_region(GTK_EDITABLE(entry), start, finish + strlen(pre) + strlen(post)); gtk_editable_insert_text(GTK_EDITABLE(entry), pre, strlen(pre), &pos); dummy = pos + strlen(pre); gtk_editable_insert_text(GTK_EDITABLE(entry), post, strlen(post), &dummy); gtk_editable_set_position(GTK_EDITABLE(entry), dummy); gtk_editable_insert_text(GTK_EDITABLE(entry), post, strlen(post), &dummy); gtk_editable_set_position(GTK_EDITABLE(entry), pos); if (convo_options & OPT_CONVO_CHECK_SPELLING) { gtkspell_attach(GTK_TEXT(entry)); gtk_widget_grab_focus(entry); void advance_past(GtkWidget *entry, char *pre, char *post) if (invert_tags(entry, pre, post, 1)) s = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1); pos = GTK_OLD_EDITABLE(entry)->current_pos; debug_printf(_("Currently at %d, "), pos); s2 = strstr(&s[pos], post); pos = s2 - s + strlen(post); gtk_editable_insert_text(GTK_EDITABLE(entry), post, strlen(post), &pos); debug_printf(_("Setting position to %d\n"), pos); gtk_editable_set_position(GTK_EDITABLE(entry), pos); gtk_widget_grab_focus(entry); void toggle_fg_color(GtkWidget *color, struct conversation *c) if (GTK_TOGGLE_BUTTON(color)->active) show_fgcolor_dialog(c, color); else if (c->fg_color_dialog) cancel_fgcolor(color, c); advance_past(c->entry, "<FONT COLOR>", "</FONT>"); void toggle_bg_color(GtkWidget *color, struct conversation *c) if (GTK_TOGGLE_BUTTON(color)->active) show_bgcolor_dialog(c, color); else if (c->bg_color_dialog) cancel_bgcolor(color, c); advance_past(c->entry, "<BODY BGCOLOR>", "</BODY>"); void toggle_font(GtkWidget *font, struct conversation *c) if (GTK_TOGGLE_BUTTON(font)->active) show_font_dialog(c, font); advance_past(c->entry, "<FONT FACE>", "</FONT>"); void toggle_link(GtkWidget *linky, struct conversation *c) if (GTK_TOGGLE_BUTTON(linky)->active) advance_past(c->entry, "<A HREF>", "</A>"); void do_strike(GtkWidget *strike, GtkWidget *entry) if (GTK_TOGGLE_BUTTON(strike)->active) surround(entry, "<STRIKE>", "</STRIKE>"); advance_past(entry, "<STRIKE>", "</STRIKE>"); void do_bold(GtkWidget *bold, GtkWidget *entry) if (GTK_TOGGLE_BUTTON(bold)->active) surround(entry, "<B>", "</B>"); advance_past(entry, "<B>", "</B>"); void do_underline(GtkWidget *underline, GtkWidget *entry) if (GTK_TOGGLE_BUTTON(underline)->active) surround(entry, "<U>", "</U>"); advance_past(entry, "<U>", "</U>"); void do_italic(GtkWidget *italic, GtkWidget *entry) if (GTK_TOGGLE_BUTTON(italic)->active) surround(entry, "<I>", "</I>"); advance_past(entry, "<I>", "</I>"); /* html code to modify font sizes must all be the same length, */ /* currently set to 15 chars */ void do_small(GtkWidget *small, GtkWidget *entry) surround(entry, "<FONT SIZE=\"1\">", "</FONT>"); void do_normal(GtkWidget *normal, GtkWidget *entry) surround(entry, "<FONT SIZE=\"3\">", "</FONT>"); void do_big(GtkWidget *big, GtkWidget *entry) surround(entry, "<FONT SIZE=\"5\">", "</FONT>"); void check_everything(GtkWidget *entry) c = (struct conversation *)gtk_object_get_user_data(GTK_OBJECT(entry)); if (invert_tags(entry, "<B>", "</B>", 0)) quiet_set(c->bold, TRUE); else if (count_tag(entry, "<B>", "</B>")) quiet_set(c->bold, TRUE); quiet_set(c->bold, FALSE); if (invert_tags(entry, "<I>", "</I>", 0)) quiet_set(c->italic, TRUE); else if (count_tag(entry, "<I>", "</I>")) quiet_set(c->italic, TRUE); quiet_set(c->italic, FALSE); if (invert_tags(entry, "<FONT COLOR", "</FONT>", 0)) quiet_set(c->fgcolorbtn, TRUE); else if (count_tag(entry, "<FONT COLOR", "</FONT>")) quiet_set(c->fgcolorbtn, TRUE); quiet_set(c->fgcolorbtn, FALSE); if (invert_tags(entry, "<BODY BGCOLOR", "</BODY>", 0)) quiet_set(c->bgcolorbtn, TRUE); else if (count_tag(entry, "<BODY BGCOLOR", "</BODY>")) quiet_set(c->bgcolorbtn, TRUE); quiet_set(c->bgcolorbtn, FALSE); if (invert_tags(entry, "<FONT FACE", "</FONT>", 0)) quiet_set(c->font, TRUE); else if (count_tag(entry, "<FONT FACE", "</FONT>")) quiet_set(c->font, TRUE); quiet_set(c->font, FALSE); if (invert_tags(entry, "<A HREF", "</A>", 0)) quiet_set(c->link, TRUE); else if (count_tag(entry, "<A HREF", "</A>")) quiet_set(c->link, TRUE); quiet_set(c->link, FALSE); if (invert_tags(entry, "<U>", "</U>", 0)) quiet_set(c->underline, TRUE); else if (count_tag(entry, "<U>", "</U>")) quiet_set(c->underline, TRUE); quiet_set(c->underline, FALSE); if (invert_tags(entry, "<STRIKE>", "</STRIKE>", 0)) quiet_set(c->strike, TRUE); else if (count_tag(entry, "<STRIKE>", "</STRIKE>")) quiet_set(c->strike, TRUE); quiet_set(c->strike, FALSE); /*------------------------------------------------------------------------*/ /* Takin care of the window.. */ /*------------------------------------------------------------------------*/ /* this is going to be interesting since the conversation could either be a * normal IM conversation or a chat window. but hopefully it won't matter */ void write_to_conv(struct conversation *c, char *what, int flags, char *who, time_t mtime, gint length) int gtk_font_options = 0; if (c->gc && c->gc->prpl->options & OPT_PROTO_USE_POINT_SIZE) if (c->is_chat && (!c->gc || !g_slist_find(c->gc->buddy_chats, c))) if (!c->is_chat && !g_list_find(conversations, c)) gtk_widget_show(c->window); if (!c->is_chat || !(c->gc->prpl->options & OPT_PROTO_UNIQUE_CHATNAME)) { if (flags & WFLAG_SEND) { b = find_buddy(c->gc, c->gc->username); if (b && strcmp(b->name, b->show)) else if (c->gc->user->alias[0]) who = c->gc->user->alias; else if (c->gc->displayname[0]) who = c->gc->displayname; b = find_buddy(c->gc, c->name); b = find_buddy(c->gc, who); strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime)); gtk_font_options = gtk_font_options ^ GTK_IMHTML_NO_COMMENTS; if (convo_options & OPT_CONVO_IGNORE_COLOUR) gtk_font_options = gtk_font_options ^ GTK_IMHTML_NO_COLOURS; if (convo_options & OPT_CONVO_IGNORE_FONTS) gtk_font_options = gtk_font_options ^ GTK_IMHTML_NO_FONTS; if (convo_options & OPT_CONVO_IGNORE_SIZES) gtk_font_options = gtk_font_options ^ GTK_IMHTML_NO_SIZES; if (!(logging_options & OPT_LOG_STRIP_HTML)) gtk_font_options = gtk_font_options ^ GTK_IMHTML_RETURN_LOG; if (flags & WFLAG_SYSTEM) { if (convo_options & OPT_CONVO_SHOW_TIME) g_snprintf(buf, BUF_LONG, "<FONT SIZE=\"%d\">(%s) </FONT><B>%s</B>", timesize, mdate, what); g_snprintf(buf, BUF_LONG, "<B>%s</B>", what); g_snprintf(buf2, sizeof(buf2), "<FONT SIZE=\"%d\"><!--(%s) --></FONT><B>%s</B><BR>", gtk_imhtml_append_text(GTK_IMHTML(c->text), buf2, -1, 0); if (logging_options & OPT_LOG_STRIP_HTML) { char *t1 = strip_html(buf); c->history = g_string_append(c->history, t1); c->history = g_string_append(c->history, "\n"); c->history = g_string_append(c->history, buf); c->history = g_string_append(c->history, "<BR>\n"); if (!(flags & WFLAG_NOLOG) && ((logging_options & OPT_LOG_ALL) || find_log_info(c->name))) { if (logging_options & OPT_LOG_STRIP_HTML) { g_snprintf(nm, 256, "%s.chat", c->name); g_snprintf(nm, 256, "%s", c->name); if (logging_options & OPT_LOG_STRIP_HTML) { fprintf(fd, "%s<BR>\n", t1); if (logging_options & OPT_LOG_STRIP_HTML) { } else if (flags & WFLAG_NOLOG) { g_snprintf(buf, BUF_LONG, "<B><FONT COLOR=\"#777777\">%s</FONT></B><BR>", what); gtk_imhtml_append_text(GTK_IMHTML(c->text), buf, -1, 0); if (flags & WFLAG_WHISPER) { /* if we're whispering, it's not an autoresponse */ if (meify(what, length)) { g_snprintf(str, 1024, "***%s", who); strcpy(colour, "#6C2585"); g_snprintf(str, 1024, "*%s*:", who); strcpy(colour, "#00ff00"); if (meify(what, length)) { g_snprintf(str, 1024, "%s ***%s", AUTO_RESPONSE, who); g_snprintf(str, 1024, "***%s", who); strcpy(colour, "#af7f00"); strcpy(colour, "#062585"); g_snprintf(str, 1024, "%s %s", who, AUTO_RESPONSE); g_snprintf(str, 1024, "%s:", who); strcpy(colour, "#af7f00"); else if (flags & WFLAG_RECV) strcpy(colour, "#ff0000"); else if (flags & WFLAG_SEND) strcpy(colour, "#0000ff"); if (convo_options & OPT_CONVO_SHOW_TIME) g_snprintf(buf, BUF_LONG, "<FONT COLOR=\"%s\"><FONT SIZE=\"%d\">(%s) </FONT>" "<B>%s</B></FONT> ", colour, timesize, mdate, str); g_snprintf(buf, BUF_LONG, "<FONT COLOR=\"%s\"><B>%s</B></FONT> ", colour, str); g_snprintf(buf2, BUF_LONG, "<FONT COLOR=\"%s\"><FONT SIZE=\"%d\"><!--(%s) --></FONT>" "<B>%s</B></FONT> ", colour, timesize, mdate, str); gtk_imhtml_append_text(GTK_IMHTML(c->text), buf2, -1, 0); logstr = gtk_imhtml_append_text(GTK_IMHTML(c->text), what, length, gtk_font_options); gtk_imhtml_append_text(GTK_IMHTML(c->text), "<BR>", -1, 0); /* XXX this needs to be updated for the new length argument */ if (logging_options & OPT_LOG_STRIP_HTML) { c->history = g_string_append(c->history, t1); c->history = g_string_append(c->history, t2); c->history = g_string_append(c->history, "\n"); c->history = g_string_append(c->history, t1); c->history = g_string_append(c->history, t2); c->history = g_string_append(c->history, "\n"); c->history = g_string_append(c->history, logstr->str); c->history = g_string_append(c->history, "<BR>\n"); /* XXX this needs to be updated for the new length argument */ if ((logging_options & OPT_LOG_ALL) || find_log_info(c->name)) { char *nm = g_malloc(256); g_snprintf(nm, 256, "%s.chat", c->name); g_snprintf(nm, 256, "%s", c->name); if (logging_options & OPT_LOG_STRIP_HTML) { if (logging_options & OPT_LOG_STRIP_HTML) { fprintf(fd, "%s%s\n", t1, t2); fprintf(fd, "%s%s%s<BR>\n", t1, t2, logstr->str); g_string_free(logstr, TRUE); if ((c->is_chat && (chat_options & OPT_CHAT_POPUP)) || (!c->is_chat && (im_options & OPT_IM_POPUP))) gdk_window_show(c->window->window); reset_typing(g_strdup(c->name)); if (c->is_chat && !(chat_options & OPT_CHAT_ONE_WINDOW)) /* if chat but not tabbed chat */ if (!c->is_chat && !(im_options & OPT_IM_ONE_WINDOW)) /* if convo but not tabbed convo */ if (!(flags & WFLAG_RECV) && !(flags & WFLAG_SYSTEM)) if ((c->unseen == 2) || ((c->unseen == 1) && !(flags & WFLAG_NICK))) if ((convo_options & OPT_CONVO_COMBINE) && (im_options & OPT_IM_ONE_WINDOW)) offs = g_list_length(conversations); if (gtk_notebook_get_current_page(GTK_NOTEBOOK(chat_notebook)) == g_list_index(chats, c) + offs) if (gtk_notebook_get_current_page(GTK_NOTEBOOK(convo_notebook)) == g_list_index(conversations, c)) if ((c->unseen != -1) && unhighlight) /* If there's no typing message and we're on the same tab, don't bother GtkNotebook *notebook = GTK_NOTEBOOK(c->is_chat ? chat_notebook : convo_notebook); int offs = ((convo_options & OPT_CONVO_COMBINE) && (im_options & OPT_IM_ONE_WINDOW) && c->is_chat) ? g_list_length(conversations) : 0; GList *ws = (c->is_chat ? chats : conversations); GtkWidget *label = gtk_notebook_get_tab_label(notebook, gtk_notebook_get_nth_page(notebook, offs + g_list_index(ws, c))); if (!GTK_WIDGET_REALIZED(label)) gtk_widget_realize(label); gdk_font_unref(gtk_style_get_font(style)); gtk_style_set_font(style, gdk_font_ref(gtk_style_get_font(label->style))); if (!unhighlight && flags & WFLAG_NICK) { style->fg[0].red = 0x0000; style->fg[0].green = 0x0000; style->fg[0].blue = 0xcccc; } else if (!unhighlight) { style->fg[0].red = 0xcccc; style->fg[0].green = 0x0000; style->fg[0].blue = 0x0000; gtk_widget_set_style(label, style); void update_progress(struct conversation *c, float percent) { if (percent >= 1 && !(c->progress)) gtk_widget_destroy(c->progress); GtkBox *box = GTK_BOX(c->text->parent->parent); c->progress = gtk_progress_bar_new(); gtk_box_pack_end(box, c->progress, FALSE, FALSE, 0); gtk_widget_set_usize (c->progress, 1, 8); gtk_widget_show (c->progress); gtk_progress_set_percentage(GTK_PROGRESS(c->progress), percent); GtkWidget *build_conv_toolbar(struct conversation *c) GdkPixmap *strike_i, *small_i, *normal_i, *big_i, *bold_i, *italic_i, *underline_i, *speaker_i, *wood_i, *fgcolor_i, *bgcolor_i, *link_i, *font_i, *smiley_i, *save_i, *image_i; GtkWidget *strike_p, *small_p, *normal_p, *big_p, *bold_p, *italic_p, *underline_p, *speaker_p, *wood_p, *fgcolor_p, *bgcolor_p, *link_p, *font_p, *smiley_p, *save_p, *image_p; GtkWidget *strike, *small, *normal, *big, *bold, *italic, *underline, *speaker, *wood, *fgcolorbtn, *bgcolorbtn, *link, *font, *smiley, *save, *image; toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_ICONS); bold_i = gdk_pixmap_create_from_xpm_d(win->window, &mask, &win->style->white, bold_xpm); bold_p = gtk_pixmap_new(bold_i, mask); italic_i = gdk_pixmap_create_from_xpm_d(win->window, &mask, &win->style->white, italic_xpm); italic_p = gtk_pixmap_new(italic_i, mask); gtk_widget_show(italic_p); underline_i = gdk_pixmap_create_from_xpm_d(win->window, &mask, &win->style->white, underline_xpm); underline_p = gtk_pixmap_new(underline_i, mask); gtk_widget_show(underline_p); strike_i = gdk_pixmap_create_from_xpm_d(win->window, &mask, &win->style->white, strike_xpm); strike_p = gtk_pixmap_new(strike_i, mask); gtk_widget_show(strike_p); small_i = gdk_pixmap_create_from_xpm_d(win->window, &mask, &win->style->white, small_xpm); small_p = gtk_pixmap_new(small_i, mask); gtk_widget_show(small_p); normal_i = gdk_pixmap_create_from_xpm_d(win->window, &mask, &win->style->white, normal_xpm); normal_p = gtk_pixmap_new(normal_i, mask); gtk_widget_show(normal_p); big_i = gdk_pixmap_create_from_xpm_d(win->window, &mask, &win->style->white, big_xpm); big_p = gtk_pixmap_new(big_i, mask); font_i = gdk_pixmap_create_from_xpm_d(win->window, &mask, &win->style->white, fontface_xpm); font_p = gtk_pixmap_new(font_i, mask); fgcolor_i = gdk_pixmap_create_from_xpm_d(win->window, &mask, &win->style->white, fgcolor_xpm); fgcolor_p = gtk_pixmap_new(fgcolor_i, mask); gtk_widget_show(fgcolor_p); bgcolor_i = gdk_pixmap_create_from_xpm_d(win->window, &mask, &win->style->white, bgcolor_xpm); bgcolor_p = gtk_pixmap_new(bgcolor_i, mask); gtk_widget_show(bgcolor_p); link_i = gdk_pixmap_create_from_xpm_d(win->window, &mask, &win->style->white, link_xpm); link_p = gtk_pixmap_new(link_i, mask); smiley_i = gdk_pixmap_create_from_xpm_d(win->window, &mask, &win->style->white, smile_icon_xpm); smiley_p = gtk_pixmap_new(smiley_i, mask); gtk_widget_show(smiley_p); image_i = gdk_pixmap_create_from_xpm_d(win->window, &mask, &win->style->white, image_icon_xpm); image_p = gtk_pixmap_new(image_i, mask); gtk_widget_show(image_p); wood_i = gdk_pixmap_create_from_xpm_d(win->window, &mask, &win->style->white, wood_xpm); wood_p = gtk_pixmap_new(wood_i, mask); save_i = gdk_pixmap_create_from_xpm_d(win->window, &mask, &win->style->white, save_small_xpm); save_p = gtk_pixmap_new(save_i, mask); speaker_i = gdk_pixmap_create_from_xpm_d(win->window, &mask, &win->style->white, speaker_xpm); speaker_p = gtk_pixmap_new(speaker_i, mask); gtk_widget_show(speaker_p); bold = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL, NULL, _("Bold Text"), _("Bold"), bold_p, GTK_SIGNAL_FUNC(do_bold), entry); italic = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL, NULL, _("Italics Text"), _("Italics"), italic_p, GTK_SIGNAL_FUNC(do_italic), entry); underline = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL, NULL, _("Underline Text"), _("Underline"), underline_p, GTK_SIGNAL_FUNC(do_underline), entry); gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL, NULL, _("Strike through Text"), _("Strike"), strike_p, GTK_SIGNAL_FUNC(do_strike), entry); gtk_toolbar_append_space(GTK_TOOLBAR(toolbar)); small = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), NULL, _("Decrease font size"), _("Small"), small_p, GTK_SIGNAL_FUNC(do_small), entry); normal = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), NULL, _("Normal font size"), _("Normal"), normal_p, GTK_SIGNAL_FUNC(do_normal), entry); big = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), NULL, _("Increase font size"), _("Big"), big_p, GTK_SIGNAL_FUNC(do_big), entry); gtk_toolbar_append_space(GTK_TOOLBAR(toolbar)); font = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL, NULL, _("Select Font"), _("Font"), font_p, GTK_SIGNAL_FUNC(toggle_font), c); fgcolorbtn = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL, NULL, _("Text Color"), _("Color"), fgcolor_p, GTK_SIGNAL_FUNC(toggle_fg_color), gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL, NULL, _("Background Color"), _("Color"), bgcolor_p, GTK_SIGNAL_FUNC(toggle_bg_color), c); gtk_toolbar_append_space(GTK_TOOLBAR(toolbar)); link = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL, NULL, _("Insert Link"), _("Link"), link_p, GTK_SIGNAL_FUNC(toggle_link), c); smiley = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL, NULL, _("Insert smiley face"), _("Smiley"), smiley_p, GTK_SIGNAL_FUNC(insert_smiley), c); image = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), NULL, _("Insert IM Image"), _("Image"), image_p, GTK_SIGNAL_FUNC(insert_image), c); gtk_toolbar_append_space(GTK_TOOLBAR(toolbar)); wood = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL, NULL, _("Enable logging"), _("Logging"), wood_p, GTK_SIGNAL_FUNC(toggle_loggle), c); if (find_log_info(c->name)) gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(wood), TRUE); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(wood), FALSE); save = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), NULL, _("Save Conversation"), _("Save"), save_p, GTK_SIGNAL_FUNC(save_convo), c); speaker = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL, NULL, _("Toggle Sound"), _("Sound"), speaker_p, GTK_SIGNAL_FUNC(toggle_sound), c); /* use a slicker look if the user wants to */ if (misc_options & OPT_MISC_COOL_LOOK) { gtk_button_set_relief(GTK_BUTTON(bold), GTK_RELIEF_NONE); gtk_button_set_relief(GTK_BUTTON(italic), GTK_RELIEF_NONE); gtk_button_set_relief(GTK_BUTTON(underline), GTK_RELIEF_NONE); gtk_button_set_relief(GTK_BUTTON(strike), GTK_RELIEF_NONE); gtk_button_set_relief(GTK_BUTTON(small), GTK_RELIEF_NONE); gtk_button_set_relief(GTK_BUTTON(normal), GTK_RELIEF_NONE); gtk_button_set_relief(GTK_BUTTON(big), GTK_RELIEF_NONE); gtk_button_set_relief(GTK_BUTTON(font), GTK_RELIEF_NONE); gtk_button_set_relief(GTK_BUTTON(fgcolorbtn), GTK_RELIEF_NONE); gtk_button_set_relief(GTK_BUTTON(bgcolorbtn), GTK_RELIEF_NONE); gtk_button_set_relief(GTK_BUTTON(link), GTK_RELIEF_NONE); gtk_button_set_relief(GTK_BUTTON(smiley), GTK_RELIEF_NONE); gtk_button_set_relief(GTK_BUTTON(image), GTK_RELIEF_NONE); gtk_button_set_relief(GTK_BUTTON(wood), GTK_RELIEF_NONE); gtk_button_set_relief(GTK_BUTTON(save), GTK_RELIEF_NONE); gtk_button_set_relief(GTK_BUTTON(speaker), GTK_RELIEF_NONE); gtk_widget_show(toolbar); gdk_pixmap_unref(bold_i); gdk_pixmap_unref(italic_i); gdk_pixmap_unref(underline_i); gdk_pixmap_unref(strike_i); gdk_pixmap_unref(small_i); gdk_pixmap_unref(normal_i); gdk_pixmap_unref(font_i); gdk_pixmap_unref(fgcolor_i); gdk_pixmap_unref(bgcolor_i); gdk_pixmap_unref(link_i); gdk_pixmap_unref(smiley_i); gdk_pixmap_unref(wood_i); gdk_pixmap_unref(save_i); gdk_pixmap_unref(speaker_i); gdk_pixmap_unref(image_i); c->underline = underline; c->fgcolorbtn = fgcolorbtn; c->bgcolorbtn = bgcolorbtn; c->speaker_p = speaker_p; gtk_widget_set_sensitive(c->log_button, ((logging_options & OPT_LOG_ALL)) ? FALSE : TRUE); gtk_widget_set_sensitive(c->bold, ((font_options & OPT_FONT_BOLD)) ? FALSE : TRUE); gtk_widget_set_sensitive(c->italic, ((font_options & OPT_FONT_ITALIC)) ? FALSE : TRUE); gtk_widget_set_sensitive(c->underline, ((font_options & OPT_FONT_UNDERLINE)) ? FALSE : TRUE); gtk_widget_set_sensitive(c->strike, ((font_options & OPT_FONT_STRIKE)) ? FALSE : TRUE); static void convo_sel_send(GtkObject *m, struct gaim_connection *c) struct conversation *cnv = gtk_object_get_user_data(m); update_buttons_by_protocol(cnv); gaim_setup_imhtml_smileys(cnv->text); int set_dispstyle(int chat) switch (chat_options & (OPT_CHAT_BUTTON_TEXT | OPT_CHAT_BUTTON_XPM)) { case OPT_CHAT_BUTTON_TEXT: case OPT_CHAT_BUTTON_XPM: default: /* both or neither */ switch (im_options & (OPT_IM_BUTTON_TEXT | OPT_IM_BUTTON_XPM)) { default: /* both or neither */ void update_convo_add_button(struct conversation *c) int dispstyle = set_dispstyle(0); GtkWidget *parent = c->add->parent; gboolean rebuild = FALSE; if (find_buddy(c->gc, c->name)) { if (!gtk_object_get_user_data(GTK_OBJECT(c->add))) { gtk_widget_destroy(c->add); c->add = picture_button2(c->window, _("Remove"), gnome_remove_xpm, dispstyle); if (c->gc->prpl->remove_buddy == NULL) gtk_widget_set_sensitive(c->add, FALSE); gtk_widget_set_sensitive(c->add, TRUE); gtk_widget_set_sensitive(c->add, FALSE); gtk_object_set_user_data(GTK_OBJECT(c->add), c); if (gtk_object_get_user_data(GTK_OBJECT(c->add))) { gtk_widget_destroy(c->add); c->add = picture_button2(c->window, _("Add"), gnome_add_xpm, dispstyle); if (c->gc->prpl->add_buddy == NULL) gtk_widget_set_sensitive(c->add, FALSE); gtk_widget_set_sensitive(c->add, TRUE); gtk_widget_set_sensitive(c->add, FALSE); gtk_signal_connect(GTK_OBJECT(c->add), "clicked", GTK_SIGNAL_FUNC(add_callback), c); gtk_box_pack_end(GTK_BOX(parent), c->add, dispstyle, dispstyle, 0); gtk_box_reorder_child(GTK_BOX(parent), c->add, 2); static void create_convo_menu(struct conversation *cnv) struct gaim_connection *c; if (g_slist_length(g) < 2) gtk_widget_hide(cnv->menu->parent); c = (struct gaim_connection *)g->data; g_snprintf(buf, sizeof buf, "%s (%s)", c->username, c->prpl->name()); opt = gtk_menu_item_new_with_label(buf); gtk_object_set_user_data(GTK_OBJECT(opt), cnv); gtk_signal_connect(GTK_OBJECT(opt), "activate", GTK_SIGNAL_FUNC(convo_sel_send), c); gtk_menu_append(GTK_MENU(menu), opt); gtk_option_menu_remove_menu(GTK_OPTION_MENU(cnv->menu)); gtk_option_menu_set_menu(GTK_OPTION_MENU(cnv->menu), menu); gtk_option_menu_set_history(GTK_OPTION_MENU(cnv->menu), 0); gtk_widget_show(cnv->menu); gtk_widget_show(cnv->menu->parent); GList *c = conversations; C = (struct conversation *)c->data; if (g_slist_find(connections, C->gc)) set_convo_gc(C, connections ? connections->data : NULL); void convo_menu_remove(struct gaim_connection *gc) GList *c = conversations; C = (struct conversation *)c->data; void set_convo_gc(struct conversation *c, struct gaim_connection *gc) gtk_option_menu_set_history(GTK_OPTION_MENU(c->menu), g_slist_index(connections, gc)); update_buttons_by_protocol(c); gaim_setup_imhtml_smileys(c->text); void update_buttons_by_protocol(struct conversation *c) gtk_widget_set_sensitive(c->info, FALSE); gtk_widget_set_sensitive(c->send, FALSE); gtk_widget_set_sensitive(c->warn, FALSE); gtk_widget_set_sensitive(c->block, FALSE); gtk_widget_set_sensitive(c->add, FALSE); gtk_widget_set_sensitive(c->whisper, FALSE); gtk_widget_set_sensitive(c->invite, FALSE); if (c->gc->prpl->get_info == NULL && c->info) gtk_widget_set_sensitive(c->info, FALSE); gtk_widget_set_sensitive(c->info, TRUE); if (c->gc->prpl->chat_send == NULL && c->send) gtk_widget_set_sensitive(c->send, FALSE); gtk_widget_set_sensitive(c->send, TRUE); gtk_widget_set_sensitive(c->imagebtn, FALSE); if (c->gc->prpl->send_im == NULL && c->send) gtk_widget_set_sensitive(c->send, FALSE); gtk_widget_set_sensitive(c->send, TRUE); if (c->gc->prpl->options & OPT_PROTO_IM_IMAGE) gtk_widget_set_sensitive(c->imagebtn, TRUE); gtk_widget_set_sensitive(c->imagebtn, FALSE); if (c->gc->prpl->warn == NULL && c->warn) gtk_widget_set_sensitive(c->warn, FALSE); gtk_widget_set_sensitive(c->warn, TRUE); if (c->gc->prpl->add_permit == NULL && c->block) gtk_widget_set_sensitive(c->block, FALSE); gtk_widget_set_sensitive(c->block, TRUE); update_convo_add_button(c); if (c->gc->prpl->chat_whisper == NULL) gtk_widget_set_sensitive(c->whisper, FALSE); gtk_widget_set_sensitive(c->whisper, TRUE); if (c->gc->prpl->chat_invite == NULL) gtk_widget_set_sensitive(c->invite, FALSE); gtk_widget_set_sensitive(c->invite, TRUE); void convo_switch(GtkNotebook *notebook, GtkWidget *page, gint page_num, gpointer data) GtkWidget *label = gtk_notebook_get_tab_label(notebook, gtk_notebook_get_nth_page(notebook, page_num)); if ((convo_options & OPT_CONVO_COMBINE) && (im_options & OPT_IM_ONE_WINDOW) && (chat_options & OPT_CHAT_ONE_WINDOW)) { int len = g_list_length(conversations); c = g_list_nth_data(conversations, page_num); c = g_list_nth_data(chats, page_num - len); } else if (GTK_WIDGET(notebook) == convo_notebook) c = g_list_nth_data(conversations, page_num); c = g_list_nth_data(chats, page_num); if (c && c->window && c->entry) gtk_window_set_focus(GTK_WINDOW(c->window), c->entry); if (!GTK_WIDGET_REALIZED(label)) if (c->unseen == -1) return; gdk_font_unref(gtk_style_get_font(style)); gtk_style_set_font(style, gdk_font_ref(gtk_style_get_font(label->style))); gtk_widget_set_style(label, style); void show_typing(struct conversation *c) { if (c->is_chat) /* We shouldn't be getting typing notifications from chats. */ if (im_options & OPT_IM_ONE_WINDOW) { /* We'll make the tab green */ GtkNotebook *notebook = GTK_NOTEBOOK(c->is_chat ? chat_notebook : convo_notebook); int offs = ((convo_options & OPT_CONVO_COMBINE) && (im_options & OPT_IM_ONE_WINDOW) && c->is_chat) ? g_list_length(conversations) : 0; GList *ws = (c->is_chat ? chats : conversations); GtkWidget *label = gtk_notebook_get_tab_label(notebook, gtk_notebook_get_nth_page(notebook, offs + g_list_index(ws, c))); if (!GTK_WIDGET_REALIZED(label)) gtk_widget_realize(label); gdk_font_unref(gtk_style_get_font(style)); gtk_style_set_font(style, gdk_font_ref(gtk_style_get_font(label->style))); style->fg[0].red = 0x0000; style->fg[0].green = 0x9999; style->fg[0].blue = 0x0000; gtk_widget_set_style(label, style); debug_printf("setting style\n"); GtkWindow *win = (GtkWindow *)c->window; if (strstr(win->title, " [TYPING]")) buf = g_malloc(strlen(win->title) + strlen(" [TYPING]") + 1); strlen(win->title) + strlen(" [TYPING]") + 1, "%s [TYPING]", gtk_window_set_title(win, buf); /* This returns a boolean, so that it can timeout */ gboolean reset_typing(char *name) { struct conversation *c = find_conversation(name); /* Reset the title (if necessary) */ if (!(im_options & OPT_IM_ONE_WINDOW)) { GtkWindow *win = (GtkWindow*)c->window; if (strstr(win->title, " [TYPING]")) { new_title = g_malloc(strlen(win->title) - strlen("[TYPING]")); g_snprintf(new_title, strlen(win->title) - strlen("[TYPING]"), win->title); gtk_window_set_title(win, new_title); } else if (c->unseen == -1) { GtkNotebook *notebook = GTK_NOTEBOOK(convo_notebook); int offs = ((convo_options & OPT_CONVO_COMBINE) && (im_options & OPT_IM_ONE_WINDOW) && c->is_chat) ? g_list_length(conversations) : 0; GList *ws = (conversations); GtkWidget *label = gtk_notebook_get_tab_label(notebook, gtk_notebook_get_nth_page(notebook, offs + g_list_index(ws, c))); if (!GTK_WIDGET_REALIZED(label)) gtk_widget_realize(label); gdk_font_unref(gtk_style_get_font(style)); gtk_style_set_font(style, gdk_font_ref(gtk_style_get_font(label->style))); gtk_widget_set_style(label, style); void show_conv(struct conversation *c) int dispstyle = set_dispstyle(0); c->fg_color_dialog = NULL; c->bg_color_dialog = NULL; sprintf(c->fontxfld, "%s", fontxfld); sprintf(c->fontface, "%s", fontface); if (im_options & OPT_IM_ONE_WINDOW) { win = all_convos = c->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); if ((convo_options & OPT_CONVO_COMBINE) && (chat_options & OPT_CHAT_ONE_WINDOW)) gtk_window_set_wmclass(GTK_WINDOW(win), "conversation", "Gaim"); gtk_window_set_policy(GTK_WINDOW(win), TRUE, TRUE, FALSE); gtk_container_border_width(GTK_CONTAINER(win), 0); gtk_window_set_title(GTK_WINDOW(win), _("Gaim - Conversations")); gtk_signal_connect(GTK_OBJECT(win), "delete_event", GTK_SIGNAL_FUNC(delete_all_convo), NULL); convo_notebook = gtk_notebook_new(); if ((convo_options & OPT_CONVO_COMBINE) && (chat_options & OPT_CHAT_ONE_WINDOW)) chat_notebook = convo_notebook; if (im_options & OPT_IM_SIDE_TAB) { if (im_options & OPT_IM_BR_TAB) { gtk_notebook_set_tab_pos(GTK_NOTEBOOK(convo_notebook), gtk_notebook_set_tab_pos(GTK_NOTEBOOK(convo_notebook), if (im_options & OPT_IM_BR_TAB) { gtk_notebook_set_tab_pos(GTK_NOTEBOOK(convo_notebook), gtk_notebook_set_tab_pos(GTK_NOTEBOOK(convo_notebook), gtk_notebook_set_scrollable(GTK_NOTEBOOK(convo_notebook), TRUE); gtk_notebook_popup_enable(GTK_NOTEBOOK(convo_notebook)); gtk_container_add(GTK_CONTAINER(win), convo_notebook); gtk_signal_connect(GTK_OBJECT(convo_notebook), "switch-page", GTK_SIGNAL_FUNC(convo_switch), NULL); gtk_widget_show(convo_notebook); win = c->window = all_convos; cont = gtk_vbox_new(FALSE, 5); gtk_container_set_border_width(GTK_CONTAINER(cont), 5); /* this doesn't matter since we're resetting the name once we're out of the if */ gtk_notebook_insert_page(GTK_NOTEBOOK(convo_notebook), cont, gtk_label_new(c->name), g_list_index(conversations, c)); cont = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_object_set_user_data(GTK_OBJECT(win), c); gtk_window_set_wmclass(GTK_WINDOW(win), "conversation", "Gaim"); gtk_window_set_policy(GTK_WINDOW(win), TRUE, TRUE, TRUE); gtk_container_border_width(GTK_CONTAINER(win), 10); gtk_signal_connect(GTK_OBJECT(win), "delete_event", GTK_SIGNAL_FUNC(delete_event_convo), c); paned = gtk_vpaned_new(); gtk_paned_set_gutter_size(GTK_PANED(paned), 15); gtk_container_add(GTK_CONTAINER(cont), paned); vbox = gtk_vbox_new(FALSE, 5); gtk_paned_pack1(GTK_PANED(paned), vbox, FALSE, TRUE); sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); gtk_widget_set_usize(sw, conv_size.width, conv_size.height); text = gtk_imhtml_new(NULL, NULL); gtk_container_add(GTK_CONTAINER(sw), text); GTK_LAYOUT(text)->hadjustment->step_increment = 10.0; GTK_LAYOUT(text)->vadjustment->step_increment = 10.0; if (convo_options & OPT_CONVO_SHOW_TIME) gtk_imhtml_show_comments(GTK_IMHTML(text), TRUE); vbox2 = gtk_vbox_new(FALSE, 5); gtk_paned_pack2(GTK_PANED(paned), vbox2, FALSE, FALSE); hbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox2), hbox, FALSE, FALSE, 0); label = gtk_label_new(_("Send message as: ")); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); c->menu = gtk_option_menu_new(); gtk_box_pack_start(GTK_BOX(hbox), c->menu, FALSE, FALSE, 5); gtk_widget_show(c->menu); c->lbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox2), c->lbox, FALSE, FALSE, 0); gtk_widget_show(c->lbox); entry = gtk_text_new(NULL, NULL); if (!(im_options & OPT_IM_ONE_WINDOW)) gtk_window_set_focus(GTK_WINDOW(c->window), c->entry); toolbar = build_conv_toolbar(c); gtk_box_pack_start(GTK_BOX(vbox2), toolbar, FALSE, FALSE, 0); gtk_object_set_user_data(GTK_OBJECT(entry), c); gtk_text_set_editable(GTK_TEXT(entry), TRUE); gtk_text_set_word_wrap(GTK_TEXT(entry), TRUE); /* I hate hackish workarounds. According to Ari Pollak, a gtk bug causes Gaim to loop * infinitely if the entry is smaller than the text height. This is a hackish workaround */ gtk_widget_set_usize(entry, conv_size.width - 20, MAX(conv_size.entry_height, gdk_char_height(gtk_widget_get_default_style()->font, '0') + gtk_widget_get_default_style()->font->ascent + 1)); gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(send_callback), c); gtk_signal_connect(GTK_OBJECT(entry), "key_press_event", GTK_SIGNAL_FUNC(keypress_callback), c); gtk_signal_connect(GTK_OBJECT(entry), "key_press_event", GTK_SIGNAL_FUNC(entry_key_pressed), if (convo_options & OPT_CONVO_CHECK_SPELLING) gtkspell_attach(GTK_TEXT(c->entry)); gtk_box_pack_start(GTK_BOX(vbox2), entry, TRUE, TRUE, 0); c->bbox = bbox = gtk_hbox_new(FALSE, 5); gtk_box_pack_start(GTK_BOX(vbox2), bbox, FALSE, FALSE, 0); close = picture_button2(win, _("Close"), cancel_xpm, dispstyle); gtk_object_set_user_data(GTK_OBJECT(close), c); gtk_signal_connect(GTK_OBJECT(close), "clicked", GTK_SIGNAL_FUNC(close_callback), c); gtk_box_pack_end(GTK_BOX(bbox), close, dispstyle, dispstyle, 0); c->sep1 = gtk_vseparator_new(); gtk_box_pack_end(GTK_BOX(bbox), c->sep1, dispstyle, dispstyle, 0); gtk_widget_show(c->sep1); if (c->gc && find_buddy(c->gc, c->name) != NULL) { add = picture_button2(win, _("Remove"), gnome_remove_xpm, dispstyle); gtk_object_set_user_data(GTK_OBJECT(add), c); add = picture_button2(win, _("Add"), gnome_add_xpm, dispstyle); gtk_signal_connect(GTK_OBJECT(add), "clicked", GTK_SIGNAL_FUNC(add_callback), c); gtk_box_pack_end(GTK_BOX(bbox), add, dispstyle, dispstyle, 0); block = picture_button2(win, _("Block"), block_xpm, dispstyle); gtk_signal_connect(GTK_OBJECT(block), "clicked", GTK_SIGNAL_FUNC(block_callback), c); gtk_box_pack_end(GTK_BOX(bbox), block, dispstyle, dispstyle, 0); warn = picture_button2(win, _("Warn"), warn_xpm, dispstyle); gtk_signal_connect(GTK_OBJECT(warn), "clicked", GTK_SIGNAL_FUNC(warn_callback), c); gtk_box_pack_end(GTK_BOX(bbox), warn, dispstyle, dispstyle, 0); info = picture_button2(win, _("Info"), tb_search_xpm, dispstyle); gtk_signal_connect(GTK_OBJECT(info), "clicked", GTK_SIGNAL_FUNC(info_callback), c); gtk_box_pack_end(GTK_BOX(bbox), info, dispstyle, dispstyle, 0); c->sep2 = gtk_vseparator_new(); gtk_box_pack_end(GTK_BOX(bbox), c->sep2, dispstyle, dispstyle, 0); gtk_widget_show(c->sep2); send = picture_button2(win, _("Send"), tmp_send_xpm, dispstyle); gtk_signal_connect(GTK_OBJECT(send), "clicked", GTK_SIGNAL_FUNC(send_callback), c); gtk_box_pack_end(GTK_BOX(bbox), send, dispstyle, dispstyle, 0); update_buttons_by_protocol(c); GList *cnv = conversations; GSList *con = connections; struct gaim_connection *gc; if (convo_options & OPT_CONVO_CHECK_SPELLING){ /*If ispell fails to start, start aspell. This is the way that Gabber does it. -- lorien420@myrealbox.com */ if (gtkspell_start(NULL, ispell_cmd)<0){ debug_printf("gtkspell failed to start when using ispell\n"); if (gtkspell_start(NULL, aspell_cmd)<0){ debug_printf("gtkspell failed to start when using aspell\n"); debug_printf("gtkspell started with aspell\n"); debug_printf("gtkspell started with ispell\n"); c = (struct conversation *)cnv->data; if (convo_options & OPT_CONVO_CHECK_SPELLING) gtkspell_attach(GTK_TEXT(c->entry)); gtkspell_detach(GTK_TEXT(c->entry)); gc = (struct gaim_connection *)con->data; c = (struct conversation *)cht->data; if (convo_options & OPT_CONVO_CHECK_SPELLING) gtkspell_attach(GTK_TEXT(c->entry)); gtkspell_detach(GTK_TEXT(c->entry)); if (!(convo_options & OPT_CONVO_CHECK_SPELLING)) GList *cnv = conversations; GSList *con = connections; struct gaim_connection *gc; c = (struct conversation *)cnv->data; if (convo_options & OPT_CONVO_SHOW_TIME) gtk_imhtml_show_comments(GTK_IMHTML(c->text), TRUE); gtk_imhtml_show_comments(GTK_IMHTML(c->text), FALSE); gc = (struct gaim_connection *)con->data; c = (struct conversation *)cht->data; if (convo_options & OPT_CONVO_SHOW_TIME) gtk_imhtml_show_comments(GTK_IMHTML(c->text), TRUE); gtk_imhtml_show_comments(GTK_IMHTML(c->text), FALSE); GList *cnv = conversations; GSList *con = connections; struct gaim_connection *gc; c = (struct conversation *)cnv->data; if (convo_options & OPT_CONVO_SHOW_SMILEY) gtk_imhtml_show_smileys(GTK_IMHTML(c->text), TRUE); gtk_imhtml_show_smileys(GTK_IMHTML(c->text), FALSE); gc = (struct gaim_connection *)con->data; c = (struct conversation *)cht->data; if (convo_options & OPT_CONVO_SHOW_SMILEY) gtk_imhtml_show_smileys(GTK_IMHTML(c->text), TRUE); gtk_imhtml_show_smileys(GTK_IMHTML(c->text), FALSE); /* evil, evil i tell you! evil! */ if (im_options & OPT_IM_ONE_WINDOW) { GList *x = conversations; if ((convo_options & OPT_CONVO_COMBINE) && (chat_options & OPT_CHAT_ONE_WINDOW)) { convo_notebook = chat_notebook; struct conversation *c = x->data; gtk_widget_destroy(c->text); gtk_widget_reparent(imhtml, c->sw); struct conversation *c = x->data; gtk_container_remove(GTK_CONTAINER(c->sw), c->text); gtk_widget_reparent(imhtml, c->sw); if ((convo_options & OPT_CONVO_COMBINE) && (chat_options & OPT_CHAT_ONE_WINDOW)) { gtk_notebook_remove_page(GTK_NOTEBOOK(chat_notebook), 0); gtk_window_set_focus(GTK_WINDOW(c->window), c->entry); gtk_widget_destroy(all_convos); gtk_widget_destroy(all_convos); if (!chats && !conversations) if (convo_options & OPT_CONVO_COMBINE) { chat_notebook = convo_notebook; } else if (!conversations) { convo_notebook = chat_notebook; } else if (!conversations) { if (convo_options & OPT_CONVO_COMBINE) { convo_notebook = chat_notebook; struct conversation *c = x->data; gtk_container_remove(GTK_CONTAINER(c->sw), c->text); gtk_widget_reparent(imhtml, c->sw); if (convo_options & OPT_CONVO_COMBINE) { gtk_notebook_remove_page(GTK_NOTEBOOK(chat_notebook), 0); set_convo_title(m->data); void set_convo_title(struct conversation *c) if ((im_options & OPT_IM_ALIAS_TAB) && c->gc && ((b = find_buddy(c->gc, c->name)) != NULL)) if (im_options & OPT_IM_ONE_WINDOW) { nb = GTK_NOTEBOOK(convo_notebook); index = g_list_index(conversations, c); gtk_notebook_set_tab_label_text(nb, gtk_notebook_get_nth_page(nb, index), text); if ((find_log_info(c->name)) || (logging_options & OPT_LOG_ALL)) g_snprintf(buf, sizeof(buf), LOG_CONVERSATION_TITLE, text); g_snprintf(buf, sizeof(buf), CONVERSATION_TITLE, text); gtk_window_set_title(GTK_WINDOW(c->window), buf); GList *c = conversations; set_convo_title(c->data); void raise_convo_tab(struct conversation *c) gtk_notebook_set_page(GTK_NOTEBOOK(convo_notebook), g_list_index(conversations, c)); gdk_window_show(c->window->window); if (!convo_notebook || !all_convos) if (im_options & OPT_IM_SIDE_TAB) { if (im_options & OPT_IM_BR_TAB) { gtk_notebook_set_tab_pos(GTK_NOTEBOOK(convo_notebook), GTK_POS_RIGHT); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(convo_notebook), GTK_POS_LEFT); if (im_options & OPT_IM_BR_TAB) { gtk_notebook_set_tab_pos(GTK_NOTEBOOK(convo_notebook), GTK_POS_BOTTOM); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(convo_notebook), GTK_POS_TOP); if (!chat_notebook || !all_chats) if (chat_options & OPT_CHAT_SIDE_TAB) { if (chat_options & OPT_CHAT_BR_TAB) { gtk_notebook_set_tab_pos(GTK_NOTEBOOK(chat_notebook), GTK_POS_RIGHT); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(chat_notebook), GTK_POS_LEFT); if (chat_options & OPT_CHAT_BR_TAB) { gtk_notebook_set_tab_pos(GTK_NOTEBOOK(chat_notebook), GTK_POS_BOTTOM); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(chat_notebook), GTK_POS_TOP); void update_convo_color(gboolean fg) GList *c = conversations; GList *c = conversations; sprintf(b->fontface, "%s", fontface); sprintf(b->fontxfld, "%s", fontxfld); #include <gdk-pixbuf/gdk-pixbuf.h> #define SCALE(x) ((gdk_pixbuf_animation_get_width(x) <= 48 && gdk_pixbuf_animation_get_height(x) <= 48) \ static gboolean redraw_icon(gpointer data) struct conversation *c = data; if (!g_list_find(conversations, c)) { debug_printf("I think this is a bug.\n"); frames = gdk_pixbuf_animation_get_frames(c->anim); frame = g_list_nth_data(frames, c->frame); switch (gdk_pixbuf_frame_get_action(frame)) { case GDK_PIXBUF_FRAME_RETAIN: buf = gdk_pixbuf_frame_get_pixbuf(frame); scale = gdk_pixbuf_scale_simple(buf, MAX(gdk_pixbuf_get_width(buf) * SCALE(c->anim) / gdk_pixbuf_animation_get_width(c->anim), 1), MAX(gdk_pixbuf_get_height(buf) * SCALE(c->anim) / gdk_pixbuf_animation_get_height(c->anim), 1), gdk_pixbuf_render_pixmap_and_mask(scale, &src, &bm, 100); gtk_pixmap_get(GTK_PIXMAP(c->icon), &pm, NULL); gdk_gc_set_clip_mask(gc, bm); gdk_gc_set_clip_origin(gc, gdk_pixbuf_frame_get_x_offset(frame) * SCALE(c->anim)/gdk_pixbuf_animation_get_width(c->anim), gdk_pixbuf_frame_get_y_offset(frame) * SCALE(c->anim)/gdk_pixbuf_animation_get_height(c->anim)); gdk_draw_pixmap(pm, gc, src, 0, 0, gdk_pixbuf_frame_get_x_offset(frame)* SCALE(c->anim)/gdk_pixbuf_animation_get_width(c->anim), gdk_pixbuf_frame_get_y_offset(frame) * SCALE(c->anim)/gdk_pixbuf_animation_get_height(c->anim),-1,-1); gtk_widget_queue_draw(c->icon); case GDK_PIXBUF_FRAME_DISPOSE: buf = gdk_pixbuf_frame_get_pixbuf(frame); scale = gdk_pixbuf_scale_simple(buf, MAX(gdk_pixbuf_get_width(buf) * SCALE(c->anim) / gdk_pixbuf_animation_get_width(c->anim), 1), MAX(gdk_pixbuf_get_height(buf) * SCALE(c->anim) / gdk_pixbuf_animation_get_height(c->anim), 1), gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100); gtk_pixmap_set(GTK_PIXMAP(c->icon), pm, bm); case GDK_PIXBUF_FRAME_REVERT: buf = gdk_pixbuf_frame_get_pixbuf(frame); scale = gdk_pixbuf_scale_simple(buf, MAX(gdk_pixbuf_get_width(buf) * SCALE(c->anim) / gdk_pixbuf_animation_get_width(c->anim), 1), MAX(gdk_pixbuf_get_height(buf) * SCALE(c->anim) / gdk_pixbuf_animation_get_height(c->anim), 1), gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100); gtk_pixmap_set(GTK_PIXMAP(c->icon), pm, bm); c->frame = (c->frame + 1) % g_list_length(frames); delay = MAX(gdk_pixbuf_frame_get_delay_time(frame), 13); c->icon_timer = gtk_timeout_add(delay * 10, redraw_icon, c); static void stop_anim(GtkObject *obj, struct conversation *c) gtk_timeout_remove(c->icon_timer); static void start_anim(GtkObject *obj, struct conversation *c) frames = gdk_pixbuf_animation_get_frames(c->anim); frame = g_list_nth_data(frames, c->frame); delay = MAX(gdk_pixbuf_frame_get_delay_time(frame), 13); c->icon_timer = gtk_timeout_add(delay * 10, redraw_icon, c); static int des_save_icon(GtkObject *obj, GdkEvent *e, struct conversation *c) gtk_widget_destroy(c->save_icon); static void do_save_icon(GtkObject *obj, struct conversation *c) char *f = gtk_file_selection_get_filename(GTK_FILE_SELECTION(c->save_icon)); if (file_is_dir(f, c->save_icon)) void *data = get_icon_data(c->gc, normalize(c->name), &len); fwrite(data, 1, len, file); do_error_dialog("Can't open file for writing", "Error"); gtk_widget_destroy(c->save_icon); static void cancel_save_icon(GtkObject *obj, struct conversation *c) gtk_widget_destroy(c->save_icon); static void save_icon(GtkObject *obj, struct conversation *c) gdk_window_raise(c->save_icon->window); c->save_icon = gtk_file_selection_new(_("Gaim - Save Icon")); gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(c->save_icon)); g_snprintf(buf, BUF_LEN - 1, "%s/%s.icon", g_get_home_dir(), c->name); gtk_file_selection_set_filename(GTK_FILE_SELECTION(c->save_icon), buf); gtk_signal_connect(GTK_OBJECT(c->save_icon), "delete_event", GTK_SIGNAL_FUNC(des_save_icon), c); gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(c->save_icon)->ok_button), "clicked", GTK_SIGNAL_FUNC(do_save_icon), c); gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(c->save_icon)->cancel_button), "clicked", GTK_SIGNAL_FUNC(cancel_save_icon), c); gtk_widget_show(c->save_icon); static gboolean icon_menu(GtkObject *obj, GdkEventButton *e, struct conversation *c) static GtkWidget *menu = NULL; if (e->type != GDK_BUTTON_PRESS) * 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(_("Disable Animation")); gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(stop_anim), c); gtk_menu_append(GTK_MENU(menu), button); } else if (c->anim && (gdk_pixbuf_animation_get_num_frames(c->anim) > 1)) { button = gtk_menu_item_new_with_label(_("Enable Animation")); gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(start_anim), c); gtk_menu_append(GTK_MENU(menu), button); button = gtk_menu_item_new_with_label(_("Hide Icon")); gtk_signal_connect_object(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(remove_icon), (void *)c); gtk_menu_append(GTK_MENU(menu), button); button = gtk_menu_item_new_with_label(_("Save Icon As...")); gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(save_icon), c); gtk_menu_append(GTK_MENU(menu), button); gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, e->button, e->time); void remove_icon(struct conversation *c) gtk_container_remove(GTK_CONTAINER(c->bbox), c->icon->parent->parent); gdk_pixbuf_animation_unref(c->anim); gtk_timeout_remove(c->icon_timer); void update_fontmode(struct conversation *c) gtk_imhtml_set_use_pointsize(GTK_IMHTML(c->text), c->gc->prpl->options & OPT_PROTO_USE_POINT_SIZE); void update_smilies(struct conversation *c) if (c->gc->prpl->smiley_list) { gtk_imhtml_remove_smileys(GTK_IMHTML(c->text)); smilies = c->gc->prpl->smiley_list(); struct _prpl_smiley *smile = (struct _prpl_smiley *)smilies->data; gtk_imhtml_associate_smiley(GTK_IMHTML(c->text), smile->key, smile->xpm); smilies = g_slist_next(smilies); gtk_imhtml_reset_smileys(GTK_IMHTML(c->text)); void update_icon(struct conversation *c) if (im_options & OPT_IM_HIDE_ICONS) data = get_icon_data(c->gc, normalize(c->name), &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. */ g_snprintf(filename, sizeof(filename), "%s/gaimicon-%s.%d", g_get_tmp_dir(), c->name, getpid()); file = fopen(filename, "w"); fwrite(data, 1, len, file); c->anim = gdk_pixbuf_animation_new_from_file(filename); /* make sure we remove the file as soon as possible */ frames = gdk_pixbuf_animation_get_frames(c->anim); buf = gdk_pixbuf_frame_get_pixbuf(frames->data); scale = gdk_pixbuf_scale_simple(buf, MAX(gdk_pixbuf_get_width(buf) * sf / gdk_pixbuf_animation_get_width(c->anim), 1), MAX(gdk_pixbuf_get_height(buf) * sf / gdk_pixbuf_animation_get_height(c->anim), 1), if (gdk_pixbuf_animation_get_num_frames(c->anim) > 1) { int delay = MAX(gdk_pixbuf_frame_get_delay_time(frames->data), 13); c->icon_timer = gtk_timeout_add(delay * 10, redraw_icon, c); gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100); frame = gtk_frame_new(NULL); gtk_frame_set_shadow_type(GTK_FRAME(frame), bm ? GTK_SHADOW_NONE : GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(c->bbox), frame, FALSE, FALSE, 5); event = gtk_event_box_new(); gtk_container_add(GTK_CONTAINER(frame), event); gtk_signal_connect(GTK_OBJECT(event), "button-press-event", GTK_SIGNAL_FUNC(icon_menu), c); c->icon = gtk_pixmap_new(pm, bm); gtk_widget_set_usize(c->icon, sf, sf); gtk_container_add(GTK_CONTAINER(event), c->icon); gtk_widget_show(c->icon); if(im_options & OPT_IM_NO_ANIMATION) void got_new_icon(struct gaim_connection *gc, char *who) struct conversation *c = find_conversation(who); GList *c = conversations; GList *c = conversations; if (im_options & OPT_IM_HIDE_ICONS) if(im_options & OPT_IM_NO_ANIMATION) stop_anim(NULL, c->data); start_anim(NULL, c->data); static void remove_checkbox(struct conversation *c) gtk_container_remove(GTK_CONTAINER(c->lbox), c->check); static void update_checkbox(struct conversation *c) c->check = gtk_check_button_new_with_label(c->gc->checkbox); gtk_box_pack_start(GTK_BOX(c->lbox), c->check, FALSE, FALSE, 5); gtk_widget_show(c->check);