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