Mercurial > pidgin
annotate src/gtkconv.c @ 4368:9c83a731a3ea
[gaim-migrate @ 4634]
Should prevent a segfault and the Add button tooltip issue.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Mon, 20 Jan 2003 21:54:46 +0000 |
parents | 6e96ced6fb78 |
children | 7e1fb422e5fd |
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 | |
1653 dest_win = gaim_gtkwin_get_at_xy(e->x_root, e->y_root); | |
1654 dest_gtkwin = GAIM_GTK_WINDOW(dest_win); | |
1655 | |
1656 conv = gaim_window_get_active_conversation(win); | |
1657 | |
1658 if (dest_win == NULL) { | |
1659 if (gaim_window_get_conversation_count(win) < 2) | |
1660 return FALSE; | |
1661 | |
1662 if (gaim_window_get_conversation_count(win) > 1) { | |
1663 /* Make a new window to stick this to. */ | |
1664 struct gaim_window *new_win; | |
1665 | |
1666 new_win = gaim_window_new(); | |
1667 gaim_window_remove_conversation(win, | |
1668 gaim_conversation_get_index(conv)); | |
1669 gaim_window_add_conversation(new_win, conv); | |
1670 gaim_window_show(new_win); | |
1671 } | |
1672 | |
1673 return TRUE; | |
1674 } | |
1675 | |
1676 /* Get the destination notebook. */ | |
1677 dest_notebook = GTK_NOTEBOOK(gtkwin->notebook); | |
1678 | |
1679 /* Get the destination page number. */ | |
1680 dest_page_num = gaim_gtkconv_get_dest_tab_at_xy(dest_win, | |
1681 e->x_root, e->y_root); | |
1682 | |
1683 if (win == dest_win) { | |
1684 gaim_window_move_conversation(win, | |
1685 gaim_conversation_get_index(conv), dest_page_num); | |
1686 } | |
1687 else { | |
1688 size_t pos; | |
1689 | |
1690 gaim_window_remove_conversation(win, | |
1691 gaim_conversation_get_index(conv)); | |
1692 | |
1693 pos = gaim_window_add_conversation(dest_win, conv); | |
1694 | |
1695 gaim_window_move_conversation(dest_win, pos, dest_page_num); | |
1696 | |
1697 gaim_window_switch_conversation(dest_win, dest_page_num); | |
1698 } | |
1699 | |
1700 gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); | |
1701 | |
1702 debug_printf("release cb returning.\n"); | |
1703 return TRUE; | |
1704 } | |
1705 | |
1706 static void | |
1707 switch_conv_cb(GtkNotebook *notebook, GtkWidget *page, gint page_num, | |
1708 gpointer user_data) | |
1709 { | |
1710 struct gaim_window *win; | |
1711 struct gaim_conversation *conv; | |
1712 struct gaim_gtk_conversation *gtkconv; | |
1713 struct gaim_gtk_window *gtkwin; | |
1714 struct gaim_connection *gc; | |
1715 | |
1716 if (gaim_gtk_is_state_locked()) | |
1717 return; | |
1718 | |
1719 debug_printf("Switching conversation\n"); | |
1720 | |
1721 win = (struct gaim_window *)user_data; | |
1722 | |
1723 conv = gaim_window_get_conversation_at(win, page_num); | |
1724 gc = gaim_conversation_get_gc(conv); | |
1725 gtkwin = GAIM_GTK_WINDOW(win); | |
1726 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
1727 | |
1728 gaim_conversation_set_unseen(conv, GAIM_UNSEEN_NONE); | |
1729 | |
4364
fa56829b9587
[gaim-migrate @ 4630]
Christian Hammond <chipx86@chipx86.com>
parents:
4363
diff
changeset
|
1730 if (gc != NULL) { |
fa56829b9587
[gaim-migrate @ 4630]
Christian Hammond <chipx86@chipx86.com>
parents:
4363
diff
changeset
|
1731 gtk_widget_set_sensitive(gtkwin->menu.insert_link, TRUE); |
fa56829b9587
[gaim-migrate @ 4630]
Christian Hammond <chipx86@chipx86.com>
parents:
4363
diff
changeset
|
1732 } |
fa56829b9587
[gaim-migrate @ 4630]
Christian Hammond <chipx86@chipx86.com>
parents:
4363
diff
changeset
|
1733 |
4359 | 1734 /* Update the menubar */ |
1735 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { | |
1736 gtk_widget_set_sensitive(gtkwin->menu.view_history, TRUE); | |
1737 gtk_widget_set_sensitive(gtkwin->menu.insert_image, | |
1738 (gc && gc->prpl->options & OPT_PROTO_IM_IMAGE)); | |
1739 | |
1740 if (gtkwin->menu.send_as != NULL) | |
1741 update_send_as_selection(win); | |
1742 } | |
1743 else { | |
1744 gtk_widget_set_sensitive(gtkwin->menu.view_history, FALSE); | |
1745 gtk_widget_set_sensitive(gtkwin->menu.insert_image, FALSE); | |
1746 | |
1747 if (gtkwin->menu.send_as != NULL) | |
1748 gtk_widget_hide(gtkwin->menu.send_as); | |
1749 } | |
1750 | |
1751 gaim_gtk_set_state_lock(TRUE); | |
1752 | |
1753 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtkwin->menu.logging), | |
1754 gaim_conversation_is_logging(conv)); | |
1755 | |
1756 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtkwin->menu.sounds), | |
1757 gtkconv->make_sound); | |
1758 | |
1759 gaim_gtk_set_state_lock(FALSE); | |
1760 | |
1761 gtk_widget_grab_focus(gtkconv->entry); | |
1762 } | |
1763 | |
1764 /************************************************************************** | |
1765 * Utility functions | |
1766 **************************************************************************/ | |
1767 static void | |
1768 do_bold(GtkWidget *bold, struct gaim_gtk_conversation *gtkconv) | |
1769 { | |
1770 if (gaim_gtk_is_state_locked()) | |
1771 return; | |
1772 | |
1773 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(bold))) | |
1774 gaim_gtk_surround(gtkconv, "<B>", "</B>"); | |
1775 else | |
1776 gaim_gtk_advance_past(gtkconv, "<B>", "</B>"); | |
1777 | |
1778 gtk_widget_grab_focus(gtkconv->entry); | |
1779 } | |
1780 | |
1781 static void | |
1782 do_italic(GtkWidget *italic, struct gaim_gtk_conversation *gtkconv) | |
1783 { | |
1784 if (gaim_gtk_is_state_locked()) | |
1785 return; | |
1786 | |
1787 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(italic))) | |
1788 gaim_gtk_surround(gtkconv, "<I>", "</I>"); | |
1789 else | |
1790 gaim_gtk_advance_past(gtkconv, "<I>", "</I>"); | |
1791 | |
1792 gtk_widget_grab_focus(gtkconv->entry); | |
1793 } | |
1794 | |
1795 static void | |
1796 do_underline(GtkWidget *underline, struct gaim_gtk_conversation *gtkconv) | |
1797 { | |
1798 if (gaim_gtk_is_state_locked()) | |
1799 return; | |
1800 | |
1801 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(underline))) | |
1802 gaim_gtk_surround(gtkconv, "<U>", "</U>"); | |
1803 else | |
1804 gaim_gtk_advance_past(gtkconv, "<U>", "</U>"); | |
1805 | |
1806 gtk_widget_grab_focus(gtkconv->entry); | |
1807 } | |
1808 | |
1809 static void | |
1810 do_small(GtkWidget *small, struct gaim_gtk_conversation *gtkconv) | |
1811 { | |
1812 if (gaim_gtk_is_state_locked()) | |
1813 return; | |
1814 | |
1815 gaim_gtk_surround(gtkconv, "<FONT SIZE=\"1\">", "</FONT>"); | |
1816 | |
1817 gtk_widget_grab_focus(gtkconv->entry); | |
1818 } | |
1819 | |
1820 static void | |
1821 do_normal(GtkWidget *small, struct gaim_gtk_conversation *gtkconv) | |
1822 { | |
1823 if (gaim_gtk_is_state_locked()) | |
1824 return; | |
1825 | |
1826 gaim_gtk_surround(gtkconv, "<FONT SIZE=\"3\">", "</FONT>"); | |
1827 | |
1828 gtk_widget_grab_focus(gtkconv->entry); | |
1829 } | |
1830 | |
1831 static void | |
1832 do_big(GtkWidget *small, struct gaim_gtk_conversation *gtkconv) | |
1833 { | |
1834 if (gaim_gtk_is_state_locked()) | |
1835 return; | |
1836 | |
1837 gaim_gtk_surround(gtkconv, "<FONT SIZE=\"5\">", "</FONT>"); | |
1838 | |
1839 gtk_widget_grab_focus(gtkconv->entry); | |
1840 } | |
1841 | |
1842 static void | |
1843 toggle_font(GtkWidget *font, struct gaim_conversation *conv) | |
1844 { | |
1845 struct gaim_gtk_conversation *gtkconv; | |
1846 | |
1847 if (gaim_gtk_is_state_locked()) | |
1848 return; | |
1849 | |
1850 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
1851 | |
1852 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(font))) | |
1853 show_font_dialog(conv, font); | |
1854 else if (gtkconv->dialogs.fg_color != NULL) | |
1855 cancel_font(font, conv); | |
1856 else | |
1857 gaim_gtk_advance_past(gtkconv, "<FONT FACE>", "</FONT>"); | |
1858 } | |
1859 | |
1860 static void | |
1861 toggle_fg_color(GtkWidget *color, struct gaim_conversation *conv) | |
1862 { | |
1863 struct gaim_gtk_conversation *gtkconv; | |
1864 | |
1865 if (gaim_gtk_is_state_locked()) | |
1866 return; | |
1867 | |
1868 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
1869 | |
1870 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(color))) | |
1871 show_fgcolor_dialog(conv, color); | |
1872 else if (gtkconv->dialogs.fg_color != NULL) | |
1873 cancel_fgcolor(color, conv); | |
1874 else | |
1875 gaim_gtk_advance_past(gtkconv, "<FONT COLOR>", "</FONT>"); | |
1876 } | |
1877 | |
1878 static void | |
1879 toggle_bg_color(GtkWidget *color, struct gaim_conversation *conv) | |
1880 { | |
1881 struct gaim_gtk_conversation *gtkconv; | |
1882 | |
1883 if (gaim_gtk_is_state_locked()) | |
1884 return; | |
1885 | |
1886 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
1887 | |
1888 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(color))) | |
1889 show_bgcolor_dialog(conv, color); | |
1890 else if (gtkconv->dialogs.bg_color != NULL) | |
1891 cancel_bgcolor(color, conv); | |
1892 else | |
1893 gaim_gtk_advance_past(gtkconv, "<BODY BGCOLOR>", "</BODY>"); | |
1894 } | |
1895 | |
1896 static void | |
1897 check_everything(GtkTextBuffer *buffer) | |
1898 { | |
1899 struct gaim_conversation *conv; | |
1900 struct gaim_gtk_conversation *gtkconv; | |
1901 | |
1902 conv = (struct gaim_conversation *)g_object_get_data(G_OBJECT(buffer), | |
1903 "user_data"); | |
1904 | |
1905 if (conv == NULL) | |
1906 return; | |
1907 | |
1908 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
1909 | |
1910 /* CONV TODO */ | |
1911 } | |
1912 | |
1913 static void | |
1914 quiet_set(GtkWidget *tb, gboolean active) | |
1915 { | |
1916 gaim_gtk_set_state_lock(TRUE); | |
1917 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tb), active); | |
1918 gaim_gtk_set_state_lock(FALSE); | |
1919 } | |
1920 | |
1921 static void | |
1922 got_typing_keypress(struct gaim_conversation *conv, gboolean first) | |
1923 { | |
1924 struct gaim_im *im; | |
1925 | |
1926 /* | |
1927 * We know we got something, so we at least have to make sure we don't | |
1928 * send TYPED any time soon. | |
1929 */ | |
1930 | |
1931 im = GAIM_IM(conv); | |
1932 | |
1933 if (gaim_im_get_type_again_timeout(im)) | |
1934 gaim_im_stop_type_again_timeout(im); | |
1935 | |
1936 gaim_im_start_type_again_timeout(im); | |
1937 | |
1938 if (first || (gaim_im_get_type_again(im) != 0 && | |
1939 time(NULL) > gaim_im_get_type_again(im))) { | |
1940 | |
1941 int timeout = serv_send_typing(gaim_conversation_get_gc(conv), | |
1942 (char *)gaim_conversation_get_name(conv), | |
1943 TYPING); | |
1944 | |
1945 if (timeout) | |
1946 gaim_im_set_type_again(im, time(NULL) + timeout); | |
1947 else | |
1948 gaim_im_set_type_again(im, 0); | |
1949 } | |
1950 } | |
1951 | |
1952 static void | |
1953 update_send_as_selection(struct gaim_window *win) | |
1954 { | |
1955 struct aim_user *user; | |
1956 struct gaim_conversation *conv; | |
1957 struct gaim_gtk_window *gtkwin; | |
1958 const char *username; | |
1959 GtkWidget *menu; | |
1960 GList *child; | |
1961 | |
1962 conv = gaim_window_get_active_conversation(win); | |
1963 | |
1964 if (conv == NULL) | |
1965 return; | |
1966 | |
1967 user = gaim_conversation_get_user(conv); | |
1968 gtkwin = GAIM_GTK_WINDOW(win); | |
1969 | |
4364
fa56829b9587
[gaim-migrate @ 4630]
Christian Hammond <chipx86@chipx86.com>
parents:
4363
diff
changeset
|
1970 if (gtkwin->menu.send_as == NULL) |
fa56829b9587
[gaim-migrate @ 4630]
Christian Hammond <chipx86@chipx86.com>
parents:
4363
diff
changeset
|
1971 return; |
fa56829b9587
[gaim-migrate @ 4630]
Christian Hammond <chipx86@chipx86.com>
parents:
4363
diff
changeset
|
1972 |
4359 | 1973 username = (user->gc == NULL ? user->username : user->gc->username); |
1974 | |
1975 gtk_widget_show(gtkwin->menu.send_as); | |
1976 | |
1977 menu = gtk_menu_item_get_submenu( | |
1978 GTK_MENU_ITEM(gtkwin->menu.send_as)); | |
1979 | |
1980 gaim_gtk_set_state_lock(TRUE); | |
1981 | |
1982 for (child = gtk_container_get_children(GTK_CONTAINER(menu)); | |
1983 child != NULL; | |
1984 child = child->next) { | |
1985 | |
1986 GtkWidget *item = child->data; | |
1987 GtkWidget *label; | |
1988 const char *title; | |
1989 | |
1990 label = gtk_bin_get_child(GTK_BIN(item)); | |
1991 | |
1992 if (!GTK_IS_LABEL(label)) | |
1993 continue; | |
1994 | |
1995 title = gtk_label_get_text(GTK_LABEL(label)); | |
1996 | |
1997 if (!strcmp(title, username)) { | |
1998 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE); | |
1999 break; | |
2000 } | |
2001 } | |
2002 | |
2003 gaim_gtk_set_state_lock(FALSE); | |
2004 } | |
2005 | |
2006 static void | |
4360
c435a29370b8
[gaim-migrate @ 4626]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
2007 generate_send_as_items(struct gaim_window *win, |
c435a29370b8
[gaim-migrate @ 4626]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
2008 struct gaim_conversation *deleted_conv) |
4359 | 2009 { |
2010 struct gaim_gtk_window *gtkwin; | |
2011 GtkWidget *menu; | |
2012 GtkWidget *menuitem; | |
2013 GSList *gcs; | |
2014 GList *convs; | |
2015 GSList *group = NULL; | |
2016 gboolean first_offline = TRUE; | |
2017 gboolean found_online = FALSE; | |
2018 | |
2019 gtkwin = GAIM_GTK_WINDOW(win); | |
2020 | |
2021 if (gtkwin->menu.send_as != NULL) | |
2022 gtk_widget_destroy(gtkwin->menu.send_as); | |
2023 | |
2024 /* See if we have > 1 connection active. */ | |
2025 if (g_slist_length(connections) < 2) { | |
2026 /* Now make sure we don't have any Offline entries. */ | |
2027 gboolean found_offline = FALSE; | |
2028 | |
2029 for (convs = gaim_get_conversations(); | |
2030 convs != NULL; | |
2031 convs = convs->next) { | |
2032 | |
2033 struct gaim_conversation *conv; | |
2034 struct aim_user *user; | |
2035 | |
2036 conv = (struct gaim_conversation *)convs->data; | |
2037 user = gaim_conversation_get_user(conv); | |
2038 | |
2039 if (user->gc == NULL) { | |
2040 found_offline = TRUE; | |
2041 break; | |
2042 } | |
2043 } | |
2044 | |
2045 if (!found_offline) { | |
2046 gtkwin->menu.send_as = NULL; | |
2047 return; | |
2048 } | |
2049 } | |
2050 | |
2051 /* Build the Send As menu */ | |
2052 gtkwin->menu.send_as = gtk_menu_item_new_with_mnemonic(_("_Send As")); | |
2053 gtk_widget_show(gtkwin->menu.send_as); | |
2054 | |
2055 menu = gtk_menu_new(); | |
2056 | |
2057 gtk_menu_shell_append(GTK_MENU_SHELL(gtkwin->menu.menubar), | |
2058 gtkwin->menu.send_as); | |
2059 gtk_menu_item_set_submenu(GTK_MENU_ITEM(gtkwin->menu.send_as), menu); | |
2060 | |
2061 gtk_widget_show(menu); | |
2062 | |
2063 /* Fill it with entries. */ | |
2064 for (gcs = connections; gcs != NULL; gcs = gcs->next) { | |
2065 struct gaim_connection *gc; | |
2066 | |
2067 found_online = TRUE; | |
2068 | |
2069 gc = (struct gaim_connection *)gcs->data; | |
2070 | |
2071 menuitem = gtk_radio_menu_item_new_with_label(group, gc->username); | |
2072 group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(menuitem)); | |
2073 | |
2074 g_object_set_data(G_OBJECT(menuitem), "user_data", win); | |
2075 | |
2076 g_signal_connect(G_OBJECT(menuitem), "activate", | |
2077 G_CALLBACK(menu_conv_sel_send_cb), gc->user); | |
2078 | |
2079 gtk_widget_show(menuitem); | |
2080 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
2081 } | |
2082 | |
2083 /* | |
2084 * Fill it with any accounts that still has an open (yet disabled) window | |
2085 * (signed off accounts with a window open). | |
2086 */ | |
2087 for (convs = gaim_get_conversations(); | |
2088 convs != NULL; | |
2089 convs = convs->next) { | |
2090 | |
2091 struct gaim_conversation *conv; | |
2092 struct aim_user *user; | |
2093 | |
2094 conv = (struct gaim_conversation *)convs->data; | |
4360
c435a29370b8
[gaim-migrate @ 4626]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
2095 |
c435a29370b8
[gaim-migrate @ 4626]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
2096 if (conv == deleted_conv) |
c435a29370b8
[gaim-migrate @ 4626]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
2097 continue; |
c435a29370b8
[gaim-migrate @ 4626]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
2098 |
4359 | 2099 user = gaim_conversation_get_user(conv); |
2100 | |
2101 if (user->gc == NULL) { | |
2102 if (first_offline && found_online) { | |
2103 menuitem = gtk_separator_menu_item_new(); | |
2104 gtk_widget_show(menuitem); | |
2105 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
2106 | |
2107 first_offline = FALSE; | |
2108 } | |
2109 | |
2110 menuitem = gtk_radio_menu_item_new_with_label(group, | |
2111 user->username); | |
2112 group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(menuitem)); | |
2113 | |
2114 gtk_widget_set_sensitive(menuitem, FALSE); | |
2115 | |
2116 gtk_widget_show(menuitem); | |
2117 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
2118 } | |
2119 } | |
2120 | |
2121 gtk_widget_show(gtkwin->menu.send_as); | |
2122 update_send_as_selection(win); | |
2123 } | |
2124 | |
2125 static GList * | |
2126 generate_invite_user_names(struct gaim_connection *gc) | |
2127 { | |
2128 GSList *grp; | |
2129 GSList *bl; | |
2130 struct group *g; | |
2131 struct buddy *buddy; | |
2132 static GList *tmp = NULL; | |
2133 | |
2134 if (tmp) | |
2135 g_list_free(tmp); | |
2136 | |
2137 tmp = g_list_append(NULL, ""); | |
2138 | |
2139 if (gc != NULL) { | |
2140 for (grp = groups; grp != NULL; grp = grp->next) { | |
2141 g = (struct group *)grp->data; | |
2142 | |
2143 for (bl = g->members; bl != NULL; bl = bl->next) { | |
2144 buddy = (struct buddy *)bl->data; | |
2145 | |
2146 if (buddy->present) | |
2147 tmp = g_list_append(tmp, buddy->name); | |
2148 } | |
2149 } | |
2150 } | |
2151 | |
2152 return tmp; | |
2153 } | |
2154 | |
2155 static void | |
2156 add_chat_buddy_common(struct gaim_conversation *conv, const char *name, | |
2157 int pos) | |
2158 { | |
2159 struct gaim_gtk_conversation *gtkconv; | |
2160 struct gaim_gtk_chat_pane *gtkchat; | |
2161 struct gaim_chat *chat; | |
2162 GtkTreeIter iter; | |
2163 GtkListStore *ls; | |
2164 | |
2165 chat = GAIM_CHAT(conv); | |
2166 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
2167 gtkchat = gtkconv->u.chat; | |
2168 | |
2169 ls = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list))); | |
2170 | |
2171 gtk_list_store_append(ls, &iter); | |
2172 gtk_list_store_set(ls, &iter, 0, | |
2173 (gaim_chat_is_user_ignored(chat, name) ? "X" : " "), | |
2174 1, name, -1); | |
2175 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(ls), 1, | |
2176 GTK_SORT_ASCENDING); | |
2177 } | |
2178 | |
2179 static void | |
2180 tab_complete(struct gaim_conversation *conv) | |
2181 { | |
2182 struct gaim_gtk_conversation *gtkconv; | |
2183 struct gaim_chat *chat; | |
2184 GtkTextIter cursor, word_start, start_buffer; | |
2185 int start; | |
2186 int most_matched = -1; | |
2187 char *entered, *partial = NULL; | |
2188 char *text; | |
2189 GList *matches = NULL; | |
2190 GList *nicks = NULL; | |
2191 | |
2192 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
2193 chat = GAIM_CHAT(conv); | |
2194 | |
2195 gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, &start_buffer); | |
2196 gtk_text_buffer_get_iter_at_mark(gtkconv->entry_buffer, &cursor, | |
2197 gtk_text_buffer_get_insert(gtkconv->entry_buffer)); | |
2198 | |
2199 word_start = cursor; | |
2200 | |
2201 /* if there's nothing there just return */ | |
2202 if (!gtk_text_iter_compare(&cursor, &start_buffer)) | |
2203 return; | |
2204 | |
2205 text = gtk_text_buffer_get_text(gtkconv->entry_buffer, &start_buffer, | |
2206 &cursor, FALSE); | |
2207 | |
2208 /* if we're at the end of ": " we need to move back 2 spaces */ | |
2209 start = strlen(text) - 1; | |
2210 | |
2211 if (strlen(text) >= 2 && !strncmp(&text[start-1], ": ", 2)) | |
2212 gtk_text_iter_backward_chars(&word_start, 2); | |
2213 | |
2214 /* find the start of the word that we're tabbing */ | |
2215 while (start >= 0 && text[start] != ' ') { | |
2216 gtk_text_iter_backward_char(&word_start); | |
2217 start--; | |
2218 } | |
2219 | |
2220 g_free(text); | |
2221 | |
2222 entered = gtk_text_buffer_get_text(gtkconv->entry_buffer, &word_start, | |
2223 &cursor, FALSE); | |
2224 | |
2225 if (chat_options & OPT_CHAT_OLD_STYLE_TAB) { | |
2226 if (strlen(entered) >= 2 && | |
2227 !strncmp(": ", entered + strlen(entered) - 2, 2)) { | |
2228 | |
2229 entered[strlen(entered) - 2] = 0; | |
2230 } | |
2231 } | |
2232 | |
2233 if (!strlen(entered)) { | |
2234 g_free(entered); | |
2235 return; | |
2236 } | |
2237 | |
2238 for (nicks = gaim_chat_get_users(chat); | |
2239 nicks != NULL; | |
2240 nicks = nicks->next) { | |
2241 | |
2242 char *nick = nicks->data; | |
2243 /* this checks to see if the current nick could be a completion */ | |
2244 if (g_strncasecmp(nick, entered, strlen(entered))) { | |
2245 if (nick[0] != '+' && nick[0] != '@') | |
2246 continue; | |
2247 | |
2248 if (g_strncasecmp(nick + 1, entered, strlen(entered))) { | |
2249 if (nick[0] != '@' || nick[1] != '+') | |
2250 continue; | |
2251 | |
2252 if (g_strncasecmp(nick + 2, entered, strlen(entered))) | |
2253 continue; | |
2254 else | |
2255 nick += 2; | |
2256 } | |
2257 else | |
2258 nick++; | |
2259 } | |
2260 | |
2261 /* if we're here, it's a possible completion */ | |
2262 | |
2263 /* if we're doing old-style, just fill in the completion */ | |
2264 if (chat_options & OPT_CHAT_OLD_STYLE_TAB) { | |
2265 gtk_text_buffer_delete(gtkconv->entry_buffer, | |
2266 &word_start, &cursor); | |
2267 | |
2268 if (strlen(nick) == strlen(entered)) { | |
2269 nicks = (nicks->next | |
2270 ? nicks->next | |
2271 : gaim_chat_get_users(chat)); | |
2272 | |
2273 nick = nicks->data; | |
2274 | |
2275 if (*nick == '@') nick++; | |
2276 if (*nick == '+') nick++; | |
2277 } | |
2278 | |
2279 gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, | |
2280 &start_buffer); | |
2281 gtk_text_buffer_get_iter_at_mark(gtkconv->entry_buffer, &cursor, | |
2282 gtk_text_buffer_get_insert(gtkconv->entry_buffer)); | |
2283 | |
2284 if (!gtk_text_iter_compare(&cursor, &start_buffer)) { | |
2285 char *tmp = g_strdup_printf("%s: ", nick); | |
2286 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, | |
2287 tmp, -1); | |
2288 g_free(tmp); | |
2289 } | |
2290 else | |
2291 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, | |
2292 nick, -1); | |
2293 | |
2294 g_free(entered); | |
2295 | |
2296 return; | |
2297 } | |
2298 | |
2299 /* we're only here if we're doing new style */ | |
2300 if (most_matched == -1) { | |
2301 /* | |
2302 * this will only get called once, since from now | |
2303 * on most_matched is >= 0 | |
2304 */ | |
2305 most_matched = strlen(nick); | |
2306 partial = g_strdup(nick); | |
2307 } | |
2308 else if (most_matched) { | |
2309 while (g_strncasecmp(nick, partial, most_matched)) | |
2310 most_matched--; | |
2311 | |
2312 partial[most_matched] = 0; | |
2313 } | |
2314 | |
2315 matches = g_list_append(matches, nick); | |
2316 } | |
2317 | |
2318 /* we're only here if we're doing new style */ | |
2319 | |
2320 /* if there weren't any matches, return */ | |
2321 if (!matches) { | |
2322 /* if matches isn't set partials won't be either */ | |
2323 g_free(entered); | |
2324 return; | |
2325 } | |
2326 | |
2327 gtk_text_buffer_delete(gtkconv->entry_buffer, &word_start, &cursor); | |
2328 | |
2329 if (!matches->next) { | |
2330 /* there was only one match. fill it in. */ | |
2331 gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, &start_buffer); | |
2332 gtk_text_buffer_get_iter_at_mark(gtkconv->entry_buffer, &cursor, | |
2333 gtk_text_buffer_get_insert(gtkconv->entry_buffer)); | |
2334 | |
2335 if (!gtk_text_iter_compare(&cursor, &start_buffer)) { | |
2336 char *tmp = g_strdup_printf("%s: ", (char *)matches->data); | |
2337 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, tmp, -1); | |
2338 g_free(tmp); | |
2339 } | |
2340 else | |
2341 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, | |
2342 matches->data, -1); | |
2343 | |
2344 matches = g_list_remove(matches, matches->data); | |
2345 } | |
2346 else { | |
2347 /* | |
2348 * there were lots of matches, fill in as much as possible | |
2349 * and display all of them | |
2350 */ | |
2351 char *addthis = g_malloc0(1); | |
2352 | |
2353 while (matches) { | |
2354 char *tmp = addthis; | |
2355 addthis = g_strconcat(tmp, matches->data, " ", NULL); | |
2356 g_free(tmp); | |
2357 matches = g_list_remove(matches, matches->data); | |
2358 } | |
2359 | |
2360 gaim_conversation_write(conv, NULL, addthis, -1, WFLAG_NOLOG, | |
2361 time(NULL)); | |
2362 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, partial, -1); | |
2363 g_free(addthis); | |
2364 } | |
2365 | |
2366 g_free(entered); | |
2367 g_free(partial); | |
2368 } | |
2369 | |
2370 static gboolean | |
2371 meify(char *message, size_t len) | |
2372 { | |
2373 /* | |
2374 * Read /me-ify: If the message (post-HTML) starts with /me, | |
2375 * remove the "/me " part of it (including that space) and return TRUE. | |
2376 */ | |
2377 char *c; | |
2378 gboolean inside_html = 0; | |
2379 | |
2380 if (message == NULL) | |
2381 return FALSE; /* Umm.. this would be very bad if this happens. */ | |
2382 | |
2383 if (len == -1) | |
2384 len = strlen(message); | |
2385 | |
2386 for (c = message; *c != '\0'; c++, len--) { | |
2387 if (inside_html) { | |
2388 if (*c == '>') | |
2389 inside_html = FALSE; | |
2390 } | |
2391 else { | |
2392 if (*c == '<') | |
2393 inside_html = TRUE; | |
2394 else | |
2395 break; | |
2396 } | |
2397 } | |
2398 | |
2399 if (*c != '\0' && !g_strncasecmp(c, "/me ", 4)) { | |
2400 memmove(c, c + 4, len - 3); | |
2401 | |
2402 return TRUE; | |
2403 } | |
2404 | |
2405 return FALSE; | |
2406 } | |
2407 | |
2408 static GtkItemFactoryEntry menu_items[] = | |
2409 { | |
2410 /* Conversation menu */ | |
2411 { "/_Conversation", NULL, NULL, 0, "<Branch>" }, | |
2412 { "/Conversation/_Save As...", NULL, menu_save_as_cb, 0, | |
2413 "<StockItem>", GTK_STOCK_SAVE_AS }, | |
2414 { "/Conversation/View _History...", NULL, menu_view_history_cb, 0, NULL }, | |
2415 { "/Conversation/sep1", NULL, NULL, 0, "<Separator>" }, | |
2416 { "/Conversation/Insert _URL...", NULL, menu_insert_link_cb, 0, | |
2417 "<StockItem>", GAIM_STOCK_LINK }, | |
2418 { "/Conversation/Insert _Image...", NULL, menu_insert_image_cb, 0, | |
2419 "<StockItem>", GAIM_STOCK_IMAGE }, | |
2420 { "/Conversation/sep2", NULL, NULL, 0, "<Separator>" }, | |
2421 { "/Conversation/_Close", NULL, menu_close_conv_cb, 0, | |
2422 "<StockItem>", GTK_STOCK_CLOSE }, | |
2423 | |
2424 /* Options */ | |
2425 { "/_Options", NULL, NULL, 0, "<Branch>" }, | |
2426 { "/Options/Enable _Logging", NULL, menu_logging_cb, 0, "<CheckItem>" }, | |
2427 { "/Options/Enable _Sounds", NULL, menu_sounds_cb, 0, "<CheckItem>" }, | |
2428 }; | |
2429 | |
2430 static const int menu_item_count = | |
2431 sizeof(menu_items) / sizeof(*menu_items); | |
2432 | |
2433 static GtkWidget * | |
2434 setup_menubar(struct gaim_window *win) | |
2435 { | |
2436 struct gaim_gtk_window *gtkwin; | |
2437 GtkWidget *hb; | |
2438 GtkItemFactory *item_factory; | |
2439 | |
2440 gtkwin = GAIM_GTK_WINDOW(win); | |
2441 | |
2442 /* Create the handle box. */ | |
2443 hb = gtk_handle_box_new(); | |
2444 | |
2445 item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", NULL); | |
2446 | |
2447 gtk_item_factory_create_items(item_factory, menu_item_count, | |
2448 menu_items, win); | |
2449 | |
2450 gtkwin->menu.menubar = gtk_item_factory_get_widget(item_factory, "<main>"); | |
2451 gtkwin->menu.view_history = gtk_item_factory_get_widget(item_factory, | |
2452 "/Conversation/View History..."); | |
2453 gtkwin->menu.insert_link = gtk_item_factory_get_widget(item_factory, | |
2454 "/Conversation/Insert URL..."); | |
2455 gtkwin->menu.insert_image = gtk_item_factory_get_widget(item_factory, | |
2456 "/Conversation/Insert Image..."); | |
2457 gtkwin->menu.logging = gtk_item_factory_get_widget(item_factory, | |
2458 "/Options/Enable Logging"); | |
2459 gtkwin->menu.sounds = gtk_item_factory_get_widget(item_factory, | |
2460 "/Options/Enable Sounds"); | |
2461 | |
4360
c435a29370b8
[gaim-migrate @ 4626]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
2462 generate_send_as_items(win, NULL); |
4359 | 2463 |
2464 gtk_container_add(GTK_CONTAINER(hb), gtkwin->menu.menubar); | |
2465 | |
2466 gtk_widget_show(gtkwin->menu.menubar); | |
2467 gtk_widget_show(hb); | |
2468 | |
2469 return hb; | |
2470 } | |
2471 | |
2472 static void | |
2473 setup_im_buttons(struct gaim_conversation *conv, GtkWidget *parent) | |
2474 { | |
2475 struct gaim_connection *gc; | |
2476 struct gaim_gtk_conversation *gtkconv; | |
2477 struct gaim_gtk_im_pane *gtkim; | |
2478 GaimConversationType type = GAIM_CONV_IM; | |
2479 | |
2480 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
2481 gtkim = gtkconv->u.im; | |
2482 gc = gaim_conversation_get_gc(conv); | |
2483 | |
2484 /* From right to left... */ | |
2485 | |
2486 /* Send button */ | |
2487 gtkconv->send = gaim_gtk_change_text(_("Send"), gtkconv->send, | |
2488 GAIM_STOCK_SEND, type); | |
2489 gtk_tooltips_set_tip(gtkconv->tooltips, gtkconv->send, _("Send"), NULL); | |
2490 | |
2491 gtk_box_pack_end(GTK_BOX(parent), gtkconv->send, FALSE, FALSE, 0); | |
2492 | |
2493 /* Separator */ | |
2494 if (gtkim->sep2 != NULL) | |
2495 gtk_widget_destroy(gtkim->sep2); | |
2496 | |
2497 gtkim->sep2 = gtk_vseparator_new(); | |
2498 gtk_box_pack_end(GTK_BOX(parent), gtkim->sep2, FALSE, TRUE, 0); | |
2499 gtk_widget_show(gtkim->sep2); | |
2500 | |
2501 /* Now, um, just kind of all over the place. Huh? */ | |
2502 | |
2503 /* Add button */ | |
2504 if (find_buddy(gaim_conversation_get_gc(conv)->user, | |
2505 gaim_conversation_get_name(conv)) == NULL) { | |
2506 gtkim->add = gaim_gtk_change_text(_("Add"), gtkim->add, | |
2507 GTK_STOCK_ADD, type); | |
2508 gtk_tooltips_set_tip(gtkconv->tooltips, gtkim->add, | |
2509 _("Add buddy"), NULL); | |
2510 } | |
2511 else { | |
2512 gtkim->add = gaim_gtk_change_text(_("Remove"), gtkim->add, | |
2513 GTK_STOCK_REMOVE, type); | |
2514 gtk_tooltips_set_tip(gtkconv->tooltips, gtkim->add, | |
2515 _("Remove buddy"), NULL); | |
2516 } | |
2517 | |
2518 gtk_box_pack_start(GTK_BOX(parent), gtkim->add, | |
2519 FALSE, FALSE, 0); | |
2520 | |
2521 /* Warn button */ | |
2522 gtkim->warn = gaim_gtk_change_text(_("Warn"), gtkim->warn, | |
2523 GAIM_STOCK_WARN, type); | |
2524 gtk_box_pack_start(GTK_BOX(parent), gtkim->warn, FALSE, FALSE, 0); | |
2525 | |
2526 /* Info button */ | |
2527 gtkconv->info = gaim_gtk_change_text(_("Info"), gtkconv->info, | |
2528 GAIM_STOCK_INFO, type); | |
2529 gtk_box_pack_start(GTK_BOX(parent), gtkconv->info, FALSE, FALSE, 0); | |
2530 gtk_tooltips_set_tip(gtkconv->tooltips, gtkconv->info, | |
2531 _("Get user information"), NULL); | |
2532 | |
2533 /* Block button */ | |
2534 gtkim->block = gaim_gtk_change_text(_("Block"), gtkim->block, | |
2535 GAIM_STOCK_BLOCK, type); | |
2536 gtk_box_pack_start(GTK_BOX(parent), gtkim->block, FALSE, FALSE, 0); | |
2537 gtk_tooltips_set_tip(gtkconv->tooltips, gtkim->block, | |
2538 _("Block user"), NULL); | |
2539 | |
2540 gtk_button_set_relief(GTK_BUTTON(gtkconv->info), GTK_RELIEF_NONE); | |
2541 gtk_button_set_relief(GTK_BUTTON(gtkim->add), GTK_RELIEF_NONE); | |
2542 gtk_button_set_relief(GTK_BUTTON(gtkim->warn), GTK_RELIEF_NONE); | |
2543 gtk_button_set_relief(GTK_BUTTON(gtkconv->send), GTK_RELIEF_NONE); | |
2544 gtk_button_set_relief(GTK_BUTTON(gtkim->block), GTK_RELIEF_NONE); | |
2545 | |
2546 gtk_size_group_add_widget(gtkconv->sg, gtkconv->info); | |
2547 gtk_size_group_add_widget(gtkconv->sg, gtkim->add); | |
2548 gtk_size_group_add_widget(gtkconv->sg, gtkim->warn); | |
2549 gtk_size_group_add_widget(gtkconv->sg, gtkconv->send); | |
2550 gtk_size_group_add_widget(gtkconv->sg, gtkim->block); | |
2551 | |
2552 gtk_box_reorder_child(GTK_BOX(parent), gtkim->warn, 1); | |
2553 gtk_box_reorder_child(GTK_BOX(parent), gtkim->block, 2); | |
2554 gtk_box_reorder_child(GTK_BOX(parent), gtkconv->info, 4); | |
2555 | |
2556 gaim_gtkconv_update_buttons_by_protocol(conv); | |
2557 | |
2558 g_signal_connect(G_OBJECT(gtkconv->send), "clicked", | |
2559 G_CALLBACK(send_cb), conv); | |
2560 g_signal_connect(G_OBJECT(gtkconv->info), "clicked", | |
2561 G_CALLBACK(info_cb), conv); | |
2562 g_signal_connect(G_OBJECT(gtkim->warn), "clicked", | |
2563 G_CALLBACK(warn_cb), conv); | |
2564 g_signal_connect(G_OBJECT(gtkim->block), "clicked", | |
2565 G_CALLBACK(block_cb), conv); | |
2566 } | |
2567 | |
2568 static void | |
2569 setup_chat_buttons(struct gaim_conversation *conv, GtkWidget *parent) | |
2570 { | |
2571 struct gaim_connection *gc; | |
2572 struct gaim_gtk_conversation *gtkconv; | |
2573 struct gaim_gtk_chat_pane *gtkchat; | |
2574 struct gaim_gtk_window *gtkwin; | |
2575 GtkWidget *sep; | |
2576 | |
2577 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
2578 gtkchat = gtkconv->u.chat; | |
2579 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(conv)); | |
2580 gc = gaim_conversation_get_gc(conv); | |
2581 | |
2582 /* Send button */ | |
2583 gtkconv->send = gaim_gtk_change_text(_("Send"), gtkconv->send, | |
2584 GAIM_STOCK_SEND, GAIM_CONV_CHAT); | |
2585 gtk_tooltips_set_tip(gtkconv->tooltips, gtkconv->send, _("Send"), NULL); | |
2586 | |
2587 gtk_box_pack_end(GTK_BOX(parent), gtkconv->send, FALSE, FALSE, 0); | |
2588 | |
2589 /* Separator */ | |
2590 sep = gtk_vseparator_new(); | |
2591 gtk_box_pack_end(GTK_BOX(parent), sep, FALSE, TRUE, 0); | |
2592 gtk_widget_show(sep); | |
2593 | |
2594 /* Invite */ | |
2595 gtkchat->invite = gaim_gtk_change_text(_("Invite"), gtkchat->invite, | |
2596 GAIM_STOCK_INVITE, GAIM_CONV_CHAT); | |
2597 gtk_tooltips_set_tip(gtkconv->tooltips, gtkchat->invite, | |
2598 _("Invite a user"), NULL); | |
2599 gtk_box_pack_end(GTK_BOX(parent), gtkchat->invite, FALSE, FALSE, 0); | |
2600 | |
2601 /* Set the relief on these. */ | |
2602 gtk_button_set_relief(GTK_BUTTON(gtkchat->invite), GTK_RELIEF_NONE); | |
2603 gtk_button_set_relief(GTK_BUTTON(gtkconv->send), GTK_RELIEF_NONE); | |
2604 | |
2605 /* Callbacks */ | |
2606 g_signal_connect(G_OBJECT(gtkconv->send), "clicked", | |
2607 G_CALLBACK(send_cb), conv); | |
2608 g_signal_connect(G_OBJECT(gtkchat->invite), "clicked", | |
2609 G_CALLBACK(invite_cb), conv); | |
2610 } | |
2611 | |
2612 static GtkWidget * | |
2613 build_conv_toolbar(struct gaim_conversation *conv) | |
2614 { | |
2615 struct gaim_gtk_conversation *gtkconv; | |
2616 GtkWidget *vbox; | |
2617 GtkWidget *hbox; | |
2618 GtkWidget *button; | |
2619 GtkWidget *sep; | |
2620 GtkSizeGroup *sg; | |
2621 | |
2622 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
2623 | |
2624 sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); | |
2625 | |
2626 vbox = gtk_vbox_new(FALSE, 0); | |
2627 sep = gtk_hseparator_new(); | |
2628 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
2629 | |
2630 hbox = gtk_hbox_new(FALSE, 5); | |
2631 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
2632 | |
2633 /* Bold */ | |
2634 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_BOLD); | |
2635 gtk_size_group_add_widget(sg, button); | |
2636 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
2637 gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Bold"), NULL); | |
2638 | |
2639 g_signal_connect(G_OBJECT(button), "clicked", | |
2640 G_CALLBACK(do_bold), gtkconv); | |
2641 | |
2642 gtkconv->toolbar.bold = button; | |
2643 | |
2644 /* Italic */ | |
2645 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_ITALIC); | |
2646 gtk_size_group_add_widget(sg, button); | |
2647 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
2648 gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Italic"), NULL); | |
2649 | |
2650 g_signal_connect(G_OBJECT(button), "clicked", | |
2651 G_CALLBACK(do_italic), gtkconv); | |
2652 | |
2653 gtkconv->toolbar.italic = button; | |
2654 | |
2655 /* Underline */ | |
2656 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_UNDERLINE); | |
2657 gtk_size_group_add_widget(sg, button); | |
2658 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
2659 gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Underline"), NULL); | |
2660 | |
2661 g_signal_connect(G_OBJECT(button), "clicked", | |
2662 G_CALLBACK(do_underline), gtkconv); | |
2663 | |
2664 gtkconv->toolbar.underline = button; | |
2665 | |
2666 /* Sep */ | |
2667 sep = gtk_vseparator_new(); | |
2668 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
2669 | |
2670 /* Increase font size */ | |
2671 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_BIGGER); | |
2672 gtk_size_group_add_widget(sg, button); | |
2673 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
2674 gtk_tooltips_set_tip(gtkconv->tooltips, button, | |
2675 _("Larger font size"), NULL); | |
2676 | |
2677 g_signal_connect(G_OBJECT(button), "clicked", | |
2678 G_CALLBACK(do_big), gtkconv); | |
2679 | |
2680 /* Normal font size */ | |
2681 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_NORMAL); | |
2682 gtk_size_group_add_widget(sg, button); | |
2683 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
2684 gtk_tooltips_set_tip(gtkconv->tooltips, button, | |
2685 _("Normal font size"), NULL); | |
2686 | |
2687 g_signal_connect(G_OBJECT(button), "clicked", | |
2688 G_CALLBACK(do_normal), gtkconv); | |
2689 | |
2690 gtkconv->toolbar.normal_size = button; | |
2691 | |
2692 /* Decrease font size */ | |
2693 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_SMALLER); | |
2694 gtk_size_group_add_widget(sg, button); | |
2695 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
2696 gtk_tooltips_set_tip(gtkconv->tooltips, button, | |
2697 _("Smaller font size"), NULL); | |
2698 | |
2699 g_signal_connect(G_OBJECT(button), "clicked", | |
2700 G_CALLBACK(do_small), gtkconv); | |
2701 | |
2702 /* Sep */ | |
2703 sep = gtk_vseparator_new(); | |
2704 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
2705 | |
2706 /* Foreground Color */ | |
2707 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_FGCOLOR); | |
2708 gtk_size_group_add_widget(sg, button); | |
2709 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
2710 gtk_tooltips_set_tip(gtkconv->tooltips, button, | |
2711 _("Foreground font color"), NULL); | |
2712 | |
2713 g_signal_connect(G_OBJECT(button), "clicked", | |
2714 G_CALLBACK(toggle_fg_color), conv); | |
2715 | |
2716 gtkconv->toolbar.fgcolor = button; | |
2717 | |
2718 /* Background Color */ | |
2719 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_BGCOLOR); | |
2720 gtk_size_group_add_widget(sg, button); | |
2721 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
2722 gtk_tooltips_set_tip(gtkconv->tooltips, button, | |
2723 _("Background color"), NULL); | |
2724 | |
2725 g_signal_connect(G_OBJECT(button), "clicked", | |
2726 G_CALLBACK(toggle_bg_color), conv); | |
2727 | |
2728 gtkconv->toolbar.bgcolor = button; | |
2729 | |
2730 /* Sep */ | |
2731 sep = gtk_vseparator_new(); | |
2732 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
2733 | |
2734 /* Insert IM Image */ | |
2735 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_IMAGE); | |
2736 gtk_size_group_add_widget(sg, button); | |
2737 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
2738 gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Insert image"), NULL); | |
2739 | |
2740 g_signal_connect(G_OBJECT(button), "clicked", | |
2741 G_CALLBACK(insert_image_cb), conv); | |
2742 | |
2743 gtkconv->toolbar.image = button; | |
2744 | |
2745 /* Insert Link */ | |
2746 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_LINK); | |
2747 gtk_size_group_add_widget(sg, button); | |
2748 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
2749 gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Insert link"), NULL); | |
2750 | |
2751 g_signal_connect(G_OBJECT(button), "clicked", | |
2752 G_CALLBACK(insert_link_cb), conv); | |
2753 | |
2754 gtkconv->toolbar.link = button; | |
2755 | |
2756 /* Insert Smiley */ | |
2757 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_SMILEY); | |
2758 gtk_size_group_add_widget(sg, button); | |
2759 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
2760 gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Insert smiley"), NULL); | |
2761 | |
2762 g_signal_connect(G_OBJECT(button), "clicked", | |
2763 G_CALLBACK(insert_smiley_cb), conv); | |
2764 | |
2765 gtkconv->toolbar.smiley = button; | |
2766 | |
2767 | |
2768 sep = gtk_hseparator_new(); | |
2769 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
2770 | |
2771 gtk_widget_show_all(vbox); | |
2772 | |
2773 return vbox; | |
2774 } | |
2775 | |
2776 static GtkWidget * | |
2777 setup_chat_pane(struct gaim_conversation *conv) | |
2778 { | |
2779 struct gaim_gtk_conversation *gtkconv; | |
2780 struct gaim_gtk_chat_pane *gtkchat; | |
2781 struct gaim_connection *gc; | |
2782 GtkWidget *vpaned, *hpaned; | |
2783 GtkWidget *vbox, *hbox; | |
2784 GtkWidget *lbox, *bbox; | |
2785 GtkWidget *label; | |
2786 GtkWidget *sw2; | |
2787 GtkWidget *list; | |
2788 GtkWidget *button; | |
2789 GtkWidget *frame; | |
2790 GtkListStore *ls; | |
2791 GtkCellRenderer *rend; | |
2792 GtkTreeViewColumn *col; | |
2793 | |
2794 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
2795 gtkchat = gtkconv->u.chat; | |
2796 gc = gaim_conversation_get_gc(conv); | |
2797 | |
2798 /* Setup the outer pane. */ | |
2799 vpaned = gtk_vpaned_new(); | |
2800 gtk_paned_set_gutter_size(GTK_PANED(vpaned), 15); | |
2801 gtk_widget_show(vpaned); | |
2802 | |
2803 /* Setup the top part of the pane. */ | |
2804 vbox = gtk_vbox_new(FALSE, 5); | |
2805 gtk_paned_pack1(GTK_PANED(vpaned), vbox, TRUE, FALSE); | |
2806 gtk_widget_show(vbox); | |
2807 | |
2808 if (gc->prpl->options & OPT_PROTO_CHAT_TOPIC) | |
2809 { | |
2810 hbox = gtk_hbox_new(FALSE, 0); | |
2811 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
2812 gtk_widget_show(hbox); | |
2813 | |
2814 label = gtk_label_new(_("Topic:")); | |
2815 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); | |
2816 gtk_widget_show(label); | |
2817 | |
2818 gtkchat->topic_text = gtk_entry_new(); | |
2819 gtk_entry_set_editable(GTK_ENTRY(gtkchat->topic_text), FALSE); | |
2820 gtk_box_pack_start(GTK_BOX(hbox), gtkchat->topic_text, TRUE, TRUE, 5); | |
2821 gtk_widget_show(gtkchat->topic_text); | |
2822 } | |
2823 | |
2824 /* Setup the horizontal pane. */ | |
2825 hpaned = gtk_hpaned_new(); | |
2826 gtk_paned_set_gutter_size(GTK_PANED(hpaned), 15); | |
2827 gtk_box_pack_start(GTK_BOX(vbox), hpaned, TRUE, TRUE, 5); | |
2828 gtk_widget_show(hpaned); | |
2829 | |
2830 /* Setup the scrolled window to put gtkimhtml in. */ | |
2831 gtkconv->sw = gtk_scrolled_window_new(NULL, NULL); | |
2832 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkconv->sw), | |
2833 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); | |
2834 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(gtkconv->sw), | |
2835 GTK_SHADOW_IN); | |
2836 gtk_paned_pack1(GTK_PANED(hpaned), gtkconv->sw, TRUE, TRUE); | |
2837 | |
2838 gtk_widget_set_size_request(gtkconv->sw, | |
2839 buddy_chat_size.width, buddy_chat_size.height); | |
2840 gtk_widget_show(gtkconv->sw); | |
2841 | |
2842 /* Setup gtkihmtml. */ | |
2843 gtkconv->imhtml = gtk_imhtml_new(NULL, NULL); | |
2844 gtk_container_add(GTK_CONTAINER(gtkconv->sw), gtkconv->imhtml); | |
2845 | |
2846 gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), | |
2847 (convo_options & OPT_CONVO_SHOW_TIME)); | |
2848 | |
2849 g_signal_connect_after(G_OBJECT(gtkconv->imhtml), "button_press_event", | |
2850 G_CALLBACK(entry_stop_rclick_cb), NULL); | |
2851 | |
2852 gaim_setup_imhtml(gtkconv->imhtml); | |
2853 | |
2854 gtk_widget_show(gtkconv->imhtml); | |
2855 | |
2856 /* Build the right pane. */ | |
2857 lbox = gtk_vbox_new(FALSE, 5); | |
2858 gtk_paned_pack2(GTK_PANED(hpaned), lbox, TRUE, TRUE); | |
2859 gtk_widget_show(lbox); | |
2860 | |
2861 /* Setup the label telling how many people are in the room. */ | |
2862 gtkchat->count = gtk_label_new(_("0 people in room")); | |
2863 gtk_box_pack_start(GTK_BOX(lbox), gtkchat->count, FALSE, FALSE, 0); | |
2864 gtk_widget_show(gtkchat->count); | |
2865 | |
2866 /* Setup the list of users. */ | |
2867 sw2 = gtk_scrolled_window_new(NULL, NULL); | |
2868 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw2), | |
2869 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); | |
2870 gtk_box_pack_start(GTK_BOX(lbox), sw2, TRUE, TRUE, 0); | |
2871 gtk_widget_show(sw2); | |
2872 | |
2873 ls = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); | |
2874 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(ls), 1, | |
2875 GTK_SORT_ASCENDING); | |
2876 | |
2877 list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ls)); | |
2878 | |
2879 rend = gtk_cell_renderer_text_new(); | |
2880 col = gtk_tree_view_column_new_with_attributes(NULL, rend, | |
2881 "text", 0, NULL); | |
2882 gtk_tree_view_column_set_clickable(GTK_TREE_VIEW_COLUMN(col), TRUE); | |
2883 | |
2884 g_signal_connect(G_OBJECT(list), "button_press_event", | |
2885 G_CALLBACK(right_click_chat_cb), conv); | |
2886 | |
2887 gtk_tree_view_append_column(GTK_TREE_VIEW(list), col); | |
2888 | |
2889 col = gtk_tree_view_column_new_with_attributes(NULL, rend, | |
2890 "text", 1, NULL); | |
2891 gtk_tree_view_column_set_clickable(GTK_TREE_VIEW_COLUMN(col), TRUE); | |
2892 | |
2893 #if 0 | |
2894 g_signal_connect(G_OBJECT(list), "button_press_event", | |
2895 G_CALLBACK(right_click_chat), conv); | |
2896 #endif | |
2897 | |
2898 gtk_tree_view_append_column(GTK_TREE_VIEW(list), col); | |
2899 | |
2900 gtk_widget_set_size_request(list, 150, -1); | |
2901 | |
2902 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list), FALSE); | |
2903 gtk_widget_show(list); | |
2904 | |
2905 gtkchat->list = list; | |
2906 | |
2907 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw2), list); | |
2908 | |
2909 /* Setup the user list toolbar. */ | |
2910 bbox = gtk_hbox_new(TRUE, 5); | |
2911 gtk_box_pack_start(GTK_BOX(lbox), bbox, FALSE, FALSE, 0); | |
2912 gtk_widget_show(bbox); | |
2913 | |
2914 /* IM */ | |
2915 button = gaim_pixbuf_button_from_stock(NULL, GTK_STOCK_REDO, | |
2916 GAIM_BUTTON_VERTICAL); | |
2917 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
2918 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
2919 gtk_tooltips_set_tip(gtkconv->tooltips, button, _("IM"), NULL); | |
2920 g_signal_connect(G_OBJECT(button), "clicked", | |
2921 G_CALLBACK(im_cb), conv); | |
2922 | |
2923 gtk_widget_show(button); | |
2924 | |
2925 /* Ignore */ | |
2926 button = gaim_pixbuf_button_from_stock(NULL, GAIM_STOCK_IGNORE, | |
2927 GAIM_BUTTON_VERTICAL); | |
2928 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
2929 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
2930 gtk_tooltips_set_tip(gtkconv->tooltips, button, _("Ignore user"), NULL); | |
2931 g_signal_connect(G_OBJECT(button), "clicked", | |
2932 G_CALLBACK(ignore_cb), conv); | |
2933 gtk_widget_show(button); | |
2934 | |
2935 /* Info */ | |
2936 button = gaim_pixbuf_button_from_stock(NULL, GAIM_STOCK_INFO, | |
2937 GAIM_BUTTON_VERTICAL); | |
2938 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
2939 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
2940 gtk_tooltips_set_tip(gtkconv->tooltips, button, | |
2941 _("Get user information"), NULL); | |
2942 g_signal_connect(G_OBJECT(button), "clicked", | |
2943 G_CALLBACK(info_cb), conv); | |
2944 | |
2945 gtk_widget_show(button); | |
2946 | |
2947 gtkconv->info = button; | |
2948 | |
2949 /* Build the toolbar. */ | |
2950 vbox = gtk_vbox_new(FALSE, 5); | |
2951 gtk_paned_pack2(GTK_PANED(vpaned), vbox, TRUE, FALSE); | |
2952 gtk_widget_show(vbox); | |
2953 | |
2954 gtkconv->toolbar.toolbar = build_conv_toolbar(conv); | |
2955 gtk_box_pack_start(GTK_BOX(vbox), gtkconv->toolbar.toolbar, | |
2956 FALSE, FALSE, 0); | |
2957 | |
2958 /* Setup the entry widget. */ | |
2959 frame = gtk_frame_new(NULL); | |
2960 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); | |
2961 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); | |
2962 gtk_widget_show(frame); | |
2963 | |
2964 gtkconv->entry_buffer = gtk_text_buffer_new(NULL); | |
2965 g_object_set_data(G_OBJECT(gtkconv->entry_buffer), "user_data", conv); | |
2966 gtkconv->entry = gtk_text_view_new_with_buffer(gtkconv->entry_buffer); | |
2967 | |
2968 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(gtkconv->entry), GTK_WRAP_WORD); | |
2969 gtk_widget_set_size_request(gtkconv->entry, buddy_chat_size.width, | |
2970 MAX(buddy_chat_size.entry_height, 25)); | |
2971 | |
2972 /* Connect the signal handlers. */ | |
2973 g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "key_press_event", | |
2974 G_CALLBACK(entry_key_pressed_cb_1), | |
2975 gtkconv->entry_buffer); | |
2976 g_signal_connect_after(G_OBJECT(gtkconv->entry), "button_press_event", | |
2977 G_CALLBACK(entry_stop_rclick_cb), NULL); | |
2978 g_signal_connect(G_OBJECT(gtkconv->entry), "key_press_event", | |
2979 G_CALLBACK(entry_key_pressed_cb_2), conv); | |
2980 | |
2981 #ifdef USE_GTKSPELL | |
2982 if (convo_options & OPT_CONVO_CHECK_SPELLING) | |
2983 gtkspell_new_attach(GTK_TEXT_VIEW(gtkconv->entry), NULL, NULL); | |
2984 #endif | |
2985 | |
2986 gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(gtkconv->entry)); | |
2987 gtk_widget_show(gtkconv->entry); | |
2988 | |
2989 /* Setup the bottom button box. */ | |
2990 gtkconv->bbox = gtk_hbox_new(FALSE, 5); | |
2991 gtk_box_pack_start(GTK_BOX(vbox), gtkconv->bbox, FALSE, FALSE, 0); | |
2992 gtk_widget_show(gtkconv->bbox); | |
2993 | |
2994 setup_chat_buttons(conv, gtkconv->bbox); | |
2995 | |
2996 return vpaned; | |
2997 } | |
2998 | |
2999 static GtkWidget * | |
3000 setup_im_pane(struct gaim_conversation *conv) | |
3001 { | |
3002 struct gaim_gtk_conversation *gtkconv; | |
3003 struct gaim_gtk_im_pane *gtkim; | |
3004 GtkWidget *paned; | |
3005 GtkWidget *vbox; | |
3006 GtkWidget *vbox2; | |
3007 GtkWidget *frame; | |
3008 | |
3009 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
3010 gtkim = gtkconv->u.im; | |
3011 | |
3012 /* Setup the outer pane. */ | |
3013 paned = gtk_vpaned_new(); | |
3014 gtk_paned_set_gutter_size(GTK_PANED(paned), 15); | |
3015 gtk_widget_show(paned); | |
3016 | |
3017 /* Setup the top part of the pane. */ | |
3018 vbox = gtk_vbox_new(FALSE, 5); | |
3019 gtk_paned_pack1(GTK_PANED(paned), vbox, FALSE, TRUE); | |
3020 gtk_widget_show(vbox); | |
3021 | |
3022 /* Setup the gtkimhtml widget. */ | |
3023 gtkconv->sw = gtk_scrolled_window_new(NULL, NULL); | |
3024 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkconv->sw), | |
3025 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); | |
3026 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(gtkconv->sw), | |
3027 GTK_SHADOW_IN); | |
3028 gtk_box_pack_start(GTK_BOX(vbox), gtkconv->sw, TRUE, TRUE, 0); | |
3029 gtk_widget_set_size_request(gtkconv->sw, conv_size.width, conv_size.height); | |
3030 gtk_widget_show(gtkconv->sw); | |
3031 | |
3032 gtkconv->imhtml = gtk_imhtml_new(NULL, NULL); | |
3033 gtk_container_add(GTK_CONTAINER(gtkconv->sw), gtkconv->imhtml); | |
3034 | |
3035 g_signal_connect_after(G_OBJECT(gtkconv->imhtml), "button_press_event", | |
3036 G_CALLBACK(entry_stop_rclick_cb), NULL); | |
3037 | |
3038 gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), | |
3039 (convo_options & OPT_CONVO_SHOW_TIME)); | |
3040 | |
3041 gaim_setup_imhtml(gtkconv->imhtml); | |
3042 | |
3043 gtk_widget_show(gtkconv->imhtml); | |
3044 | |
3045 vbox2 = gtk_vbox_new(FALSE, 5); | |
3046 gtk_paned_pack2(GTK_PANED(paned), vbox2, FALSE, FALSE); | |
3047 gtk_widget_show(vbox2); | |
3048 | |
3049 /* Build the toolbar. */ | |
3050 gtkconv->toolbar.toolbar = build_conv_toolbar(conv); | |
3051 gtk_box_pack_start(GTK_BOX(vbox2), gtkconv->toolbar.toolbar, | |
3052 FALSE, FALSE, 0); | |
3053 | |
3054 /* Setup the entry widget. */ | |
3055 frame = gtk_frame_new(NULL); | |
3056 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); | |
3057 gtk_box_pack_start(GTK_BOX(vbox2), frame, TRUE, TRUE, 0); | |
3058 gtk_widget_show(frame); | |
3059 | |
3060 gtkconv->entry_buffer = gtk_text_buffer_new(NULL); | |
3061 g_object_set_data(G_OBJECT(gtkconv->entry_buffer), "user_data", conv); | |
3062 gtkconv->entry = gtk_text_view_new_with_buffer(gtkconv->entry_buffer); | |
3063 | |
3064 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(gtkconv->entry), GTK_WRAP_WORD); | |
3065 gtk_widget_set_size_request(gtkconv->entry, conv_size.width - 20, | |
3066 MAX(conv_size.entry_height, 25)); | |
3067 | |
3068 /* Connect the signal handlers. */ | |
3069 g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "key_press_event", | |
3070 G_CALLBACK(entry_key_pressed_cb_1), | |
3071 gtkconv->entry_buffer); | |
3072 g_signal_connect(G_OBJECT(gtkconv->entry), "key_press_event", | |
3073 G_CALLBACK(entry_key_pressed_cb_2), conv); | |
3074 g_signal_connect_after(G_OBJECT(gtkconv->entry), "button_press_event", | |
3075 G_CALLBACK(entry_stop_rclick_cb), NULL); | |
3076 | |
3077 g_signal_connect(G_OBJECT(gtkconv->entry_buffer), "insert_text", | |
3078 G_CALLBACK(insert_text_cb), conv); | |
3079 g_signal_connect(G_OBJECT(gtkconv->entry_buffer), "delete_range", | |
3080 G_CALLBACK(delete_text_cb), conv); | |
3081 | |
3082 #ifdef USE_GTKSPELL | |
3083 if (convo_options & OPT_CONVO_CHECK_SPELLING) | |
3084 gtkspell_new_attach(GTK_TEXT_VIEW(gtkconv->entry), NULL, NULL); | |
3085 #endif | |
3086 | |
3087 gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(gtkconv->entry)); | |
3088 gtk_widget_show(gtkconv->entry); | |
3089 | |
3090 gtkconv->bbox = gtk_hbox_new(FALSE, 5); | |
3091 gtk_box_pack_start(GTK_BOX(vbox2), gtkconv->bbox, FALSE, FALSE, 0); | |
3092 gtk_widget_show(gtkconv->bbox); | |
3093 | |
3094 setup_im_buttons(conv, gtkconv->bbox); | |
3095 | |
3096 return paned; | |
3097 } | |
3098 | |
3099 static void | |
3100 move_next_tab(struct gaim_conversation *conv) | |
3101 { | |
3102 struct gaim_conversation *next_conv = NULL; | |
3103 struct gaim_window *win; | |
3104 GList *l; | |
3105 int index, i; | |
3106 | |
3107 win = gaim_conversation_get_window(conv); | |
3108 index = gaim_conversation_get_index(conv); | |
3109 | |
3110 /* First check the tabs after this position. */ | |
3111 for (l = g_list_nth(gaim_window_get_conversations(win), index); | |
3112 l != NULL; | |
3113 l = l->next) { | |
3114 | |
3115 next_conv = (struct gaim_conversation *)l->data; | |
3116 | |
3117 if (gaim_conversation_get_unseen(next_conv) > 0) | |
3118 break; | |
3119 | |
3120 next_conv = NULL; | |
3121 } | |
3122 | |
3123 if (next_conv == NULL) { | |
3124 | |
3125 /* Now check before this position. */ | |
3126 for (l = gaim_window_get_conversations(win), i = 0; | |
3127 l != NULL && i < index; | |
3128 l = l->next) { | |
3129 | |
3130 next_conv = (struct gaim_conversation *)l->data; | |
3131 | |
3132 if (gaim_conversation_get_unseen(next_conv) > 0) | |
3133 break; | |
3134 | |
3135 next_conv = NULL; | |
3136 } | |
3137 | |
3138 if (next_conv == NULL) { | |
3139 /* Okay, just grab the next conversation tab. */ | |
3140 if (index == gaim_window_get_conversation_count(win) - 1) | |
3141 next_conv = gaim_window_get_conversation_at(win, 0); | |
3142 else | |
3143 next_conv = gaim_window_get_conversation_at(win, index + 1); | |
3144 } | |
3145 } | |
3146 | |
3147 if (next_conv != NULL && next_conv != conv) { | |
3148 gaim_window_switch_conversation(win, | |
3149 gaim_conversation_get_index(next_conv)); | |
3150 } | |
3151 } | |
3152 | |
3153 | |
3154 /************************************************************************** | |
3155 * GTK+ window ops | |
3156 **************************************************************************/ | |
3157 static struct gaim_conversation_ops * | |
3158 gaim_gtk_get_conversation_ops(void) | |
3159 { | |
3160 return gaim_get_gtk_conversation_ops(); | |
3161 } | |
3162 | |
3163 static void | |
3164 gaim_gtk_new_window(struct gaim_window *win) | |
3165 { | |
3166 struct gaim_gtk_window *gtkwin; | |
3167 GtkPositionType pos; | |
3168 GtkWidget *testidea; | |
3169 GtkWidget *menubar; | |
3170 | |
3171 gtkwin = g_malloc0(sizeof(struct gaim_gtk_window)); | |
3172 | |
3173 win->ui_data = gtkwin; | |
3174 | |
3175 /* Create the window. */ | |
3176 gtkwin->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
3177 gtk_window_set_role(GTK_WINDOW(gtkwin->window), "conversation"); | |
3178 gtk_window_set_policy(GTK_WINDOW(gtkwin->window), TRUE, TRUE, FALSE); | |
3179 gtk_container_border_width(GTK_CONTAINER(gtkwin->window), 0); | |
3180 gtk_widget_realize(gtkwin->window); | |
3181 gtk_window_set_title(GTK_WINDOW(gtkwin->window), _("Gaim - Conversations")); | |
3182 | |
3183 g_signal_connect(G_OBJECT(gtkwin->window), "delete_event", | |
3184 G_CALLBACK(close_win_cb), win); | |
3185 | |
3186 /* Create the notebook. */ | |
3187 gtkwin->notebook = gtk_notebook_new(); | |
3188 | |
3189 pos = ((im_options & OPT_IM_SIDE_TAB) | |
3190 ? ((im_options & OPT_IM_BR_TAB) ? GTK_POS_RIGHT : GTK_POS_LEFT) | |
3191 : ((im_options & OPT_IM_BR_TAB) ? GTK_POS_BOTTOM : GTK_POS_TOP)); | |
3192 | |
3193 #if 0 | |
3194 gtk_notebook_set_tab_hborder(GTK_NOTEBOOK(gtkwin->notebook), 0); | |
3195 gtk_notebook_set_tab_vborder(GTK_NOTEBOOK(gtkwin->notebook), 0); | |
3196 #endif | |
3197 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(gtkwin->notebook), pos); | |
3198 gtk_notebook_set_scrollable(GTK_NOTEBOOK(gtkwin->notebook), TRUE); | |
3199 gtk_notebook_popup_enable(GTK_NOTEBOOK(gtkwin->notebook)); | |
3200 gtk_widget_show(gtkwin->notebook); | |
3201 | |
3202 g_signal_connect_after(G_OBJECT(gtkwin->notebook), "switch_page", | |
3203 G_CALLBACK(switch_conv_cb), win); | |
3204 | |
3205 /* Setup the tab drag and drop signals. */ | |
3206 gtk_widget_add_events(gtkwin->notebook, | |
3207 GDK_BUTTON1_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK); | |
3208 g_signal_connect(G_OBJECT(gtkwin->notebook), "button_press_event", | |
3209 G_CALLBACK(notebook_press_cb), win); | |
3210 g_signal_connect(G_OBJECT(gtkwin->notebook), "button_release_event", | |
3211 G_CALLBACK(notebook_release_cb), win); | |
3212 | |
3213 testidea = gtk_vbox_new(FALSE, 0); | |
3214 | |
3215 /* Setup the menubar. */ | |
3216 menubar = setup_menubar(win); | |
3217 gtk_box_pack_start(GTK_BOX(testidea), menubar, FALSE, TRUE, 0); | |
3218 | |
3219 gtk_box_pack_start(GTK_BOX(testidea), gtkwin->notebook, TRUE, TRUE, 0); | |
3220 | |
3221 gtk_container_add(GTK_CONTAINER(gtkwin->window), testidea); | |
3222 | |
3223 gtk_widget_show(testidea); | |
3224 } | |
3225 | |
3226 static void | |
3227 gaim_gtk_destroy_window(struct gaim_window *win) | |
3228 { | |
3229 struct gaim_gtk_window *gtkwin = GAIM_GTK_WINDOW(win); | |
3230 | |
3231 gtk_widget_destroy(gtkwin->window); | |
3232 | |
3233 g_free(gtkwin); | |
3234 win->ui_data = NULL; | |
3235 } | |
3236 | |
3237 static void | |
3238 gaim_gtk_show(struct gaim_window *win) | |
3239 { | |
3240 struct gaim_gtk_window *gtkwin = GAIM_GTK_WINDOW(win); | |
3241 | |
3242 gtk_widget_show(gtkwin->window); | |
3243 } | |
3244 | |
3245 static void | |
3246 gaim_gtk_hide(struct gaim_window *win) | |
3247 { | |
3248 struct gaim_gtk_window *gtkwin = GAIM_GTK_WINDOW(win); | |
3249 | |
3250 gtk_widget_hide(gtkwin->window); | |
3251 } | |
3252 | |
3253 static void | |
3254 gaim_gtk_raise(struct gaim_window *win) | |
3255 { | |
3256 struct gaim_gtk_window *gtkwin = GAIM_GTK_WINDOW(win); | |
3257 | |
3258 gdk_window_raise(gtkwin->window->window); | |
3259 } | |
3260 | |
3261 static void | |
3262 gaim_gtk_flash(struct gaim_window *win) | |
3263 { | |
3264 #ifdef _WIN32 | |
3265 struct gaim_gtk_window *gtkwin = GAIM_GTK_WINDOW(win); | |
3266 | |
3267 wgaim_im_blink(gtkwin->window); | |
3268 #endif | |
3269 } | |
3270 | |
3271 static void | |
3272 gaim_gtk_switch_conversation(struct gaim_window *win, unsigned int index) | |
3273 { | |
3274 struct gaim_gtk_window *gtkwin; | |
3275 | |
3276 gtkwin = GAIM_GTK_WINDOW(win); | |
3277 | |
3278 gtk_notebook_set_current_page(GTK_NOTEBOOK(gtkwin->notebook), index); | |
3279 } | |
3280 | |
3281 static void | |
3282 gaim_gtk_add_conversation(struct gaim_window *win, | |
3283 struct gaim_conversation *conv) | |
3284 { | |
3285 struct gaim_gtk_window *gtkwin; | |
3286 struct gaim_gtk_conversation *gtkconv; | |
3287 GtkWidget *pane = NULL; | |
3288 GtkWidget *tab_cont; | |
3289 GtkWidget *tabby; | |
3290 gboolean new_ui; | |
3291 | |
3292 gtkwin = GAIM_GTK_WINDOW(win); | |
3293 | |
3294 if (conv->ui_data != NULL) { | |
3295 gtkconv = (struct gaim_gtk_conversation *)conv->ui_data; | |
3296 | |
3297 tab_cont = gtkconv->tab_cont; | |
3298 | |
3299 new_ui = FALSE; | |
3300 } | |
3301 else { | |
3302 gtkconv = g_malloc0(sizeof(struct gaim_gtk_conversation)); | |
3303 conv->ui_data = gtkconv; | |
3304 | |
3305 /* Setup some initial variables. */ | |
3306 gtkconv->sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
3307 gtkconv->tooltips = gtk_tooltips_new(); | |
3308 | |
3309 if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { | |
3310 gtkconv->u.chat = g_malloc0(sizeof(struct gaim_gtk_chat_pane)); | |
3311 | |
3312 pane = setup_chat_pane(conv); | |
3313 } | |
3314 else if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { | |
3315 gtkconv->u.im = g_malloc0(sizeof(struct gaim_gtk_im_pane)); | |
3316 gtkconv->u.im->a_virgin = TRUE; | |
3317 | |
3318 pane = setup_im_pane(conv); | |
3319 } | |
3320 | |
3321 if (pane == NULL) { | |
3322 if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { | |
3323 g_free(gtkconv->u.chat); | |
3324 } | |
3325 else if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { | |
3326 g_free(gtkconv->u.im); | |
3327 }; | |
3328 | |
3329 g_free(gtkconv); | |
3330 conv->ui_data = NULL; | |
3331 | |
3332 return; | |
3333 } | |
3334 | |
3335 /* Setup the container for the tab. */ | |
3336 gtkconv->tab_cont = tab_cont = gtk_vbox_new(FALSE, 5); | |
3337 gtk_container_set_border_width(GTK_CONTAINER(tab_cont), 5); | |
3338 gtk_container_add(GTK_CONTAINER(tab_cont), pane); | |
3339 gtk_widget_show(pane); | |
3340 | |
3341 new_ui = TRUE; | |
3342 | |
3343 gtkconv->make_sound = TRUE; | |
3344 } | |
3345 | |
3346 gtkconv->tabby = tabby = gtk_hbox_new(FALSE, 5); | |
3347 | |
3348 /* Close button. */ | |
3349 gtkconv->close = gtk_button_new(); | |
3350 gtk_widget_set_size_request(GTK_WIDGET(gtkconv->close), 16, 16); | |
3351 gtk_container_add(GTK_CONTAINER(gtkconv->close), | |
3352 gtk_image_new_from_stock(GTK_STOCK_CLOSE, | |
3353 GTK_ICON_SIZE_MENU)); | |
3354 gtk_button_set_relief(GTK_BUTTON(gtkconv->close), GTK_RELIEF_NONE); | |
3355 gtk_tooltips_set_tip(gtkconv->tooltips, gtkconv->close, | |
3356 _("Close conversation"), NULL); | |
3357 | |
3358 g_signal_connect(G_OBJECT(gtkconv->close), "clicked", | |
3359 G_CALLBACK(close_conv_cb), conv); | |
3360 | |
3361 /* Tab label. */ | |
3362 gtkconv->tab_label = gtk_label_new(gaim_conversation_get_title(conv)); | |
3363 #if 0 | |
3364 gtk_misc_set_alignment(GTK_MISC(gtkconv->tab_label), 0.00, 0.5); | |
3365 gtk_misc_set_padding(GTK_MISC(gtkconv->tab_label), 4, 0); | |
3366 #endif | |
3367 | |
3368 /* Pack it all together. */ | |
3369 gtk_box_pack_start(GTK_BOX(tabby), gtkconv->tab_label, TRUE, TRUE, 0); | |
3370 gtk_box_pack_start(GTK_BOX(tabby), gtkconv->close, FALSE, FALSE, 0); | |
3371 gtk_widget_show_all(tabby); | |
3372 | |
3373 | |
3374 /* Add this pane to the conversations notebook. */ | |
3375 gtk_notebook_append_page(GTK_NOTEBOOK(gtkwin->notebook), tab_cont, tabby); | |
3376 gtk_notebook_set_menu_label_text(GTK_NOTEBOOK(gtkwin->notebook), tab_cont, | |
3377 gaim_conversation_get_title(conv)); | |
3378 | |
3379 gtk_widget_show(tab_cont); | |
3380 | |
3381 /* Er, bug in notebooks? Switch to the page manually. */ | |
3382 if (gaim_window_get_conversation_count(win) == 1) | |
3383 gtk_notebook_set_current_page(GTK_NOTEBOOK(gtkwin->notebook), 0); | |
3384 | |
3385 debug_printf("*** Current page = %d\n", | |
3386 gtk_notebook_get_current_page(GTK_NOTEBOOK(gtkwin->notebook))); | |
3387 | |
3388 if ((gtk_notebook_get_current_page(GTK_NOTEBOOK(gtkwin->notebook)) == 0) || | |
3389 (conv == g_list_nth_data(gaim_window_get_conversations(win), 0))) { | |
3390 | |
3391 gtk_widget_grab_focus(gtkconv->entry); | |
3392 } | |
3393 | |
3394 gaim_gtkconv_update_buddy_icon(conv); | |
3395 | |
3396 if (!new_ui) | |
3397 g_object_unref(gtkconv->tab_cont); | |
3398 | |
3399 if (gaim_window_get_conversation_count(win) == 1) | |
3400 update_send_as_selection(win); | |
3401 } | |
3402 | |
3403 static void | |
3404 gaim_gtk_remove_conversation(struct gaim_window *win, | |
3405 struct gaim_conversation *conv) | |
3406 { | |
3407 struct gaim_gtk_window *gtkwin; | |
3408 struct gaim_gtk_conversation *gtkconv; | |
3409 unsigned int index; | |
3410 | |
3411 index = gaim_conversation_get_index(conv); | |
3412 | |
3413 gtkwin = GAIM_GTK_WINDOW(win); | |
3414 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
3415 | |
3416 g_object_ref(gtkconv->tab_cont); | |
3417 gtk_object_sink(GTK_OBJECT(gtkconv->tab_cont)); | |
3418 | |
3419 gaim_gtk_set_state_lock(TRUE); | |
3420 | |
3421 gtk_notebook_remove_page(GTK_NOTEBOOK(gtkwin->notebook), index); | |
3422 | |
3423 gaim_gtk_set_state_lock(FALSE); | |
3424 | |
3425 /* If this window is setup with an inactive gc, regenerate the menu. */ | |
3426 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM && | |
3427 gaim_conversation_get_gc(conv) == NULL) { | |
3428 | |
4360
c435a29370b8
[gaim-migrate @ 4626]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
3429 generate_send_as_items(win, conv); |
4359 | 3430 } |
3431 } | |
3432 | |
3433 static void | |
3434 gaim_gtk_move_conversation(struct gaim_window *win, | |
3435 struct gaim_conversation *conv, | |
3436 unsigned int new_index) | |
3437 { | |
3438 struct gaim_gtk_window *gtkwin; | |
3439 struct gaim_gtk_conversation *gtkconv; | |
3440 | |
3441 gtkwin = GAIM_GTK_WINDOW(win); | |
3442 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
3443 | |
3444 gtk_notebook_reorder_child(GTK_NOTEBOOK(gtkwin->notebook), | |
3445 gtkconv->tab_cont, new_index); | |
3446 } | |
3447 | |
3448 static int | |
3449 gaim_gtk_get_active_index(const struct gaim_window *win) | |
3450 { | |
3451 struct gaim_gtk_window *gtkwin; | |
3452 | |
3453 gtkwin = GAIM_GTK_WINDOW(win); | |
3454 | |
3455 return gtk_notebook_get_current_page(GTK_NOTEBOOK(gtkwin->notebook)); | |
3456 } | |
3457 | |
3458 static struct gaim_window_ops window_ops = | |
3459 { | |
3460 gaim_gtk_get_conversation_ops, | |
3461 gaim_gtk_new_window, | |
3462 gaim_gtk_destroy_window, | |
3463 gaim_gtk_show, | |
3464 gaim_gtk_hide, | |
3465 gaim_gtk_raise, | |
3466 gaim_gtk_flash, | |
3467 gaim_gtk_switch_conversation, | |
3468 gaim_gtk_add_conversation, | |
3469 gaim_gtk_remove_conversation, | |
3470 gaim_gtk_move_conversation, | |
3471 gaim_gtk_get_active_index | |
3472 }; | |
3473 | |
3474 static void | |
3475 update_convo_add_button(struct gaim_conversation *conv) | |
3476 { | |
3477 struct gaim_gtk_conversation *gtkconv; | |
3478 struct gaim_connection *gc; | |
3479 GaimConversationType type; | |
3480 GtkWidget *parent; | |
3481 gboolean rebuild = FALSE; | |
3482 | |
3483 type = gaim_conversation_get_type(conv); | |
3484 gc = gaim_conversation_get_gc(conv); | |
3485 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
3486 parent = gtk_widget_get_parent(gtkconv->u.im->add); | |
3487 | |
3488 if (find_buddy(gc->user, gaim_conversation_get_name(conv))) { | |
3489 if (!g_object_get_data(G_OBJECT(gtkconv->u.im->add), "user_data")) { | |
3490 gtkconv->u.im->add = | |
3491 gaim_gtk_change_text(_("Remove"), gtkconv->u.im->add, | |
3492 GTK_STOCK_REMOVE, type); | |
3493 | |
3494 rebuild = TRUE; | |
3495 } | |
3496 | |
3497 gtk_widget_set_sensitive(gtkconv->u.im->add, | |
3498 (gc != NULL && gc->prpl->remove_buddy != NULL)); | |
3499 | |
3500 g_object_set_data(G_OBJECT(gtkconv->u.im->add), "user_data", conv); | |
3501 | |
3502 } else { | |
3503 if (g_object_get_data(G_OBJECT(gtkconv->u.im->add), "user_data")) { | |
3504 gtkconv->u.im->add = | |
3505 gaim_gtk_change_text(_("Add"), gtkconv->u.im->add, | |
3506 GTK_STOCK_ADD, type); | |
3507 | |
3508 rebuild = TRUE; | |
3509 } | |
3510 | |
3511 gtk_widget_set_sensitive(gtkconv->u.im->add, | |
3512 (gc != NULL && gc->prpl->add_buddy != NULL)); | |
3513 } | |
3514 | |
3515 if (rebuild) { | |
3516 g_signal_connect(G_OBJECT(gtkconv->u.im->add), "clicked", | |
3517 G_CALLBACK(add_cb), conv); | |
3518 | |
3519 gtk_box_pack_start(GTK_BOX(parent), gtkconv->u.im->add, | |
3520 FALSE, FALSE, 0); | |
3521 gtk_box_reorder_child(GTK_BOX(parent), gtkconv->u.im->add, 3); | |
3522 gtk_button_set_relief(GTK_BUTTON(gtkconv->u.im->add), GTK_RELIEF_NONE); | |
3523 gtk_size_group_add_widget(gtkconv->sg, gtkconv->u.im->add); | |
3524 } | |
3525 } | |
3526 | |
3527 struct gaim_window_ops * | |
3528 gaim_get_gtk_window_ops(void) | |
3529 { | |
3530 return &window_ops; | |
3531 } | |
3532 | |
3533 /************************************************************************** | |
3534 * Conversation ops | |
3535 **************************************************************************/ | |
3536 static void | |
3537 gaim_gtkconv_destroy(struct gaim_conversation *conv) | |
3538 { | |
3539 struct gaim_gtk_conversation *gtkconv = GAIM_GTK_CONVERSATION(conv); | |
3540 | |
3541 if (gtkconv->dialogs.fg_color != NULL) | |
3542 gtk_widget_destroy(gtkconv->dialogs.fg_color); | |
3543 | |
3544 if (gtkconv->dialogs.bg_color != NULL) | |
3545 gtk_widget_destroy(gtkconv->dialogs.bg_color); | |
3546 | |
3547 if (gtkconv->dialogs.font != NULL) | |
3548 gtk_widget_destroy(gtkconv->dialogs.font); | |
3549 | |
3550 if (gtkconv->dialogs.smiley != NULL) | |
3551 gtk_widget_destroy(gtkconv->dialogs.smiley); | |
3552 | |
3553 if (gtkconv->dialogs.link != NULL) | |
3554 gtk_widget_destroy(gtkconv->dialogs.link); | |
3555 | |
3556 if (gtkconv->dialogs.log != NULL) | |
3557 gtk_widget_destroy(gtkconv->dialogs.log); | |
3558 | |
3559 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { | |
3560 if (gtkconv->u.im->save_icon != NULL) | |
3561 gtk_widget_destroy(gtkconv->u.im->save_icon); | |
3562 | |
3563 if (gtkconv->u.im->anim != NULL) | |
3564 gdk_pixbuf_animation_unref(gtkconv->u.im->anim); | |
3565 | |
3566 g_free(gtkconv->u.im); | |
3567 } | |
3568 else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { | |
3569 g_free(gtkconv->u.chat); | |
3570 } | |
3571 | |
3572 g_free(gtkconv); | |
3573 } | |
3574 | |
3575 static void | |
3576 gaim_gtkconv_write_im(struct gaim_conversation *conv, const char *who, | |
3577 const char *message, size_t len, int flags, time_t mtime) | |
3578 { | |
3579 struct gaim_gtk_conversation *gtkconv; | |
3580 | |
3581 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
3582 | |
3583 debug_printf("Write IM\n"); | |
3584 | |
3585 if (gtkconv->make_sound) { | |
3586 if (flags & WFLAG_RECV) { | |
3587 if (gtkconv->u.im->a_virgin && | |
3588 (sound_options & OPT_SOUND_FIRST_RCV)) { | |
3589 | |
3590 play_sound(SND_FIRST_RECEIVE); | |
3591 } | |
3592 else | |
3593 play_sound(SND_RECEIVE); | |
3594 } | |
3595 else { | |
3596 debug_printf("Playing SND_SEND\n"); | |
3597 play_sound(SND_SEND); | |
3598 } | |
3599 } | |
3600 | |
3601 gtkconv->u.im->a_virgin = FALSE; | |
3602 | |
3603 gaim_conversation_write(conv, who, message, len, flags, mtime); | |
3604 } | |
3605 | |
3606 static void | |
3607 gaim_gtkconv_write_chat(struct gaim_conversation *conv, const char *who, | |
3608 const char *message, int flags, time_t mtime) | |
3609 { | |
3610 struct gaim_gtk_conversation *gtkconv; | |
3611 | |
3612 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
3613 | |
3614 if (gtkconv->make_sound) { | |
3615 if (!(flags & WFLAG_WHISPER) && (flags & WFLAG_SEND)) | |
3616 play_sound(SND_CHAT_YOU_SAY); | |
3617 else if (flags & WFLAG_RECV) { | |
3618 if ((flags & WFLAG_NICK) && (sound_options & OPT_SOUND_CHAT_NICK)) | |
3619 play_sound(SND_CHAT_NICK); | |
3620 else | |
3621 play_sound(SND_CHAT_SAY); | |
3622 } | |
3623 } | |
3624 | |
3625 if (chat_options & OPT_CHAT_COLORIZE) | |
3626 flags |= WFLAG_COLORIZE; | |
3627 | |
3628 gaim_conversation_write(conv, who, message, -1, flags, mtime); | |
3629 } | |
3630 | |
3631 static void | |
3632 gaim_gtkconv_write_conv(struct gaim_conversation *conv, const char *who, | |
3633 const char *message, size_t length, int flags, | |
3634 time_t mtime) | |
3635 { | |
3636 struct gaim_gtk_conversation *gtkconv; | |
3637 struct gaim_connection *gc; | |
3638 int gtk_font_options = 0; | |
3639 GString *log_str; | |
3640 FILE *fd; | |
3641 char buf[BUF_LONG]; | |
3642 char buf2[BUF_LONG]; | |
3643 char mdate[64]; | |
3644 char color[10]; | |
3645 char *str; | |
3646 char *with_font_tag; | |
3647 | |
3648 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
3649 gc = gaim_conversation_get_gc(conv); | |
3650 | |
3651 strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime)); | |
3652 | |
3653 gtk_font_options ^= GTK_IMHTML_NO_COMMENTS; | |
3654 | |
3655 if (convo_options & OPT_CONVO_IGNORE_COLOUR) | |
3656 gtk_font_options ^= GTK_IMHTML_NO_COLOURS; | |
3657 | |
3658 if (convo_options & OPT_CONVO_IGNORE_FONTS) | |
3659 gtk_font_options ^= GTK_IMHTML_NO_FONTS; | |
3660 | |
3661 if (convo_options & OPT_CONVO_IGNORE_SIZES) | |
3662 gtk_font_options ^= GTK_IMHTML_NO_SIZES; | |
3663 | |
3664 if (!(logging_options & OPT_LOG_STRIP_HTML)) | |
3665 gtk_font_options ^= GTK_IMHTML_RETURN_LOG; | |
3666 | |
3667 if (flags & WFLAG_SYSTEM) { | |
3668 if (convo_options & OPT_CONVO_SHOW_TIME) | |
3669 g_snprintf(buf, BUF_LONG, "<FONT SIZE=\"2\">(%s) </FONT><B>%s</B>", | |
3670 mdate, message); | |
3671 else | |
3672 g_snprintf(buf, BUF_LONG, "<B>%s</B>", message); | |
3673 | |
3674 g_snprintf(buf2, sizeof(buf2), | |
3675 "<FONT SIZE=\"2\"><!--(%s) --></FONT><B>%s</B><BR>", | |
3676 mdate, message); | |
3677 | |
3678 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, -1, 0); | |
3679 | |
3680 if (logging_options & OPT_LOG_STRIP_HTML) { | |
3681 char *t1 = strip_html(buf); | |
3682 | |
3683 conv->history = g_string_append(conv->history, t1); | |
3684 conv->history = g_string_append(conv->history, "\n"); | |
3685 | |
3686 g_free(t1); | |
3687 } | |
3688 else { | |
3689 conv->history = g_string_append(conv->history, buf); | |
3690 conv->history = g_string_append(conv->history, "<BR>\n"); | |
3691 } | |
3692 | |
3693 if (!(flags & WFLAG_NOLOG) && gaim_conversation_is_logging(conv)) { | |
3694 /* | |
3695 XXX | |
3696 ((gaim_conversation_get_type(conv) == GAIM_CONV_CHAT && | |
3697 (logging_options & OPT_LOG_CHATS)) || | |
3698 (gaim_conversation_get_type(conv) == GAIM_CONV_IM && | |
3699 (logging_options & OPT_LOG_CONVOS)) || | |
3700 find_log_info(gaim_conversation_get_name(conv)))) { | |
3701 */ | |
3702 | |
3703 char *t1; | |
3704 char nm[256]; | |
3705 | |
3706 if (logging_options & OPT_LOG_STRIP_HTML) | |
3707 t1 = strip_html(buf); | |
3708 else | |
3709 t1 = buf; | |
3710 | |
3711 if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) | |
3712 g_snprintf(nm, sizeof(nm), "%s.chat", | |
3713 gaim_conversation_get_name(conv)); | |
3714 else | |
3715 strncpy(nm, gaim_conversation_get_name(conv), sizeof(nm)); | |
3716 | |
3717 fd = open_log_file(nm, | |
3718 (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT)); | |
3719 | |
3720 if (fd) { | |
3721 if (logging_options & OPT_LOG_STRIP_HTML) | |
3722 fprintf(fd, "%s\n", t1); | |
3723 else | |
3724 fprintf(fd, "%s<BR>\n", t1); | |
3725 | |
3726 fclose(fd); | |
3727 } | |
3728 | |
3729 if (logging_options & OPT_LOG_STRIP_HTML) | |
3730 g_free(t1); | |
3731 } | |
3732 } | |
3733 else if (flags & WFLAG_NOLOG) { | |
3734 g_snprintf(buf, BUF_LONG, | |
3735 "<B><FONT COLOR=\"#777777\">%s</FONT></B><BR>", | |
3736 message); | |
3737 | |
3738 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf, -1, 0); | |
3739 } | |
3740 else { | |
3741 char *new_message = g_strdup(message); | |
3742 | |
3743 if (flags & WFLAG_WHISPER) { | |
3744 str = g_malloc(1024); | |
3745 | |
3746 /* If we're whispering, it's not an autoresponse. */ | |
3747 if (meify(new_message, length)) { | |
3748 g_snprintf(str, 1024, "***%s", who); | |
3749 strcpy(color, "#6C2585"); | |
3750 } | |
3751 else { | |
3752 g_snprintf(str, 1024, "*%s*:", who); | |
3753 strcpy(color, "#00FF00"); | |
3754 } | |
3755 } | |
3756 else { | |
3757 if (meify(new_message, length)) { | |
3758 str = g_malloc(1024); | |
3759 | |
3760 if (flags & WFLAG_AUTO) | |
3761 g_snprintf(str, 1024, "%s ***%s", AUTO_RESPONSE, who); | |
3762 else | |
3763 g_snprintf(str, 1024, "***%s", who); | |
3764 | |
3765 if (flags & WFLAG_NICK) | |
3766 strcpy(color, "#AF7F00"); | |
3767 else | |
3768 strcpy(color, "#062585"); | |
3769 } | |
3770 else { | |
3771 str = g_malloc(1024); | |
3772 | |
3773 if (flags & WFLAG_AUTO) | |
3774 g_snprintf(str, 1024, "%s %s", who, AUTO_RESPONSE); | |
3775 else | |
3776 g_snprintf(str, 1024, "%s:", who); | |
3777 | |
3778 if (flags & WFLAG_NICK) | |
3779 strcpy(color, "#AF7F00"); | |
3780 else if (flags & WFLAG_RECV) { | |
3781 if (flags & WFLAG_COLORIZE) { | |
3782 const char *u; | |
3783 int m = 0; | |
3784 | |
3785 for (u = who; *u != '\0'; u++) | |
3786 m += *u; | |
3787 | |
3788 m = m % NUM_NICK_COLORS; | |
3789 | |
3790 strcpy(color, nick_colors[m]); | |
3791 } | |
3792 else | |
3793 strcpy(color, "#A82F2F"); | |
3794 } | |
3795 else if (flags & WFLAG_SEND) | |
3796 strcpy(color, "#16569E"); | |
3797 } | |
3798 } | |
3799 | |
3800 if (convo_options & OPT_CONVO_SHOW_TIME) | |
3801 g_snprintf(buf, BUF_LONG, | |
3802 "<FONT COLOR=\"%s\"><FONT SIZE=\"2\">(%s) </FONT>" | |
3803 "<B>%s</B></FONT> ", color, mdate, str); | |
3804 else | |
3805 g_snprintf(buf, BUF_LONG, | |
3806 "<FONT COLOR=\"%s\"><B>%s</B></FONT> ", color, str); | |
3807 | |
3808 g_snprintf(buf2, BUF_LONG, | |
3809 "<FONT COLOR=\"%s\"><FONT SIZE=\"2\"><!--(%s) --></FONT>" | |
3810 "<B>%s</B></FONT> ", | |
3811 color, mdate, str); | |
3812 | |
3813 g_free(str); | |
3814 | |
3815 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, -1, 0); | |
3816 | |
3817 with_font_tag = g_strdup_printf("<font sml=\"%s\">%s</font>", | |
3818 gc->prpl->name, new_message); | |
3819 | |
3820 log_str = gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), | |
3821 with_font_tag, length, | |
3822 gtk_font_options); | |
3823 | |
3824 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR>", -1, 0); | |
3825 | |
3826 /* XXX This needs to be updated for the new length argument. */ | |
3827 if (logging_options & OPT_LOG_STRIP_HTML) { | |
3828 char *t1, *t2; | |
3829 | |
3830 t1 = strip_html(buf); | |
3831 t2 = strip_html(new_message); | |
3832 | |
3833 conv->history = g_string_append(conv->history, t1); | |
3834 conv->history = g_string_append(conv->history, t2); | |
3835 conv->history = g_string_append(conv->history, "\n"); | |
3836 | |
3837 g_free(t1); | |
3838 g_free(t2); | |
3839 } | |
3840 else { | |
3841 char *t1, *t2; | |
3842 | |
3843 t1 = html_logize(buf); | |
3844 t2 = html_logize(new_message); | |
3845 | |
3846 conv->history = g_string_append(conv->history, t1); | |
3847 conv->history = g_string_append(conv->history, t2); | |
3848 conv->history = g_string_append(conv->history, "\n"); | |
3849 conv->history = g_string_append(conv->history, log_str->str); | |
3850 conv->history = g_string_append(conv->history, "<BR>\n"); | |
3851 | |
3852 g_free(t1); | |
3853 g_free(t2); | |
3854 } | |
3855 | |
3856 /* XXX This needs to be updated for the new length argument. */ | |
3857 if (gaim_conversation_is_logging(conv)) { | |
3858 /* | |
3859 XXX | |
3860 if ((gaim_conversation_get_type(conv) == GAIM_CONV_CHAT && | |
3861 (logging_options & OPT_LOG_CHATS)) || | |
3862 (gaim_conversation_get_type(conv) == GAIM_CONV_IM && | |
3863 (logging_options & OPT_LOG_CONVOS)) || | |
3864 find_log_info(gaim_conversation_get_name(conv))) { | |
3865 */ | |
3866 | |
3867 char *t1, *t2; | |
3868 char nm[256]; | |
3869 | |
3870 if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) | |
3871 g_snprintf(nm, sizeof(nm), "%s.chat", | |
3872 gaim_conversation_get_name(conv)); | |
3873 else | |
3874 strncpy(nm, gaim_conversation_get_name(conv), sizeof(nm)); | |
3875 | |
3876 if (logging_options & OPT_LOG_STRIP_HTML) { | |
3877 t1 = strip_html(buf); | |
3878 t2 = strip_html(with_font_tag); | |
3879 } | |
3880 else { | |
3881 t1 = html_logize(buf); | |
3882 t2 = html_logize(with_font_tag); | |
3883 } | |
3884 | |
3885 fd = open_log_file(nm, | |
3886 (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT)); | |
3887 | |
3888 if (fd) { | |
3889 if (logging_options & OPT_LOG_STRIP_HTML) | |
3890 fprintf(fd, "%s%s\n", t1, t2); | |
3891 else { | |
3892 fprintf(fd, "%s%s%s<BR>\n", t1, t2, log_str->str); | |
3893 g_string_free(log_str, TRUE); | |
3894 } | |
3895 | |
3896 fclose(fd); | |
3897 } | |
3898 | |
3899 g_free(t1); | |
3900 g_free(t2); | |
3901 } | |
3902 | |
3903 g_free(with_font_tag); | |
3904 g_free(new_message); | |
3905 } | |
3906 } | |
3907 | |
3908 static void | |
3909 gaim_gtkconv_chat_add_user(struct gaim_conversation *conv, const char *user) | |
3910 { | |
3911 struct gaim_chat *chat; | |
3912 struct gaim_gtk_conversation *gtkconv; | |
3913 struct gaim_gtk_chat_pane *gtkchat; | |
3914 char tmp[BUF_LONG]; | |
3915 int num_users; | |
3916 int pos; | |
3917 | |
3918 chat = GAIM_CHAT(conv); | |
3919 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
3920 gtkchat = gtkconv->u.chat; | |
3921 | |
3922 num_users = g_list_length(gaim_chat_get_users(chat)); | |
3923 | |
3924 g_snprintf(tmp, sizeof(tmp), | |
3925 ngettext("%d person in room", "%d people in room", | |
3926 num_users), | |
3927 num_users); | |
3928 | |
3929 gtk_label_set_text(GTK_LABEL(gtkchat->count), tmp); | |
3930 | |
3931 if (gtkconv->make_sound) | |
3932 play_sound(SND_CHAT_JOIN); | |
3933 | |
3934 pos = g_list_index(gaim_chat_get_users(chat), user); | |
3935 | |
3936 add_chat_buddy_common(conv, user, pos); | |
3937 } | |
3938 | |
3939 static void | |
3940 gaim_gtkconv_chat_rename_user(struct gaim_conversation *conv, | |
3941 const char *old_name, const char *new_name) | |
3942 { | |
3943 struct gaim_chat *chat; | |
3944 struct gaim_gtk_conversation *gtkconv; | |
3945 struct gaim_gtk_chat_pane *gtkchat; | |
3946 GtkTreeIter iter; | |
3947 GtkTreeModel *model; | |
3948 GList *names; | |
3949 int pos; | |
3950 int f = 1; | |
3951 | |
3952 chat = GAIM_CHAT(conv); | |
3953 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
3954 gtkchat = gtkconv->u.chat; | |
3955 | |
3956 for (names = gaim_chat_get_users(chat); | |
3957 names != NULL; | |
3958 names = names->next) { | |
3959 | |
3960 char *u = (char *)names->data; | |
3961 | |
3962 if (!g_strcasecmp(u, old_name)) { | |
3963 model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); | |
3964 | |
3965 if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) | |
3966 break; | |
3967 | |
3968 while (f != 0) { | |
3969 char *val; | |
3970 | |
3971 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &val, -1); | |
3972 | |
3973 if (!g_strcasecmp(old_name, val)) | |
3974 gtk_list_store_remove(GTK_LIST_STORE(model), &iter); | |
3975 | |
3976 f = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter); | |
3977 | |
3978 g_free(val); | |
3979 } | |
3980 | |
3981 break; | |
3982 } | |
3983 } | |
3984 | |
3985 if (!names) | |
3986 return; | |
3987 | |
3988 pos = g_list_index(gaim_chat_get_users(chat), new_name); | |
3989 | |
3990 add_chat_buddy_common(conv, new_name, pos); | |
3991 } | |
3992 | |
3993 static void | |
3994 gaim_gtkconv_chat_remove_user(struct gaim_conversation *conv, const char *user) | |
3995 { | |
3996 struct gaim_chat *chat; | |
3997 struct gaim_gtk_conversation *gtkconv; | |
3998 struct gaim_gtk_chat_pane *gtkchat; | |
3999 GtkTreeIter iter; | |
4000 GtkTreeModel *model; | |
4001 GList *names; | |
4002 char tmp[BUF_LONG]; | |
4003 int num_users; | |
4004 int f = 1; | |
4005 | |
4006 chat = GAIM_CHAT(conv); | |
4007 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4008 gtkchat = gtkconv->u.chat; | |
4009 | |
4010 num_users = g_list_length(gaim_chat_get_users(chat)) - 1; | |
4011 | |
4012 for (names = gaim_chat_get_users(chat); | |
4013 names != NULL; | |
4014 names = names->next) { | |
4015 | |
4016 char *u = (char *)names->data; | |
4017 | |
4018 if (!g_strcasecmp(u, user)) { | |
4019 model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); | |
4020 | |
4021 if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) | |
4022 break; | |
4023 | |
4024 while (f != 0) { | |
4025 char *val; | |
4026 | |
4027 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &val, -1); | |
4028 | |
4029 if (!g_strcasecmp(user, val)) | |
4030 gtk_list_store_remove(GTK_LIST_STORE(model), &iter); | |
4031 | |
4032 f = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter); | |
4033 | |
4034 g_free(val); | |
4035 } | |
4036 | |
4037 break; | |
4038 } | |
4039 } | |
4040 | |
4041 if (names == NULL) | |
4042 return; | |
4043 | |
4044 g_snprintf(tmp, sizeof(tmp), | |
4045 ngettext("%d person in room", "%d people in room", | |
4046 num_users), num_users); | |
4047 | |
4048 gtk_label_set_text(GTK_LABEL(gtkchat->count), tmp); | |
4049 | |
4050 if (gtkconv->make_sound) | |
4051 play_sound(SND_CHAT_LEAVE); | |
4052 } | |
4053 | |
4054 static void | |
4055 gaim_gtkconv_set_title(struct gaim_conversation *conv, const char *title) | |
4056 { | |
4057 struct gaim_gtk_conversation *gtkconv; | |
4058 | |
4059 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4060 | |
4061 gtk_label_set_text(GTK_LABEL(gtkconv->tab_label), title); | |
4062 } | |
4063 | |
4064 static void | |
4065 gaim_gtkconv_updated(struct gaim_conversation *conv, GaimConvUpdateType type) | |
4066 { | |
4067 struct gaim_window *win; | |
4068 struct gaim_gtk_conversation *gtkconv; | |
4069 struct gaim_gtk_chat_pane *gtkchat; | |
4070 struct gaim_chat *chat; | |
4071 | |
4072 win = gaim_conversation_get_window(conv); | |
4073 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4074 | |
4075 if (type == GAIM_CONV_UPDATE_USER) { | |
4076 gaim_conversation_autoset_title(conv); | |
4077 gaim_gtkconv_update_buddy_icon(conv); | |
4078 gaim_gtkconv_update_buttons_by_protocol(conv); | |
4079 | |
4080 update_send_as_selection(win); | |
4081 | |
4082 smiley_themeize(gtkconv->imhtml); | |
4083 } | |
4084 else if (type == GAIM_CONV_UPDATE_TYPING || | |
4085 type == GAIM_CONV_UPDATE_UNSEEN) { | |
4086 | |
4087 GtkStyle *style; | |
4088 struct gaim_im *im = NULL; | |
4089 | |
4090 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) | |
4091 im = GAIM_IM(conv); | |
4092 | |
4093 style = gtk_style_new(); | |
4094 | |
4095 if (!GTK_WIDGET_REALIZED(gtkconv->tab_label)) | |
4096 gtk_widget_realize(gtkconv->tab_label); | |
4097 | |
4098 gtk_style_set_font(style, | |
4099 gdk_font_ref(gtk_style_get_font(gtk_widget_get_style( | |
4100 gtkconv->tab_label)))); | |
4101 | |
4102 if (im != NULL && gaim_im_get_typing_state(im) == TYPING) { | |
4103 style->fg[0].red = 0x0000; | |
4104 style->fg[0].green = 0x9999; | |
4105 style->fg[0].blue = 0x0000; | |
4106 } | |
4107 else if (im != NULL && gaim_im_get_typing_state(im) == TYPED) { | |
4108 style->fg[0].red = 0xFFFF; | |
4109 style->fg[0].green = 0xBBBB; | |
4110 style->fg[0].blue = 0x2222; | |
4111 } | |
4112 else if (gaim_conversation_get_unseen(conv) == GAIM_UNSEEN_NICK) { | |
4113 style->fg[0].red = 0x0000; | |
4114 style->fg[0].green = 0x0000; | |
4115 style->fg[0].blue = 0xCCCC; | |
4116 } | |
4117 else if (gaim_conversation_get_unseen(conv) == GAIM_UNSEEN_TEXT) { | |
4118 style->fg[0].red = 0xCCCC; | |
4119 style->fg[0].green = 0x0000; | |
4120 style->fg[0].blue = 0x0000; | |
4121 } | |
4122 | |
4123 gtk_widget_set_style(gtkconv->tab_label, style); | |
4124 gtk_style_unref(style); | |
4125 } | |
4126 else if (type == GAIM_CONV_UPDATE_TOPIC) { | |
4127 chat = GAIM_CHAT(conv); | |
4128 gtkchat = gtkconv->u.chat; | |
4129 | |
4130 gtk_entry_set_text(GTK_ENTRY(gtkchat->topic_text), | |
4131 gaim_chat_get_topic(chat)); | |
4132 } | |
4133 else if (type == GAIM_CONV_ACCOUNT_ONLINE || | |
4134 type == GAIM_CONV_ACCOUNT_OFFLINE) { | |
4135 | |
4360
c435a29370b8
[gaim-migrate @ 4626]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
4136 generate_send_as_items(win, NULL); |
4359 | 4137 } |
4138 } | |
4139 | |
4140 static struct gaim_conversation_ops conversation_ops = | |
4141 { | |
4142 gaim_gtkconv_destroy, /* destroy_conversation */ | |
4143 gaim_gtkconv_write_chat, /* write_chat */ | |
4144 gaim_gtkconv_write_im, /* write_im */ | |
4145 gaim_gtkconv_write_conv, /* write_conv */ | |
4146 gaim_gtkconv_chat_add_user, /* chat_add_user */ | |
4147 gaim_gtkconv_chat_rename_user, /* chat_rename_user */ | |
4148 gaim_gtkconv_chat_remove_user, /* chat_remove_user */ | |
4149 gaim_gtkconv_set_title, /* set_title */ | |
4150 NULL, /* update_progress */ | |
4151 gaim_gtkconv_updated /* updated */ | |
4152 }; | |
4153 | |
4154 struct gaim_conversation_ops * | |
4155 gaim_get_gtk_conversation_ops(void) | |
4156 { | |
4157 return &conversation_ops;; | |
4158 } | |
4159 | |
4160 /************************************************************************** | |
4161 * Public conversation utility functions | |
4162 **************************************************************************/ | |
4163 void | |
4164 gaim_gtk_set_state_lock(gboolean lock) | |
4165 { | |
4166 state_lock = lock; | |
4167 } | |
4168 | |
4169 gboolean | |
4170 gaim_gtk_is_state_locked(void) | |
4171 { | |
4172 return state_lock; | |
4173 } | |
4174 | |
4175 void | |
4176 gaim_gtkconv_toggle_smileys(void) | |
4177 { | |
4178 GList *cl; | |
4179 struct gaim_conversation *conv; | |
4180 struct gaim_gtk_conversation *gtkconv; | |
4181 | |
4182 for (cl = gaim_get_conversations(); cl != NULL; cl = cl->next) { | |
4183 | |
4184 conv = (struct gaim_conversation *)cl->data; | |
4185 | |
4186 if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) | |
4187 continue; | |
4188 | |
4189 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4190 | |
4191 gtk_imhtml_show_smileys(GTK_IMHTML(gtkconv->imhtml), | |
4192 (convo_options & OPT_CONVO_SHOW_SMILEY)); | |
4193 } | |
4194 } | |
4195 | |
4196 void | |
4197 gaim_gtkconv_toggle_timestamps(void) | |
4198 { | |
4199 GList *cl; | |
4200 struct gaim_conversation *conv; | |
4201 struct gaim_gtk_conversation *gtkconv; | |
4202 | |
4203 for (cl = gaim_get_conversations(); cl != NULL; cl = cl->next) { | |
4204 | |
4205 conv = (struct gaim_conversation *)cl->data; | |
4206 | |
4207 if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) | |
4208 continue; | |
4209 | |
4210 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4211 | |
4212 gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), | |
4213 (convo_options & OPT_CONVO_SHOW_TIME)); | |
4214 } | |
4215 } | |
4216 | |
4217 void | |
4218 gaim_gtkconv_toggle_spellchk(void) | |
4219 { | |
4220 #ifdef USE_GTKSPELL | |
4221 GList *cl; | |
4222 struct gaim_conversation *conv; | |
4223 struct gaim_gtk_conversation *gtkconv; | |
4224 GtkSpell *spell; | |
4225 | |
4226 for (cl = gaim_get_conversations(); cl != NULL; cl = cl->next) { | |
4227 | |
4228 conv = (struct gaim_conversation *)cl->data; | |
4229 | |
4230 if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) | |
4231 continue; | |
4232 | |
4233 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4234 | |
4235 if (convo_options & OPT_CONVO_CHECK_SPELLING) | |
4236 gtkspell_new_attach(GTK_TEXT_VIEW(gtkconv->entry), NULL, NULL); | |
4237 else { | |
4238 spell = gtkspell_get_from_text_view(GTK_TEXT_VIEW(gtkconv->entry)); | |
4239 gtkspell_detach(spell); | |
4240 } | |
4241 } | |
4242 #endif | |
4243 } | |
4244 | |
4245 static void | |
4246 remove_icon(struct gaim_gtk_conversation *gtkconv) | |
4247 { | |
4248 if (gtkconv == NULL) | |
4249 return; | |
4250 | |
4251 if (gtkconv->u.im->icon != NULL) | |
4252 gtk_container_remove(GTK_CONTAINER(gtkconv->bbox), | |
4253 gtkconv->u.im->icon->parent->parent); | |
4254 | |
4255 if (gtkconv->u.im->anim != NULL) | |
4256 gdk_pixbuf_animation_unref(gtkconv->u.im->anim); | |
4257 | |
4258 if (gtkconv->u.im->icon_timer != 0) | |
4259 g_source_remove(gtkconv->u.im->icon_timer); | |
4260 | |
4261 if (gtkconv->u.im->iter != NULL) | |
4262 g_object_unref(G_OBJECT(gtkconv->u.im->iter)); | |
4263 | |
4264 gtkconv->u.im->icon_timer = 0; | |
4265 gtkconv->u.im->icon = NULL; | |
4266 gtkconv->u.im->anim = NULL; | |
4267 gtkconv->u.im->iter = NULL; | |
4268 } | |
4269 | |
4270 static gboolean | |
4271 redraw_icon(gpointer data) | |
4272 { | |
4273 struct gaim_conversation *conv = (struct gaim_conversation *)data; | |
4274 struct gaim_gtk_conversation *gtkconv; | |
4275 | |
4276 GdkPixbuf *buf; | |
4277 GdkPixbuf *scale; | |
4278 GdkPixmap *pm; | |
4279 GdkBitmap *bm; | |
4280 gint delay; | |
4281 | |
4282 if (!g_list_find(gaim_get_ims(), conv)) { | |
4283 debug_printf("I think this is a bug.\n"); | |
4284 return FALSE; | |
4285 } | |
4286 | |
4287 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4288 | |
4289 gdk_pixbuf_animation_iter_advance(gtkconv->u.im->iter, NULL); | |
4290 buf = gdk_pixbuf_animation_iter_get_pixbuf(gtkconv->u.im->iter); | |
4291 | |
4292 scale = gdk_pixbuf_scale_simple(buf, | |
4293 MAX(gdk_pixbuf_get_width(buf) * SCALE(gtkconv->u.im->anim) / | |
4294 gdk_pixbuf_animation_get_width(gtkconv->u.im->anim), 1), | |
4295 MAX(gdk_pixbuf_get_height(buf) * SCALE(gtkconv->u.im->anim) / | |
4296 gdk_pixbuf_animation_get_height(gtkconv->u.im->anim), 1), | |
4297 GDK_INTERP_NEAREST); | |
4298 | |
4299 gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100); | |
4300 gdk_pixbuf_unref(scale); | |
4301 gtk_pixmap_set(GTK_PIXMAP(gtkconv->u.im->icon), pm, bm); | |
4302 gdk_pixmap_unref(pm); | |
4303 gtk_widget_queue_draw(gtkconv->u.im->icon); | |
4304 | |
4305 if (bm) | |
4306 gdk_bitmap_unref(bm); | |
4307 | |
4308 delay = gdk_pixbuf_animation_iter_get_delay_time(gtkconv->u.im->iter) / 10; | |
4309 | |
4310 gtkconv->u.im->icon_timer = g_timeout_add(delay * 10, redraw_icon, conv); | |
4311 | |
4312 return FALSE; | |
4313 } | |
4314 | |
4315 static void | |
4316 start_anim(GtkObject *obj, struct gaim_conversation *conv) | |
4317 { | |
4318 struct gaim_gtk_conversation *gtkconv; | |
4319 int delay; | |
4320 | |
4321 if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) | |
4322 return; | |
4323 | |
4324 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4325 | |
4326 delay = gdk_pixbuf_animation_iter_get_delay_time(gtkconv->u.im->iter) / 10; | |
4327 | |
4328 if (gtkconv->u.im->anim) | |
4329 gtkconv->u.im->icon_timer = g_timeout_add(delay * 10, redraw_icon, | |
4330 conv); | |
4331 } | |
4332 | |
4333 static void | |
4334 stop_anim(GtkObject *obj, struct gaim_conversation *conv) | |
4335 { | |
4336 struct gaim_gtk_conversation *gtkconv; | |
4337 | |
4338 if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) | |
4339 return; | |
4340 | |
4341 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4342 | |
4343 if (gtkconv->u.im->icon_timer != 0) | |
4344 g_source_remove(gtkconv->u.im->icon_timer); | |
4345 | |
4346 gtkconv->u.im->icon_timer = 0; | |
4347 } | |
4348 | |
4349 static gboolean | |
4350 icon_menu(GtkObject *obj, GdkEventButton *e, struct gaim_conversation *conv) | |
4351 { | |
4352 struct gaim_gtk_conversation *gtkconv; | |
4353 static GtkWidget *menu = NULL; | |
4354 GtkWidget *button; | |
4355 | |
4356 if (e->button != 3 || e->type != GDK_BUTTON_PRESS) | |
4357 return FALSE; | |
4358 | |
4359 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4360 | |
4361 /* | |
4362 * If a menu already exists, destroy it before creating a new one, | |
4363 * thus freeing-up the memory it occupied. | |
4364 */ | |
4365 if (menu != NULL) | |
4366 gtk_widget_destroy(menu); | |
4367 | |
4368 menu = gtk_menu_new(); | |
4369 | |
4370 if (gtkconv->u.im->icon_timer) { | |
4371 button = gtk_menu_item_new_with_label(_("Disable Animation")); | |
4372 g_signal_connect(GTK_OBJECT(button), "activate", | |
4373 G_CALLBACK(stop_anim), conv); | |
4374 gtk_menu_shell_append(GTK_MENU_SHELL(menu), button); | |
4375 gtk_widget_show(button); | |
4376 } | |
4377 else if (gtkconv->u.im->anim && | |
4378 !(gdk_pixbuf_animation_is_static_image(gtkconv->u.im->anim))) | |
4379 { | |
4380 button = gtk_menu_item_new_with_label(_("Enable Animation")); | |
4381 g_signal_connect(GTK_OBJECT(button), "activate", | |
4382 G_CALLBACK(start_anim), conv); | |
4383 gtk_menu_shell_append(GTK_MENU_SHELL(menu), button); | |
4384 gtk_widget_show(button); | |
4385 } | |
4386 | |
4387 button = gtk_menu_item_new_with_label(_("Hide Icon")); | |
4388 g_signal_connect_swapped(GTK_OBJECT(button), "activate", | |
4389 G_CALLBACK(remove_icon), conv); | |
4390 gtk_menu_shell_append(GTK_MENU_SHELL(menu), button); | |
4391 gtk_widget_show(button); | |
4392 | |
4393 button = gtk_menu_item_new_with_label(_("Save Icon As...")); | |
4394 g_signal_connect(GTK_OBJECT(button), "activate", | |
4395 G_CALLBACK(gaim_gtk_save_icon_dialog), conv); | |
4396 gtk_menu_shell_append(GTK_MENU_SHELL(menu), button); | |
4397 gtk_widget_show(button); | |
4398 | |
4399 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, e->button, e->time); | |
4400 | |
4401 return TRUE; | |
4402 } | |
4403 | |
4404 void | |
4405 gaim_gtkconv_update_buddy_icon(struct gaim_conversation *conv) | |
4406 { | |
4407 struct gaim_gtk_conversation *gtkconv; | |
4408 | |
4409 char filename[256]; | |
4410 FILE *file; | |
4411 GError *err = NULL; | |
4412 | |
4413 void *data; | |
4414 int len, delay; | |
4415 | |
4416 GdkPixbuf *buf; | |
4417 | |
4418 GtkWidget *event; | |
4419 GtkWidget *frame; | |
4420 GdkPixbuf *scale; | |
4421 GdkPixmap *pm; | |
4422 GdkBitmap *bm; | |
4423 int sf = 0; | |
4424 | |
4425 if (conv == NULL || | |
4426 gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops() || | |
4427 gaim_conversation_get_type(conv) != GAIM_CONV_IM) { | |
4428 | |
4429 return; | |
4430 } | |
4431 | |
4432 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4433 | |
4434 remove_icon(gtkconv); | |
4435 | |
4436 if (im_options & OPT_IM_HIDE_ICONS) | |
4437 return; | |
4438 | |
4439 if (gaim_conversation_get_gc(conv) == NULL) | |
4440 return; | |
4441 | |
4442 data = get_icon_data(gaim_conversation_get_gc(conv), | |
4443 normalize(gaim_conversation_get_name(conv)), | |
4444 &len); | |
4445 | |
4446 if (!data) | |
4447 return; | |
4448 | |
4449 /* this is such an evil hack, i don't know why i'm even considering it. | |
4450 * we'll do it differently when gdk-pixbuf-loader isn't leaky anymore. */ | |
4451 g_snprintf(filename, sizeof(filename), | |
4452 "%s" G_DIR_SEPARATOR_S "gaimicon-%s.%d", | |
4453 g_get_tmp_dir(), gaim_conversation_get_name(conv), getpid()); | |
4454 | |
4455 if (!(file = fopen(filename, "w"))) | |
4456 return; | |
4457 | |
4458 fwrite(data, 1, len, file); | |
4459 fclose(file); | |
4460 | |
4461 gtkconv->u.im->anim = gdk_pixbuf_animation_new_from_file(filename, &err); | |
4462 | |
4463 if (err) { | |
4464 debug_printf("Buddy icon error: %s\n", err->message); | |
4465 g_error_free(err); | |
4466 } | |
4467 | |
4468 /* make sure we remove the file as soon as possible */ | |
4469 unlink(filename); | |
4470 | |
4471 if (!gtkconv->u.im->anim) | |
4472 return; | |
4473 | |
4474 if (gdk_pixbuf_animation_is_static_image(gtkconv->u.im->anim)) { | |
4475 gtkconv->u.im->iter = NULL; | |
4476 delay = 0; | |
4477 buf = gdk_pixbuf_animation_get_static_image(gtkconv->u.im->anim); | |
4478 } else { | |
4479 gtkconv->u.im->iter = | |
4480 gdk_pixbuf_animation_get_iter(gtkconv->u.im->anim, NULL); | |
4481 buf = gdk_pixbuf_animation_iter_get_pixbuf(gtkconv->u.im->iter); | |
4482 delay = gdk_pixbuf_animation_iter_get_delay_time(gtkconv->u.im->iter); | |
4483 delay = delay / 10; | |
4484 } | |
4485 | |
4486 sf = SCALE(gtkconv->u.im->anim); | |
4487 scale = gdk_pixbuf_scale_simple(buf, | |
4488 MAX(gdk_pixbuf_get_width(buf) * sf / | |
4489 gdk_pixbuf_animation_get_width(gtkconv->u.im->anim), 1), | |
4490 MAX(gdk_pixbuf_get_height(buf) * sf / | |
4491 gdk_pixbuf_animation_get_height(gtkconv->u.im->anim), 1), | |
4492 GDK_INTERP_NEAREST); | |
4493 | |
4494 if (delay) | |
4495 gtkconv->u.im->icon_timer = g_timeout_add(delay * 10, redraw_icon, | |
4496 conv); | |
4497 | |
4498 gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100); | |
4499 gdk_pixbuf_unref(scale); | |
4500 | |
4501 frame = gtk_frame_new(NULL); | |
4502 gtk_frame_set_shadow_type(GTK_FRAME(frame), | |
4503 (bm ? GTK_SHADOW_NONE : GTK_SHADOW_IN)); | |
4504 gtk_box_pack_start(GTK_BOX(gtkconv->bbox), frame, FALSE, FALSE, 5); | |
4505 gtk_box_reorder_child(GTK_BOX(gtkconv->bbox), frame, 0); | |
4506 gtk_widget_show(frame); | |
4507 | |
4508 event = gtk_event_box_new(); | |
4509 gtk_container_add(GTK_CONTAINER(frame), event); | |
4510 g_signal_connect(GTK_OBJECT(event), "button-press-event", | |
4511 G_CALLBACK(icon_menu), conv); | |
4512 gtk_widget_show(event); | |
4513 | |
4514 gtkconv->u.im->icon = gtk_pixmap_new(pm, bm); | |
4515 gtk_widget_set_size_request(gtkconv->u.im->icon, sf, sf); | |
4516 gtk_container_add(GTK_CONTAINER(event), gtkconv->u.im->icon); | |
4517 gtk_widget_show(gtkconv->u.im->icon); | |
4518 | |
4519 if(im_options & OPT_IM_NO_ANIMATION) | |
4520 stop_anim(NULL, conv); | |
4521 | |
4522 gdk_pixmap_unref(pm); | |
4523 | |
4524 if (bm) | |
4525 gdk_bitmap_unref(bm); | |
4526 } | |
4527 | |
4528 void | |
4529 gaim_gtkconv_hide_buddy_icons(void) | |
4530 { | |
4531 gaim_conversation_foreach(gaim_gtkconv_update_buddy_icon); | |
4532 } | |
4533 | |
4534 void | |
4535 gaim_gtkconv_set_anim(void) | |
4536 { | |
4537 GList *l; | |
4538 | |
4539 if (im_options & OPT_IM_HIDE_ICONS) | |
4540 return; | |
4541 | |
4542 if (im_options & OPT_IM_NO_ANIMATION) { | |
4543 for (l = gaim_get_ims(); l != NULL; l = l->next) | |
4544 stop_anim(NULL, (struct gaim_conversation *)l->data); | |
4545 } else { | |
4546 for (l = gaim_get_ims(); l != NULL; l = l->next) | |
4547 start_anim(NULL, (struct gaim_conversation *)l->data); | |
4548 } | |
4549 } | |
4550 | |
4551 void | |
4552 gaim_gtkconv_update_font_buttons(void) | |
4553 { | |
4554 GList *l; | |
4555 struct gaim_conversation *conv; | |
4556 struct gaim_gtk_conversation *gtkconv; | |
4557 | |
4558 for (l = gaim_get_ims(); l != NULL; l = l->next) { | |
4559 conv = (struct gaim_conversation *)l->data; | |
4560 | |
4561 if (gaim_conversation_get_ops(conv) != | |
4562 gaim_get_gtk_conversation_ops()) | |
4563 continue; | |
4564 | |
4565 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4566 | |
4567 if (gtkconv->toolbar.bold != NULL) | |
4568 gtk_widget_set_sensitive(gtkconv->toolbar.bold, | |
4569 (!(font_options & OPT_FONT_BOLD))); | |
4570 | |
4571 if (gtkconv->toolbar.italic != NULL) | |
4572 gtk_widget_set_sensitive(gtkconv->toolbar.italic, | |
4573 (!(font_options & OPT_FONT_ITALIC))); | |
4574 | |
4575 if (gtkconv->toolbar.underline != NULL) | |
4576 gtk_widget_set_sensitive(gtkconv->toolbar.underline, | |
4577 (!(font_options & OPT_FONT_UNDERLINE))); | |
4578 } | |
4579 } | |
4580 | |
4581 void | |
4582 gaim_gtkconv_update_tabs(void) | |
4583 { | |
4584 GList *l; | |
4585 GtkPositionType pos; | |
4586 struct gaim_window *win; | |
4587 struct gaim_gtk_window *gtkwin; | |
4588 | |
4589 pos = ((im_options & OPT_IM_SIDE_TAB) | |
4590 ? ((im_options & OPT_IM_BR_TAB) ? GTK_POS_RIGHT : GTK_POS_LEFT) | |
4591 : ((im_options & OPT_IM_BR_TAB) ? GTK_POS_BOTTOM : GTK_POS_TOP)); | |
4592 | |
4593 for (l = gaim_get_windows(); l != NULL; l = l->next) { | |
4594 win = (struct gaim_window *)l->data; | |
4595 | |
4596 if (gaim_window_get_ops(win) != gaim_get_gtk_window_ops()) | |
4597 continue; | |
4598 | |
4599 gtkwin = GAIM_GTK_WINDOW(win); | |
4600 | |
4601 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(gtkwin->notebook), pos); | |
4602 } | |
4603 } | |
4604 | |
4605 void | |
4606 gaim_gtkconv_update_chat_button_style() | |
4607 { | |
4608 GSList *l; | |
4609 struct gaim_connection *g; | |
4610 GtkWidget *parent; | |
4611 GaimConversationType type = GAIM_CONV_CHAT; | |
4612 | |
4613 for (l = connections; l != NULL; l = l->next) { | |
4614 GSList *bcs; | |
4615 struct gaim_conversation *conv; | |
4616 struct gaim_gtk_conversation *gtkconv; | |
4617 struct gaim_gtk_window *gtkwin; | |
4618 | |
4619 g = (struct gaim_connection *)l->data; | |
4620 | |
4621 for (bcs = g->buddy_chats; bcs != NULL; bcs = bcs->next) { | |
4622 conv = (struct gaim_conversation *)bcs->data; | |
4623 | |
4624 if (gaim_conversation_get_type(conv) != GAIM_CONV_CHAT) | |
4625 continue; | |
4626 | |
4627 if (gaim_conversation_get_ops(conv) != | |
4628 gaim_get_gtk_conversation_ops()) | |
4629 continue; | |
4630 | |
4631 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4632 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(conv)); | |
4633 parent = gtk_widget_get_parent(gtkconv->send); | |
4634 | |
4635 gtkconv->send = | |
4636 gaim_gtk_change_text(_("Send"), | |
4637 gtkconv->send, GAIM_STOCK_SEND, type); | |
4638 gtkconv->u.chat->invite = | |
4639 gaim_gtk_change_text(_("Invite"), | |
4640 gtkconv->u.chat->invite, | |
4641 GAIM_STOCK_INVITE, type); | |
4642 | |
4643 gtk_box_pack_end(GTK_BOX(parent), gtkconv->send, FALSE, FALSE, | |
4644 type); | |
4645 gtk_box_pack_end(GTK_BOX(parent), gtkconv->u.chat->invite, | |
4646 FALSE, FALSE, 0); | |
4647 | |
4648 g_signal_connect(G_OBJECT(gtkconv->send), "clicked", | |
4649 G_CALLBACK(send_cb), conv); | |
4650 g_signal_connect(G_OBJECT(gtkconv->u.chat->invite), "clicked", | |
4651 G_CALLBACK(invite_cb), conv); | |
4652 | |
4653 gtk_button_set_relief(GTK_BUTTON(gtkconv->send), | |
4654 GTK_RELIEF_NONE); | |
4655 gtk_button_set_relief(GTK_BUTTON(gtkconv->u.chat->invite), | |
4656 GTK_RELIEF_NONE); | |
4657 | |
4658 gaim_gtkconv_update_buttons_by_protocol(conv); | |
4659 } | |
4660 } | |
4661 } | |
4662 | |
4663 void | |
4664 gaim_gtkconv_update_im_button_style() | |
4665 { | |
4666 GList *l; | |
4667 struct gaim_conversation *conv; | |
4668 struct gaim_gtk_conversation *gtkconv; | |
4669 | |
4670 for (l = gaim_get_ims(); l != NULL; l = l->next) { | |
4671 conv = (struct gaim_conversation *)l->data; | |
4672 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4673 | |
4674 setup_im_buttons(conv, gtk_widget_get_parent(gtkconv->send)); | |
4675 } | |
4676 } | |
4677 | |
4678 void | |
4679 gaim_gtkconv_update_buttons_by_protocol(struct gaim_conversation *conv) | |
4680 { | |
4681 struct gaim_window *win; | |
4682 struct gaim_gtk_window *gtkwin = NULL; | |
4683 struct gaim_gtk_conversation *gtkconv; | |
4684 struct gaim_connection *gc; | |
4685 | |
4686 if (gaim_conversation_get_ops(conv) != gaim_get_gtk_conversation_ops()) | |
4687 return; | |
4688 | |
4689 gc = gaim_conversation_get_gc(conv); | |
4690 win = gaim_conversation_get_window(conv); | |
4691 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4692 | |
4693 if (win != NULL) | |
4694 gtkwin = GAIM_GTK_WINDOW(win); | |
4695 | |
4696 if (gc == NULL) { | |
4697 gtk_widget_set_sensitive(gtkconv->send, FALSE); | |
4698 | |
4365
6e96ced6fb78
[gaim-migrate @ 4631]
Christian Hammond <chipx86@chipx86.com>
parents:
4364
diff
changeset
|
4699 if (win != NULL && gaim_window_get_active_conversation(win) == conv) { |
4359 | 4700 gtk_widget_set_sensitive(gtkwin->menu.insert_link, FALSE); |
4701 } | |
4702 } | |
4364
fa56829b9587
[gaim-migrate @ 4630]
Christian Hammond <chipx86@chipx86.com>
parents:
4363
diff
changeset
|
4703 else { |
4365
6e96ced6fb78
[gaim-migrate @ 4631]
Christian Hammond <chipx86@chipx86.com>
parents:
4364
diff
changeset
|
4704 if (win != NULL) { |
6e96ced6fb78
[gaim-migrate @ 4631]
Christian Hammond <chipx86@chipx86.com>
parents:
4364
diff
changeset
|
4705 gtk_widget_set_sensitive(gtkwin->menu.insert_link, TRUE); |
6e96ced6fb78
[gaim-migrate @ 4631]
Christian Hammond <chipx86@chipx86.com>
parents:
4364
diff
changeset
|
4706 } |
4364
fa56829b9587
[gaim-migrate @ 4630]
Christian Hammond <chipx86@chipx86.com>
parents:
4363
diff
changeset
|
4707 } |
4359 | 4708 |
4709 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { | |
4710 if (gc == NULL) { | |
4711 gtk_widget_set_sensitive(gtkconv->info, FALSE); | |
4712 gtk_widget_set_sensitive(gtkconv->u.im->warn, FALSE); | |
4713 gtk_widget_set_sensitive(gtkconv->u.im->block, FALSE); | |
4714 gtk_widget_set_sensitive(gtkconv->u.im->add, FALSE); | |
4715 | |
4716 if (win != NULL && | |
4717 gaim_window_get_active_conversation(win) == conv) { | |
4718 | |
4719 gtk_widget_set_sensitive(gtkwin->menu.insert_image, FALSE); | |
4720 } | |
4721 | |
4722 return; | |
4723 } | |
4724 | |
4725 gtk_widget_set_sensitive(gtkconv->info, | |
4726 (gc->prpl->get_info != NULL)); | |
4727 | |
4728 gtk_widget_set_sensitive(gtkconv->toolbar.image, | |
4729 (gc->prpl->options & OPT_PROTO_IM_IMAGE)); | |
4730 | |
4731 if (win != NULL && gaim_window_get_active_conversation(win) == conv) { | |
4732 gtk_widget_set_sensitive(gtkwin->menu.insert_image, | |
4733 (gc->prpl->options & OPT_PROTO_IM_IMAGE)); | |
4734 } | |
4735 | |
4736 gtk_widget_set_sensitive(gtkconv->u.im->warn, | |
4737 (gc->prpl->warn != NULL)); | |
4738 | |
4739 gtk_widget_set_sensitive(gtkconv->u.im->block, | |
4740 (gc->prpl->add_permit != NULL)); | |
4741 | |
4742 update_convo_add_button(conv); | |
4743 } | |
4744 else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { | |
4745 if (gc == NULL) { | |
4746 gtk_widget_set_sensitive(gtkconv->u.chat->whisper, FALSE); | |
4747 gtk_widget_set_sensitive(gtkconv->u.chat->invite, FALSE); | |
4748 | |
4749 return; | |
4750 } | |
4751 | |
4752 gtk_widget_set_sensitive(gtkconv->send, (gc->prpl->chat_send != NULL)); | |
4753 | |
4754 gtk_widget_set_sensitive(gtkconv->toolbar.image, FALSE); | |
4755 /* gtk_widget_set_sensitive(gtkwin->menu.insert_image, FALSE); */ | |
4756 | |
4757 gtk_widget_set_sensitive(gtkconv->u.chat->whisper, | |
4758 (gc->prpl->chat_whisper != NULL)); | |
4759 | |
4760 gtk_widget_set_sensitive(gtkconv->u.chat->invite, | |
4761 (gc->prpl->chat_invite != NULL)); | |
4762 } | |
4763 } | |
4764 | |
4765 struct gaim_window * | |
4766 gaim_gtkwin_get_at_xy(int x, int y) | |
4767 { | |
4768 struct gaim_window *win = NULL; | |
4769 struct gaim_gtk_window *gtkwin; | |
4770 GdkWindow *gdkwin; | |
4771 GList *l; | |
4772 | |
4773 gdkwin = gdk_window_at_pointer(&x, &y); | |
4774 | |
4775 if (gdkwin) | |
4776 gdkwin = gdk_window_get_toplevel(gdkwin); | |
4777 | |
4778 for (l = gaim_get_windows(); l != NULL; l = l->next) { | |
4779 win = (struct gaim_window *)l->data; | |
4780 | |
4781 if (gaim_window_get_ops(win) != gaim_get_gtk_window_ops()) | |
4782 continue; | |
4783 | |
4784 gtkwin = GAIM_GTK_WINDOW(win); | |
4785 | |
4786 if (gdkwin == gtkwin->window->window) | |
4787 return win; | |
4788 } | |
4789 | |
4790 return NULL; | |
4791 } | |
4792 | |
4793 int | |
4794 gaim_gtkconv_get_tab_at_xy(struct gaim_window *win, int x, int y) | |
4795 { | |
4796 struct gaim_gtk_window *gtkwin; | |
4797 GList *l; | |
4798 gint nb_x, nb_y, x_rel, y_rel; | |
4799 GtkNotebook *notebook; | |
4800 GtkWidget *tab; | |
4801 gint i, page_num = 0; | |
4802 gboolean first_visible = TRUE; | |
4803 | |
4804 if (gaim_window_get_ops(win) != gaim_get_gtk_window_ops()) | |
4805 return -1; | |
4806 | |
4807 gtkwin = GAIM_GTK_WINDOW(win); | |
4808 notebook = GTK_NOTEBOOK(gtkwin->notebook); | |
4809 | |
4810 gdk_window_get_origin(gtkwin->notebook->window, &nb_x, &nb_y); | |
4811 x_rel = x - nb_x; | |
4812 y_rel = y - nb_y; | |
4813 | |
4814 for (l = gaim_window_get_conversations(win), i = 0; | |
4815 l != NULL; | |
4816 l = l->next, i++) { | |
4817 | |
4818 struct gaim_conversation *conv = l->data; | |
4819 tab = GAIM_GTK_CONVERSATION(conv)->tab_label; | |
4820 | |
4821 if (!GTK_WIDGET_MAPPED(tab)) | |
4822 continue; | |
4823 | |
4824 if (first_visible) { | |
4825 first_visible = FALSE; | |
4826 | |
4827 if (x_rel < tab->allocation.x) x_rel = tab->allocation.x; | |
4828 if (y_rel < tab->allocation.y) y_rel = tab->allocation.y; | |
4829 } | |
4830 | |
4831 if (gtk_notebook_get_tab_pos(notebook) == GTK_POS_TOP || | |
4832 gtk_notebook_get_tab_pos(notebook) == GTK_POS_BOTTOM) { | |
4833 | |
4834 if (tab->allocation.x <= x_rel) { | |
4835 if (tab->allocation.x + tab->allocation.width <= x_rel) | |
4836 page_num = i + 1; | |
4837 else | |
4838 page_num = i; | |
4839 } | |
4840 else | |
4841 break; | |
4842 } | |
4843 else { | |
4844 if (tab->allocation.y <= y_rel) { | |
4845 if (tab->allocation.y + tab->allocation.height <= y_rel) | |
4846 page_num = i + 1; | |
4847 else | |
4848 page_num = i; | |
4849 } | |
4850 else | |
4851 break; | |
4852 } | |
4853 } | |
4854 | |
4855 if (i == gaim_window_get_conversation_count(win) + 1) | |
4856 return -1; | |
4857 | |
4858 return page_num; | |
4859 } | |
4860 | |
4861 int | |
4862 gaim_gtkconv_get_dest_tab_at_xy(struct gaim_window *win, int x, int y) | |
4863 { | |
4864 struct gaim_gtk_window *gtkwin; | |
4865 GList *l; | |
4866 gint nb_x, nb_y, x_rel, y_rel; | |
4867 GtkNotebook *notebook; | |
4868 GtkWidget *tab; | |
4869 gint i, page_num = 0; | |
4870 | |
4871 if (gaim_window_get_ops(win) != gaim_get_gtk_window_ops()) | |
4872 return -1; | |
4873 | |
4874 gtkwin = GAIM_GTK_WINDOW(win); | |
4875 notebook = GTK_NOTEBOOK(gtkwin->notebook); | |
4876 | |
4877 gdk_window_get_origin(gtkwin->notebook->window, &nb_x, &nb_y); | |
4878 x_rel = x - nb_x; | |
4879 y_rel = y - nb_y; | |
4880 | |
4881 for (l = gaim_window_get_conversations(win), i = 0; | |
4882 l != NULL; | |
4883 l = l->next, i++) { | |
4884 | |
4885 struct gaim_conversation *conv = l->data; | |
4886 tab = GAIM_GTK_CONVERSATION(conv)->tab_label; | |
4887 | |
4888 if (!GTK_WIDGET_MAPPED(tab)) | |
4889 continue; | |
4890 | |
4891 if (gtk_notebook_get_tab_pos(notebook) == GTK_POS_TOP || | |
4892 gtk_notebook_get_tab_pos(notebook) == GTK_POS_BOTTOM) { | |
4893 | |
4894 if (tab->allocation.x <= x_rel) { | |
4895 if (tab->allocation.x + (tab->allocation.width / 2) <= x_rel) | |
4896 page_num = i + 1; | |
4897 else | |
4898 page_num = i; | |
4899 } | |
4900 else | |
4901 break; | |
4902 } | |
4903 else { | |
4904 if (tab->allocation.y <= y_rel) { | |
4905 if (tab->allocation.y + (tab->allocation.height / 2) <= y_rel) | |
4906 page_num = i + 1; | |
4907 else | |
4908 page_num = i; | |
4909 } | |
4910 else | |
4911 break; | |
4912 } | |
4913 } | |
4914 | |
4915 if (i == gaim_window_get_conversation_count(win) + 1) | |
4916 return -1; | |
4917 | |
4918 return page_num; | |
4919 } |