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