Mercurial > pidgin
annotate src/gtkconv.c @ 4361:25d5b2a7545f
[gaim-migrate @ 4627]
Compiler warnings... Fixed.
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Mon, 20 Jan 2003 09:58:43 +0000 |
| parents | c435a29370b8 |
| children | 4f8a1b65ffa3 |
| rev | line source |
|---|---|
| 4359 | 1 /* |
| 2 * gaim | |
| 3 * | |
| 4 * Copyright (C) 2002-2003, Christian Hammond <chipx86@gnupdate.org> | |
| 5 * | |
| 6 * This program is free software; you can redistribute it and/or modify | |
| 7 * it under the terms of the GNU General Public License as published by | |
| 8 * the Free Software Foundation; either version 2 of the License, or | |
| 9 * (at your option) any later version. | |
| 10 * | |
| 11 * This program is distributed in the hope that it will be useful, | |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 * GNU General Public License for more details. | |
| 15 * | |
| 16 * You should have received a copy of the GNU General Public License | |
| 17 * along with this program; if not, write to the Free Software | |
| 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 * | |
| 20 */ | |
| 21 #ifdef HAVE_CONFIG_H | |
| 22 #include <config.h> | |
| 23 #endif | |
| 24 #include <string.h> | |
| 25 #ifndef _WIN32 | |
| 26 #include <sys/time.h> | |
| 27 #include <unistd.h> | |
| 28 #include <gdk/gdkx.h> | |
| 29 #include <X11/Xlib.h> | |
| 30 #else | |
| 31 #ifdef small | |
| 32 #undef small | |
| 33 #endif | |
| 34 #endif /*_WIN32*/ | |
| 35 #include <sys/types.h> | |
| 36 #include <sys/stat.h> | |
| 37 #include <stdio.h> | |
| 38 #include <stdlib.h> | |
| 39 #include <errno.h> | |
| 40 #include <ctype.h> | |
| 41 #include <gtk/gtk.h> | |
| 42 #ifdef USE_GTKSPELL | |
| 43 #include <gtkspell/gtkspell.h> | |
| 44 #endif | |
| 45 #include "gtkimhtml.h" | |
| 46 #include <gdk/gdkkeysyms.h> | |
| 47 #include "prpl.h" | |
| 48 #include "gtkimhtml.h" | |
| 49 #include "dnd-hints.h" | |
| 50 | |
| 51 static char nick_colors[][8] = { | |
| 52 "#ba55d3", /* Medium Orchid */ | |
| 53 "#ee82ee", /* Violet */ | |
| 54 "#c715b4", /* Medium Violet Red */ | |
| 55 "#ff69b4", /* Hot Pink */ | |
| 56 "#ff6347", /* Tomato */ | |
| 57 "#fa8c00", /* Dark Orange */ | |
| 58 "#fa8072", /* Salmon */ | |
| 59 "#b22222", /* Fire Brick */ | |
| 60 "#f4a460", /* Sandy Brown */ | |
| 61 "#cd5c5c", /* Indian Red */ | |
| 62 "#bc8f8f", /* Rosy Brown */ | |
| 63 "#f0e68c", /* Khaki */ | |
| 64 "#bdb76b", /* Dark Khaki */ | |
| 65 "#228b22", /* Forest Green */ | |
| 66 "#9acd32", /* Yellow Green */ | |
| 67 "#32cd32", /* Lime Green */ | |
| 68 "#3cb371", /* Medium Sea Green */ | |
| 69 "#2e8b57", /* Sea Green */ | |
| 70 "#8fbc8f", /* Dark Sea Green */ | |
| 71 "#66cdaa", /* Medium Aquamarine */ | |
| 72 "#5f9ea0", /* Cadet Blue */ | |
| 73 "#48d1cc", /* Medium Turquoise */ | |
| 74 "#00ced1", /* Dark Turquoise */ | |
| 75 "#4682b4", /* Stell Blue */ | |
| 76 "#00bfff", /* Deep Sky Blue */ | |
| 77 "#1690ff", /* Dodger Blue */ | |
| 78 "#4169ff", /* Royal Blue */ | |
| 79 "#6a5acd", /* Slate Blue */ | |
| 80 "#6495ed", /* Cornflower Blue */ | |
| 81 "#708090", /* Slate gray */ | |
| 82 "#ffdead", /* Navajo White */ | |
| 83 }; | |
| 84 #define NUM_NICK_COLORS (sizeof(nick_colors) / sizeof(*nick_colors)) | |
| 85 | |
| 86 #define SCALE(x) \ | |
| 87 ((gdk_pixbuf_animation_get_width(x) <= 48 && \ | |
| 88 gdk_pixbuf_animation_get_height(x) <= 48) ? 48 : 50) | |
| 89 | |
| 90 struct InviteBuddyInfo | |
| 91 { | |
| 92 GtkWidget *window; | |
| 93 | |
| 94 GtkWidget *entry; | |
| 95 GtkWidget *message; | |
| 96 | |
| 97 struct gaim_conversation *conv; | |
| 98 }; | |
| 99 | |
| 100 char fontface[128] = { 0 }; | |
| 101 int fontsize = 3; | |
| 102 | |
| 103 static GtkWidget *invite_dialog = NULL; | |
| 104 #if 0 | |
| 105 static GtkWidget *invite_entry; | |
| 106 static GtkWidget *invite_mess; | |
| 107 #endif | |
| 108 | |
| 109 static volatile gboolean state_lock = FALSE; | |
| 110 | |
| 111 /* Prototypes. <-- because Paco-Paco hates this comment. */ | |
| 112 static void check_everything(GtkTextBuffer *buffer); | |
| 113 static void quiet_set(GtkWidget *tb, gboolean active); | |
| 114 static void move_next_tab(struct gaim_conversation *conv); | |
| 115 static void do_bold(GtkWidget *bold, struct gaim_gtk_conversation *gtkconv); | |
| 116 static void do_italic(GtkWidget *italic, struct gaim_gtk_conversation *gtkconv); | |
| 117 static void do_underline(GtkWidget *underline, struct gaim_gtk_conversation *gtkconv); | |
| 118 static void do_small(GtkWidget *small, struct gaim_gtk_conversation *gtkconv); | |
| 119 static void do_normal(GtkWidget *small, struct gaim_gtk_conversation *gtkconv); | |
| 120 static void do_big(GtkWidget *small, struct gaim_gtk_conversation *gtkconv); | |
| 121 static void toggle_font(GtkWidget *font, struct gaim_conversation *conv); | |
| 122 static void toggle_fg_color(GtkWidget *color, struct gaim_conversation *conv); | |
| 123 static void toggle_bg_color(GtkWidget *color, struct gaim_conversation *conv); | |
| 124 static void got_typing_keypress(struct gaim_conversation *conv, gboolean first); | |
| 125 static GList *generate_invite_user_names(struct gaim_connection *gc); | |
| 126 static void add_chat_buddy_common(struct gaim_conversation *conv, | |
| 127 const char *name, int pos); | |
| 128 static void tab_complete(struct gaim_conversation *conv); | |
| 129 static void update_send_as_selection(struct gaim_window *win); | |
| 130 | |
| 131 /************************************************************************** | |
| 132 * Callbacks | |
| 133 **************************************************************************/ | |
| 134 static void | |
| 135 do_insert_image_cb(GObject *obj, GtkWidget *wid) | |
| 136 { | |
| 137 struct gaim_conversation *conv; | |
| 138 struct gaim_gtk_conversation *gtkconv; | |
| 139 struct gaim_im *im; | |
| 140 const char *name; | |
| 141 const char *filename; | |
| 142 char *buf; | |
| 143 struct stat st; | |
| 144 int id; | |
| 145 | |
| 146 conv = g_object_get_data(obj, "user_data"); | |
| 147 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 148 im = GAIM_IM(conv); | |
| 149 name = gtk_file_selection_get_filename(GTK_FILE_SELECTION(wid)); | |
| 150 id = g_slist_length(im->images) + 1; | |
| 151 | |
| 152 if (file_is_dir(name, wid)) | |
| 153 return; | |
| 154 | |
| 155 gtk_widget_destroy(wid); | |
| 156 | |
| 157 if (!name) | |
| 158 return; | |
| 159 | |
| 160 if (stat(name, &st) != 0) { | |
| 161 debug_printf("Could not stat %s\n", name); | |
| 162 return; | |
| 163 } | |
| 164 | |
| 165 filename = name; | |
| 166 while (strchr(filename, '/')) | |
| 167 filename = strchr(filename, '/') + 1; | |
| 168 | |
| 169 buf = g_strdup_printf("<IMG SRC=\"file://%s\" ID=\"%d\" DATASIZE=\"%d\">", | |
| 170 filename, id, (int)st.st_size); | |
| 171 im->images = g_slist_append(im->images, g_strdup(name)); | |
| 172 gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER(gtkconv->entry_buffer), | |
| 173 buf, -1); | |
| 174 g_free(buf); | |
| 175 } | |
| 176 | |
| 177 static gint | |
| 178 close_win_cb(GtkWidget *w, GdkEventAny *e, gpointer d) | |
| 179 { | |
| 180 struct gaim_window *win = (struct gaim_window *)d; | |
| 181 | |
| 182 gaim_window_destroy(win); | |
|
4361
25d5b2a7545f
[gaim-migrate @ 4627]
Christian Hammond <chipx86@chipx86.com>
parents:
4360
diff
changeset
|
183 |
|
25d5b2a7545f
[gaim-migrate @ 4627]
Christian Hammond <chipx86@chipx86.com>
parents:
4360
diff
changeset
|
184 return TRUE; |
| 4359 | 185 } |
| 186 | |
| 187 static gint | |
| 188 close_conv_cb(GtkWidget *w, gpointer d) | |
| 189 { | |
| 190 struct gaim_conversation *conv = (struct gaim_conversation *)d; | |
| 191 | |
| 192 gaim_conversation_destroy(conv); | |
|
4361
25d5b2a7545f
[gaim-migrate @ 4627]
Christian Hammond <chipx86@chipx86.com>
parents:
4360
diff
changeset
|
193 |
|
25d5b2a7545f
[gaim-migrate @ 4627]
Christian Hammond <chipx86@chipx86.com>
parents:
4360
diff
changeset
|
194 return TRUE; |
| 4359 | 195 } |
| 196 | |
| 197 static void | |
| 198 insert_image_cb(GtkWidget *save, struct gaim_conversation *conv) | |
| 199 { | |
| 200 struct gaim_gtk_conversation *gtkconv; | |
| 201 char buf[BUF_LONG]; | |
| 202 GtkWidget *window; | |
| 203 | |
| 204 if (gaim_gtk_is_state_locked()) | |
| 205 return; | |
| 206 | |
| 207 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 208 | |
| 209 window = gtk_file_selection_new(_("Gaim - Insert Image")); | |
| 210 g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S, gaim_home_dir()); | |
| 211 gtk_file_selection_set_filename(GTK_FILE_SELECTION(window), buf); | |
| 212 | |
| 213 g_object_set_data(G_OBJECT(GTK_FILE_SELECTION(window)->ok_button), | |
| 214 "user_data", conv); | |
| 215 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(window)->ok_button), | |
| 216 "clicked", G_CALLBACK(do_insert_image_cb), window); | |
| 217 g_signal_connect_swapped( | |
| 218 G_OBJECT(GTK_FILE_SELECTION(window)->cancel_button), | |
| 219 "clicked", G_CALLBACK(gtk_widget_destroy), window); | |
| 220 | |
| 221 gtk_widget_show(window); | |
| 222 | |
| 223 gaim_gtk_set_state_lock(TRUE); | |
| 224 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(gtkconv->toolbar.image), | |
| 225 FALSE); | |
| 226 gaim_gtk_set_state_lock(FALSE); | |
| 227 } | |
| 228 | |
| 229 static void | |
| 230 insert_link_cb(GtkWidget *w, struct gaim_conversation *conv) | |
| 231 { | |
| 232 struct gaim_gtk_conversation *gtkconv; | |
| 233 | |
| 234 if (gaim_gtk_is_state_locked()) | |
| 235 return; | |
| 236 | |
| 237 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 238 | |
| 239 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gtkconv->toolbar.link))) | |
| 240 show_insert_link(gtkconv->toolbar.link, conv); | |
| 241 else if (gtkconv->dialogs.link) | |
| 242 cancel_link(gtkconv->toolbar.link, conv); | |
| 243 else | |
| 244 gaim_gtk_advance_past(gtkconv, "<A HREF>", "</A>"); | |
| 245 | |
| 246 gtk_widget_grab_focus(gtkconv->entry); | |
| 247 } | |
| 248 | |
| 249 static void | |
| 250 insert_smiley_cb(GtkWidget *smiley, struct gaim_conversation *conv) | |
| 251 { | |
| 252 struct gaim_gtk_conversation *gtkconv; | |
| 253 | |
| 254 if (gaim_gtk_is_state_locked()) | |
| 255 return; | |
| 256 | |
| 257 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 258 | |
| 259 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(smiley))) | |
| 260 show_smiley_dialog(conv, smiley); | |
| 261 else if (gtkconv->dialogs.smiley) | |
| 262 close_smiley_dialog(smiley, conv); | |
| 263 | |
| 264 gtk_widget_grab_focus(gtkconv->entry); | |
| 265 } | |
| 266 | |
| 267 static void | |
| 268 menu_save_as_cb(gpointer data, guint action, GtkWidget *widget) | |
| 269 { | |
| 270 struct gaim_window *win = (struct gaim_window *)data; | |
| 271 | |
| 272 save_convo(NULL, gaim_window_get_active_conversation(win)); | |
| 273 } | |
| 274 | |
| 275 static void | |
| 276 menu_view_history_cb(gpointer data, guint action, GtkWidget *widget) | |
| 277 { | |
| 278 struct gaim_window *win = (struct gaim_window *)data; | |
| 279 | |
| 280 conv_show_log(NULL, gaim_window_get_active_conversation(win)); | |
| 281 } | |
| 282 static void | |
| 283 menu_insert_link_cb(gpointer data, guint action, GtkWidget *widget) | |
| 284 { | |
| 285 struct gaim_window *win = (struct gaim_window *)data; | |
| 286 struct gaim_conversation *conv; | |
| 287 struct gaim_gtk_conversation *gtkconv; | |
| 288 | |
| 289 conv = gaim_window_get_active_conversation(win); | |
| 290 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 291 | |
| 292 show_insert_link(gtkconv->toolbar.link, conv); | |
| 293 } | |
| 294 | |
| 295 static void | |
| 296 menu_insert_image_cb(gpointer data, guint action, GtkWidget *widget) | |
| 297 { | |
| 298 struct gaim_window *win = (struct gaim_window *)data; | |
| 299 | |
| 300 insert_image_cb(NULL, gaim_window_get_active_conversation(win)); | |
| 301 } | |
| 302 | |
| 303 static void | |
| 304 menu_close_conv_cb(gpointer data, guint action, GtkWidget *widget) | |
| 305 { | |
| 306 struct gaim_window *win = (struct gaim_window *)data; | |
| 307 | |
| 308 close_conv_cb(NULL, gaim_window_get_active_conversation(win)); | |
| 309 } | |
| 310 | |
| 311 static void | |
| 312 menu_logging_cb(gpointer data, guint action, GtkWidget *widget) | |
| 313 { | |
| 314 struct gaim_window *win = (struct gaim_window *)data; | |
| 315 struct gaim_conversation *conv; | |
| 316 | |
| 317 if (gaim_gtk_is_state_locked()) | |
| 318 return; | |
| 319 | |
| 320 conv = gaim_window_get_active_conversation(win); | |
| 321 | |
| 322 gaim_conversation_set_logging(conv, !gaim_conversation_is_logging(conv)); | |
| 323 } | |
| 324 | |
| 325 static void | |
| 326 menu_sounds_cb(gpointer data, guint action, GtkWidget *widget) | |
| 327 { | |
| 328 struct gaim_window *win = (struct gaim_window *)data; | |
| 329 struct gaim_conversation *conv; | |
| 330 struct gaim_gtk_conversation *gtkconv; | |
| 331 | |
| 332 if (gaim_gtk_is_state_locked()) | |
| 333 return; | |
| 334 | |
| 335 conv = gaim_window_get_active_conversation(win); | |
| 336 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 337 | |
| 338 gtkconv->make_sound = !gtkconv->make_sound; | |
| 339 } | |
| 340 | |
| 341 static gboolean | |
| 342 entry_key_pressed_cb_1(GtkTextBuffer *buffer) | |
| 343 { | |
| 344 check_everything(buffer); | |
| 345 | |
| 346 return FALSE; | |
| 347 } | |
| 348 | |
| 349 static void | |
| 350 send_cb(GtkWidget *widget, struct gaim_conversation *conv) | |
| 351 { | |
| 352 struct gaim_gtk_conversation *gtkconv; | |
| 353 char *buf, *buf2; | |
| 354 GtkTextIter start_iter, end_iter; | |
| 355 int limit; | |
| 356 | |
| 357 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 358 | |
| 359 gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, &start_iter); | |
| 360 gtk_text_buffer_get_end_iter(gtkconv->entry_buffer, &end_iter); | |
| 361 buf2 = gtk_text_buffer_get_text(gtkconv->entry_buffer, | |
| 362 &start_iter, &end_iter, FALSE); | |
| 363 | |
| 364 quiet_set(gtkconv->toolbar.bold, FALSE); | |
| 365 quiet_set(gtkconv->toolbar.italic, FALSE); | |
| 366 quiet_set(gtkconv->toolbar.underline, FALSE); | |
| 367 quiet_set(gtkconv->toolbar.normal_size, FALSE); | |
| 368 quiet_set(gtkconv->toolbar.fgcolor, FALSE); | |
| 369 quiet_set(gtkconv->toolbar.bgcolor, FALSE); | |
| 370 quiet_set(gtkconv->toolbar.link, FALSE); | |
| 371 | |
| 372 gtk_widget_grab_focus(gtkconv->entry); | |
| 373 | |
| 374 limit = 32 * 1024; /* This will be done again in gaim_im_send. *shrug* */ | |
| 375 | |
| 376 buf = g_malloc(limit); | |
| 377 strncpy(buf, buf2, limit); | |
| 378 | |
| 379 g_free(buf2); | |
| 380 | |
| 381 if (strlen(buf) == 0) { | |
| 382 g_free(buf); | |
| 383 | |
| 384 return; | |
| 385 } | |
| 386 | |
| 387 buf2 = g_malloc(limit); | |
| 388 | |
| 389 if (gaim_conversation_get_gc(conv)->flags & OPT_CONN_HTML) { | |
| 390 if (font_options & OPT_FONT_BOLD) { | |
| 391 g_snprintf(buf2, limit, "<B>%s</B>", buf); | |
| 392 strcpy(buf, buf2); | |
| 393 } | |
| 394 | |
| 395 if (font_options & OPT_FONT_ITALIC) { | |
| 396 g_snprintf(buf2, limit, "<I>%s</I>", buf); | |
| 397 strcpy(buf, buf2); | |
| 398 } | |
| 399 | |
| 400 if (font_options & OPT_FONT_UNDERLINE) { | |
| 401 g_snprintf(buf2, limit, "<U>%s</U>", buf); | |
| 402 strcpy(buf, buf2); | |
| 403 } | |
| 404 | |
| 405 if (font_options & OPT_FONT_STRIKE) { | |
| 406 g_snprintf(buf2, limit, "<STRIKE>%s</STRIKE>", buf); | |
| 407 strcpy(buf, buf2); | |
| 408 } | |
| 409 | |
| 410 if ((font_options & OPT_FONT_FACE) || gtkconv->has_font) { | |
| 411 g_snprintf(buf2, limit, | |
| 412 "<FONT FACE=\"%s\">%s</FONT>", gtkconv->fontface, buf); | |
| 413 strcpy(buf, buf2); | |
| 414 } | |
| 415 | |
| 416 if (font_options & OPT_FONT_SIZE) { | |
| 417 g_snprintf(buf2, limit, | |
| 418 "<FONT SIZE=\"%d\">%s</FONT>", fontsize, buf); | |
| 419 strcpy(buf, buf2); | |
| 420 } | |
| 421 | |
| 422 if ((font_options & OPT_FONT_FGCOL) || gtkconv->has_fg) { | |
| 423 g_snprintf(buf2, limit, | |
| 424 "<FONT COLOR=\"#%02X%02X%02X\">%s</FONT>", | |
| 425 gtkconv->fg_color.red / 256, | |
| 426 gtkconv->fg_color.green / 256, | |
| 427 gtkconv->fg_color.blue / 256, buf); | |
| 428 strcpy(buf, buf2); | |
| 429 } | |
| 430 | |
| 431 if ((font_options & OPT_FONT_BGCOL) || gtkconv->has_bg) { | |
| 432 g_snprintf(buf2, limit, | |
| 433 "<BODY BGCOLOR=\"#%02X%02X%02X\">%s</BODY>", | |
| 434 gtkconv->fg_color.red / 256, | |
| 435 gtkconv->fg_color.green / 256, | |
| 436 gtkconv->fg_color.blue / 256, buf); | |
| 437 strcpy(buf, buf2); | |
| 438 } | |
| 439 } | |
| 440 | |
| 441 g_free(buf2); | |
| 442 | |
| 443 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) | |
| 444 gaim_im_send(GAIM_IM(conv), buf); | |
| 445 else | |
| 446 gaim_chat_send(GAIM_CHAT(conv), buf); | |
| 447 | |
| 448 g_free(buf); | |
| 449 | |
| 450 gtk_text_buffer_set_text(gtkconv->entry_buffer, "", -1); | |
| 451 } | |
| 452 | |
| 453 static void | |
| 454 add_cb(GtkWidget *widget, struct gaim_conversation *conv) | |
| 455 { | |
| 456 struct gaim_connection *gc; | |
| 457 struct buddy *b; | |
| 458 const char *name; | |
| 459 | |
| 460 gc = gaim_conversation_get_gc(conv); | |
| 461 name = gaim_conversation_get_name(conv); | |
| 462 b = find_buddy(gc->user, name); | |
| 463 | |
| 464 if (b != NULL) | |
| 465 show_confirm_del(gc, (char *)name); | |
| 466 else if (gc != NULL) | |
| 467 show_add_buddy(gc, (char *)name, NULL, NULL); | |
| 468 | |
| 469 gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); | |
| 470 } | |
| 471 | |
| 472 static void | |
| 473 info_cb(GtkWidget *widget, struct gaim_conversation *conv) | |
| 474 { | |
| 475 struct gaim_gtk_conversation *gtkconv; | |
| 476 | |
| 477 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 478 | |
| 479 if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { | |
| 480 struct gaim_gtk_chat_pane *gtkchat; | |
| 481 GtkTreeIter iter; | |
| 482 GtkTreeModel *model; | |
| 483 GtkTreeSelection *sel; | |
| 484 const char *name; | |
| 485 | |
| 486 gtkchat = gtkconv->u.chat; | |
| 487 | |
| 488 model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); | |
| 489 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkchat->list)); | |
| 490 | |
| 491 if (gtk_tree_selection_get_selected(sel, NULL, &iter)) | |
| 492 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &name, -1); | |
| 493 else | |
| 494 return; | |
| 495 | |
| 496 serv_get_info(gaim_conversation_get_gc(conv), (char *)name); | |
| 497 } | |
| 498 else { | |
| 499 serv_get_info(gaim_conversation_get_gc(conv), | |
| 500 (char *)gaim_conversation_get_name(conv)); | |
| 501 | |
| 502 gtk_widget_grab_focus(gtkconv->entry); | |
| 503 } | |
| 504 } | |
| 505 | |
| 506 static void | |
| 507 warn_cb(GtkWidget *widget, struct gaim_conversation *conv) | |
| 508 { | |
| 509 show_warn_dialog(gaim_conversation_get_gc(conv), | |
| 510 (char *)gaim_conversation_get_name(conv)); | |
| 511 | |
| 512 gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); | |
| 513 } | |
| 514 | |
| 515 static void | |
| 516 block_cb(GtkWidget *widget, struct gaim_conversation *conv) | |
| 517 { | |
| 518 struct gaim_connection *gc; | |
| 519 | |
| 520 gc = gaim_conversation_get_gc(conv); | |
| 521 | |
| 522 if (gc != NULL) | |
| 523 show_add_perm(gc, (char *)gaim_conversation_get_name(conv), FALSE); | |
| 524 | |
| 525 gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); | |
| 526 } | |
| 527 | |
| 528 void | |
| 529 im_cb(GtkWidget *widget, struct gaim_conversation *conv) | |
| 530 { | |
| 531 struct gaim_conversation *conv2; | |
| 532 struct gaim_gtk_conversation *gtkconv; | |
| 533 struct gaim_gtk_chat_pane *gtkchat; | |
| 534 GtkTreeIter iter; | |
| 535 GtkTreeModel *model; | |
| 536 GtkTreeSelection *sel; | |
| 537 const char *name; | |
| 538 | |
| 539 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 540 gtkchat = gtkconv->u.chat; | |
| 541 | |
| 542 model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); | |
| 543 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkchat->list)); | |
| 544 | |
| 545 if (gtk_tree_selection_get_selected(sel, NULL, &iter)) | |
| 546 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &name, -1); | |
| 547 else | |
| 548 return; | |
| 549 | |
| 550 if (*name == '@') name++; | |
| 551 if (*name == '+') name++; | |
| 552 | |
| 553 conv2 = gaim_find_conversation(name); | |
| 554 | |
| 555 if (conv2 != NULL) | |
| 556 gaim_window_raise(gaim_conversation_get_window(conv2)); | |
| 557 else | |
| 558 conv2 = gaim_conversation_new(GAIM_CONV_IM, name); | |
| 559 | |
| 560 gaim_conversation_set_user(conv2, gaim_conversation_get_user(conv)); | |
| 561 } | |
| 562 | |
| 563 static void | |
| 564 ignore_cb(GtkWidget *w, struct gaim_conversation *conv) | |
| 565 { | |
| 566 struct gaim_gtk_conversation *gtkconv; | |
| 567 struct gaim_gtk_chat_pane *gtkchat; | |
| 568 struct gaim_chat *chat; | |
| 569 GtkTreeIter iter; | |
| 570 GtkTreeModel *model; | |
| 571 GtkTreeSelection *sel; | |
| 572 const char *name; | |
| 573 int pos; | |
| 574 | |
| 575 chat = GAIM_CHAT(conv); | |
| 576 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 577 gtkchat = gtkconv->u.chat; | |
| 578 | |
| 579 model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); | |
| 580 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkchat->list)); | |
| 581 | |
| 582 if (gtk_tree_selection_get_selected(sel, NULL, &iter)) { | |
| 583 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &name, -1); | |
| 584 gtk_list_store_remove(GTK_LIST_STORE(model), &iter); | |
| 585 } | |
| 586 else | |
| 587 return; | |
| 588 | |
| 589 pos = g_list_index(gaim_chat_get_users(chat), name); | |
| 590 | |
| 591 if (gaim_chat_is_user_ignored(chat, name)) | |
| 592 gaim_chat_unignore(chat, name); | |
| 593 else | |
| 594 gaim_chat_ignore(chat, name); | |
| 595 | |
| 596 add_chat_buddy_common(conv, name, pos); | |
| 597 } | |
| 598 | |
| 599 static void | |
| 600 menu_im_cb(GtkWidget *w, struct gaim_conversation *conv) | |
| 601 { | |
| 602 const char *who; | |
| 603 struct gaim_conversation *conv2; | |
| 604 | |
| 605 who = g_object_get_data(G_OBJECT(w), "user_data"); | |
| 606 | |
| 607 conv2 = gaim_find_conversation(who); | |
| 608 | |
| 609 if (conv2 != NULL) | |
| 610 gaim_window_show(gaim_conversation_get_window(conv2)); | |
| 611 else { | |
| 612 conv2 = gaim_conversation_new(GAIM_CONV_IM, who); | |
| 613 gaim_conversation_set_user(conv2, gaim_conversation_get_user(conv)); | |
| 614 } | |
| 615 } | |
| 616 | |
| 617 static void | |
| 618 menu_info_cb(GtkWidget *w, struct gaim_conversation *conv) | |
| 619 { | |
| 620 struct gaim_connection *gc; | |
| 621 char *who; | |
| 622 | |
| 623 gc = gaim_conversation_get_gc(conv); | |
| 624 who = g_object_get_data(G_OBJECT(w), "user_data"); | |
| 625 | |
| 626 if (gc != NULL) { | |
| 627 /* | |
| 628 * If there are special needs for getting info on users in | |
| 629 * buddy chat "rooms"... | |
| 630 */ | |
| 631 if (gc->prpl->get_cb_info != NULL) | |
| 632 gc->prpl->get_cb_info(gc, gaim_chat_get_id(GAIM_CHAT(conv)), who); | |
| 633 else | |
| 634 gc->prpl->get_info(gc, who); | |
| 635 } | |
| 636 } | |
| 637 | |
| 638 static void | |
| 639 menu_away_cb(GtkWidget *w, struct gaim_conversation *conv) | |
| 640 { | |
| 641 struct gaim_connection *gc; | |
| 642 char *who; | |
| 643 | |
| 644 gc = gaim_conversation_get_gc(conv); | |
| 645 who = g_object_get_data(G_OBJECT(w), "user_data"); | |
| 646 | |
| 647 if (gc != NULL) { | |
| 648 /* | |
| 649 * May want to expand this to work similarly to menu_info_cb? | |
| 650 */ | |
| 651 | |
| 652 if (gc->prpl->get_cb_away != NULL) | |
| 653 gc->prpl->get_cb_away(gc, gaim_chat_get_id(GAIM_CHAT(conv)), who); | |
| 654 } | |
| 655 } | |
| 656 | |
| 657 static void | |
| 658 menu_add_cb(GtkWidget *w, struct gaim_conversation *conv) | |
| 659 { | |
| 660 struct gaim_connection *gc; | |
| 661 struct buddy *b; | |
| 662 char *name; | |
| 663 | |
| 664 gc = gaim_conversation_get_gc(conv); | |
| 665 name = g_object_get_data(G_OBJECT(w), "user_data"); | |
| 666 b = find_buddy(gc->user, name); | |
| 667 | |
| 668 if (b != NULL) | |
| 669 show_confirm_del(gc, name); | |
| 670 else if (gc != NULL) | |
| 671 show_add_buddy(gc, name, NULL, NULL); | |
| 672 | |
| 673 gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); | |
| 674 } | |
| 675 | |
| 676 static gint | |
| 677 right_click_chat_cb(GtkWidget *widget, GdkEventButton *event, | |
| 678 struct gaim_conversation *conv) | |
| 679 { | |
| 680 struct gaim_gtk_conversation *gtkconv; | |
| 681 struct gaim_gtk_chat_pane *gtkchat; | |
| 682 struct gaim_connection *gc; | |
| 683 struct aim_user *user; | |
| 684 GtkTreePath *path; | |
| 685 GtkTreeIter iter; | |
| 686 GtkTreeModel *model; | |
| 687 GtkTreeViewColumn *column; | |
| 688 gchar *who; | |
| 689 int x, y; | |
| 690 | |
| 691 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 692 gtkchat = gtkconv->u.chat; | |
| 693 user = gaim_conversation_get_user(conv); | |
| 694 gc = user->gc; | |
| 695 | |
| 696 model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); | |
| 697 | |
| 698 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(gtkchat->list), | |
| 699 event->x, event->y, &path, &column, &x, &y); | |
| 700 | |
| 701 if (path == NULL) | |
| 702 return FALSE; | |
| 703 | |
| 704 gtk_tree_selection_select_path(GTK_TREE_SELECTION( | |
| 705 gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkchat->list))), path); | |
| 706 | |
| 707 gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path); | |
| 708 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &who, -1); | |
| 709 | |
| 710 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS) { | |
| 711 struct gaim_conversation *c; | |
| 712 | |
| 713 if ((c = gaim_find_conversation(who)) == NULL) | |
| 714 c = gaim_conversation_new(GAIM_CONV_IM, who); | |
| 715 | |
| 716 gaim_conversation_set_user(c, user); | |
| 717 } | |
| 718 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS) { | |
| 719 static GtkWidget *menu = NULL; | |
| 720 GtkWidget *button; | |
| 721 | |
| 722 /* | |
| 723 * If a menu already exists, destroy it before creating a new one, | |
| 724 * thus freeing-up the memory it occupied. | |
| 725 */ | |
| 726 | |
| 727 if (menu) | |
| 728 gtk_widget_destroy(menu); | |
| 729 | |
| 730 menu = gtk_menu_new(); | |
| 731 | |
| 732 button = gtk_menu_item_new_with_label(_("IM")); | |
| 733 g_signal_connect(G_OBJECT(button), "activate", | |
| 734 G_CALLBACK(menu_im_cb), conv); | |
| 735 g_object_set_data(G_OBJECT(button), "user_data", who); | |
| 736 gtk_menu_append(GTK_MENU(menu), button); | |
| 737 gtk_widget_show(button); | |
| 738 | |
| 739 if (gaim_chat_is_user_ignored(GAIM_CHAT(conv), who)) | |
| 740 button = gtk_menu_item_new_with_label(_("Un-Ignore")); | |
| 741 else | |
| 742 button = gtk_menu_item_new_with_label(_("Ignore")); | |
| 743 | |
| 744 g_signal_connect(G_OBJECT(button), "activate", | |
| 745 G_CALLBACK(ignore_cb), conv); | |
| 746 g_object_set_data(G_OBJECT(button), "user_data", who); | |
| 747 gtk_menu_append(GTK_MENU(menu), button); | |
| 748 gtk_widget_show(button); | |
| 749 | |
| 750 if (gc && gc->prpl->get_info) { | |
| 751 button = gtk_menu_item_new_with_label(_("Info")); | |
| 752 g_signal_connect(G_OBJECT(button), "activate", | |
| 753 G_CALLBACK(menu_info_cb), conv); | |
| 754 g_object_set_data(G_OBJECT(button), "user_data", who); | |
| 755 gtk_menu_append(GTK_MENU(menu), button); | |
| 756 gtk_widget_show(button); | |
| 757 } | |
| 758 | |
| 759 if (gc && gc->prpl->get_cb_away) { | |
| 760 button = gtk_menu_item_new_with_label(_("Get Away Msg")); | |
| 761 g_signal_connect(G_OBJECT(button), "activate", | |
| 762 G_CALLBACK(menu_away_cb), conv); | |
| 763 g_object_set_data(G_OBJECT(button), "user_data", who); | |
| 764 gtk_menu_append(GTK_MENU(menu), button); | |
| 765 gtk_widget_show(button); | |
| 766 } | |
| 767 | |
| 768 /* Added by Jonas <jonas@birme.se> */ | |
| 769 if (gc) { | |
| 770 if (find_buddy(gc->user, who)) | |
| 771 button = gtk_menu_item_new_with_label(_("Remove")); | |
| 772 else | |
| 773 button = gtk_menu_item_new_with_label(_("Add")); | |
| 774 | |
| 775 g_signal_connect(G_OBJECT(button), "activate", | |
| 776 G_CALLBACK(menu_add_cb), conv); | |
| 777 | |
| 778 g_object_set_data(G_OBJECT(button), "user_data", who); | |
| 779 gtk_menu_append(GTK_MENU(menu), button); | |
| 780 gtk_widget_show(button); | |
| 781 } | |
| 782 /* End Jonas */ | |
| 783 | |
| 784 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, | |
| 785 event->button, event->time); | |
| 786 } | |
| 787 | |
| 788 return TRUE; | |
| 789 } | |
| 790 | |
| 791 static void | |
| 792 do_invite(GtkWidget *w, int resp, struct InviteBuddyInfo *info) | |
| 793 { | |
| 794 const char *buddy, *message; | |
| 795 struct gaim_gtk_conversation *gtkconv; | |
| 796 | |
| 797 gtkconv = GAIM_GTK_CONVERSATION(info->conv); | |
| 798 | |
| 799 if (resp == GTK_RESPONSE_OK) { | |
| 800 buddy = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(info->entry)->entry)); | |
| 801 message = gtk_entry_get_text(GTK_ENTRY(info->message)); | |
| 802 | |
| 803 if (!g_strcasecmp(buddy, "")) { | |
| 804 g_free(info); | |
| 805 | |
| 806 return; | |
| 807 } | |
| 808 | |
| 809 serv_chat_invite(gaim_conversation_get_gc(info->conv), | |
| 810 gaim_chat_get_id(GAIM_CHAT(info->conv)), | |
| 811 message, buddy); | |
| 812 } | |
| 813 | |
| 814 gtk_widget_destroy(invite_dialog); | |
| 815 invite_dialog = NULL; | |
| 816 | |
| 817 g_free(info); | |
| 818 } | |
| 819 | |
| 820 static void | |
| 821 invite_cb(GtkWidget *widget, struct gaim_conversation *conv) | |
| 822 { | |
| 823 struct InviteBuddyInfo *info = NULL; | |
| 824 | |
| 825 if (invite_dialog == NULL) { | |
| 826 struct gaim_connection *gc; | |
| 827 struct gaim_window *win; | |
| 828 struct gaim_gtk_window *gtkwin; | |
| 829 char *filename; | |
| 830 GtkWidget *label; | |
| 831 GtkWidget *vbox, *hbox; | |
| 832 GtkWidget *table; | |
| 833 GtkWidget *img; | |
| 834 | |
| 835 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "dialogs", | |
| 836 "gaim_question.png", NULL); | |
| 837 | |
| 838 img = gtk_image_new_from_file(filename); | |
| 839 | |
| 840 g_free(filename); | |
| 841 | |
| 842 | |
| 843 info = g_new0(struct InviteBuddyInfo, 1); | |
| 844 info->conv = conv; | |
| 845 | |
| 846 gc = gaim_conversation_get_gc(conv); | |
| 847 win = gaim_conversation_get_window(conv); | |
| 848 gtkwin = GAIM_GTK_WINDOW(win); | |
| 849 | |
| 850 /* Create the new dialog. */ | |
| 851 invite_dialog = gtk_dialog_new_with_buttons( | |
| 852 _("Gaim - Invite Buddy Into Chat Room"), | |
| 853 GTK_WINDOW(gtkwin->window), | |
| 854 GTK_DIALOG_MODAL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
| 855 GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); | |
| 856 | |
| 857 gtk_dialog_set_default_response(GTK_DIALOG(invite_dialog), | |
| 858 GTK_RESPONSE_OK); | |
| 859 gtk_container_set_border_width(GTK_CONTAINER(invite_dialog), 6); | |
| 860 gtk_window_set_resizable(GTK_WINDOW(invite_dialog), FALSE); | |
| 861 gtk_dialog_set_has_separator(GTK_DIALOG(invite_dialog), FALSE); | |
| 862 | |
| 863 /* Setup the outside spacing. */ | |
| 864 vbox = GTK_DIALOG(invite_dialog)->vbox; | |
| 865 | |
| 866 gtk_box_set_spacing(GTK_BOX(vbox), 12); | |
| 867 gtk_container_set_border_width(GTK_CONTAINER(vbox), 6); | |
| 868 | |
| 869 /* Setup the inner hbox and put the dialog's icon in it. */ | |
| 870 hbox = gtk_hbox_new(FALSE, 12); | |
| 871 gtk_container_add(GTK_CONTAINER(vbox), hbox); | |
| 872 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
| 873 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
| 874 | |
| 875 /* Setup the right vbox. */ | |
| 876 vbox = gtk_vbox_new(FALSE, 0); | |
| 877 gtk_container_add(GTK_CONTAINER(hbox), vbox); | |
| 878 | |
| 879 /* Put our happy label in it. */ | |
| 880 label = gtk_label_new(_("Please enter the name of the user you wish " | |
| 881 "to invite, along with an optional invite " | |
| 882 "message.")); | |
| 883 gtk_widget_set_size_request(label, 350, -1); | |
| 884 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
| 885 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
| 886 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
| 887 | |
| 888 /* hbox for the table, and to give it some spacing on the left. */ | |
| 889 hbox = gtk_hbox_new(FALSE, 6); | |
| 890 gtk_container_add(GTK_CONTAINER(vbox), hbox); | |
| 891 | |
| 892 /* Setup the table we're going to use to lay stuff out. */ | |
| 893 table = gtk_table_new(2, 2, FALSE); | |
| 894 gtk_table_set_row_spacings(GTK_TABLE(table), 6); | |
| 895 gtk_table_set_col_spacings(GTK_TABLE(table), 6); | |
| 896 gtk_container_set_border_width(GTK_CONTAINER(table), 12); | |
| 897 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); | |
| 898 | |
| 899 /* Now the Buddy label */ | |
| 900 label = gtk_label_new(NULL); | |
| 901 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Buddy:")); | |
| 902 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
| 903 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); | |
| 904 | |
| 905 /* Now the Buddy drop-down entry field. */ | |
| 906 info->entry = gtk_combo_new(); | |
| 907 gtk_combo_set_case_sensitive(GTK_COMBO(info->entry), FALSE); | |
| 908 gtk_entry_set_activates_default( | |
| 909 GTK_ENTRY(GTK_COMBO(info->entry)->entry), TRUE); | |
| 910 | |
| 911 gtk_table_attach_defaults(GTK_TABLE(table), info->entry, 1, 2, 0, 1); | |
| 912 gtk_label_set_mnemonic_widget(GTK_LABEL(label), info->entry); | |
| 913 | |
| 914 /* Fill in the names. */ | |
| 915 gtk_combo_set_popdown_strings(GTK_COMBO(info->entry), | |
| 916 generate_invite_user_names(gc)); | |
| 917 | |
| 918 | |
| 919 /* Now the label for "Message" */ | |
| 920 label = gtk_label_new(NULL); | |
| 921 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Message:")); | |
| 922 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
| 923 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2); | |
| 924 | |
| 925 | |
| 926 /* And finally, the Message entry field. */ | |
| 927 info->message = gtk_entry_new(); | |
| 928 gtk_entry_set_activates_default(GTK_ENTRY(info->message), TRUE); | |
| 929 | |
| 930 gtk_table_attach_defaults(GTK_TABLE(table), info->message, 1, 2, 1, 2); | |
| 931 gtk_label_set_mnemonic_widget(GTK_LABEL(label), info->message); | |
| 932 | |
| 933 /* Connect the signals. */ | |
| 934 g_signal_connect(G_OBJECT(invite_dialog), "response", | |
| 935 G_CALLBACK(do_invite), info); | |
| 936 } | |
| 937 | |
| 938 gtk_widget_show_all(invite_dialog); | |
| 939 | |
| 940 if (info != NULL) | |
| 941 gtk_widget_grab_focus(GTK_COMBO(info->entry)->entry); | |
| 942 } | |
| 943 | |
| 944 static gboolean | |
| 945 entry_key_pressed_cb_2(GtkWidget *entry, GdkEventKey *event, gpointer data) | |
| 946 { | |
| 947 struct gaim_window *win; | |
| 948 struct gaim_conversation *conv; | |
| 949 struct gaim_gtk_conversation *gtkconv; | |
| 950 | |
| 951 conv = (struct gaim_conversation *)data; | |
| 952 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 953 win = gaim_conversation_get_window(conv); | |
| 954 | |
| 955 if (event->keyval == GDK_Escape) { | |
| 956 if (convo_options & OPT_CONVO_ESC_CAN_CLOSE) { | |
| 957 g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); | |
| 958 gaim_conversation_destroy(conv); | |
| 959 } | |
| 960 } | |
| 961 else if (event->keyval == GDK_Page_Up) { | |
| 962 g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); | |
| 963 | |
| 964 if (!(event->state & GDK_CONTROL_MASK)) | |
| 965 gtk_imhtml_page_up(GTK_IMHTML(gtkconv->imhtml)); | |
| 966 } | |
| 967 else if (event->keyval == GDK_Page_Down) { | |
| 968 g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); | |
| 969 | |
| 970 if (!(event->state & GDK_CONTROL_MASK)) | |
| 971 gtk_imhtml_page_down(GTK_IMHTML(gtkconv->imhtml)); | |
| 972 } | |
| 973 else if ((event->keyval == GDK_F2) && | |
| 974 (convo_options & OPT_CONVO_F2_TOGGLES)) { | |
| 975 gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), | |
| 976 !GTK_IMHTML(gtkconv->imhtml)->comments); | |
| 977 } | |
| 978 else if (event->keyval == GDK_Return || event->keyval == GDK_KP_Enter) { | |
| 979 if ((event->state & GDK_CONTROL_MASK) && | |
| 980 (convo_options & OPT_CONVO_CTL_ENTER)) { | |
| 981 | |
| 982 send_cb(NULL, conv); | |
| 983 g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); | |
| 984 | |
| 985 return TRUE; | |
| 986 } | |
| 987 else if (!(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK)) && | |
| 988 (convo_options & OPT_CONVO_ENTER_SENDS)) { | |
| 989 | |
| 990 send_cb(NULL, conv); | |
| 991 g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); | |
| 992 | |
| 993 return TRUE; | |
| 994 } | |
| 995 | |
| 996 return FALSE; | |
| 997 } | |
| 998 else if ((event->state & GDK_CONTROL_MASK) && (event->keyval == 'm')) { | |
| 999 g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); | |
| 1000 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, "\n", 1); | |
| 1001 } | |
| 1002 else if (event->state & GDK_CONTROL_MASK) { | |
| 1003 switch (event->keyval) { | |
| 1004 case GDK_Up: | |
| 1005 if (!conv->send_history) | |
| 1006 break; | |
| 1007 | |
| 1008 if (!conv->send_history->prev) { | |
| 1009 GtkTextIter start, end; | |
| 1010 | |
| 1011 if (conv->send_history->data) | |
| 1012 g_free(conv->send_history->data); | |
| 1013 | |
| 1014 gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, | |
| 1015 &start); | |
| 1016 gtk_text_buffer_get_end_iter(gtkconv->entry_buffer, &end); | |
| 1017 | |
| 1018 conv->send_history->data = | |
| 1019 gtk_text_buffer_get_text(gtkconv->entry_buffer, | |
| 1020 &start, &end, FALSE); | |
| 1021 } | |
| 1022 | |
| 1023 if (conv->send_history->next && | |
| 1024 conv->send_history->next->data) { | |
| 1025 | |
| 1026 conv->send_history = conv->send_history->next; | |
| 1027 gtk_text_buffer_set_text(gtkconv->entry_buffer, | |
| 1028 conv->send_history->data, -1); | |
| 1029 } | |
| 1030 | |
| 1031 break; | |
| 1032 | |
| 1033 case GDK_Down: | |
| 1034 if (!conv->send_history) | |
| 1035 break; | |
| 1036 | |
| 1037 if (conv->send_history->prev) { | |
| 1038 conv->send_history = conv->send_history->prev; | |
| 1039 | |
| 1040 if (conv->send_history->data) | |
| 1041 gtk_text_buffer_set_text(gtkconv->entry_buffer, | |
| 1042 conv->send_history->data, -1); | |
| 1043 } | |
| 1044 | |
| 1045 break; | |
| 1046 } | |
| 1047 | |
| 1048 if (convo_options & OPT_CONVO_CTL_CHARS) { | |
| 1049 switch (event->keyval) { | |
| 1050 case 'i': | |
| 1051 case 'I': | |
| 1052 quiet_set(gtkconv->toolbar.italic, | |
| 1053 !gtk_toggle_button_get_active( | |
| 1054 GTK_TOGGLE_BUTTON(gtkconv->toolbar.italic))); | |
| 1055 | |
| 1056 do_italic(gtkconv->toolbar.italic, gtkconv); | |
| 1057 | |
| 1058 g_signal_stop_emission_by_name(G_OBJECT(entry), | |
| 1059 "key_press_event"); | |
| 1060 break; | |
| 1061 | |
| 1062 case 'u': /* ctrl-u is GDK_Clear, which clears the line. */ | |
| 1063 case 'U': | |
| 1064 quiet_set(gtkconv->toolbar.underline, | |
| 1065 !gtk_toggle_button_get_active( | |
| 1066 GTK_TOGGLE_BUTTON(gtkconv->toolbar.underline))); | |
| 1067 | |
| 1068 do_underline(gtkconv->toolbar.underline, gtkconv); | |
| 1069 | |
| 1070 g_signal_stop_emission_by_name(G_OBJECT(entry), | |
| 1071 "key_press_event"); | |
| 1072 break; | |
| 1073 | |
| 1074 case 'b': /* ctrl-b is GDK_Left, which moves backwards. */ | |
| 1075 case 'B': | |
| 1076 quiet_set(gtkconv->toolbar.bold, | |
| 1077 !gtk_toggle_button_get_active( | |
| 1078 GTK_TOGGLE_BUTTON(gtkconv->toolbar.bold))); | |
| 1079 | |
| 1080 do_bold(gtkconv->toolbar.bold, gtkconv); | |
| 1081 | |
| 1082 g_signal_stop_emission_by_name(G_OBJECT(entry), | |
| 1083 "key_press_event"); | |
| 1084 break; | |
| 1085 | |
| 1086 case '-': | |
| 1087 do_small(NULL, gtkconv); | |
| 1088 | |
| 1089 g_signal_stop_emission_by_name(G_OBJECT(entry), | |
| 1090 "key_press_event"); | |
| 1091 break; | |
| 1092 | |
| 1093 case '=': | |
| 1094 case '+': | |
| 1095 do_big(NULL, gtkconv); | |
| 1096 | |
| 1097 g_signal_stop_emission_by_name(G_OBJECT(entry), | |
| 1098 "key_press_event"); | |
| 1099 break; | |
| 1100 | |
| 1101 case '0': | |
| 1102 do_normal(NULL, gtkconv); | |
| 1103 | |
| 1104 g_signal_stop_emission_by_name(G_OBJECT(entry), | |
| 1105 "key_press_event"); | |
| 1106 break; | |
| 1107 | |
| 1108 case 'f': | |
| 1109 case 'F': | |
| 1110 quiet_set(gtkconv->toolbar.normal_size, | |
| 1111 !gtk_toggle_button_get_active( | |
| 1112 GTK_TOGGLE_BUTTON(gtkconv->toolbar.normal_size))); | |
| 1113 | |
| 1114 toggle_font(gtkconv->toolbar.normal_size, conv); | |
| 1115 | |
| 1116 g_signal_stop_emission_by_name(G_OBJECT(entry), | |
| 1117 "key_press_event"); | |
| 1118 break; | |
| 1119 } | |
| 1120 } | |
| 1121 | |
| 1122 if (convo_options & OPT_CONVO_CTL_SMILEYS) { | |
| 1123 char buf[7]; | |
| 1124 | |
| 1125 *buf = '\0'; | |
| 1126 | |
| 1127 switch (event->keyval) { | |
| 1128 case '1': strcpy(buf, ":-)"); break; | |
| 1129 case '2': strcpy(buf, ":-("); break; | |
| 1130 case '3': strcpy(buf, ";-)"); break; | |
| 1131 case '4': strcpy(buf, ":-P"); break; | |
| 1132 case '5': strcpy(buf, "=-O"); break; | |
| 1133 case '6': strcpy(buf, ":-*"); break; | |
| 1134 case '7': strcpy(buf, ">:o"); break; | |
| 1135 case '8': strcpy(buf, "8-)"); break; | |
| 1136 case '!': strcpy(buf, ":-$"); break; | |
| 1137 case '@': strcpy(buf, ":-!"); break; | |
| 1138 case '#': strcpy(buf, ":-["); break; | |
| 1139 case '$': strcpy(buf, "O:-)"); break; | |
| 1140 case '%': strcpy(buf, ":-/"); break; | |
| 1141 case '^': strcpy(buf, ":'("); break; | |
| 1142 case '&': strcpy(buf, ":-X"); break; | |
| 1143 case '*': strcpy(buf, ":-D"); break; | |
| 1144 default: break; | |
| 1145 } | |
| 1146 | |
| 1147 if (*buf) { | |
| 1148 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, | |
| 1149 buf, -1); | |
| 1150 g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); | |
| 1151 } | |
| 1152 } | |
| 1153 | |
| 1154 if (event->keyval == 'l') { | |
| 1155 gtk_imhtml_clear(GTK_IMHTML(gtkconv->imhtml)); | |
| 1156 g_string_free(conv->history, TRUE); | |
| 1157 conv->history = g_string_new(""); | |
| 1158 } | |
| 1159 else if ((event->keyval == 'w') && | |
| 1160 (convo_options & OPT_CONVO_CTL_W_CLOSES)) { | |
| 1161 | |
| 1162 g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); | |
| 1163 gaim_conversation_destroy(conv); | |
| 1164 return TRUE; | |
| 1165 } | |
| 1166 else if (event->keyval == 'n') { | |
| 1167 g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); | |
| 1168 | |
| 1169 show_im_dialog(); | |
| 1170 } | |
| 1171 else if (event->keyval == 'z') { | |
| 1172 g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); | |
| 1173 | |
|
4361
25d5b2a7545f
[gaim-migrate @ 4627]
Christian Hammond <chipx86@chipx86.com>
parents:
4360
diff
changeset
|
1174 #ifndef _WIN32 |
| 4359 | 1175 XIconifyWindow(GDK_DISPLAY(), |
| 1176 GDK_WINDOW_XWINDOW(gtkwin->window->window), | |
| 1177 ((_XPrivDisplay)GDK_DISPALY())->default_screen); | |
| 1178 #endif | |
| 1179 } | |
| 1180 else if (event->keyval == '[') { | |
| 1181 gaim_window_switch_conversation(win, | |
| 1182 gaim_conversation_get_index(conv) - 1); | |
| 1183 | |
| 1184 g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); | |
| 1185 } | |
| 1186 else if (event->keyval == ']') { | |
| 1187 gaim_window_switch_conversation(win, | |
| 1188 gaim_conversation_get_index(conv) + 1); | |
| 1189 | |
| 1190 g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); | |
| 1191 } | |
| 1192 else if (event->keyval == GDK_Tab) { | |
| 1193 move_next_tab(conv); | |
| 1194 | |
| 1195 g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); | |
| 1196 | |
| 1197 return TRUE; | |
| 1198 } | |
| 1199 } | |
| 1200 else if ((event->keyval == GDK_Tab) && | |
| 1201 gaim_conversation_get_type(conv) == GAIM_CONV_CHAT && | |
| 1202 (chat_options & OPT_CHAT_TAB_COMPLETE)) { | |
| 1203 | |
| 1204 tab_complete(conv); | |
| 1205 | |
| 1206 g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); | |
| 1207 | |
| 1208 return TRUE; | |
| 1209 } | |
| 1210 else if ((event->state & GDK_MOD1_MASK) && | |
| 1211 event->keyval > '0' && event->keyval <= '9') { | |
| 1212 | |
| 1213 gaim_window_switch_conversation(win, event->keyval - '1'); | |
| 1214 | |
| 1215 g_signal_stop_emission_by_name(G_OBJECT(entry), "key_press_event"); | |
| 1216 } | |
| 1217 | |
| 1218 return FALSE; | |
| 1219 } | |
| 1220 | |
| 1221 /* | |
| 1222 * NOTE: | |
| 1223 * This guy just kills a single right click from being propagated any | |
| 1224 * further. I have no idea *why* we need this, but we do ... It | |
| 1225 * prevents right clicks on the GtkTextView in a convo dialog from | |
| 1226 * going all the way down to the notebook. I suspect a bug in | |
| 1227 * GtkTextView, but I'm not ready to point any fingers yet. | |
| 1228 */ | |
| 1229 static gboolean | |
| 1230 entry_stop_rclick_cb(GtkWidget *widget, GdkEventButton *event, gpointer data) | |
| 1231 { | |
| 1232 if (event->button == 3 && event->type == GDK_BUTTON_PRESS) { | |
| 1233 /* Right single click */ | |
| 1234 g_signal_stop_emission_by_name(G_OBJECT(widget), "button_press_event"); | |
| 1235 | |
| 1236 return TRUE; | |
| 1237 } | |
| 1238 | |
| 1239 return FALSE; | |
| 1240 } | |
| 1241 | |
| 1242 static void | |
| 1243 menu_conv_sel_send_cb(GObject *m, struct aim_user *user) | |
| 1244 { | |
| 1245 struct gaim_window *win = g_object_get_data(m, "user_data"); | |
| 1246 struct gaim_conversation *conv; | |
| 1247 | |
| 1248 if (gaim_gtk_is_state_locked()) | |
| 1249 return; | |
| 1250 | |
| 1251 conv = gaim_window_get_active_conversation(win); | |
| 1252 | |
| 1253 gaim_conversation_set_user(conv, user); | |
| 1254 } | |
| 1255 | |
| 1256 static void | |
| 1257 insert_text_cb(GtkTextBuffer *textbuffer, GtkTextIter *position, | |
| 1258 gchar *new_text, gint new_text_length, gpointer user_data) | |
| 1259 { | |
| 1260 struct gaim_conversation *conv = (struct gaim_conversation *)user_data; | |
| 1261 | |
| 1262 if (conv == NULL) | |
| 1263 return; | |
| 1264 | |
| 1265 if (misc_options & OPT_MISC_STEALTH_TYPING) | |
| 1266 return; | |
| 1267 | |
| 1268 got_typing_keypress(conv, (gtk_text_iter_is_start(position) && | |
| 1269 gtk_text_iter_is_end(position))); | |
| 1270 } | |
| 1271 | |
| 1272 static void | |
| 1273 delete_text_cb(GtkTextBuffer *textbuffer, GtkTextIter *start_pos, | |
| 1274 GtkTextIter *end_pos, gpointer user_data) | |
| 1275 { | |
| 1276 struct gaim_conversation *conv = (struct gaim_conversation *)user_data; | |
| 1277 struct gaim_im *im; | |
| 1278 | |
| 1279 if (conv == NULL) | |
| 1280 return; | |
| 1281 | |
| 1282 if (misc_options & OPT_MISC_STEALTH_TYPING) | |
| 1283 return; | |
| 1284 | |
| 1285 im = GAIM_IM(conv); | |
| 1286 | |
| 1287 if (gtk_text_iter_is_start(start_pos) && gtk_text_iter_is_end(end_pos)) { | |
| 1288 | |
| 1289 /* We deleted all the text, so turn off typing. */ | |
| 1290 if (gaim_im_get_type_again_timeout(im)) | |
| 1291 gaim_im_stop_type_again_timeout(im); | |
| 1292 | |
| 1293 /* XXX The (char *) should go away! Somebody add consts to stuff! */ | |
| 1294 serv_send_typing(gaim_conversation_get_gc(conv), | |
| 1295 (char *)gaim_conversation_get_name(conv), | |
| 1296 NOT_TYPING); | |
| 1297 } | |
| 1298 else { | |
| 1299 /* We're deleting, but not all of it, so it counts as typing. */ | |
| 1300 got_typing_keypress(conv, FALSE); | |
| 1301 } | |
| 1302 } | |
| 1303 | |
| 1304 static void | |
| 1305 notebook_init_grab(struct gaim_gtk_window *gtkwin, GtkWidget *widget) | |
| 1306 { | |
| 1307 static GdkCursor *cursor = NULL; | |
| 1308 | |
| 1309 gtkwin->in_drag = TRUE; | |
| 1310 | |
| 1311 if (gtkwin->drag_leave_signal) { | |
| 1312 g_signal_handler_disconnect(G_OBJECT(widget), | |
| 1313 gtkwin->drag_leave_signal); | |
| 1314 | |
| 1315 gtkwin->drag_leave_signal = 0; | |
| 1316 } | |
| 1317 | |
| 1318 if (cursor == NULL) | |
| 1319 cursor = gdk_cursor_new(GDK_FLEUR); | |
| 1320 | |
| 1321 /* Grab the pointer */ | |
| 1322 gtk_grab_add(gtkwin->notebook); | |
| 1323 gdk_pointer_grab(gtkwin->notebook->window, FALSE, | |
| 1324 GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, | |
| 1325 NULL, cursor, GDK_CURRENT_TIME); | |
| 1326 } | |
| 1327 | |
| 1328 static gboolean | |
| 1329 notebook_motion_cb(GtkWidget *widget, GdkEventButton *e, | |
| 1330 struct gaim_window *win) | |
| 1331 { | |
| 1332 struct gaim_gtk_window *gtkwin; | |
| 1333 | |
| 1334 gtkwin = GAIM_GTK_WINDOW(win); | |
| 1335 | |
| 1336 /* | |
| 1337 * Make sure the user moved the mouse far enough for the | |
| 1338 * drag to be initiated. | |
| 1339 */ | |
| 1340 if (gtkwin->in_predrag) { | |
| 1341 if (e->x_root < gtkwin->drag_min_x || | |
| 1342 e->x_root >= gtkwin->drag_max_x || | |
| 1343 e->y_root < gtkwin->drag_min_y || | |
| 1344 e->y_root >= gtkwin->drag_max_y) { | |
| 1345 | |
| 1346 gtkwin->in_predrag = FALSE; | |
| 1347 notebook_init_grab(gtkwin, widget); | |
| 1348 } | |
| 1349 } | |
| 1350 else { /* Otherwise, draw the arrows. */ | |
| 1351 struct gaim_window *dest_win; | |
| 1352 struct gaim_gtk_window *dest_gtkwin; | |
| 1353 GtkNotebook *dest_notebook; | |
| 1354 GtkWidget *tab, *last_vis_tab = NULL; | |
| 1355 gint nb_x, nb_y, page_num, i, last_vis_tab_loc = -1; | |
| 1356 gint arrow1_x, arrow1_y, arrow2_x, arrow2_y; | |
| 1357 gboolean horiz_tabs = FALSE, tab_found = FALSE; | |
| 1358 GList *l; | |
| 1359 | |
| 1360 /* Get the window that the cursor is over. */ | |
| 1361 dest_win = gaim_gtkwin_get_at_xy(e->x_root, e->y_root); | |
| 1362 | |
| 1363 if (dest_win == NULL) { | |
| 1364 dnd_hints_hide_all(); | |
| 1365 | |
| 1366 return TRUE; | |
| 1367 } | |
| 1368 | |
| 1369 dest_gtkwin = GAIM_GTK_WINDOW(dest_win); | |
| 1370 | |
| 1371 dest_notebook = GTK_NOTEBOOK(dest_gtkwin->notebook); | |
| 1372 | |
| 1373 gdk_window_get_origin(GTK_WIDGET(dest_notebook)->window, &nb_x, &nb_y); | |
| 1374 | |
| 1375 arrow1_x = arrow2_x = nb_x; | |
| 1376 arrow1_y = arrow2_y = nb_y; | |
| 1377 | |
| 1378 page_num = gaim_gtkconv_get_dest_tab_at_xy(dest_win, | |
| 1379 e->x_root, e->y_root); | |
| 1380 | |
| 1381 if (gtk_notebook_get_tab_pos(dest_notebook) == GTK_POS_TOP || | |
| 1382 gtk_notebook_get_tab_pos(dest_notebook) == GTK_POS_BOTTOM) { | |
| 1383 | |
| 1384 horiz_tabs = TRUE; | |
| 1385 } | |
| 1386 | |
| 1387 /* Find out where to put the arrows. */ | |
| 1388 for (l = gaim_window_get_conversations(dest_win), i = 0; | |
| 1389 l != NULL; | |
| 1390 l = l->next, i++) { | |
| 1391 | |
| 1392 struct gaim_conversation *conv = l->data; | |
| 1393 | |
| 1394 tab = GAIM_GTK_CONVERSATION(conv)->tabby; | |
| 1395 | |
| 1396 /* | |
| 1397 * If this is the correct tab, record the positions | |
| 1398 * for the arrows. | |
| 1399 */ | |
| 1400 if (i == page_num) { | |
| 1401 if (horiz_tabs) { | |
| 1402 arrow1_x = arrow2_x = nb_x + tab->allocation.x; | |
| 1403 arrow1_y = nb_y + tab->allocation.y; | |
| 1404 arrow2_y = nb_y + tab->allocation.y + | |
| 1405 tab->allocation.height; | |
| 1406 } | |
| 1407 else { | |
| 1408 arrow1_x = nb_x + tab->allocation.x; | |
| 1409 arrow2_x = nb_x + tab->allocation.x + | |
| 1410 tab->allocation.width; | |
| 1411 arrow1_y = arrow2_y = nb_y + tab->allocation.y; | |
| 1412 } | |
| 1413 | |
| 1414 tab_found = TRUE; | |
| 1415 break; | |
| 1416 } | |
| 1417 else { /* Keep track of the right-most tab that we see. */ | |
| 1418 if (horiz_tabs && tab->allocation.x > last_vis_tab_loc) { | |
| 1419 last_vis_tab = tab; | |
| 1420 last_vis_tab_loc = tab->allocation.x; | |
| 1421 } | |
| 1422 else if (!horiz_tabs && tab->allocation.y > last_vis_tab_loc) { | |
| 1423 last_vis_tab = tab; | |
| 1424 last_vis_tab_loc = tab->allocation.y; | |
| 1425 } | |
| 1426 } | |
| 1427 } | |
| 1428 | |
| 1429 /* | |
| 1430 * If we didn't find the tab, then we'll just place the | |
| 1431 * arrows to the right/bottom of the last visible tab. | |
| 1432 */ | |
| 1433 if (!tab_found && last_vis_tab) { | |
| 1434 if (horiz_tabs) { | |
| 1435 arrow1_x = arrow2_x = nb_x + last_vis_tab->allocation.x + | |
| 1436 last_vis_tab->allocation.width; | |
| 1437 arrow1_y = nb_y + last_vis_tab->allocation.y; | |
| 1438 arrow2_y = nb_y + last_vis_tab->allocation.y + | |
| 1439 last_vis_tab->allocation.height; | |
| 1440 } | |
| 1441 else { | |
| 1442 arrow1_x = nb_x + last_vis_tab->allocation.x; | |
| 1443 arrow2_x = nb_x + last_vis_tab->allocation.x + | |
| 1444 last_vis_tab->allocation.width; | |
| 1445 arrow1_y = arrow2_y = nb_y + last_vis_tab->allocation.y + | |
| 1446 last_vis_tab->allocation.height; | |
| 1447 } | |
| 1448 } | |
| 1449 | |
| 1450 if (horiz_tabs) { | |
| 1451 dnd_hints_show(HINT_ARROW_DOWN, arrow1_x, arrow1_y); | |
| 1452 dnd_hints_show(HINT_ARROW_UP, arrow2_x, arrow2_y); | |
| 1453 } | |
| 1454 else { | |
| 1455 dnd_hints_show(HINT_ARROW_RIGHT, arrow1_x, arrow1_y); | |
| 1456 dnd_hints_show(HINT_ARROW_LEFT, arrow2_x, arrow2_y); | |
| 1457 } | |
| 1458 } | |
| 1459 | |
| 1460 return TRUE; | |
| 1461 } | |
| 1462 | |
| 1463 static gboolean | |
| 1464 notebook_leave_cb(GtkWidget *widget, GdkEventCrossing *e, | |
| 1465 struct gaim_window *win) | |
| 1466 { | |
| 1467 struct gaim_gtk_window *gtkwin; | |
| 1468 | |
| 1469 gtkwin = GAIM_GTK_WINDOW(win); | |
| 1470 | |
| 1471 if (gtkwin->in_drag) | |
| 1472 return FALSE; | |
| 1473 | |
| 1474 if (e->x_root < gtkwin->drag_min_x || | |
| 1475 e->x_root >= gtkwin->drag_max_x || | |
| 1476 e->y_root < gtkwin->drag_min_y || | |
| 1477 e->y_root >= gtkwin->drag_max_y) { | |
| 1478 | |
| 1479 gtkwin->in_predrag = FALSE; | |
| 1480 notebook_init_grab(gtkwin, widget); | |
| 1481 } | |
| 1482 | |
| 1483 return TRUE; | |
| 1484 } | |
| 1485 | |
| 1486 /* | |
| 1487 * THANK YOU GALEON! | |
| 1488 */ | |
| 1489 static gboolean | |
| 1490 notebook_press_cb(GtkWidget *widget, GdkEventButton *e, | |
| 1491 struct gaim_window *win) | |
| 1492 { | |
| 1493 struct gaim_gtk_window *gtkwin; | |
| 1494 gint nb_x, nb_y, x_rel, y_rel; | |
| 1495 GList *l; | |
| 1496 int tab_clicked; | |
| 1497 | |
| 1498 debug_printf("notebook_press_cb\n"); | |
| 1499 if (e->button != 1 || e->type != GDK_BUTTON_PRESS) | |
| 1500 return FALSE; | |
| 1501 | |
| 1502 gtkwin = GAIM_GTK_WINDOW(win); | |
| 1503 | |
| 1504 debug_printf("notebook_press_cb: 1\n"); | |
| 1505 if (gtkwin->in_drag) { | |
| 1506 debug_printf("Already in the middle of a window " | |
| 1507 "drag at tab_press_cb\n"); | |
| 1508 return FALSE; | |
| 1509 } | |
| 1510 | |
| 1511 /* | |
| 1512 * Make sure a tab was actually clicked. The arrow buttons | |
| 1513 * mess things up. | |
| 1514 */ | |
| 1515 tab_clicked = gaim_gtkconv_get_tab_at_xy(win, e->x_root, e->y_root); | |
| 1516 | |
| 1517 printf("tab_clicked == %d\n", tab_clicked); | |
| 1518 | |
| 1519 if (tab_clicked == -1) | |
| 1520 return FALSE; | |
| 1521 | |
| 1522 /* | |
| 1523 * Get the relative position of the press event, with regards to | |
| 1524 * the position of the notebook. | |
| 1525 */ | |
| 1526 gdk_window_get_origin(gtkwin->notebook->window, &nb_x, &nb_y); | |
| 1527 | |
| 1528 x_rel = e->x_root - nb_x; | |
| 1529 y_rel = e->y_root - nb_y; | |
| 1530 | |
| 1531 /* Reset the min/max x/y */ | |
| 1532 gtkwin->drag_min_x = 0; | |
| 1533 gtkwin->drag_min_y = 0; | |
| 1534 gtkwin->drag_max_x = 0; | |
| 1535 gtkwin->drag_max_y = 0; | |
| 1536 | |
| 1537 /* Find out which tab was dragged. */ | |
| 1538 for (l = gaim_window_get_conversations(win); l != NULL; l = l->next) { | |
| 1539 struct gaim_conversation *conv = l->data; | |
| 1540 GtkWidget *tab = GAIM_GTK_CONVERSATION(conv)->tabby; | |
| 1541 | |
| 1542 debug_printf("Tab: %d\n", gaim_conversation_get_index(conv)); | |
| 1543 if (!GTK_WIDGET_VISIBLE(tab)) | |
| 1544 continue; | |
| 1545 | |
| 1546 debug_printf("Tab Visible.\n"); | |
| 1547 if (tab->allocation.x > x_rel || tab->allocation.y > y_rel) | |
| 1548 break; | |
| 1549 | |
| 1550 /* Save the borders of the tab. */ | |
| 1551 gtkwin->drag_min_x = tab->allocation.x + nb_x; | |
| 1552 gtkwin->drag_min_y = tab->allocation.y + nb_y; | |
| 1553 gtkwin->drag_max_x = tab->allocation.width + gtkwin->drag_min_x; | |
| 1554 gtkwin->drag_max_y = tab->allocation.height + gtkwin->drag_min_y; | |
| 1555 } | |
| 1556 | |
| 1557 debug_printf("notebook_press_cb: 3\n"); | |
| 1558 | |
| 1559 /* Make sure the click occurred in the tab. */ | |
| 1560 if (e->x_root < gtkwin->drag_min_x || | |
| 1561 e->x_root >= gtkwin->drag_max_x || | |
| 1562 e->y_root < gtkwin->drag_min_y || | |
| 1563 e->y_root >= gtkwin->drag_max_y) { | |
| 1564 | |
| 1565 debug_printf("Passing this down.\n"); | |
| 1566 return FALSE; | |
| 1567 } | |
| 1568 | |
| 1569 debug_printf("notebook_press_cb: 4\n"); | |
| 1570 gtkwin->in_predrag = TRUE; | |
| 1571 | |
| 1572 /* Connect the new motion signals. */ | |
| 1573 gtkwin->drag_motion_signal = | |
| 1574 g_signal_connect(G_OBJECT(widget), "motion_notify_event", | |
| 1575 G_CALLBACK(notebook_motion_cb), win); | |
| 1576 | |
| 1577 gtkwin->drag_leave_signal = | |
| 1578 g_signal_connect(G_OBJECT(widget), "leave_notify_event", | |
| 1579 G_CALLBACK(notebook_leave_cb), win); | |
| 1580 | |
| 1581 debug_printf("notebook_press_cb: 5\n"); | |
| 1582 return FALSE; | |
| 1583 } | |
| 1584 | |
| 1585 static gboolean | |
| 1586 notebook_release_cb(GtkWidget *widget, GdkEventButton *e, | |
| 1587 struct gaim_window *win) | |
| 1588 { | |
| 1589 struct gaim_window *dest_win; | |
| 1590 struct gaim_gtk_window *gtkwin; | |
| 1591 struct gaim_gtk_window *dest_gtkwin; | |
| 1592 struct gaim_conversation *conv; | |
| 1593 GtkNotebook *dest_notebook; | |
| 1594 gint dest_page_num; | |
| 1595 | |
| 1596 /* | |
| 1597 * Don't check to make sure that the event's window matches the | |
| 1598 * widget's, because we may be getting an event passed on from the | |
| 1599 * close button. | |
| 1600 */ | |
| 1601 if (e->button != 1 && e->type != GDK_BUTTON_RELEASE) | |
| 1602 return FALSE; | |
| 1603 | |
| 1604 if (gdk_pointer_is_grabbed()) { | |
| 1605 gdk_pointer_ungrab(GDK_CURRENT_TIME); | |
| 1606 gtk_grab_remove(widget); | |
| 1607 } | |
| 1608 | |
| 1609 gtkwin = GAIM_GTK_WINDOW(win); | |
| 1610 | |
| 1611 if (!gtkwin->in_predrag && !gtkwin->in_drag) { | |
| 1612 printf("Not in predrag.\n"); | |
| 1613 return TRUE; | |
| 1614 } | |
| 1615 | |
| 1616 /* Disconnect the motion signal. */ | |
| 1617 if (gtkwin->drag_motion_signal) { | |
| 1618 g_signal_handler_disconnect(G_OBJECT(widget), | |
| 1619 gtkwin->drag_motion_signal); | |
| 1620 | |
| 1621 gtkwin->drag_motion_signal = 0; | |
| 1622 } | |
| 1623 | |
| 1624 /* | |
| 1625 * If we're in a pre-drag, we'll also need to disconnect the leave | |
| 1626 * signal. | |
| 1627 */ | |
| 1628 if (gtkwin->in_predrag) { | |
| 1629 gtkwin->in_predrag = FALSE; | |
| 1630 | |
| 1631 if (gtkwin->drag_leave_signal) { | |
| 1632 g_signal_handler_disconnect(G_OBJECT(widget), | |
| 1633 gtkwin->drag_leave_signal); | |
| 1634 | |
| 1635 gtkwin->drag_leave_signal = 0; | |
| 1636 } | |
| 1637 } | |
| 1638 | |
| 1639 /* If we're not in drag... */ | |
| 1640 /* We're perfectly normal people! */ | |
| 1641 if (!gtkwin->in_drag) { | |
| 1642 debug_printf("Not in drag.\n"); | |
| 1643 return FALSE; | |
| 1644 } | |
| 1645 | |
| 1646 gtkwin->in_drag = FALSE; | |
| 1647 | |
| 1648 dnd_hints_hide_all(); | |
| 1649 | |
| 1650 dest_win = gaim_gtkwin_get_at_xy(e->x_root, e->y_root); | |
| 1651 dest_gtkwin = GAIM_GTK_WINDOW(dest_win); | |
| 1652 | |
| 1653 conv = gaim_window_get_active_conversation(win); | |
| 1654 | |
| 1655 if (dest_win == NULL) { | |
| 1656 if (gaim_window_get_conversation_count(win) < 2) | |
| 1657 return FALSE; | |
| 1658 | |
| 1659 if (gaim_window_get_conversation_count(win) > 1) { | |
| 1660 /* Make a new window to stick this to. */ | |
| 1661 struct gaim_window *new_win; | |
| 1662 | |
| 1663 new_win = gaim_window_new(); | |
| 1664 gaim_window_remove_conversation(win, | |
| 1665 gaim_conversation_get_index(conv)); | |
| 1666 gaim_window_add_conversation(new_win, conv); | |
| 1667 gaim_window_show(new_win); | |
| 1668 } | |
| 1669 | |
| 1670 return TRUE; | |
| 1671 } | |
| 1672 | |
| 1673 /* Get the destination notebook. */ | |
| 1674 dest_notebook = GTK_NOTEBOOK(gtkwin->notebook); | |
| 1675 | |
| 1676 /* Get the destination page number. */ | |
| 1677 dest_page_num = gaim_gtkconv_get_dest_tab_at_xy(dest_win, | |
| 1678 e->x_root, e->y_root); | |
| 1679 | |
| 1680 if (win == dest_win) { | |
| 1681 gaim_window_move_conversation(win, | |
| 1682 gaim_conversation_get_index(conv), dest_page_num); | |
| 1683 } | |
| 1684 else { | |
| 1685 size_t pos; | |
| 1686 | |
| 1687 gaim_window_remove_conversation(win, | |
| 1688 gaim_conversation_get_index(conv)); | |
| 1689 | |
| 1690 pos = gaim_window_add_conversation(dest_win, conv); | |
| 1691 | |
| 1692 gaim_window_move_conversation(dest_win, pos, dest_page_num); | |
| 1693 | |
| 1694 gaim_window_switch_conversation(dest_win, dest_page_num); | |
| 1695 } | |
| 1696 | |
| 1697 gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); | |
| 1698 | |
| 1699 debug_printf("release cb returning.\n"); | |
| 1700 return TRUE; | |
| 1701 } | |
| 1702 | |
| 1703 static void | |
| 1704 switch_conv_cb(GtkNotebook *notebook, GtkWidget *page, gint page_num, | |
| 1705 gpointer user_data) | |
| 1706 { | |
| 1707 struct gaim_window *win; | |
| 1708 struct gaim_conversation *conv; | |
| 1709 struct gaim_gtk_conversation *gtkconv; | |
| 1710 struct gaim_gtk_window *gtkwin; | |
| 1711 struct gaim_connection *gc; | |
| 1712 | |
| 1713 if (gaim_gtk_is_state_locked()) | |
| 1714 return; | |
| 1715 | |
| 1716 debug_printf("Switching conversation\n"); | |
| 1717 | |
| 1718 win = (struct gaim_window *)user_data; | |
| 1719 | |
| 1720 conv = gaim_window_get_conversation_at(win, page_num); | |
| 1721 gc = gaim_conversation_get_gc(conv); | |
| 1722 gtkwin = GAIM_GTK_WINDOW(win); | |
| 1723 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 1724 | |
| 1725 gaim_conversation_set_unseen(conv, GAIM_UNSEEN_NONE); | |
| 1726 | |
| 1727 /* Update the menubar */ | |
| 1728 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { | |
| 1729 gtk_widget_set_sensitive(gtkwin->menu.view_history, TRUE); | |
| 1730 gtk_widget_set_sensitive(gtkwin->menu.insert_image, | |
| 1731 (gc && gc->prpl->options & OPT_PROTO_IM_IMAGE)); | |
| 1732 | |
| 1733 if (gtkwin->menu.send_as != NULL) | |
| 1734 update_send_as_selection(win); | |
| 1735 } | |
| 1736 else { | |
| 1737 gtk_widget_set_sensitive(gtkwin->menu.view_history, FALSE); | |
| 1738 gtk_widget_set_sensitive(gtkwin->menu.insert_image, FALSE); | |
| 1739 | |
| 1740 if (gtkwin->menu.send_as != NULL) | |
| 1741 gtk_widget_hide(gtkwin->menu.send_as); | |
| 1742 } | |
| 1743 | |
| 1744 gaim_gtk_set_state_lock(TRUE); | |
| 1745 | |
| 1746 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtkwin->menu.logging), | |
| 1747 gaim_conversation_is_logging(conv)); | |
| 1748 | |
| 1749 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtkwin->menu.sounds), | |
| 1750 gtkconv->make_sound); | |
| 1751 | |
| 1752 gaim_gtk_set_state_lock(FALSE); | |
| 1753 | |
| 1754 gtk_widget_grab_focus(gtkconv->entry); | |
| 1755 } | |
| 1756 | |
| 1757 /************************************************************************** | |
| 1758 * Utility functions | |
| 1759 **************************************************************************/ | |
| 1760 static void | |
| 1761 do_bold(GtkWidget *bold, struct gaim_gtk_conversation *gtkconv) | |
| 1762 { | |
| 1763 if (gaim_gtk_is_state_locked()) | |
| 1764 return; | |
| 1765 | |
| 1766 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(bold))) | |
| 1767 gaim_gtk_surround(gtkconv, "<B>", "</B>"); | |
| 1768 else | |
| 1769 gaim_gtk_advance_past(gtkconv, "<B>", "</B>"); | |
| 1770 | |
| 1771 gtk_widget_grab_focus(gtkconv->entry); | |
| 1772 } | |
| 1773 | |
| 1774 static void | |
| 1775 do_italic(GtkWidget *italic, struct gaim_gtk_conversation *gtkconv) | |
| 1776 { | |
| 1777 if (gaim_gtk_is_state_locked()) | |
| 1778 return; | |
| 1779 | |
| 1780 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(italic))) | |
| 1781 gaim_gtk_surround(gtkconv, "<I>", "</I>"); | |
| 1782 else | |
| 1783 gaim_gtk_advance_past(gtkconv, "<I>", "</I>"); | |
| 1784 | |
| 1785 gtk_widget_grab_focus(gtkconv->entry); | |
| 1786 } | |
| 1787 | |
| 1788 static void | |
| 1789 do_underline(GtkWidget *underline, struct gaim_gtk_conversation *gtkconv) | |
| 1790 { | |
| 1791 if (gaim_gtk_is_state_locked()) | |
| 1792 return; | |
| 1793 | |
| 1794 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(underline))) | |
| 1795 gaim_gtk_surround(gtkconv, "<U>", "</U>"); | |
| 1796 else | |
| 1797 gaim_gtk_advance_past(gtkconv, "<U>", "</U>"); | |
| 1798 | |
| 1799 gtk_widget_grab_focus(gtkconv->entry); | |
| 1800 } | |
| 1801 | |
| 1802 static void | |
| 1803 do_small(GtkWidget *small, struct gaim_gtk_conversation *gtkconv) | |
| 1804 { | |
| 1805 if (gaim_gtk_is_state_locked()) | |
| 1806 return; | |
| 1807 | |
| 1808 gaim_gtk_surround(gtkconv, "<FONT SIZE=\"1\">", "</FONT>"); | |
| 1809 | |
| 1810 gtk_widget_grab_focus(gtkconv->entry); | |
| 1811 } | |
| 1812 | |
| 1813 static void | |
| 1814 do_normal(GtkWidget *small, struct gaim_gtk_conversation *gtkconv) | |
| 1815 { | |
| 1816 if (gaim_gtk_is_state_locked()) | |
| 1817 return; | |
| 1818 | |
| 1819 gaim_gtk_surround(gtkconv, "<FONT SIZE=\"3\">", "</FONT>"); | |
| 1820 | |
| 1821 gtk_widget_grab_focus(gtkconv->entry); | |
| 1822 } | |
| 1823 | |
| 1824 static void | |
| 1825 do_big(GtkWidget *small, struct gaim_gtk_conversation *gtkconv) | |
| 1826 { | |
| 1827 if (gaim_gtk_is_state_locked()) | |
| 1828 return; | |
| 1829 | |
| 1830 gaim_gtk_surround(gtkconv, "<FONT SIZE=\"5\">", "</FONT>"); | |
| 1831 | |
| 1832 gtk_widget_grab_focus(gtkconv->entry); | |
| 1833 } | |
| 1834 | |
| 1835 static void | |
| 1836 toggle_font(GtkWidget *font, struct gaim_conversation *conv) | |
| 1837 { | |
| 1838 struct gaim_gtk_conversation *gtkconv; | |
| 1839 | |
| 1840 if (gaim_gtk_is_state_locked()) | |
| 1841 return; | |
| 1842 | |
| 1843 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 1844 | |
| 1845 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(font))) | |
| 1846 show_font_dialog(conv, font); | |
| 1847 else if (gtkconv->dialogs.fg_color != NULL) | |
| 1848 cancel_font(font, conv); | |
| 1849 else | |
| 1850 gaim_gtk_advance_past(gtkconv, "<FONT FACE>", "</FONT>"); | |
| 1851 } | |
| 1852 | |
| 1853 static void | |
| 1854 toggle_fg_color(GtkWidget *color, struct gaim_conversation *conv) | |
| 1855 { | |
| 1856 struct gaim_gtk_conversation *gtkconv; | |
| 1857 | |
| 1858 if (gaim_gtk_is_state_locked()) | |
| 1859 return; | |
| 1860 | |
| 1861 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 1862 | |
| 1863 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(color))) | |
| 1864 show_fgcolor_dialog(conv, color); | |
| 1865 else if (gtkconv->dialogs.fg_color != NULL) | |
| 1866 cancel_fgcolor(color, conv); | |
| 1867 else | |
| 1868 gaim_gtk_advance_past(gtkconv, "<FONT COLOR>", "</FONT>"); | |
| 1869 } | |
| 1870 | |
| 1871 static void | |
| 1872 toggle_bg_color(GtkWidget *color, struct gaim_conversation *conv) | |
| 1873 { | |
| 1874 struct gaim_gtk_conversation *gtkconv; | |
| 1875 | |
| 1876 if (gaim_gtk_is_state_locked()) | |
| 1877 return; | |
| 1878 | |
| 1879 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 1880 | |
| 1881 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(color))) | |
| 1882 show_bgcolor_dialog(conv, color); | |
| 1883 else if (gtkconv->dialogs.bg_color != NULL) | |
| 1884 cancel_bgcolor(color, conv); | |
| 1885 else | |
| 1886 gaim_gtk_advance_past(gtkconv, "<BODY BGCOLOR>", "</BODY>"); | |
| 1887 } | |
| 1888 | |
| 1889 static void | |
| 1890 check_everything(GtkTextBuffer *buffer) | |
| 1891 { | |
| 1892 struct gaim_conversation *conv; | |
| 1893 struct gaim_gtk_conversation *gtkconv; | |
| 1894 | |
| 1895 conv = (struct gaim_conversation *)g_object_get_data(G_OBJECT(buffer), | |
| 1896 "user_data"); | |
| 1897 | |
| 1898 if (conv == NULL) | |
| 1899 return; | |
| 1900 | |
| 1901 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 1902 | |
| 1903 /* CONV TODO */ | |
| 1904 } | |
| 1905 | |
| 1906 static void | |
| 1907 quiet_set(GtkWidget *tb, gboolean active) | |
| 1908 { | |
| 1909 gaim_gtk_set_state_lock(TRUE); | |
| 1910 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tb), active); | |
| 1911 gaim_gtk_set_state_lock(FALSE); | |
| 1912 } | |
| 1913 | |
| 1914 static void | |
| 1915 got_typing_keypress(struct gaim_conversation *conv, gboolean first) | |
| 1916 { | |
| 1917 struct gaim_im *im; | |
| 1918 | |
| 1919 /* | |
| 1920 * We know we got something, so we at least have to make sure we don't | |
| 1921 * send TYPED any time soon. | |
| 1922 */ | |
| 1923 | |
| 1924 im = GAIM_IM(conv); | |
| 1925 | |
| 1926 if (gaim_im_get_type_again_timeout(im)) | |
| 1927 gaim_im_stop_type_again_timeout(im); | |
| 1928 | |
| 1929 gaim_im_start_type_again_timeout(im); | |
| 1930 | |
| 1931 if (first || (gaim_im_get_type_again(im) != 0 && | |
| 1932 time(NULL) > gaim_im_get_type_again(im))) { | |
| 1933 | |
| 1934 int timeout = serv_send_typing(gaim_conversation_get_gc(conv), | |
| 1935 (char *)gaim_conversation_get_name(conv), | |
| 1936 TYPING); | |
| 1937 | |
| 1938 if (timeout) | |
| 1939 gaim_im_set_type_again(im, time(NULL) + timeout); | |
| 1940 else | |
| 1941 gaim_im_set_type_again(im, 0); | |
| 1942 } | |
| 1943 } | |
| 1944 | |
| 1945 static void | |
| 1946 update_send_as_selection(struct gaim_window *win) | |
| 1947 { | |
| 1948 struct aim_user *user; | |
| 1949 struct gaim_conversation *conv; | |
| 1950 struct gaim_gtk_window *gtkwin; | |
| 1951 const char *username; | |
| 1952 GtkWidget *menu; | |
| 1953 GList *child; | |
| 1954 | |
| 1955 conv = gaim_window_get_active_conversation(win); | |
| 1956 | |
| 1957 if (conv == NULL) | |
| 1958 return; | |
| 1959 | |
| 1960 user = gaim_conversation_get_user(conv); | |
| 1961 gtkwin = GAIM_GTK_WINDOW(win); | |
| 1962 | |
| 1963 username = (user->gc == NULL ? user->username : user->gc->username); | |
| 1964 | |
| 1965 gtk_widget_show(gtkwin->menu.send_as); | |
| 1966 | |
| 1967 menu = gtk_menu_item_get_submenu( | |
| 1968 GTK_MENU_ITEM(gtkwin->menu.send_as)); | |
| 1969 | |
| 1970 gaim_gtk_set_state_lock(TRUE); | |
| 1971 | |
| 1972 for (child = gtk_container_get_children(GTK_CONTAINER(menu)); | |
| 1973 child != NULL; | |
| 1974 child = child->next) { | |
| 1975 | |
| 1976 GtkWidget *item = child->data; | |
| 1977 GtkWidget *label; | |
| 1978 const char *title; | |
| 1979 | |
| 1980 label = gtk_bin_get_child(GTK_BIN(item)); | |
| 1981 | |
| 1982 if (!GTK_IS_LABEL(label)) | |
| 1983 continue; | |
| 1984 | |
| 1985 title = gtk_label_get_text(GTK_LABEL(label)); | |
| 1986 | |
| 1987 if (!strcmp(title, username)) { | |
| 1988 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE); | |
| 1989 break; | |
| 1990 } | |
| 1991 } | |
| 1992 | |
| 1993 gaim_gtk_set_state_lock(FALSE); | |
| 1994 } | |
| 1995 | |
| 1996 static void | |
|
4360
c435a29370b8
[gaim-migrate @ 4626]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
1997 generate_send_as_items(struct gaim_window *win, |
|
c435a29370b8
[gaim-migrate @ 4626]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
1998 struct gaim_conversation *deleted_conv) |
| 4359 | 1999 { |
| 2000 struct gaim_gtk_window *gtkwin; | |
| 2001 GtkWidget *menu; | |
| 2002 GtkWidget *menuitem; | |
| 2003 GSList *gcs; | |
| 2004 GList *convs; | |
| 2005 GSList *group = NULL; | |
| 2006 gboolean first_offline = TRUE; | |
| 2007 gboolean found_online = FALSE; | |
| 2008 | |
| 2009 gtkwin = GAIM_GTK_WINDOW(win); | |
| 2010 | |
| 2011 if (gtkwin->menu.send_as != NULL) | |
| 2012 gtk_widget_destroy(gtkwin->menu.send_as); | |
| 2013 | |
| 2014 /* See if we have > 1 connection active. */ | |
| 2015 if (g_slist_length(connections) < 2) { | |
| 2016 /* Now make sure we don't have any Offline entries. */ | |
| 2017 gboolean found_offline = FALSE; | |
| 2018 | |
| 2019 for (convs = gaim_get_conversations(); | |
| 2020 convs != NULL; | |
| 2021 convs = convs->next) { | |
| 2022 | |
| 2023 struct gaim_conversation *conv; | |
| 2024 struct aim_user *user; | |
| 2025 | |
| 2026 conv = (struct gaim_conversation *)convs->data; | |
| 2027 user = gaim_conversation_get_user(conv); | |
| 2028 | |
| 2029 if (user->gc == NULL) { | |
| 2030 found_offline = TRUE; | |
| 2031 break; | |
| 2032 } | |
| 2033 } | |
| 2034 | |
| 2035 if (!found_offline) { | |
| 2036 gtkwin->menu.send_as = NULL; | |
| 2037 return; | |
| 2038 } | |
| 2039 } | |
| 2040 | |
| 2041 /* Build the Send As menu */ | |
| 2042 gtkwin->menu.send_as = gtk_menu_item_new_with_mnemonic(_("_Send As")); | |
| 2043 gtk_widget_show(gtkwin->menu.send_as); | |
| 2044 | |
| 2045 menu = gtk_menu_new(); | |
| 2046 | |
| 2047 gtk_menu_shell_append(GTK_MENU_SHELL(gtkwin->menu.menubar), | |
| 2048 gtkwin->menu.send_as); | |
| 2049 gtk_menu_item_set_submenu(GTK_MENU_ITEM(gtkwin->menu.send_as), menu); | |
| 2050 | |
| 2051 gtk_widget_show(menu); | |
| 2052 | |
| 2053 /* Fill it with entries. */ | |
| 2054 for (gcs = connections; gcs != NULL; gcs = gcs->next) { | |
| 2055 struct gaim_connection *gc; | |
| 2056 | |
| 2057 found_online = TRUE; | |
| 2058 | |
| 2059 gc = (struct gaim_connection *)gcs->data; | |
| 2060 | |
| 2061 menuitem = gtk_radio_menu_item_new_with_label(group, gc->username); | |
| 2062 group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(menuitem)); | |
| 2063 | |
| 2064 g_object_set_data(G_OBJECT(menuitem), "user_data", win); | |
| 2065 | |
| 2066 g_signal_connect(G_OBJECT(menuitem), "activate", | |
| 2067 G_CALLBACK(menu_conv_sel_send_cb), gc->user); | |
| 2068 | |
| 2069 gtk_widget_show(menuitem); | |
| 2070 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
| 2071 } | |
| 2072 | |
| 2073 /* | |
| 2074 * Fill it with any accounts that still has an open (yet disabled) window | |
| 2075 * (signed off accounts with a window open). | |
| 2076 */ | |
| 2077 for (convs = gaim_get_conversations(); | |
| 2078 convs != NULL; | |
| 2079 convs = convs->next) { | |
| 2080 | |
| 2081 struct gaim_conversation *conv; | |
| 2082 struct aim_user *user; | |
| 2083 | |
| 2084 conv = (struct gaim_conversation *)convs->data; | |
|
4360
c435a29370b8
[gaim-migrate @ 4626]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
2085 |
|
c435a29370b8
[gaim-migrate @ 4626]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
2086 if (conv == deleted_conv) |
|
c435a29370b8
[gaim-migrate @ 4626]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
2087 continue; |
|
c435a29370b8
[gaim-migrate @ 4626]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
2088 |
| 4359 | 2089 user = gaim_conversation_get_user(conv); |
| 2090 | |
| 2091 if (user->gc == NULL) { | |
| 2092 if (first_offline && found_online) { | |
| 2093 menuitem = gtk_separator_menu_item_new(); | |
| 2094 gtk_widget_show(menuitem); | |
| 2095 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
| 2096 | |
| 2097 first_offline = FALSE; | |
| 2098 } | |
| 2099 | |
| 2100 menuitem = gtk_radio_menu_item_new_with_label(group, | |
| 2101 user->username); | |
| 2102 group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(menuitem)); | |
| 2103 | |
| 2104 gtk_widget_set_sensitive(menuitem, FALSE); | |
| 2105 | |
| 2106 gtk_widget_show(menuitem); | |
| 2107 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
| 2108 } | |
| 2109 } | |
| 2110 | |
| 2111 gtk_widget_show(gtkwin->menu.send_as); | |
| 2112 update_send_as_selection(win); | |
| 2113 } | |
| 2114 | |
| 2115 static GList * | |
| 2116 generate_invite_user_names(struct gaim_connection *gc) | |
| 2117 { | |
| 2118 GSList *grp; | |
| 2119 GSList *bl; | |
| 2120 struct group *g; | |
| 2121 struct buddy *buddy; | |
| 2122 static GList *tmp = NULL; | |
| 2123 | |
| 2124 if (tmp) | |
| 2125 g_list_free(tmp); | |
| 2126 | |
| 2127 tmp = g_list_append(NULL, ""); | |
| 2128 | |
| 2129 if (gc != NULL) { | |
| 2130 for (grp = groups; grp != NULL; grp = grp->next) { | |
| 2131 g = (struct group *)grp->data; | |
| 2132 | |
| 2133 for (bl = g->members; bl != NULL; bl = bl->next) { | |
| 2134 buddy = (struct buddy *)bl->data; | |
| 2135 | |
| 2136 if (buddy->present) | |
| 2137 tmp = g_list_append(tmp, buddy->name); | |
| 2138 } | |
| 2139 } | |
| 2140 } | |
| 2141 | |
| 2142 return tmp; | |
| 2143 } | |
| 2144 | |
| 2145 static void | |
| 2146 add_chat_buddy_common(struct gaim_conversation *conv, const char *name, | |
| 2147 int pos) | |
| 2148 { | |
| 2149 struct gaim_gtk_conversation *gtkconv; | |
| 2150 struct gaim_gtk_chat_pane *gtkchat; | |
| 2151 struct gaim_chat *chat; | |
| 2152 GtkTreeIter iter; | |
| 2153 GtkListStore *ls; | |
| 2154 | |
| 2155 chat = GAIM_CHAT(conv); | |
| 2156 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 2157 gtkchat = gtkconv->u.chat; | |
| 2158 | |
| 2159 ls = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list))); | |
| 2160 | |
| 2161 gtk_list_store_append(ls, &iter); | |
| 2162 gtk_list_store_set(ls, &iter, 0, | |
| 2163 (gaim_chat_is_user_ignored(chat, name) ? "X" : " "), | |
| 2164 1, name, -1); | |
| 2165 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(ls), 1, | |
| 2166 GTK_SORT_ASCENDING); | |
| 2167 } | |
| 2168 | |
| 2169 static void | |
| 2170 tab_complete(struct gaim_conversation *conv) | |
| 2171 { | |
| 2172 struct gaim_gtk_conversation *gtkconv; | |
| 2173 struct gaim_chat *chat; | |
| 2174 GtkTextIter cursor, word_start, start_buffer; | |
| 2175 int start; | |
| 2176 int most_matched = -1; | |
| 2177 char *entered, *partial = NULL; | |
| 2178 char *text; | |
| 2179 GList *matches = NULL; | |
| 2180 GList *nicks = NULL; | |
| 2181 | |
| 2182 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 2183 chat = GAIM_CHAT(conv); | |
| 2184 | |
| 2185 gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, &start_buffer); | |
| 2186 gtk_text_buffer_get_iter_at_mark(gtkconv->entry_buffer, &cursor, | |
| 2187 gtk_text_buffer_get_insert(gtkconv->entry_buffer)); | |
| 2188 | |
| 2189 word_start = cursor; | |
| 2190 | |
| 2191 /* if there's nothing there just return */ | |
| 2192 if (!gtk_text_iter_compare(&cursor, &start_buffer)) | |
| 2193 return; | |
| 2194 | |
| 2195 text = gtk_text_buffer_get_text(gtkconv->entry_buffer, &start_buffer, | |
| 2196 &cursor, FALSE); | |
| 2197 | |
| 2198 /* if we're at the end of ": " we need to move back 2 spaces */ | |
| 2199 start = strlen(text) - 1; | |
| 2200 | |
| 2201 if (strlen(text) >= 2 && !strncmp(&text[start-1], ": ", 2)) | |
| 2202 gtk_text_iter_backward_chars(&word_start, 2); | |
| 2203 | |
| 2204 /* find the start of the word that we're tabbing */ | |
| 2205 while (start >= 0 && text[start] != ' ') { | |
| 2206 gtk_text_iter_backward_char(&word_start); | |
| 2207 start--; | |
| 2208 } | |
| 2209 | |
| 2210 g_free(text); | |
| 2211 | |
| 2212 entered = gtk_text_buffer_get_text(gtkconv->entry_buffer, &word_start, | |
| 2213 &cursor, FALSE); | |
| 2214 | |
| 2215 if (chat_options & OPT_CHAT_OLD_STYLE_TAB) { | |
| 2216 if (strlen(entered) >= 2 && | |
| 2217 !strncmp(": ", entered + strlen(entered) - 2, 2)) { | |
| 2218 | |
| 2219 entered[strlen(entered) - 2] = 0; | |
| 2220 } | |
| 2221 } | |
| 2222 | |
| 2223 if (!strlen(entered)) { | |
| 2224 g_free(entered); | |
| 2225 return; | |
| 2226 } | |
| 2227 | |
| 2228 for (nicks = gaim_chat_get_users(chat); | |
| 2229 nicks != NULL; | |
| 2230 nicks = nicks->next) { | |
| 2231 | |
| 2232 char *nick = nicks->data; | |
| 2233 /* this checks to see if the current nick could be a completion */ | |
| 2234 if (g_strncasecmp(nick, entered, strlen(entered))) { | |
| 2235 if (nick[0] != '+' && nick[0] != '@') | |
| 2236 continue; | |
| 2237 | |
| 2238 if (g_strncasecmp(nick + 1, entered, strlen(entered))) { | |
| 2239 if (nick[0] != '@' || nick[1] != '+') | |
| 2240 continue; | |
| 2241 | |
| 2242 if (g_strncasecmp(nick + 2, entered, strlen(entered))) | |
| 2243 continue; | |
| 2244 else | |
| 2245 nick += 2; | |
| 2246 } | |
| 2247 else | |
| 2248 nick++; | |
| 2249 } | |
| 2250 | |
| 2251 /* if we're here, it's a possible completion */ | |
| 2252 | |
| 2253 /* if we're doing old-style, just fill in the completion */ | |
| 2254 if (chat_options & OPT_CHAT_OLD_STYLE_TAB) { | |
| 2255 gtk_text_buffer_delete(gtkconv->entry_buffer, | |
| 2256 &word_start, &cursor); | |
| 2257 | |
| 2258 if (strlen(nick) == strlen(entered)) { | |
| 2259 nicks = (nicks->next | |
| 2260 ? nicks->next | |
| 2261 : gaim_chat_get_users(chat)); | |
| 2262 | |
| 2263 nick = nicks->data; | |
| 2264 | |
| 2265 if (*nick == '@') nick++; | |
| 2266 if (*nick == '+') nick++; | |
| 2267 } | |
| 2268 | |
| 2269 gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, | |
| 2270 &start_buffer); | |
| 2271 gtk_text_buffer_get_iter_at_mark(gtkconv->entry_buffer, &cursor, | |
| 2272 gtk_text_buffer_get_insert(gtkconv->entry_buffer)); | |
| 2273 | |
| 2274 if (!gtk_text_iter_compare(&cursor, &start_buffer)) { | |
| 2275 char *tmp = g_strdup_printf("%s: ", nick); | |
| 2276 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, | |
| 2277 tmp, -1); | |
| 2278 g_free(tmp); | |
| 2279 } | |
| 2280 else | |
| 2281 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, | |
| 2282 nick, -1); | |
| 2283 | |
| 2284 g_free(entered); | |
| 2285 | |
| 2286 return; | |
| 2287 } | |
| 2288 | |
| 2289 /* we're only here if we're doing new style */ | |
| 2290 if (most_matched == -1) { | |
| 2291 /* | |
| 2292 * this will only get called once, since from now | |
| 2293 * on most_matched is >= 0 | |
| 2294 */ | |
| 2295 most_matched = strlen(nick); | |
| 2296 partial = g_strdup(nick); | |
| 2297 } | |
| 2298 else if (most_matched) { | |
| 2299 while (g_strncasecmp(nick, partial, most_matched)) | |
| 2300 most_matched--; | |
| 2301 | |
| 2302 partial[most_matched] = 0; | |
| 2303 } | |
| 2304 | |
| 2305 matches = g_list_append(matches, nick); | |
| 2306 } | |
| 2307 | |
| 2308 /* we're only here if we're doing new style */ | |
| 2309 | |
| 2310 /* if there weren't any matches, return */ | |
| 2311 if (!matches) { | |
| 2312 /* if matches isn't set partials won't be either */ | |
| 2313 g_free(entered); | |
| 2314 return; | |
| 2315 } | |
| 2316 | |
| 2317 gtk_text_buffer_delete(gtkconv->entry_buffer, &word_start, &cursor); | |
| 2318 | |
| 2319 if (!matches->next) { | |
| 2320 /* there was only one match. fill it in. */ | |
| 2321 gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, &start_buffer); | |
| 2322 gtk_text_buffer_get_iter_at_mark(gtkconv->entry_buffer, &cursor, | |
| 2323 gtk_text_buffer_get_insert(gtkconv->entry_buffer)); | |
| 2324 | |
| 2325 if (!gtk_text_iter_compare(&cursor, &start_buffer)) { | |
| 2326 char *tmp = g_strdup_printf("%s: ", (char *)matches->data); | |
| 2327 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, tmp, -1); | |
| 2328 g_free(tmp); | |
| 2329 } | |
| 2330 else | |
| 2331 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, | |
| 2332 matches->data, -1); | |
| 2333 | |
| 2334 matches = g_list_remove(matches, matches->data); | |
| 2335 } | |
| 2336 else { | |
| 2337 /* | |
| 2338 * there were lots of matches, fill in as much as possible | |
| 2339 * and display all of them | |
| 2340 */ | |
| 2341 char *addthis = g_malloc0(1); | |
| 2342 | |
| 2343 while (matches) { | |
| 2344 char *tmp = addthis; | |
| 2345 addthis = g_strconcat(tmp, matches->data, " ", NULL); | |
| 2346 g_free(tmp); | |
| 2347 matches = g_list_remove(matches, matches->data); | |
| 2348 } | |
| 2349 | |
| 2350 gaim_conversation_write(conv, NULL, addthis, -1, WFLAG_NOLOG, | |
| 2351 time(NULL)); | |
| 2352 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, partial, -1); | |
| 2353 g_free(addthis); | |
| 2354 } | |
| 2355 | |
| 2356 g_free(entered); | |
| 2357 g_free(partial); | |
| 2358 } | |
| 2359 | |
| 2360 static gboolean | |
| 2361 meify(char *message, size_t len) | |
| 2362 { | |
| 2363 /* | |
| 2364 * Read /me-ify: If the message (post-HTML) starts with /me, | |
| 2365 * remove the "/me " part of it (including that space) and return TRUE. | |
| 2366 */ | |
| 2367 char *c; | |
| 2368 gboolean inside_html = 0; | |
| 2369 | |
| 2370 if (message == NULL) | |
| 2371 return FALSE; /* Umm.. this would be very bad if this happens. */ | |
| 2372 | |
| 2373 if (len == -1) | |
| 2374 len = strlen(message); | |
| 2375 | |
| 2376 for (c = message; *c != '\0'; c++, len--) { | |
| 2377 if (inside_html) { | |
| 2378 if (*c == '>') | |
| 2379 inside_html = FALSE; | |
| 2380 } | |
| 2381 else { | |
| 2382 if (*c == '<') | |
| 2383 inside_html = TRUE; | |
| 2384 else | |
| 2385 break; | |
| 2386 } | |
| 2387 } | |
| 2388 | |
| 2389 if (*c != '\0' && !g_strncasecmp(c, "/me ", 4)) { | |
| 2390 memmove(c, c + 4, len - 3); | |
| 2391 | |
| 2392 return TRUE; | |
| 2393 } | |
| 2394 | |
| 2395 return FALSE; | |
| 2396 } | |
| 2397 | |
| 2398 static GtkItemFactoryEntry menu_items[] = | |
| 2399 { | |
| 2400 /* Conversation menu */ | |
| 2401 { "/_Conversation", NULL, NULL, 0, "<Branch>" }, | |
| 2402 { "/Conversation/_Save As...", NULL, menu_save_as_cb, 0, | |
| 2403 "<StockItem>", GTK_STOCK_SAVE_AS }, | |
| 2404 { "/Conversation/View _History...", NULL, menu_view_history_cb, 0, NULL }, | |
| 2405 { "/Conversation/sep1", NULL, NULL, 0, "<Separator>" }, | |
| 2406 { "/Conversation/Insert _URL...", NULL, menu_insert_link_cb, 0, | |
| 2407 "<StockItem>", GAIM_STOCK_LINK }, | |
| 2408 { "/Conversation/Insert _Image...", NULL, menu_insert_image_cb, 0, | |
| 2409 "<StockItem>", GAIM_STOCK_IMAGE }, | |
| 2410 { "/Conversation/sep2", NULL, NULL, 0, "<Separator>" }, | |
| 2411 { "/Conversation/_Close", NULL, menu_close_conv_cb, 0, | |
| 2412 "<StockItem>", GTK_STOCK_CLOSE }, | |
| 2413 | |
| 2414 /* Options */ | |
| 2415 { "/_Options", NULL, NULL, 0, "<Branch>" }, | |
| 2416 { "/Options/Enable _Logging", NULL, menu_logging_cb, 0, "<CheckItem>" }, | |
| 2417 { "/Options/Enable _Sounds", NULL, menu_sounds_cb, 0, "<CheckItem>" }, | |
| 2418 }; | |
| 2419 | |
| 2420 static const int menu_item_count = | |
| 2421 sizeof(menu_items) / sizeof(*menu_items); | |
| 2422 | |
| 2423 static GtkWidget * | |
| 2424 setup_menubar(struct gaim_window *win) | |
| 2425 { | |
| 2426 struct gaim_gtk_window *gtkwin; | |
| 2427 GtkWidget *hb; | |
| 2428 GtkItemFactory *item_factory; | |
| 2429 | |
| 2430 gtkwin = GAIM_GTK_WINDOW(win); | |
| 2431 | |
| 2432 /* Create the handle box. */ | |
| 2433 hb = gtk_handle_box_new(); | |
| 2434 | |
| 2435 item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", NULL); | |
| 2436 | |
| 2437 gtk_item_factory_create_items(item_factory, menu_item_count, | |
| 2438 menu_items, win); | |
| 2439 | |
| 2440 gtkwin->menu.menubar = gtk_item_factory_get_widget(item_factory, "<main>"); | |
| 2441 gtkwin->menu.view_history = gtk_item_factory_get_widget(item_factory, | |
| 2442 "/Conversation/View History..."); | |
| 2443 gtkwin->menu.insert_link = gtk_item_factory_get_widget(item_factory, | |
| 2444 "/Conversation/Insert URL..."); | |
| 2445 gtkwin->menu.insert_image = gtk_item_factory_get_widget(item_factory, | |
| 2446 "/Conversation/Insert Image..."); | |
| 2447 gtkwin->menu.logging = gtk_item_factory_get_widget(item_factory, | |
| 2448 "/Options/Enable Logging"); | |
| 2449 gtkwin->menu.sounds = gtk_item_factory_get_widget(item_factory, | |
| 2450 "/Options/Enable Sounds"); | |
| 2451 | |
|
4360
c435a29370b8
[gaim-migrate @ 4626]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
2452 generate_send_as_items(win, NULL); |
| 4359 | 2453 |
| 2454 gtk_container_add(GTK_CONTAINER(hb), gtkwin->menu.menubar); | |
| 2455 | |
| 2456 gtk_widget_show(gtkwin->menu.menubar); | |
| 2457 gtk_widget_show(hb); | |
| 2458 | |
| 2459 return hb; | |
| 2460 } | |
| 2461 | |
| 2462 static void | |
| 2463 setup_im_buttons(struct gaim_conversation *conv, GtkWidget *parent) | |
| 2464 { | |
| 2465 struct gaim_connection *gc; | |
| 2466 struct gaim_gtk_conversation *gtkconv; | |
| 2467 struct gaim_gtk_im_pane *gtkim; | |
| 2468 struct gaim_gtk_window *gtkwin; | |
| 2469 GaimConversationType type = GAIM_CONV_IM; | |
| 2470 | |
| 2471 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 2472 gtkim = gtkconv->u.im; | |
| 2473 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(conv)); | |
| 2474 gc = gaim_conversation_get_gc(conv); | |
| 2475 | |
| 2476 /* From right to left... */ | |
| 2477 | |
| 2478 /* Send button */ | |
| 2479 gtkconv->send = gaim_gtk_change_text(_("Send"), gtkconv->send, | |
| 2480 GAIM_STOCK_SEND, type); | |
| 2481 gtk_tooltips_set_tip(gtkconv->tooltips, gtkconv->send, _("Send"), NULL); | |
| 2482 | |
| 2483 gtk_box_pack_end(GTK_BOX(parent), gtkconv->send, FALSE, FALSE, 0); | |
| 2484 | |
| 2485 /* Separator */ | |
| 2486 if (gtkim->sep2 != NULL) | |
| 2487 gtk_widget_destroy(gtkim->sep2); | |
| 2488 | |
| 2489 gtkim->sep2 = gtk_vseparator_new(); | |
| 2490 gtk_box_pack_end(GTK_BOX(parent), gtkim->sep2, FALSE, TRUE, 0); | |
| 2491 gtk_widget_show(gtkim->sep2); | |
| 2492 | |
| 2493 /* Now, um, just kind of all over the place. Huh? */ | |
| 2494 | |
| 2495 /* Add button */ | |
| 2496 if (find_buddy(gaim_conversation_get_gc(conv)->user, | |
| 2497 gaim_conversation_get_name(conv)) == NULL) { | |
| 2498 gtkim->add = gaim_gtk_change_text(_("Add"), gtkim->add, | |
| 2499 GTK_STOCK_ADD, type); | |
| 2500 gtk_tooltips_set_tip(gtkconv->tooltips, gtkim->add, | |
| 2501 _("Add buddy"), NULL); | |
| 2502 } | |
| 2503 else { | |
| 2504 gtkim->add = gaim_gtk_change_text(_("Remove"), gtkim->add, | |
| 2505 GTK_STOCK_REMOVE, type); | |
| 2506 gtk_tooltips_set_tip(gtkconv->tooltips, gtkim->add, | |
| 2507 _("Remove buddy"), NULL); | |
| 2508 } | |
| 2509 | |
| 2510 gtk_box_pack_start(GTK_BOX(parent), gtkim->add, | |
| 2511 FALSE, FALSE, 0); | |
| 2512 | |
| 2513 /* Warn button */ | |
| 2514 gtkim->warn = gaim_gtk_change_text(_("Warn"), gtkim->warn, | |
| 2515 GAIM_STOCK_WARN, type); | |
| 2516 gtk_box_pack_start(GTK_BOX(parent), gtkim->warn, FALSE, FALSE, 0); | |
| 2517 gtk_tooltips_set_tip(gtkconv->tooltips, gtkim->add, | |
| 2518 _("Remove buddy"), NULL); | |
| 2519 | |
| 2520 /* Info button */ | |
| 2521 gtkconv->info = gaim_gtk_change_text(_("Info"), gtkconv->info, | |
| 2522 GAIM_STOCK_INFO, type); | |
| 2523 gtk_box_pack_start(GTK_BOX(parent), gtkconv->info, FALSE, FALSE, 0); | |
| 2524 gtk_tooltips_set_tip(gtkconv->tooltips, gtkconv->info, | |
| 2525 _("Get user information"), NULL); | |
| 2526 | |
| 2527 /* Block button */ | |
| 2528 gtkim->block = gaim_gtk_change_text(_("Block"), gtkim->block, | |
| 2529 GAIM_STOCK_BLOCK, type); | |
| 2530 gtk_box_pack_start(GTK_BOX(parent), gtkim->block, FALSE, FALSE, 0); | |
| 2531 gtk_tooltips_set_tip(gtkconv->tooltips, gtkim->block, | |
| 2532 _("Block user"), NULL); | |
| 2533 | |
| 2534 gtk_button_set_relief(GTK_BUTTON(gtkconv->info), GTK_RELIEF_NONE); | |
| 2535 gtk_button_set_relief(GTK_BUTTON(gtkim->add), GTK_RELIEF_NONE); | |
| 2536 gtk_button_set_relief(GTK_BUTTON(gtkim->warn), GTK_RELIEF_NONE); | |
| 2537 gtk_button_set_relief(GTK_BUTTON(gtkconv->send), GTK_RELIEF_NONE); | |
| 2538 gtk_button_set_relief(GTK_BUTTON(gtkim->block), GTK_RELIEF_NONE); | |
| 2539 | |
| 2540 gtk_size_group_add_widget(gtkconv->sg, gtkconv->info); | |
| 2541 gtk_size_group_add_widget(gtkconv->sg, gtkim->add); | |
| 2542 gtk_size_group_add_widget(gtkconv->sg, gtkim->warn); | |
| 2543 gtk_size_group_add_widget(gtkconv->sg, gtkconv->send); | |
| 2544 gtk_size_group_add_widget(gtkconv->sg, gtkim->block); | |
| 2545 | |
| 2546 gtk_box_reorder_child(GTK_BOX(parent), gtkim->warn, 1); | |
| 2547 gtk_box_reorder_child(GTK_BOX(parent), gtkim->block, 2); | |
| 2548 gtk_box_reorder_child(GTK_BOX(parent), gtkconv->info, 4); | |
| 2549 | |
| 2550 gaim_gtkconv_update_buttons_by_protocol(conv); | |
| 2551 | |
| 2552 g_signal_connect(G_OBJECT(gtkconv->send), "clicked", | |
| 2553 G_CALLBACK(send_cb), conv); | |
| 2554 g_signal_connect(G_OBJECT(gtkconv->info), "clicked", | |
| 2555 G_CALLBACK(info_cb), conv); | |
| 2556 g_signal_connect(G_OBJECT(gtkim->warn), "clicked", | |
| 2557 G_CALLBACK(warn_cb), conv); | |
| 2558 g_signal_connect(G_OBJECT(gtkim->block), "clicked", | |
| 2559 G_CALLBACK(block_cb), conv); | |
| 2560 } | |
| 2561 | |
| 2562 static void | |
| 2563 setup_chat_buttons(struct gaim_conversation *conv, GtkWidget *parent) | |
| 2564 { | |
| 2565 struct gaim_connection *gc; | |
| 2566 struct gaim_gtk_conversation *gtkconv; | |
| 2567 struct gaim_gtk_chat_pane *gtkchat; | |
| 2568 struct gaim_gtk_window *gtkwin; | |
| 2569 GtkWidget *sep; | |
| 2570 | |
| 2571 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 2572 gtkchat = gtkconv->u.chat; | |
| 2573 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(conv)); | |
| 2574 gc = gaim_conversation_get_gc(conv); | |
| 2575 | |
| 2576 /* Send button */ | |
| 2577 gtkconv->send = gaim_gtk_change_text(_("Send"), gtkconv->send, | |
| 2578 GAIM_STOCK_SEND, GAIM_CONV_CHAT); | |
| 2579 gtk_tooltips_set_tip(gtkconv->tooltips, gtkconv->send, _("Send"), NULL); | |
| 2580 | |
| 2581 gtk_box_pack_end(GTK_BOX(parent), gtkconv->send, FALSE, FALSE, 0); | |
| 2582 | |
| 2583 /* Separator */ | |
| 2584 sep = gtk_vseparator_new(); | |
| 2585 gtk_box_pack_end(GTK_BOX(parent), sep, FALSE, TRUE, 0); | |
| 2586 gtk_widget_show(sep); | |
| 2587 | |
| 2588 /* Invite */ | |
| 2589 gtkchat->invite = gaim_gtk_change_text(_("Invite"), gtkchat->invite, | |
| 2590 GAIM_STOCK_INVITE, GAIM_CONV_CHAT); | |
| 2591 gtk_tooltips_set_tip(gtkconv->tooltips, gtkchat->invite, | |
| 2592 _("Invite a user"), NULL); | |
| 2593 gtk_box_pack_end(GTK_BOX(parent), gtkchat->invite, FALSE, FALSE, 0); | |
| 2594 | |
| 2595 /* Set the relief on these. */ | |
| 2596 gtk_button_set_relief(GTK_BUTTON(gtkchat->invite), GTK_RELIEF_NONE); | |
| 2597 gtk_button_set_relief(GTK_BUTTON(gtkconv->send), GTK_RELIEF_NONE); | |
| 2598 | |
| 2599 /* Callbacks */ | |
| 2600 g_signal_connect(G_OBJECT(gtkconv->send), "clicked", | |
| 2601 G_CALLBACK(send_cb), conv); | |
| 2602 g_signal_connect(G_OBJECT(gtkchat->invite), "clicked", | |
| 2603 G_CALLBACK(invite_cb), conv); | |
| 2604 } | |
| 2605 | |
| 2606 static GtkWidget * | |
| 2607 build_conv_toolbar(struct gaim_conversation *conv) | |
| 2608 { | |
| 2609 struct gaim_gtk_conversation *gtkconv; | |
| 2610 GtkWidget *vbox; | |
| 2611 GtkWidget *hbox; | |
| 2612 GtkWidget *button; | |
| 2613 GtkWidget *sep; | |
| 2614 GtkSizeGroup *sg; | |
| 2615 | |
| 2616 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 2617 | |
| 2618 sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); | |
| 2619 | |
| 2620 vbox = gtk_vbox_new(FALSE, 0); | |
| 2621 sep = gtk_hseparator_new(); | |
| 2622 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
| 2623 | |
| 2624 hbox = gtk_hbox_new(FALSE, 5); | |
| 2625 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
| 2626 | |
| 2627 /* Bold */ | |
| 2628 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_BOLD); | |
| 2629 gtk_size_group_add_widget(sg, button); | |
| 2630 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 2631 gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Bold"), NULL); | |
| 2632 | |
| 2633 g_signal_connect(G_OBJECT(button), "clicked", | |
| 2634 G_CALLBACK(do_bold), gtkconv); | |
| 2635 | |
| 2636 gtkconv->toolbar.bold = button; | |
| 2637 | |
| 2638 /* Italic */ | |
| 2639 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_ITALIC); | |
| 2640 gtk_size_group_add_widget(sg, button); | |
| 2641 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 2642 gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Italic"), NULL); | |
| 2643 | |
| 2644 g_signal_connect(G_OBJECT(button), "clicked", | |
| 2645 G_CALLBACK(do_italic), gtkconv); | |
| 2646 | |
| 2647 gtkconv->toolbar.italic = button; | |
| 2648 | |
| 2649 /* Underline */ | |
| 2650 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_UNDERLINE); | |
| 2651 gtk_size_group_add_widget(sg, button); | |
| 2652 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 2653 gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Underline"), NULL); | |
| 2654 | |
| 2655 g_signal_connect(G_OBJECT(button), "clicked", | |
| 2656 G_CALLBACK(do_underline), gtkconv); | |
| 2657 | |
| 2658 gtkconv->toolbar.underline = button; | |
| 2659 | |
| 2660 /* Sep */ | |
| 2661 sep = gtk_vseparator_new(); | |
| 2662 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
| 2663 | |
| 2664 /* Increase font size */ | |
| 2665 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_BIGGER); | |
| 2666 gtk_size_group_add_widget(sg, button); | |
| 2667 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 2668 gtk_tooltips_set_tip(gtkconv->tooltips, button, | |
| 2669 _("Larger font size"), NULL); | |
| 2670 | |
| 2671 g_signal_connect(G_OBJECT(button), "clicked", | |
| 2672 G_CALLBACK(do_big), gtkconv); | |
| 2673 | |
| 2674 /* Normal font size */ | |
| 2675 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_NORMAL); | |
| 2676 gtk_size_group_add_widget(sg, button); | |
| 2677 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 2678 gtk_tooltips_set_tip(gtkconv->tooltips, button, | |
| 2679 _("Normal font size"), NULL); | |
| 2680 | |
| 2681 g_signal_connect(G_OBJECT(button), "clicked", | |
| 2682 G_CALLBACK(do_normal), gtkconv); | |
| 2683 | |
| 2684 gtkconv->toolbar.normal_size = button; | |
| 2685 | |
| 2686 /* Decrease font size */ | |
| 2687 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_SMALLER); | |
| 2688 gtk_size_group_add_widget(sg, button); | |
| 2689 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 2690 gtk_tooltips_set_tip(gtkconv->tooltips, button, | |
| 2691 _("Smaller font size"), NULL); | |
| 2692 | |
| 2693 g_signal_connect(G_OBJECT(button), "clicked", | |
| 2694 G_CALLBACK(do_small), gtkconv); | |
| 2695 | |
| 2696 /* Sep */ | |
| 2697 sep = gtk_vseparator_new(); | |
| 2698 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
| 2699 | |
| 2700 /* Foreground Color */ | |
| 2701 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_FGCOLOR); | |
| 2702 gtk_size_group_add_widget(sg, button); | |
| 2703 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 2704 gtk_tooltips_set_tip(gtkconv->tooltips, button, | |
| 2705 _("Foreground font color"), NULL); | |
| 2706 | |
| 2707 g_signal_connect(G_OBJECT(button), "clicked", | |
| 2708 G_CALLBACK(toggle_fg_color), conv); | |
| 2709 | |
| 2710 gtkconv->toolbar.fgcolor = button; | |
| 2711 | |
| 2712 /* Background Color */ | |
| 2713 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_BGCOLOR); | |
| 2714 gtk_size_group_add_widget(sg, button); | |
| 2715 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 2716 gtk_tooltips_set_tip(gtkconv->tooltips, button, | |
| 2717 _("Background color"), NULL); | |
| 2718 | |
| 2719 g_signal_connect(G_OBJECT(button), "clicked", | |
| 2720 G_CALLBACK(toggle_bg_color), conv); | |
| 2721 | |
| 2722 gtkconv->toolbar.bgcolor = button; | |
| 2723 | |
| 2724 /* Sep */ | |
| 2725 sep = gtk_vseparator_new(); | |
| 2726 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
| 2727 | |
| 2728 /* Insert IM Image */ | |
| 2729 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_IMAGE); | |
| 2730 gtk_size_group_add_widget(sg, button); | |
| 2731 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 2732 gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Insert image"), NULL); | |
| 2733 | |
| 2734 g_signal_connect(G_OBJECT(button), "clicked", | |
| 2735 G_CALLBACK(insert_image_cb), conv); | |
| 2736 | |
| 2737 gtkconv->toolbar.image = button; | |
| 2738 | |
| 2739 /* Insert Link */ | |
| 2740 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_LINK); | |
| 2741 gtk_size_group_add_widget(sg, button); | |
| 2742 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 2743 gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Insert link"), NULL); | |
| 2744 | |
| 2745 g_signal_connect(G_OBJECT(button), "clicked", | |
| 2746 G_CALLBACK(insert_link_cb), conv); | |
| 2747 | |
| 2748 gtkconv->toolbar.link = button; | |
| 2749 | |
| 2750 /* Insert Smiley */ | |
| 2751 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_SMILEY); | |
| 2752 gtk_size_group_add_widget(sg, button); | |
| 2753 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 2754 gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Insert smiley"), NULL); | |
| 2755 | |
| 2756 g_signal_connect(G_OBJECT(button), "clicked", | |
| 2757 G_CALLBACK(insert_smiley_cb), conv); | |
| 2758 | |
| 2759 gtkconv->toolbar.smiley = button; | |
| 2760 | |
| 2761 | |
| 2762 sep = gtk_hseparator_new(); | |
| 2763 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
| 2764 | |
| 2765 gtk_widget_show_all(vbox); | |
| 2766 | |
| 2767 return vbox; | |
| 2768 } | |
| 2769 | |
| 2770 static GtkWidget * | |
| 2771 setup_chat_pane(struct gaim_conversation *conv) | |
| 2772 { | |
| 2773 struct gaim_gtk_conversation *gtkconv; | |
| 2774 struct gaim_gtk_chat_pane *gtkchat; | |
| 2775 struct gaim_connection *gc; | |
| 2776 GtkWidget *vpaned, *hpaned; | |
| 2777 GtkWidget *vbox, *hbox; | |
| 2778 GtkWidget *lbox, *bbox; | |
| 2779 GtkWidget *label; | |
| 2780 GtkWidget *sw2; | |
| 2781 GtkWidget *list; | |
| 2782 GtkWidget *button; | |
| 2783 GtkWidget *frame; | |
| 2784 GtkListStore *ls; | |
| 2785 GtkCellRenderer *rend; | |
| 2786 GtkTreeViewColumn *col; | |
| 2787 | |
| 2788 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 2789 gtkchat = gtkconv->u.chat; | |
| 2790 gc = gaim_conversation_get_gc(conv); | |
| 2791 | |
| 2792 /* Setup the outer pane. */ | |
| 2793 vpaned = gtk_vpaned_new(); | |
| 2794 gtk_paned_set_gutter_size(GTK_PANED(vpaned), 15); | |
| 2795 gtk_widget_show(vpaned); | |
| 2796 | |
| 2797 /* Setup the top part of the pane. */ | |
| 2798 vbox = gtk_vbox_new(FALSE, 5); | |
| 2799 gtk_paned_pack1(GTK_PANED(vpaned), vbox, TRUE, FALSE); | |
| 2800 gtk_widget_show(vbox); | |
| 2801 | |
| 2802 if (gc->prpl->options & OPT_PROTO_CHAT_TOPIC) | |
| 2803 { | |
| 2804 hbox = gtk_hbox_new(FALSE, 0); | |
| 2805 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 2806 gtk_widget_show(hbox); | |
| 2807 | |
| 2808 label = gtk_label_new(_("Topic:")); | |
| 2809 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); | |
| 2810 gtk_widget_show(label); | |
| 2811 | |
| 2812 gtkchat->topic_text = gtk_entry_new(); | |
| 2813 gtk_entry_set_editable(GTK_ENTRY(gtkchat->topic_text), FALSE); | |
| 2814 gtk_box_pack_start(GTK_BOX(hbox), gtkchat->topic_text, TRUE, TRUE, 5); | |
| 2815 gtk_widget_show(gtkchat->topic_text); | |
| 2816 } | |
| 2817 | |
| 2818 /* Setup the horizontal pane. */ | |
| 2819 hpaned = gtk_hpaned_new(); | |
| 2820 gtk_paned_set_gutter_size(GTK_PANED(hpaned), 15); | |
| 2821 gtk_box_pack_start(GTK_BOX(vbox), hpaned, TRUE, TRUE, 5); | |
| 2822 gtk_widget_show(hpaned); | |
| 2823 | |
| 2824 /* Setup the scrolled window to put gtkimhtml in. */ | |
| 2825 gtkconv->sw = gtk_scrolled_window_new(NULL, NULL); | |
| 2826 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkconv->sw), | |
| 2827 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); | |
| 2828 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(gtkconv->sw), | |
| 2829 GTK_SHADOW_IN); | |
| 2830 gtk_paned_pack1(GTK_PANED(hpaned), gtkconv->sw, TRUE, TRUE); | |
| 2831 | |
| 2832 gtk_widget_set_size_request(gtkconv->sw, | |
| 2833 buddy_chat_size.width, buddy_chat_size.height); | |
| 2834 gtk_widget_show(gtkconv->sw); | |
| 2835 | |
| 2836 /* Setup gtkihmtml. */ | |
| 2837 gtkconv->imhtml = gtk_imhtml_new(NULL, NULL); | |
| 2838 gtk_container_add(GTK_CONTAINER(gtkconv->sw), gtkconv->imhtml); | |
| 2839 | |
| 2840 gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), | |
| 2841 (convo_options & OPT_CONVO_SHOW_TIME)); | |
| 2842 | |
| 2843 g_signal_connect_after(G_OBJECT(gtkconv->imhtml), "button_press_event", | |
| 2844 G_CALLBACK(entry_stop_rclick_cb), NULL); | |
| 2845 | |
| 2846 gaim_setup_imhtml(gtkconv->imhtml); | |
| 2847 | |
| 2848 gtk_widget_show(gtkconv->imhtml); | |
| 2849 | |
| 2850 /* Build the right pane. */ | |
| 2851 lbox = gtk_vbox_new(FALSE, 5); | |
| 2852 gtk_paned_pack2(GTK_PANED(hpaned), lbox, TRUE, TRUE); | |
| 2853 gtk_widget_show(lbox); | |
| 2854 | |
| 2855 /* Setup the label telling how many people are in the room. */ | |
| 2856 gtkchat->count = gtk_label_new(_("0 people in room")); | |
| 2857 gtk_box_pack_start(GTK_BOX(lbox), gtkchat->count, FALSE, FALSE, 0); | |
| 2858 gtk_widget_show(gtkchat->count); | |
| 2859 | |
| 2860 /* Setup the list of users. */ | |
| 2861 sw2 = gtk_scrolled_window_new(NULL, NULL); | |
| 2862 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw2), | |
| 2863 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); | |
| 2864 gtk_box_pack_start(GTK_BOX(lbox), sw2, TRUE, TRUE, 0); | |
| 2865 gtk_widget_show(sw2); | |
| 2866 | |
| 2867 ls = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); | |
| 2868 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(ls), 1, | |
| 2869 GTK_SORT_ASCENDING); | |
| 2870 | |
| 2871 list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ls)); | |
| 2872 | |
| 2873 rend = gtk_cell_renderer_text_new(); | |
| 2874 col = gtk_tree_view_column_new_with_attributes(NULL, rend, | |
| 2875 "text", 0, NULL); | |
| 2876 gtk_tree_view_column_set_clickable(GTK_TREE_VIEW_COLUMN(col), TRUE); | |
| 2877 | |
| 2878 g_signal_connect(G_OBJECT(list), "button_press_event", | |
| 2879 G_CALLBACK(right_click_chat_cb), conv); | |
| 2880 | |
| 2881 gtk_tree_view_append_column(GTK_TREE_VIEW(list), col); | |
| 2882 | |
| 2883 col = gtk_tree_view_column_new_with_attributes(NULL, rend, | |
| 2884 "text", 1, NULL); | |
| 2885 gtk_tree_view_column_set_clickable(GTK_TREE_VIEW_COLUMN(col), TRUE); | |
| 2886 | |
| 2887 #if 0 | |
| 2888 g_signal_connect(G_OBJECT(list), "button_press_event", | |
| 2889 G_CALLBACK(right_click_chat), conv); | |
| 2890 #endif | |
| 2891 | |
| 2892 gtk_tree_view_append_column(GTK_TREE_VIEW(list), col); | |
| 2893 | |
| 2894 gtk_widget_set_size_request(list, 150, -1); | |
| 2895 | |
| 2896 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list), FALSE); | |
| 2897 gtk_widget_show(list); | |
| 2898 | |
| 2899 gtkchat->list = list; | |
| 2900 | |
| 2901 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw2), list); | |
| 2902 | |
| 2903 /* Setup the user list toolbar. */ | |
| 2904 bbox = gtk_hbox_new(TRUE, 5); | |
| 2905 gtk_box_pack_start(GTK_BOX(lbox), bbox, FALSE, FALSE, 0); | |
| 2906 gtk_widget_show(bbox); | |
| 2907 | |
| 2908 /* IM */ | |
| 2909 button = gaim_pixbuf_button_from_stock(NULL, GTK_STOCK_REDO, | |
| 2910 GAIM_BUTTON_VERTICAL); | |
| 2911 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
| 2912 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
| 2913 gtk_tooltips_set_tip(gtkconv->tooltips, button, _("IM"), NULL); | |
| 2914 g_signal_connect(G_OBJECT(button), "clicked", | |
| 2915 G_CALLBACK(im_cb), conv); | |
| 2916 | |
| 2917 gtk_widget_show(button); | |
| 2918 | |
| 2919 /* Ignore */ | |
| 2920 button = gaim_pixbuf_button_from_stock(NULL, GAIM_STOCK_IGNORE, | |
| 2921 GAIM_BUTTON_VERTICAL); | |
| 2922 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
| 2923 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
| 2924 gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Ignore user"), NULL); | |
| 2925 g_signal_connect(G_OBJECT(button), "clicked", | |
| 2926 G_CALLBACK(ignore_cb), conv); | |
| 2927 gtk_widget_show(button); | |
| 2928 | |
| 2929 /* Info */ | |
| 2930 button = gaim_pixbuf_button_from_stock(NULL, GAIM_STOCK_INFO, | |
| 2931 GAIM_BUTTON_VERTICAL); | |
| 2932 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
| 2933 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
| 2934 gtk_tooltips_set_tip(gtkconv->tooltips, button, | |
| 2935 _("Get user information"), NULL); | |
| 2936 g_signal_connect(G_OBJECT(button), "clicked", | |
| 2937 G_CALLBACK(info_cb), conv); | |
| 2938 | |
| 2939 gtk_widget_show(button); | |
| 2940 | |
| 2941 gtkconv->info = button; | |
| 2942 | |
| 2943 /* Build the toolbar. */ | |
| 2944 vbox = gtk_vbox_new(FALSE, 5); | |
| 2945 gtk_paned_pack2(GTK_PANED(vpaned), vbox, TRUE, FALSE); | |
| 2946 gtk_widget_show(vbox); | |
| 2947 | |
| 2948 gtkconv->toolbar.toolbar = build_conv_toolbar(conv); | |
| 2949 gtk_box_pack_start(GTK_BOX(vbox), gtkconv->toolbar.toolbar, | |
| 2950 FALSE, FALSE, 0); | |
| 2951 | |
| 2952 /* Setup the entry widget. */ | |
| 2953 frame = gtk_frame_new(NULL); | |
| 2954 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); | |
| 2955 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); | |
| 2956 gtk_widget_show(frame); | |
| 2957 | |
| 2958 gtkconv->entry_buffer = gtk_text_buffer_new(NULL); | |
| 2959 g_object_set_data(G_OBJECT(gtkconv->entry_buffer), "user_data", conv); | |
| 2960 gtkconv->entry = gtk_text_view_new_with_buffer(gtkconv->entry_buffer); | |
| 2961 | |
| 2962 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(gtkconv->entry), GTK_WRAP_WORD); | |
| 2963 gtk_widget_set_size_request(gtkconv->entry, buddy_chat_size.width, | |
| 2964 MAX(buddy_chat_size.entry_height, 25)); | |
| 2965 | |
| 2966 /* Connect the signal handlers. */ | |
| 2967 g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "key_press_event", | |
| 2968 G_CALLBACK(entry_key_pressed_cb_1), | |
| 2969 gtkconv->entry_buffer); | |
| 2970 g_signal_connect_after(G_OBJECT(gtkconv->entry), "button_press_event", | |
| 2971 G_CALLBACK(entry_stop_rclick_cb), NULL); | |
| 2972 g_signal_connect(G_OBJECT(gtkconv->entry), "key_press_event", | |
| 2973 G_CALLBACK(entry_key_pressed_cb_2), conv); | |
| 2974 | |
| 2975 #ifdef USE_GTKSPELL | |
| 2976 if (convo_options & OPT_CONVO_CHECK_SPELLING) | |
| 2977 gtkspell_new_attach(GTK_TEXT_VIEW(gtkconv->entry), NULL, NULL); | |
| 2978 #endif | |
| 2979 | |
| 2980 gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(gtkconv->entry)); | |
| 2981 gtk_widget_show(gtkconv->entry); | |
| 2982 | |
| 2983 /* Setup the bottom button box. */ | |
| 2984 gtkconv->bbox = gtk_hbox_new(FALSE, 5); | |
| 2985 gtk_box_pack_start(GTK_BOX(vbox), gtkconv->bbox, FALSE, FALSE, 0); | |
| 2986 gtk_widget_show(gtkconv->bbox); | |
| 2987 | |
| 2988 setup_chat_buttons(conv, gtkconv->bbox); | |
| 2989 | |
| 2990 return vpaned; | |
| 2991 } | |
| 2992 | |
| 2993 static GtkWidget * | |
| 2994 setup_im_pane(struct gaim_conversation *conv) | |
| 2995 { | |
| 2996 struct gaim_gtk_conversation *gtkconv; | |
| 2997 struct gaim_gtk_im_pane *gtkim; | |
| 2998 GtkWidget *paned; | |
| 2999 GtkWidget *vbox; | |
| 3000 GtkWidget *vbox2; | |
| 3001 GtkWidget *frame; | |
| 3002 | |
| 3003 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 3004 gtkim = gtkconv->u.im; | |
| 3005 | |
| 3006 /* Setup the outer pane. */ | |
| 3007 paned = gtk_vpaned_new(); | |
| 3008 gtk_paned_set_gutter_size(GTK_PANED(paned), 15); | |
| 3009 gtk_widget_show(paned); | |
| 3010 | |
| 3011 /* Setup the top part of the pane. */ | |
| 3012 vbox = gtk_vbox_new(FALSE, 5); | |
| 3013 gtk_paned_pack1(GTK_PANED(paned), vbox, FALSE, TRUE); | |
| 3014 gtk_widget_show(vbox); | |
| 3015 | |
| 3016 /* Setup the gtkimhtml widget. */ | |
| 3017 gtkconv->sw = gtk_scrolled_window_new(NULL, NULL); | |
| 3018 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkconv->sw), | |
| 3019 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); | |
| 3020 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(gtkconv->sw), | |
| 3021 GTK_SHADOW_IN); | |
| 3022 gtk_box_pack_start(GTK_BOX(vbox), gtkconv->sw, TRUE, TRUE, 0); | |
| 3023 gtk_widget_set_size_request(gtkconv->sw, conv_size.width, conv_size.height); | |
| 3024 gtk_widget_show(gtkconv->sw); | |
| 3025 | |
| 3026 gtkconv->imhtml = gtk_imhtml_new(NULL, NULL); | |
| 3027 gtk_container_add(GTK_CONTAINER(gtkconv->sw), gtkconv->imhtml); | |
| 3028 | |
| 3029 g_signal_connect_after(G_OBJECT(gtkconv->imhtml), "button_press_event", | |
| 3030 G_CALLBACK(entry_stop_rclick_cb), NULL); | |
| 3031 | |
| 3032 gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), | |
| 3033 (convo_options & OPT_CONVO_SHOW_TIME)); | |
| 3034 | |
| 3035 gaim_setup_imhtml(gtkconv->imhtml); | |
| 3036 | |
| 3037 gtk_widget_show(gtkconv->imhtml); | |
| 3038 | |
| 3039 vbox2 = gtk_vbox_new(FALSE, 5); | |
| 3040 gtk_paned_pack2(GTK_PANED(paned), vbox2, FALSE, FALSE); | |
| 3041 gtk_widget_show(vbox2); | |
| 3042 | |
| 3043 /* Build the toolbar. */ | |
| 3044 gtkconv->toolbar.toolbar = build_conv_toolbar(conv); | |
| 3045 gtk_box_pack_start(GTK_BOX(vbox2), gtkconv->toolbar.toolbar, | |
| 3046 FALSE, FALSE, 0); | |
| 3047 | |
| 3048 /* Setup the entry widget. */ | |
| 3049 frame = gtk_frame_new(NULL); | |
| 3050 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); | |
| 3051 gtk_box_pack_start(GTK_BOX(vbox2), frame, TRUE, TRUE, 0); | |
| 3052 gtk_widget_show(frame); | |
| 3053 | |
| 3054 gtkconv->entry_buffer = gtk_text_buffer_new(NULL); | |
| 3055 g_object_set_data(G_OBJECT(gtkconv->entry_buffer), "user_data", conv); | |
| 3056 gtkconv->entry = gtk_text_view_new_with_buffer(gtkconv->entry_buffer); | |
| 3057 | |
| 3058 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(gtkconv->entry), GTK_WRAP_WORD); | |
| 3059 gtk_widget_set_size_request(gtkconv->entry, conv_size.width - 20, | |
| 3060 MAX(conv_size.entry_height, 25)); | |
| 3061 | |
| 3062 /* Connect the signal handlers. */ | |
| 3063 g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "key_press_event", | |
| 3064 G_CALLBACK(entry_key_pressed_cb_1), | |
| 3065 gtkconv->entry_buffer); | |
| 3066 g_signal_connect(G_OBJECT(gtkconv->entry), "key_press_event", | |
| 3067 G_CALLBACK(entry_key_pressed_cb_2), conv); | |
| 3068 g_signal_connect_after(G_OBJECT(gtkconv->entry), "button_press_event", | |
| 3069 G_CALLBACK(entry_stop_rclick_cb), NULL); | |
| 3070 | |
| 3071 g_signal_connect(G_OBJECT(gtkconv->entry_buffer), "insert_text", | |
| 3072 G_CALLBACK(insert_text_cb), conv); | |
| 3073 g_signal_connect(G_OBJECT(gtkconv->entry_buffer), "delete_range", | |
| 3074 G_CALLBACK(delete_text_cb), conv); | |
| 3075 | |
| 3076 #ifdef USE_GTKSPELL | |
| 3077 if (convo_options & OPT_CONVO_CHECK_SPELLING) | |
| 3078 gtkspell_new_attach(GTK_TEXT_VIEW(gtkconv->entry), NULL, NULL); | |
| 3079 #endif | |
| 3080 | |
| 3081 gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(gtkconv->entry)); | |
| 3082 gtk_widget_show(gtkconv->entry); | |
| 3083 | |
| 3084 gtkconv->bbox = gtk_hbox_new(FALSE, 5); | |
| 3085 gtk_box_pack_start(GTK_BOX(vbox2), gtkconv->bbox, FALSE, FALSE, 0); | |
| 3086 gtk_widget_show(gtkconv->bbox); | |
| 3087 | |
| 3088 setup_im_buttons(conv, gtkconv->bbox); | |
| 3089 | |
| 3090 return paned; | |
| 3091 } | |
| 3092 | |
| 3093 static void | |
| 3094 move_next_tab(struct gaim_conversation *conv) | |
| 3095 { | |
| 3096 struct gaim_conversation *next_conv = NULL; | |
| 3097 struct gaim_window *win; | |
| 3098 GList *l; | |
| 3099 int index, i; | |
| 3100 | |
| 3101 win = gaim_conversation_get_window(conv); | |
| 3102 index = gaim_conversation_get_index(conv); | |
| 3103 | |
| 3104 /* First check the tabs after this position. */ | |
| 3105 for (l = g_list_nth(gaim_window_get_conversations(win), index); | |
| 3106 l != NULL; | |
| 3107 l = l->next) { | |
| 3108 | |
| 3109 next_conv = (struct gaim_conversation *)l->data; | |
| 3110 | |
| 3111 if (gaim_conversation_get_unseen(next_conv) > 0) | |
| 3112 break; | |
| 3113 | |
| 3114 next_conv = NULL; | |
| 3115 } | |
| 3116 | |
| 3117 if (next_conv == NULL) { | |
| 3118 | |
| 3119 /* Now check before this position. */ | |
| 3120 for (l = gaim_window_get_conversations(win), i = 0; | |
| 3121 l != NULL && i < index; | |
| 3122 l = l->next) { | |
| 3123 | |
| 3124 next_conv = (struct gaim_conversation *)l->data; | |
| 3125 | |
| 3126 if (gaim_conversation_get_unseen(next_conv) > 0) | |
| 3127 break; | |
| 3128 | |
| 3129 next_conv = NULL; | |
| 3130 } | |
| 3131 | |
| 3132 if (next_conv == NULL) { | |
| 3133 /* Okay, just grab the next conversation tab. */ | |
| 3134 if (index == gaim_window_get_conversation_count(win) - 1) | |
| 3135 next_conv = gaim_window_get_conversation_at(win, 0); | |
| 3136 else | |
| 3137 next_conv = gaim_window_get_conversation_at(win, index + 1); | |
| 3138 } | |
| 3139 } | |
| 3140 | |
| 3141 if (next_conv != NULL && next_conv != conv) { | |
| 3142 gaim_window_switch_conversation(win, | |
| 3143 gaim_conversation_get_index(next_conv)); | |
| 3144 } | |
| 3145 } | |
| 3146 | |
| 3147 | |
| 3148 /************************************************************************** | |
| 3149 * GTK+ window ops | |
| 3150 **************************************************************************/ | |
| 3151 static struct gaim_conversation_ops * | |
| 3152 gaim_gtk_get_conversation_ops(void) | |
| 3153 { | |
| 3154 return gaim_get_gtk_conversation_ops(); | |
| 3155 } | |
| 3156 | |
| 3157 static void | |
| 3158 gaim_gtk_new_window(struct gaim_window *win) | |
| 3159 { | |
| 3160 struct gaim_gtk_window *gtkwin; | |
| 3161 GtkPositionType pos; | |
| 3162 GtkWidget *testidea; | |
| 3163 GtkWidget *menubar; | |
| 3164 | |
| 3165 gtkwin = g_malloc0(sizeof(struct gaim_gtk_window)); | |
| 3166 | |
| 3167 win->ui_data = gtkwin; | |
| 3168 | |
| 3169 /* Create the window. */ | |
| 3170 gtkwin->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 3171 gtk_window_set_role(GTK_WINDOW(gtkwin->window), "conversation"); | |
| 3172 gtk_window_set_policy(GTK_WINDOW(gtkwin->window), TRUE, TRUE, FALSE); | |
| 3173 gtk_container_border_width(GTK_CONTAINER(gtkwin->window), 0); | |
| 3174 gtk_widget_realize(gtkwin->window); | |
| 3175 gtk_window_set_title(GTK_WINDOW(gtkwin->window), _("Gaim - Conversations")); | |
| 3176 | |
| 3177 g_signal_connect(G_OBJECT(gtkwin->window), "delete_event", | |
| 3178 G_CALLBACK(close_win_cb), win); | |
| 3179 | |
| 3180 /* Create the notebook. */ | |
| 3181 gtkwin->notebook = gtk_notebook_new(); | |
| 3182 | |
| 3183 pos = ((im_options & OPT_IM_SIDE_TAB) | |
| 3184 ? ((im_options & OPT_IM_BR_TAB) ? GTK_POS_RIGHT : GTK_POS_LEFT) | |
| 3185 : ((im_options & OPT_IM_BR_TAB) ? GTK_POS_BOTTOM : GTK_POS_TOP)); | |
| 3186 | |
| 3187 #if 0 | |
| 3188 gtk_notebook_set_tab_hborder(GTK_NOTEBOOK(gtkwin->notebook), 0); | |
| 3189 gtk_notebook_set_tab_vborder(GTK_NOTEBOOK(gtkwin->notebook), 0); | |
| 3190 #endif | |
| 3191 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(gtkwin->notebook), pos); | |
| 3192 gtk_notebook_set_scrollable(GTK_NOTEBOOK(gtkwin->notebook), TRUE); | |
| 3193 gtk_notebook_popup_enable(GTK_NOTEBOOK(gtkwin->notebook)); | |
| 3194 gtk_widget_show(gtkwin->notebook); | |
| 3195 | |
| 3196 g_signal_connect_after(G_OBJECT(gtkwin->notebook), "switch_page", | |
| 3197 G_CALLBACK(switch_conv_cb), win); | |
| 3198 | |
| 3199 /* Setup the tab drag and drop signals. */ | |
| 3200 gtk_widget_add_events(gtkwin->notebook, | |
| 3201 GDK_BUTTON1_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK); | |
| 3202 g_signal_connect(G_OBJECT(gtkwin->notebook), "button_press_event", | |
| 3203 G_CALLBACK(notebook_press_cb), win); | |
| 3204 g_signal_connect(G_OBJECT(gtkwin->notebook), "button_release_event", | |
| 3205 G_CALLBACK(notebook_release_cb), win); | |
| 3206 | |
| 3207 testidea = gtk_vbox_new(FALSE, 0); | |
| 3208 | |
| 3209 /* Setup the menubar. */ | |
| 3210 menubar = setup_menubar(win); | |
| 3211 gtk_box_pack_start(GTK_BOX(testidea), menubar, FALSE, TRUE, 0); | |
| 3212 | |
| 3213 gtk_box_pack_start(GTK_BOX(testidea), gtkwin->notebook, TRUE, TRUE, 0); | |
| 3214 | |
| 3215 gtk_container_add(GTK_CONTAINER(gtkwin->window), testidea); | |
| 3216 | |
| 3217 gtk_widget_show(testidea); | |
| 3218 } | |
| 3219 | |
| 3220 static void | |
| 3221 gaim_gtk_destroy_window(struct gaim_window *win) | |
| 3222 { | |
| 3223 struct gaim_gtk_window *gtkwin = GAIM_GTK_WINDOW(win); | |
| 3224 | |
| 3225 gtk_widget_destroy(gtkwin->window); | |
| 3226 | |
| 3227 g_free(gtkwin); | |
| 3228 win->ui_data = NULL; | |
| 3229 } | |
| 3230 | |
| 3231 static void | |
| 3232 gaim_gtk_show(struct gaim_window *win) | |
| 3233 { | |
| 3234 struct gaim_gtk_window *gtkwin = GAIM_GTK_WINDOW(win); | |
| 3235 | |
| 3236 gtk_widget_show(gtkwin->window); | |
| 3237 } | |
| 3238 | |
| 3239 static void | |
| 3240 gaim_gtk_hide(struct gaim_window *win) | |
| 3241 { | |
| 3242 struct gaim_gtk_window *gtkwin = GAIM_GTK_WINDOW(win); | |
| 3243 | |
| 3244 gtk_widget_hide(gtkwin->window); | |
| 3245 } | |
| 3246 | |
| 3247 static void | |
| 3248 gaim_gtk_raise(struct gaim_window *win) | |
| 3249 { | |
| 3250 struct gaim_gtk_window *gtkwin = GAIM_GTK_WINDOW(win); | |
| 3251 | |
| 3252 gdk_window_raise(gtkwin->window->window); | |
| 3253 } | |
| 3254 | |
| 3255 static void | |
| 3256 gaim_gtk_flash(struct gaim_window *win) | |
| 3257 { | |
| 3258 #ifdef _WIN32 | |
| 3259 struct gaim_gtk_window *gtkwin = GAIM_GTK_WINDOW(win); | |
| 3260 | |
| 3261 wgaim_im_blink(gtkwin->window); | |
| 3262 #endif | |
| 3263 } | |
| 3264 | |
| 3265 static void | |
| 3266 gaim_gtk_switch_conversation(struct gaim_window *win, unsigned int index) | |
| 3267 { | |
| 3268 struct gaim_gtk_window *gtkwin; | |
| 3269 | |
| 3270 gtkwin = GAIM_GTK_WINDOW(win); | |
| 3271 | |
| 3272 gtk_notebook_set_current_page(GTK_NOTEBOOK(gtkwin->notebook), index); | |
| 3273 } | |
| 3274 | |
| 3275 static void | |
| 3276 gaim_gtk_add_conversation(struct gaim_window *win, | |
| 3277 struct gaim_conversation *conv) | |
| 3278 { | |
| 3279 struct gaim_gtk_window *gtkwin; | |
| 3280 struct gaim_gtk_conversation *gtkconv; | |
| 3281 GtkWidget *pane = NULL; | |
| 3282 GtkWidget *tab_cont; | |
| 3283 GtkWidget *tabby; | |
| 3284 gboolean new_ui; | |
| 3285 | |
| 3286 gtkwin = GAIM_GTK_WINDOW(win); | |
| 3287 | |
| 3288 if (conv->ui_data != NULL) { | |
| 3289 gtkconv = (struct gaim_gtk_conversation *)conv->ui_data; | |
| 3290 | |
| 3291 tab_cont = gtkconv->tab_cont; | |
| 3292 | |
| 3293 new_ui = FALSE; | |
| 3294 } | |
| 3295 else { | |
| 3296 gtkconv = g_malloc0(sizeof(struct gaim_gtk_conversation)); | |
| 3297 conv->ui_data = gtkconv; | |
| 3298 | |
| 3299 /* Setup some initial variables. */ | |
| 3300 gtkconv->sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
| 3301 gtkconv->tooltips = gtk_tooltips_new(); | |
| 3302 | |
| 3303 if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { | |
| 3304 gtkconv->u.chat = g_malloc0(sizeof(struct gaim_gtk_chat_pane)); | |
| 3305 | |
| 3306 pane = setup_chat_pane(conv); | |
| 3307 } | |
| 3308 else if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { | |
| 3309 gtkconv->u.im = g_malloc0(sizeof(struct gaim_gtk_im_pane)); | |
| 3310 gtkconv->u.im->a_virgin = TRUE; | |
| 3311 | |
| 3312 pane = setup_im_pane(conv); | |
| 3313 } | |
| 3314 | |
| 3315 if (pane == NULL) { | |
| 3316 if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { | |
| 3317 g_free(gtkconv->u.chat); | |
| 3318 } | |
| 3319 else if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { | |
| 3320 g_free(gtkconv->u.im); | |
| 3321 }; | |
| 3322 | |
| 3323 g_free(gtkconv); | |
| 3324 conv->ui_data = NULL; | |
| 3325 | |
| 3326 return; | |
| 3327 } | |
| 3328 | |
| 3329 /* Setup the container for the tab. */ | |
| 3330 gtkconv->tab_cont = tab_cont = gtk_vbox_new(FALSE, 5); | |
| 3331 gtk_container_set_border_width(GTK_CONTAINER(tab_cont), 5); | |
| 3332 gtk_container_add(GTK_CONTAINER(tab_cont), pane); | |
| 3333 gtk_widget_show(pane); | |
| 3334 | |
| 3335 new_ui = TRUE; | |
| 3336 | |
| 3337 gtkconv->make_sound = TRUE; | |
| 3338 } | |
| 3339 | |
| 3340 gtkconv->tabby = tabby = gtk_hbox_new(FALSE, 5); | |
| 3341 | |
| 3342 /* Close button. */ | |
| 3343 gtkconv->close = gtk_button_new(); | |
| 3344 gtk_widget_set_size_request(GTK_WIDGET(gtkconv->close), 16, 16); | |
| 3345 gtk_container_add(GTK_CONTAINER(gtkconv->close), | |
| 3346 gtk_image_new_from_stock(GTK_STOCK_CLOSE, | |
| 3347 GTK_ICON_SIZE_MENU)); | |
| 3348 gtk_button_set_relief(GTK_BUTTON(gtkconv->close), GTK_RELIEF_NONE); | |
| 3349 gtk_tooltips_set_tip(gtkconv->tooltips, gtkconv->close, | |
| 3350 _("Close conversation"), NULL); | |
| 3351 | |
| 3352 g_signal_connect(G_OBJECT(gtkconv->close), "clicked", | |
| 3353 G_CALLBACK(close_conv_cb), conv); | |
| 3354 | |
| 3355 /* Tab label. */ | |
| 3356 gtkconv->tab_label = gtk_label_new(gaim_conversation_get_title(conv)); | |
| 3357 #if 0 | |
| 3358 gtk_misc_set_alignment(GTK_MISC(gtkconv->tab_label), 0.00, 0.5); | |
| 3359 gtk_misc_set_padding(GTK_MISC(gtkconv->tab_label), 4, 0); | |
| 3360 #endif | |
| 3361 | |
| 3362 /* Pack it all together. */ | |
| 3363 gtk_box_pack_start(GTK_BOX(tabby), gtkconv->tab_label, TRUE, TRUE, 0); | |
| 3364 gtk_box_pack_start(GTK_BOX(tabby), gtkconv->close, FALSE, FALSE, 0); | |
| 3365 gtk_widget_show_all(tabby); | |
| 3366 | |
| 3367 | |
| 3368 /* Add this pane to the conversations notebook. */ | |
| 3369 gtk_notebook_append_page(GTK_NOTEBOOK(gtkwin->notebook), tab_cont, tabby); | |
| 3370 gtk_notebook_set_menu_label_text(GTK_NOTEBOOK(gtkwin->notebook), tab_cont, | |
| 3371 gaim_conversation_get_title(conv)); | |
| 3372 | |
| 3373 gtk_widget_show(tab_cont); | |
| 3374 | |
| 3375 /* Er, bug in notebooks? Switch to the page manually. */ | |
| 3376 if (gaim_window_get_conversation_count(win) == 1) | |
| 3377 gtk_notebook_set_current_page(GTK_NOTEBOOK(gtkwin->notebook), 0); | |
| 3378 | |
| 3379 debug_printf("*** Current page = %d\n", | |
| 3380 gtk_notebook_get_current_page(GTK_NOTEBOOK(gtkwin->notebook))); | |
| 3381 | |
| 3382 if ((gtk_notebook_get_current_page(GTK_NOTEBOOK(gtkwin->notebook)) == 0) || | |
| 3383 (conv == g_list_nth_data(gaim_window_get_conversations(win), 0))) { | |
| 3384 | |
| 3385 gtk_widget_grab_focus(gtkconv->entry); | |
| 3386 } | |
| 3387 | |
| 3388 gaim_gtkconv_update_buddy_icon(conv); | |
| 3389 | |
| 3390 if (!new_ui) | |
| 3391 g_object_unref(gtkconv->tab_cont); | |
| 3392 | |
| 3393 if (gaim_window_get_conversation_count(win) == 1) | |
| 3394 update_send_as_selection(win); | |
| 3395 } | |
| 3396 | |
| 3397 static void | |
| 3398 gaim_gtk_remove_conversation(struct gaim_window *win, | |
| 3399 struct gaim_conversation *conv) | |
| 3400 { | |
| 3401 struct gaim_gtk_window *gtkwin; | |
| 3402 struct gaim_gtk_conversation *gtkconv; | |
| 3403 unsigned int index; | |
| 3404 | |
| 3405 index = gaim_conversation_get_index(conv); | |
| 3406 | |
| 3407 gtkwin = GAIM_GTK_WINDOW(win); | |
| 3408 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 3409 | |
| 3410 g_object_ref(gtkconv->tab_cont); | |
| 3411 gtk_object_sink(GTK_OBJECT(gtkconv->tab_cont)); | |
| 3412 | |
| 3413 gaim_gtk_set_state_lock(TRUE); | |
| 3414 | |
| 3415 gtk_notebook_remove_page(GTK_NOTEBOOK(gtkwin->notebook), index); | |
| 3416 | |
| 3417 gaim_gtk_set_state_lock(FALSE); | |
| 3418 | |
| 3419 /* If this window is setup with an inactive gc, regenerate the menu. */ | |
| 3420 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM && | |
| 3421 gaim_conversation_get_gc(conv) == NULL) { | |
| 3422 | |
|
4360
c435a29370b8
[gaim-migrate @ 4626]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
3423 generate_send_as_items(win, conv); |
| 4359 | 3424 } |
| 3425 } | |
| 3426 | |
| 3427 static void | |
| 3428 gaim_gtk_move_conversation(struct gaim_window *win, | |
| 3429 struct gaim_conversation *conv, | |
| 3430 unsigned int new_index) | |
| 3431 { | |
| 3432 struct gaim_gtk_window *gtkwin; | |
| 3433 struct gaim_gtk_conversation *gtkconv; | |
| 3434 | |
| 3435 gtkwin = GAIM_GTK_WINDOW(win); | |
| 3436 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 3437 | |
| 3438 gtk_notebook_reorder_child(GTK_NOTEBOOK(gtkwin->notebook), | |
| 3439 gtkconv->tab_cont, new_index); | |
| 3440 } | |
| 3441 | |
| 3442 static int | |
| 3443 gaim_gtk_get_active_index(const struct gaim_window *win) | |
| 3444 { | |
| 3445 struct gaim_gtk_window *gtkwin; | |
| 3446 | |
| 3447 gtkwin = GAIM_GTK_WINDOW(win); | |
| 3448 | |
| 3449 return gtk_notebook_get_current_page(GTK_NOTEBOOK(gtkwin->notebook)); | |
| 3450 } | |
| 3451 | |
| 3452 static struct gaim_window_ops window_ops = | |
| 3453 { | |
| 3454 gaim_gtk_get_conversation_ops, | |
| 3455 gaim_gtk_new_window, | |
| 3456 gaim_gtk_destroy_window, | |
| 3457 gaim_gtk_show, | |
| 3458 gaim_gtk_hide, | |
| 3459 gaim_gtk_raise, | |
| 3460 gaim_gtk_flash, | |
| 3461 gaim_gtk_switch_conversation, | |
| 3462 gaim_gtk_add_conversation, | |
| 3463 gaim_gtk_remove_conversation, | |
| 3464 gaim_gtk_move_conversation, | |
| 3465 gaim_gtk_get_active_index | |
| 3466 }; | |
| 3467 | |
| 3468 static void | |
| 3469 update_convo_add_button(struct gaim_conversation *conv) | |
| 3470 { | |
| 3471 struct gaim_gtk_conversation *gtkconv; | |
| 3472 struct gaim_connection *gc; | |
| 3473 GaimConversationType type; | |
| 3474 GtkWidget *parent; | |
| 3475 gboolean rebuild = FALSE; | |
| 3476 | |
| 3477 type = gaim_conversation_get_type(conv); | |
| 3478 gc = gaim_conversation_get_gc(conv); | |
| 3479 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 3480 parent = gtk_widget_get_parent(gtkconv->u.im->add); | |
| 3481 | |
| 3482 if (find_buddy(gc->user, gaim_conversation_get_name(conv))) { | |
| 3483 if (!g_object_get_data(G_OBJECT(gtkconv->u.im->add), "user_data")) { | |
| 3484 gtkconv->u.im->add = | |
| 3485 gaim_gtk_change_text(_("Remove"), gtkconv->u.im->add, | |
| 3486 GTK_STOCK_REMOVE, type); | |
| 3487 | |
| 3488 rebuild = TRUE; | |
| 3489 } | |
| 3490 | |
| 3491 gtk_widget_set_sensitive(gtkconv->u.im->add, | |
| 3492 (gc != NULL && gc->prpl->remove_buddy != NULL)); | |
| 3493 | |
| 3494 g_object_set_data(G_OBJECT(gtkconv->u.im->add), "user_data", conv); | |
| 3495 | |
| 3496 } else { | |
| 3497 if (g_object_get_data(G_OBJECT(gtkconv->u.im->add), "user_data")) { | |
| 3498 gtkconv->u.im->add = | |
| 3499 gaim_gtk_change_text(_("Add"), gtkconv->u.im->add, | |
| 3500 GTK_STOCK_ADD, type); | |
| 3501 | |
| 3502 rebuild = TRUE; | |
| 3503 } | |
| 3504 | |
| 3505 gtk_widget_set_sensitive(gtkconv->u.im->add, | |
| 3506 (gc != NULL && gc->prpl->add_buddy != NULL)); | |
| 3507 } | |
| 3508 | |
| 3509 if (rebuild) { | |
| 3510 g_signal_connect(G_OBJECT(gtkconv->u.im->add), "clicked", | |
| 3511 G_CALLBACK(add_cb), conv); | |
| 3512 | |
| 3513 gtk_box_pack_start(GTK_BOX(parent), gtkconv->u.im->add, | |
| 3514 FALSE, FALSE, 0); | |
| 3515 gtk_box_reorder_child(GTK_BOX(parent), gtkconv->u.im->add, 3); | |
| 3516 gtk_button_set_relief(GTK_BUTTON(gtkconv->u.im->add), GTK_RELIEF_NONE); | |
| 3517 gtk_size_group_add_widget(gtkconv->sg, gtkconv->u.im->add); | |
| 3518 } | |
| 3519 } | |
| 3520 | |
| 3521 struct gaim_window_ops * | |
| 3522 gaim_get_gtk_window_ops(void) | |
| 3523 { | |
| 3524 return &window_ops; | |
| 3525 } | |
| 3526 | |
| 3527 /************************************************************************** | |
| 3528 * Conversation ops | |
| 3529 **************************************************************************/ | |
| 3530 static void | |
| 3531 gaim_gtkconv_destroy(struct gaim_conversation *conv) | |
| 3532 { | |
| 3533 struct gaim_gtk_conversation *gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 3534 | |
| 3535 if (gtkconv->dialogs.fg_color != NULL) | |
| 3536 gtk_widget_destroy(gtkconv->dialogs.fg_color); | |
| 3537 | |
| 3538 if (gtkconv->dialogs.bg_color != NULL) | |
| 3539 gtk_widget_destroy(gtkconv->dialogs.bg_color); | |
| 3540 | |
| 3541 if (gtkconv->dialogs.font != NULL) | |
| 3542 gtk_widget_destroy(gtkconv->dialogs.font); | |
| 3543 | |
| 3544 if (gtkconv->dialogs.smiley != NULL) | |
| 3545 gtk_widget_destroy(gtkconv->dialogs.smiley); | |
| 3546 | |
| 3547 if (gtkconv->dialogs.link != NULL) | |
| 3548 gtk_widget_destroy(gtkconv->dialogs.link); | |
| 3549 | |
| 3550 if (gtkconv->dialogs.log != NULL) | |
| 3551 gtk_widget_destroy(gtkconv->dialogs.log); | |
| 3552 | |
| 3553 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { | |
| 3554 if (gtkconv->u.im->save_icon != NULL) | |
| 3555 gtk_widget_destroy(gtkconv->u.im->save_icon); | |
| 3556 | |
| 3557 if (gtkconv->u.im->anim != NULL) | |
| 3558 gdk_pixbuf_animation_unref(gtkconv->u.im->anim); | |
| 3559 | |
| 3560 g_free(gtkconv->u.im); | |
| 3561 } | |
| 3562 else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { | |
| 3563 g_free(gtkconv->u.chat); | |
| 3564 } | |
| 3565 | |
| 3566 g_free(gtkconv); | |
| 3567 } | |
| 3568 | |
| 3569 static void | |
| 3570 gaim_gtkconv_write_im(struct gaim_conversation *conv, const char *who, | |
| 3571 const char *message, size_t len, int flags, time_t mtime) | |
| 3572 { | |
| 3573 struct gaim_gtk_conversation *gtkconv; | |
| 3574 | |
| 3575 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 3576 | |
| 3577 debug_printf("Write IM\n"); | |
| 3578 | |
| 3579 if (gtkconv->make_sound) { | |
| 3580 if (flags & WFLAG_RECV) { | |
| 3581 if (gtkconv->u.im->a_virgin && | |
| 3582 (sound_options & OPT_SOUND_FIRST_RCV)) { | |
| 3583 | |
| 3584 play_sound(SND_FIRST_RECEIVE); | |
| 3585 } | |
| 3586 else | |
| 3587 play_sound(SND_RECEIVE); | |
| 3588 } | |
| 3589 else { | |
| 3590 debug_printf("Playing SND_SEND\n"); | |
| 3591 play_sound(SND_SEND); | |
| 3592 } | |
| 3593 } | |
| 3594 | |
| 3595 gtkconv->u.im->a_virgin = FALSE; | |
| 3596 | |
| 3597 gaim_conversation_write(conv, who, message, len, flags, mtime); | |
| 3598 } | |
| 3599 | |
| 3600 static void | |
| 3601 gaim_gtkconv_write_chat(struct gaim_conversation *conv, const char *who, | |
| 3602 const char *message, int flags, time_t mtime) | |
| 3603 { | |
| 3604 struct gaim_gtk_conversation *gtkconv; | |
| 3605 | |
| 3606 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 3607 | |
| 3608 if (gtkconv->make_sound) { | |
| 3609 if (!(flags & WFLAG_WHISPER) && (flags & WFLAG_SEND)) | |
| 3610 play_sound(SND_CHAT_YOU_SAY); | |
| 3611 else if (flags & WFLAG_RECV) { | |
| 3612 if ((flags & WFLAG_NICK) && (sound_options & OPT_SOUND_CHAT_NICK)) | |
| 3613 play_sound(SND_CHAT_NICK); | |
| 3614 else | |
| 3615 play_sound(SND_CHAT_SAY); | |
| 3616 } | |
| 3617 } | |
| 3618 | |
| 3619 if (chat_options & OPT_CHAT_COLORIZE) | |
| 3620 flags |= WFLAG_COLORIZE; | |
| 3621 | |
| 3622 gaim_conversation_write(conv, who, message, -1, flags, mtime); | |
| 3623 } | |
| 3624 | |
| 3625 static void | |
| 3626 gaim_gtkconv_write_conv(struct gaim_conversation *conv, const char *who, | |
| 3627 const char *message, size_t length, int flags, | |
| 3628 time_t mtime) | |
| 3629 { | |
| 3630 struct gaim_gtk_conversation *gtkconv; | |
| 3631 struct gaim_connection *gc; | |
| 3632 int gtk_font_options = 0; | |
| 3633 GString *log_str; | |
| 3634 FILE *fd; | |
| 3635 char buf[BUF_LONG]; | |
| 3636 char buf2[BUF_LONG]; | |
| 3637 char mdate[64]; | |
| 3638 char color[10]; | |
| 3639 char *str; | |
| 3640 char *with_font_tag; | |
| 3641 | |
| 3642 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 3643 gc = gaim_conversation_get_gc(conv); | |
| 3644 | |
| 3645 strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime)); | |
| 3646 | |
| 3647 gtk_font_options ^= GTK_IMHTML_NO_COMMENTS; | |
| 3648 | |
| 3649 if (convo_options & OPT_CONVO_IGNORE_COLOUR) | |
| 3650 gtk_font_options ^= GTK_IMHTML_NO_COLOURS; | |
| 3651 | |
| 3652 if (convo_options & OPT_CONVO_IGNORE_FONTS) | |
| 3653 gtk_font_options ^= GTK_IMHTML_NO_FONTS; | |
| 3654 | |
| 3655 if (convo_options & OPT_CONVO_IGNORE_SIZES) | |
| 3656 gtk_font_options ^= GTK_IMHTML_NO_SIZES; | |
| 3657 | |
| 3658 if (!(logging_options & OPT_LOG_STRIP_HTML)) | |
| 3659 gtk_font_options ^= GTK_IMHTML_RETURN_LOG; | |
| 3660 | |
| 3661 if (flags & WFLAG_SYSTEM) { | |
| 3662 if (convo_options & OPT_CONVO_SHOW_TIME) | |
| 3663 g_snprintf(buf, BUF_LONG, "<FONT SIZE=\"2\">(%s) </FONT><B>%s</B>", | |
| 3664 mdate, message); | |
| 3665 else | |
| 3666 g_snprintf(buf, BUF_LONG, "<B>%s</B>", message); | |
| 3667 | |
| 3668 g_snprintf(buf2, sizeof(buf2), | |
| 3669 "<FONT SIZE=\"2\"><!--(%s) --></FONT><B>%s</B><BR>", | |
| 3670 mdate, message); | |
| 3671 | |
| 3672 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, -1, 0); | |
| 3673 | |
| 3674 if (logging_options & OPT_LOG_STRIP_HTML) { | |
| 3675 char *t1 = strip_html(buf); | |
| 3676 | |
| 3677 conv->history = g_string_append(conv->history, t1); | |
| 3678 conv->history = g_string_append(conv->history, "\n"); | |
| 3679 | |
| 3680 g_free(t1); | |
| 3681 } | |
| 3682 else { | |
| 3683 conv->history = g_string_append(conv->history, buf); | |
| 3684 conv->history = g_string_append(conv->history, "<BR>\n"); | |
| 3685 } | |
| 3686 | |
| 3687 if (!(flags & WFLAG_NOLOG) && gaim_conversation_is_logging(conv)) { | |
| 3688 /* | |
| 3689 XXX | |
| 3690 ((gaim_conversation_get_type(conv) == GAIM_CONV_CHAT && | |
| 3691 (logging_options & OPT_LOG_CHATS)) || | |
| 3692 (gaim_conversation_get_type(conv) == GAIM_CONV_IM && | |
| 3693 (logging_options & OPT_LOG_CONVOS)) || | |
| 3694 find_log_info(gaim_conversation_get_name(conv)))) { | |
| 3695 */ | |
| 3696 | |
| 3697 char *t1; | |
| 3698 char nm[256]; | |
| 3699 | |
| 3700 if (logging_options & OPT_LOG_STRIP_HTML) | |
| 3701 t1 = strip_html(buf); | |
| 3702 else | |
| 3703 t1 = buf; | |
| 3704 | |
| 3705 if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) | |
| 3706 g_snprintf(nm, sizeof(nm), "%s.chat", | |
| 3707 gaim_conversation_get_name(conv)); | |
| 3708 else | |
| 3709 strncpy(nm, gaim_conversation_get_name(conv), sizeof(nm)); | |
| 3710 | |
| 3711 fd = open_log_file(nm, | |
| 3712 (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT)); | |
| 3713 | |
| 3714 if (fd) { | |
| 3715 if (logging_options & OPT_LOG_STRIP_HTML) | |
| 3716 fprintf(fd, "%s\n", t1); | |
| 3717 else | |
| 3718 fprintf(fd, "%s<BR>\n", t1); | |
| 3719 | |
| 3720 fclose(fd); | |
| 3721 } | |
| 3722 | |
| 3723 if (logging_options & OPT_LOG_STRIP_HTML) | |
| 3724 g_free(t1); | |
| 3725 } | |
| 3726 } | |
| 3727 else if (flags & WFLAG_NOLOG) { | |
| 3728 g_snprintf(buf, BUF_LONG, | |
| 3729 "<B><FONT COLOR=\"#777777\">%s</FONT></B><BR>", | |
| 3730 message); | |
| 3731 | |
| 3732 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf, -1, 0); | |
| 3733 } | |
| 3734 else { | |
| 3735 char *new_message = g_strdup(message); | |
| 3736 | |
| 3737 if (flags & WFLAG_WHISPER) { | |
| 3738 str = g_malloc(1024); | |
| 3739 | |
| 3740 /* If we're whispering, it's not an autoresponse. */ | |
| 3741 if (meify(new_message, length)) { | |
| 3742 g_snprintf(str, 1024, "***%s", who); | |
| 3743 strcpy(color, "#6C2585"); | |
| 3744 } | |
| 3745 else { | |
| 3746 g_snprintf(str, 1024, "*%s*:", who); | |
| 3747 strcpy(color, "#00FF00"); | |
| 3748 } | |
| 3749 } | |
| 3750 else { | |
| 3751 if (meify(new_message, length)) { | |
| 3752 str = g_malloc(1024); | |
| 3753 | |
| 3754 if (flags & WFLAG_AUTO) | |
| 3755 g_snprintf(str, 1024, "%s ***%s", AUTO_RESPONSE, who); | |
| 3756 else | |
| 3757 g_snprintf(str, 1024, "***%s", who); | |
| 3758 | |
| 3759 if (flags & WFLAG_NICK) | |
| 3760 strcpy(color, "#AF7F00"); | |
| 3761 else | |
| 3762 strcpy(color, "#062585"); | |
| 3763 } | |
| 3764 else { | |
| 3765 str = g_malloc(1024); | |
| 3766 | |
| 3767 if (flags & WFLAG_AUTO) | |
| 3768 g_snprintf(str, 1024, "%s %s", who, AUTO_RESPONSE); | |
| 3769 else | |
| 3770 g_snprintf(str, 1024, "%s:", who); | |
| 3771 | |
| 3772 if (flags & WFLAG_NICK) | |
| 3773 strcpy(color, "#AF7F00"); | |
| 3774 else if (flags & WFLAG_RECV) { | |
| 3775 if (flags & WFLAG_COLORIZE) { | |
| 3776 const char *u; | |
| 3777 int m = 0; | |
| 3778 | |
| 3779 for (u = who; *u != '\0'; u++) | |
| 3780 m += *u; | |
| 3781 | |
| 3782 m = m % NUM_NICK_COLORS; | |
| 3783 | |
| 3784 strcpy(color, nick_colors[m]); | |
| 3785 } | |
| 3786 else | |
| 3787 strcpy(color, "#A82F2F"); | |
| 3788 } | |
| 3789 else if (flags & WFLAG_SEND) | |
| 3790 strcpy(color, "#16569E"); | |
| 3791 } | |
| 3792 } | |
| 3793 | |
| 3794 if (convo_options & OPT_CONVO_SHOW_TIME) | |
| 3795 g_snprintf(buf, BUF_LONG, | |
| 3796 "<FONT COLOR=\"%s\"><FONT SIZE=\"2\">(%s) </FONT>" | |
| 3797 "<B>%s</B></FONT> ", color, mdate, str); | |
| 3798 else | |
| 3799 g_snprintf(buf, BUF_LONG, | |
| 3800 "<FONT COLOR=\"%s\"><B>%s</B></FONT> ", color, str); | |
| 3801 | |
| 3802 g_snprintf(buf2, BUF_LONG, | |
| 3803 "<FONT COLOR=\"%s\"><FONT SIZE=\"2\"><!--(%s) --></FONT>" | |
| 3804 "<B>%s</B></FONT> ", | |
| 3805 color, mdate, str); | |
| 3806 | |
| 3807 g_free(str); | |
| 3808 | |
| 3809 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, -1, 0); | |
| 3810 | |
| 3811 with_font_tag = g_strdup_printf("<font sml=\"%s\">%s</font>", | |
| 3812 gc->prpl->name, new_message); | |
| 3813 | |
| 3814 log_str = gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), | |
| 3815 with_font_tag, length, | |
| 3816 gtk_font_options); | |
| 3817 | |
| 3818 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR>", -1, 0); | |
| 3819 | |
| 3820 /* XXX This needs to be updated for the new length argument. */ | |
| 3821 if (logging_options & OPT_LOG_STRIP_HTML) { | |
| 3822 char *t1, *t2; | |
| 3823 | |
| 3824 t1 = strip_html(buf); | |
| 3825 t2 = strip_html(new_message); | |
| 3826 | |
| 3827 conv->history = g_string_append(conv->history, t1); | |
| 3828 conv->history = g_string_append(conv->history, t2); | |
| 3829 conv->history = g_string_append(conv->history, "\n"); | |
| 3830 | |
| 3831 g_free(t1); | |
| 3832 g_free(t2); | |
| 3833 } | |
| 3834 else { | |
| 3835 char *t1, *t2; | |
| 3836 | |
| 3837 t1 = html_logize(buf); | |
| 3838 t2 = html_logize(new_message); | |
| 3839 | |
| 3840 conv->history = g_string_append(conv->history, t1); | |
| 3841 conv->history = g_string_append(conv->history, t2); | |
| 3842 conv->history = g_string_append(conv->history, "\n"); | |
| 3843 conv->history = g_string_append(conv->history, log_str->str); | |
| 3844 conv->history = g_string_append(conv->history, "<BR>\n"); | |
| 3845 | |
| 3846 g_free(t1); | |
| 3847 g_free(t2); | |
| 3848 } | |
| 3849 | |
| 3850 /* XXX This needs to be updated for the new length argument. */ | |
| 3851 if (gaim_conversation_is_logging(conv)) { | |
| 3852 /* | |
| 3853 XXX | |
| 3854 if ((gaim_conversation_get_type(conv) == GAIM_CONV_CHAT && | |
| 3855 (logging_options & OPT_LOG_CHATS)) || | |
| 3856 (gaim_conversation_get_type(conv) == GAIM_CONV_IM && | |
| 3857 (logging_options & OPT_LOG_CONVOS)) || | |
| 3858 find_log_info(gaim_conversation_get_name(conv))) { | |
| 3859 */ | |
| 3860 | |
| 3861 char *t1, *t2; | |
| 3862 char nm[256]; | |
| 3863 | |
| 3864 if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) | |
| 3865 g_snprintf(nm, sizeof(nm), "%s.chat", | |
| 3866 gaim_conversation_get_name(conv)); | |
| 3867 else | |
| 3868 strncpy(nm, gaim_conversation_get_name(conv), sizeof(nm)); | |
| 3869 | |
| 3870 if (logging_options & OPT_LOG_STRIP_HTML) { | |
| 3871 t1 = strip_html(buf); | |
| 3872 t2 = strip_html(with_font_tag); | |
| 3873 } | |
| 3874 else { | |
| 3875 t1 = html_logize(buf); | |
| 3876 t2 = html_logize(with_font_tag); | |
| 3877 } | |
| 3878 | |
| 3879 fd = open_log_file(nm, | |
| 3880 (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT)); | |
| 3881 | |
| 3882 if (fd) { | |
| 3883 if (logging_options & OPT_LOG_STRIP_HTML) | |
| 3884 fprintf(fd, "%s%s\n", t1, t2); | |
| 3885 else { | |
| 3886 fprintf(fd, "%s%s%s<BR>\n", t1, t2, log_str->str); | |
| 3887 g_string_free(log_str, TRUE); | |
| 3888 } | |
| 3889 | |
| 3890 fclose(fd); | |
| 3891 } | |
| 3892 | |
| 3893 g_free(t1); | |
| 3894 g_free(t2); | |
| 3895 } | |
| 3896 | |
| 3897 g_free(with_font_tag); | |
| 3898 g_free(new_message); | |
| 3899 } | |
| 3900 } | |
| 3901 | |
| 3902 static void | |
| 3903 gaim_gtkconv_chat_add_user(struct gaim_conversation *conv, const char *user) | |
| 3904 { | |
| 3905 struct gaim_chat *chat; | |
| 3906 struct gaim_gtk_conversation *gtkconv; | |
| 3907 struct gaim_gtk_chat_pane *gtkchat; | |
| 3908 char tmp[BUF_LONG]; | |
| 3909 int num_users; | |
| 3910 int pos; | |
| 3911 | |
| 3912 chat = GAIM_CHAT(conv); | |
| 3913 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 3914 gtkchat = gtkconv->u.chat; | |
| 3915 | |
| 3916 num_users = g_list_length(gaim_chat_get_users(chat)); | |
| 3917 | |
| 3918 g_snprintf(tmp, sizeof(tmp), | |
| 3919 ngettext("%d person in room", "%d people in room", | |
| 3920 num_users), | |
| 3921 num_users); | |
| 3922 | |
| 3923 gtk_label_set_text(GTK_LABEL(gtkchat->count), tmp); | |
| 3924 | |
| 3925 if (gtkconv->make_sound) | |
| 3926 play_sound(SND_CHAT_JOIN); | |
| 3927 | |
| 3928 pos = g_list_index(gaim_chat_get_users(chat), user); | |
| 3929 | |
| 3930 add_chat_buddy_common(conv, user, pos); | |
| 3931 } | |
| 3932 | |
| 3933 static void | |
| 3934 gaim_gtkconv_chat_rename_user(struct gaim_conversation *conv, | |
| 3935 const char *old_name, const char *new_name) | |
| 3936 { | |
| 3937 struct gaim_chat *chat; | |
| 3938 struct gaim_gtk_conversation *gtkconv; | |
| 3939 struct gaim_gtk_chat_pane *gtkchat; | |
| 3940 GtkTreeIter iter; | |
| 3941 GtkTreeModel *model; | |
| 3942 GList *names; | |
| 3943 int pos; | |
| 3944 int f = 1; | |
| 3945 | |
| 3946 chat = GAIM_CHAT(conv); | |
| 3947 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 3948 gtkchat = gtkconv->u.chat; | |
| 3949 | |
| 3950 for (names = gaim_chat_get_users(chat); | |
| 3951 names != NULL; | |
| 3952 names = names->next) { | |
| 3953 | |
| 3954 char *u = (char *)names->data; | |
| 3955 | |
| 3956 if (!g_strcasecmp(u, old_name)) { | |
| 3957 model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); | |
| 3958 | |
| 3959 if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) | |
| 3960 break; | |
| 3961 | |
| 3962 while (f != 0) { | |
| 3963 char *val; | |
| 3964 | |
| 3965 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &val, -1); | |
| 3966 | |
| 3967 if (!g_strcasecmp(old_name, val)) | |
| 3968 gtk_list_store_remove(GTK_LIST_STORE(model), &iter); | |
| 3969 | |
| 3970 f = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter); | |
| 3971 | |
| 3972 g_free(val); | |
| 3973 } | |
| 3974 | |
| 3975 break; | |
| 3976 } | |
| 3977 } | |
| 3978 | |
| 3979 if (!names) | |
| 3980 return; | |
| 3981 | |
| 3982 pos = g_list_index(gaim_chat_get_users(chat), new_name); | |
| 3983 | |
| 3984 add_chat_buddy_common(conv, new_name, pos); | |
| 3985 } | |
| 3986 | |
| 3987 static void | |
| 3988 gaim_gtkconv_chat_remove_user(struct gaim_conversation *conv, const char *user) | |
| 3989 { | |
| 3990 struct gaim_chat *chat; | |
| 3991 struct gaim_gtk_conversation *gtkconv; | |
| 3992 struct gaim_gtk_chat_pane *gtkchat; | |
| 3993 GtkTreeIter iter; | |
| 3994 GtkTreeModel *model; | |
| 3995 GList *names; | |
| 3996 char tmp[BUF_LONG]; | |
| 3997 int num_users; | |
| 3998 int f = 1; | |
| 3999 | |
| 4000 chat = GAIM_CHAT(conv); | |
| 4001 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 4002 gtkchat = gtkconv->u.chat; | |
| 4003 | |
| 4004 num_users = g_list_length(gaim_chat_get_users(chat)) - 1; | |
| 4005 | |
| 4006 for (names = gaim_chat_get_users(chat); | |
| 4007 names != NULL; | |
| 4008 names = names->next) { | |
| 4009 | |
| 4010 char *u = (char *)names->data; | |
| 4011 | |
| 4012 if (!g_strcasecmp(u, user)) { | |
| 4013 model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); | |
| 4014 | |
| 4015 if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) | |
| 4016 break; | |
| 4017 | |
| 4018 while (f != 0) { | |
| 4019 char *val; | |
| 4020 | |
| 4021 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &val, -1); | |
| 4022 | |
| 4023 if (!g_strcasecmp(user, val)) | |
| 4024 gtk_list_store_remove(GTK_LIST_STORE(model), &iter); | |
| 4025 | |
| 4026 f = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter); | |
| 4027 | |
| 4028 g_free(val); | |
| 4029 } | |
| 4030 | |
| 4031 break; | |
| 4032 } | |
| 4033 } | |
| 4034 | |
| 4035 if (names == NULL) | |
| 4036 return; | |
| 4037 | |
| 4038 g_snprintf(tmp, sizeof(tmp), | |
| 4039 ngettext("%d person in room", "%d people in room", | |
| 4040 num_users), num_users); | |
| 4041 | |
| 4042 gtk_label_set_text(GTK_LABEL(gtkchat->count), tmp); | |
| 4043 | |
| 4044 if (gtkconv->make_sound) | |
| 4045 play_sound(SND_CHAT_LEAVE); | |
| 4046 } | |
| 4047 | |
| 4048 static void | |
| 4049 gaim_gtkconv_set_title(struct gaim_conversation *conv, const char *title) | |
| 4050 { | |
| 4051 struct gaim_gtk_conversation *gtkconv; | |
| 4052 | |
| 4053 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 4054 | |
| 4055 gtk_label_set_text(GTK_LABEL(gtkconv->tab_label), title); | |
| 4056 } | |
| 4057 | |
| 4058 static void | |
| 4059 gaim_gtkconv_updated(struct gaim_conversation *conv, GaimConvUpdateType type) | |
| 4060 { | |
| 4061 struct gaim_window *win; | |
| 4062 struct gaim_gtk_conversation *gtkconv; | |
| 4063 struct gaim_gtk_chat_pane *gtkchat; | |
| 4064 struct gaim_chat *chat; | |
| 4065 | |
| 4066 win = gaim_conversation_get_window(conv); | |
| 4067 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 4068 | |
| 4069 if (type == GAIM_CONV_UPDATE_USER) { | |
| 4070 gaim_conversation_autoset_title(conv); | |
| 4071 gaim_gtkconv_update_buddy_icon(conv); | |
| 4072 gaim_gtkconv_update_buttons_by_protocol(conv); | |
| 4073 | |
| 4074 update_send_as_selection(win); | |
| 4075 | |
| 4076 smiley_themeize(gtkconv->imhtml); | |
| 4077 } | |
| 4078 else if (type == GAIM_CONV_UPDATE_TYPING || | |
| 4079 type == GAIM_CONV_UPDATE_UNSEEN) { | |
| 4080 | |
| 4081 GtkStyle *style; | |
| 4082 struct gaim_im *im = NULL; | |
| 4083 | |
| 4084 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) | |
| 4085 im = GAIM_IM(conv); | |
| 4086 | |
| 4087 style = gtk_style_new(); | |
| 4088 | |
| 4089 if (!GTK_WIDGET_REALIZED(gtkconv->tab_label)) | |
| 4090 gtk_widget_realize(gtkconv->tab_label); | |
| 4091 | |
| 4092 gtk_style_set_font(style, | |
| 4093 gdk_font_ref(gtk_style_get_font(gtk_widget_get_style( | |
| 4094 gtkconv->tab_label)))); | |
| 4095 | |
| 4096 if (im != NULL && gaim_im_get_typing_state(im) == TYPING) { | |
| 4097 style->fg[0].red = 0x0000; | |
| 4098 style->fg[0].green = 0x9999; | |
| 4099 style->fg[0].blue = 0x0000; | |
| 4100 } | |
| 4101 else if (im != NULL && gaim_im_get_typing_state(im) == TYPED) { | |
| 4102 style->fg[0].red = 0xFFFF; | |
| 4103 style->fg[0].green = 0xBBBB; | |
| 4104 style->fg[0].blue = 0x2222; | |
| 4105 } | |
| 4106 else if (gaim_conversation_get_unseen(conv) == GAIM_UNSEEN_NICK) { | |
| 4107 style->fg[0].red = 0x0000; | |
| 4108 style->fg[0].green = 0x0000; | |
| 4109 style->fg[0].blue = 0xCCCC; | |
| 4110 } | |
| 4111 else if (gaim_conversation_get_unseen(conv) == GAIM_UNSEEN_TEXT) { | |
| 4112 style->fg[0].red = 0xCCCC; | |
| 4113 style->fg[0].green = 0x0000; | |
| 4114 style->fg[0].blue = 0x0000; | |
| 4115 } | |
| 4116 | |
| 4117 gtk_widget_set_style(gtkconv->tab_label, style); | |
| 4118 gtk_style_unref(style); | |
| 4119 } | |
| 4120 else if (type == GAIM_CONV_UPDATE_TOPIC) { | |
| 4121 chat = GAIM_CHAT(conv); | |
| 4122 gtkchat = gtkconv->u.chat; | |
| 4123 | |
| 4124 gtk_entry_set_text(GTK_ENTRY(gtkchat->topic_text), | |
| 4125 gaim_chat_get_topic(chat)); | |
| 4126 } | |
| 4127 else if (type == GAIM_CONV_ACCOUNT_ONLINE || | |
| 4128 type == GAIM_CONV_ACCOUNT_OFFLINE) { | |
| 4129 | |
|
4360
c435a29370b8
[gaim-migrate @ 4626]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
4130 generate_send_as_items(win, NULL); |
| 4359 | 4131 } |
| 4132 } | |
| 4133 | |
| 4134 static struct gaim_conversation_ops conversation_ops = | |
| 4135 { | |
| 4136 gaim_gtkconv_destroy, /* destroy_conversation */ | |
| 4137 gaim_gtkconv_write_chat, /* write_chat */ | |
| 4138 gaim_gtkconv_write_im, /* write_im */ | |
| 4139 gaim_gtkconv_write_conv, /* write_conv */ | |
| 4140 gaim_gtkconv_chat_add_user, /* chat_add_user */ | |
| 4141 gaim_gtkconv_chat_rename_user, /* chat_rename_user */ | |
| 4142 gaim_gtkconv_chat_remove_user, /* chat_remove_user */ | |
| 4143 gaim_gtkconv_set_title, /* set_title */ | |
| 4144 NULL, /* update_progress */ | |
| 4145 gaim_gtkconv_updated /* updated */ | |
| 4146 }; | |
| 4147 | |
| 4148 struct gaim_conversation_ops * | |
| 4149 gaim_get_gtk_conversation_ops(void) | |
| 4150 { | |
| 4151 return &conversation_ops;; | |
| 4152 } | |
| 4153 | |
| 4154 /************************************************************************** | |
| 4155 * Public conversation utility functions | |
| 4156 **************************************************************************/ | |
| 4157 void | |
| 4158 gaim_gtk_set_state_lock(gboolean lock) | |
| 4159 { | |
| 4160 state_lock = lock; | |
| 4161 } | |
| 4162 | |
| 4163 gboolean | |
| 4164 gaim_gtk_is_state_locked(void) | |
| 4165 { | |
| 4166 return state_lock; | |
| 4167 } | |
| 4168 | |
| 4169 void | |
| 4170 gaim_gtkconv_toggle_smileys(void) | |
| 4171 { | |
| 4172 GList *cl; | |
| 4173 struct gaim_conversation *conv; | |
| 4174 struct gaim_gtk_conversation *gtkconv; | |
| 4175 | |
| 4176 for (cl = gaim_get_conversations(); cl != NULL; cl = cl->next) { | |
| 4177 | |
| 4178 conv = (struct gaim_conversation *)cl->data; | |
| 4179 | |
| 4180 if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) | |
| 4181 continue; | |
| 4182 | |
| 4183 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 4184 | |
| 4185 gtk_imhtml_show_smileys(GTK_IMHTML(gtkconv->imhtml), | |
| 4186 (convo_options & OPT_CONVO_SHOW_SMILEY)); | |
| 4187 } | |
| 4188 } | |
| 4189 | |
| 4190 void | |
| 4191 gaim_gtkconv_toggle_timestamps(void) | |
| 4192 { | |
| 4193 GList *cl; | |
| 4194 struct gaim_conversation *conv; | |
| 4195 struct gaim_gtk_conversation *gtkconv; | |
| 4196 | |
| 4197 for (cl = gaim_get_conversations(); cl != NULL; cl = cl->next) { | |
| 4198 | |
| 4199 conv = (struct gaim_conversation *)cl->data; | |
| 4200 | |
| 4201 if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) | |
| 4202 continue; | |
| 4203 | |
| 4204 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 4205 | |
| 4206 gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), | |
| 4207 (convo_options & OPT_CONVO_SHOW_TIME)); | |
| 4208 } | |
| 4209 } | |
| 4210 | |
| 4211 void | |
| 4212 gaim_gtkconv_toggle_spellchk(void) | |
| 4213 { | |
| 4214 #ifdef USE_GTKSPELL | |
| 4215 GList *cl; | |
| 4216 struct gaim_conversation *conv; | |
| 4217 struct gaim_gtk_conversation *gtkconv; | |
| 4218 GtkSpell *spell; | |
| 4219 | |
| 4220 for (cl = gaim_get_conversations(); cl != NULL; cl = cl->next) { | |
| 4221 | |
| 4222 conv = (struct gaim_conversation *)cl->data; | |
| 4223 | |
| 4224 if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) | |
| 4225 continue; | |
| 4226 | |
| 4227 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 4228 | |
| 4229 if (convo_options & OPT_CONVO_CHECK_SPELLING) | |
| 4230 gtkspell_new_attach(GTK_TEXT_VIEW(gtkconv->entry), NULL, NULL); | |
| 4231 else { | |
| 4232 spell = gtkspell_get_from_text_view(GTK_TEXT_VIEW(gtkconv->entry)); | |
| 4233 gtkspell_detach(spell); | |
| 4234 } | |
| 4235 } | |
| 4236 #endif | |
| 4237 } | |
| 4238 | |
| 4239 static void | |
| 4240 remove_icon(struct gaim_gtk_conversation *gtkconv) | |
| 4241 { | |
| 4242 if (gtkconv == NULL) | |
| 4243 return; | |
| 4244 | |
| 4245 if (gtkconv->u.im->icon != NULL) | |
| 4246 gtk_container_remove(GTK_CONTAINER(gtkconv->bbox), | |
| 4247 gtkconv->u.im->icon->parent->parent); | |
| 4248 | |
| 4249 if (gtkconv->u.im->anim != NULL) | |
| 4250 gdk_pixbuf_animation_unref(gtkconv->u.im->anim); | |
| 4251 | |
| 4252 if (gtkconv->u.im->icon_timer != 0) | |
| 4253 g_source_remove(gtkconv->u.im->icon_timer); | |
| 4254 | |
| 4255 if (gtkconv->u.im->iter != NULL) | |
| 4256 g_object_unref(G_OBJECT(gtkconv->u.im->iter)); | |
| 4257 | |
| 4258 gtkconv->u.im->icon_timer = 0; | |
| 4259 gtkconv->u.im->icon = NULL; | |
| 4260 gtkconv->u.im->anim = NULL; | |
| 4261 gtkconv->u.im->iter = NULL; | |
| 4262 } | |
| 4263 | |
| 4264 static gboolean | |
| 4265 redraw_icon(gpointer data) | |
| 4266 { | |
| 4267 struct gaim_conversation *conv = (struct gaim_conversation *)data; | |
| 4268 struct gaim_gtk_conversation *gtkconv; | |
| 4269 | |
| 4270 GdkPixbuf *buf; | |
| 4271 GdkPixbuf *scale; | |
| 4272 GdkPixmap *pm; | |
| 4273 GdkBitmap *bm; | |
| 4274 gint delay; | |
| 4275 | |
| 4276 if (!g_list_find(gaim_get_ims(), conv)) { | |
| 4277 debug_printf("I think this is a bug.\n"); | |
| 4278 return FALSE; | |
| 4279 } | |
| 4280 | |
| 4281 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 4282 | |
| 4283 gdk_pixbuf_animation_iter_advance(gtkconv->u.im->iter, NULL); | |
| 4284 buf = gdk_pixbuf_animation_iter_get_pixbuf(gtkconv->u.im->iter); | |
| 4285 | |
| 4286 scale = gdk_pixbuf_scale_simple(buf, | |
| 4287 MAX(gdk_pixbuf_get_width(buf) * SCALE(gtkconv->u.im->anim) / | |
| 4288 gdk_pixbuf_animation_get_width(gtkconv->u.im->anim), 1), | |
| 4289 MAX(gdk_pixbuf_get_height(buf) * SCALE(gtkconv->u.im->anim) / | |
| 4290 gdk_pixbuf_animation_get_height(gtkconv->u.im->anim), 1), | |
| 4291 GDK_INTERP_NEAREST); | |
| 4292 | |
| 4293 gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100); | |
| 4294 gdk_pixbuf_unref(scale); | |
| 4295 gtk_pixmap_set(GTK_PIXMAP(gtkconv->u.im->icon), pm, bm); | |
| 4296 gdk_pixmap_unref(pm); | |
| 4297 gtk_widget_queue_draw(gtkconv->u.im->icon); | |
| 4298 | |
| 4299 if (bm) | |
| 4300 gdk_bitmap_unref(bm); | |
| 4301 | |
| 4302 delay = gdk_pixbuf_animation_iter_get_delay_time(gtkconv->u.im->iter) / 10; | |
| 4303 | |
| 4304 gtkconv->u.im->icon_timer = g_timeout_add(delay * 10, redraw_icon, conv); | |
| 4305 | |
| 4306 return FALSE; | |
| 4307 } | |
| 4308 | |
| 4309 static void | |
| 4310 start_anim(GtkObject *obj, struct gaim_conversation *conv) | |
| 4311 { | |
| 4312 struct gaim_gtk_conversation *gtkconv; | |
| 4313 int delay; | |
| 4314 | |
| 4315 if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) | |
| 4316 return; | |
| 4317 | |
| 4318 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 4319 | |
| 4320 delay = gdk_pixbuf_animation_iter_get_delay_time(gtkconv->u.im->iter) / 10; | |
| 4321 | |
| 4322 if (gtkconv->u.im->anim) | |
| 4323 gtkconv->u.im->icon_timer = g_timeout_add(delay * 10, redraw_icon, | |
| 4324 conv); | |
| 4325 } | |
| 4326 | |
| 4327 static void | |
| 4328 stop_anim(GtkObject *obj, struct gaim_conversation *conv) | |
| 4329 { | |
| 4330 struct gaim_gtk_conversation *gtkconv; | |
| 4331 | |
| 4332 if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) | |
| 4333 return; | |
| 4334 | |
| 4335 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 4336 | |
| 4337 if (gtkconv->u.im->icon_timer != 0) | |
| 4338 g_source_remove(gtkconv->u.im->icon_timer); | |
| 4339 | |
| 4340 gtkconv->u.im->icon_timer = 0; | |
| 4341 } | |
| 4342 | |
| 4343 static gboolean | |
| 4344 icon_menu(GtkObject *obj, GdkEventButton *e, struct gaim_conversation *conv) | |
| 4345 { | |
| 4346 struct gaim_gtk_conversation *gtkconv; | |
| 4347 static GtkWidget *menu = NULL; | |
| 4348 GtkWidget *button; | |
| 4349 | |
| 4350 if (e->button != 3 || e->type != GDK_BUTTON_PRESS) | |
| 4351 return FALSE; | |
| 4352 | |
| 4353 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 4354 | |
| 4355 /* | |
| 4356 * If a menu already exists, destroy it before creating a new one, | |
| 4357 * thus freeing-up the memory it occupied. | |
| 4358 */ | |
| 4359 if (menu != NULL) | |
| 4360 gtk_widget_destroy(menu); | |
| 4361 | |
| 4362 menu = gtk_menu_new(); | |
| 4363 | |
| 4364 if (gtkconv->u.im->icon_timer) { | |
| 4365 button = gtk_menu_item_new_with_label(_("Disable Animation")); | |
| 4366 g_signal_connect(GTK_OBJECT(button), "activate", | |
| 4367 G_CALLBACK(stop_anim), conv); | |
| 4368 gtk_menu_shell_append(GTK_MENU_SHELL(menu), button); | |
| 4369 gtk_widget_show(button); | |
| 4370 } | |
| 4371 else if (gtkconv->u.im->anim && | |
| 4372 !(gdk_pixbuf_animation_is_static_image(gtkconv->u.im->anim))) | |
| 4373 { | |
| 4374 button = gtk_menu_item_new_with_label(_("Enable Animation")); | |
| 4375 g_signal_connect(GTK_OBJECT(button), "activate", | |
| 4376 G_CALLBACK(start_anim), conv); | |
| 4377 gtk_menu_shell_append(GTK_MENU_SHELL(menu), button); | |
| 4378 gtk_widget_show(button); | |
| 4379 } | |
| 4380 | |
| 4381 button = gtk_menu_item_new_with_label(_("Hide Icon")); | |
| 4382 g_signal_connect_swapped(GTK_OBJECT(button), "activate", | |
| 4383 G_CALLBACK(remove_icon), conv); | |
| 4384 gtk_menu_shell_append(GTK_MENU_SHELL(menu), button); | |
| 4385 gtk_widget_show(button); | |
| 4386 | |
| 4387 button = gtk_menu_item_new_with_label(_("Save Icon As...")); | |
| 4388 g_signal_connect(GTK_OBJECT(button), "activate", | |
| 4389 G_CALLBACK(gaim_gtk_save_icon_dialog), conv); | |
| 4390 gtk_menu_shell_append(GTK_MENU_SHELL(menu), button); | |
| 4391 gtk_widget_show(button); | |
| 4392 | |
| 4393 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, e->button, e->time); | |
| 4394 | |
| 4395 return TRUE; | |
| 4396 } | |
| 4397 | |
| 4398 void | |
| 4399 gaim_gtkconv_update_buddy_icon(struct gaim_conversation *conv) | |
| 4400 { | |
| 4401 struct gaim_gtk_conversation *gtkconv; | |
| 4402 | |
| 4403 char filename[256]; | |
| 4404 FILE *file; | |
| 4405 GError *err = NULL; | |
| 4406 | |
| 4407 void *data; | |
| 4408 int len, delay; | |
| 4409 | |
| 4410 GdkPixbuf *buf; | |
| 4411 | |
| 4412 GtkWidget *event; | |
| 4413 GtkWidget *frame; | |
| 4414 GdkPixbuf *scale; | |
| 4415 GdkPixmap *pm; | |
| 4416 GdkBitmap *bm; | |
| 4417 int sf = 0; | |
| 4418 | |
| 4419 if (conv == NULL || | |
| 4420 gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops() || | |
| 4421 gaim_conversation_get_type(conv) != GAIM_CONV_IM) { | |
| 4422 | |
| 4423 return; | |
| 4424 } | |
| 4425 | |
| 4426 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 4427 | |
| 4428 remove_icon(gtkconv); | |
| 4429 | |
| 4430 if (im_options & OPT_IM_HIDE_ICONS) | |
| 4431 return; | |
| 4432 | |
| 4433 if (gaim_conversation_get_gc(conv) == NULL) | |
| 4434 return; | |
| 4435 | |
| 4436 data = get_icon_data(gaim_conversation_get_gc(conv), | |
| 4437 normalize(gaim_conversation_get_name(conv)), | |
| 4438 &len); | |
| 4439 | |
| 4440 if (!data) | |
| 4441 return; | |
| 4442 | |
| 4443 /* this is such an evil hack, i don't know why i'm even considering it. | |
| 4444 * we'll do it differently when gdk-pixbuf-loader isn't leaky anymore. */ | |
| 4445 g_snprintf(filename, sizeof(filename), | |
| 4446 "%s" G_DIR_SEPARATOR_S "gaimicon-%s.%d", | |
| 4447 g_get_tmp_dir(), gaim_conversation_get_name(conv), getpid()); | |
| 4448 | |
| 4449 if (!(file = fopen(filename, "w"))) | |
| 4450 return; | |
| 4451 | |
| 4452 fwrite(data, 1, len, file); | |
| 4453 fclose(file); | |
| 4454 | |
| 4455 gtkconv->u.im->anim = gdk_pixbuf_animation_new_from_file(filename, &err); | |
| 4456 | |
| 4457 if (err) { | |
| 4458 debug_printf("Buddy icon error: %s\n", err->message); | |
| 4459 g_error_free(err); | |
| 4460 } | |
| 4461 | |
| 4462 /* make sure we remove the file as soon as possible */ | |
| 4463 unlink(filename); | |
| 4464 | |
| 4465 if (!gtkconv->u.im->anim) | |
| 4466 return; | |
| 4467 | |
| 4468 if (gdk_pixbuf_animation_is_static_image(gtkconv->u.im->anim)) { | |
| 4469 gtkconv->u.im->iter = NULL; | |
| 4470 delay = 0; | |
| 4471 buf = gdk_pixbuf_animation_get_static_image(gtkconv->u.im->anim); | |
| 4472 } else { | |
| 4473 gtkconv->u.im->iter = | |
| 4474 gdk_pixbuf_animation_get_iter(gtkconv->u.im->anim, NULL); | |
| 4475 buf = gdk_pixbuf_animation_iter_get_pixbuf(gtkconv->u.im->iter); | |
| 4476 delay = gdk_pixbuf_animation_iter_get_delay_time(gtkconv->u.im->iter); | |
| 4477 delay = delay / 10; | |
| 4478 } | |
| 4479 | |
| 4480 sf = SCALE(gtkconv->u.im->anim); | |
| 4481 scale = gdk_pixbuf_scale_simple(buf, | |
| 4482 MAX(gdk_pixbuf_get_width(buf) * sf / | |
| 4483 gdk_pixbuf_animation_get_width(gtkconv->u.im->anim), 1), | |
| 4484 MAX(gdk_pixbuf_get_height(buf) * sf / | |
| 4485 gdk_pixbuf_animation_get_height(gtkconv->u.im->anim), 1), | |
| 4486 GDK_INTERP_NEAREST); | |
| 4487 | |
| 4488 if (delay) | |
| 4489 gtkconv->u.im->icon_timer = g_timeout_add(delay * 10, redraw_icon, | |
| 4490 conv); | |
| 4491 | |
| 4492 gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100); | |
| 4493 gdk_pixbuf_unref(scale); | |
| 4494 | |
| 4495 frame = gtk_frame_new(NULL); | |
| 4496 gtk_frame_set_shadow_type(GTK_FRAME(frame), | |
| 4497 (bm ? GTK_SHADOW_NONE : GTK_SHADOW_IN)); | |
| 4498 gtk_box_pack_start(GTK_BOX(gtkconv->bbox), frame, FALSE, FALSE, 5); | |
| 4499 gtk_box_reorder_child(GTK_BOX(gtkconv->bbox), frame, 0); | |
| 4500 gtk_widget_show(frame); | |
| 4501 | |
| 4502 event = gtk_event_box_new(); | |
| 4503 gtk_container_add(GTK_CONTAINER(frame), event); | |
| 4504 g_signal_connect(GTK_OBJECT(event), "button-press-event", | |
| 4505 G_CALLBACK(icon_menu), conv); | |
| 4506 gtk_widget_show(event); | |
| 4507 | |
| 4508 gtkconv->u.im->icon = gtk_pixmap_new(pm, bm); | |
| 4509 gtk_widget_set_size_request(gtkconv->u.im->icon, sf, sf); | |
| 4510 gtk_container_add(GTK_CONTAINER(event), gtkconv->u.im->icon); | |
| 4511 gtk_widget_show(gtkconv->u.im->icon); | |
| 4512 | |
| 4513 if(im_options & OPT_IM_NO_ANIMATION) | |
| 4514 stop_anim(NULL, conv); | |
| 4515 | |
| 4516 gdk_pixmap_unref(pm); | |
| 4517 | |
| 4518 if (bm) | |
| 4519 gdk_bitmap_unref(bm); | |
| 4520 } | |
| 4521 | |
| 4522 void | |
| 4523 gaim_gtkconv_hide_buddy_icons(void) | |
| 4524 { | |
| 4525 gaim_conversation_foreach(gaim_gtkconv_update_buddy_icon); | |
| 4526 } | |
| 4527 | |
| 4528 void | |
| 4529 gaim_gtkconv_set_anim(void) | |
| 4530 { | |
| 4531 GList *l; | |
| 4532 | |
| 4533 if (im_options & OPT_IM_HIDE_ICONS) | |
| 4534 return; | |
| 4535 | |
| 4536 if (im_options & OPT_IM_NO_ANIMATION) { | |
| 4537 for (l = gaim_get_ims(); l != NULL; l = l->next) | |
| 4538 stop_anim(NULL, (struct gaim_conversation *)l->data); | |
| 4539 } else { | |
| 4540 for (l = gaim_get_ims(); l != NULL; l = l->next) | |
| 4541 start_anim(NULL, (struct gaim_conversation *)l->data); | |
| 4542 } | |
| 4543 } | |
| 4544 | |
| 4545 void | |
| 4546 gaim_gtkconv_update_font_buttons(void) | |
| 4547 { | |
| 4548 GList *l; | |
| 4549 struct gaim_conversation *conv; | |
| 4550 struct gaim_gtk_conversation *gtkconv; | |
| 4551 | |
| 4552 for (l = gaim_get_ims(); l != NULL; l = l->next) { | |
| 4553 conv = (struct gaim_conversation *)l->data; | |
| 4554 | |
| 4555 if (gaim_conversation_get_ops(conv) != | |
| 4556 gaim_get_gtk_conversation_ops()) | |
| 4557 continue; | |
| 4558 | |
| 4559 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 4560 | |
| 4561 if (gtkconv->toolbar.bold != NULL) | |
| 4562 gtk_widget_set_sensitive(gtkconv->toolbar.bold, | |
| 4563 (!(font_options & OPT_FONT_BOLD))); | |
| 4564 | |
| 4565 if (gtkconv->toolbar.italic != NULL) | |
| 4566 gtk_widget_set_sensitive(gtkconv->toolbar.italic, | |
| 4567 (!(font_options & OPT_FONT_ITALIC))); | |
| 4568 | |
| 4569 if (gtkconv->toolbar.underline != NULL) | |
| 4570 gtk_widget_set_sensitive(gtkconv->toolbar.underline, | |
| 4571 (!(font_options & OPT_FONT_UNDERLINE))); | |
| 4572 } | |
| 4573 } | |
| 4574 | |
| 4575 void | |
| 4576 gaim_gtkconv_update_tabs(void) | |
| 4577 { | |
| 4578 GList *l; | |
| 4579 GtkPositionType pos; | |
| 4580 struct gaim_window *win; | |
| 4581 struct gaim_gtk_window *gtkwin; | |
| 4582 | |
| 4583 pos = ((im_options & OPT_IM_SIDE_TAB) | |
| 4584 ? ((im_options & OPT_IM_BR_TAB) ? GTK_POS_RIGHT : GTK_POS_LEFT) | |
| 4585 : ((im_options & OPT_IM_BR_TAB) ? GTK_POS_BOTTOM : GTK_POS_TOP)); | |
| 4586 | |
| 4587 for (l = gaim_get_windows(); l != NULL; l = l->next) { | |
| 4588 win = (struct gaim_window *)l->data; | |
| 4589 | |
| 4590 if (gaim_window_get_ops(win) != gaim_get_gtk_window_ops()) | |
| 4591 continue; | |
| 4592 | |
| 4593 gtkwin = GAIM_GTK_WINDOW(win); | |
| 4594 | |
| 4595 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(gtkwin->notebook), pos); | |
| 4596 } | |
| 4597 } | |
| 4598 | |
| 4599 void | |
| 4600 gaim_gtkconv_update_chat_button_style() | |
| 4601 { | |
| 4602 GSList *l; | |
| 4603 struct gaim_connection *g; | |
| 4604 GtkWidget *parent; | |
| 4605 GaimConversationType type = GAIM_CONV_CHAT; | |
| 4606 | |
| 4607 for (l = connections; l != NULL; l = l->next) { | |
| 4608 GSList *bcs; | |
| 4609 struct gaim_conversation *conv; | |
| 4610 struct gaim_gtk_conversation *gtkconv; | |
| 4611 struct gaim_gtk_window *gtkwin; | |
| 4612 | |
| 4613 g = (struct gaim_connection *)l->data; | |
| 4614 | |
| 4615 for (bcs = g->buddy_chats; bcs != NULL; bcs = bcs->next) { | |
| 4616 conv = (struct gaim_conversation *)bcs->data; | |
| 4617 | |
| 4618 if (gaim_conversation_get_type(conv) != GAIM_CONV_CHAT) | |
| 4619 continue; | |
| 4620 | |
| 4621 if (gaim_conversation_get_ops(conv) != | |
| 4622 gaim_get_gtk_conversation_ops()) | |
| 4623 continue; | |
| 4624 | |
| 4625 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 4626 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(conv)); | |
| 4627 parent = gtk_widget_get_parent(gtkconv->send); | |
| 4628 | |
| 4629 gtkconv->send = | |
| 4630 gaim_gtk_change_text(_("Send"), | |
| 4631 gtkconv->send, GAIM_STOCK_SEND, type); | |
| 4632 gtkconv->u.chat->invite = | |
| 4633 gaim_gtk_change_text(_("Invite"), | |
| 4634 gtkconv->u.chat->invite, | |
| 4635 GAIM_STOCK_INVITE, type); | |
| 4636 | |
| 4637 gtk_box_pack_end(GTK_BOX(parent), gtkconv->send, FALSE, FALSE, | |
| 4638 type); | |
| 4639 gtk_box_pack_end(GTK_BOX(parent), gtkconv->u.chat->invite, | |
| 4640 FALSE, FALSE, 0); | |
| 4641 | |
| 4642 g_signal_connect(G_OBJECT(gtkconv->send), "clicked", | |
| 4643 G_CALLBACK(send_cb), conv); | |
| 4644 g_signal_connect(G_OBJECT(gtkconv->u.chat->invite), "clicked", | |
| 4645 G_CALLBACK(invite_cb), conv); | |
| 4646 | |
| 4647 gtk_button_set_relief(GTK_BUTTON(gtkconv->send), | |
| 4648 GTK_RELIEF_NONE); | |
| 4649 gtk_button_set_relief(GTK_BUTTON(gtkconv->u.chat->invite), | |
| 4650 GTK_RELIEF_NONE); | |
| 4651 | |
| 4652 gaim_gtkconv_update_buttons_by_protocol(conv); | |
| 4653 } | |
| 4654 } | |
| 4655 } | |
| 4656 | |
| 4657 void | |
| 4658 gaim_gtkconv_update_im_button_style() | |
| 4659 { | |
| 4660 GList *l; | |
| 4661 struct gaim_conversation *conv; | |
| 4662 struct gaim_gtk_conversation *gtkconv; | |
| 4663 | |
| 4664 for (l = gaim_get_ims(); l != NULL; l = l->next) { | |
| 4665 conv = (struct gaim_conversation *)l->data; | |
| 4666 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 4667 | |
| 4668 setup_im_buttons(conv, gtk_widget_get_parent(gtkconv->send)); | |
| 4669 } | |
| 4670 } | |
| 4671 | |
| 4672 void | |
| 4673 gaim_gtkconv_update_buttons_by_protocol(struct gaim_conversation *conv) | |
| 4674 { | |
| 4675 struct gaim_window *win; | |
| 4676 struct gaim_gtk_window *gtkwin = NULL; | |
| 4677 struct gaim_gtk_conversation *gtkconv; | |
| 4678 struct gaim_connection *gc; | |
| 4679 | |
| 4680 if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) | |
| 4681 return; | |
| 4682 | |
| 4683 gc = gaim_conversation_get_gc(conv); | |
| 4684 win = gaim_conversation_get_window(conv); | |
| 4685 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
| 4686 | |
| 4687 if (win != NULL) | |
| 4688 gtkwin = GAIM_GTK_WINDOW(win); | |
| 4689 | |
| 4690 if (gc == NULL) { | |
| 4691 gtk_widget_set_sensitive(gtkconv->send, FALSE); | |
| 4692 | |
| 4693 if (gaim_window_get_active_conversation(win) == conv) { | |
| 4694 gtk_widget_set_sensitive(gtkwin->menu.insert_link, FALSE); | |
| 4695 } | |
| 4696 } | |
| 4697 | |
| 4698 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { | |
| 4699 if (gc == NULL) { | |
| 4700 gtk_widget_set_sensitive(gtkconv->info, FALSE); | |
| 4701 gtk_widget_set_sensitive(gtkconv->u.im->warn, FALSE); | |
| 4702 gtk_widget_set_sensitive(gtkconv->u.im->block, FALSE); | |
| 4703 gtk_widget_set_sensitive(gtkconv->u.im->add, FALSE); | |
| 4704 | |
| 4705 if (win != NULL && | |
| 4706 gaim_window_get_active_conversation(win) == conv) { | |
| 4707 | |
| 4708 gtk_widget_set_sensitive(gtkwin->menu.insert_image, FALSE); | |
| 4709 } | |
| 4710 | |
| 4711 return; | |
| 4712 } | |
| 4713 | |
| 4714 gtk_widget_set_sensitive(gtkconv->info, | |
| 4715 (gc->prpl->get_info != NULL)); | |
| 4716 | |
| 4717 gtk_widget_set_sensitive(gtkconv->toolbar.image, | |
| 4718 (gc->prpl->options & OPT_PROTO_IM_IMAGE)); | |
| 4719 | |
| 4720 if (win != NULL && gaim_window_get_active_conversation(win) == conv) { | |
| 4721 gtk_widget_set_sensitive(gtkwin->menu.insert_image, | |
| 4722 (gc->prpl->options & OPT_PROTO_IM_IMAGE)); | |
| 4723 } | |
| 4724 | |
| 4725 gtk_widget_set_sensitive(gtkconv->u.im->warn, | |
| 4726 (gc->prpl->warn != NULL)); | |
| 4727 | |
| 4728 gtk_widget_set_sensitive(gtkconv->u.im->block, | |
| 4729 (gc->prpl->add_permit != NULL)); | |
| 4730 | |
| 4731 update_convo_add_button(conv); | |
| 4732 } | |
| 4733 else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { | |
| 4734 if (gc == NULL) { | |
| 4735 gtk_widget_set_sensitive(gtkconv->u.chat->whisper, FALSE); | |
| 4736 gtk_widget_set_sensitive(gtkconv->u.chat->invite, FALSE); | |
| 4737 | |
| 4738 return; | |
| 4739 } | |
| 4740 | |
| 4741 gtk_widget_set_sensitive(gtkconv->send, (gc->prpl->chat_send != NULL)); | |
| 4742 | |
| 4743 gtk_widget_set_sensitive(gtkconv->toolbar.image, FALSE); | |
| 4744 /* gtk_widget_set_sensitive(gtkwin->menu.insert_image, FALSE); */ | |
| 4745 | |
| 4746 gtk_widget_set_sensitive(gtkconv->u.chat->whisper, | |
| 4747 (gc->prpl->chat_whisper != NULL)); | |
| 4748 | |
| 4749 gtk_widget_set_sensitive(gtkconv->u.chat->invite, | |
| 4750 (gc->prpl->chat_invite != NULL)); | |
| 4751 } | |
| 4752 } | |
| 4753 | |
| 4754 struct gaim_window * | |
| 4755 gaim_gtkwin_get_at_xy(int x, int y) | |
| 4756 { | |
| 4757 struct gaim_window *win = NULL; | |
| 4758 struct gaim_gtk_window *gtkwin; | |
| 4759 GdkWindow *gdkwin; | |
| 4760 GList *l; | |
| 4761 | |
| 4762 gdkwin = gdk_window_at_pointer(&x, &y); | |
| 4763 | |
| 4764 if (gdkwin) | |
| 4765 gdkwin = gdk_window_get_toplevel(gdkwin); | |
| 4766 | |
| 4767 for (l = gaim_get_windows(); l != NULL; l = l->next) { | |
| 4768 win = (struct gaim_window *)l->data; | |
| 4769 | |
| 4770 if (gaim_window_get_ops(win) != gaim_get_gtk_window_ops()) | |
| 4771 continue; | |
| 4772 | |
| 4773 gtkwin = GAIM_GTK_WINDOW(win); | |
| 4774 | |
| 4775 if (gdkwin == gtkwin->window->window) | |
| 4776 return win; | |
| 4777 } | |
| 4778 | |
| 4779 return NULL; | |
| 4780 } | |
| 4781 | |
| 4782 int | |
| 4783 gaim_gtkconv_get_tab_at_xy(struct gaim_window *win, int x, int y) | |
| 4784 { | |
| 4785 struct gaim_gtk_window *gtkwin; | |
| 4786 GList *l; | |
| 4787 gint nb_x, nb_y, x_rel, y_rel; | |
| 4788 GtkNotebook *notebook; | |
| 4789 GtkWidget *tab; | |
| 4790 gint i, page_num = 0; | |
| 4791 gboolean first_visible = TRUE; | |
| 4792 | |
| 4793 if (gaim_window_get_ops(win) != gaim_get_gtk_window_ops()) | |
| 4794 return -1; | |
| 4795 | |
| 4796 gtkwin = GAIM_GTK_WINDOW(win); | |
| 4797 notebook = GTK_NOTEBOOK(gtkwin->notebook); | |
| 4798 | |
| 4799 gdk_window_get_origin(gtkwin->notebook->window, &nb_x, &nb_y); | |
| 4800 x_rel = x - nb_x; | |
| 4801 y_rel = y - nb_y; | |
| 4802 | |
| 4803 for (l = gaim_window_get_conversations(win), i = 0; | |
| 4804 l != NULL; | |
| 4805 l = l->next, i++) { | |
| 4806 | |
| 4807 struct gaim_conversation *conv = l->data; | |
| 4808 tab = GAIM_GTK_CONVERSATION(conv)->tab_label; | |
| 4809 | |
| 4810 if (!GTK_WIDGET_MAPPED(tab)) | |
| 4811 continue; | |
| 4812 | |
| 4813 if (first_visible) { | |
| 4814 first_visible = FALSE; | |
| 4815 | |
| 4816 if (x_rel < tab->allocation.x) x_rel = tab->allocation.x; | |
| 4817 if (y_rel < tab->allocation.y) y_rel = tab->allocation.y; | |
| 4818 } | |
| 4819 | |
| 4820 if (gtk_notebook_get_tab_pos(notebook) == GTK_POS_TOP || | |
| 4821 gtk_notebook_get_tab_pos(notebook) == GTK_POS_BOTTOM) { | |
| 4822 | |
| 4823 if (tab->allocation.x <= x_rel) { | |
| 4824 if (tab->allocation.x + tab->allocation.width <= x_rel) | |
| 4825 page_num = i + 1; | |
| 4826 else | |
| 4827 page_num = i; | |
| 4828 } | |
| 4829 else | |
| 4830 break; | |
| 4831 } | |
| 4832 else { | |
| 4833 if (tab->allocation.y <= y_rel) { | |
| 4834 if (tab->allocation.y + tab->allocation.height <= y_rel) | |
| 4835 page_num = i + 1; | |
| 4836 else | |
| 4837 page_num = i; | |
| 4838 } | |
| 4839 else | |
| 4840 break; | |
| 4841 } | |
| 4842 } | |
| 4843 | |
| 4844 if (i == gaim_window_get_conversation_count(win) + 1) | |
| 4845 return -1; | |
| 4846 | |
| 4847 return page_num; | |
| 4848 } | |
| 4849 | |
| 4850 int | |
| 4851 gaim_gtkconv_get_dest_tab_at_xy(struct gaim_window *win, int x, int y) | |
| 4852 { | |
| 4853 struct gaim_gtk_window *gtkwin; | |
| 4854 GList *l; | |
| 4855 gint nb_x, nb_y, x_rel, y_rel; | |
| 4856 GtkNotebook *notebook; | |
| 4857 GtkWidget *tab; | |
| 4858 gint i, page_num = 0; | |
| 4859 | |
| 4860 if (gaim_window_get_ops(win) != gaim_get_gtk_window_ops()) | |
| 4861 return -1; | |
| 4862 | |
| 4863 gtkwin = GAIM_GTK_WINDOW(win); | |
| 4864 notebook = GTK_NOTEBOOK(gtkwin->notebook); | |
| 4865 | |
| 4866 gdk_window_get_origin(gtkwin->notebook->window, &nb_x, &nb_y); | |
| 4867 x_rel = x - nb_x; | |
| 4868 y_rel = y - nb_y; | |
| 4869 | |
| 4870 for (l = gaim_window_get_conversations(win), i = 0; | |
| 4871 l != NULL; | |
| 4872 l = l->next, i++) { | |
| 4873 | |
| 4874 struct gaim_conversation *conv = l->data; | |
| 4875 tab = GAIM_GTK_CONVERSATION(conv)->tab_label; | |
| 4876 | |
| 4877 if (!GTK_WIDGET_MAPPED(tab)) | |
| 4878 continue; | |
| 4879 | |
| 4880 if (gtk_notebook_get_tab_pos(notebook) == GTK_POS_TOP || | |
| 4881 gtk_notebook_get_tab_pos(notebook) == GTK_POS_BOTTOM) { | |
| 4882 | |
| 4883 if (tab->allocation.x <= x_rel) { | |
| 4884 if (tab->allocation.x + (tab->allocation.width / 2) <= x_rel) | |
| 4885 page_num = i + 1; | |
| 4886 else | |
| 4887 page_num = i; | |
| 4888 } | |
| 4889 else | |
| 4890 break; | |
| 4891 } | |
| 4892 else { | |
| 4893 if (tab->allocation.y <= y_rel) { | |
| 4894 if (tab->allocation.y + (tab->allocation.height / 2) <= y_rel) | |
| 4895 page_num = i + 1; | |
| 4896 else | |
| 4897 page_num = i; | |
| 4898 } | |
| 4899 else | |
| 4900 break; | |
| 4901 } | |
| 4902 } | |
| 4903 | |
| 4904 if (i == gaim_window_get_conversation_count(win) + 1) | |
| 4905 return -1; | |
| 4906 | |
| 4907 return page_num; | |
| 4908 } |
