Mercurial > pidgin.yaz
comparison gtk/gtkconv.c @ 14191:009db0b357b5
This is a hand-crafted commit to migrate across subversion revisions
16854:16861, due to some vagaries of the way the original renames were
done. Witness that monotone can do in one revision what svn had to
spread across several.
author | Ethan Blanton <elb@pidgin.im> |
---|---|
date | Sat, 16 Dec 2006 04:59:55 +0000 |
parents | |
children | c18bdf510325 |
comparison
equal
deleted
inserted
replaced
14190:366be2ce35a7 | 14191:009db0b357b5 |
---|---|
1 /** | |
2 * @file gtkconv.c GTK+ Conversation API | |
3 * @ingroup gtkui | |
4 * | |
5 * gaim | |
6 * | |
7 * Gaim is the legal property of its developers, whose names are too numerous | |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 * | |
25 */ | |
26 #include "internal.h" | |
27 #include "gtkgaim.h" | |
28 | |
29 #ifndef _WIN32 | |
30 # include <X11/Xlib.h> | |
31 #endif | |
32 | |
33 #ifdef USE_GTKSPELL | |
34 # include <gtkspell/gtkspell.h> | |
35 # ifdef _WIN32 | |
36 # include "wspell.h" | |
37 # endif | |
38 #endif | |
39 | |
40 #include <gdk/gdkkeysyms.h> | |
41 | |
42 #include "account.h" | |
43 #include "cmds.h" | |
44 #include "debug.h" | |
45 #include "idle.h" | |
46 #include "imgstore.h" | |
47 #include "log.h" | |
48 #include "notify.h" | |
49 #include "prpl.h" | |
50 #include "request.h" | |
51 #include "util.h" | |
52 | |
53 #include "gtkdnd-hints.h" | |
54 #include "gtkblist.h" | |
55 #include "gtkconv.h" | |
56 #include "gtkconvwin.h" | |
57 #include "gtkdialogs.h" | |
58 #include "gtkimhtml.h" | |
59 #include "gtkimhtmltoolbar.h" | |
60 #include "gtklog.h" | |
61 #include "gtkmenutray.h" | |
62 #include "gtkpounce.h" | |
63 #include "gtkprefs.h" | |
64 #include "gtkprivacy.h" | |
65 #include "gtkthemes.h" | |
66 #include "gtkutils.h" | |
67 #include "gaimstock.h" | |
68 | |
69 #include "gtknickcolors.h" | |
70 | |
71 #define AUTO_RESPONSE "<AUTO-REPLY> : " | |
72 | |
73 typedef enum | |
74 { | |
75 GAIM_GTKCONV_SET_TITLE = 1 << 0, | |
76 GAIM_GTKCONV_BUDDY_ICON = 1 << 1, | |
77 GAIM_GTKCONV_MENU = 1 << 2, | |
78 GAIM_GTKCONV_TAB_ICON = 1 << 3, | |
79 GAIM_GTKCONV_TOPIC = 1 << 4, | |
80 GAIM_GTKCONV_SMILEY_THEME = 1 << 5, | |
81 GAIM_GTKCONV_COLORIZE_TITLE = 1 << 6 | |
82 }GaimGtkConvFields; | |
83 | |
84 #define GAIM_GTKCONV_ALL ((1 << 7) - 1) | |
85 | |
86 #define SEND_COLOR "#204a87" | |
87 #define RECV_COLOR "#cc0000" | |
88 #define HIGHLIGHT_COLOR "#AF7F00" | |
89 | |
90 /* Undef this to turn off "custom-smiley" debug messages */ | |
91 #define DEBUG_CUSTOM_SMILEY | |
92 | |
93 #define LUMINANCE(c) (float)((0.3*(c.red))+(0.59*(c.green))+(0.11*(c.blue))) | |
94 | |
95 #if 0 | |
96 /* These colors come from the default GNOME palette */ | |
97 static GdkColor nick_colors[] = { | |
98 {0, 47616, 46336, 43776}, /* Basic 3D Medium */ | |
99 {0, 32768, 32000, 29696}, /* Basic 3D Dark */ | |
100 {0, 22016, 20992, 18432}, /* 3D Shadow */ | |
101 {0, 33536, 42496, 32512}, /* Green Medium */ | |
102 {0, 23808, 29952, 21760}, /* Green Dark */ | |
103 {0, 17408, 22016, 12800}, /* Green Shadow */ | |
104 {0, 57344, 46592, 44800}, /* Red Hilight */ | |
105 {0, 49408, 26112, 23040}, /* Red Medium */ | |
106 {0, 34816, 17920, 12544}, /* Red Dark */ | |
107 {0, 49408, 14336, 8704}, /* Red Shadow */ | |
108 {0, 34816, 32512, 41728}, /* Purple Medium */ | |
109 {0, 25088, 23296, 33024}, /* Purple Dark */ | |
110 {0, 18688, 16384, 26112}, /* Purple Shadow */ | |
111 {0, 40192, 47104, 53760}, /* Blue Hilight */ | |
112 {0, 29952, 36864, 44544}, /* Blue Medium */ | |
113 {0, 57344, 49920, 40448}, /* Face Skin Medium */ | |
114 {0, 45824, 37120, 26880}, /* Face skin Dark */ | |
115 {0, 33280, 26112, 18176}, /* Face Skin Shadow */ | |
116 {0, 57088, 16896, 7680}, /* Accent Red */ | |
117 {0, 39168, 0, 0}, /* Accent Red Dark */ | |
118 {0, 17920, 40960, 17920}, /* Accent Green */ | |
119 {0, 9728, 50944, 9728} /* Accent Green Dark */ | |
120 }; | |
121 | |
122 #define NUM_NICK_COLORS (sizeof(nick_colors) / sizeof(*nick_colors)) | |
123 #endif | |
124 | |
125 /* From http://www.w3.org/TR/AERT#color-contrast */ | |
126 #define MIN_BRIGHTNESS_CONTRAST 75 | |
127 #define MIN_COLOR_CONTRAST 200 | |
128 | |
129 #define NUM_NICK_COLORS 220 | |
130 static GdkColor *nick_colors = NULL; | |
131 static guint nbr_nick_colors; | |
132 | |
133 typedef struct { | |
134 GtkWidget *window; | |
135 | |
136 GtkWidget *entry; | |
137 GtkWidget *message; | |
138 | |
139 GaimConversation *conv; | |
140 | |
141 } InviteBuddyInfo; | |
142 | |
143 static GtkWidget *invite_dialog = NULL; | |
144 static GtkWidget *warn_close_dialog = NULL; | |
145 | |
146 static GaimGtkWindow *hidden_convwin = NULL; | |
147 static GList *window_list = NULL; | |
148 | |
149 | |
150 static gboolean update_send_to_selection(GaimGtkWindow *win); | |
151 static void generate_send_to_items(GaimGtkWindow *win); | |
152 | |
153 /* Prototypes. <-- because Paco-Paco hates this comment. */ | |
154 static void got_typing_keypress(GaimGtkConversation *gtkconv, gboolean first); | |
155 static void gray_stuff_out(GaimGtkConversation *gtkconv); | |
156 static GList *generate_invite_user_names(GaimConnection *gc); | |
157 static void add_chat_buddy_common(GaimConversation *conv, GaimConvChatBuddy *cb, const char *old_name); | |
158 static gboolean tab_complete(GaimConversation *conv); | |
159 static void gaim_gtkconv_updated(GaimConversation *conv, GaimConvUpdateType type); | |
160 static void gtkconv_set_unseen(GaimGtkConversation *gtkconv, GaimUnseenState state); | |
161 static void update_typing_icon(GaimGtkConversation *gtkconv); | |
162 static const char *item_factory_translate_func (const char *path, gpointer func_data); | |
163 gboolean gaim_gtkconv_has_focus(GaimConversation *conv); | |
164 static void gaim_gtkconv_custom_smiley_allocated(GdkPixbufLoader *loader, gpointer user_data); | |
165 static void gaim_gtkconv_custom_smiley_closed(GdkPixbufLoader *loader, gpointer user_data); | |
166 static GdkColor* generate_nick_colors(guint *numcolors, GdkColor background); | |
167 static gboolean color_is_visible(GdkColor foreground, GdkColor background, int color_contrast, int brightness_contrast); | |
168 static void gaim_gtkconv_update_fields(GaimConversation *conv, GaimGtkConvFields fields); | |
169 | |
170 static GdkColor *get_nick_color(GaimGtkConversation *gtkconv, const char *name) { | |
171 static GdkColor col; | |
172 GtkStyle *style = gtk_widget_get_style(gtkconv->imhtml); | |
173 float scale; | |
174 | |
175 col = nick_colors[g_str_hash(name) % nbr_nick_colors]; | |
176 scale = ((1-(LUMINANCE(style->base[GTK_STATE_NORMAL]) / LUMINANCE(style->white))) * | |
177 (LUMINANCE(style->white)/MAX(MAX(col.red, col.blue), col.green))); | |
178 | |
179 /* The colors are chosen to look fine on white; we should never have to darken */ | |
180 if (scale > 1) { | |
181 col.red *= scale; | |
182 col.green *= scale; | |
183 col.blue *= scale; | |
184 } | |
185 | |
186 return &col; | |
187 } | |
188 | |
189 /************************************************************************** | |
190 * Callbacks | |
191 **************************************************************************/ | |
192 | |
193 static gint | |
194 close_conv_cb(GtkWidget *w, GaimGtkConversation *gtkconv) | |
195 { | |
196 GList *list = g_list_copy(gtkconv->convs); | |
197 | |
198 g_list_foreach(list, (GFunc)gaim_conversation_destroy, NULL); | |
199 g_list_free(list); | |
200 | |
201 return TRUE; | |
202 } | |
203 | |
204 static gboolean | |
205 size_allocate_cb(GtkWidget *w, GtkAllocation *allocation, GaimGtkConversation *gtkconv) | |
206 { | |
207 GaimConversation *conv = gtkconv->active_conv; | |
208 | |
209 if (!GTK_WIDGET_VISIBLE(w)) | |
210 return FALSE; | |
211 | |
212 if (!GAIM_IS_GTK_CONVERSATION(conv)) | |
213 return FALSE; | |
214 | |
215 /* I find that I resize the window when it has a bunch of conversations in it, mostly so that the | |
216 * tab bar will fit, but then I don't want new windows taking up the entire screen. I check to see | |
217 * if there is only one conversation in the window. This way we'll be setting new windows to the | |
218 * size of the last resized new window. */ | |
219 /* I think that the above justification is not the majority, and that the new tab resizing should | |
220 * negate it anyway. --luke */ | |
221 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) | |
222 { | |
223 if (w == gtkconv->imhtml) { | |
224 gaim_prefs_set_int("/gaim/gtk/conversations/im/default_width", allocation->width); | |
225 gaim_prefs_set_int("/gaim/gtk/conversations/im/default_height", allocation->height); | |
226 } | |
227 if (w == gtkconv->entry) | |
228 gaim_prefs_set_int("/gaim/gtk/conversations/im/entry_height", allocation->height); | |
229 } | |
230 else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) | |
231 { | |
232 if (w == gtkconv->imhtml) { | |
233 gaim_prefs_set_int("/gaim/gtk/conversations/chat/default_width", allocation->width); | |
234 gaim_prefs_set_int("/gaim/gtk/conversations/chat/default_height", allocation->height); | |
235 } | |
236 if (w == gtkconv->entry) | |
237 gaim_prefs_set_int("/gaim/gtk/conversations/chat/entry_height", allocation->height); | |
238 } | |
239 | |
240 return FALSE; | |
241 } | |
242 | |
243 static void | |
244 default_formatize(GaimGtkConversation *c) | |
245 { | |
246 GaimConversation *conv = c->active_conv; | |
247 | |
248 if (conv->features & GAIM_CONNECTION_HTML) | |
249 { | |
250 char *color; | |
251 GdkColor fg_color, bg_color; | |
252 | |
253 if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_bold") != GTK_IMHTML(c->entry)->edit.bold) | |
254 gtk_imhtml_toggle_bold(GTK_IMHTML(c->entry)); | |
255 | |
256 if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_italic") != GTK_IMHTML(c->entry)->edit.italic) | |
257 gtk_imhtml_toggle_italic(GTK_IMHTML(c->entry)); | |
258 | |
259 if (gaim_prefs_get_bool("/gaim/gtk/conversations/send_underline") != GTK_IMHTML(c->entry)->edit.underline) | |
260 gtk_imhtml_toggle_underline(GTK_IMHTML(c->entry)); | |
261 | |
262 gtk_imhtml_toggle_fontface(GTK_IMHTML(c->entry), | |
263 gaim_prefs_get_string("/gaim/gtk/conversations/font_face")); | |
264 | |
265 if (!(conv->features & GAIM_CONNECTION_NO_FONTSIZE)) | |
266 gtk_imhtml_font_set_size(GTK_IMHTML(c->entry), | |
267 gaim_prefs_get_int("/gaim/gtk/conversations/font_size")); | |
268 | |
269 if(strcmp(gaim_prefs_get_string("/gaim/gtk/conversations/fgcolor"), "") != 0) | |
270 { | |
271 gdk_color_parse(gaim_prefs_get_string("/gaim/gtk/conversations/fgcolor"), | |
272 &fg_color); | |
273 color = g_strdup_printf("#%02x%02x%02x", | |
274 fg_color.red / 256, | |
275 fg_color.green / 256, | |
276 fg_color.blue / 256); | |
277 } | |
278 else | |
279 color = g_strdup(""); | |
280 | |
281 gtk_imhtml_toggle_forecolor(GTK_IMHTML(c->entry), color); | |
282 g_free(color); | |
283 | |
284 if(!(conv->features & GAIM_CONNECTION_NO_BGCOLOR) && | |
285 strcmp(gaim_prefs_get_string("/gaim/gtk/conversations/bgcolor"), "") != 0) | |
286 { | |
287 gdk_color_parse(gaim_prefs_get_string("/gaim/gtk/conversations/bgcolor"), | |
288 &bg_color); | |
289 color = g_strdup_printf("#%02x%02x%02x", | |
290 bg_color.red / 256, | |
291 bg_color.green / 256, | |
292 bg_color.blue / 256); | |
293 } | |
294 else | |
295 color = g_strdup(""); | |
296 | |
297 gtk_imhtml_toggle_background(GTK_IMHTML(c->entry), color); | |
298 g_free(color); | |
299 | |
300 | |
301 if (conv->features & GAIM_CONNECTION_FORMATTING_WBFO) | |
302 gtk_imhtml_set_whole_buffer_formatting_only(GTK_IMHTML(c->entry), TRUE); | |
303 else | |
304 gtk_imhtml_set_whole_buffer_formatting_only(GTK_IMHTML(c->entry), FALSE); | |
305 } | |
306 } | |
307 | |
308 static void | |
309 clear_formatting_cb(GtkIMHtml *imhtml, GaimGtkConversation *gtkconv) | |
310 { | |
311 default_formatize(gtkconv); | |
312 } | |
313 | |
314 static const char * | |
315 gaim_gtk_get_cmd_prefix(void) | |
316 { | |
317 return "/"; | |
318 } | |
319 | |
320 static GaimCmdRet | |
321 say_command_cb(GaimConversation *conv, | |
322 const char *cmd, char **args, char **error, void *data) | |
323 { | |
324 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) | |
325 gaim_conv_im_send(GAIM_CONV_IM(conv), args[0]); | |
326 else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) | |
327 gaim_conv_chat_send(GAIM_CONV_CHAT(conv), args[0]); | |
328 | |
329 return GAIM_CMD_RET_OK; | |
330 } | |
331 | |
332 static GaimCmdRet | |
333 me_command_cb(GaimConversation *conv, | |
334 const char *cmd, char **args, char **error, void *data) | |
335 { | |
336 char *tmp; | |
337 | |
338 tmp = g_strdup_printf("/me %s", args[0]); | |
339 | |
340 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) | |
341 gaim_conv_im_send(GAIM_CONV_IM(conv), tmp); | |
342 else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) | |
343 gaim_conv_chat_send(GAIM_CONV_CHAT(conv), tmp); | |
344 | |
345 g_free(tmp); | |
346 return GAIM_CMD_RET_OK; | |
347 } | |
348 | |
349 static GaimCmdRet | |
350 debug_command_cb(GaimConversation *conv, | |
351 const char *cmd, char **args, char **error, void *data) | |
352 { | |
353 char *tmp, *markup; | |
354 GaimCmdStatus status; | |
355 | |
356 if (!g_ascii_strcasecmp(args[0], "version")) { | |
357 tmp = g_strdup_printf("me is using Gaim v%s.", VERSION); | |
358 markup = g_markup_escape_text(tmp, -1); | |
359 | |
360 status = gaim_cmd_do_command(conv, tmp, markup, error); | |
361 | |
362 g_free(tmp); | |
363 g_free(markup); | |
364 return status; | |
365 } else { | |
366 gaim_conversation_write(conv, NULL, _("Supported debug options are: version"), | |
367 GAIM_MESSAGE_NO_LOG|GAIM_MESSAGE_ERROR, time(NULL)); | |
368 return GAIM_CMD_STATUS_OK; | |
369 } | |
370 } | |
371 | |
372 static GaimCmdRet | |
373 clear_command_cb(GaimConversation *conv, | |
374 const char *cmd, char **args, char **error, void *data) | |
375 { | |
376 GaimGtkConversation *gtkconv = NULL; | |
377 | |
378 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
379 | |
380 gtk_imhtml_clear(GTK_IMHTML(gtkconv->imhtml)); | |
381 return GAIM_CMD_STATUS_OK; | |
382 } | |
383 | |
384 static GaimCmdRet | |
385 help_command_cb(GaimConversation *conv, | |
386 const char *cmd, char **args, char **error, void *data) | |
387 { | |
388 GList *l, *text; | |
389 GString *s; | |
390 | |
391 if (args[0] != NULL) { | |
392 s = g_string_new(""); | |
393 text = gaim_cmd_help(conv, args[0]); | |
394 | |
395 if (text) { | |
396 for (l = text; l; l = l->next) | |
397 if (l->next) | |
398 g_string_append_printf(s, "%s\n", (char *)l->data); | |
399 else | |
400 g_string_append_printf(s, "%s", (char *)l->data); | |
401 } else { | |
402 g_string_append(s, _("No such command (in this context).")); | |
403 } | |
404 } else { | |
405 s = g_string_new(_("Use \"/help <command>\" for help on a specific command.\n" | |
406 "The following commands are available in this context:\n")); | |
407 | |
408 text = gaim_cmd_list(conv); | |
409 for (l = text; l; l = l->next) | |
410 if (l->next) | |
411 g_string_append_printf(s, "%s, ", (char *)l->data); | |
412 else | |
413 g_string_append_printf(s, "%s.", (char *)l->data); | |
414 g_list_free(text); | |
415 } | |
416 | |
417 gaim_conversation_write(conv, NULL, s->str, GAIM_MESSAGE_NO_LOG, time(NULL)); | |
418 g_string_free(s, TRUE); | |
419 | |
420 return GAIM_CMD_STATUS_OK; | |
421 } | |
422 | |
423 static void | |
424 send_history_add(GaimGtkConversation *gtkconv, const char *message) | |
425 { | |
426 GList *first; | |
427 | |
428 first = g_list_first(gtkconv->send_history); | |
429 g_free(first->data); | |
430 first->data = g_strdup(message); | |
431 gtkconv->send_history = g_list_prepend(first, NULL); | |
432 } | |
433 | |
434 static gboolean | |
435 check_for_and_do_command(GaimConversation *conv) | |
436 { | |
437 GaimGtkConversation *gtkconv; | |
438 char *cmd; | |
439 const char *prefix; | |
440 GtkTextIter start; | |
441 | |
442 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
443 prefix = gaim_gtk_get_cmd_prefix(); | |
444 | |
445 cmd = gtk_imhtml_get_text(GTK_IMHTML(gtkconv->entry), NULL, NULL); | |
446 gtk_text_buffer_get_start_iter(GTK_IMHTML(gtkconv->entry)->text_buffer, &start); | |
447 | |
448 if (cmd && (strncmp(cmd, prefix, strlen(prefix)) == 0) | |
449 && !gtk_text_iter_get_child_anchor(&start)) { | |
450 GaimCmdStatus status; | |
451 char *error, *cmdline, *markup, *send_history; | |
452 GtkTextIter end; | |
453 | |
454 send_history = gtk_imhtml_get_markup(GTK_IMHTML(gtkconv->entry)); | |
455 send_history_add(gtkconv, send_history); | |
456 g_free(send_history); | |
457 | |
458 cmdline = cmd + strlen(prefix); | |
459 | |
460 gtk_text_iter_forward_chars(&start, g_utf8_strlen(prefix, -1)); | |
461 gtk_text_buffer_get_end_iter(GTK_IMHTML(gtkconv->entry)->text_buffer, &end); | |
462 markup = gtk_imhtml_get_markup_range(GTK_IMHTML(gtkconv->entry), &start, &end); | |
463 status = gaim_cmd_do_command(conv, cmdline, markup, &error); | |
464 g_free(cmd); | |
465 g_free(markup); | |
466 | |
467 switch (status) { | |
468 case GAIM_CMD_STATUS_OK: | |
469 return TRUE; | |
470 case GAIM_CMD_STATUS_NOT_FOUND: | |
471 if (!gaim_prefs_get_bool("/gaim/gtk/conversations/passthrough_unknown_commands")) { | |
472 gaim_conversation_write(conv, "", _("No such command."), | |
473 GAIM_MESSAGE_NO_LOG, time(NULL)); | |
474 | |
475 return TRUE; | |
476 } | |
477 return FALSE; | |
478 case GAIM_CMD_STATUS_WRONG_ARGS: | |
479 gaim_conversation_write(conv, "", _("Syntax Error: You typed the wrong number of arguments " | |
480 "to that command."), | |
481 GAIM_MESSAGE_NO_LOG, time(NULL)); | |
482 return TRUE; | |
483 case GAIM_CMD_STATUS_FAILED: | |
484 gaim_conversation_write(conv, "", error ? error : _("Your command failed for an unknown reason."), | |
485 GAIM_MESSAGE_NO_LOG, time(NULL)); | |
486 g_free(error); | |
487 return TRUE; | |
488 case GAIM_CMD_STATUS_WRONG_TYPE: | |
489 if(gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) | |
490 gaim_conversation_write(conv, "", _("That command only works in chats, not IMs."), | |
491 GAIM_MESSAGE_NO_LOG, time(NULL)); | |
492 else | |
493 gaim_conversation_write(conv, "", _("That command only works in IMs, not chats."), | |
494 GAIM_MESSAGE_NO_LOG, time(NULL)); | |
495 return TRUE; | |
496 case GAIM_CMD_STATUS_WRONG_PRPL: | |
497 gaim_conversation_write(conv, "", _("That command doesn't work on this protocol."), | |
498 GAIM_MESSAGE_NO_LOG, time(NULL)); | |
499 return TRUE; | |
500 } | |
501 } | |
502 | |
503 g_free(cmd); | |
504 return FALSE; | |
505 } | |
506 | |
507 static void | |
508 send_cb(GtkWidget *widget, GaimGtkConversation *gtkconv) | |
509 { | |
510 GaimConversation *conv = gtkconv->active_conv; | |
511 GaimAccount *account; | |
512 GaimConnection *gc; | |
513 GaimMessageFlags flags = 0; | |
514 char *buf, *clean; | |
515 | |
516 account = gaim_conversation_get_account(conv); | |
517 | |
518 if (!gaim_account_is_connected(account)) | |
519 return; | |
520 | |
521 if ((gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) && | |
522 gaim_conv_chat_has_left(GAIM_CONV_CHAT(conv))) | |
523 return; | |
524 | |
525 if (check_for_and_do_command(conv)) { | |
526 gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry)); | |
527 return; | |
528 } | |
529 | |
530 buf = gtk_imhtml_get_markup(GTK_IMHTML(gtkconv->entry)); | |
531 clean = gtk_imhtml_get_text(GTK_IMHTML(gtkconv->entry), NULL, NULL); | |
532 | |
533 gtk_widget_grab_focus(gtkconv->entry); | |
534 | |
535 if (strlen(clean) == 0) { | |
536 g_free(buf); | |
537 g_free(clean); | |
538 return; | |
539 } | |
540 | |
541 gaim_idle_touch(); | |
542 | |
543 /* XXX: is there a better way to tell if the message has images? */ | |
544 if (GTK_IMHTML(gtkconv->entry)->im_images != NULL) | |
545 flags |= GAIM_MESSAGE_IMAGES; | |
546 | |
547 gc = gaim_account_get_connection(account); | |
548 if (gc && (conv->features & GAIM_CONNECTION_NO_NEWLINES)) { | |
549 char **bufs; | |
550 int i; | |
551 | |
552 bufs = gtk_imhtml_get_markup_lines(GTK_IMHTML(gtkconv->entry)); | |
553 for (i = 0; bufs[i]; i++) { | |
554 send_history_add(gtkconv, bufs[i]); | |
555 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) | |
556 gaim_conv_im_send_with_flags(GAIM_CONV_IM(conv), bufs[i], flags); | |
557 else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) | |
558 gaim_conv_chat_send_with_flags(GAIM_CONV_CHAT(conv), bufs[i], flags); | |
559 } | |
560 | |
561 g_strfreev(bufs); | |
562 | |
563 } else { | |
564 send_history_add(gtkconv, buf); | |
565 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) | |
566 gaim_conv_im_send_with_flags(GAIM_CONV_IM(conv), buf, flags); | |
567 else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) | |
568 gaim_conv_chat_send_with_flags(GAIM_CONV_CHAT(conv), buf, flags); | |
569 } | |
570 | |
571 g_free(clean); | |
572 g_free(buf); | |
573 | |
574 gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry)); | |
575 gtkconv_set_unseen(gtkconv, GAIM_UNSEEN_NONE); | |
576 } | |
577 | |
578 static void | |
579 add_remove_cb(GtkWidget *widget, GaimGtkConversation *gtkconv) | |
580 { | |
581 GaimAccount *account; | |
582 const char *name; | |
583 GaimConversation *conv = gtkconv->active_conv; | |
584 | |
585 account = gaim_conversation_get_account(conv); | |
586 name = gaim_conversation_get_name(conv); | |
587 | |
588 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) { | |
589 GaimBuddy *b; | |
590 | |
591 b = gaim_find_buddy(account, name); | |
592 if (b != NULL) | |
593 gaim_gtkdialogs_remove_buddy(b); | |
594 else if (account != NULL && gaim_account_is_connected(account)) | |
595 gaim_blist_request_add_buddy(account, (char *)name, NULL, NULL); | |
596 } else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) { | |
597 GaimChat *c; | |
598 | |
599 c = gaim_blist_find_chat(account, name); | |
600 if (c != NULL) | |
601 gaim_gtkdialogs_remove_chat(c); | |
602 else if (account != NULL && gaim_account_is_connected(account)) | |
603 gaim_blist_request_add_chat(account, NULL, NULL, name); | |
604 } | |
605 | |
606 gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); | |
607 } | |
608 | |
609 static void chat_do_info(GaimGtkConversation *gtkconv, const char *who) | |
610 { | |
611 GaimConversation *conv = gtkconv->active_conv; | |
612 GaimPluginProtocolInfo *prpl_info = NULL; | |
613 GaimConnection *gc; | |
614 | |
615 if ((gc = gaim_conversation_get_gc(conv))) { | |
616 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
617 | |
618 /* | |
619 * If there are special needs for getting info on users in | |
620 * buddy chat "rooms"... | |
621 */ | |
622 if (prpl_info->get_cb_info != NULL) | |
623 { | |
624 prpl_info->get_cb_info(gc, | |
625 gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), who); | |
626 } | |
627 else | |
628 prpl_info->get_info(gc, who); | |
629 } | |
630 } | |
631 | |
632 | |
633 static void | |
634 info_cb(GtkWidget *widget, GaimGtkConversation *gtkconv) | |
635 { | |
636 GaimConversation *conv = gtkconv->active_conv; | |
637 | |
638 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) { | |
639 serv_get_info(gaim_conversation_get_gc(conv), | |
640 gaim_conversation_get_name(conv)); | |
641 | |
642 gtk_widget_grab_focus(gtkconv->entry); | |
643 } else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) { | |
644 /* Get info of the person currently selected in the GtkTreeView */ | |
645 GaimGtkChatPane *gtkchat; | |
646 GtkTreeIter iter; | |
647 GtkTreeModel *model; | |
648 GtkTreeSelection *sel; | |
649 char *name; | |
650 | |
651 gtkchat = gtkconv->u.chat; | |
652 | |
653 model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); | |
654 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkchat->list)); | |
655 | |
656 if (gtk_tree_selection_get_selected(sel, NULL, &iter)) | |
657 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CHAT_USERS_NAME_COLUMN, &name, -1); | |
658 else | |
659 return; | |
660 | |
661 chat_do_info(gtkconv, name); | |
662 g_free(name); | |
663 } | |
664 } | |
665 | |
666 static void | |
667 block_cb(GtkWidget *widget, GaimGtkConversation *gtkconv) | |
668 { | |
669 GaimConversation *conv = gtkconv->active_conv; | |
670 GaimAccount *account; | |
671 | |
672 account = gaim_conversation_get_account(conv); | |
673 | |
674 if (account != NULL && gaim_account_is_connected(account)) | |
675 gaim_gtk_request_add_block(account, gaim_conversation_get_name(conv)); | |
676 | |
677 gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); | |
678 } | |
679 | |
680 static void | |
681 do_invite(GtkWidget *w, int resp, InviteBuddyInfo *info) | |
682 { | |
683 const char *buddy, *message; | |
684 GaimGtkConversation *gtkconv; | |
685 | |
686 gtkconv = GAIM_GTK_CONVERSATION(info->conv); | |
687 | |
688 if (resp == GTK_RESPONSE_OK) { | |
689 buddy = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(info->entry)->entry)); | |
690 message = gtk_entry_get_text(GTK_ENTRY(info->message)); | |
691 | |
692 if (!g_ascii_strcasecmp(buddy, "")) | |
693 return; | |
694 | |
695 serv_chat_invite(gaim_conversation_get_gc(info->conv), | |
696 gaim_conv_chat_get_id(GAIM_CONV_CHAT(info->conv)), | |
697 message, buddy); | |
698 } | |
699 | |
700 gtk_widget_destroy(invite_dialog); | |
701 invite_dialog = NULL; | |
702 | |
703 g_free(info); | |
704 } | |
705 | |
706 static void | |
707 invite_dnd_recv(GtkWidget *widget, GdkDragContext *dc, gint x, gint y, | |
708 GtkSelectionData *sd, guint inf, guint t, gpointer data) | |
709 { | |
710 InviteBuddyInfo *info = (InviteBuddyInfo *)data; | |
711 const char *convprotocol; | |
712 | |
713 convprotocol = gaim_account_get_protocol_id(gaim_conversation_get_account(info->conv)); | |
714 | |
715 if (sd->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE)) | |
716 { | |
717 GaimBlistNode *node = NULL; | |
718 GaimBuddy *buddy; | |
719 | |
720 memcpy(&node, sd->data, sizeof(node)); | |
721 | |
722 if (GAIM_BLIST_NODE_IS_CONTACT(node)) | |
723 buddy = gaim_contact_get_priority_buddy((GaimContact *)node); | |
724 else if (GAIM_BLIST_NODE_IS_BUDDY(node)) | |
725 buddy = (GaimBuddy *)node; | |
726 else | |
727 return; | |
728 | |
729 if (strcmp(convprotocol, gaim_account_get_protocol_id(buddy->account))) | |
730 { | |
731 gaim_notify_error(GAIM_GTK_CONVERSATION(info->conv), NULL, | |
732 _("That buddy is not on the same protocol as this " | |
733 "chat."), NULL); | |
734 } | |
735 else | |
736 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(info->entry)->entry), buddy->name); | |
737 | |
738 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); | |
739 } | |
740 else if (sd->target == gdk_atom_intern("application/x-im-contact", FALSE)) | |
741 { | |
742 char *protocol = NULL; | |
743 char *username = NULL; | |
744 GaimAccount *account; | |
745 | |
746 if (gaim_gtk_parse_x_im_contact((const char *)sd->data, FALSE, &account, | |
747 &protocol, &username, NULL)) | |
748 { | |
749 if (account == NULL) | |
750 { | |
751 gaim_notify_error(GAIM_GTK_CONVERSATION(info->conv), NULL, | |
752 _("You are not currently signed on with an account that " | |
753 "can invite that buddy."), NULL); | |
754 } | |
755 else if (strcmp(convprotocol, gaim_account_get_protocol_id(account))) | |
756 { | |
757 gaim_notify_error(GAIM_GTK_CONVERSATION(info->conv), NULL, | |
758 _("That buddy is not on the same protocol as this " | |
759 "chat."), NULL); | |
760 } | |
761 else | |
762 { | |
763 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(info->entry)->entry), username); | |
764 } | |
765 } | |
766 | |
767 g_free(username); | |
768 g_free(protocol); | |
769 | |
770 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); | |
771 } | |
772 } | |
773 | |
774 static const GtkTargetEntry dnd_targets[] = | |
775 { | |
776 {"GAIM_BLIST_NODE", GTK_TARGET_SAME_APP, 0}, | |
777 {"application/x-im-contact", 0, 1} | |
778 }; | |
779 | |
780 static void | |
781 invite_cb(GtkWidget *widget, GaimGtkConversation *gtkconv) | |
782 { | |
783 GaimConversation *conv = gtkconv->active_conv; | |
784 InviteBuddyInfo *info = NULL; | |
785 | |
786 if (invite_dialog == NULL) { | |
787 GaimConnection *gc; | |
788 GaimGtkWindow *gtkwin; | |
789 GtkWidget *label; | |
790 GtkWidget *vbox, *hbox; | |
791 GtkWidget *table; | |
792 GtkWidget *img; | |
793 | |
794 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, | |
795 GTK_ICON_SIZE_DIALOG); | |
796 | |
797 info = g_new0(InviteBuddyInfo, 1); | |
798 info->conv = conv; | |
799 | |
800 gc = gaim_conversation_get_gc(conv); | |
801 gtkwin = gaim_gtkconv_get_window(gtkconv); | |
802 | |
803 /* Create the new dialog. */ | |
804 invite_dialog = gtk_dialog_new_with_buttons( | |
805 _("Invite Buddy Into Chat Room"), | |
806 GTK_WINDOW(gtkwin->window), 0, | |
807 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
808 GAIM_STOCK_INVITE, GTK_RESPONSE_OK, NULL); | |
809 | |
810 gtk_dialog_set_default_response(GTK_DIALOG(invite_dialog), | |
811 GTK_RESPONSE_OK); | |
812 gtk_container_set_border_width(GTK_CONTAINER(invite_dialog), GAIM_HIG_BOX_SPACE); | |
813 gtk_window_set_resizable(GTK_WINDOW(invite_dialog), FALSE); | |
814 gtk_dialog_set_has_separator(GTK_DIALOG(invite_dialog), FALSE); | |
815 | |
816 info->window = GTK_WIDGET(invite_dialog); | |
817 | |
818 /* Setup the outside spacing. */ | |
819 vbox = GTK_DIALOG(invite_dialog)->vbox; | |
820 | |
821 gtk_box_set_spacing(GTK_BOX(vbox), GAIM_HIG_BORDER); | |
822 gtk_container_set_border_width(GTK_CONTAINER(vbox), GAIM_HIG_BOX_SPACE); | |
823 | |
824 /* Setup the inner hbox and put the dialog's icon in it. */ | |
825 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BORDER); | |
826 gtk_container_add(GTK_CONTAINER(vbox), hbox); | |
827 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
828 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
829 | |
830 /* Setup the right vbox. */ | |
831 vbox = gtk_vbox_new(FALSE, 0); | |
832 gtk_container_add(GTK_CONTAINER(hbox), vbox); | |
833 | |
834 /* Put our happy label in it. */ | |
835 label = gtk_label_new(_("Please enter the name of the user you wish " | |
836 "to invite, along with an optional invite " | |
837 "message.")); | |
838 gtk_widget_set_size_request(label, 350, -1); | |
839 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
840 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
841 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
842 | |
843 /* hbox for the table, and to give it some spacing on the left. */ | |
844 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
845 gtk_container_add(GTK_CONTAINER(vbox), hbox); | |
846 | |
847 /* Setup the table we're going to use to lay stuff out. */ | |
848 table = gtk_table_new(2, 2, FALSE); | |
849 gtk_table_set_row_spacings(GTK_TABLE(table), GAIM_HIG_BOX_SPACE); | |
850 gtk_table_set_col_spacings(GTK_TABLE(table), GAIM_HIG_BOX_SPACE); | |
851 gtk_container_set_border_width(GTK_CONTAINER(table), GAIM_HIG_BORDER); | |
852 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); | |
853 | |
854 /* Now the Buddy label */ | |
855 label = gtk_label_new(NULL); | |
856 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Buddy:")); | |
857 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
858 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); | |
859 | |
860 /* Now the Buddy drop-down entry field. */ | |
861 info->entry = gtk_combo_new(); | |
862 gtk_combo_set_case_sensitive(GTK_COMBO(info->entry), FALSE); | |
863 gtk_entry_set_activates_default( | |
864 GTK_ENTRY(GTK_COMBO(info->entry)->entry), TRUE); | |
865 | |
866 gtk_table_attach_defaults(GTK_TABLE(table), info->entry, 1, 2, 0, 1); | |
867 gtk_label_set_mnemonic_widget(GTK_LABEL(label), info->entry); | |
868 | |
869 /* Fill in the names. */ | |
870 gtk_combo_set_popdown_strings(GTK_COMBO(info->entry), | |
871 generate_invite_user_names(gc)); | |
872 | |
873 | |
874 /* Now the label for "Message" */ | |
875 label = gtk_label_new(NULL); | |
876 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Message:")); | |
877 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
878 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2); | |
879 | |
880 | |
881 /* And finally, the Message entry field. */ | |
882 info->message = gtk_entry_new(); | |
883 gtk_entry_set_activates_default(GTK_ENTRY(info->message), TRUE); | |
884 | |
885 gtk_table_attach_defaults(GTK_TABLE(table), info->message, 1, 2, 1, 2); | |
886 gtk_label_set_mnemonic_widget(GTK_LABEL(label), info->message); | |
887 | |
888 /* Connect the signals. */ | |
889 g_signal_connect(G_OBJECT(invite_dialog), "response", | |
890 G_CALLBACK(do_invite), info); | |
891 /* Setup drag-and-drop */ | |
892 gtk_drag_dest_set(info->window, | |
893 GTK_DEST_DEFAULT_MOTION | | |
894 GTK_DEST_DEFAULT_DROP, | |
895 dnd_targets, | |
896 sizeof(dnd_targets) / sizeof(GtkTargetEntry), | |
897 GDK_ACTION_COPY); | |
898 gtk_drag_dest_set(info->entry, | |
899 GTK_DEST_DEFAULT_MOTION | | |
900 GTK_DEST_DEFAULT_DROP, | |
901 dnd_targets, | |
902 sizeof(dnd_targets) / sizeof(GtkTargetEntry), | |
903 GDK_ACTION_COPY); | |
904 | |
905 g_signal_connect(G_OBJECT(info->window), "drag_data_received", | |
906 G_CALLBACK(invite_dnd_recv), info); | |
907 g_signal_connect(G_OBJECT(info->entry), "drag_data_received", | |
908 G_CALLBACK(invite_dnd_recv), info); | |
909 | |
910 } | |
911 | |
912 gtk_widget_show_all(invite_dialog); | |
913 | |
914 if (info != NULL) | |
915 gtk_widget_grab_focus(GTK_COMBO(info->entry)->entry); | |
916 } | |
917 | |
918 static void | |
919 menu_new_conv_cb(gpointer data, guint action, GtkWidget *widget) | |
920 { | |
921 gaim_gtkdialogs_im(); | |
922 } | |
923 | |
924 static void | |
925 savelog_writefile_cb(void *user_data, const char *filename) | |
926 { | |
927 GaimConversation *conv = (GaimConversation *)user_data; | |
928 FILE *fp; | |
929 const char *name; | |
930 gchar *text; | |
931 | |
932 if ((fp = g_fopen(filename, "w+")) == NULL) { | |
933 gaim_notify_error(GAIM_GTK_CONVERSATION(conv), NULL, _("Unable to open file."), NULL); | |
934 return; | |
935 } | |
936 | |
937 name = gaim_conversation_get_name(conv); | |
938 fprintf(fp, "<html>\n<head><title>%s</title></head>\n<body>", name); | |
939 fprintf(fp, _("<h1>Conversation with %s</h1>\n"), name); | |
940 | |
941 text = gtk_imhtml_get_markup( | |
942 GTK_IMHTML(GAIM_GTK_CONVERSATION(conv)->imhtml)); | |
943 fprintf(fp, "%s", text); | |
944 g_free(text); | |
945 | |
946 fprintf(fp, "\n</body>\n</html>\n"); | |
947 fclose(fp); | |
948 } | |
949 | |
950 /* | |
951 * It would be kinda cool if this gave the option of saving a | |
952 * plaintext v. HTML file. | |
953 */ | |
954 static void | |
955 menu_save_as_cb(gpointer data, guint action, GtkWidget *widget) | |
956 { | |
957 GaimGtkWindow *win = data; | |
958 GaimConversation *conv = gaim_gtk_conv_window_get_active_conversation(win); | |
959 gchar *buf; | |
960 | |
961 buf = g_strdup_printf("%s.html", gaim_normalize(conv->account, conv->name)); | |
962 | |
963 gaim_request_file(GAIM_GTK_CONVERSATION(conv), _("Save Conversation"), | |
964 gaim_escape_filename(buf), | |
965 TRUE, G_CALLBACK(savelog_writefile_cb), NULL, conv); | |
966 | |
967 g_free(buf); | |
968 } | |
969 | |
970 static void | |
971 menu_view_log_cb(gpointer data, guint action, GtkWidget *widget) | |
972 { | |
973 GaimGtkWindow *win = data; | |
974 GaimConversation *conv; | |
975 GaimLogType type; | |
976 GaimGtkBuddyList *gtkblist; | |
977 GdkCursor *cursor; | |
978 const char *name; | |
979 GaimAccount *account; | |
980 GSList *buddies; | |
981 GSList *cur; | |
982 | |
983 conv = gaim_gtk_conv_window_get_active_conversation(win); | |
984 | |
985 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) | |
986 type = GAIM_LOG_IM; | |
987 else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) | |
988 type = GAIM_LOG_CHAT; | |
989 else | |
990 return; | |
991 | |
992 gtkblist = gaim_gtk_blist_get_default_gtk_blist(); | |
993 | |
994 cursor = gdk_cursor_new(GDK_WATCH); | |
995 gdk_window_set_cursor(gtkblist->window->window, cursor); | |
996 gdk_window_set_cursor(win->window->window, cursor); | |
997 gdk_cursor_unref(cursor); | |
998 #if GTK_CHECK_VERSION(2,4,0) | |
999 gdk_display_flush(gdk_drawable_get_display(GDK_DRAWABLE(widget->window))); | |
1000 #else | |
1001 gdk_flush(); | |
1002 #endif | |
1003 | |
1004 name = gaim_conversation_get_name(conv); | |
1005 account = gaim_conversation_get_account(conv); | |
1006 | |
1007 buddies = gaim_find_buddies(account, name); | |
1008 for (cur = buddies; cur != NULL; cur = cur->next) | |
1009 { | |
1010 GaimBlistNode *node = cur->data; | |
1011 if ((node != NULL) && ((node->prev != NULL) || (node->next != NULL))) | |
1012 { | |
1013 gaim_gtk_log_show_contact((GaimContact *)node->parent); | |
1014 g_slist_free(buddies); | |
1015 gdk_window_set_cursor(gtkblist->window->window, NULL); | |
1016 gdk_window_set_cursor(win->window->window, NULL); | |
1017 return; | |
1018 } | |
1019 } | |
1020 g_slist_free(buddies); | |
1021 | |
1022 gaim_gtk_log_show(type, name, account); | |
1023 | |
1024 gdk_window_set_cursor(gtkblist->window->window, NULL); | |
1025 gdk_window_set_cursor(win->window->window, NULL); | |
1026 } | |
1027 | |
1028 static void | |
1029 menu_clear_cb(gpointer data, guint action, GtkWidget *widget) | |
1030 { | |
1031 GaimGtkWindow *win = data; | |
1032 GaimConversation *conv; | |
1033 GaimGtkConversation *gtkconv; | |
1034 | |
1035 conv = gaim_gtk_conv_window_get_active_conversation(win); | |
1036 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
1037 | |
1038 gtk_imhtml_clear(GTK_IMHTML(gtkconv->imhtml)); | |
1039 } | |
1040 | |
1041 struct _search { | |
1042 GaimGtkConversation *gtkconv; | |
1043 GtkWidget *entry; | |
1044 }; | |
1045 | |
1046 static void do_search_cb(GtkWidget *widget, gint resp, struct _search *s) | |
1047 { | |
1048 switch (resp) { | |
1049 case GTK_RESPONSE_OK: | |
1050 gtk_imhtml_search_find(GTK_IMHTML(s->gtkconv->imhtml), | |
1051 gtk_entry_get_text(GTK_ENTRY(s->entry))); | |
1052 break; | |
1053 | |
1054 case GTK_RESPONSE_DELETE_EVENT: | |
1055 case GTK_RESPONSE_CLOSE: | |
1056 gtk_imhtml_search_clear(GTK_IMHTML(s->gtkconv->imhtml)); | |
1057 gtk_widget_destroy(s->gtkconv->dialogs.search); | |
1058 s->gtkconv->dialogs.search = NULL; | |
1059 g_free(s); | |
1060 break; | |
1061 } | |
1062 } | |
1063 | |
1064 static void | |
1065 menu_find_cb(gpointer data, guint action, GtkWidget *widget) | |
1066 { | |
1067 GaimGtkWindow *gtkwin = data; | |
1068 GaimConversation *conv = gaim_gtk_conv_window_get_active_conversation(gtkwin); | |
1069 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv); | |
1070 GtkWidget *hbox; | |
1071 GtkWidget *img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, | |
1072 GTK_ICON_SIZE_DIALOG); | |
1073 GtkWidget *label; | |
1074 struct _search *s; | |
1075 | |
1076 if (gtkconv->dialogs.search) { | |
1077 gtk_window_present(GTK_WINDOW(gtkconv->dialogs.search)); | |
1078 return; | |
1079 } | |
1080 | |
1081 s = g_malloc(sizeof(struct _search)); | |
1082 s->gtkconv = gtkconv; | |
1083 | |
1084 gtkconv->dialogs.search = gtk_dialog_new_with_buttons(_("Find"), | |
1085 GTK_WINDOW(gtkwin->window), GTK_DIALOG_DESTROY_WITH_PARENT, | |
1086 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, | |
1087 GTK_STOCK_FIND, GTK_RESPONSE_OK, NULL); | |
1088 gtk_dialog_set_default_response(GTK_DIALOG(gtkconv->dialogs.search), | |
1089 GTK_RESPONSE_OK); | |
1090 g_signal_connect(G_OBJECT(gtkconv->dialogs.search), "response", | |
1091 G_CALLBACK(do_search_cb), s); | |
1092 | |
1093 gtk_container_set_border_width(GTK_CONTAINER(gtkconv->dialogs.search), GAIM_HIG_BOX_SPACE); | |
1094 gtk_window_set_resizable(GTK_WINDOW(gtkconv->dialogs.search), FALSE); | |
1095 gtk_dialog_set_has_separator(GTK_DIALOG(gtkconv->dialogs.search), FALSE); | |
1096 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(gtkconv->dialogs.search)->vbox), GAIM_HIG_BORDER); | |
1097 gtk_container_set_border_width( | |
1098 GTK_CONTAINER(GTK_DIALOG(gtkconv->dialogs.search)->vbox), GAIM_HIG_BOX_SPACE); | |
1099 | |
1100 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BORDER); | |
1101 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(gtkconv->dialogs.search)->vbox), | |
1102 hbox); | |
1103 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
1104 | |
1105 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
1106 gtk_dialog_set_response_sensitive(GTK_DIALOG(gtkconv->dialogs.search), | |
1107 GTK_RESPONSE_OK, FALSE); | |
1108 | |
1109 label = gtk_label_new(NULL); | |
1110 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Search for:")); | |
1111 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1112 | |
1113 s->entry = gtk_entry_new(); | |
1114 gtk_entry_set_activates_default(GTK_ENTRY(s->entry), TRUE); | |
1115 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(s->entry)); | |
1116 g_signal_connect(G_OBJECT(s->entry), "changed", | |
1117 G_CALLBACK(gaim_gtk_set_sensitive_if_input), | |
1118 gtkconv->dialogs.search); | |
1119 gtk_box_pack_start(GTK_BOX(hbox), s->entry, FALSE, FALSE, 0); | |
1120 | |
1121 gtk_widget_show_all(gtkconv->dialogs.search); | |
1122 gtk_widget_grab_focus(s->entry); | |
1123 } | |
1124 | |
1125 static void | |
1126 menu_send_file_cb(gpointer data, guint action, GtkWidget *widget) | |
1127 { | |
1128 GaimGtkWindow *win = data; | |
1129 GaimConversation *conv = gaim_gtk_conv_window_get_active_conversation(win); | |
1130 | |
1131 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) { | |
1132 serv_send_file(gaim_conversation_get_gc(conv), gaim_conversation_get_name(conv), NULL); | |
1133 } | |
1134 | |
1135 } | |
1136 | |
1137 static void | |
1138 menu_add_pounce_cb(gpointer data, guint action, GtkWidget *widget) | |
1139 { | |
1140 GaimGtkWindow *win = data; | |
1141 GaimConversation *conv; | |
1142 | |
1143 conv = gaim_gtk_conv_window_get_active_gtkconv(win)->active_conv; | |
1144 | |
1145 gaim_gtk_pounce_editor_show(gaim_conversation_get_account(conv), | |
1146 gaim_conversation_get_name(conv), NULL); | |
1147 } | |
1148 | |
1149 static void | |
1150 menu_insert_link_cb(gpointer data, guint action, GtkWidget *widget) | |
1151 { | |
1152 GaimGtkWindow *win = data; | |
1153 GaimGtkConversation *gtkconv; | |
1154 GtkIMHtmlToolbar *toolbar; | |
1155 | |
1156 gtkconv = gaim_gtk_conv_window_get_active_gtkconv(win); | |
1157 toolbar = GTK_IMHTMLTOOLBAR(gtkconv->toolbar); | |
1158 | |
1159 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->link), | |
1160 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->link))); | |
1161 } | |
1162 | |
1163 static void | |
1164 menu_insert_image_cb(gpointer data, guint action, GtkWidget *widget) | |
1165 { | |
1166 GaimGtkWindow *win = data; | |
1167 GaimConversation *conv; | |
1168 GaimGtkConversation *gtkconv; | |
1169 GtkIMHtmlToolbar *toolbar; | |
1170 | |
1171 gtkconv = gaim_gtk_conv_window_get_active_gtkconv(win); | |
1172 conv = gtkconv->active_conv; | |
1173 toolbar = GTK_IMHTMLTOOLBAR(gtkconv->toolbar); | |
1174 | |
1175 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image), | |
1176 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->image))); | |
1177 } | |
1178 | |
1179 static void | |
1180 menu_alias_cb(gpointer data, guint action, GtkWidget *widget) | |
1181 { | |
1182 GaimGtkWindow *win = data; | |
1183 GaimConversation *conv; | |
1184 GaimAccount *account; | |
1185 const char *name; | |
1186 | |
1187 conv = gaim_gtk_conv_window_get_active_conversation(win); | |
1188 account = gaim_conversation_get_account(conv); | |
1189 name = gaim_conversation_get_name(conv); | |
1190 | |
1191 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) { | |
1192 GaimBuddy *b; | |
1193 | |
1194 b = gaim_find_buddy(account, name); | |
1195 if (b != NULL) | |
1196 gaim_gtkdialogs_alias_buddy(b); | |
1197 } else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) { | |
1198 GaimChat *c; | |
1199 | |
1200 c = gaim_blist_find_chat(account, name); | |
1201 if (c != NULL) | |
1202 gaim_gtkdialogs_alias_chat(c); | |
1203 } | |
1204 } | |
1205 | |
1206 static void | |
1207 menu_get_info_cb(gpointer data, guint action, GtkWidget *widget) | |
1208 { | |
1209 GaimGtkWindow *win = data; | |
1210 GaimConversation *conv; | |
1211 | |
1212 conv = gaim_gtk_conv_window_get_active_conversation(win); | |
1213 | |
1214 info_cb(NULL, GAIM_GTK_CONVERSATION(conv)); | |
1215 } | |
1216 | |
1217 static void | |
1218 menu_invite_cb(gpointer data, guint action, GtkWidget *widget) | |
1219 { | |
1220 GaimGtkWindow *win = data; | |
1221 GaimConversation *conv; | |
1222 | |
1223 conv = gaim_gtk_conv_window_get_active_conversation(win); | |
1224 | |
1225 invite_cb(NULL, GAIM_GTK_CONVERSATION(conv)); | |
1226 } | |
1227 | |
1228 static void | |
1229 menu_block_cb(gpointer data, guint action, GtkWidget *widget) | |
1230 { | |
1231 GaimGtkWindow *win = data; | |
1232 GaimConversation *conv; | |
1233 | |
1234 conv = gaim_gtk_conv_window_get_active_conversation(win); | |
1235 | |
1236 block_cb(NULL, GAIM_GTK_CONVERSATION(conv)); | |
1237 } | |
1238 | |
1239 static void | |
1240 menu_add_remove_cb(gpointer data, guint action, GtkWidget *widget) | |
1241 { | |
1242 GaimGtkWindow *win = data; | |
1243 GaimConversation *conv; | |
1244 | |
1245 conv = gaim_gtk_conv_window_get_active_conversation(win); | |
1246 | |
1247 add_remove_cb(NULL, GAIM_GTK_CONVERSATION(conv)); | |
1248 } | |
1249 | |
1250 static void | |
1251 menu_close_conv_cb(gpointer data, guint action, GtkWidget *widget) | |
1252 { | |
1253 GaimGtkWindow *win = data; | |
1254 | |
1255 close_conv_cb(NULL, GAIM_GTK_CONVERSATION(gaim_gtk_conv_window_get_active_conversation(win))); | |
1256 } | |
1257 | |
1258 static void | |
1259 menu_logging_cb(gpointer data, guint action, GtkWidget *widget) | |
1260 { | |
1261 GaimGtkWindow *win = data; | |
1262 GaimConversation *conv; | |
1263 gboolean logging; | |
1264 | |
1265 conv = gaim_gtk_conv_window_get_active_conversation(win); | |
1266 | |
1267 if (conv == NULL) | |
1268 return; | |
1269 | |
1270 logging = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); | |
1271 | |
1272 if (logging == gaim_conversation_is_logging(conv)) | |
1273 return; | |
1274 | |
1275 if (logging) | |
1276 { | |
1277 /* Enable logging first so the message below can be logged. */ | |
1278 gaim_conversation_set_logging(conv, TRUE); | |
1279 | |
1280 gaim_conversation_write(conv, NULL, | |
1281 _("Logging started. Future messages in this conversation will be logged."), | |
1282 conv->logs ? (GAIM_MESSAGE_SYSTEM) : | |
1283 (GAIM_MESSAGE_SYSTEM | GAIM_MESSAGE_NO_LOG), | |
1284 time(NULL)); | |
1285 } | |
1286 else | |
1287 { | |
1288 gaim_conversation_write(conv, NULL, | |
1289 _("Logging stopped. Future messages in this conversation will not be logged."), | |
1290 conv->logs ? (GAIM_MESSAGE_SYSTEM) : | |
1291 (GAIM_MESSAGE_SYSTEM | GAIM_MESSAGE_NO_LOG), | |
1292 time(NULL)); | |
1293 | |
1294 /* Disable the logging second, so that the above message can be logged. */ | |
1295 gaim_conversation_set_logging(conv, FALSE); | |
1296 } | |
1297 } | |
1298 | |
1299 static void | |
1300 menu_toolbar_cb(gpointer data, guint action, GtkWidget *widget) | |
1301 { | |
1302 gaim_prefs_set_bool("/gaim/gtk/conversations/show_formatting_toolbar", | |
1303 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))); | |
1304 } | |
1305 | |
1306 static void | |
1307 menu_sounds_cb(gpointer data, guint action, GtkWidget *widget) | |
1308 { | |
1309 GaimGtkWindow *win = data; | |
1310 GaimConversation *conv; | |
1311 GaimGtkConversation *gtkconv; | |
1312 | |
1313 conv = gaim_gtk_conv_window_get_active_conversation(win); | |
1314 | |
1315 if (!conv) | |
1316 return; | |
1317 | |
1318 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
1319 | |
1320 gtkconv->make_sound = | |
1321 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); | |
1322 } | |
1323 | |
1324 static void | |
1325 menu_timestamps_cb(gpointer data, guint action, GtkWidget *widget) | |
1326 { | |
1327 gaim_prefs_set_bool("/gaim/gtk/conversations/show_timestamps", | |
1328 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))); | |
1329 } | |
1330 | |
1331 static void | |
1332 chat_do_im(GaimGtkConversation *gtkconv, const char *who) | |
1333 { | |
1334 GaimConversation *conv = gtkconv->active_conv; | |
1335 GaimAccount *account; | |
1336 GaimConnection *gc; | |
1337 GaimPluginProtocolInfo *prpl_info = NULL; | |
1338 char *real_who; | |
1339 | |
1340 account = gaim_conversation_get_account(conv); | |
1341 g_return_if_fail(account != NULL); | |
1342 | |
1343 gc = gaim_account_get_connection(account); | |
1344 g_return_if_fail(gc != NULL); | |
1345 | |
1346 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
1347 | |
1348 if (prpl_info && prpl_info->get_cb_real_name) | |
1349 real_who = prpl_info->get_cb_real_name(gc, | |
1350 gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), who); | |
1351 else | |
1352 real_who = g_strdup(who); | |
1353 | |
1354 if(!real_who) | |
1355 return; | |
1356 | |
1357 gaim_gtkdialogs_im_with_user(account, real_who); | |
1358 | |
1359 g_free(real_who); | |
1360 } | |
1361 | |
1362 static void | |
1363 ignore_cb(GtkWidget *w, GaimGtkConversation *gtkconv) | |
1364 { | |
1365 GaimConversation *conv = gtkconv->active_conv; | |
1366 GaimGtkChatPane *gtkchat; | |
1367 GaimConvChatBuddy *cbuddy; | |
1368 GaimConvChat *chat; | |
1369 GaimConvChatBuddyFlags flags; | |
1370 GtkTreeIter iter; | |
1371 GtkTreeModel *model; | |
1372 GtkTreeSelection *sel; | |
1373 char *name; | |
1374 char *alias; | |
1375 | |
1376 chat = GAIM_CONV_CHAT(conv); | |
1377 gtkchat = gtkconv->u.chat; | |
1378 | |
1379 model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); | |
1380 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkchat->list)); | |
1381 | |
1382 if (gtk_tree_selection_get_selected(sel, NULL, &iter)) { | |
1383 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, | |
1384 CHAT_USERS_NAME_COLUMN, &name, | |
1385 CHAT_USERS_ALIAS_COLUMN, &alias, | |
1386 CHAT_USERS_FLAGS_COLUMN, &flags, | |
1387 -1); | |
1388 gtk_list_store_remove(GTK_LIST_STORE(model), &iter); | |
1389 } | |
1390 else | |
1391 return; | |
1392 | |
1393 if (gaim_conv_chat_is_user_ignored(chat, name)) | |
1394 gaim_conv_chat_unignore(chat, name); | |
1395 else | |
1396 gaim_conv_chat_ignore(chat, name); | |
1397 | |
1398 cbuddy = gaim_conv_chat_cb_new(name, alias, flags); | |
1399 | |
1400 add_chat_buddy_common(conv, cbuddy, NULL); | |
1401 g_free(name); | |
1402 g_free(alias); | |
1403 } | |
1404 | |
1405 static void | |
1406 menu_chat_im_cb(GtkWidget *w, GaimGtkConversation *gtkconv) | |
1407 { | |
1408 const char *who = g_object_get_data(G_OBJECT(w), "user_data"); | |
1409 | |
1410 chat_do_im(gtkconv, who); | |
1411 } | |
1412 | |
1413 static void | |
1414 menu_chat_send_file_cb(GtkWidget *w, GaimGtkConversation *gtkconv) | |
1415 { | |
1416 GaimConversation *conv = gtkconv->active_conv; | |
1417 const char *who = g_object_get_data(G_OBJECT(w), "user_data"); | |
1418 GaimConnection *gc = gaim_conversation_get_gc(conv); | |
1419 | |
1420 serv_send_file(gc, who, NULL); | |
1421 } | |
1422 | |
1423 static void | |
1424 menu_chat_info_cb(GtkWidget *w, GaimGtkConversation *gtkconv) | |
1425 { | |
1426 char *who; | |
1427 | |
1428 who = g_object_get_data(G_OBJECT(w), "user_data"); | |
1429 | |
1430 chat_do_info(gtkconv, who); | |
1431 } | |
1432 | |
1433 static void | |
1434 menu_chat_get_away_cb(GtkWidget *w, GaimGtkConversation *gtkconv) | |
1435 { | |
1436 GaimConversation *conv = gtkconv->active_conv; | |
1437 GaimPluginProtocolInfo *prpl_info = NULL; | |
1438 GaimConnection *gc; | |
1439 char *who; | |
1440 | |
1441 gc = gaim_conversation_get_gc(conv); | |
1442 who = g_object_get_data(G_OBJECT(w), "user_data"); | |
1443 | |
1444 if (gc != NULL) { | |
1445 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
1446 | |
1447 /* | |
1448 * May want to expand this to work similarly to menu_info_cb? | |
1449 */ | |
1450 | |
1451 if (prpl_info->get_cb_away != NULL) | |
1452 { | |
1453 prpl_info->get_cb_away(gc, | |
1454 gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), who); | |
1455 } | |
1456 } | |
1457 } | |
1458 | |
1459 static void | |
1460 menu_chat_add_remove_cb(GtkWidget *w, GaimGtkConversation *gtkconv) | |
1461 { | |
1462 GaimConversation *conv = gtkconv->active_conv; | |
1463 GaimAccount *account; | |
1464 GaimBuddy *b; | |
1465 char *name; | |
1466 | |
1467 account = gaim_conversation_get_account(conv); | |
1468 name = g_object_get_data(G_OBJECT(w), "user_data"); | |
1469 b = gaim_find_buddy(account, name); | |
1470 | |
1471 if (b != NULL) | |
1472 gaim_gtkdialogs_remove_buddy(b); | |
1473 else if (account != NULL && gaim_account_is_connected(account)) | |
1474 gaim_blist_request_add_buddy(account, name, NULL, NULL); | |
1475 | |
1476 gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); | |
1477 } | |
1478 | |
1479 static GtkTextMark * | |
1480 get_mark_for_user(GaimGtkConversation *gtkconv, const char *who) | |
1481 { | |
1482 GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->imhtml)); | |
1483 char *tmp = g_strconcat("user:", who, NULL); | |
1484 GtkTextMark *mark = gtk_text_buffer_get_mark(buf, tmp); | |
1485 | |
1486 g_free(tmp); | |
1487 return mark; | |
1488 } | |
1489 | |
1490 static void | |
1491 menu_last_said_cb(GtkWidget *w, GaimGtkConversation *gtkconv) | |
1492 { | |
1493 GtkTextMark *mark; | |
1494 const char *who; | |
1495 | |
1496 who = g_object_get_data(G_OBJECT(w), "user_data"); | |
1497 mark = get_mark_for_user(gtkconv, who); | |
1498 | |
1499 if (mark != NULL) | |
1500 gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(gtkconv->imhtml), mark, 0.1, FALSE, 0, 0); | |
1501 else | |
1502 g_return_if_reached(); | |
1503 } | |
1504 | |
1505 static GtkWidget * | |
1506 create_chat_menu(GaimConversation *conv, const char *who, GaimConnection *gc) | |
1507 { | |
1508 static GtkWidget *menu = NULL; | |
1509 GaimPluginProtocolInfo *prpl_info = NULL; | |
1510 GaimConvChat *chat = GAIM_CONV_CHAT(conv); | |
1511 gboolean is_me = FALSE; | |
1512 GtkWidget *button; | |
1513 GaimBuddy *buddy = NULL; | |
1514 | |
1515 if (gc != NULL) | |
1516 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
1517 | |
1518 /* | |
1519 * If a menu already exists, destroy it before creating a new one, | |
1520 * thus freeing-up the memory it occupied. | |
1521 */ | |
1522 if (menu) | |
1523 gtk_widget_destroy(menu); | |
1524 | |
1525 if (!strcmp(chat->nick, gaim_normalize(conv->account, who))) | |
1526 is_me = TRUE; | |
1527 | |
1528 menu = gtk_menu_new(); | |
1529 | |
1530 if (!is_me) { | |
1531 button = gaim_new_item_from_stock(menu, _("IM"), GAIM_STOCK_IM, | |
1532 G_CALLBACK(menu_chat_im_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); | |
1533 | |
1534 if (gc == NULL) | |
1535 gtk_widget_set_sensitive(button, FALSE); | |
1536 | |
1537 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); | |
1538 | |
1539 | |
1540 if (prpl_info && prpl_info->send_file) | |
1541 { | |
1542 button = gaim_new_item_from_stock(menu, _("Send File"), | |
1543 GAIM_STOCK_FILE_TRANSFER, G_CALLBACK(menu_chat_send_file_cb), | |
1544 GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); | |
1545 | |
1546 if (gc == NULL || prpl_info == NULL || | |
1547 !(!prpl_info->can_receive_file || prpl_info->can_receive_file(gc, who))) | |
1548 { | |
1549 gtk_widget_set_sensitive(button, FALSE); | |
1550 } | |
1551 | |
1552 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); | |
1553 } | |
1554 | |
1555 | |
1556 if (gaim_conv_chat_is_user_ignored(GAIM_CONV_CHAT(conv), who)) | |
1557 button = gaim_new_item_from_stock(menu, _("Un-Ignore"), GAIM_STOCK_IGNORE, | |
1558 G_CALLBACK(ignore_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); | |
1559 else | |
1560 button = gaim_new_item_from_stock(menu, _("Ignore"), GAIM_STOCK_IGNORE, | |
1561 G_CALLBACK(ignore_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); | |
1562 | |
1563 if (gc == NULL) | |
1564 gtk_widget_set_sensitive(button, FALSE); | |
1565 | |
1566 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); | |
1567 } | |
1568 | |
1569 if (prpl_info && (prpl_info->get_info || prpl_info->get_cb_info)) { | |
1570 button = gaim_new_item_from_stock(menu, _("Info"), GAIM_STOCK_INFO, | |
1571 G_CALLBACK(menu_chat_info_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); | |
1572 | |
1573 if (gc == NULL) | |
1574 gtk_widget_set_sensitive(button, FALSE); | |
1575 | |
1576 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); | |
1577 } | |
1578 | |
1579 if (prpl_info && prpl_info->get_cb_away) { | |
1580 button = gaim_new_item_from_stock(menu, _("Get Away Message"), GAIM_STOCK_AWAY, | |
1581 G_CALLBACK(menu_chat_get_away_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); | |
1582 | |
1583 if (gc == NULL) | |
1584 gtk_widget_set_sensitive(button, FALSE); | |
1585 | |
1586 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); | |
1587 } | |
1588 | |
1589 if (!is_me && prpl_info && !(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) { | |
1590 if ((buddy = gaim_find_buddy(conv->account, who)) != NULL) | |
1591 button = gaim_new_item_from_stock(menu, _("Remove"), GTK_STOCK_REMOVE, | |
1592 G_CALLBACK(menu_chat_add_remove_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); | |
1593 else | |
1594 button = gaim_new_item_from_stock(menu, _("Add"), GTK_STOCK_ADD, | |
1595 G_CALLBACK(menu_chat_add_remove_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); | |
1596 | |
1597 if (gc == NULL) | |
1598 gtk_widget_set_sensitive(button, FALSE); | |
1599 | |
1600 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); | |
1601 } | |
1602 | |
1603 button = gaim_new_item_from_stock(menu, _("Last said"), GTK_STOCK_INDEX, | |
1604 G_CALLBACK(menu_last_said_cb), GAIM_GTK_CONVERSATION(conv), 0, 0, NULL); | |
1605 g_object_set_data_full(G_OBJECT(button), "user_data", g_strdup(who), g_free); | |
1606 if (!get_mark_for_user(GAIM_GTK_CONVERSATION(conv), who)) | |
1607 gtk_widget_set_sensitive(button, FALSE); | |
1608 | |
1609 if (buddy != NULL) | |
1610 { | |
1611 if (gaim_account_is_connected(conv->account)) | |
1612 gaim_gtk_append_blist_node_proto_menu(menu, conv->account->gc, | |
1613 (GaimBlistNode *)buddy); | |
1614 gaim_gtk_append_blist_node_extended_menu(menu, (GaimBlistNode *)buddy); | |
1615 gtk_widget_show_all(menu); | |
1616 } | |
1617 | |
1618 return menu; | |
1619 } | |
1620 | |
1621 | |
1622 static gint | |
1623 gtkconv_chat_popup_menu_cb(GtkWidget *widget, GaimGtkConversation *gtkconv) | |
1624 { | |
1625 GaimConversation *conv = gtkconv->active_conv; | |
1626 GaimGtkChatPane *gtkchat; | |
1627 GaimConnection *gc; | |
1628 GaimAccount *account; | |
1629 GtkTreeSelection *sel; | |
1630 GtkTreeIter iter; | |
1631 GtkTreeModel *model; | |
1632 GtkWidget *menu; | |
1633 gchar *who; | |
1634 | |
1635 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
1636 gtkchat = gtkconv->u.chat; | |
1637 account = gaim_conversation_get_account(conv); | |
1638 gc = account->gc; | |
1639 | |
1640 model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); | |
1641 | |
1642 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkchat->list)); | |
1643 if(!gtk_tree_selection_get_selected(sel, NULL, &iter)) | |
1644 return FALSE; | |
1645 | |
1646 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CHAT_USERS_NAME_COLUMN, &who, -1); | |
1647 menu = create_chat_menu (conv, who, gc); | |
1648 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, | |
1649 gaim_gtk_treeview_popup_menu_position_func, widget, | |
1650 0, GDK_CURRENT_TIME); | |
1651 g_free(who); | |
1652 | |
1653 return TRUE; | |
1654 } | |
1655 | |
1656 | |
1657 static gint | |
1658 right_click_chat_cb(GtkWidget *widget, GdkEventButton *event, | |
1659 GaimGtkConversation *gtkconv) | |
1660 { | |
1661 GaimConversation *conv = gtkconv->active_conv; | |
1662 GaimGtkChatPane *gtkchat; | |
1663 GaimConnection *gc; | |
1664 GaimAccount *account; | |
1665 GtkTreePath *path; | |
1666 GtkTreeIter iter; | |
1667 GtkTreeModel *model; | |
1668 GtkTreeViewColumn *column; | |
1669 gchar *who; | |
1670 int x, y; | |
1671 | |
1672 gtkchat = gtkconv->u.chat; | |
1673 account = gaim_conversation_get_account(conv); | |
1674 gc = account->gc; | |
1675 | |
1676 model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); | |
1677 | |
1678 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(gtkchat->list), | |
1679 event->x, event->y, &path, &column, &x, &y); | |
1680 | |
1681 if (path == NULL) | |
1682 return FALSE; | |
1683 | |
1684 gtk_tree_selection_select_path(GTK_TREE_SELECTION( | |
1685 gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkchat->list))), path); | |
1686 | |
1687 gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path); | |
1688 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CHAT_USERS_NAME_COLUMN, &who, -1); | |
1689 | |
1690 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS) { | |
1691 chat_do_im(gtkconv, who); | |
1692 } else if (event->button == 2 && event->type == GDK_BUTTON_PRESS) { | |
1693 /* Move to user's anchor */ | |
1694 GtkTextMark *mark = get_mark_for_user(gtkconv, who); | |
1695 | |
1696 if(mark != NULL) | |
1697 gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(gtkconv->imhtml), mark, 0.1, FALSE, 0, 0); | |
1698 } else if (event->button == 3 && event->type == GDK_BUTTON_PRESS) { | |
1699 GtkWidget *menu = create_chat_menu (conv, who, gc); | |
1700 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, | |
1701 event->button, event->time); | |
1702 } | |
1703 | |
1704 g_free(who); | |
1705 gtk_tree_path_free(path); | |
1706 | |
1707 return TRUE; | |
1708 } | |
1709 | |
1710 static void | |
1711 move_to_next_unread_tab(GaimGtkConversation *gtkconv, gboolean forward) | |
1712 { | |
1713 GaimGtkConversation *next_gtkconv = NULL; | |
1714 GaimGtkWindow *win; | |
1715 int initial, i, total, diff; | |
1716 | |
1717 win = gtkconv->win; | |
1718 initial = gtk_notebook_page_num(GTK_NOTEBOOK(win->notebook), | |
1719 gtkconv->tab_cont); | |
1720 total = gaim_gtk_conv_window_get_gtkconv_count(win); | |
1721 /* By adding total here, the moduli calculated later will always have two | |
1722 * positive arguments. x % y where x < 0 is not guaranteed to return a | |
1723 * positive number. | |
1724 */ | |
1725 diff = (forward ? 1 : -1) + total; | |
1726 | |
1727 for (i = (initial + diff) % total; i != initial; i = (i + diff) % total) { | |
1728 next_gtkconv = gaim_gtk_conv_window_get_gtkconv_at_index(win, i); | |
1729 if (next_gtkconv->unseen_state > 0) | |
1730 break; | |
1731 } | |
1732 | |
1733 if (i == initial) { /* no new messages */ | |
1734 i = (i + diff) % total; | |
1735 next_gtkconv = gaim_gtk_conv_window_get_gtkconv_at_index(win, i); | |
1736 } | |
1737 | |
1738 if (next_gtkconv != NULL && next_gtkconv != gtkconv) | |
1739 gaim_gtk_conv_window_switch_gtkconv(win, next_gtkconv); | |
1740 } | |
1741 | |
1742 static gboolean | |
1743 entry_key_press_cb(GtkWidget *entry, GdkEventKey *event, gpointer data) | |
1744 { | |
1745 GaimGtkWindow *win; | |
1746 GaimConversation *conv; | |
1747 GaimGtkConversation *gtkconv; | |
1748 int curconv; | |
1749 | |
1750 gtkconv = (GaimGtkConversation *)data; | |
1751 conv = gtkconv->active_conv; | |
1752 win = gtkconv->win; | |
1753 curconv = gtk_notebook_get_current_page(GTK_NOTEBOOK(win->notebook)); | |
1754 | |
1755 /* If CTRL was held down... */ | |
1756 if (event->state & GDK_CONTROL_MASK) { | |
1757 switch (event->keyval) { | |
1758 case GDK_Up: | |
1759 if (!gtkconv->send_history) | |
1760 break; | |
1761 | |
1762 if (!gtkconv->send_history->prev) { | |
1763 GtkTextIter start, end; | |
1764 | |
1765 g_free(gtkconv->send_history->data); | |
1766 | |
1767 gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, | |
1768 &start); | |
1769 gtk_text_buffer_get_end_iter(gtkconv->entry_buffer, &end); | |
1770 | |
1771 gtkconv->send_history->data = | |
1772 gtk_imhtml_get_markup(GTK_IMHTML(gtkconv->entry)); | |
1773 } | |
1774 | |
1775 if (gtkconv->send_history->next && gtkconv->send_history->next->data) { | |
1776 GObject *object; | |
1777 GtkTextIter iter; | |
1778 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry)); | |
1779 | |
1780 gtkconv->send_history = gtkconv->send_history->next; | |
1781 | |
1782 /* Block the signal to prevent application of default formatting. */ | |
1783 object = g_object_ref(G_OBJECT(gtkconv->entry)); | |
1784 g_signal_handlers_block_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL, | |
1785 NULL, gtkconv); | |
1786 /* Clear the formatting. */ | |
1787 gtk_imhtml_clear_formatting(GTK_IMHTML(gtkconv->entry)); | |
1788 /* Unblock the signal. */ | |
1789 g_signal_handlers_unblock_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL, | |
1790 NULL, gtkconv); | |
1791 g_object_unref(object); | |
1792 | |
1793 gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry)); | |
1794 gtk_imhtml_append_text_with_images( | |
1795 GTK_IMHTML(gtkconv->entry), gtkconv->send_history->data, | |
1796 0, NULL); | |
1797 /* this is mainly just a hack so the formatting at the | |
1798 * cursor gets picked up. */ | |
1799 gtk_text_buffer_get_end_iter(buffer, &iter); | |
1800 gtk_text_buffer_move_mark_by_name(buffer, "insert", &iter); | |
1801 } | |
1802 | |
1803 return TRUE; | |
1804 break; | |
1805 | |
1806 case GDK_Down: | |
1807 if (!gtkconv->send_history) | |
1808 break; | |
1809 | |
1810 if (gtkconv->send_history->prev && gtkconv->send_history->prev->data) { | |
1811 GObject *object; | |
1812 GtkTextIter iter; | |
1813 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry)); | |
1814 | |
1815 gtkconv->send_history = gtkconv->send_history->prev; | |
1816 | |
1817 /* Block the signal to prevent application of default formatting. */ | |
1818 object = g_object_ref(G_OBJECT(gtkconv->entry)); | |
1819 g_signal_handlers_block_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL, | |
1820 NULL, gtkconv); | |
1821 /* Clear the formatting. */ | |
1822 gtk_imhtml_clear_formatting(GTK_IMHTML(gtkconv->entry)); | |
1823 /* Unblock the signal. */ | |
1824 g_signal_handlers_unblock_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL, | |
1825 NULL, gtkconv); | |
1826 g_object_unref(object); | |
1827 | |
1828 gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry)); | |
1829 gtk_imhtml_append_text_with_images( | |
1830 GTK_IMHTML(gtkconv->entry), gtkconv->send_history->data, | |
1831 0, NULL); | |
1832 /* this is mainly just a hack so the formatting at the | |
1833 * cursor gets picked up. */ | |
1834 if (*(char *)gtkconv->send_history->data) { | |
1835 gtk_text_buffer_get_end_iter(buffer, &iter); | |
1836 gtk_text_buffer_move_mark_by_name(buffer, "insert", &iter); | |
1837 } else { | |
1838 /* Restore the default formatting */ | |
1839 default_formatize(gtkconv); | |
1840 } | |
1841 } | |
1842 | |
1843 return TRUE; | |
1844 break; | |
1845 | |
1846 case GDK_Page_Down: | |
1847 case ']': | |
1848 if (!gaim_gtk_conv_window_get_gtkconv_at_index(win, curconv + 1)) | |
1849 gtk_notebook_set_current_page(GTK_NOTEBOOK(win->notebook), 0); | |
1850 else | |
1851 gtk_notebook_set_current_page(GTK_NOTEBOOK(win->notebook), curconv + 1); | |
1852 return TRUE; | |
1853 break; | |
1854 | |
1855 case GDK_Page_Up: | |
1856 case '[': | |
1857 if (!gaim_gtk_conv_window_get_gtkconv_at_index(win, curconv - 1)) | |
1858 gtk_notebook_set_current_page(GTK_NOTEBOOK(win->notebook), -1); | |
1859 else | |
1860 gtk_notebook_set_current_page(GTK_NOTEBOOK(win->notebook), curconv - 1); | |
1861 return TRUE; | |
1862 break; | |
1863 | |
1864 case GDK_Tab: | |
1865 case GDK_ISO_Left_Tab: | |
1866 if (event->state & GDK_SHIFT_MASK) { | |
1867 move_to_next_unread_tab(gtkconv, FALSE); | |
1868 } else { | |
1869 move_to_next_unread_tab(gtkconv, TRUE); | |
1870 } | |
1871 | |
1872 return TRUE; | |
1873 break; | |
1874 | |
1875 case GDK_comma: | |
1876 gtk_notebook_reorder_child(GTK_NOTEBOOK(win->notebook), | |
1877 gtk_notebook_get_nth_page(GTK_NOTEBOOK(win->notebook), curconv), | |
1878 curconv - 1); | |
1879 break; | |
1880 | |
1881 case GDK_period: | |
1882 gtk_notebook_reorder_child(GTK_NOTEBOOK(win->notebook), | |
1883 gtk_notebook_get_nth_page(GTK_NOTEBOOK(win->notebook), curconv), | |
1884 #if GTK_CHECK_VERSION(2,2,0) | |
1885 (curconv + 1) % gtk_notebook_get_n_pages(GTK_NOTEBOOK(win->notebook))); | |
1886 #else | |
1887 (curconv + 1) % g_list_length(GTK_NOTEBOOK(win->notebook)->children)); | |
1888 #endif | |
1889 break; | |
1890 | |
1891 } /* End of switch */ | |
1892 } | |
1893 | |
1894 /* If ALT (or whatever) was held down... */ | |
1895 else if (event->state & GDK_MOD1_MASK) | |
1896 { | |
1897 if (event->keyval > '0' && event->keyval <= '9') | |
1898 { | |
1899 guint switchto = event->keyval - '1'; | |
1900 if (switchto < gaim_gtk_conv_window_get_gtkconv_count(win)) | |
1901 gtk_notebook_set_current_page(GTK_NOTEBOOK(win->notebook), switchto); | |
1902 | |
1903 return TRUE; | |
1904 } | |
1905 } | |
1906 | |
1907 /* If neither CTRL nor ALT were held down... */ | |
1908 else | |
1909 { | |
1910 switch (event->keyval) | |
1911 { | |
1912 case GDK_Tab: | |
1913 return tab_complete(conv); | |
1914 break; | |
1915 | |
1916 case GDK_Page_Up: | |
1917 gtk_imhtml_page_up(GTK_IMHTML(gtkconv->imhtml)); | |
1918 return TRUE; | |
1919 break; | |
1920 | |
1921 case GDK_Page_Down: | |
1922 gtk_imhtml_page_down(GTK_IMHTML(gtkconv->imhtml)); | |
1923 return TRUE; | |
1924 break; | |
1925 | |
1926 } | |
1927 } | |
1928 return FALSE; | |
1929 } | |
1930 | |
1931 /* | |
1932 * NOTE: | |
1933 * This guy just kills a single right click from being propagated any | |
1934 * further. I have no idea *why* we need this, but we do ... It | |
1935 * prevents right clicks on the GtkTextView in a convo dialog from | |
1936 * going all the way down to the notebook. I suspect a bug in | |
1937 * GtkTextView, but I'm not ready to point any fingers yet. | |
1938 */ | |
1939 static gboolean | |
1940 entry_stop_rclick_cb(GtkWidget *widget, GdkEventButton *event, gpointer data) | |
1941 { | |
1942 if (event->button == 3 && event->type == GDK_BUTTON_PRESS) { | |
1943 /* Right single click */ | |
1944 g_signal_stop_emission_by_name(G_OBJECT(widget), "button_press_event"); | |
1945 | |
1946 return TRUE; | |
1947 } | |
1948 | |
1949 return FALSE; | |
1950 } | |
1951 | |
1952 /* | |
1953 * If someone tries to type into the conversation backlog of a | |
1954 * conversation window then we yank focus from the conversation backlog | |
1955 * and give it to the text entry box so that people can type | |
1956 * all the live long day and it will get entered into the entry box. | |
1957 */ | |
1958 static gboolean | |
1959 refocus_entry_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
1960 { | |
1961 GaimGtkConversation *gtkconv = data; | |
1962 | |
1963 /* If we have a valid key for the conversation display, then exit */ | |
1964 if ((event->state & GDK_CONTROL_MASK) || | |
1965 (event->keyval == GDK_F10) || | |
1966 (event->keyval == GDK_Shift_L) || | |
1967 (event->keyval == GDK_Shift_R) || | |
1968 (event->keyval == GDK_Escape) || | |
1969 (event->keyval == GDK_Up) || | |
1970 (event->keyval == GDK_Down) || | |
1971 (event->keyval == GDK_Left) || | |
1972 (event->keyval == GDK_Right) || | |
1973 (event->keyval == GDK_Home) || | |
1974 (event->keyval == GDK_End) || | |
1975 (event->keyval == GDK_Tab) || | |
1976 (event->keyval == GDK_ISO_Left_Tab)) | |
1977 return FALSE; | |
1978 | |
1979 if (event->type == GDK_KEY_RELEASE) | |
1980 gtk_widget_grab_focus(gtkconv->entry); | |
1981 | |
1982 gtk_widget_event(gtkconv->entry, (GdkEvent *)event); | |
1983 | |
1984 return TRUE; | |
1985 } | |
1986 | |
1987 void | |
1988 gaim_gtkconv_switch_active_conversation(GaimConversation *conv) | |
1989 { | |
1990 GaimGtkConversation *gtkconv; | |
1991 GaimConversation *old_conv; | |
1992 GtkIMHtml *entry; | |
1993 const char *protocol_name; | |
1994 | |
1995 g_return_if_fail(conv != NULL); | |
1996 | |
1997 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
1998 old_conv = gtkconv->active_conv; | |
1999 | |
2000 if (old_conv == conv) | |
2001 return; | |
2002 | |
2003 gaim_conversation_close_logs(old_conv); | |
2004 gtkconv->active_conv = conv; | |
2005 | |
2006 gaim_conversation_set_logging(conv, | |
2007 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gtkconv->win->menu.logging))); | |
2008 | |
2009 entry = GTK_IMHTML(gtkconv->entry); | |
2010 protocol_name = gaim_account_get_protocol_name(conv->account); | |
2011 gtk_imhtml_set_protocol_name(entry, protocol_name); | |
2012 gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->imhtml), protocol_name); | |
2013 | |
2014 if (!(conv->features & GAIM_CONNECTION_HTML)) | |
2015 gtk_imhtml_clear_formatting(GTK_IMHTML(gtkconv->entry)); | |
2016 else if (conv->features & GAIM_CONNECTION_FORMATTING_WBFO && | |
2017 !(old_conv->features & GAIM_CONNECTION_FORMATTING_WBFO)) | |
2018 { | |
2019 /* The old conversation allowed formatting on parts of the | |
2020 * buffer, but the new one only allows it on the whole | |
2021 * buffer. This code saves the formatting from the current | |
2022 * position of the cursor, clears the formatting, then | |
2023 * applies the saved formatting to the entire buffer. */ | |
2024 | |
2025 gboolean bold; | |
2026 gboolean italic; | |
2027 gboolean underline; | |
2028 char *fontface = gtk_imhtml_get_current_fontface(entry); | |
2029 char *forecolor = gtk_imhtml_get_current_forecolor(entry); | |
2030 char *backcolor = gtk_imhtml_get_current_backcolor(entry); | |
2031 char *background = gtk_imhtml_get_current_background(entry); | |
2032 gint fontsize = gtk_imhtml_get_current_fontsize(entry); | |
2033 gboolean bold2; | |
2034 gboolean italic2; | |
2035 gboolean underline2; | |
2036 | |
2037 gtk_imhtml_get_current_format(entry, &bold, &italic, &underline); | |
2038 | |
2039 /* Clear existing formatting */ | |
2040 gtk_imhtml_clear_formatting(entry); | |
2041 | |
2042 /* Apply saved formatting to the whole buffer. */ | |
2043 | |
2044 gtk_imhtml_get_current_format(entry, &bold2, &italic2, &underline2); | |
2045 | |
2046 if (bold != bold2) | |
2047 gtk_imhtml_toggle_bold(entry); | |
2048 | |
2049 if (italic != italic2) | |
2050 gtk_imhtml_toggle_italic(entry); | |
2051 | |
2052 if (underline != underline2) | |
2053 gtk_imhtml_toggle_underline(entry); | |
2054 | |
2055 gtk_imhtml_toggle_fontface(entry, fontface); | |
2056 | |
2057 if (!(conv->features & GAIM_CONNECTION_NO_FONTSIZE)) | |
2058 gtk_imhtml_font_set_size(entry, fontsize); | |
2059 | |
2060 gtk_imhtml_toggle_forecolor(entry, forecolor); | |
2061 | |
2062 if (!(conv->features & GAIM_CONNECTION_NO_BGCOLOR)) | |
2063 { | |
2064 gtk_imhtml_toggle_backcolor(entry, backcolor); | |
2065 gtk_imhtml_toggle_background(entry, background); | |
2066 } | |
2067 | |
2068 g_free(fontface); | |
2069 g_free(forecolor); | |
2070 g_free(backcolor); | |
2071 g_free(background); | |
2072 } | |
2073 else | |
2074 { | |
2075 /* This is done in default_formatize, which is called from clear_formatting_cb, | |
2076 * which is (obviously) a clear_formatting signal handler. However, if we're | |
2077 * here, we didn't call gtk_imhtml_clear_formatting() (because we want to | |
2078 * preserve the formatting exactly as it is), so we have to do this now. */ | |
2079 gtk_imhtml_set_whole_buffer_formatting_only(entry, | |
2080 (conv->features & GAIM_CONNECTION_FORMATTING_WBFO)); | |
2081 } | |
2082 | |
2083 gaim_signal_emit(gaim_gtk_conversations_get_handle(), "conversation-switched", conv); | |
2084 | |
2085 gray_stuff_out(gtkconv); | |
2086 update_typing_icon(gtkconv); | |
2087 | |
2088 gtk_window_set_title(GTK_WINDOW(gtkconv->win->window), | |
2089 gtk_label_get_text(GTK_LABEL(gtkconv->tab_label))); | |
2090 } | |
2091 | |
2092 static void | |
2093 menu_conv_sel_send_cb(GObject *m, gpointer data) | |
2094 { | |
2095 GaimAccount *account = g_object_get_data(m, "gaim_account"); | |
2096 gchar *name = g_object_get_data(m, "gaim_buddy_name"); | |
2097 GaimConversation *conv; | |
2098 | |
2099 if (gtk_check_menu_item_get_active((GtkCheckMenuItem*) m) == FALSE) | |
2100 return; | |
2101 | |
2102 conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, name); | |
2103 gaim_gtkconv_switch_active_conversation(conv); | |
2104 } | |
2105 | |
2106 static void | |
2107 insert_text_cb(GtkTextBuffer *textbuffer, GtkTextIter *position, | |
2108 gchar *new_text, gint new_text_length, gpointer user_data) | |
2109 { | |
2110 GaimGtkConversation *gtkconv = (GaimGtkConversation *)user_data; | |
2111 GaimConversation *conv; | |
2112 | |
2113 g_return_if_fail(gtkconv != NULL); | |
2114 | |
2115 conv = gtkconv->active_conv; | |
2116 | |
2117 if (!gaim_prefs_get_bool("/core/conversations/im/send_typing")) | |
2118 return; | |
2119 | |
2120 got_typing_keypress(gtkconv, (gtk_text_iter_is_start(position) && | |
2121 gtk_text_iter_is_end(position))); | |
2122 } | |
2123 | |
2124 static void | |
2125 delete_text_cb(GtkTextBuffer *textbuffer, GtkTextIter *start_pos, | |
2126 GtkTextIter *end_pos, gpointer user_data) | |
2127 { | |
2128 GaimGtkConversation *gtkconv = (GaimGtkConversation *)user_data; | |
2129 GaimConversation *conv; | |
2130 GaimConvIm *im; | |
2131 | |
2132 g_return_if_fail(gtkconv != NULL); | |
2133 | |
2134 conv = gtkconv->active_conv; | |
2135 | |
2136 if (!gaim_prefs_get_bool("/core/conversations/im/send_typing")) | |
2137 return; | |
2138 | |
2139 im = GAIM_CONV_IM(conv); | |
2140 | |
2141 if (gtk_text_iter_is_start(start_pos) && gtk_text_iter_is_end(end_pos)) { | |
2142 | |
2143 /* We deleted all the text, so turn off typing. */ | |
2144 gaim_conv_im_stop_send_typed_timeout(im); | |
2145 | |
2146 serv_send_typing(gaim_conversation_get_gc(conv), | |
2147 gaim_conversation_get_name(conv), | |
2148 GAIM_NOT_TYPING); | |
2149 } | |
2150 else { | |
2151 /* We're deleting, but not all of it, so it counts as typing. */ | |
2152 got_typing_keypress(gtkconv, FALSE); | |
2153 } | |
2154 } | |
2155 | |
2156 /************************************************************************** | |
2157 * A bunch of buddy icon functions | |
2158 **************************************************************************/ | |
2159 GdkPixbuf * | |
2160 gaim_gtkconv_get_tab_icon(GaimConversation *conv, gboolean small_icon) | |
2161 { | |
2162 GaimAccount *account = NULL; | |
2163 const char *name = NULL; | |
2164 GdkPixbuf *status = NULL; | |
2165 GaimBlistUiOps *ops = gaim_blist_get_ui_ops(); | |
2166 | |
2167 g_return_val_if_fail(conv != NULL, NULL); | |
2168 | |
2169 account = gaim_conversation_get_account(conv); | |
2170 name = gaim_conversation_get_name(conv); | |
2171 | |
2172 g_return_val_if_fail(account != NULL, NULL); | |
2173 g_return_val_if_fail(name != NULL, NULL); | |
2174 | |
2175 /* Use the buddy icon, if possible */ | |
2176 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) { | |
2177 GaimBuddy *b = gaim_find_buddy(account, name); | |
2178 if (b != NULL) { | |
2179 /* I hate this hack. It fixes a bug where the pending message icon | |
2180 * displays in the conv tab even though it shouldn't. | |
2181 * A better solution would be great. */ | |
2182 if (ops && ops->update) | |
2183 ops->update(NULL, (GaimBlistNode*)b); | |
2184 | |
2185 status = gaim_gtk_blist_get_status_icon((GaimBlistNode*)b, | |
2186 (small_icon ? GAIM_STATUS_ICON_SMALL : GAIM_STATUS_ICON_LARGE)); | |
2187 } | |
2188 } | |
2189 | |
2190 /* If they don't have a buddy icon, then use the PRPL icon */ | |
2191 if (status == NULL) | |
2192 status = gaim_gtk_create_prpl_icon(account, small_icon ? 0.5 : 1.0); | |
2193 | |
2194 return status; | |
2195 } | |
2196 | |
2197 static void | |
2198 update_tab_icon(GaimConversation *conv) | |
2199 { | |
2200 GaimGtkConversation *gtkconv; | |
2201 GaimGtkWindow *win; | |
2202 GdkPixbuf *status = NULL; | |
2203 | |
2204 g_return_if_fail(conv != NULL); | |
2205 | |
2206 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
2207 win = gtkconv->win; | |
2208 if (conv != gtkconv->active_conv) | |
2209 return; | |
2210 | |
2211 status = gaim_gtkconv_get_tab_icon(conv, TRUE); | |
2212 | |
2213 g_return_if_fail(status != NULL); | |
2214 | |
2215 gtk_image_set_from_pixbuf(GTK_IMAGE(gtkconv->icon), status); | |
2216 gtk_image_set_from_pixbuf(GTK_IMAGE(gtkconv->menu_icon), status); | |
2217 | |
2218 if (status != NULL) | |
2219 g_object_unref(status); | |
2220 | |
2221 if (gaim_gtk_conv_window_is_active_conversation(conv) && | |
2222 (gaim_conversation_get_type(conv) != GAIM_CONV_TYPE_IM || | |
2223 gtkconv->u.im->anim == NULL)) | |
2224 { | |
2225 status = gaim_gtkconv_get_tab_icon(conv, FALSE); | |
2226 | |
2227 gtk_window_set_icon(GTK_WINDOW(win->window), status); | |
2228 | |
2229 if (status != NULL) | |
2230 g_object_unref(status); | |
2231 } | |
2232 } | |
2233 | |
2234 static gboolean | |
2235 redraw_icon(gpointer data) | |
2236 { | |
2237 GaimGtkConversation *gtkconv = (GaimGtkConversation *)data; | |
2238 GaimConversation *conv = gtkconv->active_conv; | |
2239 GaimAccount *account; | |
2240 GaimPluginProtocolInfo *prpl_info = NULL; | |
2241 | |
2242 GdkPixbuf *buf; | |
2243 GdkPixbuf *scale; | |
2244 gint delay; | |
2245 int scale_width, scale_height; | |
2246 | |
2247 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
2248 account = gaim_conversation_get_account(conv); | |
2249 if(account && account->gc) | |
2250 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(account->gc->prpl); | |
2251 | |
2252 gdk_pixbuf_animation_iter_advance(gtkconv->u.im->iter, NULL); | |
2253 buf = gdk_pixbuf_animation_iter_get_pixbuf(gtkconv->u.im->iter); | |
2254 | |
2255 gaim_gtk_buddy_icon_get_scale_size(buf, prpl_info ? &prpl_info->icon_spec : | |
2256 NULL, &scale_width, &scale_height); | |
2257 | |
2258 /* this code is ugly, and scares me */ | |
2259 scale = gdk_pixbuf_scale_simple(buf, | |
2260 MAX(gdk_pixbuf_get_width(buf) * scale_width / | |
2261 gdk_pixbuf_animation_get_width(gtkconv->u.im->anim), 1), | |
2262 MAX(gdk_pixbuf_get_height(buf) * scale_height / | |
2263 gdk_pixbuf_animation_get_height(gtkconv->u.im->anim), 1), | |
2264 GDK_INTERP_BILINEAR); | |
2265 | |
2266 gtk_image_set_from_pixbuf(GTK_IMAGE(gtkconv->u.im->icon), scale); | |
2267 g_object_unref(G_OBJECT(scale)); | |
2268 gtk_widget_queue_draw(gtkconv->u.im->icon); | |
2269 | |
2270 delay = gdk_pixbuf_animation_iter_get_delay_time(gtkconv->u.im->iter); | |
2271 | |
2272 if (delay < 100) | |
2273 delay = 100; | |
2274 | |
2275 gtkconv->u.im->icon_timer = g_timeout_add(delay, redraw_icon, gtkconv); | |
2276 | |
2277 return FALSE; | |
2278 } | |
2279 | |
2280 static void | |
2281 start_anim(GtkObject *obj, GaimGtkConversation *gtkconv) | |
2282 { | |
2283 int delay; | |
2284 | |
2285 if (gtkconv->u.im->anim == NULL) | |
2286 return; | |
2287 | |
2288 if (gtkconv->u.im->icon_timer != 0) | |
2289 return; | |
2290 | |
2291 if (gdk_pixbuf_animation_is_static_image(gtkconv->u.im->anim)) | |
2292 return; | |
2293 | |
2294 delay = gdk_pixbuf_animation_iter_get_delay_time(gtkconv->u.im->iter); | |
2295 | |
2296 if (delay < 100) | |
2297 delay = 100; | |
2298 | |
2299 gtkconv->u.im->icon_timer = g_timeout_add(delay, redraw_icon, gtkconv); | |
2300 } | |
2301 | |
2302 static void | |
2303 remove_icon(GaimGtkConversation *gtkconv) | |
2304 { | |
2305 GaimConversation *conv = gtkconv->active_conv; | |
2306 GaimGtkWindow *gtkwin; | |
2307 | |
2308 g_return_if_fail(conv != NULL); | |
2309 | |
2310 if (gtkconv->u.im->icon_container != NULL) | |
2311 gtk_widget_destroy(gtkconv->u.im->icon_container); | |
2312 | |
2313 if (gtkconv->u.im->anim != NULL) | |
2314 g_object_unref(G_OBJECT(gtkconv->u.im->anim)); | |
2315 | |
2316 if (gtkconv->u.im->icon_timer != 0) | |
2317 g_source_remove(gtkconv->u.im->icon_timer); | |
2318 | |
2319 if (gtkconv->u.im->iter != NULL) | |
2320 g_object_unref(G_OBJECT(gtkconv->u.im->iter)); | |
2321 | |
2322 gtkconv->u.im->icon_timer = 0; | |
2323 gtkconv->u.im->icon = NULL; | |
2324 gtkconv->u.im->anim = NULL; | |
2325 gtkconv->u.im->iter = NULL; | |
2326 gtkconv->u.im->icon_container = NULL; | |
2327 gtkconv->u.im->show_icon = FALSE; | |
2328 | |
2329 gtkwin = gtkconv->win; | |
2330 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtkwin->menu.show_icon), FALSE); | |
2331 } | |
2332 | |
2333 static void | |
2334 saveicon_writefile_cb(void *user_data, const char *filename) | |
2335 { | |
2336 GaimGtkConversation *gtkconv = (GaimGtkConversation *)user_data; | |
2337 GaimConversation *conv = gtkconv->active_conv; | |
2338 FILE *fp; | |
2339 GaimBuddyIcon *icon; | |
2340 const void *data; | |
2341 size_t len; | |
2342 | |
2343 if ((fp = g_fopen(filename, "wb")) == NULL) { | |
2344 gaim_notify_error(gtkconv, NULL, _("Unable to open file."), NULL); | |
2345 return; | |
2346 } | |
2347 | |
2348 icon = gaim_conv_im_get_icon(GAIM_CONV_IM(conv)); | |
2349 data = gaim_buddy_icon_get_data(icon, &len); | |
2350 | |
2351 if ((len <= 0) || (data == NULL)) { | |
2352 gaim_notify_error(gtkconv, NULL, _("Unable to save icon file to disk."), NULL); | |
2353 fclose(fp); | |
2354 return; | |
2355 } | |
2356 | |
2357 fwrite(data, 1, len, fp); | |
2358 fclose(fp); | |
2359 } | |
2360 | |
2361 static void | |
2362 icon_menu_save_cb(GtkWidget *widget, GaimGtkConversation *gtkconv) | |
2363 { | |
2364 GaimConversation *conv = gtkconv->active_conv; | |
2365 const gchar *ext; | |
2366 gchar *buf; | |
2367 | |
2368 g_return_if_fail(conv != NULL); | |
2369 | |
2370 ext = gaim_buddy_icon_get_type(gaim_conv_im_get_icon(GAIM_CONV_IM(conv))); | |
2371 if (ext == NULL) | |
2372 ext = "icon"; | |
2373 | |
2374 buf = g_strdup_printf("%s.%s", gaim_normalize(conv->account, conv->name), ext); | |
2375 | |
2376 gaim_request_file(gtkconv, _("Save Icon"), buf, TRUE, | |
2377 G_CALLBACK(saveicon_writefile_cb), NULL, gtkconv); | |
2378 | |
2379 g_free(buf); | |
2380 } | |
2381 | |
2382 static void | |
2383 stop_anim(GtkObject *obj, GaimGtkConversation *gtkconv) | |
2384 { | |
2385 if (gtkconv->u.im->icon_timer != 0) | |
2386 g_source_remove(gtkconv->u.im->icon_timer); | |
2387 | |
2388 gtkconv->u.im->icon_timer = 0; | |
2389 } | |
2390 | |
2391 | |
2392 static void | |
2393 toggle_icon_animate_cb(GtkWidget *w, GaimGtkConversation *gtkconv) | |
2394 { | |
2395 gtkconv->u.im->animate = | |
2396 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w)); | |
2397 | |
2398 if (gtkconv->u.im->animate) | |
2399 start_anim(NULL, gtkconv); | |
2400 else | |
2401 stop_anim(NULL, gtkconv); | |
2402 } | |
2403 | |
2404 static gboolean | |
2405 icon_menu(GtkObject *obj, GdkEventButton *e, GaimGtkConversation *gtkconv) | |
2406 { | |
2407 static GtkWidget *menu = NULL; | |
2408 GtkWidget *item; | |
2409 | |
2410 if (e->button != 3 || e->type != GDK_BUTTON_PRESS) | |
2411 return FALSE; | |
2412 | |
2413 /* | |
2414 * If a menu already exists, destroy it before creating a new one, | |
2415 * thus freeing-up the memory it occupied. | |
2416 */ | |
2417 if (menu != NULL) | |
2418 gtk_widget_destroy(menu); | |
2419 | |
2420 menu = gtk_menu_new(); | |
2421 | |
2422 if (gtkconv->u.im->anim && | |
2423 !(gdk_pixbuf_animation_is_static_image(gtkconv->u.im->anim))) | |
2424 { | |
2425 gaim_new_check_item(menu, _("Animate"), | |
2426 G_CALLBACK(toggle_icon_animate_cb), gtkconv, | |
2427 gtkconv->u.im->icon_timer); | |
2428 } | |
2429 | |
2430 item = gtk_menu_item_new_with_label(_("Hide Icon")); | |
2431 g_signal_connect_swapped(G_OBJECT(item), "activate", | |
2432 G_CALLBACK(remove_icon), gtkconv); | |
2433 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
2434 gtk_widget_show(item); | |
2435 | |
2436 gaim_new_item_from_stock(menu, _("Save Icon As..."), GTK_STOCK_SAVE_AS, | |
2437 G_CALLBACK(icon_menu_save_cb), gtkconv, | |
2438 0, 0, NULL); | |
2439 | |
2440 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, e->button, e->time); | |
2441 | |
2442 return TRUE; | |
2443 } | |
2444 | |
2445 static void | |
2446 menu_buddyicon_cb(gpointer data, guint action, GtkWidget *widget) | |
2447 { | |
2448 GaimGtkWindow *win = data; | |
2449 GaimConversation *conv; | |
2450 GaimGtkConversation *gtkconv; | |
2451 gboolean active; | |
2452 | |
2453 conv = gaim_gtk_conv_window_get_active_conversation(win); | |
2454 | |
2455 if (!conv) | |
2456 return; | |
2457 | |
2458 g_return_if_fail(gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM); | |
2459 | |
2460 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
2461 | |
2462 active = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); | |
2463 gtkconv->u.im->show_icon = active; | |
2464 if (active) | |
2465 gaim_gtkconv_update_buddy_icon(conv); | |
2466 else | |
2467 remove_icon(gtkconv); | |
2468 } | |
2469 | |
2470 /************************************************************************** | |
2471 * End of the bunch of buddy icon functions | |
2472 **************************************************************************/ | |
2473 void | |
2474 gaim_gtkconv_present_conversation(GaimConversation *conv) | |
2475 { | |
2476 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv); | |
2477 | |
2478 if(gtkconv->win==hidden_convwin) { | |
2479 gaim_gtk_conv_window_remove_gtkconv(hidden_convwin, gtkconv); | |
2480 gaim_gtkconv_placement_place(gtkconv); | |
2481 } | |
2482 | |
2483 gaim_gtkconv_switch_active_conversation(conv); | |
2484 gaim_gtk_conv_window_switch_gtkconv(gtkconv->win, gtkconv); | |
2485 gtk_window_present(GTK_WINDOW(gtkconv->win->window)); | |
2486 } | |
2487 | |
2488 GList * | |
2489 gaim_gtk_conversations_find_unseen_list(GaimConversationType type, | |
2490 GaimUnseenState min_state, | |
2491 gboolean hidden_only, | |
2492 guint max_count) | |
2493 { | |
2494 GList *l; | |
2495 GList *r = NULL; | |
2496 guint c = 0; | |
2497 | |
2498 if (type == GAIM_CONV_TYPE_IM) { | |
2499 l = gaim_get_ims(); | |
2500 } else if (type == GAIM_CONV_TYPE_CHAT) { | |
2501 l = gaim_get_chats(); | |
2502 } else { | |
2503 l = gaim_get_conversations(); | |
2504 } | |
2505 | |
2506 for (; l != NULL && (max_count == 0 || c < max_count); l = l->next) { | |
2507 GaimConversation *conv = (GaimConversation*)l->data; | |
2508 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv); | |
2509 | |
2510 if(gtkconv->active_conv != conv) | |
2511 continue; | |
2512 | |
2513 if (gtkconv->unseen_state >= min_state | |
2514 && (!hidden_only || | |
2515 (hidden_only && gtkconv->win == hidden_convwin))) { | |
2516 | |
2517 r = g_list_prepend(r, conv); | |
2518 c++; | |
2519 } | |
2520 } | |
2521 | |
2522 return r; | |
2523 } | |
2524 | |
2525 static void | |
2526 unseen_conv_menu_cb(GtkMenuItem *item, GaimConversation *conv) | |
2527 { | |
2528 g_return_if_fail(conv != NULL); | |
2529 gaim_gtkconv_present_conversation(conv); | |
2530 } | |
2531 | |
2532 guint | |
2533 gaim_gtk_conversations_fill_menu(GtkWidget *menu, GList *convs) | |
2534 { | |
2535 GList *l; | |
2536 guint ret=0; | |
2537 | |
2538 g_return_val_if_fail(menu != NULL, 0); | |
2539 g_return_val_if_fail(convs != NULL, 0); | |
2540 | |
2541 for (l = convs; l != NULL ; l = l->next) { | |
2542 GaimConversation *conv = (GaimConversation*)l->data; | |
2543 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv); | |
2544 | |
2545 GtkWidget *icon = gtk_image_new(); | |
2546 GdkPixbuf *pbuf = gaim_gtkconv_get_tab_icon(conv, TRUE); | |
2547 GtkWidget *item; | |
2548 gchar *text = g_strdup_printf("%s (%d)", | |
2549 gtk_label_get_text(GTK_LABEL(gtkconv->tab_label)), | |
2550 gtkconv->unseen_count); | |
2551 | |
2552 gtk_image_set_from_pixbuf(GTK_IMAGE(icon), pbuf); | |
2553 g_object_unref(pbuf); | |
2554 | |
2555 item = gtk_image_menu_item_new_with_label(text); | |
2556 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), icon); | |
2557 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(unseen_conv_menu_cb), conv); | |
2558 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
2559 g_free(text); | |
2560 ret++; | |
2561 } | |
2562 | |
2563 return ret; | |
2564 } | |
2565 | |
2566 GaimGtkWindow * | |
2567 gaim_gtkconv_get_window(GaimGtkConversation *gtkconv) | |
2568 { | |
2569 g_return_val_if_fail(gtkconv != NULL, NULL); | |
2570 return gtkconv->win; | |
2571 } | |
2572 | |
2573 static GtkItemFactoryEntry menu_items[] = | |
2574 { | |
2575 /* Conversation menu */ | |
2576 { N_("/_Conversation"), NULL, NULL, 0, "<Branch>", NULL }, | |
2577 | |
2578 { N_("/Conversation/New Instant _Message..."), "<CTL>M", menu_new_conv_cb, | |
2579 0, "<StockItem>", GAIM_STOCK_IM }, | |
2580 | |
2581 { "/Conversation/sep0", NULL, NULL, 0, "<Separator>", NULL }, | |
2582 | |
2583 { N_("/Conversation/_Find..."), NULL, menu_find_cb, 0, | |
2584 "<StockItem>", GTK_STOCK_FIND }, | |
2585 { N_("/Conversation/View _Log"), NULL, menu_view_log_cb, 0, "<StockItem>", GAIM_STOCK_LOG }, | |
2586 { N_("/Conversation/_Save As..."), NULL, menu_save_as_cb, 0, | |
2587 "<StockItem>", GTK_STOCK_SAVE_AS }, | |
2588 { N_("/Conversation/Clea_r Scrollback"), "<CTL>L", menu_clear_cb, 0, "<StockItem>", GTK_STOCK_CLEAR }, | |
2589 | |
2590 { "/Conversation/sep1", NULL, NULL, 0, "<Separator>", NULL }, | |
2591 | |
2592 { N_("/Conversation/Se_nd File..."), NULL, menu_send_file_cb, 0, "<StockItem>", GAIM_STOCK_FILE_TRANSFER }, | |
2593 { N_("/Conversation/Add Buddy _Pounce..."), NULL, menu_add_pounce_cb, | |
2594 0, "<StockItem>", GAIM_STOCK_POUNCE }, | |
2595 { N_("/Conversation/_Get Info"), "<CTL>O", menu_get_info_cb, 0, | |
2596 "<StockItem>", GAIM_STOCK_INFO }, | |
2597 { N_("/Conversation/In_vite..."), NULL, menu_invite_cb, 0, | |
2598 "<StockItem>", GAIM_STOCK_INVITE }, | |
2599 { N_("/Conversation/M_ore"), NULL, NULL, 0, "<Branch>", NULL }, | |
2600 | |
2601 { "/Conversation/sep2", NULL, NULL, 0, "<Separator>", NULL }, | |
2602 | |
2603 { N_("/Conversation/Al_ias..."), NULL, menu_alias_cb, 0, | |
2604 "<StockItem>", GAIM_STOCK_EDIT }, | |
2605 { N_("/Conversation/_Block..."), NULL, menu_block_cb, 0, | |
2606 "<StockItem>", GAIM_STOCK_BLOCK }, | |
2607 { N_("/Conversation/_Add..."), NULL, menu_add_remove_cb, 0, | |
2608 "<StockItem>", GTK_STOCK_ADD }, | |
2609 { N_("/Conversation/_Remove..."), NULL, menu_add_remove_cb, 0, | |
2610 "<StockItem>", GTK_STOCK_REMOVE }, | |
2611 | |
2612 { "/Conversation/sep3", NULL, NULL, 0, "<Separator>", NULL }, | |
2613 | |
2614 { N_("/Conversation/Insert Lin_k..."), NULL, menu_insert_link_cb, 0, | |
2615 "<StockItem>", GAIM_STOCK_LINK }, | |
2616 { N_("/Conversation/Insert Imag_e..."), NULL, menu_insert_image_cb, 0, | |
2617 "<StockItem>", GAIM_STOCK_IMAGE }, | |
2618 | |
2619 { "/Conversation/sep4", NULL, NULL, 0, "<Separator>", NULL }, | |
2620 | |
2621 { N_("/Conversation/_Close"), NULL, menu_close_conv_cb, 0, | |
2622 "<StockItem>", GTK_STOCK_CLOSE }, | |
2623 | |
2624 /* Options */ | |
2625 { N_("/_Options"), NULL, NULL, 0, "<Branch>", NULL }, | |
2626 { N_("/Options/Enable _Logging"), NULL, menu_logging_cb, 0, "<CheckItem>", NULL }, | |
2627 { N_("/Options/Enable _Sounds"), NULL, menu_sounds_cb, 0, "<CheckItem>", NULL }, | |
2628 { N_("/Options/Show Buddy _Icon"), NULL, menu_buddyicon_cb, 0, "<CheckItem>", NULL }, | |
2629 { "/Options/sep0", NULL, NULL, 0, "<Separator>", NULL }, | |
2630 { N_("/Options/Show Formatting _Toolbars"), NULL, menu_toolbar_cb, 0, "<CheckItem>", NULL }, | |
2631 { N_("/Options/Show Ti_mestamps"), "F2", menu_timestamps_cb, 0, "<CheckItem>", NULL }, | |
2632 }; | |
2633 | |
2634 static const int menu_item_count = | |
2635 sizeof(menu_items) / sizeof(*menu_items); | |
2636 | |
2637 static const char * | |
2638 item_factory_translate_func (const char *path, gpointer func_data) | |
2639 { | |
2640 return _(path); | |
2641 } | |
2642 | |
2643 static void | |
2644 sound_method_pref_changed_cb(const char *name, GaimPrefType type, | |
2645 gconstpointer value, gpointer data) | |
2646 { | |
2647 GaimGtkWindow *win = data; | |
2648 const char *method = value; | |
2649 | |
2650 if (!strcmp(method, "none")) | |
2651 { | |
2652 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(win->menu.sounds), | |
2653 FALSE); | |
2654 gtk_widget_set_sensitive(win->menu.sounds, FALSE); | |
2655 } | |
2656 else | |
2657 { | |
2658 GaimGtkConversation *gtkconv = gaim_gtk_conv_window_get_active_gtkconv(win); | |
2659 | |
2660 if (gtkconv != NULL) | |
2661 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(win->menu.sounds), | |
2662 TRUE); | |
2663 gtk_widget_set_sensitive(win->menu.sounds, TRUE); | |
2664 | |
2665 } | |
2666 } | |
2667 | |
2668 static void | |
2669 show_buddy_icons_pref_changed_cb(const char *name, GaimPrefType type, | |
2670 gconstpointer value, gpointer data) | |
2671 { | |
2672 GaimGtkWindow *win = data; | |
2673 gboolean show_icons = GPOINTER_TO_INT(value); | |
2674 | |
2675 if (!show_icons) | |
2676 { | |
2677 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(win->menu.show_icon), | |
2678 FALSE); | |
2679 gtk_widget_set_sensitive(win->menu.show_icon, FALSE); | |
2680 } | |
2681 else | |
2682 { | |
2683 GaimGtkConversation *gtkconv = gaim_gtk_conv_window_get_active_gtkconv(win); | |
2684 | |
2685 if (gtkconv != NULL) | |
2686 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(win->menu.show_icon), | |
2687 TRUE); | |
2688 gtk_widget_set_sensitive(win->menu.show_icon, TRUE); | |
2689 | |
2690 } | |
2691 } | |
2692 | |
2693 static void | |
2694 regenerate_options_items(GaimGtkWindow *win) | |
2695 { | |
2696 GtkWidget *menu; | |
2697 GList *list; | |
2698 GaimGtkConversation *gtkconv; | |
2699 GaimConversation *conv; | |
2700 GaimBuddy *buddy; | |
2701 | |
2702 gtkconv = gaim_gtk_conv_window_get_active_gtkconv(win); | |
2703 conv = gtkconv->active_conv; | |
2704 buddy = gaim_find_buddy(conv->account, conv->name); | |
2705 | |
2706 menu = gtk_item_factory_get_widget(win->menu.item_factory, N_("/Conversation/More")); | |
2707 | |
2708 /* Remove the previous entries */ | |
2709 for (list = gtk_container_get_children(GTK_CONTAINER(menu)); list; ) | |
2710 { | |
2711 GtkWidget *w = list->data; | |
2712 list = list->next; | |
2713 gtk_widget_destroy(w); | |
2714 } | |
2715 | |
2716 /* Now add the stuff */ | |
2717 if (buddy) | |
2718 { | |
2719 if (gaim_account_is_connected(conv->account)) | |
2720 gaim_gtk_append_blist_node_proto_menu(menu, conv->account->gc, | |
2721 (GaimBlistNode *)buddy); | |
2722 gaim_gtk_append_blist_node_extended_menu(menu, (GaimBlistNode *)buddy); | |
2723 } | |
2724 | |
2725 if ((list = gtk_container_get_children(GTK_CONTAINER(menu))) == NULL) | |
2726 { | |
2727 GtkWidget *item = gtk_menu_item_new_with_label(_("No actions available")); | |
2728 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
2729 gtk_widget_set_sensitive(item, FALSE); | |
2730 } | |
2731 | |
2732 gtk_widget_show_all(menu); | |
2733 } | |
2734 | |
2735 static void menubar_activated(GtkWidget *item, gpointer data) | |
2736 { | |
2737 regenerate_options_items(data); | |
2738 g_signal_handlers_block_by_func(G_OBJECT(item), G_CALLBACK(menubar_activated), data); | |
2739 } | |
2740 | |
2741 static void | |
2742 focus_out_from_menubar(GtkWidget *wid, GaimGtkWindow *win) | |
2743 { | |
2744 GtkWidget *menuitem = gtk_item_factory_get_item(win->menu.item_factory, N_("/Conversation")); | |
2745 g_signal_handlers_unblock_by_func(G_OBJECT(menuitem), G_CALLBACK(menubar_activated), win); | |
2746 } | |
2747 | |
2748 static GtkWidget * | |
2749 setup_menubar(GaimGtkWindow *win) | |
2750 { | |
2751 GtkAccelGroup *accel_group; | |
2752 const char *method; | |
2753 GtkWidget *menuitem; | |
2754 | |
2755 accel_group = gtk_accel_group_new (); | |
2756 gtk_window_add_accel_group(GTK_WINDOW(win->window), accel_group); | |
2757 g_object_unref(accel_group); | |
2758 | |
2759 win->menu.item_factory = | |
2760 gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", accel_group); | |
2761 | |
2762 gtk_item_factory_set_translate_func(win->menu.item_factory, | |
2763 (GtkTranslateFunc)item_factory_translate_func, | |
2764 NULL, NULL); | |
2765 | |
2766 gtk_item_factory_create_items(win->menu.item_factory, menu_item_count, | |
2767 menu_items, win); | |
2768 g_signal_connect(G_OBJECT(accel_group), "accel-changed", | |
2769 G_CALLBACK(gaim_gtk_save_accels_cb), NULL); | |
2770 | |
2771 menuitem = gtk_item_factory_get_item(win->menu.item_factory, N_("/Conversation")); | |
2772 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(menubar_activated), win); | |
2773 | |
2774 win->menu.menubar = | |
2775 gtk_item_factory_get_widget(win->menu.item_factory, "<main>"); | |
2776 | |
2777 g_signal_connect(G_OBJECT(win->menu.menubar), "deactivate", G_CALLBACK(focus_out_from_menubar), win); | |
2778 | |
2779 win->menu.view_log = | |
2780 gtk_item_factory_get_widget(win->menu.item_factory, | |
2781 N_("/Conversation/View Log")); | |
2782 | |
2783 /* --- */ | |
2784 | |
2785 win->menu.send_file = | |
2786 gtk_item_factory_get_widget(win->menu.item_factory, | |
2787 N_("/Conversation/Send File...")); | |
2788 | |
2789 win->menu.add_pounce = | |
2790 gtk_item_factory_get_widget(win->menu.item_factory, | |
2791 N_("/Conversation/Add Buddy Pounce...")); | |
2792 | |
2793 /* --- */ | |
2794 | |
2795 win->menu.get_info = | |
2796 gtk_item_factory_get_widget(win->menu.item_factory, | |
2797 N_("/Conversation/Get Info")); | |
2798 | |
2799 win->menu.invite = | |
2800 gtk_item_factory_get_widget(win->menu.item_factory, | |
2801 N_("/Conversation/Invite...")); | |
2802 | |
2803 /* --- */ | |
2804 | |
2805 win->menu.alias = | |
2806 gtk_item_factory_get_widget(win->menu.item_factory, | |
2807 N_("/Conversation/Alias...")); | |
2808 | |
2809 win->menu.block = | |
2810 gtk_item_factory_get_widget(win->menu.item_factory, | |
2811 N_("/Conversation/Block...")); | |
2812 | |
2813 win->menu.add = | |
2814 gtk_item_factory_get_widget(win->menu.item_factory, | |
2815 N_("/Conversation/Add...")); | |
2816 | |
2817 win->menu.remove = | |
2818 gtk_item_factory_get_widget(win->menu.item_factory, | |
2819 N_("/Conversation/Remove...")); | |
2820 | |
2821 /* --- */ | |
2822 | |
2823 win->menu.insert_link = | |
2824 gtk_item_factory_get_widget(win->menu.item_factory, | |
2825 N_("/Conversation/Insert Link...")); | |
2826 | |
2827 win->menu.insert_image = | |
2828 gtk_item_factory_get_widget(win->menu.item_factory, | |
2829 N_("/Conversation/Insert Image...")); | |
2830 | |
2831 /* --- */ | |
2832 | |
2833 win->menu.logging = | |
2834 gtk_item_factory_get_widget(win->menu.item_factory, | |
2835 N_("/Options/Enable Logging")); | |
2836 win->menu.sounds = | |
2837 gtk_item_factory_get_widget(win->menu.item_factory, | |
2838 N_("/Options/Enable Sounds")); | |
2839 method = gaim_prefs_get_string("/gaim/gtk/sound/method"); | |
2840 if (!strcmp(method, "none")) | |
2841 { | |
2842 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(win->menu.sounds), | |
2843 FALSE); | |
2844 gtk_widget_set_sensitive(win->menu.sounds, FALSE); | |
2845 } | |
2846 gaim_prefs_connect_callback(win, "/gaim/gtk/sound/method", | |
2847 sound_method_pref_changed_cb, win); | |
2848 | |
2849 win->menu.show_formatting_toolbar = | |
2850 gtk_item_factory_get_widget(win->menu.item_factory, | |
2851 N_("/Options/Show Formatting Toolbars")); | |
2852 win->menu.show_timestamps = | |
2853 gtk_item_factory_get_widget(win->menu.item_factory, | |
2854 N_("/Options/Show Timestamps")); | |
2855 win->menu.show_icon = | |
2856 gtk_item_factory_get_widget(win->menu.item_factory, | |
2857 N_("/Options/Show Buddy Icon")); | |
2858 if (!gaim_prefs_get_bool("/gaim/gtk/conversations/im/show_buddy_icons")) | |
2859 { | |
2860 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(win->menu.show_icon), | |
2861 FALSE); | |
2862 gtk_widget_set_sensitive(win->menu.show_icon, FALSE); | |
2863 } | |
2864 gaim_prefs_connect_callback(win, "/gaim/gtk/conversations/im/show_buddy_icons", | |
2865 show_buddy_icons_pref_changed_cb, win); | |
2866 | |
2867 win->menu.tray = gaim_gtk_menu_tray_new(); | |
2868 gtk_menu_shell_append(GTK_MENU_SHELL(win->menu.menubar), | |
2869 win->menu.tray); | |
2870 gtk_widget_show(win->menu.tray); | |
2871 | |
2872 gtk_widget_show(win->menu.menubar); | |
2873 | |
2874 return win->menu.menubar; | |
2875 } | |
2876 | |
2877 | |
2878 /************************************************************************** | |
2879 * Utility functions | |
2880 **************************************************************************/ | |
2881 | |
2882 static void | |
2883 got_typing_keypress(GaimGtkConversation *gtkconv, gboolean first) | |
2884 { | |
2885 GaimConversation *conv = gtkconv->active_conv; | |
2886 GaimConvIm *im; | |
2887 | |
2888 /* | |
2889 * We know we got something, so we at least have to make sure we don't | |
2890 * send GAIM_TYPED any time soon. | |
2891 */ | |
2892 | |
2893 im = GAIM_CONV_IM(conv); | |
2894 | |
2895 gaim_conv_im_stop_send_typed_timeout(im); | |
2896 gaim_conv_im_start_send_typed_timeout(im); | |
2897 | |
2898 /* Check if we need to send another GAIM_TYPING message */ | |
2899 if (first || (gaim_conv_im_get_type_again(im) != 0 && | |
2900 time(NULL) > gaim_conv_im_get_type_again(im))) | |
2901 { | |
2902 unsigned int timeout; | |
2903 timeout = serv_send_typing(gaim_conversation_get_gc(conv), | |
2904 gaim_conversation_get_name(conv), | |
2905 GAIM_TYPING); | |
2906 gaim_conv_im_set_type_again(im, timeout); | |
2907 } | |
2908 } | |
2909 | |
2910 static void | |
2911 update_typing_icon(GaimGtkConversation *gtkconv) | |
2912 { | |
2913 GaimGtkWindow *gtkwin; | |
2914 GaimConvIm *im = NULL; | |
2915 GaimConversation *conv = gtkconv->active_conv; | |
2916 char *stock_id; | |
2917 const char *tooltip; | |
2918 | |
2919 gtkwin = gtkconv->win; | |
2920 | |
2921 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) | |
2922 im = GAIM_CONV_IM(conv); | |
2923 | |
2924 if (gtkwin->menu.typing_icon) { | |
2925 gtk_widget_hide(gtkwin->menu.typing_icon); | |
2926 } | |
2927 | |
2928 if (!im || (gaim_conv_im_get_typing_state(im) == GAIM_NOT_TYPING)) | |
2929 return; | |
2930 | |
2931 if (gaim_conv_im_get_typing_state(im) == GAIM_TYPING) { | |
2932 stock_id = GAIM_STOCK_TYPING; | |
2933 tooltip = _("User is typing..."); | |
2934 } else { | |
2935 stock_id = GAIM_STOCK_TYPED; | |
2936 tooltip = _("User has typed something and stopped"); | |
2937 } | |
2938 | |
2939 if (gtkwin->menu.typing_icon == NULL) | |
2940 { | |
2941 gtkwin->menu.typing_icon = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_MENU); | |
2942 gaim_gtk_menu_tray_append(GAIM_GTK_MENU_TRAY(gtkwin->menu.tray), | |
2943 gtkwin->menu.typing_icon, | |
2944 tooltip); | |
2945 } | |
2946 else | |
2947 { | |
2948 gtk_image_set_from_stock(GTK_IMAGE(gtkwin->menu.typing_icon), stock_id, GTK_ICON_SIZE_MENU); | |
2949 gaim_gtk_menu_tray_set_tooltip(GAIM_GTK_MENU_TRAY(gtkwin->menu.tray), | |
2950 gtkwin->menu.typing_icon, | |
2951 tooltip); | |
2952 } | |
2953 | |
2954 gtk_widget_show(gtkwin->menu.typing_icon); | |
2955 } | |
2956 | |
2957 static gboolean | |
2958 update_send_to_selection(GaimGtkWindow *win) | |
2959 { | |
2960 GaimAccount *account; | |
2961 GaimConversation *conv; | |
2962 GtkWidget *menu; | |
2963 GList *child; | |
2964 GaimBuddy *b; | |
2965 | |
2966 conv = gaim_gtk_conv_window_get_active_conversation(win); | |
2967 | |
2968 if (conv == NULL) | |
2969 return FALSE; | |
2970 | |
2971 account = gaim_conversation_get_account(conv); | |
2972 | |
2973 if (account == NULL) | |
2974 return FALSE; | |
2975 | |
2976 if (win->menu.send_to == NULL) | |
2977 return FALSE; | |
2978 | |
2979 if (!(b = gaim_find_buddy(account, conv->name))) | |
2980 return FALSE; | |
2981 | |
2982 | |
2983 gtk_widget_show(win->menu.send_to); | |
2984 | |
2985 menu = gtk_menu_item_get_submenu( | |
2986 GTK_MENU_ITEM(win->menu.send_to)); | |
2987 | |
2988 for (child = gtk_container_get_children(GTK_CONTAINER(menu)); | |
2989 child != NULL; | |
2990 child = child->next) { | |
2991 | |
2992 GtkWidget *item = child->data; | |
2993 GaimBuddy *item_buddy; | |
2994 GaimAccount *item_account = g_object_get_data(G_OBJECT(item), "gaim_account"); | |
2995 gchar *buddy_name = g_object_get_data(G_OBJECT(item), | |
2996 "gaim_buddy_name"); | |
2997 item_buddy = gaim_find_buddy(item_account, buddy_name); | |
2998 | |
2999 if (b == item_buddy) { | |
3000 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE); | |
3001 break; | |
3002 } | |
3003 } | |
3004 | |
3005 return FALSE; | |
3006 } | |
3007 | |
3008 static gboolean | |
3009 send_to_item_enter_notify_cb(GtkWidget *menuitem, GdkEventCrossing *event, GtkWidget *label) | |
3010 { | |
3011 gtk_widget_set_sensitive(GTK_WIDGET(label), TRUE); | |
3012 return FALSE; | |
3013 } | |
3014 | |
3015 static gboolean | |
3016 send_to_item_leave_notify_cb(GtkWidget *menuitem, GdkEventCrossing *event, GtkWidget *label) | |
3017 { | |
3018 gtk_widget_set_sensitive(GTK_WIDGET(label), FALSE); | |
3019 return FALSE; | |
3020 } | |
3021 | |
3022 static void | |
3023 create_sendto_item(GtkWidget *menu, GtkSizeGroup *sg, GSList **group, GaimBuddy *buddy, GaimAccount *account, const char *name) | |
3024 { | |
3025 GtkWidget *box; | |
3026 GtkWidget *label; | |
3027 GtkWidget *image; | |
3028 GtkWidget *menuitem; | |
3029 GdkPixbuf *pixbuf; | |
3030 gchar *text; | |
3031 | |
3032 /* Create a pixmap for the protocol icon. */ | |
3033 if (buddy != NULL) | |
3034 pixbuf = gaim_gtk_blist_get_status_icon((GaimBlistNode*)buddy, GAIM_STATUS_ICON_SMALL); | |
3035 else | |
3036 pixbuf = gaim_gtk_create_prpl_icon(account, 0.5); | |
3037 | |
3038 /* Now convert it to GtkImage */ | |
3039 if (pixbuf == NULL) | |
3040 image = gtk_image_new(); | |
3041 else | |
3042 { | |
3043 image = gtk_image_new_from_pixbuf(pixbuf); | |
3044 g_object_unref(G_OBJECT(pixbuf)); | |
3045 } | |
3046 | |
3047 gtk_size_group_add_widget(sg, image); | |
3048 | |
3049 /* Make our menu item */ | |
3050 text = g_strdup_printf("%s (%s)", name, gaim_account_get_username(account)); | |
3051 menuitem = gtk_radio_menu_item_new_with_label(*group, text); | |
3052 g_free(text); | |
3053 *group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(menuitem)); | |
3054 | |
3055 /* Do some evil, see some evil, speak some evil. */ | |
3056 box = gtk_hbox_new(FALSE, 0); | |
3057 | |
3058 label = gtk_bin_get_child(GTK_BIN(menuitem)); | |
3059 g_object_ref(label); | |
3060 gtk_container_remove(GTK_CONTAINER(menuitem), label); | |
3061 | |
3062 gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0); | |
3063 gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 4); | |
3064 | |
3065 if (buddy != NULL && | |
3066 !gaim_presence_is_online(gaim_buddy_get_presence(buddy)) && | |
3067 !gaim_account_supports_offline_message(account, buddy)) | |
3068 { | |
3069 gtk_widget_set_sensitive(label, FALSE); | |
3070 | |
3071 /* Set the label sensitive when the menuitem is highlighted and | |
3072 * insensitive again when the mouse leaves it. This way, it | |
3073 * doesn't appear weird from the highlighting of the embossed | |
3074 * (insensitive style) text.*/ | |
3075 g_signal_connect(menuitem, "enter-notify-event", | |
3076 G_CALLBACK(send_to_item_enter_notify_cb), label); | |
3077 g_signal_connect(menuitem, "leave-notify-event", | |
3078 G_CALLBACK(send_to_item_leave_notify_cb), label); | |
3079 } | |
3080 | |
3081 g_object_unref(label); | |
3082 | |
3083 gtk_container_add(GTK_CONTAINER(menuitem), box); | |
3084 | |
3085 gtk_widget_show(label); | |
3086 gtk_widget_show(image); | |
3087 gtk_widget_show(box); | |
3088 | |
3089 /* Set our data and callbacks. */ | |
3090 g_object_set_data(G_OBJECT(menuitem), "gaim_account", account); | |
3091 g_object_set_data_full(G_OBJECT(menuitem), "gaim_buddy_name", g_strdup(name), g_free); | |
3092 | |
3093 g_signal_connect(G_OBJECT(menuitem), "activate", | |
3094 G_CALLBACK(menu_conv_sel_send_cb), NULL); | |
3095 | |
3096 gtk_widget_show(menuitem); | |
3097 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
3098 } | |
3099 | |
3100 static void | |
3101 generate_send_to_items(GaimGtkWindow *win) | |
3102 { | |
3103 GtkWidget *menu; | |
3104 GSList *group = NULL; | |
3105 GtkSizeGroup *sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
3106 GaimGtkConversation *gtkconv; | |
3107 GSList *l, *buds; | |
3108 | |
3109 g_return_if_fail(win != NULL); | |
3110 | |
3111 gtkconv = gaim_gtk_conv_window_get_active_gtkconv(win); | |
3112 | |
3113 g_return_if_fail(gtkconv != NULL); | |
3114 | |
3115 if (win->menu.send_to != NULL) | |
3116 gtk_widget_destroy(win->menu.send_to); | |
3117 | |
3118 /* Build the Send To menu */ | |
3119 win->menu.send_to = gtk_menu_item_new_with_mnemonic(_("_Send To")); | |
3120 gtk_widget_show(win->menu.send_to); | |
3121 | |
3122 menu = gtk_menu_new(); | |
3123 gtk_menu_shell_insert(GTK_MENU_SHELL(win->menu.menubar), | |
3124 win->menu.send_to, 2); | |
3125 gtk_menu_item_set_submenu(GTK_MENU_ITEM(win->menu.send_to), menu); | |
3126 | |
3127 gtk_widget_show(menu); | |
3128 | |
3129 if (gtkconv->active_conv->type == GAIM_CONV_TYPE_IM) { | |
3130 buds = gaim_find_buddies(gtkconv->active_conv->account, gtkconv->active_conv->name); | |
3131 | |
3132 if (buds == NULL) | |
3133 { | |
3134 /* The user isn't on the buddy list. */ | |
3135 create_sendto_item(menu, sg, &group, NULL, gtkconv->active_conv->account, gtkconv->active_conv->name); | |
3136 } | |
3137 else | |
3138 { | |
3139 GList *list = NULL, *iter; | |
3140 for (l = buds; l != NULL; l = l->next) | |
3141 { | |
3142 GaimBlistNode *node; | |
3143 | |
3144 node = (GaimBlistNode *) gaim_buddy_get_contact((GaimBuddy *)l->data); | |
3145 | |
3146 for (node = node->child; node != NULL; node = node->next) | |
3147 { | |
3148 GaimBuddy *buddy = (GaimBuddy *)node; | |
3149 GaimAccount *account; | |
3150 | |
3151 if (!GAIM_BLIST_NODE_IS_BUDDY(node)) | |
3152 continue; | |
3153 | |
3154 account = gaim_buddy_get_account(buddy); | |
3155 if (gaim_account_is_connected(account)) | |
3156 { | |
3157 /* Use the GaimPresence to get unique buddies. */ | |
3158 GaimPresence *presence = gaim_buddy_get_presence(buddy); | |
3159 if (!g_list_find(list, presence)) | |
3160 list = g_list_prepend(list, presence); | |
3161 } | |
3162 } | |
3163 } | |
3164 | |
3165 /* Loop over the list backwards so we get the items in the right order, | |
3166 * since we did a g_list_prepend() earlier. */ | |
3167 for (iter = g_list_last(list); iter != NULL; iter = iter->prev) | |
3168 { | |
3169 GaimPresence *pre = iter->data; | |
3170 GaimBuddy *buddy = gaim_presence_get_buddies(pre)->data; | |
3171 create_sendto_item(menu, sg, &group, buddy, | |
3172 gaim_buddy_get_account(buddy), gaim_buddy_get_name(buddy)); | |
3173 } | |
3174 g_list_free(list); | |
3175 g_slist_free(buds); | |
3176 } | |
3177 } | |
3178 | |
3179 g_object_unref(sg); | |
3180 | |
3181 gtk_widget_show(win->menu.send_to); | |
3182 /* TODO: This should never be insensitive. Possibly hidden or not. */ | |
3183 if (!group) | |
3184 gtk_widget_set_sensitive(win->menu.send_to, FALSE); | |
3185 update_send_to_selection(win); | |
3186 } | |
3187 | |
3188 static GList * | |
3189 generate_invite_user_names(GaimConnection *gc) | |
3190 { | |
3191 GaimBlistNode *gnode,*cnode,*bnode; | |
3192 static GList *tmp = NULL; | |
3193 | |
3194 g_list_free(tmp); | |
3195 | |
3196 tmp = g_list_append(NULL, ""); | |
3197 | |
3198 if (gc != NULL) { | |
3199 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { | |
3200 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
3201 continue; | |
3202 for(cnode = gnode->child; cnode; cnode = cnode->next) { | |
3203 if(!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
3204 continue; | |
3205 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
3206 GaimBuddy *buddy; | |
3207 | |
3208 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
3209 continue; | |
3210 | |
3211 buddy = (GaimBuddy *)bnode; | |
3212 | |
3213 if (buddy->account == gc->account && | |
3214 GAIM_BUDDY_IS_ONLINE(buddy)) | |
3215 tmp = g_list_insert_sorted(tmp, buddy->name, | |
3216 (GCompareFunc)g_utf8_collate); | |
3217 } | |
3218 } | |
3219 } | |
3220 } | |
3221 | |
3222 return tmp; | |
3223 } | |
3224 | |
3225 static GdkPixbuf * | |
3226 get_chat_buddy_status_icon(GaimConvChat *chat, const char *name, GaimConvChatBuddyFlags flags) | |
3227 { | |
3228 GdkPixbuf *pixbuf, *scale, *scale2; | |
3229 char *filename; | |
3230 const char *image = NULL; | |
3231 | |
3232 if (flags & GAIM_CBFLAGS_FOUNDER) { | |
3233 image = "founder.png"; | |
3234 } else if (flags & GAIM_CBFLAGS_OP) { | |
3235 image = "op.png"; | |
3236 } else if (flags & GAIM_CBFLAGS_HALFOP) { | |
3237 image = "halfop.png"; | |
3238 } else if (flags & GAIM_CBFLAGS_VOICE) { | |
3239 image = "voice.png"; | |
3240 } else if ((!flags) && gaim_conv_chat_is_user_ignored(chat, name)) { | |
3241 image = "ignored.png"; | |
3242 } else { | |
3243 return NULL; | |
3244 } | |
3245 | |
3246 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
3247 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
3248 g_free(filename); | |
3249 | |
3250 if (!pixbuf) | |
3251 return NULL; | |
3252 | |
3253 scale = gdk_pixbuf_scale_simple(pixbuf, 15, 15, GDK_INTERP_BILINEAR); | |
3254 g_object_unref(pixbuf); | |
3255 | |
3256 if (flags && gaim_conv_chat_is_user_ignored(chat, name)) { | |
3257 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "ignored.png", NULL); | |
3258 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
3259 g_free(filename); | |
3260 scale2 = gdk_pixbuf_scale_simple(pixbuf, 15, 15, GDK_INTERP_BILINEAR); | |
3261 g_object_unref(pixbuf); | |
3262 gdk_pixbuf_composite(scale2, scale, 0, 0, 15, 15, 0, 0, 1, 1, GDK_INTERP_BILINEAR, 192); | |
3263 g_object_unref(scale2); | |
3264 } | |
3265 | |
3266 return scale; | |
3267 } | |
3268 | |
3269 static void | |
3270 add_chat_buddy_common(GaimConversation *conv, GaimConvChatBuddy *cb, const char *old_name) | |
3271 { | |
3272 GaimGtkConversation *gtkconv; | |
3273 GaimGtkChatPane *gtkchat; | |
3274 GaimConvChat *chat; | |
3275 GaimConnection *gc; | |
3276 GaimPluginProtocolInfo *prpl_info; | |
3277 GtkListStore *ls; | |
3278 GdkPixbuf *pixbuf; | |
3279 GtkTreeIter iter; | |
3280 gboolean is_me = FALSE; | |
3281 gboolean is_buddy; | |
3282 gchar *alias_key, *name, *alias; | |
3283 int flags; | |
3284 | |
3285 alias = cb->alias; | |
3286 name = cb->name; | |
3287 flags = GPOINTER_TO_INT(cb->flags); | |
3288 | |
3289 chat = GAIM_CONV_CHAT(conv); | |
3290 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
3291 gtkchat = gtkconv->u.chat; | |
3292 gc = gaim_conversation_get_gc(conv); | |
3293 | |
3294 if (!gc || !(prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl))) | |
3295 return; | |
3296 | |
3297 ls = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list))); | |
3298 | |
3299 pixbuf = get_chat_buddy_status_icon(chat, name, flags); | |
3300 | |
3301 if (!strcmp(chat->nick, gaim_normalize(conv->account, old_name != NULL ? old_name : name))) | |
3302 is_me = TRUE; | |
3303 | |
3304 is_buddy = (gaim_find_buddy(conv->account, name) != NULL); | |
3305 | |
3306 alias_key = g_utf8_collate_key(alias, strlen(alias)); | |
3307 | |
3308 if (is_me) | |
3309 { | |
3310 GdkColor send_color; | |
3311 gdk_color_parse(SEND_COLOR, &send_color); | |
3312 | |
3313 #if GTK_CHECK_VERSION(2,6,0) | |
3314 gtk_list_store_insert_with_values | |
3315 (ls, | |
3316 &iter, | |
3317 /* | |
3318 * The GTK docs are mute about the effects of the "row" value for performance. | |
3319 * X-Chat hardcodes their value to 0 (prepend) and -1 (append), so we will too. | |
3320 * It *might* be faster to search the gtk_list_store and set row accurately, | |
3321 * but no one in #gtk+ seems to know anything about it either. | |
3322 * Inserting in the "wrong" location has no visible ill effects. - F.P. | |
3323 */ | |
3324 -1, /* "row" */ | |
3325 CHAT_USERS_ICON_COLUMN, pixbuf, | |
3326 CHAT_USERS_ALIAS_COLUMN, alias, | |
3327 CHAT_USERS_ALIAS_KEY_COLUMN, alias_key, | |
3328 CHAT_USERS_NAME_COLUMN, name, | |
3329 CHAT_USERS_FLAGS_COLUMN, flags, | |
3330 CHAT_USERS_COLOR_COLUMN, &send_color, | |
3331 CHAT_USERS_BUDDY_COLUMN, is_buddy, | |
3332 -1); | |
3333 } | |
3334 else { | |
3335 gtk_list_store_insert_with_values | |
3336 (ls, | |
3337 &iter, | |
3338 -1, /* "row" */ | |
3339 CHAT_USERS_ICON_COLUMN, pixbuf, | |
3340 CHAT_USERS_ALIAS_COLUMN, alias, | |
3341 CHAT_USERS_ALIAS_KEY_COLUMN, alias_key, | |
3342 CHAT_USERS_NAME_COLUMN, name, | |
3343 CHAT_USERS_FLAGS_COLUMN, flags, | |
3344 CHAT_USERS_COLOR_COLUMN, get_nick_color(gtkconv, name), | |
3345 CHAT_USERS_BUDDY_COLUMN, is_buddy, | |
3346 -1); | |
3347 | |
3348 #else | |
3349 gtk_list_store_append(ls, &iter); | |
3350 gtk_list_store_set(ls, &iter, | |
3351 CHAT_USERS_ICON_COLUMN, pixbuf, | |
3352 CHAT_USERS_ALIAS_COLUMN, alias, | |
3353 CHAT_USERS_ALIAS_KEY_COLUMN, alias_key, | |
3354 CHAT_USERS_NAME_COLUMN, name, | |
3355 CHAT_USERS_FLAGS_COLUMN, flags, | |
3356 CHAT_USERS_COLOR_COLUMN, &send_color, | |
3357 CHAT_USERS_BUDDY_COLUMN, is_buddy, | |
3358 -1); | |
3359 } | |
3360 | |
3361 else { | |
3362 | |
3363 gtk_list_store_append(ls, &iter); | |
3364 gtk_list_store_set(ls, &iter, | |
3365 CHAT_USERS_ICON_COLUMN, pixbuf, | |
3366 CHAT_USERS_ALIAS_COLUMN, alias, | |
3367 CHAT_USERS_ALIAS_KEY_COLUMN, alias_key, | |
3368 CHAT_USERS_NAME_COLUMN, name, | |
3369 CHAT_USERS_FLAGS_COLUMN, flags, | |
3370 CHAT_USERS_COLOR_COLUMN, get_nick_color(gtkconv, name), | |
3371 CHAT_USERS_BUDDY_COLUMN, is_buddy, | |
3372 -1); | |
3373 #endif | |
3374 } | |
3375 | |
3376 if (pixbuf) | |
3377 g_object_unref(pixbuf); | |
3378 g_free(alias_key); | |
3379 } | |
3380 | |
3381 static void | |
3382 tab_complete_process_item(int *most_matched, char *entered, char **partial, char *nick_partial, | |
3383 GList **matches, gboolean command, char *name) | |
3384 { | |
3385 strncpy(nick_partial, name, strlen(entered)); | |
3386 nick_partial[strlen(entered)] = '\0'; | |
3387 if (gaim_utf8_strcasecmp(nick_partial, entered)) | |
3388 return; | |
3389 | |
3390 /* if we're here, it's a possible completion */ | |
3391 | |
3392 if (*most_matched == -1) { | |
3393 /* | |
3394 * this will only get called once, since from now | |
3395 * on *most_matched is >= 0 | |
3396 */ | |
3397 *most_matched = strlen(name); | |
3398 *partial = g_strdup(name); | |
3399 } | |
3400 else if (*most_matched) { | |
3401 char *tmp = g_strdup(name); | |
3402 | |
3403 while (gaim_utf8_strcasecmp(tmp, *partial)) { | |
3404 (*partial)[*most_matched] = '\0'; | |
3405 if (*most_matched < strlen(tmp)) | |
3406 tmp[*most_matched] = '\0'; | |
3407 (*most_matched)--; | |
3408 } | |
3409 (*most_matched)++; | |
3410 | |
3411 g_free(tmp); | |
3412 } | |
3413 | |
3414 *matches = g_list_insert_sorted(*matches, g_strdup(name), | |
3415 (GCompareFunc)gaim_utf8_strcasecmp); | |
3416 } | |
3417 | |
3418 static gboolean | |
3419 tab_complete(GaimConversation *conv) | |
3420 { | |
3421 GaimGtkConversation *gtkconv; | |
3422 GtkTextIter cursor, word_start, start_buffer; | |
3423 int start; | |
3424 int most_matched = -1; | |
3425 char *entered, *partial = NULL; | |
3426 char *text; | |
3427 char *nick_partial; | |
3428 const char *prefix; | |
3429 GList *matches = NULL; | |
3430 gboolean command = FALSE; | |
3431 | |
3432 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
3433 | |
3434 gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, &start_buffer); | |
3435 gtk_text_buffer_get_iter_at_mark(gtkconv->entry_buffer, &cursor, | |
3436 gtk_text_buffer_get_insert(gtkconv->entry_buffer)); | |
3437 | |
3438 word_start = cursor; | |
3439 | |
3440 /* if there's nothing there just return */ | |
3441 if (!gtk_text_iter_compare(&cursor, &start_buffer)) | |
3442 return (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) ? TRUE : FALSE; | |
3443 | |
3444 text = gtk_text_buffer_get_text(gtkconv->entry_buffer, &start_buffer, | |
3445 &cursor, FALSE); | |
3446 | |
3447 /* if we're at the end of ": " we need to move back 2 spaces */ | |
3448 start = strlen(text) - 1; | |
3449 | |
3450 if (strlen(text) >= 2 && !strncmp(&text[start-1], ": ", 2)) { | |
3451 gtk_text_iter_backward_chars(&word_start, 2); | |
3452 start-=2; | |
3453 } | |
3454 | |
3455 /* find the start of the word that we're tabbing */ | |
3456 while (start >= 0 && text[start] != ' ') { | |
3457 gtk_text_iter_backward_char(&word_start); | |
3458 start--; | |
3459 } | |
3460 | |
3461 prefix = gaim_gtk_get_cmd_prefix(); | |
3462 if (start == -1 && (strlen(text) >= strlen(prefix)) && !strncmp(text, prefix, strlen(prefix))) { | |
3463 command = TRUE; | |
3464 gtk_text_iter_forward_chars(&word_start, strlen(prefix)); | |
3465 } | |
3466 | |
3467 g_free(text); | |
3468 | |
3469 entered = gtk_text_buffer_get_text(gtkconv->entry_buffer, &word_start, | |
3470 &cursor, FALSE); | |
3471 | |
3472 if (!g_utf8_strlen(entered, -1)) { | |
3473 g_free(entered); | |
3474 return (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) ? TRUE : FALSE; | |
3475 } | |
3476 | |
3477 nick_partial = g_malloc(strlen(entered)+1); | |
3478 | |
3479 if (command) { | |
3480 GList *list = gaim_cmd_list(conv); | |
3481 GList *l; | |
3482 | |
3483 /* Commands */ | |
3484 for (l = list; l != NULL; l = l->next) { | |
3485 tab_complete_process_item(&most_matched, entered, &partial, nick_partial, | |
3486 &matches, TRUE, l->data); | |
3487 } | |
3488 g_list_free(list); | |
3489 } else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) { | |
3490 GaimConvChat *chat = GAIM_CONV_CHAT(conv); | |
3491 GList *l = gaim_conv_chat_get_users(chat); | |
3492 GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(GAIM_GTK_CONVERSATION(conv)->u.chat->list)); | |
3493 GtkTreeIter iter; | |
3494 int f; | |
3495 | |
3496 /* Users */ | |
3497 for (; l != NULL; l = l->next) { | |
3498 tab_complete_process_item(&most_matched, entered, &partial, nick_partial, | |
3499 &matches, TRUE, ((GaimConvChatBuddy *)l->data)->name); | |
3500 } | |
3501 | |
3502 | |
3503 /* Aliases */ | |
3504 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) | |
3505 { | |
3506 do { | |
3507 char *name; | |
3508 char *alias; | |
3509 | |
3510 gtk_tree_model_get(model, &iter, | |
3511 CHAT_USERS_NAME_COLUMN, &name, | |
3512 CHAT_USERS_ALIAS_COLUMN, &alias, | |
3513 -1); | |
3514 | |
3515 if (strcmp(name, alias)) | |
3516 tab_complete_process_item(&most_matched, entered, &partial, nick_partial, | |
3517 &matches, FALSE, alias); | |
3518 g_free(name); | |
3519 g_free(alias); | |
3520 | |
3521 f = gtk_tree_model_iter_next(model, &iter); | |
3522 } while (f != 0); | |
3523 } | |
3524 } else { | |
3525 g_free(nick_partial); | |
3526 g_free(entered); | |
3527 return FALSE; | |
3528 } | |
3529 | |
3530 g_free(nick_partial); | |
3531 | |
3532 /* we're only here if we're doing new style */ | |
3533 | |
3534 /* if there weren't any matches, return */ | |
3535 if (!matches) { | |
3536 /* if matches isn't set partials won't be either */ | |
3537 g_free(entered); | |
3538 return (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) ? TRUE : FALSE; | |
3539 } | |
3540 | |
3541 gtk_text_buffer_delete(gtkconv->entry_buffer, &word_start, &cursor); | |
3542 | |
3543 if (!matches->next) { | |
3544 /* there was only one match. fill it in. */ | |
3545 gtk_text_buffer_get_start_iter(gtkconv->entry_buffer, &start_buffer); | |
3546 gtk_text_buffer_get_iter_at_mark(gtkconv->entry_buffer, &cursor, | |
3547 gtk_text_buffer_get_insert(gtkconv->entry_buffer)); | |
3548 | |
3549 if (!gtk_text_iter_compare(&cursor, &start_buffer)) { | |
3550 char *tmp = g_strdup_printf("%s: ", (char *)matches->data); | |
3551 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, tmp, -1); | |
3552 g_free(tmp); | |
3553 } | |
3554 else | |
3555 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, | |
3556 matches->data, -1); | |
3557 | |
3558 g_free(matches->data); | |
3559 matches = g_list_remove(matches, matches->data); | |
3560 } | |
3561 else { | |
3562 /* | |
3563 * there were lots of matches, fill in as much as possible | |
3564 * and display all of them | |
3565 */ | |
3566 char *addthis = g_malloc0(1); | |
3567 | |
3568 while (matches) { | |
3569 char *tmp = addthis; | |
3570 addthis = g_strconcat(tmp, matches->data, " ", NULL); | |
3571 g_free(tmp); | |
3572 g_free(matches->data); | |
3573 matches = g_list_remove(matches, matches->data); | |
3574 } | |
3575 | |
3576 gaim_conversation_write(conv, NULL, addthis, GAIM_MESSAGE_NO_LOG, | |
3577 time(NULL)); | |
3578 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, partial, -1); | |
3579 g_free(addthis); | |
3580 } | |
3581 | |
3582 g_free(entered); | |
3583 g_free(partial); | |
3584 | |
3585 return TRUE; | |
3586 } | |
3587 | |
3588 static void topic_callback(GtkWidget *w, GaimGtkConversation *gtkconv) | |
3589 { | |
3590 GaimPluginProtocolInfo *prpl_info = NULL; | |
3591 GaimConnection *gc; | |
3592 GaimConversation *conv = gtkconv->active_conv; | |
3593 GaimGtkChatPane *gtkchat; | |
3594 char *new_topic; | |
3595 const char *current_topic; | |
3596 | |
3597 gc = gaim_conversation_get_gc(conv); | |
3598 | |
3599 if(!gc || !(prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl))) | |
3600 return; | |
3601 | |
3602 if(prpl_info->set_chat_topic == NULL) | |
3603 return; | |
3604 | |
3605 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
3606 gtkchat = gtkconv->u.chat; | |
3607 new_topic = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtkchat->topic_text))); | |
3608 current_topic = gaim_conv_chat_get_topic(GAIM_CONV_CHAT(conv)); | |
3609 | |
3610 if(current_topic && !g_utf8_collate(new_topic, current_topic)){ | |
3611 g_free(new_topic); | |
3612 return; | |
3613 } | |
3614 | |
3615 gtk_entry_set_text(GTK_ENTRY(gtkchat->topic_text), current_topic); | |
3616 | |
3617 prpl_info->set_chat_topic(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), | |
3618 new_topic); | |
3619 | |
3620 g_free(new_topic); | |
3621 } | |
3622 | |
3623 static gint | |
3624 sort_chat_users(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer userdata) | |
3625 { | |
3626 GaimConvChatBuddyFlags f1 = 0, f2 = 0; | |
3627 char *user1 = NULL, *user2 = NULL; | |
3628 gboolean buddy1 = FALSE, buddy2 = FALSE; | |
3629 gint ret = 0; | |
3630 | |
3631 gtk_tree_model_get(model, a, | |
3632 CHAT_USERS_ALIAS_KEY_COLUMN, &user1, | |
3633 CHAT_USERS_FLAGS_COLUMN, &f1, | |
3634 CHAT_USERS_BUDDY_COLUMN, &buddy1, | |
3635 -1); | |
3636 gtk_tree_model_get(model, b, | |
3637 CHAT_USERS_ALIAS_KEY_COLUMN, &user2, | |
3638 CHAT_USERS_FLAGS_COLUMN, &f2, | |
3639 CHAT_USERS_BUDDY_COLUMN, &buddy2, | |
3640 -1); | |
3641 | |
3642 if (user1 == NULL || user2 == NULL) { | |
3643 if (!(user1 == NULL && user2 == NULL)) | |
3644 ret = (user1 == NULL) ? -1: 1; | |
3645 } else if (f1 != f2) { | |
3646 /* sort more important users first */ | |
3647 ret = (f1 > f2) ? -1 : 1; | |
3648 } else if (buddy1 != buddy2) { | |
3649 ret = buddy1 ? -1 : 1; | |
3650 } else { | |
3651 ret = strcasecmp(user1, user2); | |
3652 } | |
3653 | |
3654 g_free(user1); | |
3655 g_free(user2); | |
3656 | |
3657 return ret; | |
3658 } | |
3659 | |
3660 static void | |
3661 update_chat_alias(GaimBuddy *buddy, GaimConversation *conv, GaimConnection *gc, GaimPluginProtocolInfo *prpl_info) | |
3662 { | |
3663 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv); | |
3664 GaimConvChat *chat = GAIM_CONV_CHAT(conv); | |
3665 GtkTreeModel *model; | |
3666 char *normalized_name; | |
3667 GtkTreeIter iter; | |
3668 int f; | |
3669 | |
3670 g_return_if_fail(buddy != NULL); | |
3671 g_return_if_fail(conv != NULL); | |
3672 | |
3673 /* This is safe because this callback is only used in chats, not IMs. */ | |
3674 model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkconv->u.chat->list)); | |
3675 | |
3676 if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) | |
3677 return; | |
3678 | |
3679 normalized_name = g_strdup(gaim_normalize(conv->account, buddy->name)); | |
3680 | |
3681 do { | |
3682 char *name; | |
3683 | |
3684 gtk_tree_model_get(model, &iter, CHAT_USERS_NAME_COLUMN, &name, -1); | |
3685 | |
3686 if (!strcmp(normalized_name, gaim_normalize(conv->account, name))) { | |
3687 const char *alias = name; | |
3688 char *alias_key = NULL; | |
3689 GaimBuddy *buddy2; | |
3690 | |
3691 if (strcmp(chat->nick, gaim_normalize(conv->account, name))) { | |
3692 /* This user is not me, so look into updating the alias. */ | |
3693 | |
3694 if ((buddy2 = gaim_find_buddy(conv->account, name)) != NULL) { | |
3695 alias = gaim_buddy_get_contact_alias(buddy2); | |
3696 } | |
3697 | |
3698 alias_key = g_utf8_collate_key(alias, strlen(alias)); | |
3699 | |
3700 gtk_list_store_set(GTK_LIST_STORE(model), &iter, | |
3701 CHAT_USERS_ALIAS_COLUMN, alias, | |
3702 CHAT_USERS_ALIAS_KEY_COLUMN, alias_key, | |
3703 -1); | |
3704 g_free(alias_key); | |
3705 } | |
3706 g_free(name); | |
3707 break; | |
3708 } | |
3709 | |
3710 f = gtk_tree_model_iter_next(model, &iter); | |
3711 | |
3712 g_free(name); | |
3713 } while (f != 0); | |
3714 | |
3715 g_free(normalized_name); | |
3716 } | |
3717 | |
3718 static void | |
3719 blist_node_aliased_cb(GaimBlistNode *node, const char *old_alias, GaimConversation *conv) | |
3720 { | |
3721 GaimConnection *gc; | |
3722 GaimPluginProtocolInfo *prpl_info; | |
3723 | |
3724 g_return_if_fail(node != NULL); | |
3725 g_return_if_fail(conv != NULL); | |
3726 | |
3727 gc = gaim_conversation_get_gc(conv); | |
3728 g_return_if_fail(gc != NULL); | |
3729 g_return_if_fail(gc->prpl != NULL); | |
3730 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
3731 | |
3732 if (prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME) | |
3733 return; | |
3734 | |
3735 if (GAIM_BLIST_NODE_IS_CONTACT(node)) | |
3736 { | |
3737 GaimBlistNode *bnode; | |
3738 | |
3739 for(bnode = node->child; bnode; bnode = bnode->next) { | |
3740 | |
3741 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
3742 continue; | |
3743 | |
3744 update_chat_alias((GaimBuddy *)bnode, conv, gc, prpl_info); | |
3745 } | |
3746 } | |
3747 else if (GAIM_BLIST_NODE_IS_BUDDY(node)) | |
3748 update_chat_alias((GaimBuddy *)node, conv, gc, prpl_info); | |
3749 } | |
3750 | |
3751 static void | |
3752 buddy_cb_common(GaimBuddy *buddy, GaimConversation *conv, gboolean is_buddy) | |
3753 { | |
3754 GtkTreeModel *model; | |
3755 char *normalized_name; | |
3756 GtkTreeIter iter; | |
3757 int f; | |
3758 | |
3759 g_return_if_fail(buddy != NULL); | |
3760 g_return_if_fail(conv != NULL); | |
3761 | |
3762 /* Do nothing if the buddy does not belong to the conv's account */ | |
3763 if (gaim_buddy_get_account(buddy) != gaim_conversation_get_account(conv)) | |
3764 return; | |
3765 | |
3766 /* This is safe because this callback is only used in chats, not IMs. */ | |
3767 model = gtk_tree_view_get_model(GTK_TREE_VIEW(GAIM_GTK_CONVERSATION(conv)->u.chat->list)); | |
3768 | |
3769 if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) | |
3770 return; | |
3771 | |
3772 normalized_name = g_strdup(gaim_normalize(conv->account, buddy->name)); | |
3773 | |
3774 do { | |
3775 char *name; | |
3776 | |
3777 gtk_tree_model_get(model, &iter, CHAT_USERS_NAME_COLUMN, &name, -1); | |
3778 | |
3779 if (!strcmp(normalized_name, gaim_normalize(conv->account, name))) { | |
3780 gtk_list_store_set(GTK_LIST_STORE(model), &iter, CHAT_USERS_BUDDY_COLUMN, is_buddy, -1); | |
3781 g_free(name); | |
3782 break; | |
3783 } | |
3784 | |
3785 f = gtk_tree_model_iter_next(model, &iter); | |
3786 | |
3787 g_free(name); | |
3788 } while (f != 0); | |
3789 | |
3790 g_free(normalized_name); | |
3791 | |
3792 blist_node_aliased_cb((GaimBlistNode *)buddy, NULL, conv); | |
3793 } | |
3794 | |
3795 static void | |
3796 buddy_added_cb(GaimBuddy *buddy, GaimConversation *conv) | |
3797 { | |
3798 buddy_cb_common(buddy, conv, TRUE); | |
3799 } | |
3800 | |
3801 static void | |
3802 buddy_removed_cb(GaimBuddy *buddy, GaimConversation *conv) | |
3803 { | |
3804 /* If there's another buddy for the same "dude" on the list, do nothing. */ | |
3805 if (gaim_find_buddy(buddy->account, buddy->name) != NULL) | |
3806 return; | |
3807 | |
3808 buddy_cb_common(buddy, conv, FALSE); | |
3809 } | |
3810 | |
3811 static void send_menu_cb(GtkWidget *widget, GaimGtkConversation *gtkconv) | |
3812 { | |
3813 g_signal_emit_by_name(gtkconv->entry, "message_send"); | |
3814 } | |
3815 | |
3816 static void | |
3817 entry_popup_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data) | |
3818 { | |
3819 GtkWidget *menuitem; | |
3820 GaimGtkConversation *gtkconv = data; | |
3821 | |
3822 g_return_if_fail(menu != NULL); | |
3823 g_return_if_fail(gtkconv != NULL); | |
3824 | |
3825 menuitem = gaim_new_item_from_stock(NULL, _("_Send"), GAIM_STOCK_SEND, | |
3826 G_CALLBACK(send_menu_cb), gtkconv, | |
3827 0, 0, NULL); | |
3828 if (gtk_text_buffer_get_char_count(imhtml->text_buffer) == 0) | |
3829 gtk_widget_set_sensitive(menuitem, FALSE); | |
3830 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 0); | |
3831 | |
3832 menuitem = gtk_separator_menu_item_new(); | |
3833 gtk_widget_show(menuitem); | |
3834 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 1); | |
3835 } | |
3836 | |
3837 static GtkWidget * | |
3838 setup_chat_pane(GaimGtkConversation *gtkconv) | |
3839 { | |
3840 GaimPluginProtocolInfo *prpl_info; | |
3841 GaimConversation *conv = gtkconv->active_conv; | |
3842 GaimGtkChatPane *gtkchat; | |
3843 GaimConnection *gc; | |
3844 GtkWidget *vpaned, *hpaned; | |
3845 GtkWidget *vbox, *hbox, *frame; | |
3846 GtkWidget *imhtml_sw; | |
3847 GtkPolicyType imhtml_sw_hscroll; | |
3848 GtkWidget *lbox; | |
3849 GtkWidget *label; | |
3850 GtkWidget *list; | |
3851 GtkWidget *sw; | |
3852 GtkListStore *ls; | |
3853 GtkCellRenderer *rend; | |
3854 GtkTreeViewColumn *col; | |
3855 void *blist_handle = gaim_blist_get_handle(); | |
3856 GList *focus_chain = NULL; | |
3857 | |
3858 gtkchat = gtkconv->u.chat; | |
3859 gc = gaim_conversation_get_gc(conv); | |
3860 g_return_val_if_fail(gc != NULL, NULL); | |
3861 g_return_val_if_fail(gc->prpl != NULL, NULL); | |
3862 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
3863 | |
3864 /* Setup the outer pane. */ | |
3865 vpaned = gtk_vpaned_new(); | |
3866 gtk_widget_show(vpaned); | |
3867 | |
3868 /* Setup the top part of the pane. */ | |
3869 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
3870 gtk_paned_pack1(GTK_PANED(vpaned), vbox, TRUE, TRUE); | |
3871 gtk_widget_show(vbox); | |
3872 | |
3873 if (prpl_info->options & OPT_PROTO_CHAT_TOPIC) | |
3874 { | |
3875 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
3876 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
3877 gtk_widget_show(hbox); | |
3878 | |
3879 label = gtk_label_new(_("Topic:")); | |
3880 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
3881 gtk_widget_show(label); | |
3882 | |
3883 gtkchat->topic_text = gtk_entry_new(); | |
3884 | |
3885 if(prpl_info->set_chat_topic == NULL) { | |
3886 gtk_editable_set_editable(GTK_EDITABLE(gtkchat->topic_text), FALSE); | |
3887 } else { | |
3888 g_signal_connect(GTK_OBJECT(gtkchat->topic_text), "activate", | |
3889 G_CALLBACK(topic_callback), gtkconv); | |
3890 } | |
3891 | |
3892 gtk_box_pack_start(GTK_BOX(hbox), gtkchat->topic_text, TRUE, TRUE, 0); | |
3893 gtk_widget_show(gtkchat->topic_text); | |
3894 } | |
3895 | |
3896 /* Setup the horizontal pane. */ | |
3897 hpaned = gtk_hpaned_new(); | |
3898 gtk_box_pack_start(GTK_BOX(vbox), hpaned, TRUE, TRUE, 0); | |
3899 gtk_widget_show(hpaned); | |
3900 | |
3901 /* Setup gtkihmtml. */ | |
3902 frame = gaim_gtk_create_imhtml(FALSE, >kconv->imhtml, NULL, &imhtml_sw); | |
3903 gtk_widget_set_name(gtkconv->imhtml, "gaim_gtkconv_imhtml"); | |
3904 gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), TRUE); | |
3905 gtk_paned_pack1(GTK_PANED(hpaned), frame, TRUE, TRUE); | |
3906 gtk_widget_show(frame); | |
3907 gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(imhtml_sw), | |
3908 &imhtml_sw_hscroll, NULL); | |
3909 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(imhtml_sw), | |
3910 imhtml_sw_hscroll, GTK_POLICY_ALWAYS); | |
3911 | |
3912 gtk_widget_set_size_request(gtkconv->imhtml, | |
3913 gaim_prefs_get_int("/gaim/gtk/conversations/chat/default_width"), | |
3914 gaim_prefs_get_int("/gaim/gtk/conversations/chat/default_height")); | |
3915 g_signal_connect(G_OBJECT(gtkconv->imhtml), "size-allocate", | |
3916 G_CALLBACK(size_allocate_cb), gtkconv); | |
3917 | |
3918 g_signal_connect_after(G_OBJECT(gtkconv->imhtml), "button_press_event", | |
3919 G_CALLBACK(entry_stop_rclick_cb), NULL); | |
3920 g_signal_connect(G_OBJECT(gtkconv->imhtml), "key_press_event", | |
3921 G_CALLBACK(refocus_entry_cb), gtkconv); | |
3922 g_signal_connect(G_OBJECT(gtkconv->imhtml), "key_release_event", | |
3923 G_CALLBACK(refocus_entry_cb), gtkconv); | |
3924 | |
3925 /* Build the right pane. */ | |
3926 lbox = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
3927 gtk_paned_pack2(GTK_PANED(hpaned), lbox, FALSE, TRUE); | |
3928 gtk_widget_show(lbox); | |
3929 | |
3930 /* Setup the label telling how many people are in the room. */ | |
3931 gtkchat->count = gtk_label_new(_("0 people in room")); | |
3932 gtk_box_pack_start(GTK_BOX(lbox), gtkchat->count, FALSE, FALSE, 0); | |
3933 gtk_widget_show(gtkchat->count); | |
3934 | |
3935 /* Setup the list of users. */ | |
3936 sw = gtk_scrolled_window_new(NULL, NULL); | |
3937 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
3938 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
3939 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); | |
3940 gtk_box_pack_start(GTK_BOX(lbox), sw, TRUE, TRUE, 0); | |
3941 gtk_widget_show(sw); | |
3942 | |
3943 ls = gtk_list_store_new(CHAT_USERS_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, | |
3944 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, | |
3945 GDK_TYPE_COLOR, G_TYPE_BOOLEAN); | |
3946 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(ls), CHAT_USERS_ALIAS_KEY_COLUMN, | |
3947 sort_chat_users, NULL, NULL); | |
3948 | |
3949 list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ls)); | |
3950 | |
3951 rend = gtk_cell_renderer_pixbuf_new(); | |
3952 | |
3953 col = gtk_tree_view_column_new_with_attributes(NULL, rend, | |
3954 "pixbuf", CHAT_USERS_ICON_COLUMN, NULL); | |
3955 gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
3956 gtk_tree_view_append_column(GTK_TREE_VIEW(list), col); | |
3957 | |
3958 g_signal_connect(G_OBJECT(list), "button_press_event", | |
3959 G_CALLBACK(right_click_chat_cb), gtkconv); | |
3960 g_signal_connect(G_OBJECT(list), "popup-menu", | |
3961 G_CALLBACK(gtkconv_chat_popup_menu_cb), gtkconv); | |
3962 | |
3963 rend = gtk_cell_renderer_text_new(); | |
3964 | |
3965 g_object_set(rend, | |
3966 "foreground-set", TRUE, | |
3967 "weight", PANGO_WEIGHT_BOLD, | |
3968 NULL); | |
3969 col = gtk_tree_view_column_new_with_attributes(NULL, rend, | |
3970 "text", CHAT_USERS_ALIAS_COLUMN, | |
3971 "foreground-gdk", CHAT_USERS_COLOR_COLUMN, | |
3972 "weight-set", CHAT_USERS_BUDDY_COLUMN, | |
3973 NULL); | |
3974 | |
3975 gaim_signal_connect(blist_handle, "buddy-added", | |
3976 gtkchat, GAIM_CALLBACK(buddy_added_cb), conv); | |
3977 gaim_signal_connect(blist_handle, "buddy-removed", | |
3978 gtkchat, GAIM_CALLBACK(buddy_removed_cb), conv); | |
3979 gaim_signal_connect(blist_handle, "blist-node-aliased", | |
3980 gtkchat, GAIM_CALLBACK(blist_node_aliased_cb), conv); | |
3981 | |
3982 #if GTK_CHECK_VERSION(2,6,0) | |
3983 gtk_tree_view_column_set_expand(col, TRUE); | |
3984 g_object_set(rend, "ellipsize", PANGO_ELLIPSIZE_END, NULL); | |
3985 #endif | |
3986 | |
3987 gtk_tree_view_append_column(GTK_TREE_VIEW(list), col); | |
3988 | |
3989 gtk_widget_set_size_request(list, 150, -1); | |
3990 | |
3991 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list), FALSE); | |
3992 gtk_widget_show(list); | |
3993 | |
3994 gtkchat->list = list; | |
3995 | |
3996 gtk_container_add(GTK_CONTAINER(sw), list); | |
3997 | |
3998 /* Setup the bottom half of the conversation window */ | |
3999 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
4000 gtk_paned_pack2(GTK_PANED(vpaned), vbox, FALSE, TRUE); | |
4001 gtk_widget_show(vbox); | |
4002 | |
4003 gtkconv->lower_hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
4004 gtk_box_pack_start(GTK_BOX(vbox), gtkconv->lower_hbox, TRUE, TRUE, 0); | |
4005 gtk_widget_show(gtkconv->lower_hbox); | |
4006 | |
4007 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
4008 gtk_box_pack_end(GTK_BOX(gtkconv->lower_hbox), vbox, TRUE, TRUE, 0); | |
4009 gtk_widget_show(vbox); | |
4010 | |
4011 /* Setup the toolbar, entry widget and all signals */ | |
4012 frame = gaim_gtk_create_imhtml(TRUE, >kconv->entry, >kconv->toolbar, NULL); | |
4013 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); | |
4014 gtk_widget_show(frame); | |
4015 | |
4016 g_signal_connect(G_OBJECT(gtkconv->entry), "populate-popup", | |
4017 G_CALLBACK(entry_popup_menu_cb), gtkconv); | |
4018 | |
4019 gtk_widget_set_name(gtkconv->entry, "gaim_gtkconv_entry"); | |
4020 gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->entry), | |
4021 gaim_account_get_protocol_name(conv->account)); | |
4022 gtk_widget_set_size_request(gtkconv->entry, -1, | |
4023 gaim_prefs_get_int("/gaim/gtk/conversations/chat/entry_height")); | |
4024 gtkconv->entry_buffer = | |
4025 gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry)); | |
4026 g_object_set_data(G_OBJECT(gtkconv->entry_buffer), "user_data", gtkconv); | |
4027 | |
4028 g_signal_connect(G_OBJECT(gtkconv->entry), "key_press_event", | |
4029 G_CALLBACK(entry_key_press_cb), gtkconv); | |
4030 g_signal_connect_after(G_OBJECT(gtkconv->entry), "message_send", | |
4031 G_CALLBACK(send_cb), gtkconv); | |
4032 g_signal_connect_after(G_OBJECT(gtkconv->entry), "button_press_event", | |
4033 G_CALLBACK(entry_stop_rclick_cb), NULL); | |
4034 g_signal_connect(G_OBJECT(gtkconv->entry), "size-allocate", | |
4035 G_CALLBACK(size_allocate_cb), gtkconv); | |
4036 | |
4037 default_formatize(gtkconv); | |
4038 | |
4039 /* | |
4040 * Focus for chat windows should be as follows: | |
4041 * Tab title -> chat topic -> conversation scrollback -> user list -> | |
4042 * user list buttons -> entry -> buttons at bottom | |
4043 */ | |
4044 focus_chain = g_list_prepend(focus_chain, gtkconv->entry); | |
4045 gtk_container_set_focus_chain(GTK_CONTAINER(vbox), focus_chain); | |
4046 | |
4047 return vpaned; | |
4048 } | |
4049 | |
4050 static GtkWidget * | |
4051 setup_im_pane(GaimGtkConversation *gtkconv) | |
4052 { | |
4053 GaimConversation *conv = gtkconv->active_conv; | |
4054 GtkWidget *frame; | |
4055 GtkWidget *imhtml_sw; | |
4056 GtkPolicyType imhtml_sw_hscroll; | |
4057 GtkWidget *paned; | |
4058 GtkWidget *vbox; | |
4059 GtkWidget *vbox2; | |
4060 GList *focus_chain = NULL; | |
4061 | |
4062 /* Setup the outer pane */ | |
4063 paned = gtk_vpaned_new(); | |
4064 gtk_widget_show(paned); | |
4065 | |
4066 /* Setup the top part of the pane */ | |
4067 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
4068 gtk_paned_pack1(GTK_PANED(paned), vbox, TRUE, TRUE); | |
4069 gtk_widget_show(vbox); | |
4070 | |
4071 /* Setup the gtkimhtml widget */ | |
4072 frame = gaim_gtk_create_imhtml(FALSE, >kconv->imhtml, NULL, &imhtml_sw); | |
4073 gtk_widget_set_name(gtkconv->imhtml, "gaim_gtkconv_imhtml"); | |
4074 gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml),TRUE); | |
4075 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); | |
4076 gtk_widget_show(frame); | |
4077 gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(imhtml_sw), | |
4078 &imhtml_sw_hscroll, NULL); | |
4079 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(imhtml_sw), | |
4080 imhtml_sw_hscroll, GTK_POLICY_ALWAYS); | |
4081 | |
4082 gtk_widget_set_size_request(gtkconv->imhtml, | |
4083 gaim_prefs_get_int("/gaim/gtk/conversations/im/default_width"), | |
4084 gaim_prefs_get_int("/gaim/gtk/conversations/im/default_height")); | |
4085 g_signal_connect(G_OBJECT(gtkconv->imhtml), "size-allocate", | |
4086 G_CALLBACK(size_allocate_cb), gtkconv); | |
4087 | |
4088 g_signal_connect_after(G_OBJECT(gtkconv->imhtml), "button_press_event", | |
4089 G_CALLBACK(entry_stop_rclick_cb), NULL); | |
4090 g_signal_connect(G_OBJECT(gtkconv->imhtml), "key_press_event", | |
4091 G_CALLBACK(refocus_entry_cb), gtkconv); | |
4092 g_signal_connect(G_OBJECT(gtkconv->imhtml), "key_release_event", | |
4093 G_CALLBACK(refocus_entry_cb), gtkconv); | |
4094 | |
4095 /* Setup the bottom half of the conversation window */ | |
4096 vbox2 = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
4097 gtk_paned_pack2(GTK_PANED(paned), vbox2, FALSE, TRUE); | |
4098 gtk_widget_show(vbox2); | |
4099 | |
4100 gtkconv->lower_hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
4101 gtk_box_pack_start(GTK_BOX(vbox2), gtkconv->lower_hbox, TRUE, TRUE, 0); | |
4102 gtk_widget_show(gtkconv->lower_hbox); | |
4103 | |
4104 vbox2 = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
4105 gtk_box_pack_end(GTK_BOX(gtkconv->lower_hbox), vbox2, TRUE, TRUE, 0); | |
4106 gtk_widget_show(vbox2); | |
4107 | |
4108 /* Setup the toolbar, entry widget and all signals */ | |
4109 frame = gaim_gtk_create_imhtml(TRUE, >kconv->entry, >kconv->toolbar, NULL); | |
4110 gtk_box_pack_start(GTK_BOX(vbox2), frame, TRUE, TRUE, 0); | |
4111 gtk_widget_show(frame); | |
4112 | |
4113 g_signal_connect(G_OBJECT(gtkconv->entry), "populate-popup", | |
4114 G_CALLBACK(entry_popup_menu_cb), gtkconv); | |
4115 | |
4116 gtk_widget_set_name(gtkconv->entry, "gaim_gtkconv_entry"); | |
4117 gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->entry), | |
4118 gaim_account_get_protocol_name(conv->account)); | |
4119 gtk_widget_set_size_request(gtkconv->entry, -1, | |
4120 gaim_prefs_get_int("/gaim/gtk/conversations/im/entry_height")); | |
4121 gtkconv->entry_buffer = | |
4122 gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry)); | |
4123 g_object_set_data(G_OBJECT(gtkconv->entry_buffer), "user_data", gtkconv); | |
4124 | |
4125 g_signal_connect(G_OBJECT(gtkconv->entry), "key_press_event", | |
4126 G_CALLBACK(entry_key_press_cb), gtkconv); | |
4127 g_signal_connect_after(G_OBJECT(gtkconv->entry), "message_send", | |
4128 G_CALLBACK(send_cb), gtkconv); | |
4129 g_signal_connect_after(G_OBJECT(gtkconv->entry), "button_press_event", | |
4130 G_CALLBACK(entry_stop_rclick_cb), NULL); | |
4131 g_signal_connect(G_OBJECT(gtkconv->entry), "size-allocate", | |
4132 G_CALLBACK(size_allocate_cb), gtkconv); | |
4133 | |
4134 g_signal_connect(G_OBJECT(gtkconv->entry_buffer), "insert_text", | |
4135 G_CALLBACK(insert_text_cb), gtkconv); | |
4136 g_signal_connect(G_OBJECT(gtkconv->entry_buffer), "delete_range", | |
4137 G_CALLBACK(delete_text_cb), gtkconv); | |
4138 | |
4139 /* had to move this after the imtoolbar is attached so that the | |
4140 * signals get fired to toggle the buttons on the toolbar as well. | |
4141 */ | |
4142 default_formatize(gtkconv); | |
4143 | |
4144 g_signal_connect_after(G_OBJECT(gtkconv->entry), "format_function_clear", | |
4145 G_CALLBACK(clear_formatting_cb), gtkconv); | |
4146 | |
4147 gtkconv->u.im->animate = gaim_prefs_get_bool("/gaim/gtk/conversations/im/animate_buddy_icons"); | |
4148 gtkconv->u.im->show_icon = TRUE; | |
4149 | |
4150 /* | |
4151 * Focus for IM windows should be as follows: | |
4152 * Tab title -> conversation scrollback -> entry | |
4153 */ | |
4154 focus_chain = g_list_prepend(focus_chain, gtkconv->entry); | |
4155 gtk_container_set_focus_chain(GTK_CONTAINER(vbox2), focus_chain); | |
4156 | |
4157 return paned; | |
4158 } | |
4159 | |
4160 static void | |
4161 conv_dnd_recv(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, | |
4162 GtkSelectionData *sd, guint info, guint t, | |
4163 GaimGtkConversation *gtkconv) | |
4164 { | |
4165 GaimConversation *conv = gtkconv->active_conv; | |
4166 GaimGtkWindow *win = gtkconv->win; | |
4167 GaimConversation *c; | |
4168 if (sd->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE)) | |
4169 { | |
4170 GaimBlistNode *n = NULL; | |
4171 GaimBuddy *b; | |
4172 GaimGtkConversation *gtkconv = NULL; | |
4173 | |
4174 n = *(GaimBlistNode **)sd->data; | |
4175 | |
4176 if (GAIM_BLIST_NODE_IS_CONTACT(n)) | |
4177 b = gaim_contact_get_priority_buddy((GaimContact*)n); | |
4178 else if (GAIM_BLIST_NODE_IS_BUDDY(n)) | |
4179 b = (GaimBuddy*)n; | |
4180 else | |
4181 return; | |
4182 | |
4183 /* | |
4184 * If we already have an open conversation with this buddy, then | |
4185 * just move the conv to this window. Otherwise, create a new | |
4186 * conv and add it to this window. | |
4187 */ | |
4188 c = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, b->name, b->account); | |
4189 if (c != NULL) { | |
4190 GaimGtkWindow *oldwin; | |
4191 gtkconv = GAIM_GTK_CONVERSATION(c); | |
4192 oldwin = gtkconv->win; | |
4193 if (oldwin != win) { | |
4194 gaim_gtk_conv_window_remove_gtkconv(oldwin, gtkconv); | |
4195 gaim_gtk_conv_window_add_gtkconv(win, gtkconv); | |
4196 } | |
4197 } else { | |
4198 c = gaim_conversation_new(GAIM_CONV_TYPE_IM, b->account, b->name); | |
4199 gtkconv = GAIM_GTK_CONVERSATION(c); | |
4200 if (gtkconv->win != win) | |
4201 { | |
4202 gaim_gtk_conv_window_remove_gtkconv(gtkconv->win, gtkconv); | |
4203 gaim_gtk_conv_window_add_gtkconv(win, gtkconv); | |
4204 } | |
4205 } | |
4206 | |
4207 /* Make this conversation the active conversation */ | |
4208 gaim_gtk_conv_window_switch_gtkconv(win, gtkconv); | |
4209 | |
4210 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); | |
4211 } | |
4212 else if (sd->target == gdk_atom_intern("application/x-im-contact", FALSE)) | |
4213 { | |
4214 char *protocol = NULL; | |
4215 char *username = NULL; | |
4216 GaimAccount *account; | |
4217 GaimGtkConversation *gtkconv; | |
4218 | |
4219 if (gaim_gtk_parse_x_im_contact((const char *)sd->data, FALSE, &account, | |
4220 &protocol, &username, NULL)) | |
4221 { | |
4222 if (account == NULL) | |
4223 { | |
4224 gaim_notify_error(win, NULL, | |
4225 _("You are not currently signed on with an account that " | |
4226 "can add that buddy."), NULL); | |
4227 } | |
4228 else | |
4229 { | |
4230 c = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, username); | |
4231 gtkconv = GAIM_GTK_CONVERSATION(c); | |
4232 if (gtkconv->win != win) | |
4233 { | |
4234 gaim_gtk_conv_window_remove_gtkconv(gtkconv->win, gtkconv); | |
4235 gaim_gtk_conv_window_add_gtkconv(win, gtkconv); | |
4236 } | |
4237 } | |
4238 } | |
4239 | |
4240 g_free(username); | |
4241 g_free(protocol); | |
4242 | |
4243 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); | |
4244 } | |
4245 else if (sd->target == gdk_atom_intern("text/uri-list", FALSE)) { | |
4246 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) | |
4247 gaim_dnd_file_manage(sd, gaim_conversation_get_account(conv), gaim_conversation_get_name(conv)); | |
4248 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); | |
4249 } | |
4250 else | |
4251 gtk_drag_finish(dc, FALSE, FALSE, t); | |
4252 } | |
4253 | |
4254 | |
4255 static const GtkTargetEntry te[] = | |
4256 { | |
4257 GTK_IMHTML_DND_TARGETS, | |
4258 {"GAIM_BLIST_NODE", GTK_TARGET_SAME_APP, GTK_IMHTML_DRAG_NUM}, | |
4259 {"application/x-im-contact", 0, GTK_IMHTML_DRAG_NUM + 1} | |
4260 }; | |
4261 | |
4262 static GaimGtkConversation * | |
4263 gaim_gtk_conv_find_gtkconv(GaimConversation * conv) | |
4264 { | |
4265 GaimBuddy *bud = gaim_find_buddy(conv->account, conv->name), *b; | |
4266 GaimContact *c; | |
4267 GaimBlistNode *cn; | |
4268 | |
4269 if (!bud) | |
4270 return NULL; | |
4271 | |
4272 if (!(c = gaim_buddy_get_contact(bud))) | |
4273 return NULL; | |
4274 | |
4275 cn = (GaimBlistNode *)c; | |
4276 for (b = (GaimBuddy *)cn->child; b; b = (GaimBuddy *) ((GaimBlistNode *)b)->next) { | |
4277 GaimConversation *conv; | |
4278 if ((conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, b->name, b->account))) { | |
4279 if (conv->ui_data) | |
4280 return conv->ui_data; | |
4281 } | |
4282 } | |
4283 | |
4284 return NULL; | |
4285 } | |
4286 | |
4287 static void | |
4288 buddy_update_cb(GaimBlistNode *bnode, gpointer null) | |
4289 { | |
4290 GList *list; | |
4291 | |
4292 g_return_if_fail(bnode); | |
4293 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(bnode)); | |
4294 | |
4295 for (list = gaim_gtk_conv_windows_get_list(); list; list = list->next) | |
4296 { | |
4297 GaimGtkWindow *win = list->data; | |
4298 GaimConversation *conv = gaim_gtk_conv_window_get_active_conversation(win); | |
4299 | |
4300 if (gaim_conversation_get_type(conv) != GAIM_CONV_TYPE_IM) | |
4301 continue; | |
4302 | |
4303 gaim_gtkconv_update_fields(conv, GAIM_GTKCONV_MENU); | |
4304 } | |
4305 } | |
4306 | |
4307 /************************************************************************** | |
4308 * Conversation UI operations | |
4309 **************************************************************************/ | |
4310 static void | |
4311 private_gtkconv_new(GaimConversation *conv, gboolean hidden) | |
4312 { | |
4313 GaimGtkConversation *gtkconv; | |
4314 GaimConversationType conv_type = gaim_conversation_get_type(conv); | |
4315 GtkWidget *pane = NULL; | |
4316 GtkWidget *tab_cont; | |
4317 | |
4318 if (conv_type == GAIM_CONV_TYPE_IM && (gtkconv = gaim_gtk_conv_find_gtkconv(conv))) { | |
4319 conv->ui_data = gtkconv; | |
4320 if (!g_list_find(gtkconv->convs, conv)) | |
4321 gtkconv->convs = g_list_prepend(gtkconv->convs, conv); | |
4322 gaim_gtkconv_switch_active_conversation(conv); | |
4323 return; | |
4324 } | |
4325 | |
4326 gtkconv = g_new0(GaimGtkConversation, 1); | |
4327 conv->ui_data = gtkconv; | |
4328 gtkconv->active_conv = conv; | |
4329 gtkconv->convs = g_list_prepend(gtkconv->convs, conv); | |
4330 gtkconv->send_history = g_list_append(NULL, NULL); | |
4331 | |
4332 /* Setup some initial variables. */ | |
4333 gtkconv->sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); | |
4334 gtkconv->tooltips = gtk_tooltips_new(); | |
4335 gtkconv->unseen_state = GAIM_UNSEEN_NONE; | |
4336 gtkconv->unseen_count = 0; | |
4337 | |
4338 if (conv_type == GAIM_CONV_TYPE_IM) { | |
4339 gtkconv->u.im = g_malloc0(sizeof(GaimGtkImPane)); | |
4340 | |
4341 pane = setup_im_pane(gtkconv); | |
4342 } else if (conv_type == GAIM_CONV_TYPE_CHAT) { | |
4343 gtkconv->u.chat = g_malloc0(sizeof(GaimGtkChatPane)); | |
4344 pane = setup_chat_pane(gtkconv); | |
4345 } | |
4346 | |
4347 gtk_imhtml_set_format_functions(GTK_IMHTML(gtkconv->imhtml), | |
4348 gtk_imhtml_get_format_functions(GTK_IMHTML(gtkconv->imhtml)) | GTK_IMHTML_IMAGE); | |
4349 | |
4350 if (pane == NULL) { | |
4351 if (conv_type == GAIM_CONV_TYPE_CHAT) | |
4352 g_free(gtkconv->u.chat); | |
4353 else if (conv_type == GAIM_CONV_TYPE_IM) | |
4354 g_free(gtkconv->u.im); | |
4355 | |
4356 g_free(gtkconv); | |
4357 conv->ui_data = NULL; | |
4358 return; | |
4359 } | |
4360 | |
4361 /* Setup drag-and-drop */ | |
4362 gtk_drag_dest_set(pane, | |
4363 GTK_DEST_DEFAULT_MOTION | | |
4364 GTK_DEST_DEFAULT_DROP, | |
4365 te, sizeof(te) / sizeof(GtkTargetEntry), | |
4366 GDK_ACTION_COPY); | |
4367 gtk_drag_dest_set(pane, | |
4368 GTK_DEST_DEFAULT_MOTION | | |
4369 GTK_DEST_DEFAULT_DROP, | |
4370 te, sizeof(te) / sizeof(GtkTargetEntry), | |
4371 GDK_ACTION_COPY); | |
4372 gtk_drag_dest_set(gtkconv->imhtml, 0, | |
4373 te, sizeof(te) / sizeof(GtkTargetEntry), | |
4374 GDK_ACTION_COPY); | |
4375 | |
4376 gtk_drag_dest_set(gtkconv->entry, 0, | |
4377 te, sizeof(te) / sizeof(GtkTargetEntry), | |
4378 GDK_ACTION_COPY); | |
4379 | |
4380 g_signal_connect(G_OBJECT(pane), "drag_data_received", | |
4381 G_CALLBACK(conv_dnd_recv), gtkconv); | |
4382 g_signal_connect(G_OBJECT(gtkconv->imhtml), "drag_data_received", | |
4383 G_CALLBACK(conv_dnd_recv), gtkconv); | |
4384 g_signal_connect(G_OBJECT(gtkconv->entry), "drag_data_received", | |
4385 G_CALLBACK(conv_dnd_recv), gtkconv); | |
4386 | |
4387 /* Setup the container for the tab. */ | |
4388 gtkconv->tab_cont = tab_cont = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
4389 g_object_set_data(G_OBJECT(tab_cont), "GaimGtkConversation", gtkconv); | |
4390 gtk_container_set_border_width(GTK_CONTAINER(tab_cont), GAIM_HIG_BOX_SPACE); | |
4391 gtk_container_add(GTK_CONTAINER(tab_cont), pane); | |
4392 gtk_widget_show(pane); | |
4393 | |
4394 gtkconv->make_sound = TRUE; | |
4395 | |
4396 if (gaim_prefs_get_bool("/gaim/gtk/conversations/show_formatting_toolbar")) | |
4397 gtk_widget_show(gtkconv->toolbar); | |
4398 else | |
4399 gtk_widget_hide(gtkconv->toolbar); | |
4400 | |
4401 gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), | |
4402 gaim_prefs_get_bool("/gaim/gtk/conversations/show_timestamps")); | |
4403 gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->imhtml), | |
4404 gaim_account_get_protocol_name(conv->account)); | |
4405 | |
4406 g_signal_connect_swapped(G_OBJECT(pane), "focus", | |
4407 G_CALLBACK(gtk_widget_grab_focus), | |
4408 gtkconv->entry); | |
4409 | |
4410 if (hidden) | |
4411 gaim_gtk_conv_window_add_gtkconv(hidden_convwin, gtkconv); | |
4412 else | |
4413 gaim_gtkconv_placement_place(gtkconv); | |
4414 | |
4415 if (nick_colors == NULL) { | |
4416 nbr_nick_colors = NUM_NICK_COLORS; | |
4417 nick_colors = generate_nick_colors(&nbr_nick_colors, gtk_widget_get_style(gtkconv->imhtml)->base[GTK_STATE_NORMAL]); | |
4418 } | |
4419 } | |
4420 | |
4421 static void | |
4422 gaim_gtkconv_new_hidden(GaimConversation *conv) | |
4423 { | |
4424 private_gtkconv_new(conv, TRUE); | |
4425 } | |
4426 | |
4427 void | |
4428 gaim_gtkconv_new(GaimConversation *conv) | |
4429 { | |
4430 private_gtkconv_new(conv, FALSE); | |
4431 } | |
4432 | |
4433 static void | |
4434 received_im_msg_cb(GaimAccount *account, char *sender, char *message, | |
4435 GaimConversation *conv, int flags) | |
4436 { | |
4437 GaimConversationUiOps *ui_ops = gaim_gtk_conversations_get_conv_ui_ops(); | |
4438 if (conv != NULL) | |
4439 return; | |
4440 | |
4441 /* create hidden conv if hide_new pref is always */ | |
4442 if (strcmp(gaim_prefs_get_string("/gaim/gtk/conversations/im/hide_new"), "always") == 0) | |
4443 { | |
4444 ui_ops->create_conversation = gaim_gtkconv_new_hidden; | |
4445 gaim_conversation_new(GAIM_CONV_TYPE_IM, account, sender); | |
4446 ui_ops->create_conversation = gaim_gtkconv_new; | |
4447 return; | |
4448 } | |
4449 | |
4450 /* create hidden conv if hide_new pref is away and account is away */ | |
4451 if (strcmp(gaim_prefs_get_string("/gaim/gtk/conversations/im/hide_new"), "away") == 0 && | |
4452 !gaim_status_is_available(gaim_account_get_active_status(account))) | |
4453 { | |
4454 ui_ops->create_conversation = gaim_gtkconv_new_hidden; | |
4455 gaim_conversation_new(GAIM_CONV_TYPE_IM, account, sender); | |
4456 ui_ops->create_conversation = gaim_gtkconv_new; | |
4457 return; | |
4458 } | |
4459 } | |
4460 | |
4461 static void | |
4462 gaim_gtkconv_destroy(GaimConversation *conv) | |
4463 { | |
4464 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4465 | |
4466 gtkconv->convs = g_list_remove(gtkconv->convs, conv); | |
4467 /* Don't destroy ourselves until all our convos are gone */ | |
4468 if (gtkconv->convs) | |
4469 return; | |
4470 | |
4471 gaim_gtk_conv_window_remove_gtkconv(gtkconv->win, gtkconv); | |
4472 | |
4473 /* If the "Save Conversation" or "Save Icon" dialogs are open then close them */ | |
4474 gaim_request_close_with_handle(gtkconv); | |
4475 gaim_notify_close_with_handle(gtkconv); | |
4476 | |
4477 /* Close the "Find" dialog if it's open */ | |
4478 if (gtkconv->dialogs.search) | |
4479 gtk_widget_destroy(gtkconv->dialogs.search); | |
4480 | |
4481 gtk_widget_destroy(gtkconv->tab_cont); | |
4482 g_object_unref(gtkconv->tab_cont); | |
4483 | |
4484 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) { | |
4485 if (gtkconv->u.im->icon_timer != 0) | |
4486 g_source_remove(gtkconv->u.im->icon_timer); | |
4487 | |
4488 if (gtkconv->u.im->anim != NULL) | |
4489 g_object_unref(G_OBJECT(gtkconv->u.im->anim)); | |
4490 | |
4491 g_free(gtkconv->u.im); | |
4492 } else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) { | |
4493 gaim_signals_disconnect_by_handle(gtkconv->u.chat); | |
4494 g_free(gtkconv->u.chat); | |
4495 } | |
4496 | |
4497 gtk_object_sink(GTK_OBJECT(gtkconv->tooltips)); | |
4498 | |
4499 gtkconv->send_history = g_list_first(gtkconv->send_history); | |
4500 g_list_foreach(gtkconv->send_history, (GFunc)g_free, NULL); | |
4501 g_list_free(gtkconv->send_history); | |
4502 | |
4503 g_free(gtkconv); | |
4504 } | |
4505 | |
4506 | |
4507 static void | |
4508 gaim_gtkconv_write_im(GaimConversation *conv, const char *who, | |
4509 const char *message, GaimMessageFlags flags, | |
4510 time_t mtime) | |
4511 { | |
4512 GaimGtkConversation *gtkconv; | |
4513 | |
4514 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4515 | |
4516 if (conv != gtkconv->active_conv && | |
4517 flags & GAIM_MESSAGE_ACTIVE_ONLY) | |
4518 { | |
4519 /* Plugins that want these messages suppressed should be | |
4520 * calling gaim_conv_im_write(), so they get suppressed here, | |
4521 * before being written to the log. */ | |
4522 gaim_debug_info("gtkconv", | |
4523 "Suppressing message for an inactive conversation in gaim_gtkconv_write_im()\n"); | |
4524 return; | |
4525 } | |
4526 | |
4527 gaim_conversation_write(conv, who, message, flags, mtime); | |
4528 } | |
4529 | |
4530 /* The callback for an event on a link tag. */ | |
4531 static gboolean buddytag_event(GtkTextTag *tag, GObject *imhtml, | |
4532 GdkEvent *event, GtkTextIter *arg2, gpointer data) { | |
4533 if (event->type == GDK_BUTTON_PRESS | |
4534 || event->type == GDK_2BUTTON_PRESS) { | |
4535 GdkEventButton *btn_event = (GdkEventButton*) event; | |
4536 GaimConversation *conv = data; | |
4537 char *buddyname; | |
4538 | |
4539 /* strlen("BUDDY ") == 6 */ | |
4540 g_return_val_if_fail((tag->name != NULL) | |
4541 && (strlen(tag->name) > 6), FALSE); | |
4542 | |
4543 buddyname = (tag->name) + 6; | |
4544 | |
4545 if (btn_event->button == 2 | |
4546 && event->type == GDK_2BUTTON_PRESS) { | |
4547 chat_do_info(GAIM_GTK_CONVERSATION(conv), buddyname); | |
4548 | |
4549 return TRUE; | |
4550 } else if (btn_event->button == 3 | |
4551 && event->type == GDK_BUTTON_PRESS) { | |
4552 GtkTextIter start, end; | |
4553 | |
4554 /* we shouldn't display the popup | |
4555 * if the user has selected something: */ | |
4556 if (!gtk_text_buffer_get_selection_bounds( | |
4557 gtk_text_iter_get_buffer(arg2), | |
4558 &start, &end)) { | |
4559 GtkWidget *menu = NULL; | |
4560 GaimConnection *gc = | |
4561 gaim_conversation_get_gc(conv); | |
4562 | |
4563 | |
4564 menu = create_chat_menu(conv, buddyname, gc); | |
4565 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, | |
4566 NULL, GTK_WIDGET(imhtml), | |
4567 btn_event->button, | |
4568 btn_event->time); | |
4569 | |
4570 /* Don't propagate the event any further */ | |
4571 return TRUE; | |
4572 } | |
4573 } | |
4574 } | |
4575 | |
4576 return FALSE; | |
4577 } | |
4578 | |
4579 static GtkTextTag *get_buddy_tag(GaimConversation *conv, const char *who) { | |
4580 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4581 GtkTextTag *buddytag; | |
4582 /* strlen("BUDDY ") == 6 */ | |
4583 gchar str[strlen(who) + 7]; | |
4584 | |
4585 g_snprintf(str, sizeof(str), "BUDDY %s", who); | |
4586 str[sizeof(str)] = '\0'; | |
4587 | |
4588 buddytag = gtk_text_tag_table_lookup( | |
4589 gtk_text_buffer_get_tag_table( | |
4590 GTK_IMHTML(gtkconv->imhtml)->text_buffer), str); | |
4591 | |
4592 if (buddytag == NULL) { | |
4593 buddytag = gtk_text_buffer_create_tag( | |
4594 GTK_IMHTML(gtkconv->imhtml)->text_buffer, str, NULL); | |
4595 | |
4596 g_signal_connect(G_OBJECT(buddytag), "event", | |
4597 G_CALLBACK(buddytag_event), conv); | |
4598 } | |
4599 | |
4600 return buddytag; | |
4601 } | |
4602 | |
4603 static void | |
4604 gaim_gtkconv_write_conv(GaimConversation *conv, const char *name, const char *alias, | |
4605 const char *message, GaimMessageFlags flags, | |
4606 time_t mtime) | |
4607 { | |
4608 GaimGtkConversation *gtkconv; | |
4609 GaimGtkWindow *win; | |
4610 GaimConnection *gc; | |
4611 GaimAccount *account; | |
4612 GaimPluginProtocolInfo *prpl_info; | |
4613 int gtk_font_options = 0; | |
4614 int gtk_font_options_all = 0; | |
4615 int max_scrollback_lines; | |
4616 int line_count; | |
4617 char buf2[BUF_LONG]; | |
4618 char *mdate; | |
4619 char color[10]; | |
4620 char *str; | |
4621 char *with_font_tag; | |
4622 char *sml_attrib = NULL; | |
4623 size_t length; | |
4624 GaimConversationType type; | |
4625 char *displaying; | |
4626 gboolean plugin_return; | |
4627 | |
4628 g_return_if_fail(conv != NULL); | |
4629 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4630 g_return_if_fail(gtkconv != NULL); | |
4631 | |
4632 if (conv != gtkconv->active_conv) | |
4633 { | |
4634 if (flags & GAIM_MESSAGE_ACTIVE_ONLY) | |
4635 { | |
4636 /* Unless this had GAIM_MESSAGE_NO_LOG, this message | |
4637 * was logged. Plugin writers: if this isn't what | |
4638 * you wanted, call gaim_conv_im_write() instead of | |
4639 * gaim_conversation_write(). */ | |
4640 gaim_debug_info("gtkconv", | |
4641 "Suppressing message for an inactive conversation in gaim_gtkconv_write_conv()\n"); | |
4642 return; | |
4643 } | |
4644 | |
4645 /* Set the active conversation to the one that just messaged us. */ | |
4646 /* TODO: consider not doing this if the account is offline or something */ | |
4647 if (flags & (GAIM_MESSAGE_SEND | GAIM_MESSAGE_RECV)) | |
4648 gaim_gtkconv_switch_active_conversation(conv); | |
4649 } | |
4650 | |
4651 type = gaim_conversation_get_type(conv); | |
4652 account = gaim_conversation_get_account(conv); | |
4653 g_return_if_fail(account != NULL); | |
4654 gc = gaim_account_get_connection(account); | |
4655 g_return_if_fail(gc != NULL); | |
4656 | |
4657 displaying = g_strdup(message); | |
4658 plugin_return = GPOINTER_TO_INT(gaim_signal_emit_return_1( | |
4659 gaim_gtk_conversations_get_handle(), (type == GAIM_CONV_TYPE_IM ? | |
4660 "displaying-im-msg" : "displaying-chat-msg"), | |
4661 account, name, &displaying, conv, flags)); | |
4662 if (plugin_return) | |
4663 { | |
4664 g_free(displaying); | |
4665 return; | |
4666 } | |
4667 message = displaying; | |
4668 length = strlen(message) + 1; | |
4669 | |
4670 win = gtkconv->win; | |
4671 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
4672 | |
4673 line_count = gtk_text_buffer_get_line_count( | |
4674 gtk_text_view_get_buffer(GTK_TEXT_VIEW( | |
4675 gtkconv->imhtml))); | |
4676 | |
4677 max_scrollback_lines = gaim_prefs_get_int( | |
4678 "/gaim/gtk/conversations/scrollback_lines"); | |
4679 /* If we're sitting at more than 100 lines more than the | |
4680 max scrollback, trim down to max scrollback */ | |
4681 if (max_scrollback_lines > 0 | |
4682 && line_count > (max_scrollback_lines + 100)) { | |
4683 GtkTextBuffer *text_buffer = gtk_text_view_get_buffer( | |
4684 GTK_TEXT_VIEW(gtkconv->imhtml)); | |
4685 GtkTextIter start, end; | |
4686 | |
4687 gtk_text_buffer_get_start_iter(text_buffer, &start); | |
4688 gtk_text_buffer_get_iter_at_line(text_buffer, &end, | |
4689 (line_count - max_scrollback_lines)); | |
4690 gtk_imhtml_delete(GTK_IMHTML(gtkconv->imhtml), &start, &end); | |
4691 } | |
4692 | |
4693 if (type == GAIM_CONV_TYPE_CHAT) | |
4694 { | |
4695 /* Create anchor for user */ | |
4696 GtkTextIter iter; | |
4697 char *tmp = g_strconcat("user:", name, NULL); | |
4698 | |
4699 gtk_text_buffer_get_end_iter(gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->imhtml)), &iter); | |
4700 gtk_text_buffer_create_mark(gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->imhtml)), | |
4701 tmp, &iter, TRUE); | |
4702 g_free(tmp); | |
4703 } | |
4704 | |
4705 if (gaim_prefs_get_bool("/gaim/gtk/conversations/use_smooth_scrolling")) | |
4706 gtk_font_options_all |= GTK_IMHTML_USE_SMOOTHSCROLLING; | |
4707 | |
4708 if (gtk_text_buffer_get_char_count(gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->imhtml)))) | |
4709 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR>", gtk_font_options_all); | |
4710 | |
4711 mdate = gaim_signal_emit_return_1(gaim_gtk_conversations_get_handle(), | |
4712 "conversation-timestamp", | |
4713 conv, mtime); | |
4714 if (mdate == NULL) | |
4715 { | |
4716 struct tm *tm = localtime(&mtime); | |
4717 if (time(NULL) > mtime + 20*60) /* show date if older than 20 minutes */ | |
4718 mdate = g_strdup(gaim_date_format_long(tm)); | |
4719 else | |
4720 mdate = g_strdup(gaim_time_format(tm)); | |
4721 } | |
4722 | |
4723 sml_attrib = g_strdup_printf("sml=\"%s\"", gaim_account_get_protocol_name(account)); | |
4724 | |
4725 gtk_font_options |= GTK_IMHTML_NO_COMMENTS; | |
4726 | |
4727 if ((flags & GAIM_MESSAGE_RECV) && | |
4728 !gaim_prefs_get_bool("/gaim/gtk/conversations/show_incoming_formatting")) | |
4729 gtk_font_options |= GTK_IMHTML_NO_COLOURS | GTK_IMHTML_NO_FONTS | GTK_IMHTML_NO_SIZES | GTK_IMHTML_NO_FORMATTING; | |
4730 | |
4731 /* this is gonna crash one day, I can feel it. */ | |
4732 if (GAIM_PLUGIN_PROTOCOL_INFO(gaim_find_prpl(gaim_account_get_protocol_id(conv->account)))->options & | |
4733 OPT_PROTO_USE_POINTSIZE) { | |
4734 gtk_font_options |= GTK_IMHTML_USE_POINTSIZE; | |
4735 } | |
4736 | |
4737 | |
4738 /* TODO: These colors should not be hardcoded so log.c can use them */ | |
4739 if (flags & GAIM_MESSAGE_SYSTEM) { | |
4740 g_snprintf(buf2, sizeof(buf2), | |
4741 "<FONT %s><FONT SIZE=\"2\"><!--(%s) --></FONT><B>%s</B></FONT>", | |
4742 sml_attrib ? sml_attrib : "", mdate, message); | |
4743 | |
4744 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, gtk_font_options_all); | |
4745 | |
4746 } else if (flags & GAIM_MESSAGE_ERROR) { | |
4747 g_snprintf(buf2, sizeof(buf2), | |
4748 "<FONT COLOR=\"#ff0000\"><FONT %s><FONT SIZE=\"2\"><!--(%s) --></FONT><B>%s</B></FONT></FONT>", | |
4749 sml_attrib ? sml_attrib : "", mdate, message); | |
4750 | |
4751 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, gtk_font_options_all); | |
4752 | |
4753 } else if (flags & GAIM_MESSAGE_NO_LOG) { | |
4754 g_snprintf(buf2, BUF_LONG, | |
4755 "<B><FONT %s COLOR=\"#777777\">%s</FONT></B>", | |
4756 sml_attrib ? sml_attrib : "", message); | |
4757 | |
4758 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, gtk_font_options_all); | |
4759 } else if (flags & GAIM_MESSAGE_RAW) { | |
4760 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), message, gtk_font_options_all); | |
4761 } else { | |
4762 char *new_message = g_memdup(message, length); | |
4763 char *alias_escaped = (alias ? g_markup_escape_text(alias, strlen(alias)) : g_strdup("")); | |
4764 /* The initial offset is to deal with | |
4765 * escaped entities making the string longer */ | |
4766 int tag_start_offset = alias ? (strlen(alias_escaped) - strlen(alias)) : 0; | |
4767 int tag_end_offset = 0; | |
4768 GtkSmileyTree *tree = NULL; | |
4769 GHashTable *smiley_data = NULL; | |
4770 | |
4771 if (flags & GAIM_MESSAGE_SEND) | |
4772 { | |
4773 /* Temporarily revert to the original smiley-data to avoid showing up | |
4774 * custom smileys of the buddy when sending message | |
4775 */ | |
4776 tree = GTK_IMHTML(gtkconv->imhtml)->default_smilies; | |
4777 GTK_IMHTML(gtkconv->imhtml)->default_smilies = | |
4778 GTK_IMHTML(gtkconv->entry)->default_smilies; | |
4779 smiley_data = GTK_IMHTML(gtkconv->imhtml)->smiley_data; | |
4780 GTK_IMHTML(gtkconv->imhtml)->smiley_data = GTK_IMHTML(gtkconv->entry)->smiley_data; | |
4781 } | |
4782 | |
4783 if (flags & GAIM_MESSAGE_WHISPER) { | |
4784 str = g_malloc(1024); | |
4785 | |
4786 /* If we're whispering, it's not an autoresponse. */ | |
4787 if (gaim_message_meify(new_message, -1 )) { | |
4788 g_snprintf(str, 1024, "***%s", alias_escaped); | |
4789 strcpy(color, "#6C2585"); | |
4790 tag_start_offset += 3; | |
4791 } | |
4792 else { | |
4793 g_snprintf(str, 1024, "*%s*:", alias_escaped); | |
4794 tag_start_offset += 1; | |
4795 tag_end_offset = 2; | |
4796 strcpy(color, "#00FF00"); | |
4797 } | |
4798 } | |
4799 else { | |
4800 if (gaim_message_meify(new_message, -1)) { | |
4801 str = g_malloc(1024); | |
4802 | |
4803 if (flags & GAIM_MESSAGE_AUTO_RESP) { | |
4804 g_snprintf(str, 1024, "%s ***%s", AUTO_RESPONSE, alias_escaped); | |
4805 tag_start_offset += 4 | |
4806 + strlen(AUTO_RESPONSE); | |
4807 } else { | |
4808 g_snprintf(str, 1024, "***%s", alias_escaped); | |
4809 tag_start_offset += 3; | |
4810 } | |
4811 | |
4812 if (flags & GAIM_MESSAGE_NICK) | |
4813 strcpy(color, HIGHLIGHT_COLOR); | |
4814 else | |
4815 strcpy(color, "#062585"); | |
4816 } | |
4817 else { | |
4818 str = g_malloc(1024); | |
4819 if (flags & GAIM_MESSAGE_AUTO_RESP) { | |
4820 g_snprintf(str, 1024, "%s %s", alias_escaped, AUTO_RESPONSE); | |
4821 tag_start_offset += 1 | |
4822 + strlen(AUTO_RESPONSE); | |
4823 } else { | |
4824 g_snprintf(str, 1024, "%s:", alias_escaped); | |
4825 tag_end_offset = 1; | |
4826 } | |
4827 if (flags & GAIM_MESSAGE_NICK) | |
4828 strcpy(color, HIGHLIGHT_COLOR); | |
4829 else if (flags & GAIM_MESSAGE_RECV) { | |
4830 if (type == GAIM_CONV_TYPE_CHAT) { | |
4831 GdkColor *col = get_nick_color(gtkconv, name); | |
4832 | |
4833 g_snprintf(color, sizeof(color), "#%02X%02X%02X", | |
4834 col->red >> 8, col->green >> 8, col->blue >> 8); | |
4835 } else | |
4836 strcpy(color, RECV_COLOR); | |
4837 } | |
4838 else if (flags & GAIM_MESSAGE_SEND) | |
4839 strcpy(color, SEND_COLOR); | |
4840 else { | |
4841 gaim_debug_error("gtkconv", "message missing flags\n"); | |
4842 strcpy(color, "#000000"); | |
4843 } | |
4844 } | |
4845 } | |
4846 | |
4847 g_free(alias_escaped); | |
4848 | |
4849 /* Are we in a chat where we can tell which users are buddies? */ | |
4850 if (!(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME) && | |
4851 gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) { | |
4852 | |
4853 /* Bold buddies to make them stand out from non-buddies. */ | |
4854 if (flags & GAIM_MESSAGE_SEND || | |
4855 flags & GAIM_MESSAGE_NICK || | |
4856 gaim_find_buddy(account, name) != NULL) { | |
4857 g_snprintf(buf2, BUF_LONG, | |
4858 "<FONT COLOR=\"%s\" %s><FONT SIZE=\"2\"><!--(%s) --></FONT>" | |
4859 "<B>%s</B></FONT> ", | |
4860 color, sml_attrib ? sml_attrib : "", mdate, str); | |
4861 } else { | |
4862 g_snprintf(buf2, BUF_LONG, | |
4863 "<FONT COLOR=\"%s\" %s><FONT SIZE=\"2\"><!--(%s) --></FONT>" | |
4864 "%s</FONT> ", | |
4865 color, sml_attrib ? sml_attrib : "", mdate, str); | |
4866 | |
4867 } | |
4868 } else { | |
4869 /* Bold everyone's name to make the name stand out from the message. */ | |
4870 g_snprintf(buf2, BUF_LONG, | |
4871 "<FONT COLOR=\"%s\" %s><FONT SIZE=\"2\"><!--(%s) --></FONT>" | |
4872 "<B>%s</B></FONT> ", | |
4873 color, sml_attrib ? sml_attrib : "", mdate, str); | |
4874 } | |
4875 | |
4876 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, gtk_font_options_all); | |
4877 | |
4878 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT && | |
4879 !(flags & GAIM_MESSAGE_SEND)) { | |
4880 | |
4881 GtkTextIter start, end; | |
4882 GtkTextTag *buddytag = get_buddy_tag(conv, name); | |
4883 | |
4884 gtk_text_buffer_get_end_iter( | |
4885 GTK_IMHTML(gtkconv->imhtml)->text_buffer, | |
4886 &end); | |
4887 gtk_text_iter_backward_chars(&end, | |
4888 tag_end_offset + 1); | |
4889 | |
4890 gtk_text_buffer_get_end_iter( | |
4891 GTK_IMHTML(gtkconv->imhtml)->text_buffer, | |
4892 &start); | |
4893 gtk_text_iter_backward_chars(&start, | |
4894 strlen(str) + 1 - tag_start_offset); | |
4895 | |
4896 gtk_text_buffer_apply_tag( | |
4897 GTK_IMHTML(gtkconv->imhtml)->text_buffer, | |
4898 buddytag, &start, &end); | |
4899 } | |
4900 | |
4901 g_free(str); | |
4902 | |
4903 if(gc){ | |
4904 char *pre = g_strdup_printf("<font %s>", sml_attrib ? sml_attrib : ""); | |
4905 char *post = "</font>"; | |
4906 int pre_len = strlen(pre); | |
4907 int post_len = strlen(post); | |
4908 | |
4909 with_font_tag = g_malloc(length + pre_len + post_len + 1); | |
4910 | |
4911 strcpy(with_font_tag, pre); | |
4912 memcpy(with_font_tag + pre_len, new_message, length); | |
4913 strcpy(with_font_tag + pre_len + length, post); | |
4914 | |
4915 length += pre_len + post_len; | |
4916 g_free(pre); | |
4917 } | |
4918 else | |
4919 with_font_tag = g_memdup(new_message, length); | |
4920 | |
4921 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), | |
4922 with_font_tag, gtk_font_options | gtk_font_options_all); | |
4923 | |
4924 if (flags & GAIM_MESSAGE_SEND) | |
4925 { | |
4926 /* Restore the smiley-data */ | |
4927 GTK_IMHTML(gtkconv->imhtml)->default_smilies = tree; | |
4928 GTK_IMHTML(gtkconv->imhtml)->smiley_data = smiley_data; | |
4929 } | |
4930 | |
4931 g_free(with_font_tag); | |
4932 g_free(new_message); | |
4933 } | |
4934 | |
4935 g_free(mdate); | |
4936 g_free(sml_attrib); | |
4937 | |
4938 /* Tab highlighting stuff */ | |
4939 if (!(flags & GAIM_MESSAGE_SEND) && !gaim_gtkconv_has_focus(conv)) | |
4940 { | |
4941 GaimUnseenState unseen = GAIM_UNSEEN_NONE; | |
4942 | |
4943 if ((flags & GAIM_MESSAGE_NICK) == GAIM_MESSAGE_NICK) | |
4944 unseen = GAIM_UNSEEN_NICK; | |
4945 else if (((flags & GAIM_MESSAGE_SYSTEM) == GAIM_MESSAGE_SYSTEM) || | |
4946 ((flags & GAIM_MESSAGE_ERROR) == GAIM_MESSAGE_ERROR)) | |
4947 unseen = GAIM_UNSEEN_EVENT; | |
4948 else if ((flags & GAIM_MESSAGE_NO_LOG) == GAIM_MESSAGE_NO_LOG) | |
4949 unseen = GAIM_UNSEEN_NO_LOG; | |
4950 else | |
4951 unseen = GAIM_UNSEEN_TEXT; | |
4952 | |
4953 gtkconv_set_unseen(gtkconv, unseen); | |
4954 } | |
4955 | |
4956 gaim_signal_emit(gaim_gtk_conversations_get_handle(), | |
4957 (type == GAIM_CONV_TYPE_IM ? "displayed-im-msg" : "displayed-chat-msg"), | |
4958 account, name, message, conv, flags); | |
4959 g_free(displaying); | |
4960 } | |
4961 static void | |
4962 gaim_gtkconv_chat_add_users(GaimConversation *conv, GList *cbuddies, gboolean new_arrivals) | |
4963 { | |
4964 GaimConvChat *chat; | |
4965 GaimGtkConversation *gtkconv; | |
4966 GaimGtkChatPane *gtkchat; | |
4967 GtkListStore *ls; | |
4968 GList *l; | |
4969 | |
4970 char tmp[BUF_LONG]; | |
4971 int num_users; | |
4972 | |
4973 chat = GAIM_CONV_CHAT(conv); | |
4974 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
4975 gtkchat = gtkconv->u.chat; | |
4976 | |
4977 num_users = g_list_length(gaim_conv_chat_get_users(chat)); | |
4978 | |
4979 g_snprintf(tmp, sizeof(tmp), | |
4980 ngettext("%d person in room", "%d people in room", | |
4981 num_users), | |
4982 num_users); | |
4983 | |
4984 gtk_label_set_text(GTK_LABEL(gtkchat->count), tmp); | |
4985 | |
4986 ls = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list))); | |
4987 | |
4988 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(ls), GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, | |
4989 GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID); | |
4990 | |
4991 l = cbuddies; | |
4992 while (l != NULL) { | |
4993 add_chat_buddy_common(conv, (GaimConvChatBuddy *)l->data, NULL); | |
4994 l = l->next; | |
4995 } | |
4996 | |
4997 /* Currently GTK+ maintains our sorted list after it's in the tree. | |
4998 * This may change if it turns out we can manage it faster ourselves. | |
4999 */ | |
5000 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(ls), CHAT_USERS_ALIAS_KEY_COLUMN, | |
5001 GTK_SORT_ASCENDING); | |
5002 } | |
5003 | |
5004 static void | |
5005 gaim_gtkconv_chat_rename_user(GaimConversation *conv, const char *old_name, | |
5006 const char *new_name, const char *new_alias) | |
5007 { | |
5008 GaimConvChat *chat; | |
5009 GaimGtkConversation *gtkconv; | |
5010 GaimGtkChatPane *gtkchat; | |
5011 GaimConvChatBuddyFlags flags; | |
5012 GaimConvChatBuddy *cbuddy; | |
5013 GtkTreeIter iter; | |
5014 GtkTreeModel *model; | |
5015 int f = 1; | |
5016 | |
5017 chat = GAIM_CONV_CHAT(conv); | |
5018 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
5019 gtkchat = gtkconv->u.chat; | |
5020 | |
5021 model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); | |
5022 | |
5023 if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) | |
5024 return; | |
5025 | |
5026 while (f != 0) { | |
5027 char *val; | |
5028 | |
5029 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CHAT_USERS_NAME_COLUMN, &val, CHAT_USERS_FLAGS_COLUMN, &flags, -1); | |
5030 | |
5031 if (!gaim_utf8_strcasecmp(old_name, val)) { | |
5032 gtk_list_store_remove(GTK_LIST_STORE(model), &iter); | |
5033 g_free(val); | |
5034 break; | |
5035 } | |
5036 | |
5037 f = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter); | |
5038 | |
5039 g_free(val); | |
5040 } | |
5041 | |
5042 if (!gaim_conv_chat_find_user(chat, old_name)) | |
5043 return; | |
5044 | |
5045 g_return_if_fail(new_alias != NULL); | |
5046 | |
5047 cbuddy = gaim_conv_chat_cb_new(new_name, new_alias, flags); | |
5048 | |
5049 add_chat_buddy_common(conv, cbuddy, old_name); | |
5050 } | |
5051 | |
5052 static void | |
5053 gaim_gtkconv_chat_remove_users(GaimConversation *conv, GList *users) | |
5054 { | |
5055 GaimConvChat *chat; | |
5056 GaimGtkConversation *gtkconv; | |
5057 GaimGtkChatPane *gtkchat; | |
5058 GtkTreeIter iter; | |
5059 GtkTreeModel *model; | |
5060 GList *l; | |
5061 char tmp[BUF_LONG]; | |
5062 int num_users; | |
5063 gboolean f; | |
5064 | |
5065 chat = GAIM_CONV_CHAT(conv); | |
5066 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
5067 gtkchat = gtkconv->u.chat; | |
5068 | |
5069 num_users = g_list_length(gaim_conv_chat_get_users(chat)); | |
5070 | |
5071 for (l = users; l != NULL; l = l->next) { | |
5072 model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); | |
5073 | |
5074 if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) | |
5075 continue; | |
5076 | |
5077 do { | |
5078 char *val; | |
5079 | |
5080 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, | |
5081 CHAT_USERS_NAME_COLUMN, &val, -1); | |
5082 | |
5083 if (!gaim_utf8_strcasecmp((char *)l->data, val)) { | |
5084 #if GTK_CHECK_VERSION(2,2,0) | |
5085 f = gtk_list_store_remove(GTK_LIST_STORE(model), &iter); | |
5086 #else | |
5087 gtk_list_store_remove(GTK_LIST_STORE(model), &iter); | |
5088 f = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter); | |
5089 #endif | |
5090 } | |
5091 else | |
5092 f = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter); | |
5093 | |
5094 g_free(val); | |
5095 } while (f); | |
5096 } | |
5097 | |
5098 g_snprintf(tmp, sizeof(tmp), | |
5099 ngettext("%d person in room", "%d people in room", | |
5100 num_users), num_users); | |
5101 | |
5102 gtk_label_set_text(GTK_LABEL(gtkchat->count), tmp); | |
5103 } | |
5104 | |
5105 static void | |
5106 gaim_gtkconv_chat_update_user(GaimConversation *conv, const char *user) | |
5107 { | |
5108 GaimConvChat *chat; | |
5109 GaimConvChatBuddyFlags flags; | |
5110 GaimConvChatBuddy *cbuddy; | |
5111 GaimGtkConversation *gtkconv; | |
5112 GaimGtkChatPane *gtkchat; | |
5113 GtkTreeIter iter; | |
5114 GtkTreeModel *model; | |
5115 int f = 1; | |
5116 char *alias = NULL; | |
5117 | |
5118 chat = GAIM_CONV_CHAT(conv); | |
5119 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
5120 gtkchat = gtkconv->u.chat; | |
5121 | |
5122 model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list)); | |
5123 | |
5124 if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) | |
5125 return; | |
5126 | |
5127 while (f != 0) { | |
5128 char *val; | |
5129 | |
5130 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CHAT_USERS_NAME_COLUMN, &val, -1); | |
5131 | |
5132 if (!gaim_utf8_strcasecmp(user, val)) { | |
5133 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CHAT_USERS_ALIAS_COLUMN, &alias, -1); | |
5134 gtk_list_store_remove(GTK_LIST_STORE(model), &iter); | |
5135 g_free(val); | |
5136 break; | |
5137 } | |
5138 | |
5139 f = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter); | |
5140 | |
5141 g_free(val); | |
5142 } | |
5143 | |
5144 if (!gaim_conv_chat_find_user(chat, user)) | |
5145 { | |
5146 g_free(alias); | |
5147 return; | |
5148 } | |
5149 | |
5150 g_return_if_fail(alias != NULL); | |
5151 | |
5152 flags = gaim_conv_chat_user_get_flags(chat, user); | |
5153 | |
5154 cbuddy = gaim_conv_chat_cb_new(user, alias, flags); | |
5155 | |
5156 add_chat_buddy_common(conv, cbuddy, NULL); | |
5157 g_free(alias); | |
5158 } | |
5159 | |
5160 gboolean | |
5161 gaim_gtkconv_has_focus(GaimConversation *conv) | |
5162 { | |
5163 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv); | |
5164 GaimGtkWindow *win; | |
5165 gboolean has_focus; | |
5166 | |
5167 win = gtkconv->win; | |
5168 | |
5169 g_object_get(G_OBJECT(win->window), "has-toplevel-focus", &has_focus, NULL); | |
5170 | |
5171 if (has_focus && gaim_gtk_conv_window_is_active_conversation(conv)) | |
5172 return TRUE; | |
5173 | |
5174 return FALSE; | |
5175 } | |
5176 | |
5177 static void gaim_gtkconv_custom_smiley_allocated(GdkPixbufLoader *loader, gpointer user_data) | |
5178 { | |
5179 GtkIMHtmlSmiley *smiley; | |
5180 | |
5181 smiley = (GtkIMHtmlSmiley *)user_data; | |
5182 smiley->icon = gdk_pixbuf_loader_get_animation(loader); | |
5183 | |
5184 if (smiley->icon) | |
5185 g_object_ref(G_OBJECT(smiley->icon)); | |
5186 #ifdef DEBUG_CUSTOM_SMILEY | |
5187 gaim_debug_info("custom-smiley", "gaim_gtkconv_custom_smiley_allocated(): got GdkPixbufAnimation %p for smiley '%s'\n", smiley->icon, smiley->smile); | |
5188 #endif | |
5189 } | |
5190 | |
5191 static void gaim_gtkconv_custom_smiley_closed(GdkPixbufLoader *loader, gpointer user_data) | |
5192 { | |
5193 GtkIMHtmlSmiley *smiley; | |
5194 GtkWidget *icon = NULL; | |
5195 GtkTextChildAnchor *anchor = NULL; | |
5196 GSList *current = NULL; | |
5197 | |
5198 smiley = (GtkIMHtmlSmiley *)user_data; | |
5199 if (!smiley->imhtml) { | |
5200 #ifdef DEBUG_CUSTOM_SMILEY | |
5201 gaim_debug_error("custom-smiley", "gaim_gtkconv_custom_smiley_closed(): orphan smiley found: %p\n", smiley); | |
5202 #endif | |
5203 g_object_unref(G_OBJECT(loader)); | |
5204 smiley->loader = NULL; | |
5205 return; | |
5206 } | |
5207 | |
5208 for (current = smiley->anchors; current; current = g_slist_next(current)) { | |
5209 | |
5210 icon = gtk_image_new_from_animation(smiley->icon); | |
5211 | |
5212 #ifdef DEBUG_CUSTOM_SMILEY | |
5213 gaim_debug_info("custom-smiley", "gaim_gtkconv_custom_smiley_closed(): got GtkImage %p from GtkPixbufAnimation %p for smiley '%s'\n", | |
5214 icon, smiley->icon, smiley->smile); | |
5215 #endif | |
5216 if (icon) { | |
5217 gtk_widget_show(icon); | |
5218 | |
5219 anchor = GTK_TEXT_CHILD_ANCHOR(current->data); | |
5220 | |
5221 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_plaintext", gaim_unescape_html(smiley->smile), g_free); | |
5222 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", g_strdup(smiley->smile), g_free); | |
5223 | |
5224 if (smiley->imhtml) | |
5225 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(smiley->imhtml), icon, anchor); | |
5226 } | |
5227 | |
5228 } | |
5229 | |
5230 g_slist_free(smiley->anchors); | |
5231 smiley->anchors = NULL; | |
5232 | |
5233 g_object_unref(G_OBJECT(loader)); | |
5234 smiley->loader = NULL; | |
5235 } | |
5236 | |
5237 static gboolean | |
5238 add_custom_smiley_for_imhtml(GtkIMHtml *imhtml, const char *sml, const char *smile) | |
5239 { | |
5240 GtkIMHtmlSmiley *smiley; | |
5241 GdkPixbufLoader *loader; | |
5242 | |
5243 smiley = gtk_imhtml_smiley_get(imhtml, sml, smile); | |
5244 | |
5245 if (smiley) { | |
5246 | |
5247 if (!(smiley->flags & GTK_IMHTML_SMILEY_CUSTOM)) { | |
5248 return FALSE; | |
5249 } | |
5250 | |
5251 /* Close the old GdkPixbufAnimation, then create a new one for | |
5252 * the smiley we are about to receive */ | |
5253 g_object_unref(G_OBJECT(smiley->icon)); | |
5254 | |
5255 /* XXX: Is it necessary to _unref the loader first? */ | |
5256 smiley->loader = gdk_pixbuf_loader_new(); | |
5257 smiley->icon = NULL; | |
5258 | |
5259 g_signal_connect(smiley->loader, "area_prepared", G_CALLBACK(gaim_gtkconv_custom_smiley_allocated), smiley); | |
5260 g_signal_connect(smiley->loader, "closed", G_CALLBACK(gaim_gtkconv_custom_smiley_closed), smiley); | |
5261 | |
5262 return TRUE; | |
5263 } | |
5264 | |
5265 loader = gdk_pixbuf_loader_new(); | |
5266 | |
5267 /* this is wrong, this file ought not call g_new on GtkIMHtmlSmiley */ | |
5268 /* Let gtk_imhtml have a gtk_imhtml_smiley_new function, and let | |
5269 GtkIMHtmlSmiley by opaque */ | |
5270 smiley = g_new0(GtkIMHtmlSmiley, 1); | |
5271 smiley->file = NULL; | |
5272 smiley->smile = g_strdup(smile); | |
5273 smiley->loader = loader; | |
5274 smiley->flags = smiley->flags | GTK_IMHTML_SMILEY_CUSTOM; | |
5275 | |
5276 g_signal_connect(smiley->loader, "area_prepared", G_CALLBACK(gaim_gtkconv_custom_smiley_allocated), smiley); | |
5277 g_signal_connect(smiley->loader, "closed", G_CALLBACK(gaim_gtkconv_custom_smiley_closed), smiley); | |
5278 | |
5279 gtk_imhtml_associate_smiley(imhtml, sml, smiley); | |
5280 | |
5281 return TRUE; | |
5282 } | |
5283 | |
5284 static gboolean | |
5285 gaim_gtkconv_custom_smiley_add(GaimConversation *conv, const char *smile, gboolean remote) | |
5286 { | |
5287 GaimGtkConversation *gtkconv; | |
5288 struct smiley_list *list; | |
5289 const char *sml = NULL, *conv_sml; | |
5290 | |
5291 if (!conv || !smile || !*smile) { | |
5292 return FALSE; | |
5293 } | |
5294 | |
5295 /* If smileys are off, return false */ | |
5296 if (gaim_gtkthemes_smileys_disabled()) | |
5297 return FALSE; | |
5298 | |
5299 /* If possible add this smiley to the current theme. | |
5300 * The addition is only temporary: custom smilies aren't saved to disk. */ | |
5301 conv_sml = gaim_account_get_protocol_name(conv->account); | |
5302 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
5303 | |
5304 for (list = (struct smiley_list *)current_smiley_theme->list; list; list = list->next) { | |
5305 if (!strcmp(list->sml, conv_sml)) { | |
5306 sml = list->sml; | |
5307 break; | |
5308 } | |
5309 } | |
5310 | |
5311 if (!add_custom_smiley_for_imhtml(GTK_IMHTML(gtkconv->imhtml), sml, smile)) | |
5312 return FALSE; | |
5313 | |
5314 if (!remote) /* If it's a local custom smiley, then add it for the entry */ | |
5315 if (!add_custom_smiley_for_imhtml(GTK_IMHTML(gtkconv->entry), sml, smile)) | |
5316 return FALSE; | |
5317 | |
5318 return TRUE; | |
5319 } | |
5320 | |
5321 static void | |
5322 gaim_gtkconv_custom_smiley_write(GaimConversation *conv, const char *smile, | |
5323 const guchar *data, gsize size) | |
5324 { | |
5325 GaimGtkConversation *gtkconv; | |
5326 GtkIMHtmlSmiley *smiley; | |
5327 GdkPixbufLoader *loader; | |
5328 const char *sml; | |
5329 | |
5330 sml = gaim_account_get_protocol_name(conv->account); | |
5331 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
5332 smiley = gtk_imhtml_smiley_get(GTK_IMHTML(gtkconv->imhtml), sml, smile); | |
5333 | |
5334 if (!smiley) | |
5335 return; | |
5336 | |
5337 loader = smiley->loader; | |
5338 if (!loader) | |
5339 return; | |
5340 | |
5341 gdk_pixbuf_loader_write(loader, data, size, NULL); | |
5342 } | |
5343 | |
5344 static void | |
5345 gaim_gtkconv_custom_smiley_close(GaimConversation *conv, const char *smile) | |
5346 { | |
5347 GaimGtkConversation *gtkconv; | |
5348 GtkIMHtmlSmiley *smiley; | |
5349 GdkPixbufLoader *loader; | |
5350 const char *sml; | |
5351 | |
5352 g_return_if_fail(conv != NULL); | |
5353 g_return_if_fail(smile != NULL); | |
5354 | |
5355 sml = gaim_account_get_protocol_name(conv->account); | |
5356 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
5357 smiley = gtk_imhtml_smiley_get(GTK_IMHTML(gtkconv->imhtml), sml, smile); | |
5358 | |
5359 if (!smiley) | |
5360 return; | |
5361 | |
5362 loader = smiley->loader; | |
5363 | |
5364 if (!loader) | |
5365 return; | |
5366 | |
5367 | |
5368 | |
5369 gaim_debug_info("gtkconv", "About to close the smiley pixbuf\n"); | |
5370 | |
5371 gdk_pixbuf_loader_close(loader, NULL); | |
5372 | |
5373 } | |
5374 | |
5375 /* | |
5376 * Makes sure all the menu items and all the buttons are hidden/shown and | |
5377 * sensitive/insensitive. This is called after changing tabs and when an | |
5378 * account signs on or off. | |
5379 */ | |
5380 static void | |
5381 gray_stuff_out(GaimGtkConversation *gtkconv) | |
5382 { | |
5383 GaimGtkWindow *win; | |
5384 GaimConversation *conv = gtkconv->active_conv; | |
5385 GaimConnection *gc; | |
5386 GaimPluginProtocolInfo *prpl_info = NULL; | |
5387 GdkPixbuf *window_icon = NULL; | |
5388 GtkIMHtmlButtons buttons; | |
5389 GaimAccount *account; | |
5390 | |
5391 win = gaim_gtkconv_get_window(gtkconv); | |
5392 gc = gaim_conversation_get_gc(conv); | |
5393 account = gaim_conversation_get_account(conv); | |
5394 | |
5395 if (gc != NULL) | |
5396 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
5397 | |
5398 if (win->menu.send_to != NULL) | |
5399 update_send_to_selection(win); | |
5400 | |
5401 /* | |
5402 * Handle hiding and showing stuff based on what type of conv this is. | |
5403 * Stuff that Gaim IMs support in general should be shown for IM | |
5404 * conversations. Stuff that Gaim chats support in general should be | |
5405 * shown for chat conversations. It doesn't matter whether the PRPL | |
5406 * supports it or not--that only affects if the button or menu item | |
5407 * is sensitive or not. | |
5408 */ | |
5409 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) { | |
5410 /* Show stuff that applies to IMs, hide stuff that applies to chats */ | |
5411 | |
5412 /* Deal with menu items */ | |
5413 gtk_widget_show(win->menu.view_log); | |
5414 gtk_widget_show(win->menu.send_file); | |
5415 gtk_widget_show(win->menu.add_pounce); | |
5416 gtk_widget_show(win->menu.get_info); | |
5417 gtk_widget_hide(win->menu.invite); | |
5418 gtk_widget_show(win->menu.alias); | |
5419 gtk_widget_show(win->menu.block); | |
5420 | |
5421 if ((account == NULL) || gaim_find_buddy(account, gaim_conversation_get_name(conv)) == NULL) { | |
5422 gtk_widget_show(win->menu.add); | |
5423 gtk_widget_hide(win->menu.remove); | |
5424 } else { | |
5425 gtk_widget_show(win->menu.remove); | |
5426 gtk_widget_hide(win->menu.add); | |
5427 } | |
5428 | |
5429 gtk_widget_show(win->menu.insert_link); | |
5430 gtk_widget_show(win->menu.insert_image); | |
5431 gtk_widget_show(win->menu.show_icon); | |
5432 } else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) { | |
5433 /* Show stuff that applies to Chats, hide stuff that applies to IMs */ | |
5434 | |
5435 /* Deal with menu items */ | |
5436 gtk_widget_show(win->menu.view_log); | |
5437 gtk_widget_hide(win->menu.send_file); | |
5438 gtk_widget_hide(win->menu.add_pounce); | |
5439 gtk_widget_hide(win->menu.get_info); | |
5440 gtk_widget_show(win->menu.invite); | |
5441 gtk_widget_show(win->menu.alias); | |
5442 gtk_widget_hide(win->menu.block); | |
5443 gtk_widget_hide(win->menu.show_icon); | |
5444 | |
5445 if ((account == NULL) || gaim_blist_find_chat(account, gaim_conversation_get_name(conv)) == NULL) { | |
5446 /* If the chat is NOT in the buddy list */ | |
5447 gtk_widget_show(win->menu.add); | |
5448 gtk_widget_hide(win->menu.remove); | |
5449 } else { | |
5450 /* If the chat IS in the buddy list */ | |
5451 gtk_widget_hide(win->menu.add); | |
5452 gtk_widget_show(win->menu.remove); | |
5453 } | |
5454 | |
5455 gtk_widget_show(win->menu.insert_link); | |
5456 gtk_widget_hide(win->menu.insert_image); | |
5457 } | |
5458 | |
5459 /* | |
5460 * Handle graying stuff out based on whether an account is connected | |
5461 * and what features that account supports. | |
5462 */ | |
5463 if ((gc != NULL) && | |
5464 ((gaim_conversation_get_type(conv) != GAIM_CONV_TYPE_CHAT) || | |
5465 !gaim_conv_chat_has_left(GAIM_CONV_CHAT(conv)) )) | |
5466 { | |
5467 /* Account is online */ | |
5468 /* Deal with the toolbar */ | |
5469 if (conv->features & GAIM_CONNECTION_HTML) | |
5470 { | |
5471 buttons = GTK_IMHTML_ALL; /* Everything on */ | |
5472 if (conv->features & GAIM_CONNECTION_NO_BGCOLOR) | |
5473 buttons &= ~GTK_IMHTML_BACKCOLOR; | |
5474 if (conv->features & GAIM_CONNECTION_NO_FONTSIZE) | |
5475 { | |
5476 buttons &= ~GTK_IMHTML_GROW; | |
5477 buttons &= ~GTK_IMHTML_SHRINK; | |
5478 } | |
5479 if (conv->features & GAIM_CONNECTION_NO_URLDESC) | |
5480 buttons &= ~GTK_IMHTML_LINKDESC; | |
5481 } else { | |
5482 buttons = GTK_IMHTML_SMILEY | GTK_IMHTML_IMAGE; | |
5483 } | |
5484 | |
5485 if (!(prpl_info->options & OPT_PROTO_IM_IMAGE) || | |
5486 conv->features & GAIM_CONNECTION_NO_IMAGES) | |
5487 buttons &= ~GTK_IMHTML_IMAGE; | |
5488 | |
5489 gtk_imhtml_set_format_functions(GTK_IMHTML(gtkconv->entry), buttons); | |
5490 if (account != NULL) | |
5491 gtk_imhtmltoolbar_associate_smileys(GTK_IMHTMLTOOLBAR(gtkconv->toolbar), gaim_account_get_protocol_id(account)); | |
5492 | |
5493 /* Deal with menu items */ | |
5494 gtk_widget_set_sensitive(win->menu.view_log, TRUE); | |
5495 gtk_widget_set_sensitive(win->menu.add_pounce, TRUE); | |
5496 gtk_widget_set_sensitive(win->menu.get_info, (prpl_info->get_info != NULL)); | |
5497 gtk_widget_set_sensitive(win->menu.invite, (prpl_info->chat_invite != NULL)); | |
5498 gtk_widget_set_sensitive(win->menu.insert_link, (conv->features & GAIM_CONNECTION_HTML)); | |
5499 gtk_widget_set_sensitive(win->menu.insert_image, (prpl_info->options & OPT_PROTO_IM_IMAGE) && !(conv->features & GAIM_CONNECTION_NO_IMAGES)); | |
5500 | |
5501 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) | |
5502 { | |
5503 gtk_widget_set_sensitive(win->menu.add, (prpl_info->add_buddy != NULL)); | |
5504 gtk_widget_set_sensitive(win->menu.remove, (prpl_info->remove_buddy != NULL)); | |
5505 gtk_widget_set_sensitive(win->menu.send_file, | |
5506 (prpl_info->send_file != NULL && (!prpl_info->can_receive_file || | |
5507 prpl_info->can_receive_file(gc, gaim_conversation_get_name(conv))))); | |
5508 gtk_widget_set_sensitive(win->menu.alias, | |
5509 (account != NULL) && | |
5510 (gaim_find_buddy(account, gaim_conversation_get_name(conv)) != NULL)); | |
5511 } | |
5512 else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) | |
5513 { | |
5514 gtk_widget_set_sensitive(win->menu.add, (prpl_info->join_chat != NULL)); | |
5515 gtk_widget_set_sensitive(win->menu.remove, (prpl_info->join_chat != NULL)); | |
5516 gtk_widget_set_sensitive(win->menu.alias, | |
5517 (account != NULL) && | |
5518 (gaim_blist_find_chat(account, gaim_conversation_get_name(conv)) != NULL)); | |
5519 } | |
5520 | |
5521 | |
5522 } else { | |
5523 /* Account is offline */ | |
5524 /* Or it's a chat that we've left. */ | |
5525 | |
5526 /* Then deal with menu items */ | |
5527 gtk_widget_set_sensitive(win->menu.view_log, TRUE); | |
5528 gtk_widget_set_sensitive(win->menu.send_file, FALSE); | |
5529 gtk_widget_set_sensitive(win->menu.add_pounce, TRUE); | |
5530 gtk_widget_set_sensitive(win->menu.get_info, FALSE); | |
5531 gtk_widget_set_sensitive(win->menu.invite, FALSE); | |
5532 gtk_widget_set_sensitive(win->menu.alias, FALSE); | |
5533 gtk_widget_set_sensitive(win->menu.add, FALSE); | |
5534 gtk_widget_set_sensitive(win->menu.remove, FALSE); | |
5535 gtk_widget_set_sensitive(win->menu.insert_link, TRUE); | |
5536 gtk_widget_set_sensitive(win->menu.insert_image, FALSE); | |
5537 } | |
5538 | |
5539 /* | |
5540 * Update the window's icon | |
5541 */ | |
5542 if (gaim_gtk_conv_window_is_active_conversation(conv)) | |
5543 { | |
5544 if ((gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) && | |
5545 (gtkconv->u.im->anim)) | |
5546 { | |
5547 window_icon = | |
5548 gdk_pixbuf_animation_get_static_image(gtkconv->u.im->anim); | |
5549 g_object_ref(window_icon); | |
5550 } else { | |
5551 window_icon = gaim_gtkconv_get_tab_icon(conv, FALSE); | |
5552 } | |
5553 gtk_window_set_icon(GTK_WINDOW(win->window), window_icon); | |
5554 if (window_icon != NULL) | |
5555 g_object_unref(G_OBJECT(window_icon)); | |
5556 } | |
5557 } | |
5558 | |
5559 static void | |
5560 gaim_gtkconv_update_fields(GaimConversation *conv, GaimGtkConvFields fields) | |
5561 { | |
5562 GaimGtkConversation *gtkconv; | |
5563 GaimGtkWindow *win; | |
5564 | |
5565 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
5566 if (!gtkconv) | |
5567 return; | |
5568 win = gaim_gtkconv_get_window(gtkconv); | |
5569 if (!win) | |
5570 return; | |
5571 | |
5572 if (fields & GAIM_GTKCONV_SET_TITLE) | |
5573 { | |
5574 gaim_conversation_autoset_title(conv); | |
5575 } | |
5576 | |
5577 if (fields & GAIM_GTKCONV_BUDDY_ICON) | |
5578 { | |
5579 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) | |
5580 gaim_gtkconv_update_buddy_icon(conv); | |
5581 } | |
5582 | |
5583 if (fields & GAIM_GTKCONV_MENU) | |
5584 { | |
5585 gray_stuff_out(GAIM_GTK_CONVERSATION(conv)); | |
5586 generate_send_to_items(win); | |
5587 } | |
5588 | |
5589 if (fields & GAIM_GTKCONV_TAB_ICON) | |
5590 { | |
5591 update_tab_icon(conv); | |
5592 generate_send_to_items(win); /* To update the icons in SendTo menu */ | |
5593 } | |
5594 | |
5595 if ((fields & GAIM_GTKCONV_TOPIC) && | |
5596 gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) | |
5597 { | |
5598 const char *topic; | |
5599 GaimConvChat *chat = GAIM_CONV_CHAT(conv); | |
5600 GaimGtkChatPane *gtkchat = gtkconv->u.chat; | |
5601 | |
5602 if (gtkchat->topic_text != NULL) | |
5603 { | |
5604 topic = gaim_conv_chat_get_topic(chat); | |
5605 | |
5606 gtk_entry_set_text(GTK_ENTRY(gtkchat->topic_text), topic ? topic : ""); | |
5607 gtk_tooltips_set_tip(gtkconv->tooltips, gtkchat->topic_text, | |
5608 topic ? topic : "", NULL); | |
5609 } | |
5610 } | |
5611 | |
5612 if (fields & GAIM_GTKCONV_SMILEY_THEME) | |
5613 gaim_gtkthemes_smiley_themeize(GAIM_GTK_CONVERSATION(conv)->imhtml); | |
5614 | |
5615 if ((fields & GAIM_GTKCONV_COLORIZE_TITLE) || | |
5616 (fields & GAIM_GTKCONV_SET_TITLE)) | |
5617 { | |
5618 char *title; | |
5619 GaimConvIm *im = NULL; | |
5620 GaimAccount *account = gaim_conversation_get_account(conv); | |
5621 AtkObject *accessibility_obj; | |
5622 /* I think this is a little longer than it needs to be but I'm lazy. */ | |
5623 char style[51]; | |
5624 | |
5625 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) | |
5626 im = GAIM_CONV_IM(conv); | |
5627 | |
5628 if ((account == NULL) || | |
5629 !gaim_account_is_connected(account) || | |
5630 ((gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) | |
5631 && gaim_conv_chat_has_left(GAIM_CONV_CHAT(conv)))) | |
5632 title = g_strdup_printf("(%s)", gaim_conversation_get_title(conv)); | |
5633 else | |
5634 title = g_strdup(gaim_conversation_get_title(conv)); | |
5635 | |
5636 *style = '\0'; | |
5637 | |
5638 if (!GTK_WIDGET_REALIZED(gtkconv->tab_label)) | |
5639 gtk_widget_realize(gtkconv->tab_label); | |
5640 | |
5641 accessibility_obj = gtk_widget_get_accessible(gtkconv->tab_cont); | |
5642 if (im != NULL && | |
5643 gaim_conv_im_get_typing_state(im) == GAIM_TYPING) | |
5644 { | |
5645 atk_object_set_description(accessibility_obj, _("Typing")); | |
5646 strncpy(style, "color=\"#47A046\"", sizeof(style)); | |
5647 } | |
5648 else if (im != NULL && | |
5649 gaim_conv_im_get_typing_state(im) == GAIM_TYPED) | |
5650 { | |
5651 atk_object_set_description(accessibility_obj, _("Stopped Typing")); | |
5652 strncpy(style, "color=\"#D1940C\"", sizeof(style)); | |
5653 } | |
5654 else if (gtkconv->unseen_state == GAIM_UNSEEN_NICK) | |
5655 { | |
5656 atk_object_set_description(accessibility_obj, _("Nick Said")); | |
5657 strncpy(style, "color=\"#0D4E91\" style=\"italic\" weight=\"bold\"", sizeof(style)); | |
5658 } | |
5659 else if (gtkconv->unseen_state == GAIM_UNSEEN_TEXT) | |
5660 { | |
5661 atk_object_set_description(accessibility_obj, _("Unread Messages")); | |
5662 strncpy(style, "color=\"#DF421E\" weight=\"bold\"", sizeof(style)); | |
5663 } | |
5664 else if (gtkconv->unseen_state == GAIM_UNSEEN_EVENT) | |
5665 { | |
5666 atk_object_set_description(accessibility_obj, _("New Event")); | |
5667 strncpy(style, "color=\"#868272\" style=\"italic\"", sizeof(style)); | |
5668 } | |
5669 | |
5670 if (*style != '\0') | |
5671 { | |
5672 char *html_title,*label; | |
5673 | |
5674 html_title = g_markup_escape_text(title, -1); | |
5675 | |
5676 label = g_strdup_printf("<span %s>%s</span>", | |
5677 style, html_title); | |
5678 g_free(html_title); | |
5679 gtk_label_set_markup(GTK_LABEL(gtkconv->tab_label), label); | |
5680 g_free(label); | |
5681 } | |
5682 else | |
5683 gtk_label_set_text(GTK_LABEL(gtkconv->tab_label), title); | |
5684 | |
5685 if (gaim_gtk_conv_window_is_active_conversation(conv)) | |
5686 update_typing_icon(gtkconv); | |
5687 | |
5688 gtk_label_set_text(GTK_LABEL(gtkconv->menu_label), title); | |
5689 if (gaim_gtk_conv_window_is_active_conversation(conv)) | |
5690 gtk_window_set_title(GTK_WINDOW(win->window), title); | |
5691 | |
5692 g_free(title); | |
5693 } | |
5694 } | |
5695 | |
5696 static void | |
5697 gaim_gtkconv_updated(GaimConversation *conv, GaimConvUpdateType type) | |
5698 { | |
5699 GaimGtkConvFields flags = 0; | |
5700 | |
5701 g_return_if_fail(conv != NULL); | |
5702 | |
5703 if (type == GAIM_CONV_UPDATE_ACCOUNT) | |
5704 { | |
5705 flags = GAIM_GTKCONV_ALL; | |
5706 } | |
5707 else if (type == GAIM_CONV_UPDATE_TYPING || | |
5708 type == GAIM_CONV_UPDATE_UNSEEN || | |
5709 type == GAIM_CONV_UPDATE_TITLE) | |
5710 { | |
5711 flags = GAIM_GTKCONV_COLORIZE_TITLE; | |
5712 } | |
5713 else if (type == GAIM_CONV_UPDATE_TOPIC) | |
5714 { | |
5715 flags = GAIM_GTKCONV_TOPIC; | |
5716 } | |
5717 else if (type == GAIM_CONV_ACCOUNT_ONLINE || | |
5718 type == GAIM_CONV_ACCOUNT_OFFLINE) | |
5719 { | |
5720 flags = GAIM_GTKCONV_MENU | GAIM_GTKCONV_TAB_ICON | GAIM_GTKCONV_SET_TITLE; | |
5721 } | |
5722 else if (type == GAIM_CONV_UPDATE_AWAY) | |
5723 { | |
5724 flags = GAIM_GTKCONV_TAB_ICON; | |
5725 } | |
5726 else if (type == GAIM_CONV_UPDATE_ADD || | |
5727 type == GAIM_CONV_UPDATE_REMOVE || | |
5728 type == GAIM_CONV_UPDATE_CHATLEFT) | |
5729 { | |
5730 flags = GAIM_GTKCONV_SET_TITLE | GAIM_GTKCONV_MENU; | |
5731 } | |
5732 else if (type == GAIM_CONV_UPDATE_ICON) | |
5733 { | |
5734 flags = GAIM_GTKCONV_BUDDY_ICON; | |
5735 } | |
5736 else if (type == GAIM_CONV_UPDATE_FEATURES) | |
5737 { | |
5738 flags = GAIM_GTKCONV_MENU; | |
5739 } | |
5740 | |
5741 gaim_gtkconv_update_fields(conv, flags); | |
5742 } | |
5743 | |
5744 static GaimConversationUiOps conversation_ui_ops = | |
5745 { | |
5746 gaim_gtkconv_new, | |
5747 gaim_gtkconv_destroy, /* destroy_conversation */ | |
5748 NULL, /* write_chat */ | |
5749 gaim_gtkconv_write_im, /* write_im */ | |
5750 gaim_gtkconv_write_conv, /* write_conv */ | |
5751 gaim_gtkconv_chat_add_users, /* chat_add_users */ | |
5752 gaim_gtkconv_chat_rename_user, /* chat_rename_user */ | |
5753 gaim_gtkconv_chat_remove_users, /* chat_remove_users */ | |
5754 gaim_gtkconv_chat_update_user, /* chat_update_user */ | |
5755 gaim_gtkconv_present_conversation, /* present */ | |
5756 gaim_gtkconv_has_focus, /* has_focus */ | |
5757 gaim_gtkconv_custom_smiley_add, /* custom_smiley_add */ | |
5758 gaim_gtkconv_custom_smiley_write, /* custom_smiley_write */ | |
5759 gaim_gtkconv_custom_smiley_close /* custom_smiley_close */ | |
5760 }; | |
5761 | |
5762 GaimConversationUiOps * | |
5763 gaim_gtk_conversations_get_conv_ui_ops(void) | |
5764 { | |
5765 return &conversation_ui_ops; | |
5766 } | |
5767 | |
5768 /************************************************************************** | |
5769 * Public conversation utility functions | |
5770 **************************************************************************/ | |
5771 void | |
5772 gaim_gtkconv_update_buddy_icon(GaimConversation *conv) | |
5773 { | |
5774 GaimGtkConversation *gtkconv; | |
5775 GaimGtkWindow *win; | |
5776 | |
5777 GdkPixbufLoader *loader; | |
5778 GdkPixbufAnimation *anim; | |
5779 GError *err = NULL; | |
5780 | |
5781 const void *data; | |
5782 size_t len; | |
5783 | |
5784 GdkPixbuf *buf; | |
5785 | |
5786 GtkWidget *event; | |
5787 GtkWidget *frame; | |
5788 GdkPixbuf *scale; | |
5789 int scale_width, scale_height; | |
5790 | |
5791 GaimAccount *account; | |
5792 GaimPluginProtocolInfo *prpl_info = NULL; | |
5793 | |
5794 GaimBuddyIcon *icon; | |
5795 | |
5796 g_return_if_fail(conv != NULL); | |
5797 g_return_if_fail(GAIM_IS_GTK_CONVERSATION(conv)); | |
5798 g_return_if_fail(gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM); | |
5799 | |
5800 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
5801 win = gtkconv->win; | |
5802 if (conv != gtkconv->active_conv) | |
5803 return; | |
5804 | |
5805 if (!gtkconv->u.im->show_icon) | |
5806 return; | |
5807 | |
5808 account = gaim_conversation_get_account(conv); | |
5809 if(account && account->gc) | |
5810 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(account->gc->prpl); | |
5811 | |
5812 /* Remove the current icon stuff */ | |
5813 if (gtkconv->u.im->icon_container != NULL) | |
5814 gtk_widget_destroy(gtkconv->u.im->icon_container); | |
5815 gtkconv->u.im->icon_container = NULL; | |
5816 | |
5817 if (gtkconv->u.im->anim != NULL) | |
5818 g_object_unref(G_OBJECT(gtkconv->u.im->anim)); | |
5819 | |
5820 gtkconv->u.im->anim = NULL; | |
5821 | |
5822 if (gtkconv->u.im->icon_timer != 0) | |
5823 g_source_remove(gtkconv->u.im->icon_timer); | |
5824 | |
5825 gtkconv->u.im->icon_timer = 0; | |
5826 | |
5827 if (gtkconv->u.im->iter != NULL) | |
5828 g_object_unref(G_OBJECT(gtkconv->u.im->iter)); | |
5829 | |
5830 gtkconv->u.im->iter = NULL; | |
5831 | |
5832 if (!gaim_prefs_get_bool("/gaim/gtk/conversations/im/show_buddy_icons")) | |
5833 return; | |
5834 | |
5835 if (gaim_conversation_get_gc(conv) == NULL) | |
5836 return; | |
5837 | |
5838 icon = gaim_conv_im_get_icon(GAIM_CONV_IM(conv)); | |
5839 | |
5840 if (icon == NULL) | |
5841 return; | |
5842 | |
5843 data = gaim_buddy_icon_get_data(icon, &len); | |
5844 | |
5845 loader = gdk_pixbuf_loader_new(); | |
5846 gdk_pixbuf_loader_write(loader, data, len, NULL); | |
5847 gdk_pixbuf_loader_close(loader, &err); | |
5848 anim = gdk_pixbuf_loader_get_animation(loader); | |
5849 if (anim) | |
5850 g_object_ref(G_OBJECT(anim)); | |
5851 g_object_unref(loader); | |
5852 | |
5853 if (!anim) | |
5854 return; | |
5855 gtkconv->u.im->anim = anim; | |
5856 | |
5857 if (err) { | |
5858 gaim_debug(GAIM_DEBUG_ERROR, "gtkconv", | |
5859 "Buddy icon error: %s\n", err->message); | |
5860 g_error_free(err); | |
5861 } | |
5862 | |
5863 if (!gtkconv->u.im->anim) | |
5864 return; | |
5865 | |
5866 if (gdk_pixbuf_animation_is_static_image(gtkconv->u.im->anim)) { | |
5867 gtkconv->u.im->iter = NULL; | |
5868 buf = gdk_pixbuf_animation_get_static_image(gtkconv->u.im->anim); | |
5869 } else { | |
5870 gtkconv->u.im->iter = | |
5871 gdk_pixbuf_animation_get_iter(gtkconv->u.im->anim, NULL); /* LEAK */ | |
5872 buf = gdk_pixbuf_animation_iter_get_pixbuf(gtkconv->u.im->iter); | |
5873 if (gtkconv->u.im->animate) | |
5874 start_anim(NULL, gtkconv); | |
5875 } | |
5876 | |
5877 gaim_gtk_buddy_icon_get_scale_size(buf, prpl_info ? &prpl_info->icon_spec : | |
5878 NULL, &scale_width, &scale_height); | |
5879 scale = gdk_pixbuf_scale_simple(buf, | |
5880 MAX(gdk_pixbuf_get_width(buf) * scale_width / | |
5881 gdk_pixbuf_animation_get_width(gtkconv->u.im->anim), 1), | |
5882 MAX(gdk_pixbuf_get_height(buf) * scale_height / | |
5883 gdk_pixbuf_animation_get_height(gtkconv->u.im->anim), 1), | |
5884 GDK_INTERP_BILINEAR); | |
5885 | |
5886 gtkconv->u.im->icon_container = gtk_vbox_new(FALSE, 0); | |
5887 | |
5888 frame = gtk_frame_new(NULL); | |
5889 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); | |
5890 gtk_box_pack_start(GTK_BOX(gtkconv->u.im->icon_container), frame, | |
5891 FALSE, FALSE, 0); | |
5892 | |
5893 event = gtk_event_box_new(); | |
5894 gtk_container_add(GTK_CONTAINER(frame), event); | |
5895 g_signal_connect(G_OBJECT(event), "button-press-event", | |
5896 G_CALLBACK(icon_menu), gtkconv); | |
5897 gtk_widget_show(event); | |
5898 | |
5899 gtkconv->u.im->icon = gtk_image_new_from_pixbuf(scale); | |
5900 gtk_widget_set_size_request(gtkconv->u.im->icon, scale_width, scale_height); | |
5901 gtk_container_add(GTK_CONTAINER(event), gtkconv->u.im->icon); | |
5902 gtk_widget_show(gtkconv->u.im->icon); | |
5903 | |
5904 g_object_unref(G_OBJECT(scale)); | |
5905 | |
5906 gtk_box_pack_start(GTK_BOX(gtkconv->lower_hbox), | |
5907 gtkconv->u.im->icon_container, FALSE, FALSE, 0); | |
5908 | |
5909 gtk_widget_show(gtkconv->u.im->icon_container); | |
5910 gtk_widget_show(frame); | |
5911 | |
5912 /* The buddy icon code needs badly to be fixed. */ | |
5913 if(gaim_gtk_conv_window_is_active_conversation(conv)) | |
5914 { | |
5915 buf = gdk_pixbuf_animation_get_static_image(gtkconv->u.im->anim); | |
5916 gtk_window_set_icon(GTK_WINDOW(win->window), buf); | |
5917 } | |
5918 } | |
5919 | |
5920 void | |
5921 gaim_gtkconv_update_buttons_by_protocol(GaimConversation *conv) | |
5922 { | |
5923 GaimGtkWindow *win; | |
5924 | |
5925 if (!GAIM_IS_GTK_CONVERSATION(conv)) | |
5926 return; | |
5927 | |
5928 win = GAIM_GTK_CONVERSATION(conv)->win; | |
5929 | |
5930 if (win != NULL && gaim_gtk_conv_window_is_active_conversation(conv)) | |
5931 gray_stuff_out(GAIM_GTK_CONVERSATION(conv)); | |
5932 } | |
5933 | |
5934 int | |
5935 gaim_gtkconv_get_tab_at_xy(GaimGtkWindow *win, int x, int y, gboolean *to_right) | |
5936 { | |
5937 gint nb_x, nb_y, x_rel, y_rel; | |
5938 GtkNotebook *notebook; | |
5939 GtkWidget *page, *tab; | |
5940 gint i, page_num = -1; | |
5941 gint count; | |
5942 gboolean horiz; | |
5943 | |
5944 if (to_right) | |
5945 *to_right = FALSE; | |
5946 | |
5947 notebook = GTK_NOTEBOOK(win->notebook); | |
5948 | |
5949 gdk_window_get_origin(win->notebook->window, &nb_x, &nb_y); | |
5950 x_rel = x - nb_x; | |
5951 y_rel = y - nb_y; | |
5952 | |
5953 horiz = (gtk_notebook_get_tab_pos(notebook) == GTK_POS_TOP || | |
5954 gtk_notebook_get_tab_pos(notebook) == GTK_POS_BOTTOM); | |
5955 | |
5956 #if GTK_CHECK_VERSION(2,2,0) | |
5957 count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook)); | |
5958 #else | |
5959 /* this is hacky, but it's only for Gtk 2.0.0... */ | |
5960 count = g_list_length(GTK_NOTEBOOK(notebook)->children); | |
5961 #endif | |
5962 | |
5963 for (i = 0; i < count; i++) { | |
5964 | |
5965 page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), i); | |
5966 tab = gtk_notebook_get_tab_label(GTK_NOTEBOOK(notebook), page); | |
5967 | |
5968 if (horiz) { | |
5969 if (x_rel >= tab->allocation.x - GAIM_HIG_BOX_SPACE && | |
5970 x_rel <= tab->allocation.x + tab->allocation.width + GAIM_HIG_BOX_SPACE) { | |
5971 page_num = i; | |
5972 | |
5973 if (to_right && x_rel >= tab->allocation.x + tab->allocation.width/2) | |
5974 *to_right = TRUE; | |
5975 | |
5976 break; | |
5977 } | |
5978 } else { | |
5979 if (y_rel >= tab->allocation.y - GAIM_HIG_BOX_SPACE && | |
5980 y_rel <= tab->allocation.y + tab->allocation.height + GAIM_HIG_BOX_SPACE) { | |
5981 page_num = i; | |
5982 | |
5983 if (to_right && y_rel >= tab->allocation.y + tab->allocation.height/2) | |
5984 *to_right = TRUE; | |
5985 | |
5986 break; | |
5987 } | |
5988 } | |
5989 } | |
5990 | |
5991 if (page_num == -1) { | |
5992 /* Add after the last tab */ | |
5993 page_num = count - 1; | |
5994 } | |
5995 | |
5996 return page_num; | |
5997 } | |
5998 | |
5999 static void | |
6000 close_on_tabs_pref_cb(const char *name, GaimPrefType type, | |
6001 gconstpointer value, gpointer data) | |
6002 { | |
6003 GList *l; | |
6004 GaimConversation *conv; | |
6005 GaimGtkConversation *gtkconv; | |
6006 | |
6007 for (l = gaim_get_conversations(); l != NULL; l = l->next) { | |
6008 conv = (GaimConversation *)l->data; | |
6009 | |
6010 if (!GAIM_IS_GTK_CONVERSATION(conv)) | |
6011 continue; | |
6012 | |
6013 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
6014 | |
6015 if (value) | |
6016 gtk_widget_show(gtkconv->close); | |
6017 else | |
6018 gtk_widget_hide(gtkconv->close); | |
6019 } | |
6020 } | |
6021 | |
6022 static void | |
6023 spellcheck_pref_cb(const char *name, GaimPrefType type, | |
6024 gconstpointer value, gpointer data) | |
6025 { | |
6026 #ifdef USE_GTKSPELL | |
6027 GList *cl; | |
6028 GaimConversation *conv; | |
6029 GaimGtkConversation *gtkconv; | |
6030 GtkSpell *spell; | |
6031 | |
6032 for (cl = gaim_get_conversations(); cl != NULL; cl = cl->next) { | |
6033 | |
6034 conv = (GaimConversation *)cl->data; | |
6035 | |
6036 if (!GAIM_IS_GTK_CONVERSATION(conv)) | |
6037 continue; | |
6038 | |
6039 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
6040 | |
6041 if (value) | |
6042 gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(gtkconv->entry)); | |
6043 else { | |
6044 spell = gtkspell_get_from_text_view(GTK_TEXT_VIEW(gtkconv->entry)); | |
6045 gtkspell_detach(spell); | |
6046 } | |
6047 } | |
6048 #endif | |
6049 } | |
6050 | |
6051 static void | |
6052 tab_side_pref_cb(const char *name, GaimPrefType type, | |
6053 gconstpointer value, gpointer data) | |
6054 { | |
6055 GList *l; | |
6056 GtkPositionType pos; | |
6057 GaimGtkWindow *win; | |
6058 | |
6059 pos = GPOINTER_TO_INT(value); | |
6060 | |
6061 for (l = gaim_gtk_conv_windows_get_list(); l != NULL; l = l->next) { | |
6062 win = l->data; | |
6063 | |
6064 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(win->notebook), pos&~8); | |
6065 } | |
6066 } | |
6067 | |
6068 static void | |
6069 show_timestamps_pref_cb(const char *name, GaimPrefType type, | |
6070 gconstpointer value, gpointer data) | |
6071 { | |
6072 GList *l; | |
6073 GaimConversation *conv; | |
6074 GaimGtkConversation *gtkconv; | |
6075 GaimGtkWindow *win; | |
6076 | |
6077 for (l = gaim_get_conversations(); l != NULL; l = l->next) | |
6078 { | |
6079 conv = (GaimConversation *)l->data; | |
6080 | |
6081 if (!GAIM_IS_GTK_CONVERSATION(conv)) | |
6082 continue; | |
6083 | |
6084 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
6085 win = gtkconv->win; | |
6086 | |
6087 gtk_check_menu_item_set_active( | |
6088 GTK_CHECK_MENU_ITEM(win->menu.show_timestamps), | |
6089 (gboolean)GPOINTER_TO_INT(value)); | |
6090 | |
6091 gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml), | |
6092 (gboolean)GPOINTER_TO_INT(value)); | |
6093 } | |
6094 } | |
6095 | |
6096 static void | |
6097 show_formatting_toolbar_pref_cb(const char *name, GaimPrefType type, | |
6098 gconstpointer value, gpointer data) | |
6099 { | |
6100 GList *l; | |
6101 GaimConversation *conv; | |
6102 GaimGtkConversation *gtkconv; | |
6103 GaimGtkWindow *win; | |
6104 | |
6105 for (l = gaim_get_conversations(); l != NULL; l = l->next) | |
6106 { | |
6107 conv = (GaimConversation *)l->data; | |
6108 | |
6109 if (!GAIM_IS_GTK_CONVERSATION(conv)) | |
6110 continue; | |
6111 | |
6112 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
6113 win = gtkconv->win; | |
6114 | |
6115 gtk_check_menu_item_set_active( | |
6116 GTK_CHECK_MENU_ITEM(win->menu.show_formatting_toolbar), | |
6117 (gboolean)GPOINTER_TO_INT(value)); | |
6118 | |
6119 if ((gboolean)GPOINTER_TO_INT(value)) | |
6120 gtk_widget_show(gtkconv->toolbar); | |
6121 else | |
6122 gtk_widget_hide(gtkconv->toolbar); | |
6123 } | |
6124 } | |
6125 | |
6126 static void | |
6127 animate_buddy_icons_pref_cb(const char *name, GaimPrefType type, | |
6128 gconstpointer value, gpointer data) | |
6129 { | |
6130 GList *l; | |
6131 GaimConversation *conv; | |
6132 GaimGtkConversation *gtkconv; | |
6133 GaimGtkWindow *win; | |
6134 | |
6135 if (!gaim_prefs_get_bool("/gaim/gtk/conversations/im/show_buddy_icons")) | |
6136 return; | |
6137 | |
6138 /* Set the "animate" flag for each icon based on the new preference */ | |
6139 for (l = gaim_get_ims(); l != NULL; l = l->next) { | |
6140 conv = (GaimConversation *)l->data; | |
6141 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
6142 gtkconv->u.im->animate = GPOINTER_TO_INT(value); | |
6143 } | |
6144 | |
6145 /* Now either stop or start animation for the active conversation in each window */ | |
6146 for (l = gaim_gtk_conv_windows_get_list(); l != NULL; l = l->next) { | |
6147 win = l->data; | |
6148 conv = gaim_gtk_conv_window_get_active_conversation(win); | |
6149 gaim_gtkconv_update_buddy_icon(conv); | |
6150 } | |
6151 } | |
6152 | |
6153 static void | |
6154 show_buddy_icons_pref_cb(const char *name, GaimPrefType type, | |
6155 gconstpointer value, gpointer data) | |
6156 { | |
6157 GList *l; | |
6158 | |
6159 for (l = gaim_get_conversations(); l != NULL; l = l->next) { | |
6160 GaimConversation *conv = l->data; | |
6161 | |
6162 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) | |
6163 gaim_gtkconv_update_buddy_icon(conv); | |
6164 } | |
6165 } | |
6166 | |
6167 static void | |
6168 conv_placement_usetabs_cb(const char *name, GaimPrefType type, | |
6169 gconstpointer value, gpointer data) | |
6170 { | |
6171 gaim_prefs_trigger_callback("/gaim/gtk/conversations/placement"); | |
6172 } | |
6173 | |
6174 static void | |
6175 account_status_changed_cb(GaimAccount *account, GaimStatus *oldstatus, | |
6176 GaimStatus *newstatus) | |
6177 { | |
6178 GList *l; | |
6179 GaimConversation *conv = NULL; | |
6180 GaimGtkConversation *gtkconv; | |
6181 | |
6182 if(strcmp(gaim_prefs_get_string("/gaim/gtk/conversations/im/hide_new"), "away")!=0) | |
6183 return; | |
6184 | |
6185 if(gaim_status_is_available(oldstatus) || !gaim_status_is_available(newstatus)) | |
6186 return; | |
6187 | |
6188 while ((l = hidden_convwin->gtkconvs) != NULL) | |
6189 { | |
6190 gtkconv = l->data; | |
6191 | |
6192 conv = gtkconv->active_conv; | |
6193 | |
6194 while(l && !gaim_status_is_available( | |
6195 gaim_account_get_active_status( | |
6196 gaim_conversation_get_account(conv)))) | |
6197 l = l->next; | |
6198 if (!l) | |
6199 break; | |
6200 | |
6201 gaim_gtk_conv_window_remove_gtkconv(hidden_convwin, gtkconv); | |
6202 gaim_gtkconv_placement_place(gtkconv); | |
6203 } | |
6204 } | |
6205 | |
6206 static void | |
6207 hide_new_pref_cb(const char *name, GaimPrefType type, | |
6208 gconstpointer value, gpointer data) | |
6209 { | |
6210 GList *l; | |
6211 GaimConversation *conv = NULL; | |
6212 GaimGtkConversation *gtkconv; | |
6213 gboolean when_away = FALSE; | |
6214 | |
6215 if(!hidden_convwin) | |
6216 return; | |
6217 | |
6218 if(strcmp(gaim_prefs_get_string("/gaim/gtk/conversations/im/hide_new"), "always")==0) | |
6219 return; | |
6220 | |
6221 if(strcmp(gaim_prefs_get_string("/gaim/gtk/conversations/im/hide_new"), "away")==0) | |
6222 when_away = TRUE; | |
6223 | |
6224 while ((l = hidden_convwin->gtkconvs) != NULL) | |
6225 { | |
6226 gtkconv = l->data; | |
6227 | |
6228 conv = gtkconv->active_conv; | |
6229 | |
6230 if(when_away && !gaim_status_is_available( | |
6231 gaim_account_get_active_status( | |
6232 gaim_conversation_get_account(conv)))) | |
6233 continue; | |
6234 | |
6235 gaim_gtk_conv_window_remove_gtkconv(hidden_convwin, gtkconv); | |
6236 gaim_gtkconv_placement_place(gtkconv); | |
6237 } | |
6238 } | |
6239 | |
6240 | |
6241 static void | |
6242 conv_placement_pref_cb(const char *name, GaimPrefType type, | |
6243 gconstpointer value, gpointer data) | |
6244 { | |
6245 GaimConvPlacementFunc func; | |
6246 | |
6247 if (strcmp(name, "/gaim/gtk/conversations/placement")) | |
6248 return; | |
6249 | |
6250 func = gaim_gtkconv_placement_get_fnc(value); | |
6251 | |
6252 if (func == NULL) | |
6253 return; | |
6254 | |
6255 gaim_gtkconv_placement_set_current_func(func); | |
6256 } | |
6257 | |
6258 static GaimGtkConversation * | |
6259 get_gtkconv_with_contact(GaimContact *contact) | |
6260 { | |
6261 GaimBlistNode *node; | |
6262 | |
6263 node = ((GaimBlistNode*)contact)->child; | |
6264 | |
6265 for (; node; node = node->next) | |
6266 { | |
6267 GaimBuddy *buddy = (GaimBuddy*)node; | |
6268 GaimConversation *conv; | |
6269 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, buddy->name, buddy->account); | |
6270 if (conv) | |
6271 return GAIM_GTK_CONVERSATION(conv); | |
6272 } | |
6273 return NULL; | |
6274 } | |
6275 | |
6276 static void | |
6277 account_signed_off_cb(GaimConnection *gc, gpointer event) | |
6278 { | |
6279 GList *iter; | |
6280 | |
6281 for (iter = gaim_get_conversations(); iter; iter = iter->next) | |
6282 { | |
6283 GaimConversation *conv = iter->data; | |
6284 | |
6285 /* This seems fine in theory, but we also need to cover the | |
6286 * case of this account matching one of the other buddies in | |
6287 * one of the contacts containing the buddy corresponding to | |
6288 * a conversation. It's easier to just update them all. */ | |
6289 /* if (gaim_conversation_get_account(conv) == account) */ | |
6290 gaim_gtkconv_update_fields(conv, GAIM_GTKCONV_TAB_ICON | | |
6291 GAIM_GTKCONV_MENU | GAIM_GTKCONV_COLORIZE_TITLE); | |
6292 } | |
6293 } | |
6294 | |
6295 static gboolean | |
6296 update_buddy_status_timeout(GaimBuddy *buddy) | |
6297 { | |
6298 /* To remove the signing-on/off door icon */ | |
6299 GaimConversation *conv; | |
6300 | |
6301 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, buddy->name, buddy->account); | |
6302 if (conv) | |
6303 gaim_gtkconv_update_fields(conv, GAIM_GTKCONV_TAB_ICON); | |
6304 | |
6305 return FALSE; | |
6306 } | |
6307 | |
6308 static void | |
6309 update_buddy_status_changed(GaimBuddy *buddy, GaimStatus *old, GaimStatus *newstatus) | |
6310 { | |
6311 GaimGtkConversation *gtkconv; | |
6312 GaimConversation *conv; | |
6313 | |
6314 gtkconv = get_gtkconv_with_contact(gaim_buddy_get_contact(buddy)); | |
6315 if (gtkconv) | |
6316 { | |
6317 conv = gtkconv->active_conv; | |
6318 gaim_gtkconv_update_fields(conv, GAIM_GTKCONV_TAB_ICON | GAIM_GTKCONV_COLORIZE_TITLE); | |
6319 if ((gaim_status_is_online(old) ^ gaim_status_is_online(newstatus)) != 0) | |
6320 gaim_gtkconv_update_fields(conv, GAIM_GTKCONV_MENU); | |
6321 } | |
6322 | |
6323 /* In case a conversation is started after the buddy has signed-on/off */ | |
6324 g_timeout_add(11000, (GSourceFunc)update_buddy_status_timeout, buddy); | |
6325 } | |
6326 | |
6327 static void | |
6328 update_buddy_privacy_changed(GaimBuddy *buddy) | |
6329 { | |
6330 GaimGtkConversation *gtkconv; | |
6331 GaimConversation *conv; | |
6332 | |
6333 gtkconv = get_gtkconv_with_contact(gaim_buddy_get_contact(buddy)); | |
6334 if (gtkconv) | |
6335 { | |
6336 conv = gtkconv->active_conv; | |
6337 gaim_gtkconv_update_fields(conv, GAIM_GTKCONV_TAB_ICON); | |
6338 } | |
6339 } | |
6340 | |
6341 static void | |
6342 update_buddy_idle_changed(GaimBuddy *buddy, gboolean old, gboolean newidle) | |
6343 { | |
6344 GaimConversation *conv; | |
6345 | |
6346 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, buddy->name, buddy->account); | |
6347 if (conv) | |
6348 gaim_gtkconv_update_fields(conv, GAIM_GTKCONV_TAB_ICON); | |
6349 } | |
6350 | |
6351 static void | |
6352 update_buddy_icon(GaimBuddy *buddy) | |
6353 { | |
6354 GaimConversation *conv; | |
6355 | |
6356 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, buddy->name, buddy->account); | |
6357 if (conv) | |
6358 gaim_gtkconv_update_fields(conv, GAIM_GTKCONV_BUDDY_ICON); | |
6359 } | |
6360 | |
6361 static void | |
6362 update_buddy_sign(GaimBuddy *buddy, const char *which) | |
6363 { | |
6364 GaimPresence *presence; | |
6365 GaimStatus *on, *off; | |
6366 | |
6367 presence = gaim_buddy_get_presence(buddy); | |
6368 if (!presence) | |
6369 return; | |
6370 off = gaim_presence_get_status(presence, "offline"); | |
6371 on = gaim_presence_get_status(presence, "available"); | |
6372 | |
6373 if (*(which+1) == 'f') | |
6374 update_buddy_status_changed(buddy, on, off); | |
6375 else | |
6376 update_buddy_status_changed(buddy, off, on); | |
6377 } | |
6378 | |
6379 static void | |
6380 update_conversation_switched(GaimConversation *conv) | |
6381 { | |
6382 gaim_gtkconv_update_fields(conv, GAIM_GTKCONV_TAB_ICON | GAIM_GTKCONV_SET_TITLE | | |
6383 GAIM_GTKCONV_MENU | GAIM_GTKCONV_BUDDY_ICON); | |
6384 } | |
6385 | |
6386 static void | |
6387 update_buddy_typing(GaimAccount *account, const char *who) | |
6388 { | |
6389 GaimConversation *conv; | |
6390 GaimGtkConversation *gtkconv; | |
6391 | |
6392 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, who, account); | |
6393 if (!conv) | |
6394 return; | |
6395 | |
6396 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
6397 if (gtkconv && gtkconv->active_conv == conv) | |
6398 gaim_gtkconv_update_fields(conv, GAIM_GTKCONV_COLORIZE_TITLE); | |
6399 } | |
6400 | |
6401 static void | |
6402 update_chat(GaimConversation *conv) | |
6403 { | |
6404 gaim_gtkconv_update_fields(conv, GAIM_GTKCONV_TOPIC | | |
6405 GAIM_GTKCONV_MENU | GAIM_GTKCONV_SET_TITLE); | |
6406 } | |
6407 | |
6408 static void | |
6409 update_chat_topic(GaimConversation *conv, const char *old, const char *new) | |
6410 { | |
6411 gaim_gtkconv_update_fields(conv, GAIM_GTKCONV_TOPIC); | |
6412 } | |
6413 | |
6414 void * | |
6415 gaim_gtk_conversations_get_handle(void) | |
6416 { | |
6417 static int handle; | |
6418 | |
6419 return &handle; | |
6420 } | |
6421 | |
6422 void | |
6423 gaim_gtk_conversations_init(void) | |
6424 { | |
6425 void *handle = gaim_gtk_conversations_get_handle(); | |
6426 void *blist_handle = gaim_blist_get_handle(); | |
6427 | |
6428 /* Conversations */ | |
6429 gaim_prefs_add_none("/gaim/gtk/conversations"); | |
6430 gaim_prefs_add_bool("/gaim/gtk/conversations/use_smooth_scrolling", TRUE); | |
6431 gaim_prefs_add_bool("/gaim/gtk/conversations/close_on_tabs", TRUE); | |
6432 gaim_prefs_add_bool("/gaim/gtk/conversations/send_bold", FALSE); | |
6433 gaim_prefs_add_bool("/gaim/gtk/conversations/send_italic", FALSE); | |
6434 gaim_prefs_add_bool("/gaim/gtk/conversations/send_underline", FALSE); | |
6435 gaim_prefs_add_bool("/gaim/gtk/conversations/spellcheck", TRUE); | |
6436 gaim_prefs_add_bool("/gaim/gtk/conversations/show_incoming_formatting", TRUE); | |
6437 | |
6438 gaim_prefs_add_bool("/gaim/gtk/conversations/show_timestamps", TRUE); | |
6439 gaim_prefs_add_bool("/gaim/gtk/conversations/show_formatting_toolbar", TRUE); | |
6440 gaim_prefs_add_bool("/gaim/gtk/conversations/passthrough_unknown_commands", FALSE); | |
6441 | |
6442 gaim_prefs_add_string("/gaim/gtk/conversations/placement", "last"); | |
6443 gaim_prefs_add_int("/gaim/gtk/conversations/placement_number", 1); | |
6444 gaim_prefs_add_string("/gaim/gtk/conversations/bgcolor", ""); | |
6445 gaim_prefs_add_string("/gaim/gtk/conversations/fgcolor", ""); | |
6446 gaim_prefs_add_string("/gaim/gtk/conversations/font_face", ""); | |
6447 gaim_prefs_add_int("/gaim/gtk/conversations/font_size", 3); | |
6448 gaim_prefs_add_bool("/gaim/gtk/conversations/tabs", TRUE); | |
6449 gaim_prefs_add_int("/gaim/gtk/conversations/tab_side", GTK_POS_TOP); | |
6450 gaim_prefs_add_int("/gaim/gtk/conversations/scrollback_lines", 4000); | |
6451 | |
6452 /* Conversations -> Chat */ | |
6453 gaim_prefs_add_none("/gaim/gtk/conversations/chat"); | |
6454 gaim_prefs_add_int("/gaim/gtk/conversations/chat/default_width", 410); | |
6455 gaim_prefs_add_int("/gaim/gtk/conversations/chat/default_height", 160); | |
6456 gaim_prefs_add_int("/gaim/gtk/conversations/chat/entry_height", 50); | |
6457 | |
6458 /* Conversations -> IM */ | |
6459 gaim_prefs_add_none("/gaim/gtk/conversations/im"); | |
6460 | |
6461 gaim_prefs_add_bool("/gaim/gtk/conversations/im/animate_buddy_icons", TRUE); | |
6462 | |
6463 gaim_prefs_add_int("/gaim/gtk/conversations/im/default_width", 410); | |
6464 gaim_prefs_add_int("/gaim/gtk/conversations/im/default_height", 160); | |
6465 gaim_prefs_add_int("/gaim/gtk/conversations/im/entry_height", 50); | |
6466 gaim_prefs_add_bool("/gaim/gtk/conversations/im/show_buddy_icons", TRUE); | |
6467 | |
6468 gaim_prefs_add_string("/gaim/gtk/conversations/im/hide_new", "never"); | |
6469 | |
6470 /* Connect callbacks. */ | |
6471 gaim_prefs_connect_callback(handle, "/gaim/gtk/conversations/close_on_tabs", | |
6472 close_on_tabs_pref_cb, NULL); | |
6473 gaim_prefs_connect_callback(handle, "/gaim/gtk/conversations/show_timestamps", | |
6474 show_timestamps_pref_cb, NULL); | |
6475 gaim_prefs_connect_callback(handle, "/gaim/gtk/conversations/show_formatting_toolbar", | |
6476 show_formatting_toolbar_pref_cb, NULL); | |
6477 gaim_prefs_connect_callback(handle, "/gaim/gtk/conversations/spellcheck", | |
6478 spellcheck_pref_cb, NULL); | |
6479 gaim_prefs_connect_callback(handle, "/gaim/gtk/conversations/tab_side", | |
6480 tab_side_pref_cb, NULL); | |
6481 | |
6482 gaim_prefs_connect_callback(handle, "/gaim/gtk/conversations/tabs", | |
6483 conv_placement_usetabs_cb, NULL); | |
6484 | |
6485 gaim_prefs_connect_callback(handle, "/gaim/gtk/conversations/placement", | |
6486 conv_placement_pref_cb, NULL); | |
6487 gaim_prefs_trigger_callback("/gaim/gtk/conversations/placement"); | |
6488 | |
6489 /* IM callbacks */ | |
6490 gaim_prefs_connect_callback(handle, "/gaim/gtk/conversations/im/animate_buddy_icons", | |
6491 animate_buddy_icons_pref_cb, NULL); | |
6492 gaim_prefs_connect_callback(handle, "/gaim/gtk/conversations/im/show_buddy_icons", | |
6493 show_buddy_icons_pref_cb, NULL); | |
6494 gaim_prefs_connect_callback(handle, "/gaim/gtk/conversations/im/hide_new", | |
6495 hide_new_pref_cb, NULL); | |
6496 | |
6497 | |
6498 | |
6499 /********************************************************************** | |
6500 * Register signals | |
6501 **********************************************************************/ | |
6502 gaim_signal_register(handle, "conversation-dragging", | |
6503 gaim_marshal_VOID__POINTER_POINTER, NULL, 2, | |
6504 gaim_value_new(GAIM_TYPE_BOXED, | |
6505 "GaimGtkWindow *"), | |
6506 gaim_value_new(GAIM_TYPE_BOXED, | |
6507 "GaimGtkWindow *")); | |
6508 | |
6509 gaim_signal_register(handle, "conversation-timestamp", | |
6510 #if SIZEOF_TIME_T == 4 | |
6511 gaim_marshal_POINTER__POINTER_INT, | |
6512 #elif SIZEOF_TIME_T == 8 | |
6513 gaim_marshal_POINTER__POINTER_INT64, | |
6514 #else | |
6515 #error Unkown size of time_t | |
6516 #endif | |
6517 gaim_value_new(GAIM_TYPE_POINTER), 2, | |
6518 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
6519 GAIM_SUBTYPE_LOG), | |
6520 #if SIZEOF_TIME_T == 4 | |
6521 gaim_value_new(GAIM_TYPE_INT)); | |
6522 #elif SIZEOF_TIME_T == 8 | |
6523 gaim_value_new(GAIM_TYPE_INT64)); | |
6524 #else | |
6525 # error Unknown size of time_t | |
6526 #endif | |
6527 | |
6528 gaim_signal_register(handle, "displaying-im-msg", | |
6529 gaim_marshal_BOOLEAN__POINTER_POINTER_POINTER_POINTER_POINTER, | |
6530 gaim_value_new(GAIM_TYPE_BOOLEAN), 5, | |
6531 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
6532 GAIM_SUBTYPE_ACCOUNT), | |
6533 gaim_value_new(GAIM_TYPE_STRING), | |
6534 gaim_value_new_outgoing(GAIM_TYPE_STRING), | |
6535 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
6536 GAIM_SUBTYPE_CONVERSATION), | |
6537 gaim_value_new(GAIM_TYPE_INT)); | |
6538 | |
6539 gaim_signal_register(handle, "displayed-im-msg", | |
6540 gaim_marshal_VOID__POINTER_POINTER_POINTER_POINTER_UINT, | |
6541 NULL, 5, | |
6542 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
6543 GAIM_SUBTYPE_ACCOUNT), | |
6544 gaim_value_new(GAIM_TYPE_STRING), | |
6545 gaim_value_new(GAIM_TYPE_STRING), | |
6546 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
6547 GAIM_SUBTYPE_CONVERSATION), | |
6548 gaim_value_new(GAIM_TYPE_INT)); | |
6549 | |
6550 gaim_signal_register(handle, "displaying-chat-msg", | |
6551 gaim_marshal_BOOLEAN__POINTER_POINTER_POINTER_POINTER_POINTER, | |
6552 gaim_value_new(GAIM_TYPE_BOOLEAN), 5, | |
6553 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
6554 GAIM_SUBTYPE_ACCOUNT), | |
6555 gaim_value_new(GAIM_TYPE_STRING), | |
6556 gaim_value_new_outgoing(GAIM_TYPE_STRING), | |
6557 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
6558 GAIM_SUBTYPE_CONVERSATION), | |
6559 gaim_value_new(GAIM_TYPE_INT)); | |
6560 | |
6561 gaim_signal_register(handle, "displayed-chat-msg", | |
6562 gaim_marshal_VOID__POINTER_POINTER_POINTER_POINTER_UINT, | |
6563 NULL, 5, | |
6564 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
6565 GAIM_SUBTYPE_ACCOUNT), | |
6566 gaim_value_new(GAIM_TYPE_STRING), | |
6567 gaim_value_new(GAIM_TYPE_STRING), | |
6568 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
6569 GAIM_SUBTYPE_CONVERSATION), | |
6570 gaim_value_new(GAIM_TYPE_INT)); | |
6571 | |
6572 gaim_signal_register(handle, "conversation-switched", | |
6573 gaim_marshal_VOID__POINTER_POINTER, NULL, 1, | |
6574 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
6575 GAIM_SUBTYPE_CONVERSATION)); | |
6576 | |
6577 /********************************************************************** | |
6578 * Register commands | |
6579 **********************************************************************/ | |
6580 gaim_cmd_register("say", "S", GAIM_CMD_P_DEFAULT, | |
6581 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, | |
6582 say_command_cb, _("say <message>: Send a message normally as if you weren't using a command."), NULL); | |
6583 gaim_cmd_register("me", "S", GAIM_CMD_P_DEFAULT, | |
6584 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, | |
6585 me_command_cb, _("me <action>: Send an IRC style action to a buddy or chat."), NULL); | |
6586 gaim_cmd_register("debug", "w", GAIM_CMD_P_DEFAULT, | |
6587 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, | |
6588 debug_command_cb, _("debug <option>: Send various debug information to the current conversation."), NULL); | |
6589 gaim_cmd_register("clear", "", GAIM_CMD_P_DEFAULT, | |
6590 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, | |
6591 clear_command_cb, _("clear: Clears the conversation scrollback."), NULL); | |
6592 gaim_cmd_register("help", "w", GAIM_CMD_P_DEFAULT, | |
6593 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, NULL, | |
6594 help_command_cb, _("help <command>: Help on a specific command."), NULL); | |
6595 | |
6596 /********************************************************************** | |
6597 * UI operations | |
6598 **********************************************************************/ | |
6599 | |
6600 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", handle, | |
6601 G_CALLBACK(account_signed_off_cb), | |
6602 GINT_TO_POINTER(GAIM_CONV_ACCOUNT_ONLINE)); | |
6603 gaim_signal_connect(gaim_connections_get_handle(), "signed-off", handle, | |
6604 G_CALLBACK(account_signed_off_cb), | |
6605 GINT_TO_POINTER(GAIM_CONV_ACCOUNT_OFFLINE)); | |
6606 | |
6607 gaim_signal_connect(gaim_conversations_get_handle(), "received-im-msg", | |
6608 handle, G_CALLBACK(received_im_msg_cb), NULL); | |
6609 | |
6610 gaim_conversations_set_ui_ops(&conversation_ui_ops); | |
6611 | |
6612 hidden_convwin = gaim_gtk_conv_window_new(); | |
6613 window_list = g_list_remove(window_list, hidden_convwin); | |
6614 | |
6615 gaim_signal_connect(gaim_accounts_get_handle(), "account-status-changed", | |
6616 handle, GAIM_CALLBACK(account_status_changed_cb), NULL); | |
6617 | |
6618 /* Callbacks to update a conversation */ | |
6619 gaim_signal_connect(blist_handle, "buddy-added", handle, | |
6620 G_CALLBACK(buddy_update_cb), NULL); | |
6621 gaim_signal_connect(blist_handle, "buddy-removed", handle, | |
6622 G_CALLBACK(buddy_update_cb), NULL); | |
6623 gaim_signal_connect(blist_handle, "buddy-signed-on", | |
6624 handle, GAIM_CALLBACK(update_buddy_sign), "on"); | |
6625 gaim_signal_connect(blist_handle, "buddy-signed-off", | |
6626 handle, GAIM_CALLBACK(update_buddy_sign), "off"); | |
6627 gaim_signal_connect(blist_handle, "buddy-status-changed", | |
6628 handle, GAIM_CALLBACK(update_buddy_status_changed), NULL); | |
6629 gaim_signal_connect(blist_handle, "buddy-privacy-changed", | |
6630 handle, GAIM_CALLBACK(update_buddy_privacy_changed), NULL); | |
6631 gaim_signal_connect(blist_handle, "buddy-idle-changed", | |
6632 handle, GAIM_CALLBACK(update_buddy_idle_changed), NULL); | |
6633 gaim_signal_connect(blist_handle, "buddy-icon-changed", | |
6634 handle, GAIM_CALLBACK(update_buddy_icon), NULL); | |
6635 gaim_signal_connect(gaim_conversations_get_handle(), "buddy-typing", | |
6636 handle, GAIM_CALLBACK(update_buddy_typing), NULL); | |
6637 gaim_signal_connect(gaim_conversations_get_handle(), "buddy-typing-stopped", | |
6638 handle, GAIM_CALLBACK(update_buddy_typing), NULL); | |
6639 gaim_signal_connect(gaim_gtk_conversations_get_handle(), "conversation-switched", | |
6640 handle, GAIM_CALLBACK(update_conversation_switched), NULL); | |
6641 gaim_signal_connect(gaim_conversations_get_handle(), "chat-left", handle, | |
6642 GAIM_CALLBACK(update_chat), NULL); | |
6643 gaim_signal_connect(gaim_conversations_get_handle(), "chat-joined", handle, | |
6644 GAIM_CALLBACK(update_chat), NULL); | |
6645 gaim_signal_connect(gaim_conversations_get_handle(), "chat-topic-changed", handle, | |
6646 GAIM_CALLBACK(update_chat_topic), NULL); | |
6647 gaim_signal_connect_priority(gaim_conversations_get_handle(), "conversation-updated", handle, | |
6648 GAIM_CALLBACK(gaim_gtkconv_updated), NULL, | |
6649 GAIM_SIGNAL_PRIORITY_LOWEST); | |
6650 } | |
6651 | |
6652 void | |
6653 gaim_gtk_conversations_uninit(void) | |
6654 { | |
6655 gaim_prefs_disconnect_by_handle(gaim_gtk_conversations_get_handle()); | |
6656 gaim_signals_disconnect_by_handle(gaim_gtk_conversations_get_handle()); | |
6657 gaim_signals_unregister_by_instance(gaim_gtk_conversations_get_handle()); | |
6658 gaim_gtk_conv_window_destroy(hidden_convwin); | |
6659 hidden_convwin=NULL; | |
6660 } | |
6661 | |
6662 | |
6663 | |
6664 | |
6665 | |
6666 | |
6667 | |
6668 | |
6669 | |
6670 | |
6671 | |
6672 | |
6673 | |
6674 | |
6675 | |
6676 | |
6677 /* down here is where gtkconvwin.c ought to start. except they share like every freaking function, | |
6678 * and touch each others' private members all day long */ | |
6679 | |
6680 /** | |
6681 * @file gtkconvwin.c GTK+ Conversation Window API | |
6682 * @ingroup gtkui | |
6683 * | |
6684 * gaim | |
6685 * | |
6686 * Gaim is the legal property of its developers, whose names are too numerous | |
6687 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6688 * source distribution. | |
6689 * | |
6690 * This program is free software; you can redistribute it and/or modify | |
6691 * it under the terms of the GNU General Public License as published by | |
6692 * the Free Software Foundation; either version 2 of the License, or | |
6693 * (at your option) any later version. | |
6694 * | |
6695 * This program is distributed in the hope that it will be useful, | |
6696 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6697 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6698 * GNU General Public License for more details. | |
6699 * | |
6700 * You should have received a copy of the GNU General Public License | |
6701 * along with this program; if not, write to the Free Software | |
6702 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
6703 * | |
6704 */ | |
6705 #include "internal.h" | |
6706 #include "gtkgaim.h" | |
6707 | |
6708 | |
6709 #include <gdk/gdkkeysyms.h> | |
6710 | |
6711 #include "account.h" | |
6712 #include "cmds.h" | |
6713 #include "debug.h" | |
6714 #include "imgstore.h" | |
6715 #include "log.h" | |
6716 #include "notify.h" | |
6717 #include "prpl.h" | |
6718 #include "request.h" | |
6719 #include "util.h" | |
6720 | |
6721 #include "gtkdnd-hints.h" | |
6722 #include "gtkblist.h" | |
6723 #include "gtkconv.h" | |
6724 #include "gtkdialogs.h" | |
6725 #include "gtkmenutray.h" | |
6726 #include "gtkpounce.h" | |
6727 #include "gtkprefs.h" | |
6728 #include "gtkprivacy.h" | |
6729 #include "gtkutils.h" | |
6730 #include "gaimstock.h" | |
6731 #include "gtkimhtml.h" | |
6732 #include "gtkimhtmltoolbar.h" | |
6733 | |
6734 static void | |
6735 do_close(GtkWidget *w, int resp, GaimGtkWindow *win) | |
6736 { | |
6737 gtk_widget_destroy(warn_close_dialog); | |
6738 warn_close_dialog = NULL; | |
6739 | |
6740 if (resp == GTK_RESPONSE_OK) | |
6741 gaim_gtk_conv_window_destroy(win); | |
6742 } | |
6743 | |
6744 static void | |
6745 build_warn_close_dialog(GaimGtkWindow *gtkwin) | |
6746 { | |
6747 GtkWidget *label; | |
6748 GtkWidget *vbox, *hbox; | |
6749 GtkWidget *img; | |
6750 | |
6751 g_return_if_fail(warn_close_dialog == NULL); | |
6752 | |
6753 | |
6754 warn_close_dialog = gtk_dialog_new_with_buttons( | |
6755 _("Confirm close"), | |
6756 GTK_WINDOW(gtkwin->window), GTK_DIALOG_MODAL, | |
6757 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
6758 GAIM_STOCK_CLOSE_TABS, GTK_RESPONSE_OK, NULL); | |
6759 | |
6760 gtk_dialog_set_default_response(GTK_DIALOG(warn_close_dialog), | |
6761 GTK_RESPONSE_OK); | |
6762 | |
6763 gtk_container_set_border_width(GTK_CONTAINER(warn_close_dialog), | |
6764 6); | |
6765 gtk_window_set_resizable(GTK_WINDOW(warn_close_dialog), FALSE); | |
6766 gtk_dialog_set_has_separator(GTK_DIALOG(warn_close_dialog), | |
6767 FALSE); | |
6768 | |
6769 /* Setup the outside spacing. */ | |
6770 vbox = GTK_DIALOG(warn_close_dialog)->vbox; | |
6771 | |
6772 gtk_box_set_spacing(GTK_BOX(vbox), 12); | |
6773 gtk_container_set_border_width(GTK_CONTAINER(vbox), 6); | |
6774 | |
6775 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_WARNING, | |
6776 GTK_ICON_SIZE_DIALOG); | |
6777 /* Setup the inner hbox and put the dialog's icon in it. */ | |
6778 hbox = gtk_hbox_new(FALSE, 12); | |
6779 gtk_container_add(GTK_CONTAINER(vbox), hbox); | |
6780 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
6781 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
6782 | |
6783 /* Setup the right vbox. */ | |
6784 vbox = gtk_vbox_new(FALSE, 12); | |
6785 gtk_container_add(GTK_CONTAINER(hbox), vbox); | |
6786 | |
6787 label = gtk_label_new(_("You have unread messages. Are you sure you want to close the window?")); | |
6788 gtk_widget_set_size_request(label, 350, -1); | |
6789 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
6790 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
6791 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
6792 | |
6793 /* Connect the signals. */ | |
6794 g_signal_connect(G_OBJECT(warn_close_dialog), "response", | |
6795 G_CALLBACK(do_close), gtkwin); | |
6796 | |
6797 } | |
6798 | |
6799 /************************************************************************** | |
6800 * Callbacks | |
6801 **************************************************************************/ | |
6802 | |
6803 static gboolean | |
6804 close_win_cb(GtkWidget *w, GdkEventAny *e, gpointer d) | |
6805 { | |
6806 GaimGtkWindow *win = d; | |
6807 GList *l; | |
6808 | |
6809 /* If there are unread messages then show a warning dialog */ | |
6810 for (l = gaim_gtk_conv_window_get_gtkconvs(win); | |
6811 l != NULL; l = l->next) | |
6812 { | |
6813 GaimGtkConversation *gtkconv = l->data; | |
6814 if (gaim_conversation_get_type(gtkconv->active_conv) == GAIM_CONV_TYPE_IM && | |
6815 gtkconv->unseen_state >= GAIM_UNSEEN_TEXT) | |
6816 { | |
6817 build_warn_close_dialog(win); | |
6818 gtk_widget_show_all(warn_close_dialog); | |
6819 | |
6820 return TRUE; | |
6821 } | |
6822 } | |
6823 | |
6824 gaim_gtk_conv_window_destroy(win); | |
6825 | |
6826 return TRUE; | |
6827 } | |
6828 | |
6829 static void | |
6830 gtkconv_set_unseen(GaimGtkConversation *gtkconv, GaimUnseenState state) | |
6831 { | |
6832 if (state == GAIM_UNSEEN_NONE) | |
6833 { | |
6834 gtkconv->unseen_count = 0; | |
6835 gtkconv->unseen_state = GAIM_UNSEEN_NONE; | |
6836 } | |
6837 else | |
6838 { | |
6839 if (state >= GAIM_UNSEEN_TEXT) | |
6840 gtkconv->unseen_count++; | |
6841 | |
6842 if (state > gtkconv->unseen_state) | |
6843 gtkconv->unseen_state = state; | |
6844 } | |
6845 | |
6846 gaim_conversation_update(gtkconv->active_conv, GAIM_CONV_UPDATE_UNSEEN); | |
6847 } | |
6848 | |
6849 /* | |
6850 * When a conversation window is focused, we know the user | |
6851 * has looked at it so we know there are no longer unseen | |
6852 * messages. | |
6853 */ | |
6854 static gint | |
6855 focus_win_cb(GtkWidget *w, GdkEventFocus *e, gpointer d) | |
6856 { | |
6857 GaimGtkWindow *win = d; | |
6858 GaimGtkConversation *gtkconv = gaim_gtk_conv_window_get_active_gtkconv(win); | |
6859 | |
6860 gtkconv_set_unseen(gtkconv, GAIM_UNSEEN_NONE); | |
6861 | |
6862 return FALSE; | |
6863 } | |
6864 | |
6865 #if !GTK_CHECK_VERSION(2,6,0) | |
6866 /* Courtesy of Galeon! */ | |
6867 static void | |
6868 tab_close_button_state_changed_cb(GtkWidget *widget, GtkStateType prev_state) | |
6869 { | |
6870 if (GTK_WIDGET_STATE(widget) == GTK_STATE_ACTIVE) | |
6871 gtk_widget_set_state(widget, GTK_STATE_NORMAL); | |
6872 } | |
6873 #endif | |
6874 | |
6875 static void | |
6876 notebook_init_grab(GaimGtkWindow *gtkwin, GtkWidget *widget) | |
6877 { | |
6878 static GdkCursor *cursor = NULL; | |
6879 | |
6880 gtkwin->in_drag = TRUE; | |
6881 | |
6882 if (gtkwin->drag_leave_signal) { | |
6883 g_signal_handler_disconnect(G_OBJECT(widget), | |
6884 gtkwin->drag_leave_signal); | |
6885 gtkwin->drag_leave_signal = 0; | |
6886 } | |
6887 | |
6888 if (cursor == NULL) | |
6889 cursor = gdk_cursor_new(GDK_FLEUR); | |
6890 | |
6891 /* Grab the pointer */ | |
6892 gtk_grab_add(gtkwin->notebook); | |
6893 #ifndef _WIN32 | |
6894 /* Currently for win32 GTK+ (as of 2.2.1), gdk_pointer_is_grabbed will | |
6895 always be true after a button press. */ | |
6896 if (!gdk_pointer_is_grabbed()) | |
6897 #endif | |
6898 gdk_pointer_grab(gtkwin->notebook->window, FALSE, | |
6899 GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, | |
6900 NULL, cursor, GDK_CURRENT_TIME); | |
6901 } | |
6902 | |
6903 static gboolean | |
6904 notebook_motion_cb(GtkWidget *widget, GdkEventButton *e, GaimGtkWindow *win) | |
6905 { | |
6906 | |
6907 /* | |
6908 * Make sure the user moved the mouse far enough for the | |
6909 * drag to be initiated. | |
6910 */ | |
6911 if (win->in_predrag) { | |
6912 if (e->x_root < win->drag_min_x || | |
6913 e->x_root >= win->drag_max_x || | |
6914 e->y_root < win->drag_min_y || | |
6915 e->y_root >= win->drag_max_y) { | |
6916 | |
6917 win->in_predrag = FALSE; | |
6918 notebook_init_grab(win, widget); | |
6919 } | |
6920 } | |
6921 else { /* Otherwise, draw the arrows. */ | |
6922 GaimGtkWindow *dest_win; | |
6923 GtkNotebook *dest_notebook; | |
6924 GtkWidget *tab; | |
6925 gint nb_x, nb_y, page_num; | |
6926 gint arrow1_x, arrow1_y, arrow2_x, arrow2_y; | |
6927 gboolean horiz_tabs = FALSE; | |
6928 GaimGtkConversation *gtkconv; | |
6929 gboolean to_right = FALSE; | |
6930 | |
6931 /* Get the window that the cursor is over. */ | |
6932 dest_win = gaim_gtk_conv_window_get_at_xy(e->x_root, e->y_root); | |
6933 | |
6934 if (dest_win == NULL) { | |
6935 dnd_hints_hide_all(); | |
6936 | |
6937 return TRUE; | |
6938 } | |
6939 | |
6940 dest_notebook = GTK_NOTEBOOK(dest_win->notebook); | |
6941 | |
6942 gdk_window_get_origin(GTK_WIDGET(dest_notebook)->window, &nb_x, &nb_y); | |
6943 | |
6944 arrow1_x = arrow2_x = nb_x; | |
6945 arrow1_y = arrow2_y = nb_y; | |
6946 | |
6947 page_num = gaim_gtkconv_get_tab_at_xy(dest_win, | |
6948 e->x_root, e->y_root, &to_right); | |
6949 to_right = to_right && (win != dest_win); | |
6950 | |
6951 if (gtk_notebook_get_tab_pos(dest_notebook) == GTK_POS_TOP || | |
6952 gtk_notebook_get_tab_pos(dest_notebook) == GTK_POS_BOTTOM) { | |
6953 | |
6954 horiz_tabs = TRUE; | |
6955 } | |
6956 | |
6957 gtkconv = gaim_gtk_conv_window_get_gtkconv_at_index(dest_win, page_num); | |
6958 tab = gtkconv->tabby; | |
6959 | |
6960 if (horiz_tabs) { | |
6961 arrow1_x = arrow2_x = nb_x + tab->allocation.x; | |
6962 | |
6963 if (((gpointer)win == (gpointer)dest_win && win->drag_tab < page_num) || to_right) { | |
6964 arrow1_x += tab->allocation.width; | |
6965 arrow2_x += tab->allocation.width; | |
6966 } | |
6967 | |
6968 arrow1_y = nb_y + tab->allocation.y; | |
6969 arrow2_y = nb_y + tab->allocation.y + tab->allocation.height; | |
6970 } else { | |
6971 arrow1_x = nb_x + tab->allocation.x; | |
6972 arrow2_x = nb_x + tab->allocation.x + tab->allocation.width; | |
6973 arrow1_y = arrow2_y = nb_y + tab->allocation.y; | |
6974 | |
6975 if (((gpointer)win == (gpointer)dest_win && win->drag_tab < page_num) || to_right) { | |
6976 arrow1_y += tab->allocation.height; | |
6977 arrow2_y += tab->allocation.height; | |
6978 } | |
6979 } | |
6980 | |
6981 if (horiz_tabs) { | |
6982 dnd_hints_show(HINT_ARROW_DOWN, arrow1_x, arrow1_y); | |
6983 dnd_hints_show(HINT_ARROW_UP, arrow2_x, arrow2_y); | |
6984 } else { | |
6985 dnd_hints_show(HINT_ARROW_RIGHT, arrow1_x, arrow1_y); | |
6986 dnd_hints_show(HINT_ARROW_LEFT, arrow2_x, arrow2_y); | |
6987 } | |
6988 } | |
6989 | |
6990 return TRUE; | |
6991 } | |
6992 | |
6993 static gboolean | |
6994 notebook_leave_cb(GtkWidget *widget, GdkEventCrossing *e, GaimGtkWindow *win) | |
6995 { | |
6996 if (win->in_drag) | |
6997 return FALSE; | |
6998 | |
6999 if (e->x_root < win->drag_min_x || | |
7000 e->x_root >= win->drag_max_x || | |
7001 e->y_root < win->drag_min_y || | |
7002 e->y_root >= win->drag_max_y) { | |
7003 | |
7004 win->in_predrag = FALSE; | |
7005 notebook_init_grab(win, widget); | |
7006 } | |
7007 | |
7008 return TRUE; | |
7009 } | |
7010 | |
7011 /* | |
7012 * THANK YOU GALEON! | |
7013 */ | |
7014 static gboolean | |
7015 notebook_press_cb(GtkWidget *widget, GdkEventButton *e, GaimGtkWindow *win) | |
7016 { | |
7017 gint nb_x, nb_y, x_rel, y_rel; | |
7018 int tab_clicked; | |
7019 GtkWidget *page; | |
7020 GtkWidget *tab; | |
7021 | |
7022 if (e->button != 1 || e->type != GDK_BUTTON_PRESS) | |
7023 return FALSE; | |
7024 | |
7025 | |
7026 if (win->in_drag) { | |
7027 gaim_debug(GAIM_DEBUG_WARNING, "gtkconv", | |
7028 "Already in the middle of a window drag at tab_press_cb\n"); | |
7029 return TRUE; | |
7030 } | |
7031 | |
7032 /* | |
7033 * Make sure a tab was actually clicked. The arrow buttons | |
7034 * mess things up. | |
7035 */ | |
7036 tab_clicked = gaim_gtkconv_get_tab_at_xy(win, e->x_root, e->y_root, NULL); | |
7037 | |
7038 if (tab_clicked == -1) | |
7039 return FALSE; | |
7040 | |
7041 /* | |
7042 * Get the relative position of the press event, with regards to | |
7043 * the position of the notebook. | |
7044 */ | |
7045 gdk_window_get_origin(win->notebook->window, &nb_x, &nb_y); | |
7046 | |
7047 x_rel = e->x_root - nb_x; | |
7048 y_rel = e->y_root - nb_y; | |
7049 | |
7050 /* Reset the min/max x/y */ | |
7051 win->drag_min_x = 0; | |
7052 win->drag_min_y = 0; | |
7053 win->drag_max_x = 0; | |
7054 win->drag_max_y = 0; | |
7055 | |
7056 /* Find out which tab was dragged. */ | |
7057 page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(win->notebook), tab_clicked); | |
7058 tab = gtk_notebook_get_tab_label(GTK_NOTEBOOK(win->notebook), page); | |
7059 | |
7060 win->drag_min_x = tab->allocation.x + nb_x; | |
7061 win->drag_min_y = tab->allocation.y + nb_y; | |
7062 win->drag_max_x = tab->allocation.width + win->drag_min_x; | |
7063 win->drag_max_y = tab->allocation.height + win->drag_min_y; | |
7064 | |
7065 /* Make sure the click occurred in the tab. */ | |
7066 if (e->x_root < win->drag_min_x || | |
7067 e->x_root >= win->drag_max_x || | |
7068 e->y_root < win->drag_min_y || | |
7069 e->y_root >= win->drag_max_y) { | |
7070 | |
7071 return FALSE; | |
7072 } | |
7073 | |
7074 win->in_predrag = TRUE; | |
7075 win->drag_tab = tab_clicked; | |
7076 | |
7077 /* Connect the new motion signals. */ | |
7078 win->drag_motion_signal = | |
7079 g_signal_connect(G_OBJECT(widget), "motion_notify_event", | |
7080 G_CALLBACK(notebook_motion_cb), win); | |
7081 | |
7082 win->drag_leave_signal = | |
7083 g_signal_connect(G_OBJECT(widget), "leave_notify_event", | |
7084 G_CALLBACK(notebook_leave_cb), win); | |
7085 | |
7086 return FALSE; | |
7087 } | |
7088 | |
7089 static gboolean | |
7090 notebook_release_cb(GtkWidget *widget, GdkEventButton *e, GaimGtkWindow *win) | |
7091 { | |
7092 GaimGtkWindow *dest_win; | |
7093 GaimConversation *conv; | |
7094 GaimGtkConversation *gtkconv; | |
7095 gint dest_page_num = 0; | |
7096 gboolean new_window = FALSE; | |
7097 gboolean to_right = FALSE; | |
7098 | |
7099 /* | |
7100 * Don't check to make sure that the event's window matches the | |
7101 * widget's, because we may be getting an event passed on from the | |
7102 * close button. | |
7103 */ | |
7104 if (e->button != 1 && e->type != GDK_BUTTON_RELEASE) | |
7105 return FALSE; | |
7106 | |
7107 if (gdk_pointer_is_grabbed()) { | |
7108 gdk_pointer_ungrab(GDK_CURRENT_TIME); | |
7109 gtk_grab_remove(widget); | |
7110 } | |
7111 | |
7112 if (!win->in_predrag && !win->in_drag) | |
7113 return FALSE; | |
7114 | |
7115 /* Disconnect the motion signal. */ | |
7116 if (win->drag_motion_signal) { | |
7117 g_signal_handler_disconnect(G_OBJECT(widget), | |
7118 win->drag_motion_signal); | |
7119 | |
7120 win->drag_motion_signal = 0; | |
7121 } | |
7122 | |
7123 /* | |
7124 * If we're in a pre-drag, we'll also need to disconnect the leave | |
7125 * signal. | |
7126 */ | |
7127 if (win->in_predrag) { | |
7128 win->in_predrag = FALSE; | |
7129 | |
7130 if (win->drag_leave_signal) { | |
7131 g_signal_handler_disconnect(G_OBJECT(widget), | |
7132 win->drag_leave_signal); | |
7133 | |
7134 win->drag_leave_signal = 0; | |
7135 } | |
7136 } | |
7137 | |
7138 /* If we're not in drag... */ | |
7139 /* We're perfectly normal people! */ | |
7140 if (!win->in_drag) | |
7141 return FALSE; | |
7142 | |
7143 win->in_drag = FALSE; | |
7144 | |
7145 dnd_hints_hide_all(); | |
7146 | |
7147 dest_win = gaim_gtk_conv_window_get_at_xy(e->x_root, e->y_root); | |
7148 | |
7149 conv = gaim_gtk_conv_window_get_active_conversation(win); | |
7150 | |
7151 if (dest_win == NULL) { | |
7152 /* If the current window doesn't have any other conversations, | |
7153 * there isn't much point transferring the conv to a new window. */ | |
7154 if (gaim_gtk_conv_window_get_gtkconv_count(win) > 1) { | |
7155 /* Make a new window to stick this to. */ | |
7156 dest_win = gaim_gtk_conv_window_new(); | |
7157 new_window = TRUE; | |
7158 } | |
7159 } | |
7160 | |
7161 if (dest_win == NULL) | |
7162 return FALSE; | |
7163 | |
7164 gaim_signal_emit(gaim_gtk_conversations_get_handle(), | |
7165 "conversation-dragging", win, dest_win); | |
7166 | |
7167 /* Get the destination page number. */ | |
7168 if (!new_window) | |
7169 dest_page_num = gaim_gtkconv_get_tab_at_xy(dest_win, | |
7170 e->x_root, e->y_root, &to_right); | |
7171 | |
7172 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
7173 | |
7174 if (win == dest_win) { | |
7175 gtk_notebook_reorder_child(GTK_NOTEBOOK(win->notebook), gtkconv->tab_cont, dest_page_num); | |
7176 } else { | |
7177 gaim_gtk_conv_window_remove_gtkconv(win, gtkconv); | |
7178 gaim_gtk_conv_window_add_gtkconv(dest_win, gtkconv); | |
7179 gtk_notebook_reorder_child(GTK_NOTEBOOK(dest_win->notebook), gtkconv->tab_cont, dest_page_num + to_right); | |
7180 gaim_gtk_conv_window_switch_gtkconv(dest_win, gtkconv); | |
7181 if (new_window) { | |
7182 gint win_width, win_height; | |
7183 | |
7184 gtk_window_get_size(GTK_WINDOW(dest_win->window), | |
7185 &win_width, &win_height); | |
7186 | |
7187 gtk_window_move(GTK_WINDOW(dest_win->window), | |
7188 e->x_root - (win_width / 2), | |
7189 e->y_root - (win_height / 2)); | |
7190 | |
7191 gaim_gtk_conv_window_show(dest_win); | |
7192 } | |
7193 } | |
7194 | |
7195 gtk_widget_grab_focus(GAIM_GTK_CONVERSATION(conv)->entry); | |
7196 | |
7197 return TRUE; | |
7198 } | |
7199 | |
7200 | |
7201 static void | |
7202 before_switch_conv_cb(GtkNotebook *notebook, GtkWidget *page, gint page_num, | |
7203 gpointer user_data) | |
7204 { | |
7205 GaimGtkWindow *win; | |
7206 GaimConversation *conv; | |
7207 GaimGtkConversation *gtkconv; | |
7208 | |
7209 win = user_data; | |
7210 conv = gaim_gtk_conv_window_get_active_conversation(win); | |
7211 | |
7212 g_return_if_fail(conv != NULL); | |
7213 | |
7214 if (gaim_conversation_get_type(conv) != GAIM_CONV_TYPE_IM) | |
7215 return; | |
7216 | |
7217 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
7218 | |
7219 stop_anim(NULL, gtkconv); | |
7220 } | |
7221 static void | |
7222 close_window(GtkWidget *w, GaimGtkWindow *win) | |
7223 { | |
7224 close_win_cb(w, NULL, win); | |
7225 } | |
7226 | |
7227 static void | |
7228 detach_tab_cb(GtkWidget *w, GObject *menu) | |
7229 { | |
7230 GaimGtkWindow *win, *new_window; | |
7231 GaimGtkConversation *gtkconv; | |
7232 | |
7233 gtkconv = g_object_get_data(menu, "clicked_tab"); | |
7234 | |
7235 if (!gtkconv) | |
7236 return; | |
7237 | |
7238 win = gaim_gtkconv_get_window(gtkconv); | |
7239 /* Nothing to do if there's only one tab in the window */ | |
7240 if (gaim_gtk_conv_window_get_gtkconv_count(win) == 1) | |
7241 return; | |
7242 | |
7243 gaim_gtk_conv_window_remove_gtkconv(win, gtkconv); | |
7244 | |
7245 new_window = gaim_gtk_conv_window_new(); | |
7246 gaim_gtk_conv_window_add_gtkconv(new_window, gtkconv); | |
7247 gaim_gtk_conv_window_show(new_window); | |
7248 } | |
7249 | |
7250 static void | |
7251 close_others_cb(GtkWidget *w, GObject *menu) | |
7252 { | |
7253 GList *iter; | |
7254 GaimGtkConversation *gtkconv; | |
7255 GaimGtkWindow *win; | |
7256 | |
7257 gtkconv = g_object_get_data(menu, "clicked_tab"); | |
7258 | |
7259 if (!gtkconv) | |
7260 return; | |
7261 | |
7262 win = gaim_gtkconv_get_window(gtkconv); | |
7263 | |
7264 for (iter = gaim_gtk_conv_window_get_gtkconvs(win); iter; ) | |
7265 { | |
7266 GaimGtkConversation *gconv = iter->data; | |
7267 iter = iter->next; | |
7268 | |
7269 if (gconv != gtkconv) | |
7270 { | |
7271 close_conv_cb(NULL, gconv); | |
7272 } | |
7273 } | |
7274 } | |
7275 | |
7276 static void close_tab_cb(GtkWidget *w, GObject *menu) | |
7277 { | |
7278 GaimGtkConversation *gtkconv; | |
7279 | |
7280 gtkconv = g_object_get_data(menu, "clicked_tab"); | |
7281 | |
7282 if (gtkconv) | |
7283 close_conv_cb(NULL, gtkconv); | |
7284 } | |
7285 | |
7286 static gboolean | |
7287 right_click_menu_cb(GtkNotebook *notebook, GdkEventButton *event, GaimGtkWindow *win) | |
7288 { | |
7289 GtkWidget *item, *menu; | |
7290 GaimGtkConversation *gtkconv; | |
7291 | |
7292 if (event->type != GDK_BUTTON_PRESS || event->button != 3) | |
7293 return FALSE; | |
7294 | |
7295 gtkconv = gaim_gtk_conv_window_get_gtkconv_at_index(win, | |
7296 gaim_gtkconv_get_tab_at_xy(win, event->x_root, event->y_root, NULL)); | |
7297 | |
7298 if (g_object_get_data(G_OBJECT(notebook->menu), "clicked_tab")) | |
7299 { | |
7300 g_object_set_data(G_OBJECT(notebook->menu), "clicked_tab", gtkconv); | |
7301 return FALSE; | |
7302 } | |
7303 | |
7304 g_object_set_data(G_OBJECT(notebook->menu), "clicked_tab", gtkconv); | |
7305 | |
7306 menu = notebook->menu; | |
7307 gaim_separator(GTK_WIDGET(menu)); | |
7308 | |
7309 item = gtk_menu_item_new_with_label(_("Close other tabs")); | |
7310 gtk_widget_show(item); | |
7311 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
7312 g_signal_connect(G_OBJECT(item), "activate", | |
7313 G_CALLBACK(close_others_cb), menu); | |
7314 | |
7315 item = gtk_menu_item_new_with_label(_("Close all tabs")); | |
7316 gtk_widget_show(item); | |
7317 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
7318 g_signal_connect(G_OBJECT(item), "activate", | |
7319 G_CALLBACK(close_window), win); | |
7320 | |
7321 gaim_separator(menu); | |
7322 | |
7323 item = gtk_menu_item_new_with_label(_("Detach this tab")); | |
7324 gtk_widget_show(item); | |
7325 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
7326 g_signal_connect(G_OBJECT(item), "activate", | |
7327 G_CALLBACK(detach_tab_cb), menu); | |
7328 | |
7329 item = gtk_menu_item_new_with_label(_("Close this tab")); | |
7330 gtk_widget_show(item); | |
7331 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
7332 g_signal_connect(G_OBJECT(item), "activate", | |
7333 G_CALLBACK(close_tab_cb), menu); | |
7334 | |
7335 return FALSE; | |
7336 } | |
7337 | |
7338 static void | |
7339 switch_conv_cb(GtkNotebook *notebook, GtkWidget *page, gint page_num, | |
7340 gpointer user_data) | |
7341 { | |
7342 GaimGtkWindow *win; | |
7343 GaimConversation *conv; | |
7344 GaimGtkConversation *gtkconv; | |
7345 const char *sound_method; | |
7346 | |
7347 win = user_data; | |
7348 gtkconv = gaim_gtk_conv_window_get_gtkconv_at_index(win, page_num); | |
7349 conv = gtkconv->active_conv; | |
7350 | |
7351 g_return_if_fail(conv != NULL); | |
7352 | |
7353 /* | |
7354 * Only set "unseen" to "none" if the window has focus | |
7355 */ | |
7356 if (gaim_gtk_conv_window_has_focus(win)) | |
7357 gtkconv_set_unseen(gtkconv, GAIM_UNSEEN_NONE); | |
7358 | |
7359 /* Update the menubar */ | |
7360 | |
7361 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtkconv->win->menu.logging), | |
7362 gaim_conversation_is_logging(conv)); | |
7363 | |
7364 generate_send_to_items(win); | |
7365 | |
7366 gaim_gtkconv_switch_active_conversation(conv); | |
7367 | |
7368 sound_method = gaim_prefs_get_string("/gaim/gtk/sound/method"); | |
7369 if (strcmp(sound_method, "none") != 0) | |
7370 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(win->menu.sounds), | |
7371 gtkconv->make_sound); | |
7372 | |
7373 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(win->menu.show_formatting_toolbar), | |
7374 gaim_prefs_get_bool("/gaim/gtk/conversations/show_formatting_toolbar")); | |
7375 | |
7376 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(win->menu.show_timestamps), | |
7377 gaim_prefs_get_bool("/gaim/gtk/conversations/show_timestamps")); | |
7378 | |
7379 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM && | |
7380 gaim_prefs_get_bool("/gaim/gtk/conversations/im/show_buddy_icons")) | |
7381 { | |
7382 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(win->menu.show_icon), | |
7383 gtkconv->u.im->show_icon); | |
7384 } | |
7385 | |
7386 /* | |
7387 * We pause icons when they are not visible. If this icon should | |
7388 * be animated then start it back up again. | |
7389 */ | |
7390 if ((gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) && | |
7391 (gtkconv->u.im->animate)) | |
7392 start_anim(NULL, gtkconv); | |
7393 | |
7394 gaim_signal_emit(gaim_gtk_conversations_get_handle(), "conversation-switched", conv); | |
7395 } | |
7396 | |
7397 /************************************************************************** | |
7398 * GTK+ window ops | |
7399 **************************************************************************/ | |
7400 | |
7401 GList * | |
7402 gaim_gtk_conv_windows_get_list() | |
7403 { | |
7404 return window_list; | |
7405 } | |
7406 | |
7407 GaimGtkWindow * | |
7408 gaim_gtk_conv_window_new() | |
7409 { | |
7410 GaimGtkWindow *win; | |
7411 GtkPositionType pos; | |
7412 GtkWidget *testidea; | |
7413 GtkWidget *menubar; | |
7414 | |
7415 win = g_malloc0(sizeof(GaimGtkWindow)); | |
7416 | |
7417 window_list = g_list_append(window_list, win); | |
7418 | |
7419 /* Create the window. */ | |
7420 win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
7421 gtk_window_set_role(GTK_WINDOW(win->window), "conversation"); | |
7422 gtk_window_set_resizable(GTK_WINDOW(win->window), TRUE); | |
7423 gtk_container_set_border_width(GTK_CONTAINER(win->window), 0); | |
7424 GTK_WINDOW(win->window)->allow_shrink = TRUE; | |
7425 | |
7426 g_signal_connect(G_OBJECT(win->window), "delete_event", | |
7427 G_CALLBACK(close_win_cb), win); | |
7428 | |
7429 g_signal_connect(G_OBJECT(win->window), "focus_in_event", | |
7430 G_CALLBACK(focus_win_cb), win); | |
7431 | |
7432 /* Create the notebook. */ | |
7433 win->notebook = gtk_notebook_new(); | |
7434 | |
7435 pos = gaim_prefs_get_int("/gaim/gtk/conversations/tab_side"); | |
7436 | |
7437 #if 0 | |
7438 gtk_notebook_set_tab_hborder(GTK_NOTEBOOK(win->notebook), 0); | |
7439 gtk_notebook_set_tab_vborder(GTK_NOTEBOOK(win->notebook), 0); | |
7440 #endif | |
7441 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(win->notebook), pos); | |
7442 gtk_notebook_set_scrollable(GTK_NOTEBOOK(win->notebook), TRUE); | |
7443 gtk_notebook_popup_enable(GTK_NOTEBOOK(win->notebook)); | |
7444 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(win->notebook), FALSE); | |
7445 gtk_notebook_set_show_border(GTK_NOTEBOOK(win->notebook), FALSE); | |
7446 | |
7447 g_signal_connect(G_OBJECT(win->notebook), "button-press-event", | |
7448 G_CALLBACK(right_click_menu_cb), win); | |
7449 | |
7450 gtk_widget_show(win->notebook); | |
7451 | |
7452 g_signal_connect(G_OBJECT(win->notebook), "switch_page", | |
7453 G_CALLBACK(before_switch_conv_cb), win); | |
7454 g_signal_connect_after(G_OBJECT(win->notebook), "switch_page", | |
7455 G_CALLBACK(switch_conv_cb), win); | |
7456 | |
7457 /* Setup the tab drag and drop signals. */ | |
7458 gtk_widget_add_events(win->notebook, | |
7459 GDK_BUTTON1_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK); | |
7460 g_signal_connect(G_OBJECT(win->notebook), "button_press_event", | |
7461 G_CALLBACK(notebook_press_cb), win); | |
7462 g_signal_connect(G_OBJECT(win->notebook), "button_release_event", | |
7463 G_CALLBACK(notebook_release_cb), win); | |
7464 | |
7465 testidea = gtk_vbox_new(FALSE, 0); | |
7466 | |
7467 /* Setup the menubar. */ | |
7468 menubar = setup_menubar(win); | |
7469 gtk_box_pack_start(GTK_BOX(testidea), menubar, FALSE, TRUE, 0); | |
7470 | |
7471 gtk_box_pack_start(GTK_BOX(testidea), win->notebook, TRUE, TRUE, 0); | |
7472 | |
7473 gtk_container_add(GTK_CONTAINER(win->window), testidea); | |
7474 | |
7475 gtk_widget_show(testidea); | |
7476 | |
7477 return win; | |
7478 } | |
7479 | |
7480 void | |
7481 gaim_gtk_conv_window_destroy(GaimGtkWindow *win) | |
7482 { | |
7483 gaim_prefs_disconnect_by_handle(win); | |
7484 window_list = g_list_remove(window_list, win); | |
7485 | |
7486 if (win->gtkconvs) { | |
7487 while (win->gtkconvs) { | |
7488 GList *nextgtk = win->gtkconvs->next; | |
7489 GaimGtkConversation *gtkconv = win->gtkconvs->data; | |
7490 GList *nextcore = gtkconv->convs->next; | |
7491 GaimConversation *conv = gtkconv->convs->data; | |
7492 gaim_conversation_destroy(conv); | |
7493 if (!nextgtk && !nextcore) | |
7494 /* we'll end up invoking ourselves when we destroy our last child */ | |
7495 /* so don't destroy ourselves right now */ | |
7496 return; | |
7497 } | |
7498 return; | |
7499 } | |
7500 gtk_widget_destroy(win->window); | |
7501 | |
7502 g_object_unref(G_OBJECT(win->menu.item_factory)); | |
7503 | |
7504 gaim_notify_close_with_handle(win); | |
7505 | |
7506 g_free(win); | |
7507 } | |
7508 | |
7509 void | |
7510 gaim_gtk_conv_window_show(GaimGtkWindow *win) | |
7511 { | |
7512 gtk_widget_show(win->window); | |
7513 } | |
7514 | |
7515 void | |
7516 gaim_gtk_conv_window_hide(GaimGtkWindow *win) | |
7517 { | |
7518 gtk_widget_hide(win->window); | |
7519 } | |
7520 | |
7521 void | |
7522 gaim_gtk_conv_window_raise(GaimGtkWindow *win) | |
7523 { | |
7524 gdk_window_raise(GDK_WINDOW(win->window->window)); | |
7525 } | |
7526 | |
7527 void | |
7528 gaim_gtk_conv_window_switch_gtkconv(GaimGtkWindow *win, GaimGtkConversation *gtkconv) | |
7529 { | |
7530 gtk_notebook_set_current_page(GTK_NOTEBOOK(win->notebook), | |
7531 gtk_notebook_page_num(GTK_NOTEBOOK(win->notebook), | |
7532 gtkconv->tab_cont)); | |
7533 } | |
7534 | |
7535 void | |
7536 gaim_gtk_conv_window_add_gtkconv(GaimGtkWindow *win, GaimGtkConversation *gtkconv) | |
7537 { | |
7538 GaimConversation *conv = gtkconv->active_conv; | |
7539 GaimGtkConversation *focus_gtkconv; | |
7540 GtkWidget *tabby, *menu_tabby; | |
7541 GtkWidget *tab_cont = gtkconv->tab_cont; | |
7542 GtkWidget *close_image; | |
7543 GaimConversationType conv_type; | |
7544 const gchar *tmp_lab; | |
7545 gint close_button_width, close_button_height, focus_width, focus_pad; | |
7546 gboolean tabs_side = FALSE; | |
7547 gint angle = 0; | |
7548 | |
7549 conv_type = gaim_conversation_get_type(conv); | |
7550 | |
7551 | |
7552 win->gtkconvs = g_list_append(win->gtkconvs, gtkconv); | |
7553 gtkconv->win = win; | |
7554 | |
7555 if (gaim_prefs_get_int("/gaim/gtk/conversations/tab_side") == GTK_POS_LEFT || | |
7556 gaim_prefs_get_int("/gaim/gtk/conversations/tab_side") == GTK_POS_RIGHT) | |
7557 tabs_side = TRUE; | |
7558 else if (gaim_prefs_get_int("/gaim/gtk/conversations/tab_side") == (GTK_POS_LEFT|8)) | |
7559 angle = 90; | |
7560 else if (gaim_prefs_get_int("/gaim/gtk/conversations/tab_side") == (GTK_POS_RIGHT|8)) | |
7561 angle = 270; | |
7562 | |
7563 if (angle) | |
7564 gtkconv->tabby = tabby = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
7565 else | |
7566 gtkconv->tabby = tabby = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
7567 gtkconv->menu_tabby = menu_tabby = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
7568 | |
7569 /* Close button. */ | |
7570 gtkconv->close = gtk_button_new(); | |
7571 gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &close_button_width, &close_button_height); | |
7572 if (gtk_check_version(2, 4, 2) == NULL) { | |
7573 /* Need to account for extra padding around the gtkbutton */ | |
7574 gtk_widget_style_get(GTK_WIDGET(gtkconv->close), | |
7575 "focus-line-width", &focus_width, | |
7576 "focus-padding", &focus_pad, | |
7577 NULL); | |
7578 close_button_width += (focus_width + focus_pad) * 2; | |
7579 close_button_height += (focus_width + focus_pad) * 2; | |
7580 } | |
7581 gtk_widget_set_size_request(GTK_WIDGET(gtkconv->close), | |
7582 close_button_width, close_button_height); | |
7583 | |
7584 gtk_button_set_relief(GTK_BUTTON(gtkconv->close), GTK_RELIEF_NONE); | |
7585 close_image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU); | |
7586 gtk_widget_show(close_image); | |
7587 gtk_container_add(GTK_CONTAINER(gtkconv->close), close_image); | |
7588 gtk_tooltips_set_tip(gtkconv->tooltips, gtkconv->close, | |
7589 _("Close conversation"), NULL); | |
7590 | |
7591 g_signal_connect(G_OBJECT(gtkconv->close), "clicked", | |
7592 G_CALLBACK(close_conv_cb), gtkconv); | |
7593 | |
7594 #if !GTK_CHECK_VERSION(2,6,0) | |
7595 /* | |
7596 * I love Galeon. They have a fix for that stupid annoying visible | |
7597 * border bug. I love you guys! -- ChipX86 | |
7598 */ | |
7599 /* This is fixed properly in some version of Gtk before 2.6.0 */ | |
7600 g_signal_connect(G_OBJECT(gtkconv->close), "state_changed", | |
7601 G_CALLBACK(tab_close_button_state_changed_cb), NULL); | |
7602 #endif | |
7603 | |
7604 /* Status icon. */ | |
7605 gtkconv->icon = gtk_image_new(); | |
7606 gtkconv->menu_icon = gtk_image_new(); | |
7607 update_tab_icon(conv); | |
7608 | |
7609 /* Tab label. */ | |
7610 gtkconv->tab_label = gtk_label_new(tmp_lab = gaim_conversation_get_title(conv)); | |
7611 | |
7612 #if GTK_CHECK_VERSION(2,6,0) | |
7613 if (!angle) | |
7614 g_object_set(G_OBJECT(gtkconv->tab_label), "ellipsize", PANGO_ELLIPSIZE_END, NULL); | |
7615 gtk_label_set_width_chars(GTK_LABEL(gtkconv->tab_label), 6); | |
7616 if (tabs_side) { | |
7617 gtk_label_set_width_chars(GTK_LABEL(gtkconv->tab_label), MIN(g_utf8_strlen(tmp_lab, -1), 12)); | |
7618 } | |
7619 if (angle) | |
7620 gtk_label_set_angle(GTK_LABEL(gtkconv->tab_label), angle); | |
7621 #endif | |
7622 gtkconv->menu_label = gtk_label_new(gaim_conversation_get_title(conv)); | |
7623 #if 0 | |
7624 gtk_misc_set_alignment(GTK_MISC(gtkconv->tab_label), 0.00, 0.5); | |
7625 gtk_misc_set_padding(GTK_MISC(gtkconv->tab_label), 4, 0); | |
7626 #endif | |
7627 | |
7628 /* Pack it all together. */ | |
7629 if (angle == 90) | |
7630 gtk_box_pack_start(GTK_BOX(tabby), gtkconv->close, FALSE, FALSE, 0); | |
7631 else | |
7632 gtk_box_pack_start(GTK_BOX(tabby), gtkconv->icon, FALSE, FALSE, 0); | |
7633 gtk_box_pack_start(GTK_BOX(menu_tabby), gtkconv->menu_icon, | |
7634 FALSE, FALSE, 0); | |
7635 | |
7636 gtk_widget_show_all(gtkconv->icon); | |
7637 gtk_widget_show_all(gtkconv->menu_icon); | |
7638 | |
7639 gtk_box_pack_start(GTK_BOX(tabby), gtkconv->tab_label, TRUE, TRUE, 0); | |
7640 gtk_box_pack_start(GTK_BOX(menu_tabby), gtkconv->menu_label, TRUE, TRUE, 0); | |
7641 gtk_widget_show(gtkconv->tab_label); | |
7642 gtk_widget_show(gtkconv->menu_label); | |
7643 gtk_misc_set_alignment(GTK_MISC(gtkconv->menu_label), 0, 0); | |
7644 | |
7645 if (angle == 90) | |
7646 gtk_box_pack_start(GTK_BOX(tabby), gtkconv->icon, FALSE, FALSE, 0); | |
7647 else | |
7648 gtk_box_pack_start(GTK_BOX(tabby), gtkconv->close, FALSE, FALSE, 0); | |
7649 if (gaim_prefs_get_bool("/gaim/gtk/conversations/close_on_tabs")) | |
7650 gtk_widget_show(gtkconv->close); | |
7651 | |
7652 gtk_widget_show(tabby); | |
7653 gtk_widget_show(menu_tabby); | |
7654 | |
7655 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) | |
7656 gaim_gtkconv_update_buddy_icon(conv); | |
7657 | |
7658 /* Add this pane to the conversation's notebook. */ | |
7659 gtk_notebook_append_page_menu(GTK_NOTEBOOK(win->notebook), tab_cont, tabby, menu_tabby); | |
7660 gtk_notebook_set_tab_label_packing(GTK_NOTEBOOK(win->notebook), tab_cont, !tabs_side && !angle, TRUE, GTK_PACK_START); | |
7661 | |
7662 | |
7663 gtk_widget_show(tab_cont); | |
7664 | |
7665 if (gaim_gtk_conv_window_get_gtkconv_count(win) == 1) { | |
7666 /* Er, bug in notebooks? Switch to the page manually. */ | |
7667 gtk_notebook_set_current_page(GTK_NOTEBOOK(win->notebook), 0); | |
7668 | |
7669 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(win->notebook), | |
7670 gaim_prefs_get_bool("/gaim/gtk/conversations/tabs")); | |
7671 } else | |
7672 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(win->notebook), TRUE); | |
7673 | |
7674 focus_gtkconv = g_list_nth_data(gaim_gtk_conv_window_get_gtkconvs(win), | |
7675 gtk_notebook_get_current_page(GTK_NOTEBOOK(win->notebook))); | |
7676 gtk_widget_grab_focus(focus_gtkconv->entry); | |
7677 | |
7678 if (gaim_gtk_conv_window_get_gtkconv_count(win) == 1) | |
7679 update_send_to_selection(win); | |
7680 } | |
7681 | |
7682 void | |
7683 gaim_gtk_conv_window_remove_gtkconv(GaimGtkWindow *win, GaimGtkConversation *gtkconv) | |
7684 { | |
7685 unsigned int index; | |
7686 GaimConversationType conv_type; | |
7687 | |
7688 conv_type = gaim_conversation_get_type(gtkconv->active_conv); | |
7689 index = gtk_notebook_page_num(GTK_NOTEBOOK(win->notebook), gtkconv->tab_cont); | |
7690 | |
7691 g_object_ref(gtkconv->tab_cont); | |
7692 gtk_object_sink(GTK_OBJECT(gtkconv->tab_cont)); | |
7693 | |
7694 gtk_notebook_remove_page(GTK_NOTEBOOK(win->notebook), index); | |
7695 | |
7696 /* go back to tabless if need be */ | |
7697 if (gaim_gtk_conv_window_get_gtkconv_count(win) <= 2) { | |
7698 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(win->notebook), | |
7699 gaim_prefs_get_bool("/gaim/gtk/conversations/tabs")); | |
7700 } | |
7701 | |
7702 win->gtkconvs = g_list_remove(win->gtkconvs, gtkconv); | |
7703 | |
7704 if (!win->gtkconvs && win != hidden_convwin) | |
7705 gaim_gtk_conv_window_destroy(win); | |
7706 } | |
7707 | |
7708 GaimGtkConversation * | |
7709 gaim_gtk_conv_window_get_gtkconv_at_index(const GaimGtkWindow *win, int index) | |
7710 { | |
7711 GtkWidget *tab_cont; | |
7712 | |
7713 if (index == -1) | |
7714 index = 0; | |
7715 tab_cont = gtk_notebook_get_nth_page(GTK_NOTEBOOK(win->notebook), index); | |
7716 return tab_cont ? g_object_get_data(G_OBJECT(tab_cont), "GaimGtkConversation") : NULL; | |
7717 } | |
7718 | |
7719 GaimGtkConversation * | |
7720 gaim_gtk_conv_window_get_active_gtkconv(const GaimGtkWindow *win) | |
7721 { | |
7722 int index; | |
7723 GtkWidget *tab_cont; | |
7724 | |
7725 index = gtk_notebook_get_current_page(GTK_NOTEBOOK(win->notebook)); | |
7726 if (index == -1) | |
7727 index = 0; | |
7728 tab_cont = gtk_notebook_get_nth_page(GTK_NOTEBOOK(win->notebook), index); | |
7729 if (!tab_cont) | |
7730 return NULL; | |
7731 return g_object_get_data(G_OBJECT(tab_cont), "GaimGtkConversation"); | |
7732 } | |
7733 | |
7734 | |
7735 GaimConversation * | |
7736 gaim_gtk_conv_window_get_active_conversation(const GaimGtkWindow *win) | |
7737 { | |
7738 GaimGtkConversation *gtkconv; | |
7739 | |
7740 gtkconv = gaim_gtk_conv_window_get_active_gtkconv(win); | |
7741 return gtkconv ? gtkconv->active_conv : NULL; | |
7742 } | |
7743 | |
7744 gboolean | |
7745 gaim_gtk_conv_window_is_active_conversation(const GaimConversation *conv) | |
7746 { | |
7747 return conv == gaim_gtk_conv_window_get_active_conversation(GAIM_GTK_CONVERSATION(conv)->win); | |
7748 } | |
7749 | |
7750 gboolean | |
7751 gaim_gtk_conv_window_has_focus(GaimGtkWindow *win) | |
7752 { | |
7753 gboolean has_focus = FALSE; | |
7754 | |
7755 g_object_get(G_OBJECT(win->window), "has-toplevel-focus", &has_focus, NULL); | |
7756 | |
7757 return has_focus; | |
7758 } | |
7759 | |
7760 GaimGtkWindow * | |
7761 gaim_gtk_conv_window_get_at_xy(int x, int y) | |
7762 { | |
7763 GaimGtkWindow *win; | |
7764 GdkWindow *gdkwin; | |
7765 GList *l; | |
7766 | |
7767 gdkwin = gdk_window_at_pointer(&x, &y); | |
7768 | |
7769 if (gdkwin) | |
7770 gdkwin = gdk_window_get_toplevel(gdkwin); | |
7771 | |
7772 for (l = gaim_gtk_conv_windows_get_list(); l != NULL; l = l->next) { | |
7773 win = l->data; | |
7774 | |
7775 if (gdkwin == win->window->window) | |
7776 return win; | |
7777 } | |
7778 | |
7779 return NULL; | |
7780 } | |
7781 | |
7782 GList * | |
7783 gaim_gtk_conv_window_get_gtkconvs(GaimGtkWindow *win) | |
7784 { | |
7785 return win->gtkconvs; | |
7786 } | |
7787 | |
7788 guint | |
7789 gaim_gtk_conv_window_get_gtkconv_count(GaimGtkWindow *win) | |
7790 { | |
7791 return g_list_length(win->gtkconvs); | |
7792 } | |
7793 | |
7794 GaimGtkWindow * | |
7795 gaim_gtk_conv_window_first_with_type(GaimConversationType type) | |
7796 { | |
7797 GList *wins, *convs; | |
7798 GaimGtkWindow *win; | |
7799 GaimGtkConversation *conv; | |
7800 | |
7801 if (type == GAIM_CONV_TYPE_UNKNOWN) | |
7802 return NULL; | |
7803 | |
7804 for (wins = gaim_gtk_conv_windows_get_list(); wins != NULL; wins = wins->next) { | |
7805 win = wins->data; | |
7806 | |
7807 for (convs = win->gtkconvs; | |
7808 convs != NULL; | |
7809 convs = convs->next) { | |
7810 | |
7811 conv = convs->data; | |
7812 | |
7813 if (gaim_conversation_get_type(conv->active_conv) == type) | |
7814 return win; | |
7815 } | |
7816 } | |
7817 | |
7818 return NULL; | |
7819 } | |
7820 | |
7821 GaimGtkWindow * | |
7822 gaim_gtk_conv_window_last_with_type(GaimConversationType type) | |
7823 { | |
7824 GList *wins, *convs; | |
7825 GaimGtkWindow *win; | |
7826 GaimGtkConversation *conv; | |
7827 | |
7828 if (type == GAIM_CONV_TYPE_UNKNOWN) | |
7829 return NULL; | |
7830 | |
7831 for (wins = g_list_last(gaim_gtk_conv_windows_get_list()); | |
7832 wins != NULL; | |
7833 wins = wins->prev) { | |
7834 | |
7835 win = wins->data; | |
7836 | |
7837 for (convs = win->gtkconvs; | |
7838 convs != NULL; | |
7839 convs = convs->next) { | |
7840 | |
7841 conv = convs->data; | |
7842 | |
7843 if (gaim_conversation_get_type(conv->active_conv) == type) | |
7844 return win; | |
7845 } | |
7846 } | |
7847 | |
7848 return NULL; | |
7849 } | |
7850 | |
7851 | |
7852 /************************************************************************** | |
7853 * Conversation placement functions | |
7854 **************************************************************************/ | |
7855 typedef struct | |
7856 { | |
7857 char *id; | |
7858 char *name; | |
7859 GaimConvPlacementFunc fnc; | |
7860 | |
7861 } ConvPlacementData; | |
7862 | |
7863 static GList *conv_placement_fncs = NULL; | |
7864 static GaimConvPlacementFunc place_conv = NULL; | |
7865 | |
7866 /* This one places conversations in the last made window. */ | |
7867 static void | |
7868 conv_placement_last_created_win(GaimGtkConversation *conv) | |
7869 { | |
7870 GaimGtkWindow *win; | |
7871 | |
7872 GList *l = g_list_last(gaim_gtk_conv_windows_get_list()); | |
7873 win = l ? l->data : NULL;; | |
7874 | |
7875 if (win == NULL) { | |
7876 win = gaim_gtk_conv_window_new(); | |
7877 | |
7878 gaim_gtk_conv_window_add_gtkconv(win, conv); | |
7879 gaim_gtk_conv_window_show(win); | |
7880 } else { | |
7881 gaim_gtk_conv_window_add_gtkconv(win, conv); | |
7882 } | |
7883 } | |
7884 | |
7885 /* This one places conversations in the last made window of the same type. */ | |
7886 static void | |
7887 conv_placement_last_created_win_type(GaimGtkConversation *conv) | |
7888 { | |
7889 GaimGtkWindow *win; | |
7890 | |
7891 win = gaim_gtk_conv_window_last_with_type(gaim_conversation_get_type(conv->active_conv)); | |
7892 | |
7893 if (win == NULL) { | |
7894 win = gaim_gtk_conv_window_new(); | |
7895 | |
7896 gaim_gtk_conv_window_add_gtkconv(win, conv); | |
7897 gaim_gtk_conv_window_show(win); | |
7898 } else | |
7899 gaim_gtk_conv_window_add_gtkconv(win, conv); | |
7900 } | |
7901 | |
7902 /* This one places each conversation in its own window. */ | |
7903 static void | |
7904 conv_placement_new_window(GaimGtkConversation *conv) | |
7905 { | |
7906 GaimGtkWindow *win; | |
7907 | |
7908 win = gaim_gtk_conv_window_new(); | |
7909 | |
7910 gaim_gtk_conv_window_add_gtkconv(win, conv); | |
7911 | |
7912 gaim_gtk_conv_window_show(win); | |
7913 } | |
7914 | |
7915 static GaimGroup * | |
7916 conv_get_group(GaimGtkConversation *conv) | |
7917 { | |
7918 GaimGroup *group = NULL; | |
7919 | |
7920 if (gaim_conversation_get_type(conv->active_conv) == GAIM_CONV_TYPE_IM) { | |
7921 GaimBuddy *buddy; | |
7922 | |
7923 buddy = gaim_find_buddy(gaim_conversation_get_account(conv->active_conv), | |
7924 gaim_conversation_get_name(conv->active_conv)); | |
7925 | |
7926 if (buddy != NULL) | |
7927 group = gaim_buddy_get_group(buddy); | |
7928 | |
7929 } else if (gaim_conversation_get_type(conv->active_conv) == GAIM_CONV_TYPE_CHAT) { | |
7930 GaimChat *chat; | |
7931 | |
7932 chat = gaim_blist_find_chat(gaim_conversation_get_account(conv->active_conv), | |
7933 gaim_conversation_get_name(conv->active_conv)); | |
7934 | |
7935 if (chat != NULL) | |
7936 group = gaim_chat_get_group(chat); | |
7937 } | |
7938 | |
7939 return group; | |
7940 } | |
7941 | |
7942 /* | |
7943 * This groups things by, well, group. Buddies from groups will always be | |
7944 * grouped together, and a buddy from a group not belonging to any currently | |
7945 * open windows will get a new window. | |
7946 */ | |
7947 static void | |
7948 conv_placement_by_group(GaimGtkConversation *conv) | |
7949 { | |
7950 GaimConversationType type; | |
7951 GaimGroup *group = NULL; | |
7952 GList *wl, *cl; | |
7953 | |
7954 type = gaim_conversation_get_type(conv->active_conv); | |
7955 | |
7956 group = conv_get_group(conv); | |
7957 | |
7958 /* Go through the list of IMs and find one with this group. */ | |
7959 for (wl = gaim_gtk_conv_windows_get_list(); wl != NULL; wl = wl->next) { | |
7960 GaimGtkWindow *win2; | |
7961 GaimGtkConversation *conv2; | |
7962 GaimGroup *group2 = NULL; | |
7963 | |
7964 win2 = wl->data; | |
7965 | |
7966 for (cl = win2->gtkconvs; | |
7967 cl != NULL; | |
7968 cl = cl->next) { | |
7969 conv2 = cl->data; | |
7970 | |
7971 group2 = conv_get_group(conv2); | |
7972 | |
7973 if (group == group2) { | |
7974 gaim_gtk_conv_window_add_gtkconv(win2, conv); | |
7975 | |
7976 return; | |
7977 } | |
7978 } | |
7979 } | |
7980 | |
7981 /* Make a new window. */ | |
7982 conv_placement_new_window(conv); | |
7983 } | |
7984 | |
7985 /* This groups things by account. Otherwise, the same semantics as above */ | |
7986 static void | |
7987 conv_placement_by_account(GaimGtkConversation *conv) | |
7988 { | |
7989 GaimConversationType type; | |
7990 GList *wins, *convs; | |
7991 GaimAccount *account; | |
7992 | |
7993 account = gaim_conversation_get_account(conv->active_conv); | |
7994 type = gaim_conversation_get_type(conv->active_conv); | |
7995 | |
7996 /* Go through the list of IMs and find one with this group. */ | |
7997 for (wins = gaim_gtk_conv_windows_get_list(); wins != NULL; wins = wins->next) { | |
7998 GaimGtkWindow *win2; | |
7999 GaimGtkConversation *conv2; | |
8000 | |
8001 win2 = wins->data; | |
8002 | |
8003 for (convs = win2->gtkconvs; | |
8004 convs != NULL; | |
8005 convs = convs->next) { | |
8006 conv2 = convs->data; | |
8007 | |
8008 if (account == gaim_conversation_get_account(conv2->active_conv)) { | |
8009 gaim_gtk_conv_window_add_gtkconv(win2, conv); | |
8010 return; | |
8011 } | |
8012 } | |
8013 } | |
8014 | |
8015 /* Make a new window. */ | |
8016 conv_placement_new_window(conv); | |
8017 } | |
8018 | |
8019 static ConvPlacementData * | |
8020 get_conv_placement_data(const char *id) | |
8021 { | |
8022 ConvPlacementData *data = NULL; | |
8023 GList *n; | |
8024 | |
8025 for (n = conv_placement_fncs; n; n = n->next) { | |
8026 data = n->data; | |
8027 if (!strcmp(data->id, id)) | |
8028 return data; | |
8029 } | |
8030 | |
8031 return NULL; | |
8032 } | |
8033 | |
8034 static void | |
8035 add_conv_placement_fnc(const char *id, const char *name, | |
8036 GaimConvPlacementFunc fnc) | |
8037 { | |
8038 ConvPlacementData *data; | |
8039 | |
8040 data = g_new(ConvPlacementData, 1); | |
8041 | |
8042 data->id = g_strdup(id); | |
8043 data->name = g_strdup(name); | |
8044 data->fnc = fnc; | |
8045 | |
8046 conv_placement_fncs = g_list_append(conv_placement_fncs, data); | |
8047 } | |
8048 | |
8049 static void | |
8050 ensure_default_funcs(void) | |
8051 { | |
8052 if (conv_placement_fncs == NULL) { | |
8053 add_conv_placement_fnc("last", _("Last created window"), | |
8054 conv_placement_last_created_win); | |
8055 add_conv_placement_fnc("im_chat", _("Separate IM and Chat windows"), | |
8056 conv_placement_last_created_win_type); | |
8057 add_conv_placement_fnc("new", _("New window"), | |
8058 conv_placement_new_window); | |
8059 add_conv_placement_fnc("group", _("By group"), | |
8060 conv_placement_by_group); | |
8061 add_conv_placement_fnc("account", _("By account"), | |
8062 conv_placement_by_account); | |
8063 } | |
8064 } | |
8065 | |
8066 GList * | |
8067 gaim_gtkconv_placement_get_options(void) | |
8068 { | |
8069 GList *n, *list = NULL; | |
8070 ConvPlacementData *data; | |
8071 | |
8072 ensure_default_funcs(); | |
8073 | |
8074 for (n = conv_placement_fncs; n; n = n->next) { | |
8075 data = n->data; | |
8076 list = g_list_append(list, data->name); | |
8077 list = g_list_append(list, data->id); | |
8078 } | |
8079 | |
8080 return list; | |
8081 } | |
8082 | |
8083 | |
8084 void | |
8085 gaim_gtkconv_placement_add_fnc(const char *id, const char *name, | |
8086 GaimConvPlacementFunc fnc) | |
8087 { | |
8088 g_return_if_fail(id != NULL); | |
8089 g_return_if_fail(name != NULL); | |
8090 g_return_if_fail(fnc != NULL); | |
8091 | |
8092 ensure_default_funcs(); | |
8093 | |
8094 add_conv_placement_fnc(id, name, fnc); | |
8095 } | |
8096 | |
8097 void | |
8098 gaim_gtkconv_placement_remove_fnc(const char *id) | |
8099 { | |
8100 ConvPlacementData *data = get_conv_placement_data(id); | |
8101 | |
8102 if (data == NULL) | |
8103 return; | |
8104 | |
8105 conv_placement_fncs = g_list_remove(conv_placement_fncs, data); | |
8106 | |
8107 g_free(data->id); | |
8108 g_free(data->name); | |
8109 g_free(data); | |
8110 } | |
8111 | |
8112 const char * | |
8113 gaim_gtkconv_placement_get_name(const char *id) | |
8114 { | |
8115 ConvPlacementData *data; | |
8116 | |
8117 ensure_default_funcs(); | |
8118 | |
8119 data = get_conv_placement_data(id); | |
8120 | |
8121 if (data == NULL) | |
8122 return NULL; | |
8123 | |
8124 return data->name; | |
8125 } | |
8126 | |
8127 GaimConvPlacementFunc | |
8128 gaim_gtkconv_placement_get_fnc(const char *id) | |
8129 { | |
8130 ConvPlacementData *data; | |
8131 | |
8132 ensure_default_funcs(); | |
8133 | |
8134 data = get_conv_placement_data(id); | |
8135 | |
8136 if (data == NULL) | |
8137 return NULL; | |
8138 | |
8139 return data->fnc; | |
8140 } | |
8141 | |
8142 void | |
8143 gaim_gtkconv_placement_set_current_func(GaimConvPlacementFunc func) | |
8144 { | |
8145 g_return_if_fail(func != NULL); | |
8146 | |
8147 /* If tabs are enabled, set the function, otherwise, NULL it out. */ | |
8148 if (gaim_prefs_get_bool("/gaim/gtk/conversations/tabs")) | |
8149 place_conv = func; | |
8150 else | |
8151 place_conv = NULL; | |
8152 } | |
8153 | |
8154 GaimConvPlacementFunc | |
8155 gaim_gtkconv_placement_get_current_func(void) | |
8156 { | |
8157 return place_conv; | |
8158 } | |
8159 | |
8160 void | |
8161 gaim_gtkconv_placement_place(GaimGtkConversation *gtkconv) | |
8162 { | |
8163 if (place_conv) | |
8164 place_conv(gtkconv); | |
8165 else | |
8166 conv_placement_new_window(gtkconv); | |
8167 } | |
8168 | |
8169 gboolean | |
8170 gaim_gtkconv_is_hidden(GaimGtkConversation *gtkconv) | |
8171 { | |
8172 g_return_val_if_fail(gtkconv != NULL, FALSE); | |
8173 | |
8174 return (gtkconv->win == hidden_convwin); | |
8175 } | |
8176 | |
8177 | |
8178 /* Algorithm from http://www.w3.org/TR/AERT#color-contrast */ | |
8179 static gboolean | |
8180 color_is_visible(GdkColor foreground, GdkColor background, int color_contrast, int brightness_contrast) | |
8181 { | |
8182 gulong fg_brightness; | |
8183 gulong bg_brightness; | |
8184 gulong br_diff; | |
8185 gulong col_diff; | |
8186 int fred, fgreen, fblue, bred, bgreen, bblue; | |
8187 | |
8188 /* this algorithm expects colors between 0 and 255 for each of red green and blue. | |
8189 * GTK on the other hand has values between 0 and 65535 | |
8190 * Err suggested I >> 8, which grabbed the high bits. | |
8191 */ | |
8192 | |
8193 fred = foreground.red >> 8 ; | |
8194 fgreen = foreground.green >> 8 ; | |
8195 fblue = foreground.blue >> 8 ; | |
8196 | |
8197 | |
8198 bred = background.red >> 8 ; | |
8199 bgreen = background.green >> 8 ; | |
8200 bblue = background.blue >> 8 ; | |
8201 | |
8202 fg_brightness = (fred * 299 + fgreen * 587 + fblue * 114) / 1000; | |
8203 bg_brightness = (bred * 299 + bgreen * 587 + bblue * 114) / 1000; | |
8204 br_diff = abs(fg_brightness - bg_brightness); | |
8205 | |
8206 col_diff = abs(fred - bred) + abs(fgreen - bgreen) + abs(fblue - bblue); | |
8207 | |
8208 return ((col_diff > color_contrast) && (br_diff > brightness_contrast)); | |
8209 } | |
8210 | |
8211 | |
8212 static GdkColor* | |
8213 generate_nick_colors(guint *color_count, GdkColor background) | |
8214 { | |
8215 guint numcolors = *color_count; | |
8216 guint i = 0, j = 0; | |
8217 GdkColor *colors = g_new(GdkColor, numcolors); | |
8218 GdkColor nick_highlight; | |
8219 GdkColor send_color; | |
8220 time_t breakout_time; | |
8221 | |
8222 gdk_color_parse(HIGHLIGHT_COLOR, &nick_highlight); | |
8223 gdk_color_parse(SEND_COLOR, &send_color); | |
8224 | |
8225 srand(background.red + background.green + background.blue + 1); | |
8226 | |
8227 breakout_time = time(NULL) + 3; | |
8228 | |
8229 /* first we look through the list of "good" colors: colors that differ from every other color in the | |
8230 * list. only some of them will differ from the background color though. lets see if we can find | |
8231 * numcolors of them that do | |
8232 */ | |
8233 while (i < numcolors && j < NUM_NICK_SEED_COLORS && time(NULL) < breakout_time) | |
8234 { | |
8235 GdkColor color = nick_seed_colors[j]; | |
8236 | |
8237 if (color_is_visible(color, background, MIN_COLOR_CONTRAST, MIN_BRIGHTNESS_CONTRAST) && | |
8238 color_is_visible(color, nick_highlight, MIN_COLOR_CONTRAST / 2, 0) && | |
8239 color_is_visible(color, send_color, MIN_COLOR_CONTRAST / 4, 0)) | |
8240 { | |
8241 colors[i] = color; | |
8242 i++; | |
8243 } | |
8244 j++; | |
8245 } | |
8246 | |
8247 /* we might not have found numcolors in the last loop. if we did, we'll never enter this one. | |
8248 * if we did not, lets just find some colors that don't conflict with the background. its | |
8249 * expensive to find colors that not only don't conflict with the background, but also do not | |
8250 * conflict with each other. | |
8251 */ | |
8252 while(i < numcolors && time(NULL) < breakout_time) | |
8253 { | |
8254 GdkColor color = { 0, rand() % 65536, rand() % 65536, rand() % 65536 }; | |
8255 | |
8256 if (color_is_visible(color, background, MIN_COLOR_CONTRAST, MIN_BRIGHTNESS_CONTRAST) && | |
8257 color_is_visible(color, nick_highlight, MIN_COLOR_CONTRAST / 2, 0) && | |
8258 color_is_visible(color, send_color, MIN_COLOR_CONTRAST / 4, 0)) | |
8259 { | |
8260 colors[i] = color; | |
8261 i++; | |
8262 } | |
8263 } | |
8264 | |
8265 if (i < numcolors) { | |
8266 GdkColor *c = colors; | |
8267 gaim_debug_warning("gtkconv", "Unable to generate enough random colors before timeout. %u colors found.\n", i); | |
8268 colors = g_memdup(c, i * sizeof(GdkColor)); | |
8269 g_free(c); | |
8270 *color_count = i; | |
8271 } | |
8272 | |
8273 return colors; | |
8274 } |