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