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