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