comparison pidgin/gtkblist.c @ 15374:5fe8042783c1

Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author Sean Egan <seanegan@gmail.com>
date Sat, 20 Jan 2007 02:32:10 +0000
parents
children a8ee645e7fb4
comparison
equal deleted inserted replaced
15373:f79e0f4df793 15374:5fe8042783c1
1 /*
2 * @file gtkblist.c GTK+ BuddyList 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 #include "account.h"
30 #include "connection.h"
31 #include "core.h"
32 #include "debug.h"
33 #include "notify.h"
34 #include "prpl.h"
35 #include "prefs.h"
36 #include "plugin.h"
37 #include "request.h"
38 #include "signals.h"
39 #include "gaimstock.h"
40 #include "util.h"
41
42 #include "gtkaccount.h"
43 #include "gtkblist.h"
44 #include "gtkcellrendererexpander.h"
45 #include "gtkconv.h"
46 #include "gtkdebug.h"
47 #include "gtkdialogs.h"
48 #include "gtkft.h"
49 #include "gtklog.h"
50 #include "gtkmenutray.h"
51 #include "gtkpounce.h"
52 #include "gtkplugin.h"
53 #include "gtkprefs.h"
54 #include "gtkprivacy.h"
55 #include "gtkroomlist.h"
56 #include "gtkstatusbox.h"
57 #include "gtkscrollbook.h"
58 #include "gtkutils.h"
59
60 #include <gdk/gdkkeysyms.h>
61 #include <gtk/gtk.h>
62 #include <gdk/gdk.h>
63
64 #define HEADLINE_CLOSE_SIZE 12
65
66 typedef struct
67 {
68 GaimAccount *account;
69
70 GtkWidget *window;
71 GtkWidget *combo;
72 GtkWidget *entry;
73 GtkWidget *entry_for_alias;
74 GtkWidget *account_box;
75
76 } GaimGtkAddBuddyData;
77
78 typedef struct
79 {
80 GaimAccount *account;
81 gchar *default_chat_name;
82
83 GtkWidget *window;
84 GtkWidget *account_menu;
85 GtkWidget *alias_entry;
86 GtkWidget *group_combo;
87 GtkWidget *entries_box;
88 GtkSizeGroup *sg;
89
90 GList *entries;
91
92 } GaimGtkAddChatData;
93
94 typedef struct
95 {
96 GaimAccount *account;
97
98 GtkWidget *window;
99 GtkWidget *account_menu;
100 GtkWidget *entries_box;
101 GtkSizeGroup *sg;
102
103 GList *entries;
104 } GaimGtkJoinChatData;
105
106
107 static GtkWidget *accountmenu = NULL;
108
109 static guint visibility_manager_count = 0;
110 static gboolean gtk_blist_obscured = FALSE;
111 GHashTable* status_icon_hash_table = NULL;
112
113 static GList *gaim_gtk_blist_sort_methods = NULL;
114 static struct gaim_gtk_blist_sort_method *current_sort_method = NULL;
115 static void sort_method_none(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur, GtkTreeIter *iter);
116
117 /* The functions we use for sorting aren't available in gtk 2.0.x, and
118 * segfault in 2.2.0. 2.2.1 is known to work, so I'll require that */
119 #if GTK_CHECK_VERSION(2,2,1)
120 static void sort_method_alphabetical(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur, GtkTreeIter *iter);
121 static void sort_method_status(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur, GtkTreeIter *iter);
122 static void sort_method_log(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur, GtkTreeIter *iter);
123 #endif
124 static GaimGtkBuddyList *gtkblist = NULL;
125
126 static gboolean gaim_gtk_blist_refresh_timer(GaimBuddyList *list);
127 static void gaim_gtk_blist_update_buddy(GaimBuddyList *list, GaimBlistNode *node, gboolean statusChange);
128 static void gaim_gtk_blist_selection_changed(GtkTreeSelection *selection, gpointer data);
129 static void gaim_gtk_blist_update(GaimBuddyList *list, GaimBlistNode *node);
130 static void gaim_gtk_blist_update_contact(GaimBuddyList *list, GaimBlistNode *node);
131 static char *gaim_get_tooltip_text(GaimBlistNode *node, gboolean full);
132 static const char *item_factory_translate_func (const char *path, gpointer func_data);
133 static gboolean get_iter_from_node(GaimBlistNode *node, GtkTreeIter *iter);
134 static void redo_buddy_list(GaimBuddyList *list, gboolean remove, gboolean rerender);
135 static void gaim_gtk_blist_collapse_contact_cb(GtkWidget *w, GaimBlistNode *node);
136 static char *gaim_get_group_title(GaimBlistNode *gnode, gboolean expanded);
137
138 static void gaim_gtk_blist_tooltip_destroy(void);
139
140 struct _gaim_gtk_blist_node {
141 GtkTreeRowReference *row;
142 gboolean contact_expanded;
143 gboolean recent_signonoff;
144 gint recent_signonoff_timer;
145 GString *status_icon_key;
146 };
147
148 static void gaim_gtk_blist_update_buddy_status_icon_key(struct _gaim_gtk_blist_node *gtkbuddynode,
149 GaimBuddy *buddy, GaimStatusIconSize size);
150
151
152 static char dim_grey_string[8] = "";
153 static char *dim_grey()
154 {
155 if (!gtkblist)
156 return "dim grey";
157 if (!dim_grey_string[0]) {
158 GtkStyle *style = gtk_widget_get_style(gtkblist->treeview);
159 snprintf(dim_grey_string, sizeof(dim_grey_string), "#%02x%02x%02x",
160 style->text_aa[GTK_STATE_NORMAL].red >> 8,
161 style->text_aa[GTK_STATE_NORMAL].green >> 8,
162 style->text_aa[GTK_STATE_NORMAL].blue >> 8);
163 }
164 return dim_grey_string;
165 }
166
167 /***************************************************
168 * Callbacks *
169 ***************************************************/
170 static gboolean gtk_blist_visibility_cb(GtkWidget *w, GdkEventVisibility *event, gpointer data)
171 {
172 if (event->state == GDK_VISIBILITY_FULLY_OBSCURED)
173 gtk_blist_obscured = TRUE;
174 else if (gtk_blist_obscured) {
175 gtk_blist_obscured = FALSE;
176 gaim_gtk_blist_refresh_timer(gaim_get_blist());
177 }
178
179 /* continue to handle event normally */
180 return FALSE;
181 }
182
183 static gboolean gtk_blist_window_state_cb(GtkWidget *w, GdkEventWindowState *event, gpointer data)
184 {
185 if(event->changed_mask & GDK_WINDOW_STATE_WITHDRAWN) {
186 if(event->new_window_state & GDK_WINDOW_STATE_WITHDRAWN)
187 gaim_prefs_set_bool("/gaim/gtk/blist/list_visible", FALSE);
188 else {
189 gaim_prefs_set_bool("/gaim/gtk/blist/list_visible", TRUE);
190 gaim_gtk_blist_refresh_timer(gaim_get_blist());
191 }
192 }
193
194 if(event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED) {
195 if(event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED)
196 gaim_prefs_set_bool("/gaim/gtk/blist/list_maximized", TRUE);
197 else
198 gaim_prefs_set_bool("/gaim/gtk/blist/list_maximized", FALSE);
199 }
200
201 /* Refresh gtkblist if un-iconifying */
202 if (event->changed_mask & GDK_WINDOW_STATE_ICONIFIED){
203 if (!(event->new_window_state & GDK_WINDOW_STATE_ICONIFIED))
204 gaim_gtk_blist_refresh_timer(gaim_get_blist());
205 }
206
207 return FALSE;
208 }
209
210 static gboolean gtk_blist_delete_cb(GtkWidget *w, GdkEventAny *event, gpointer data)
211 {
212 if(visibility_manager_count)
213 gaim_blist_set_visible(FALSE);
214 else
215 gaim_core_quit();
216
217 /* we handle everything, event should not propogate further */
218 return TRUE;
219 }
220
221 static gboolean gtk_blist_configure_cb(GtkWidget *w, GdkEventConfigure *event, gpointer data)
222 {
223 /* unfortunately GdkEventConfigure ignores the window gravity, but *
224 * the only way we have of setting the position doesn't. we have to *
225 * call get_position because it does pay attention to the gravity. *
226 * this is inefficient and I agree it sucks, but it's more likely *
227 * to work correctly. - Robot101 */
228 gint x, y;
229
230 /* check for visibility because when we aren't visible, this will *
231 * give us bogus (0,0) coordinates. - xOr */
232 if (GTK_WIDGET_VISIBLE(w))
233 gtk_window_get_position(GTK_WINDOW(w), &x, &y);
234 else
235 return FALSE; /* carry on normally */
236
237 #ifdef _WIN32
238 /* Workaround for GTK+ bug # 169811 - "configure_event" is fired
239 * when the window is being maximized */
240 if (gdk_window_get_state(w->window)
241 & GDK_WINDOW_STATE_MAXIMIZED) {
242 return FALSE;
243 }
244 #endif
245
246 /* don't save if nothing changed */
247 if (x == gaim_prefs_get_int("/gaim/gtk/blist/x") &&
248 y == gaim_prefs_get_int("/gaim/gtk/blist/y") &&
249 event->width == gaim_prefs_get_int("/gaim/gtk/blist/width") &&
250 event->height == gaim_prefs_get_int("/gaim/gtk/blist/height")) {
251
252 return FALSE; /* carry on normally */
253 }
254
255 /* don't save off-screen positioning */
256 if (x + event->width < 0 ||
257 y + event->height < 0 ||
258 x > gdk_screen_width() ||
259 y > gdk_screen_height()) {
260
261 return FALSE; /* carry on normally */
262 }
263
264 /* ignore changes when maximized */
265 if(gaim_prefs_get_bool("/gaim/gtk/blist/list_maximized"))
266 return FALSE;
267
268 /* store the position */
269 gaim_prefs_set_int("/gaim/gtk/blist/x", x);
270 gaim_prefs_set_int("/gaim/gtk/blist/y", y);
271 gaim_prefs_set_int("/gaim/gtk/blist/width", event->width);
272 gaim_prefs_set_int("/gaim/gtk/blist/height", event->height);
273
274 gtk_widget_set_size_request(gtkblist->headline_label,
275 gaim_prefs_get_int("/gaim/gtk/blist/width")-25,-1);
276 /* continue to handle event normally */
277 return FALSE;
278 }
279
280 static void gtk_blist_menu_info_cb(GtkWidget *w, GaimBuddy *b)
281 {
282 serv_get_info(b->account->gc, b->name);
283 }
284
285 static void gtk_blist_menu_im_cb(GtkWidget *w, GaimBuddy *b)
286 {
287 gaim_gtkdialogs_im_with_user(b->account, b->name);
288 }
289
290 static void gtk_blist_menu_send_file_cb(GtkWidget *w, GaimBuddy *b)
291 {
292 serv_send_file(b->account->gc, b->name, NULL);
293 }
294
295 static void gtk_blist_menu_autojoin_cb(GtkWidget *w, GaimChat *chat)
296 {
297 gaim_blist_node_set_bool((GaimBlistNode*)chat, "gtk-autojoin",
298 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w)));
299 }
300
301 static void gtk_blist_join_chat(GaimChat *chat)
302 {
303 GaimConversation *conv;
304
305 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT,
306 gaim_chat_get_name(chat),
307 chat->account);
308
309 if (conv != NULL)
310 gaim_gtkconv_present_conversation(conv);
311
312 serv_join_chat(chat->account->gc, chat->components);
313 }
314
315 static void gtk_blist_menu_join_cb(GtkWidget *w, GaimChat *chat)
316 {
317 gtk_blist_join_chat(chat);
318 }
319
320 static void gtk_blist_renderer_edited_cb(GtkCellRendererText *text_rend, char *arg1,
321 char *arg2, gpointer nada)
322 {
323 GtkTreeIter iter;
324 GtkTreePath *path;
325 GValue val;
326 GaimBlistNode *node;
327 GaimGroup *dest;
328
329 path = gtk_tree_path_new_from_string (arg1);
330 gtk_tree_model_get_iter (GTK_TREE_MODEL(gtkblist->treemodel), &iter, path);
331 gtk_tree_path_free (path);
332 val.g_type = 0;
333 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val);
334 node = g_value_get_pointer(&val);
335 gtk_tree_view_set_enable_search (GTK_TREE_VIEW(gtkblist->treeview), TRUE);
336 g_object_set(G_OBJECT(gtkblist->text_rend), "editable", FALSE, NULL);
337
338 switch (node->type)
339 {
340 case GAIM_BLIST_CONTACT_NODE:
341 {
342 GaimContact *contact = (GaimContact *)node;
343 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data;
344
345 if (contact->alias || gtknode->contact_expanded)
346 gaim_blist_alias_contact(contact, arg2);
347 else
348 {
349 GaimBuddy *buddy = gaim_contact_get_priority_buddy(contact);
350 gaim_blist_alias_buddy(buddy, arg2);
351 serv_alias_buddy(buddy);
352 }
353 }
354 break;
355
356 case GAIM_BLIST_BUDDY_NODE:
357 gaim_blist_alias_buddy((GaimBuddy*)node, arg2);
358 serv_alias_buddy((GaimBuddy *)node);
359 break;
360 case GAIM_BLIST_GROUP_NODE:
361 dest = gaim_find_group(arg2);
362 if (dest != NULL && strcmp(arg2, ((GaimGroup*) node)->name)) {
363 gaim_gtkdialogs_merge_groups((GaimGroup*) node, arg2);
364 } else
365 gaim_blist_rename_group((GaimGroup*)node, arg2);
366 break;
367 case GAIM_BLIST_CHAT_NODE:
368 gaim_blist_alias_chat((GaimChat*)node, arg2);
369 break;
370 default:
371 break;
372 }
373 }
374
375 static void gtk_blist_menu_alias_cb(GtkWidget *w, GaimBlistNode *node)
376 {
377 GtkTreeIter iter;
378 GtkTreePath *path;
379 const char *text = NULL;
380 char *esc;
381
382 if (!(get_iter_from_node(node, &iter))) {
383 /* This is either a bug, or the buddy is in a collapsed contact */
384 node = node->parent;
385 if (!get_iter_from_node(node, &iter))
386 /* Now it's definitely a bug */
387 return;
388 }
389
390 switch (node->type) {
391 case GAIM_BLIST_BUDDY_NODE:
392 text = gaim_buddy_get_alias((GaimBuddy *)node);
393 break;
394 case GAIM_BLIST_CONTACT_NODE:
395 text = gaim_contact_get_alias((GaimContact *)node);
396 break;
397 case GAIM_BLIST_GROUP_NODE:
398 text = ((GaimGroup *)node)->name;
399 break;
400 case GAIM_BLIST_CHAT_NODE:
401 text = gaim_chat_get_name((GaimChat *)node);
402 break;
403 default:
404 g_return_if_reached();
405 }
406
407 esc = g_markup_escape_text(text, -1);
408 gtk_tree_store_set(gtkblist->treemodel, &iter, NAME_COLUMN, esc, -1);
409 g_free(esc);
410
411 path = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &iter);
412 g_object_set(G_OBJECT(gtkblist->text_rend), "editable", TRUE, NULL);
413 gtk_tree_view_set_enable_search (GTK_TREE_VIEW(gtkblist->treeview), FALSE);
414 gtk_widget_grab_focus(gtkblist->treeview);
415 #if GTK_CHECK_VERSION(2,2,0)
416 gtk_tree_view_set_cursor_on_cell(GTK_TREE_VIEW(gtkblist->treeview), path,
417 gtkblist->text_column, gtkblist->text_rend, TRUE);
418 #else
419 gtk_tree_view_set_cursor(GTK_TREE_VIEW(gtkblist->treeview), path, gtkblist->text_column, TRUE);
420 #endif
421 gtk_tree_path_free(path);
422 }
423
424 static void gtk_blist_menu_bp_cb(GtkWidget *w, GaimBuddy *b)
425 {
426 gaim_gtk_pounce_editor_show(b->account, b->name, NULL);
427 }
428
429 static void gtk_blist_menu_showlog_cb(GtkWidget *w, GaimBlistNode *node)
430 {
431 GaimLogType type;
432 GaimAccount *account;
433 char *name = NULL;
434
435 gaim_gtk_set_cursor(gtkblist->window, GDK_WATCH);
436
437 if (GAIM_BLIST_NODE_IS_BUDDY(node)) {
438 GaimBuddy *b = (GaimBuddy*) node;
439 type = GAIM_LOG_IM;
440 name = g_strdup(b->name);
441 account = b->account;
442 } else if (GAIM_BLIST_NODE_IS_CHAT(node)) {
443 GaimChat *c = (GaimChat*) node;
444 GaimPluginProtocolInfo *prpl_info = NULL;
445 type = GAIM_LOG_CHAT;
446 account = c->account;
447 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gaim_find_prpl(gaim_account_get_protocol_id(account)));
448 if (prpl_info && prpl_info->get_chat_name) {
449 name = prpl_info->get_chat_name(c->components);
450 }
451 } else if (GAIM_BLIST_NODE_IS_CONTACT(node)) {
452 gaim_gtk_log_show_contact((GaimContact *)node);
453 gaim_gtk_clear_cursor(gtkblist->window);
454 return;
455 } else {
456 gaim_gtk_clear_cursor(gtkblist->window);
457
458 /* This callback should not have been registered for a node
459 * that doesn't match the type of one of the blocks above. */
460 g_return_if_reached();
461 }
462
463 if (name && account) {
464 gaim_gtk_log_show(type, name, account);
465 g_free(name);
466
467 gaim_gtk_clear_cursor(gtkblist->window);
468 }
469 }
470
471 static void gtk_blist_show_systemlog_cb()
472 {
473 gaim_gtk_syslog_show();
474 }
475
476 static void gtk_blist_show_onlinehelp_cb()
477 {
478 gaim_notify_uri(NULL, GAIM_WEBSITE "documentation.php");
479 }
480
481 static void
482 do_join_chat(GaimGtkJoinChatData *data)
483 {
484 if (data)
485 {
486 GHashTable *components =
487 g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
488 GList *tmp;
489 GaimChat *chat;
490
491 for (tmp = data->entries; tmp != NULL; tmp = tmp->next)
492 {
493 if (g_object_get_data(tmp->data, "is_spin"))
494 {
495 g_hash_table_replace(components,
496 g_strdup(g_object_get_data(tmp->data, "identifier")),
497 g_strdup_printf("%d",
498 gtk_spin_button_get_value_as_int(tmp->data)));
499 }
500 else
501 {
502 g_hash_table_replace(components,
503 g_strdup(g_object_get_data(tmp->data, "identifier")),
504 g_strdup(gtk_entry_get_text(tmp->data)));
505 }
506 }
507
508 chat = gaim_chat_new(data->account, NULL, components);
509 gtk_blist_join_chat(chat);
510 gaim_blist_remove_chat(chat);
511 }
512 }
513
514 static void
515 do_joinchat(GtkWidget *dialog, int id, GaimGtkJoinChatData *info)
516 {
517 switch(id)
518 {
519 case GTK_RESPONSE_OK:
520 do_join_chat(info);
521
522 break;
523 }
524
525 gtk_widget_destroy(GTK_WIDGET(dialog));
526 g_list_free(info->entries);
527 g_free(info);
528 }
529
530 /*
531 * Check the values of all the text entry boxes. If any required input
532 * strings are empty then don't allow the user to click on "OK."
533 */
534 static void
535 joinchat_set_sensitive_if_input_cb(GtkWidget *entry, gpointer user_data)
536 {
537 GaimGtkJoinChatData *data;
538 GList *tmp;
539 const char *text;
540 gboolean required;
541 gboolean sensitive = TRUE;
542
543 data = user_data;
544
545 for (tmp = data->entries; tmp != NULL; tmp = tmp->next)
546 {
547 if (!g_object_get_data(tmp->data, "is_spin"))
548 {
549 required = GPOINTER_TO_INT(g_object_get_data(tmp->data, "required"));
550 text = gtk_entry_get_text(tmp->data);
551 if (required && (*text == '\0'))
552 sensitive = FALSE;
553 }
554 }
555
556 gtk_dialog_set_response_sensitive(GTK_DIALOG(data->window), GTK_RESPONSE_OK, sensitive);
557 }
558
559 static void
560 gaim_gtk_blist_update_privacy_cb(GaimBuddy *buddy)
561 {
562 gaim_gtk_blist_update_buddy(gaim_get_blist(), (GaimBlistNode*)(buddy), TRUE);
563 }
564
565 static void
566 rebuild_joinchat_entries(GaimGtkJoinChatData *data)
567 {
568 GaimConnection *gc;
569 GList *list = NULL, *tmp;
570 GHashTable *defaults = NULL;
571 struct proto_chat_entry *pce;
572 gboolean focus = TRUE;
573
574 g_return_if_fail(data->account != NULL);
575
576 gc = gaim_account_get_connection(data->account);
577
578 while ((tmp = gtk_container_get_children(GTK_CONTAINER(data->entries_box))))
579 gtk_widget_destroy(tmp->data);
580
581 g_list_free(data->entries);
582 data->entries = NULL;
583
584 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info != NULL)
585 list = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info(gc);
586
587 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults != NULL)
588 defaults = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, NULL);
589
590 for (tmp = list; tmp; tmp = tmp->next)
591 {
592 GtkWidget *label;
593 GtkWidget *rowbox;
594 GtkWidget *input;
595
596 pce = tmp->data;
597
598 rowbox = gtk_hbox_new(FALSE, GAIM_HIG_BORDER);
599 gtk_box_pack_start(GTK_BOX(data->entries_box), rowbox, FALSE, FALSE, 0);
600
601 label = gtk_label_new_with_mnemonic(pce->label);
602 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
603 gtk_size_group_add_widget(data->sg, label);
604 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0);
605
606 if (pce->is_int)
607 {
608 GtkObject *adjust;
609 adjust = gtk_adjustment_new(pce->min, pce->min, pce->max,
610 1, 10, 10);
611 input = gtk_spin_button_new(GTK_ADJUSTMENT(adjust), 1, 0);
612 gtk_widget_set_size_request(input, 50, -1);
613 gtk_box_pack_end(GTK_BOX(rowbox), input, FALSE, FALSE, 0);
614 }
615 else
616 {
617 char *value;
618 input = gtk_entry_new();
619 gtk_entry_set_activates_default(GTK_ENTRY(input), TRUE);
620 value = g_hash_table_lookup(defaults, pce->identifier);
621 if (value != NULL)
622 gtk_entry_set_text(GTK_ENTRY(input), value);
623 if (pce->secret)
624 {
625 gtk_entry_set_visibility(GTK_ENTRY(input), FALSE);
626 if (gtk_entry_get_invisible_char(GTK_ENTRY(input)) == '*')
627 gtk_entry_set_invisible_char(GTK_ENTRY(input), GAIM_INVISIBLE_CHAR);
628 }
629 gtk_box_pack_end(GTK_BOX(rowbox), input, TRUE, TRUE, 0);
630 g_signal_connect(G_OBJECT(input), "changed",
631 G_CALLBACK(joinchat_set_sensitive_if_input_cb), data);
632 }
633
634 /* Do the following for any type of input widget */
635 if (focus)
636 {
637 gtk_widget_grab_focus(input);
638 focus = FALSE;
639 }
640 gtk_label_set_mnemonic_widget(GTK_LABEL(label), input);
641 gaim_set_accessible_label(input, label);
642 g_object_set_data(G_OBJECT(input), "identifier", (gpointer)pce->identifier);
643 g_object_set_data(G_OBJECT(input), "is_spin", GINT_TO_POINTER(pce->is_int));
644 g_object_set_data(G_OBJECT(input), "required", GINT_TO_POINTER(pce->required));
645 data->entries = g_list_append(data->entries, input);
646
647 g_free(pce);
648 }
649
650 g_list_free(list);
651 g_hash_table_destroy(defaults);
652
653 /* Set whether the "OK" button should be clickable initially */
654 joinchat_set_sensitive_if_input_cb(NULL, data);
655
656 gtk_widget_show_all(data->entries_box);
657 }
658
659 static void
660 joinchat_select_account_cb(GObject *w, GaimAccount *account,
661 GaimGtkJoinChatData *data)
662 {
663 data->account = account;
664 rebuild_joinchat_entries(data);
665 }
666
667 static gboolean
668 chat_account_filter_func(GaimAccount *account)
669 {
670 GaimConnection *gc = gaim_account_get_connection(account);
671 GaimPluginProtocolInfo *prpl_info = NULL;
672
673 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
674
675 return (prpl_info->chat_info != NULL);
676 }
677
678 gboolean
679 gaim_gtk_blist_joinchat_is_showable()
680 {
681 GList *c;
682 GaimConnection *gc;
683
684 for (c = gaim_connections_get_all(); c != NULL; c = c->next) {
685 gc = c->data;
686
687 if (chat_account_filter_func(gaim_connection_get_account(gc)))
688 return TRUE;
689 }
690
691 return FALSE;
692 }
693
694 void
695 gaim_gtk_blist_joinchat_show(void)
696 {
697 GtkWidget *hbox, *vbox;
698 GtkWidget *rowbox;
699 GtkWidget *label;
700 GaimGtkBuddyList *gtkblist;
701 GtkWidget *img = NULL;
702 GaimGtkJoinChatData *data = NULL;
703
704 gtkblist = GAIM_GTK_BLIST(gaim_get_blist());
705 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION,
706 GTK_ICON_SIZE_DIALOG);
707 data = g_new0(GaimGtkJoinChatData, 1);
708
709 data->window = gtk_dialog_new_with_buttons(_("Join a Chat"),
710 NULL, GTK_DIALOG_NO_SEPARATOR,
711 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
712 GAIM_STOCK_CHAT, GTK_RESPONSE_OK, NULL);
713 gtk_dialog_set_default_response(GTK_DIALOG(data->window), GTK_RESPONSE_OK);
714 gtk_container_set_border_width(GTK_CONTAINER(data->window), GAIM_HIG_BOX_SPACE);
715 gtk_window_set_resizable(GTK_WINDOW(data->window), FALSE);
716 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(data->window)->vbox), GAIM_HIG_BORDER);
717 gtk_container_set_border_width(
718 GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), GAIM_HIG_BOX_SPACE);
719 gtk_window_set_role(GTK_WINDOW(data->window), "join_chat");
720
721 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BORDER);
722 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), hbox);
723 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
724 gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
725
726 vbox = gtk_vbox_new(FALSE, 5);
727 gtk_container_set_border_width(GTK_CONTAINER(vbox), 0);
728 gtk_container_add(GTK_CONTAINER(hbox), vbox);
729
730 label = gtk_label_new(_("Please enter the appropriate information "
731 "about the chat you would like to join.\n"));
732 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
733 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
734 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
735
736 rowbox = gtk_hbox_new(FALSE, GAIM_HIG_BORDER);
737 gtk_box_pack_start(GTK_BOX(vbox), rowbox, TRUE, TRUE, 0);
738
739 data->sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
740
741 label = gtk_label_new_with_mnemonic(_("_Account:"));
742 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
743 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0);
744 gtk_size_group_add_widget(data->sg, label);
745
746 data->account_menu = gaim_gtk_account_option_menu_new(NULL, FALSE,
747 G_CALLBACK(joinchat_select_account_cb),
748 chat_account_filter_func, data);
749 gtk_box_pack_start(GTK_BOX(rowbox), data->account_menu, TRUE, TRUE, 0);
750 gtk_label_set_mnemonic_widget(GTK_LABEL(label),
751 GTK_WIDGET(data->account_menu));
752 gaim_set_accessible_label (data->account_menu, label);
753
754 data->entries_box = gtk_vbox_new(FALSE, 5);
755 gtk_container_add(GTK_CONTAINER(vbox), data->entries_box);
756 gtk_container_set_border_width(GTK_CONTAINER(data->entries_box), 0);
757
758 data->account = gaim_gtk_account_option_menu_get_selected(data->account_menu);
759
760 rebuild_joinchat_entries(data);
761
762 g_signal_connect(G_OBJECT(data->window), "response",
763 G_CALLBACK(do_joinchat), data);
764
765 g_object_unref(data->sg);
766
767 gtk_widget_show_all(data->window);
768 }
769
770 static void gtk_blist_row_expanded_cb(GtkTreeView *tv, GtkTreeIter *iter, GtkTreePath *path, gpointer user_data) {
771 GaimBlistNode *node;
772 GValue val;
773
774 val.g_type = 0;
775 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), iter, NODE_COLUMN, &val);
776
777 node = g_value_get_pointer(&val);
778
779 if (GAIM_BLIST_NODE_IS_GROUP(node)) {
780 char *title;
781
782 title = gaim_get_group_title(node, TRUE);
783
784 gtk_tree_store_set(gtkblist->treemodel, iter,
785 NAME_COLUMN, title,
786 -1);
787
788 g_free(title);
789
790 gaim_blist_node_set_bool(node, "collapsed", FALSE);
791 }
792 }
793
794 static void gtk_blist_row_collapsed_cb(GtkTreeView *tv, GtkTreeIter *iter, GtkTreePath *path, gpointer user_data) {
795 GaimBlistNode *node;
796 GValue val;
797
798 val.g_type = 0;
799 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), iter, NODE_COLUMN, &val);
800
801 node = g_value_get_pointer(&val);
802
803 if (GAIM_BLIST_NODE_IS_GROUP(node)) {
804 char *title;
805
806 title = gaim_get_group_title(node, FALSE);
807
808 gtk_tree_store_set(gtkblist->treemodel, iter,
809 NAME_COLUMN, title,
810 -1);
811
812 g_free(title);
813
814 gaim_blist_node_set_bool(node, "collapsed", TRUE);
815 } else if(GAIM_BLIST_NODE_IS_CONTACT(node)) {
816 gaim_gtk_blist_collapse_contact_cb(NULL, node);
817 }
818 }
819
820 static void gtk_blist_row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) {
821 GaimBlistNode *node;
822 GtkTreeIter iter;
823 GValue val;
824
825 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path);
826
827 val.g_type = 0;
828 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val);
829 node = g_value_get_pointer(&val);
830
831 if(GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_BUDDY(node)) {
832 GaimBuddy *buddy;
833
834 if(GAIM_BLIST_NODE_IS_CONTACT(node))
835 buddy = gaim_contact_get_priority_buddy((GaimContact*)node);
836 else
837 buddy = (GaimBuddy*)node;
838
839 gaim_gtkdialogs_im_with_user(buddy->account, buddy->name);
840 } else if (GAIM_BLIST_NODE_IS_CHAT(node)) {
841 gtk_blist_join_chat((GaimChat *)node);
842 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) {
843 /* if (gtk_tree_view_row_expanded(tv, path))
844 gtk_tree_view_collapse_row(tv, path);
845 else
846 gtk_tree_view_expand_row(tv,path,FALSE);*/
847 }
848 }
849
850 static void gaim_gtk_blist_add_chat_cb()
851 {
852 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview));
853 GtkTreeIter iter;
854 GaimBlistNode *node;
855
856 if(gtk_tree_selection_get_selected(sel, NULL, &iter)){
857 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1);
858 if (GAIM_BLIST_NODE_IS_BUDDY(node))
859 gaim_blist_request_add_chat(NULL, (GaimGroup*)node->parent->parent, NULL, NULL);
860 if (GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_CHAT(node))
861 gaim_blist_request_add_chat(NULL, (GaimGroup*)node->parent, NULL, NULL);
862 else if (GAIM_BLIST_NODE_IS_GROUP(node))
863 gaim_blist_request_add_chat(NULL, (GaimGroup*)node, NULL, NULL);
864 }
865 else {
866 gaim_blist_request_add_chat(NULL, NULL, NULL, NULL);
867 }
868 }
869
870 static void gaim_gtk_blist_add_buddy_cb()
871 {
872 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview));
873 GtkTreeIter iter;
874 GaimBlistNode *node;
875
876 if(gtk_tree_selection_get_selected(sel, NULL, &iter)){
877 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1);
878 if (GAIM_BLIST_NODE_IS_BUDDY(node)) {
879 gaim_blist_request_add_buddy(NULL, NULL, ((GaimGroup*)node->parent->parent)->name,
880 NULL);
881 } else if (GAIM_BLIST_NODE_IS_CONTACT(node)
882 || GAIM_BLIST_NODE_IS_CHAT(node)) {
883 gaim_blist_request_add_buddy(NULL, NULL, ((GaimGroup*)node->parent)->name, NULL);
884 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) {
885 gaim_blist_request_add_buddy(NULL, NULL, ((GaimGroup*)node)->name, NULL);
886 }
887 }
888 else {
889 gaim_blist_request_add_buddy(NULL, NULL, NULL, NULL);
890 }
891 }
892
893 static void
894 gaim_gtk_blist_remove_cb (GtkWidget *w, GaimBlistNode *node)
895 {
896 if (GAIM_BLIST_NODE_IS_BUDDY(node)) {
897 gaim_gtkdialogs_remove_buddy((GaimBuddy*)node);
898 } else if (GAIM_BLIST_NODE_IS_CHAT(node)) {
899 gaim_gtkdialogs_remove_chat((GaimChat*)node);
900 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) {
901 gaim_gtkdialogs_remove_group((GaimGroup*)node);
902 } else if (GAIM_BLIST_NODE_IS_CONTACT(node)) {
903 gaim_gtkdialogs_remove_contact((GaimContact*)node);
904 }
905 }
906
907 struct _expand {
908 GtkTreeView *treeview;
909 GtkTreePath *path;
910 GaimBlistNode *node;
911 };
912
913 static gboolean
914 scroll_to_expanded_cell(gpointer data)
915 {
916 struct _expand *ex = data;
917 gtk_tree_view_scroll_to_cell(ex->treeview, ex->path, NULL, FALSE, 0, 0);
918 gaim_gtk_blist_update_contact(NULL, ex->node);
919
920 gtk_tree_path_free(ex->path);
921 g_free(ex);
922
923 return FALSE;
924 }
925
926 static void
927 gaim_gtk_blist_expand_contact_cb(GtkWidget *w, GaimBlistNode *node)
928 {
929 struct _gaim_gtk_blist_node *gtknode;
930 GtkTreeIter iter, parent;
931 GaimBlistNode *bnode;
932 GtkTreePath *path;
933
934 if(!GAIM_BLIST_NODE_IS_CONTACT(node))
935 return;
936
937 gtknode = (struct _gaim_gtk_blist_node *)node->ui_data;
938
939 gtknode->contact_expanded = TRUE;
940
941 for(bnode = node->child; bnode; bnode = bnode->next) {
942 gaim_gtk_blist_update(NULL, bnode);
943 }
944
945 /* This ensures that the bottom buddy is visible, i.e. not scrolled off the alignment */
946 if (get_iter_from_node(node, &parent)) {
947 struct _expand *ex = g_new0(struct _expand, 1);
948
949 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(gtkblist->treemodel), &iter, &parent,
950 gtk_tree_model_iter_n_children(GTK_TREE_MODEL(gtkblist->treemodel), &parent) -1);
951 path = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &iter);
952
953 /* Let the treeview draw so it knows where to scroll */
954 ex->treeview = GTK_TREE_VIEW(gtkblist->treeview);
955 ex->path = path;
956 ex->node = node->child;
957 g_idle_add(scroll_to_expanded_cell, ex);
958 }
959 }
960
961 static void
962 gaim_gtk_blist_collapse_contact_cb(GtkWidget *w, GaimBlistNode *node)
963 {
964 GaimBlistNode *bnode;
965 struct _gaim_gtk_blist_node *gtknode;
966
967 if(!GAIM_BLIST_NODE_IS_CONTACT(node))
968 return;
969
970 gtknode = (struct _gaim_gtk_blist_node *)node->ui_data;
971
972 gtknode->contact_expanded = FALSE;
973
974 for(bnode = node->child; bnode; bnode = bnode->next) {
975 gaim_gtk_blist_update(NULL, bnode);
976 }
977 }
978
979 static void
980 toggle_privacy(GtkWidget *widget, GaimBlistNode *node)
981 {
982 GaimBuddy *buddy;
983 GaimAccount *account;
984 gboolean permitted;
985 const char *name;
986
987 if (!GAIM_BLIST_NODE_IS_BUDDY(node))
988 return;
989
990 buddy = (GaimBuddy *)node;
991 account = gaim_buddy_get_account(buddy);
992 name = gaim_buddy_get_name(buddy);
993
994 permitted = gaim_privacy_check(account, name);
995
996 /* XXX: Perhaps ask whether to restore the previous lists where appropirate? */
997
998 if (permitted)
999 gaim_privacy_deny(account, name, FALSE, FALSE);
1000 else
1001 gaim_privacy_allow(account, name, FALSE, FALSE);
1002
1003 gaim_gtk_blist_update(gaim_get_blist(), node);
1004 }
1005
1006 void gaim_gtk_append_blist_node_privacy_menu(GtkWidget *menu, GaimBlistNode *node)
1007 {
1008 GaimBuddy *buddy = (GaimBuddy *)node;
1009 GaimAccount *account;
1010 gboolean permitted;
1011
1012 account = gaim_buddy_get_account(buddy);
1013 permitted = gaim_privacy_check(account, gaim_buddy_get_name(buddy));
1014
1015 gaim_new_item_from_stock(menu, permitted ? _("_Block") : _("Un_block"),
1016 GTK_STOCK_DIALOG_ERROR, G_CALLBACK(toggle_privacy),
1017 node, 0 ,0, NULL);
1018 }
1019
1020 void
1021 gaim_gtk_append_blist_node_proto_menu(GtkWidget *menu, GaimConnection *gc,
1022 GaimBlistNode *node)
1023 {
1024 GList *l, *ll;
1025 GaimPluginProtocolInfo *prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
1026
1027 if(!prpl_info || !prpl_info->blist_node_menu)
1028 return;
1029
1030 for(l = ll = prpl_info->blist_node_menu(node); l; l = l->next) {
1031 GaimMenuAction *act = (GaimMenuAction *) l->data;
1032 gaim_gtk_append_menu_action(menu, act, node);
1033 }
1034 g_list_free(ll);
1035 }
1036
1037 void
1038 gaim_gtk_append_blist_node_extended_menu(GtkWidget *menu, GaimBlistNode *node)
1039 {
1040 GList *l, *ll;
1041
1042 for(l = ll = gaim_blist_node_get_extended_menu(node); l; l = l->next) {
1043 GaimMenuAction *act = (GaimMenuAction *) l->data;
1044 gaim_gtk_append_menu_action(menu, act, node);
1045 }
1046 g_list_free(ll);
1047 }
1048
1049 void
1050 gaim_gtk_blist_make_buddy_menu(GtkWidget *menu, GaimBuddy *buddy, gboolean sub) {
1051 GaimPluginProtocolInfo *prpl_info;
1052 GaimContact *contact;
1053 gboolean contact_expanded = FALSE;
1054
1055 g_return_if_fail(menu);
1056 g_return_if_fail(buddy);
1057
1058 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(buddy->account->gc->prpl);
1059
1060 contact = gaim_buddy_get_contact(buddy);
1061 if (contact) {
1062 contact_expanded = ((struct _gaim_gtk_blist_node *)(((GaimBlistNode*)contact)->ui_data))->contact_expanded;
1063 }
1064
1065 if (prpl_info && prpl_info->get_info) {
1066 gaim_new_item_from_stock(menu, _("Get _Info"), GAIM_STOCK_INFO,
1067 G_CALLBACK(gtk_blist_menu_info_cb), buddy, 0, 0, NULL);
1068 }
1069 gaim_new_item_from_stock(menu, _("I_M"), GAIM_STOCK_IM,
1070 G_CALLBACK(gtk_blist_menu_im_cb), buddy, 0, 0, NULL);
1071 if (prpl_info && prpl_info->send_file) {
1072 if (!prpl_info->can_receive_file ||
1073 prpl_info->can_receive_file(buddy->account->gc, buddy->name))
1074 {
1075 gaim_new_item_from_stock(menu, _("_Send File"),
1076 GAIM_STOCK_FILE_TRANSFER,
1077 G_CALLBACK(gtk_blist_menu_send_file_cb),
1078 buddy, 0, 0, NULL);
1079 }
1080 }
1081
1082 gaim_new_item_from_stock(menu, _("Add Buddy _Pounce"), GAIM_STOCK_POUNCE,
1083 G_CALLBACK(gtk_blist_menu_bp_cb), buddy, 0, 0, NULL);
1084
1085 if(((GaimBlistNode*)buddy)->parent->child->next && !sub && !contact_expanded) {
1086 gaim_new_item_from_stock(menu, _("View _Log"), GAIM_STOCK_LOG,
1087 G_CALLBACK(gtk_blist_menu_showlog_cb),
1088 contact, 0, 0, NULL);
1089 } else if (!sub) {
1090 gaim_new_item_from_stock(menu, _("View _Log"), GAIM_STOCK_LOG,
1091 G_CALLBACK(gtk_blist_menu_showlog_cb), buddy, 0, 0, NULL);
1092 }
1093
1094 gaim_gtk_append_blist_node_privacy_menu(menu, (GaimBlistNode *)buddy);
1095
1096 gaim_gtk_append_blist_node_proto_menu(menu, buddy->account->gc,
1097 (GaimBlistNode *)buddy);
1098 gaim_gtk_append_blist_node_extended_menu(menu, (GaimBlistNode *)buddy);
1099
1100 if (((GaimBlistNode*)buddy)->parent->child->next && !sub && !contact_expanded) {
1101 gaim_separator(menu);
1102
1103 gaim_new_item_from_stock(menu, _("Alias..."), GAIM_STOCK_ALIAS,
1104 G_CALLBACK(gtk_blist_menu_alias_cb),
1105 contact, 0, 0, NULL);
1106 gaim_new_item_from_stock(menu, _("Remove"), GTK_STOCK_REMOVE,
1107 G_CALLBACK(gaim_gtk_blist_remove_cb),
1108 contact, 0, 0, NULL);
1109 } else if (!sub || contact_expanded) {
1110 gaim_separator(menu);
1111
1112 gaim_new_item_from_stock(menu, _("_Alias..."), GAIM_STOCK_ALIAS,
1113 G_CALLBACK(gtk_blist_menu_alias_cb), buddy, 0, 0, NULL);
1114 gaim_new_item_from_stock(menu, _("_Remove"), GTK_STOCK_REMOVE,
1115 G_CALLBACK(gaim_gtk_blist_remove_cb), buddy,
1116 0, 0, NULL);
1117 }
1118 }
1119
1120 static gboolean
1121 gtk_blist_key_press_cb(GtkWidget *tv, GdkEventKey *event, gpointer data) {
1122 GaimBlistNode *node;
1123 GValue val;
1124 GtkTreeIter iter;
1125 GtkTreeSelection *sel;
1126
1127 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv));
1128 if(!gtk_tree_selection_get_selected(sel, NULL, &iter))
1129 return FALSE;
1130
1131 val.g_type = 0;
1132 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), &iter,
1133 NODE_COLUMN, &val);
1134 node = g_value_get_pointer(&val);
1135
1136 if(event->state & GDK_CONTROL_MASK &&
1137 (event->keyval == 'o' || event->keyval == 'O')) {
1138 GaimBuddy *buddy;
1139
1140 if(GAIM_BLIST_NODE_IS_CONTACT(node)) {
1141 buddy = gaim_contact_get_priority_buddy((GaimContact*)node);
1142 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) {
1143 buddy = (GaimBuddy*)node;
1144 } else {
1145 return FALSE;
1146 }
1147 if(buddy)
1148 serv_get_info(buddy->account->gc, buddy->name);
1149 }
1150
1151 return FALSE;
1152 }
1153
1154 static GtkWidget *
1155 create_group_menu (GaimBlistNode *node, GaimGroup *g)
1156 {
1157 GtkWidget *menu;
1158 GtkWidget *item;
1159
1160 menu = gtk_menu_new();
1161 gaim_new_item_from_stock(menu, _("Add a _Buddy"), GTK_STOCK_ADD,
1162 G_CALLBACK(gaim_gtk_blist_add_buddy_cb), node, 0, 0, NULL);
1163 item = gaim_new_item_from_stock(menu, _("Add a C_hat"), GTK_STOCK_ADD,
1164 G_CALLBACK(gaim_gtk_blist_add_chat_cb), node, 0, 0, NULL);
1165 gtk_widget_set_sensitive(item, gaim_gtk_blist_joinchat_is_showable());
1166 gaim_new_item_from_stock(menu, _("_Delete Group"), GTK_STOCK_REMOVE,
1167 G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL);
1168 gaim_new_item_from_stock(menu, _("_Rename"), NULL,
1169 G_CALLBACK(gtk_blist_menu_alias_cb), node, 0, 0, NULL);
1170
1171 gaim_gtk_append_blist_node_extended_menu(menu, node);
1172
1173 return menu;
1174 }
1175
1176
1177 static GtkWidget *
1178 create_chat_menu(GaimBlistNode *node, GaimChat *c) {
1179 GtkWidget *menu;
1180 gboolean autojoin;
1181
1182 menu = gtk_menu_new();
1183 autojoin = (gaim_blist_node_get_bool(node, "gtk-autojoin") ||
1184 (gaim_blist_node_get_string(node, "gtk-autojoin") != NULL));
1185
1186 gaim_new_item_from_stock(menu, _("_Join"), GAIM_STOCK_CHAT,
1187 G_CALLBACK(gtk_blist_menu_join_cb), node, 0, 0, NULL);
1188 gaim_new_check_item(menu, _("Auto-Join"),
1189 G_CALLBACK(gtk_blist_menu_autojoin_cb), node, autojoin);
1190 gaim_new_item_from_stock(menu, _("View _Log"), GAIM_STOCK_LOG,
1191 G_CALLBACK(gtk_blist_menu_showlog_cb), node, 0, 0, NULL);
1192
1193 gaim_gtk_append_blist_node_proto_menu(menu, c->account->gc, node);
1194 gaim_gtk_append_blist_node_extended_menu(menu, node);
1195
1196 gaim_separator(menu);
1197
1198 gaim_new_item_from_stock(menu, _("_Alias..."), GAIM_STOCK_ALIAS,
1199 G_CALLBACK(gtk_blist_menu_alias_cb), node, 0, 0, NULL);
1200 gaim_new_item_from_stock(menu, _("_Remove"), GTK_STOCK_REMOVE,
1201 G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL);
1202
1203 return menu;
1204 }
1205
1206 static GtkWidget *
1207 create_contact_menu (GaimBlistNode *node)
1208 {
1209 GtkWidget *menu;
1210
1211 menu = gtk_menu_new();
1212
1213 gaim_new_item_from_stock(menu, _("View _Log"), GAIM_STOCK_LOG,
1214 G_CALLBACK(gtk_blist_menu_showlog_cb),
1215 node, 0, 0, NULL);
1216
1217 gaim_separator(menu);
1218
1219 gaim_new_item_from_stock(menu, _("_Alias..."), GAIM_STOCK_ALIAS,
1220 G_CALLBACK(gtk_blist_menu_alias_cb), node, 0, 0, NULL);
1221 gaim_new_item_from_stock(menu, _("_Remove"), GTK_STOCK_REMOVE,
1222 G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL);
1223
1224 gaim_separator(menu);
1225
1226 gaim_new_item_from_stock(menu, _("_Collapse"), GTK_STOCK_ZOOM_OUT,
1227 G_CALLBACK(gaim_gtk_blist_collapse_contact_cb),
1228 node, 0, 0, NULL);
1229
1230 gaim_gtk_append_blist_node_extended_menu(menu, node);
1231
1232 return menu;
1233 }
1234
1235 static GtkWidget *
1236 create_buddy_menu(GaimBlistNode *node, GaimBuddy *b) {
1237 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data;
1238 GtkWidget *menu;
1239 GtkWidget *menuitem;
1240 gboolean show_offline = gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies");
1241
1242 menu = gtk_menu_new();
1243 gaim_gtk_blist_make_buddy_menu(menu, b, FALSE);
1244
1245 if(GAIM_BLIST_NODE_IS_CONTACT(node)) {
1246 gaim_separator(menu);
1247
1248 if(gtknode->contact_expanded) {
1249 gaim_new_item_from_stock(menu, _("_Collapse"),
1250 GTK_STOCK_ZOOM_OUT,
1251 G_CALLBACK(gaim_gtk_blist_collapse_contact_cb),
1252 node, 0, 0, NULL);
1253 } else {
1254 gaim_new_item_from_stock(menu, _("_Expand"),
1255 GTK_STOCK_ZOOM_IN,
1256 G_CALLBACK(gaim_gtk_blist_expand_contact_cb), node,
1257 0, 0, NULL);
1258 }
1259 if(node->child->next) {
1260 GaimBlistNode *bnode;
1261
1262 for(bnode = node->child; bnode; bnode = bnode->next) {
1263 GaimBuddy *buddy = (GaimBuddy*)bnode;
1264 GdkPixbuf *buf;
1265 GtkWidget *submenu;
1266 GtkWidget *image;
1267
1268 if(buddy == b)
1269 continue;
1270 if(!buddy->account->gc)
1271 continue;
1272 if(!show_offline && !GAIM_BUDDY_IS_ONLINE(buddy))
1273 continue;
1274
1275 menuitem = gtk_image_menu_item_new_with_label(buddy->name);
1276 buf = gaim_gtk_blist_get_status_icon(bnode,
1277 GAIM_STATUS_ICON_SMALL);
1278 image = gtk_image_new_from_pixbuf(buf);
1279 g_object_unref(G_OBJECT(buf));
1280 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem),
1281 image);
1282 gtk_widget_show(image);
1283 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
1284 gtk_widget_show(menuitem);
1285
1286 submenu = gtk_menu_new();
1287 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu);
1288 gtk_widget_show(submenu);
1289
1290 gaim_gtk_blist_make_buddy_menu(submenu, buddy, TRUE);
1291 }
1292 }
1293 }
1294 return menu;
1295 }
1296
1297 static gboolean
1298 gaim_gtk_blist_show_context_menu(GaimBlistNode *node,
1299 GtkMenuPositionFunc func,
1300 GtkWidget *tv,
1301 guint button,
1302 guint32 time)
1303 {
1304 struct _gaim_gtk_blist_node *gtknode;
1305 GtkWidget *menu = NULL;
1306 gboolean handled = FALSE;
1307
1308 gtknode = (struct _gaim_gtk_blist_node *)node->ui_data;
1309
1310 /* Create a menu based on the thing we right-clicked on */
1311 if (GAIM_BLIST_NODE_IS_GROUP(node)) {
1312 GaimGroup *g = (GaimGroup *)node;
1313
1314 menu = create_group_menu(node, g);
1315 } else if (GAIM_BLIST_NODE_IS_CHAT(node)) {
1316 GaimChat *c = (GaimChat *)node;
1317
1318 menu = create_chat_menu(node, c);
1319 } else if ((GAIM_BLIST_NODE_IS_CONTACT(node)) && (gtknode->contact_expanded)) {
1320 menu = create_contact_menu(node);
1321 } else if (GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_BUDDY(node)) {
1322 GaimBuddy *b;
1323
1324 if (GAIM_BLIST_NODE_IS_CONTACT(node))
1325 b = gaim_contact_get_priority_buddy((GaimContact*)node);
1326 else
1327 b = (GaimBuddy *)node;
1328
1329 menu = create_buddy_menu(node, b);
1330 }
1331
1332 #ifdef _WIN32
1333 /* Unhook the tooltip-timeout since we don't want a tooltip
1334 * to appear and obscure the context menu we are about to show
1335 This is a workaround for GTK+ bug 107320. */
1336 if (gtkblist->timeout) {
1337 g_source_remove(gtkblist->timeout);
1338 gtkblist->timeout = 0;
1339 }
1340 #endif
1341
1342 /* Now display the menu */
1343 if (menu != NULL) {
1344 gtk_widget_show_all(menu);
1345 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, func, tv, button, time);
1346 handled = TRUE;
1347 }
1348
1349 return handled;
1350 }
1351
1352 static gboolean gtk_blist_button_press_cb(GtkWidget *tv, GdkEventButton *event, gpointer user_data)
1353 {
1354 GtkTreePath *path;
1355 GaimBlistNode *node;
1356 GValue val;
1357 GtkTreeIter iter;
1358 GtkTreeSelection *sel;
1359 GaimPlugin *prpl = NULL;
1360 GaimPluginProtocolInfo *prpl_info = NULL;
1361 struct _gaim_gtk_blist_node *gtknode;
1362 gboolean handled = FALSE;
1363
1364 /* Here we figure out which node was clicked */
1365 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL))
1366 return FALSE;
1367 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path);
1368 val.g_type = 0;
1369 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val);
1370 node = g_value_get_pointer(&val);
1371 gtknode = (struct _gaim_gtk_blist_node *)node->ui_data;
1372
1373 /* Right click draws a context menu */
1374 if ((event->button == 3) && (event->type == GDK_BUTTON_PRESS)) {
1375 handled = gaim_gtk_blist_show_context_menu(node, NULL, tv, 3, event->time);
1376
1377 /* CTRL+middle click expands or collapse a contact */
1378 } else if ((event->button == 2) && (event->type == GDK_BUTTON_PRESS) &&
1379 (event->state & GDK_CONTROL_MASK) && (GAIM_BLIST_NODE_IS_CONTACT(node))) {
1380 if (gtknode->contact_expanded)
1381 gaim_gtk_blist_collapse_contact_cb(NULL, node);
1382 else
1383 gaim_gtk_blist_expand_contact_cb(NULL, node);
1384 handled = TRUE;
1385
1386 /* Double middle click gets info */
1387 } else if ((event->button == 2) && (event->type == GDK_2BUTTON_PRESS) &&
1388 ((GAIM_BLIST_NODE_IS_CONTACT(node)) || (GAIM_BLIST_NODE_IS_BUDDY(node)))) {
1389 GaimBuddy *b;
1390 if(GAIM_BLIST_NODE_IS_CONTACT(node))
1391 b = gaim_contact_get_priority_buddy((GaimContact*)node);
1392 else
1393 b = (GaimBuddy *)node;
1394
1395 prpl = gaim_find_prpl(gaim_account_get_protocol_id(b->account));
1396 if (prpl != NULL)
1397 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
1398
1399 if (prpl && prpl_info->get_info)
1400 serv_get_info(b->account->gc, b->name);
1401 handled = TRUE;
1402 }
1403
1404 #if (1)
1405 /*
1406 * This code only exists because GTK+ doesn't work. If we return
1407 * FALSE here, as would be normal the event propoagates down and
1408 * somehow gets interpreted as the start of a drag event.
1409 *
1410 * Um, isn't it _normal_ to return TRUE here? Since the event
1411 * was handled? --Mark
1412 */
1413 if(handled) {
1414 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv));
1415 gtk_tree_selection_select_path(sel, path);
1416 gtk_tree_path_free(path);
1417 return TRUE;
1418 }
1419 #endif
1420 gtk_tree_path_free(path);
1421
1422 return FALSE;
1423 }
1424
1425 static gboolean
1426 gaim_gtk_blist_popup_menu_cb(GtkWidget *tv, void *user_data)
1427 {
1428 GaimBlistNode *node;
1429 GValue val;
1430 GtkTreeIter iter;
1431 GtkTreeSelection *sel;
1432 gboolean handled = FALSE;
1433
1434 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv));
1435 if (!gtk_tree_selection_get_selected(sel, NULL, &iter))
1436 return FALSE;
1437
1438 val.g_type = 0;
1439 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel),
1440 &iter, NODE_COLUMN, &val);
1441 node = g_value_get_pointer(&val);
1442
1443 /* Shift+F10 draws a context menu */
1444 handled = gaim_gtk_blist_show_context_menu(node, gaim_gtk_treeview_popup_menu_position_func, tv, 0, GDK_CURRENT_TIME);
1445
1446 return handled;
1447 }
1448
1449 static void gaim_gtk_blist_buddy_details_cb(gpointer data, guint action, GtkWidget *item)
1450 {
1451 gaim_gtk_set_cursor(gtkblist->window, GDK_WATCH);
1452
1453 gaim_prefs_set_bool("/gaim/gtk/blist/show_buddy_icons",
1454 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item)));
1455
1456 gaim_gtk_clear_cursor(gtkblist->window);
1457 }
1458
1459 static void gaim_gtk_blist_show_idle_time_cb(gpointer data, guint action, GtkWidget *item)
1460 {
1461 gaim_gtk_set_cursor(gtkblist->window, GDK_WATCH);
1462
1463 gaim_prefs_set_bool("/gaim/gtk/blist/show_idle_time",
1464 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item)));
1465
1466 gaim_gtk_clear_cursor(gtkblist->window);
1467 }
1468
1469 static void gaim_gtk_blist_show_empty_groups_cb(gpointer data, guint action, GtkWidget *item)
1470 {
1471 gaim_gtk_set_cursor(gtkblist->window, GDK_WATCH);
1472
1473 gaim_prefs_set_bool("/gaim/gtk/blist/show_empty_groups",
1474 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item)));
1475
1476 gaim_gtk_clear_cursor(gtkblist->window);
1477 }
1478
1479 static void gaim_gtk_blist_edit_mode_cb(gpointer callback_data, guint callback_action,
1480 GtkWidget *checkitem)
1481 {
1482 gaim_gtk_set_cursor(gtkblist->window, GDK_WATCH);
1483
1484 gaim_prefs_set_bool("/gaim/gtk/blist/show_offline_buddies",
1485 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(checkitem)));
1486
1487 gaim_gtk_clear_cursor(gtkblist->window);
1488 }
1489
1490 static void gaim_gtk_blist_mute_sounds_cb(gpointer data, guint action, GtkWidget *item)
1491 {
1492 gaim_prefs_set_bool("/gaim/gtk/sound/mute", GTK_CHECK_MENU_ITEM(item)->active);
1493 }
1494
1495 static void
1496 gaim_gtk_blist_mute_pref_cb(const char *name, GaimPrefType type,
1497 gconstpointer value, gpointer data)
1498 {
1499 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(gtkblist->ift,
1500 N_("/Tools/Mute Sounds"))), (gboolean)GPOINTER_TO_INT(value));
1501 }
1502
1503 static void
1504 gaim_gtk_blist_sound_method_pref_cb(const char *name, GaimPrefType type,
1505 gconstpointer value, gpointer data)
1506 {
1507 gboolean sensitive = TRUE;
1508
1509 if(!strcmp(value, "none"))
1510 sensitive = FALSE;
1511
1512 gtk_widget_set_sensitive(gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Mute Sounds")), sensitive);
1513 }
1514
1515 static void
1516 add_buddies_from_vcard(const char *prpl_id, GaimGroup *group, GList *list,
1517 const char *alias)
1518 {
1519 GList *l;
1520 GaimAccount *account = NULL;
1521 GaimConnection *gc;
1522
1523 if (list == NULL)
1524 return;
1525
1526 for (l = gaim_connections_get_all(); l != NULL; l = l->next)
1527 {
1528 gc = (GaimConnection *)l->data;
1529 account = gaim_connection_get_account(gc);
1530
1531 if (!strcmp(gaim_account_get_protocol_id(account), prpl_id))
1532 break;
1533
1534 account = NULL;
1535 }
1536
1537 if (account != NULL)
1538 {
1539 for (l = list; l != NULL; l = l->next)
1540 {
1541 gaim_blist_request_add_buddy(account, l->data,
1542 (group ? group->name : NULL),
1543 alias);
1544 }
1545 }
1546
1547 g_list_foreach(list, (GFunc)g_free, NULL);
1548 g_list_free(list);
1549 }
1550
1551 static gboolean
1552 parse_vcard(const char *vcard, GaimGroup *group)
1553 {
1554 char *temp_vcard;
1555 char *s, *c;
1556 char *alias = NULL;
1557 GList *aims = NULL;
1558 GList *icqs = NULL;
1559 GList *yahoos = NULL;
1560 GList *msns = NULL;
1561 GList *jabbers = NULL;
1562
1563 s = temp_vcard = g_strdup(vcard);
1564
1565 while (*s != '\0' && strncmp(s, "END:vCard", strlen("END:vCard")))
1566 {
1567 char *field, *value;
1568
1569 field = s;
1570
1571 /* Grab the field */
1572 while (*s != '\r' && *s != '\n' && *s != '\0' && *s != ':')
1573 s++;
1574
1575 if (*s == '\r') s++;
1576 if (*s == '\n')
1577 {
1578 s++;
1579 continue;
1580 }
1581
1582 if (*s != '\0') *s++ = '\0';
1583
1584 if ((c = strchr(field, ';')) != NULL)
1585 *c = '\0';
1586
1587 /* Proceed to the end of the line */
1588 value = s;
1589
1590 while (*s != '\r' && *s != '\n' && *s != '\0')
1591 s++;
1592
1593 if (*s == '\r') *s++ = '\0';
1594 if (*s == '\n') *s++ = '\0';
1595
1596 /* We only want to worry about a few fields here. */
1597 if (!strcmp(field, "FN"))
1598 alias = g_strdup(value);
1599 else if (!strcmp(field, "X-AIM") || !strcmp(field, "X-ICQ") ||
1600 !strcmp(field, "X-YAHOO") || !strcmp(field, "X-MSN") ||
1601 !strcmp(field, "X-JABBER"))
1602 {
1603 char **values = g_strsplit(value, ":", 0);
1604 char **im;
1605
1606 for (im = values; *im != NULL; im++)
1607 {
1608 if (!strcmp(field, "X-AIM"))
1609 aims = g_list_append(aims, g_strdup(*im));
1610 else if (!strcmp(field, "X-ICQ"))
1611 icqs = g_list_append(icqs, g_strdup(*im));
1612 else if (!strcmp(field, "X-YAHOO"))
1613 yahoos = g_list_append(yahoos, g_strdup(*im));
1614 else if (!strcmp(field, "X-MSN"))
1615 msns = g_list_append(msns, g_strdup(*im));
1616 else if (!strcmp(field, "X-JABBER"))
1617 jabbers = g_list_append(jabbers, g_strdup(*im));
1618 }
1619
1620 g_strfreev(values);
1621 }
1622 }
1623
1624 g_free(temp_vcard);
1625
1626 if (aims == NULL && icqs == NULL && yahoos == NULL &&
1627 msns == NULL && jabbers == NULL)
1628 {
1629 g_free(alias);
1630
1631 return FALSE;
1632 }
1633
1634 add_buddies_from_vcard("prpl-oscar", group, aims, alias);
1635 add_buddies_from_vcard("prpl-oscar", group, icqs, alias);
1636 add_buddies_from_vcard("prpl-yahoo", group, yahoos, alias);
1637 add_buddies_from_vcard("prpl-msn", group, msns, alias);
1638 add_buddies_from_vcard("prpl-jabber", group, jabbers, alias);
1639
1640 g_free(alias);
1641
1642 return TRUE;
1643 }
1644
1645 #ifdef _WIN32
1646 static void gaim_gtk_blist_drag_begin(GtkWidget *widget,
1647 GdkDragContext *drag_context, gpointer user_data)
1648 {
1649 gaim_gtk_blist_tooltip_destroy();
1650
1651
1652 /* Unhook the tooltip-timeout since we don't want a tooltip
1653 * to appear and obscure the dragging operation.
1654 * This is a workaround for GTK+ bug 107320. */
1655 if (gtkblist->timeout) {
1656 g_source_remove(gtkblist->timeout);
1657 gtkblist->timeout = 0;
1658 }
1659 }
1660 #endif
1661
1662 static void gaim_gtk_blist_drag_data_get_cb(GtkWidget *widget,
1663 GdkDragContext *dc,
1664 GtkSelectionData *data,
1665 guint info,
1666 guint time,
1667 gpointer null)
1668 {
1669
1670 if (data->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE))
1671 {
1672 GtkTreeRowReference *ref = g_object_get_data(G_OBJECT(dc), "gtk-tree-view-source-row");
1673 GtkTreePath *sourcerow = gtk_tree_row_reference_get_path(ref);
1674 GtkTreeIter iter;
1675 GaimBlistNode *node = NULL;
1676 GValue val;
1677 if(!sourcerow)
1678 return;
1679 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, sourcerow);
1680 val.g_type = 0;
1681 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val);
1682 node = g_value_get_pointer(&val);
1683 gtk_selection_data_set (data,
1684 gdk_atom_intern ("GAIM_BLIST_NODE", FALSE),
1685 8, /* bits */
1686 (void*)&node,
1687 sizeof (node));
1688
1689 gtk_tree_path_free(sourcerow);
1690 }
1691 else if (data->target == gdk_atom_intern("application/x-im-contact", FALSE))
1692 {
1693 GtkTreeRowReference *ref;
1694 GtkTreePath *sourcerow;
1695 GtkTreeIter iter;
1696 GaimBlistNode *node = NULL;
1697 GaimBuddy *buddy;
1698 GaimConnection *gc;
1699 GValue val;
1700 GString *str;
1701 const char *protocol;
1702
1703 ref = g_object_get_data(G_OBJECT(dc), "gtk-tree-view-source-row");
1704 sourcerow = gtk_tree_row_reference_get_path(ref);
1705
1706 if (!sourcerow)
1707 return;
1708
1709 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter,
1710 sourcerow);
1711 val.g_type = 0;
1712 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), &iter,
1713 NODE_COLUMN, &val);
1714
1715 node = g_value_get_pointer(&val);
1716
1717 if (GAIM_BLIST_NODE_IS_CONTACT(node))
1718 {
1719 buddy = gaim_contact_get_priority_buddy((GaimContact *)node);
1720 }
1721 else if (!GAIM_BLIST_NODE_IS_BUDDY(node))
1722 {
1723 gtk_tree_path_free(sourcerow);
1724 return;
1725 }
1726 else
1727 {
1728 buddy = (GaimBuddy *)node;
1729 }
1730
1731 gc = gaim_account_get_connection(buddy->account);
1732
1733 if (gc == NULL)
1734 {
1735 gtk_tree_path_free(sourcerow);
1736 return;
1737 }
1738
1739 protocol =
1740 GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->list_icon(buddy->account,
1741 buddy);
1742
1743 str = g_string_new(NULL);
1744 g_string_printf(str,
1745 "MIME-Version: 1.0\r\n"
1746 "Content-Type: application/x-im-contact\r\n"
1747 "X-IM-Protocol: %s\r\n"
1748 "X-IM-Username: %s\r\n",
1749 protocol,
1750 buddy->name);
1751
1752 if (buddy->alias != NULL)
1753 {
1754 g_string_append_printf(str,
1755 "X-IM-Alias: %s\r\n",
1756 buddy->alias);
1757 }
1758
1759 g_string_append(str, "\r\n");
1760
1761 gtk_selection_data_set(data,
1762 gdk_atom_intern("application/x-im-contact", FALSE),
1763 8, /* bits */
1764 (const guchar *)str->str,
1765 strlen(str->str) + 1);
1766
1767 g_string_free(str, TRUE);
1768 gtk_tree_path_free(sourcerow);
1769 }
1770 }
1771
1772 static void gaim_gtk_blist_drag_data_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y,
1773 GtkSelectionData *sd, guint info, guint t)
1774 {
1775 if (gtkblist->drag_timeout) {
1776 g_source_remove(gtkblist->drag_timeout);
1777 gtkblist->drag_timeout = 0;
1778 }
1779
1780 if (sd->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE) && sd->data) {
1781 GaimBlistNode *n = NULL;
1782 GtkTreePath *path = NULL;
1783 GtkTreeViewDropPosition position;
1784 memcpy(&n, sd->data, sizeof(n));
1785 if(gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), x, y, &path, &position)) {
1786 /* if we're here, I think it means the drop is ok */
1787 GtkTreeIter iter;
1788 GaimBlistNode *node;
1789 GValue val;
1790 struct _gaim_gtk_blist_node *gtknode;
1791
1792 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel),
1793 &iter, path);
1794 val.g_type = 0;
1795 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel),
1796 &iter, NODE_COLUMN, &val);
1797 node = g_value_get_pointer(&val);
1798 gtknode = node->ui_data;
1799
1800 if (GAIM_BLIST_NODE_IS_CONTACT(n)) {
1801 GaimContact *c = (GaimContact*)n;
1802 if (GAIM_BLIST_NODE_IS_CONTACT(node) && gtknode->contact_expanded) {
1803 gaim_blist_merge_contact(c, node);
1804 } else if (GAIM_BLIST_NODE_IS_CONTACT(node) ||
1805 GAIM_BLIST_NODE_IS_CHAT(node)) {
1806 switch(position) {
1807 case GTK_TREE_VIEW_DROP_AFTER:
1808 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
1809 gaim_blist_add_contact(c, (GaimGroup*)node->parent,
1810 node);
1811 break;
1812 case GTK_TREE_VIEW_DROP_BEFORE:
1813 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
1814 gaim_blist_add_contact(c, (GaimGroup*)node->parent,
1815 node->prev);
1816 break;
1817 }
1818 } else if(GAIM_BLIST_NODE_IS_GROUP(node)) {
1819 gaim_blist_add_contact(c, (GaimGroup*)node, NULL);
1820 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) {
1821 gaim_blist_merge_contact(c, node);
1822 }
1823 } else if (GAIM_BLIST_NODE_IS_BUDDY(n)) {
1824 GaimBuddy *b = (GaimBuddy*)n;
1825 if (GAIM_BLIST_NODE_IS_BUDDY(node)) {
1826 switch(position) {
1827 case GTK_TREE_VIEW_DROP_AFTER:
1828 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
1829 gaim_blist_add_buddy(b, (GaimContact*)node->parent,
1830 (GaimGroup*)node->parent->parent, node);
1831 break;
1832 case GTK_TREE_VIEW_DROP_BEFORE:
1833 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
1834 gaim_blist_add_buddy(b, (GaimContact*)node->parent,
1835 (GaimGroup*)node->parent->parent,
1836 node->prev);
1837 break;
1838 }
1839 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) {
1840 gaim_blist_add_buddy(b, NULL, (GaimGroup*)node->parent,
1841 NULL);
1842 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) {
1843 gaim_blist_add_buddy(b, NULL, (GaimGroup*)node, NULL);
1844 } else if (GAIM_BLIST_NODE_IS_CONTACT(node)) {
1845 if(gtknode->contact_expanded) {
1846 switch(position) {
1847 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
1848 case GTK_TREE_VIEW_DROP_AFTER:
1849 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
1850 gaim_blist_add_buddy(b, (GaimContact*)node,
1851 (GaimGroup*)node->parent, NULL);
1852 break;
1853 case GTK_TREE_VIEW_DROP_BEFORE:
1854 gaim_blist_add_buddy(b, NULL,
1855 (GaimGroup*)node->parent, node->prev);
1856 break;
1857 }
1858 } else {
1859 switch(position) {
1860 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
1861 case GTK_TREE_VIEW_DROP_AFTER:
1862 gaim_blist_add_buddy(b, NULL,
1863 (GaimGroup*)node->parent, NULL);
1864 break;
1865 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
1866 case GTK_TREE_VIEW_DROP_BEFORE:
1867 gaim_blist_add_buddy(b, NULL,
1868 (GaimGroup*)node->parent, node->prev);
1869 break;
1870 }
1871 }
1872 }
1873 } else if (GAIM_BLIST_NODE_IS_CHAT(n)) {
1874 GaimChat *chat = (GaimChat *)n;
1875 if (GAIM_BLIST_NODE_IS_BUDDY(node)) {
1876 switch(position) {
1877 case GTK_TREE_VIEW_DROP_AFTER:
1878 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
1879 case GTK_TREE_VIEW_DROP_BEFORE:
1880 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
1881 gaim_blist_add_chat(chat,
1882 (GaimGroup*)node->parent->parent,
1883 node->parent);
1884 break;
1885 }
1886 } else if(GAIM_BLIST_NODE_IS_CONTACT(node) ||
1887 GAIM_BLIST_NODE_IS_CHAT(node)) {
1888 switch(position) {
1889 case GTK_TREE_VIEW_DROP_AFTER:
1890 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
1891 gaim_blist_add_chat(chat, (GaimGroup*)node->parent, node);
1892 break;
1893 case GTK_TREE_VIEW_DROP_BEFORE:
1894 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
1895 gaim_blist_add_chat(chat, (GaimGroup*)node->parent, node->prev);
1896 break;
1897 }
1898 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) {
1899 gaim_blist_add_chat(chat, (GaimGroup*)node, NULL);
1900 }
1901 } else if (GAIM_BLIST_NODE_IS_GROUP(n)) {
1902 GaimGroup *g = (GaimGroup*)n;
1903 if (GAIM_BLIST_NODE_IS_GROUP(node)) {
1904 switch (position) {
1905 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
1906 case GTK_TREE_VIEW_DROP_AFTER:
1907 gaim_blist_add_group(g, node);
1908 break;
1909 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
1910 case GTK_TREE_VIEW_DROP_BEFORE:
1911 gaim_blist_add_group(g, node->prev);
1912 break;
1913 }
1914 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) {
1915 gaim_blist_add_group(g, node->parent->parent);
1916 } else if(GAIM_BLIST_NODE_IS_CONTACT(node) ||
1917 GAIM_BLIST_NODE_IS_CHAT(node)) {
1918 gaim_blist_add_group(g, node->parent);
1919 }
1920 }
1921
1922 gtk_tree_path_free(path);
1923 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t);
1924 }
1925 }
1926 else if (sd->target == gdk_atom_intern("application/x-im-contact",
1927 FALSE) && sd->data)
1928 {
1929 GaimGroup *group = NULL;
1930 GtkTreePath *path = NULL;
1931 GtkTreeViewDropPosition position;
1932 GaimAccount *account;
1933 char *protocol = NULL;
1934 char *username = NULL;
1935 char *alias = NULL;
1936
1937 if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget),
1938 x, y, &path, &position))
1939 {
1940 GtkTreeIter iter;
1941 GaimBlistNode *node;
1942 GValue val;
1943
1944 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel),
1945 &iter, path);
1946 val.g_type = 0;
1947 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel),
1948 &iter, NODE_COLUMN, &val);
1949 node = g_value_get_pointer(&val);
1950
1951 if (GAIM_BLIST_NODE_IS_BUDDY(node))
1952 {
1953 group = (GaimGroup *)node->parent->parent;
1954 }
1955 else if (GAIM_BLIST_NODE_IS_CHAT(node) ||
1956 GAIM_BLIST_NODE_IS_CONTACT(node))
1957 {
1958 group = (GaimGroup *)node->parent;
1959 }
1960 else if (GAIM_BLIST_NODE_IS_GROUP(node))
1961 {
1962 group = (GaimGroup *)node;
1963 }
1964 }
1965
1966 if (gaim_gtk_parse_x_im_contact((const char *)sd->data, FALSE, &account,
1967 &protocol, &username, &alias))
1968 {
1969 if (account == NULL)
1970 {
1971 gaim_notify_error(NULL, NULL,
1972 _("You are not currently signed on with an account that "
1973 "can add that buddy."), NULL);
1974 }
1975 else
1976 {
1977 gaim_blist_request_add_buddy(account, username,
1978 (group ? group->name : NULL),
1979 alias);
1980 }
1981 }
1982
1983 g_free(username);
1984 g_free(protocol);
1985 g_free(alias);
1986
1987 if (path != NULL)
1988 gtk_tree_path_free(path);
1989
1990 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t);
1991 }
1992 else if (sd->target == gdk_atom_intern("text/x-vcard", FALSE) && sd->data)
1993 {
1994 gboolean result;
1995 GaimGroup *group = NULL;
1996 GtkTreePath *path = NULL;
1997 GtkTreeViewDropPosition position;
1998
1999 if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget),
2000 x, y, &path, &position))
2001 {
2002 GtkTreeIter iter;
2003 GaimBlistNode *node;
2004 GValue val;
2005
2006 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel),
2007 &iter, path);
2008 val.g_type = 0;
2009 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel),
2010 &iter, NODE_COLUMN, &val);
2011 node = g_value_get_pointer(&val);
2012
2013 if (GAIM_BLIST_NODE_IS_BUDDY(node))
2014 {
2015 group = (GaimGroup *)node->parent->parent;
2016 }
2017 else if (GAIM_BLIST_NODE_IS_CHAT(node) ||
2018 GAIM_BLIST_NODE_IS_CONTACT(node))
2019 {
2020 group = (GaimGroup *)node->parent;
2021 }
2022 else if (GAIM_BLIST_NODE_IS_GROUP(node))
2023 {
2024 group = (GaimGroup *)node;
2025 }
2026 }
2027
2028 result = parse_vcard((const gchar *)sd->data, group);
2029
2030 gtk_drag_finish(dc, result, (dc->action == GDK_ACTION_MOVE), t);
2031 } else if (sd->target == gdk_atom_intern("text/uri-list", FALSE) && sd->data) {
2032 GtkTreePath *path = NULL;
2033 GtkTreeViewDropPosition position;
2034
2035 if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget),
2036 x, y, &path, &position))
2037 {
2038 GtkTreeIter iter;
2039 GaimBlistNode *node;
2040 GValue val;
2041
2042 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel),
2043 &iter, path);
2044 val.g_type = 0;
2045 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel),
2046 &iter, NODE_COLUMN, &val);
2047 node = g_value_get_pointer(&val);
2048
2049 if (GAIM_BLIST_NODE_IS_BUDDY(node) || GAIM_BLIST_NODE_IS_CONTACT(node)) {
2050 GaimBuddy *b = GAIM_BLIST_NODE_IS_BUDDY(node) ? (GaimBuddy*)node : gaim_contact_get_priority_buddy((GaimContact*)node);
2051 gaim_dnd_file_manage(sd, b->account, b->name);
2052 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t);
2053 } else {
2054 gtk_drag_finish(dc, FALSE, FALSE, t);
2055 }
2056 }
2057 }
2058 }
2059
2060 static GdkPixbuf *gaim_gtk_blist_get_buddy_icon(GaimBlistNode *node,
2061 gboolean scaled, gboolean greyed, gboolean custom)
2062 {
2063 GdkPixbuf *buf, *ret = NULL;
2064 GdkPixbufLoader *loader;
2065 GaimBuddyIcon *icon;
2066 const guchar *data = NULL;
2067 gsize len;
2068 GaimBuddy *buddy = (GaimBuddy *)node;
2069
2070 if(GAIM_BLIST_NODE_IS_CONTACT(node)) {
2071 buddy = gaim_contact_get_priority_buddy((GaimContact*)node);
2072 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) {
2073 buddy = (GaimBuddy*)node;
2074 } else {
2075 return NULL;
2076 }
2077
2078 #if 0
2079 if (!gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons"))
2080 return NULL;
2081 #endif
2082
2083 if (custom) {
2084 const char *file = gaim_blist_node_get_string((GaimBlistNode*)gaim_buddy_get_contact(buddy),
2085 "custom_buddy_icon");
2086 if (file && *file) {
2087 char *contents;
2088 GError *err = NULL;
2089 if (!g_file_get_contents(file, &contents, &len, &err)) {
2090 gaim_debug_info("custom -icon", "Could not open custom-icon %s for %s\n",
2091 file, gaim_buddy_get_name(buddy), err->message);
2092 g_error_free(err);
2093 } else
2094 data = (const guchar*)contents;
2095 }
2096 }
2097
2098 if (data == NULL) {
2099 if (!(icon = gaim_buddy_get_icon(buddy)))
2100 if (!(icon = gaim_buddy_icons_find(buddy->account, buddy->name))) /* Not sure I like this...*/
2101 return NULL;
2102 data = gaim_buddy_icon_get_data(icon, &len);
2103 custom = FALSE; /* We are not using the custom icon */
2104 }
2105
2106 loader = gdk_pixbuf_loader_new();
2107 gdk_pixbuf_loader_write(loader, data, len, NULL);
2108 gdk_pixbuf_loader_close(loader, NULL);
2109 buf = gdk_pixbuf_loader_get_pixbuf(loader);
2110 if (buf)
2111 g_object_ref(G_OBJECT(buf));
2112 g_object_unref(G_OBJECT(loader));
2113
2114 if (custom)
2115 g_free((void*)data);
2116 if (buf) {
2117 GaimAccount *account = gaim_buddy_get_account(buddy);
2118 GaimPluginProtocolInfo *prpl_info = NULL;
2119 int orig_width, orig_height;
2120 int scale_width, scale_height;
2121
2122 if(account && account->gc)
2123 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(account->gc->prpl);
2124
2125 if (greyed) {
2126 GaimPresence *presence = gaim_buddy_get_presence(buddy);
2127 if (!GAIM_BUDDY_IS_ONLINE(buddy))
2128 gdk_pixbuf_saturate_and_pixelate(buf, buf, 0.0, FALSE);
2129 if (gaim_presence_is_idle(presence))
2130 gdk_pixbuf_saturate_and_pixelate(buf, buf, 0.25, FALSE);
2131 }
2132
2133 /* i'd use the gaim_gtk_buddy_icon_get_scale_size() thing,
2134 * but it won't tell me the original size, which I need for scaling
2135 * purposes */
2136 scale_width = orig_width = gdk_pixbuf_get_width(buf);
2137 scale_height = orig_height = gdk_pixbuf_get_height(buf);
2138
2139 if (prpl_info && prpl_info->icon_spec.scale_rules & GAIM_ICON_SCALE_DISPLAY)
2140 gaim_buddy_icon_get_scale_size(&prpl_info->icon_spec, &scale_width, &scale_height);
2141
2142 if (scaled) {
2143 if(scale_height > scale_width) {
2144 scale_width = 30.0 * (double)scale_width / (double)scale_height;
2145 scale_height = 30;
2146 } else {
2147 scale_height = 30.0 * (double)scale_height / (double)scale_width;
2148 scale_width = 30;
2149 }
2150
2151 ret = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 30, 30);
2152 gdk_pixbuf_fill(ret, 0x00000000);
2153 gdk_pixbuf_scale(buf, ret, (30-scale_width)/2, (30-scale_height)/2, scale_width, scale_height, (30-scale_width)/2, (30-scale_height)/2, (double)scale_width/(double)orig_width, (double)scale_height/(double)orig_height, GDK_INTERP_BILINEAR);
2154 } else {
2155 ret = gdk_pixbuf_scale_simple(buf,scale_width,scale_height, GDK_INTERP_BILINEAR);
2156 }
2157 g_object_unref(G_OBJECT(buf));
2158 }
2159
2160 return ret;
2161 }
2162
2163 struct tooltip_data {
2164 PangoLayout *layout;
2165 GdkPixbuf *status_icon;
2166 GdkPixbuf *avatar;
2167 int avatar_width;
2168 int width;
2169 int height;
2170 };
2171
2172 static struct tooltip_data * create_tip_for_node(GaimBlistNode *node, gboolean full)
2173 {
2174 char *tooltip_text = NULL;
2175 struct tooltip_data *td = g_new0(struct tooltip_data, 1);
2176
2177 td->status_icon = gaim_gtk_blist_get_status_icon(node, GAIM_STATUS_ICON_LARGE);
2178 td->avatar = gaim_gtk_blist_get_buddy_icon(node, !full, FALSE, FALSE);
2179 tooltip_text = gaim_get_tooltip_text(node, full);
2180 td->layout = gtk_widget_create_pango_layout(gtkblist->tipwindow, NULL);
2181 pango_layout_set_markup(td->layout, tooltip_text, -1);
2182 pango_layout_set_wrap(td->layout, PANGO_WRAP_WORD);
2183 pango_layout_set_width(td->layout, 300000);
2184
2185 pango_layout_get_size (td->layout, &td->width, &td->height);
2186 td->width = PANGO_PIXELS(td->width) + 38 + 8;
2187 td->height = MAX(PANGO_PIXELS(td->height + 4) + 8, 38);
2188
2189 if(td->avatar) {
2190 td->avatar_width = gdk_pixbuf_get_width(td->avatar);
2191 td->width += td->avatar_width + 8;
2192 td->height = MAX(td->height, gdk_pixbuf_get_height(td->avatar) + 8);
2193 }
2194
2195 g_free(tooltip_text);
2196 return td;
2197 }
2198
2199 static void gaim_gtk_blist_paint_tip(GtkWidget *widget, GdkEventExpose *event, GaimBlistNode *node)
2200 {
2201 GtkStyle *style;
2202 int current_height, max_width;
2203 GList *l;
2204
2205 if(gtkblist->tooltipdata == NULL)
2206 return;
2207
2208 style = gtkblist->tipwindow->style;
2209 gtk_paint_flat_box(style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT,
2210 NULL, gtkblist->tipwindow, "tooltip", 0, 0, -1, -1);
2211
2212 max_width = 0;
2213 for(l = gtkblist->tooltipdata; l; l = l->next)
2214 {
2215 struct tooltip_data *td = l->data;
2216 max_width = MAX(max_width, td->width);
2217 }
2218
2219 current_height = 4;
2220 for(l = gtkblist->tooltipdata; l; l = l->next)
2221 {
2222 struct tooltip_data *td = l->data;
2223
2224 #if GTK_CHECK_VERSION(2,2,0)
2225 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, td->status_icon,
2226 0, 0, 4, current_height, -1 , -1, GDK_RGB_DITHER_NONE, 0, 0);
2227 if(td->avatar)
2228 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL,
2229 td->avatar, 0, 0, max_width - (td->avatar_width + 4), current_height, -1 , -1, GDK_RGB_DITHER_NONE, 0, 0);
2230 #else
2231 gdk_pixbuf_render_to_drawable(td->status_icon, GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, 0, 0, 4, current_height, -1, -1, GDK_RGB_DITHER_NONE, 0, 0);
2232 if(td->avatar)
2233 gdk_pixbuf_render_to_drawable(td->avatar,
2234 GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, 0, 0,
2235 max_width - (td->avatar_width + 4),
2236 current_height, -1, -1, GDK_RGB_DITHER_NONE, 0, 0);
2237 #endif
2238
2239 gtk_paint_layout (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, FALSE,
2240 NULL, gtkblist->tipwindow, "tooltip", 38 + 4, current_height, td->layout);
2241
2242 current_height += td->height;
2243
2244 if(l->next)
2245 gtk_paint_hline(style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, NULL, NULL, NULL, 4, max_width - 4, current_height-6);
2246
2247 }
2248 }
2249
2250 static void gaim_gtk_blist_tooltip_destroy()
2251 {
2252 while(gtkblist->tooltipdata) {
2253 struct tooltip_data *td = gtkblist->tooltipdata->data;
2254
2255 if(td->avatar)
2256 g_object_unref(td->avatar);
2257 if(td->status_icon)
2258 g_object_unref(td->status_icon);
2259 g_object_unref(td->layout);
2260 g_free(td);
2261 gtkblist->tooltipdata = g_list_delete_link(gtkblist->tooltipdata, gtkblist->tooltipdata);
2262 }
2263
2264 if (gtkblist->tipwindow == NULL)
2265 return;
2266
2267 gtk_widget_destroy(gtkblist->tipwindow);
2268 gtkblist->tipwindow = NULL;
2269 }
2270
2271 static gboolean gaim_gtk_blist_expand_timeout(GtkWidget *tv)
2272 {
2273 GtkTreePath *path;
2274 GtkTreeIter iter;
2275 GaimBlistNode *node;
2276 GValue val;
2277 struct _gaim_gtk_blist_node *gtknode;
2278
2279 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), gtkblist->tip_rect.x, gtkblist->tip_rect.y, &path, NULL, NULL, NULL))
2280 return FALSE;
2281 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path);
2282 val.g_type = 0;
2283 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val);
2284 node = g_value_get_pointer(&val);
2285
2286 if(!GAIM_BLIST_NODE_IS_CONTACT(node)) {
2287 gtk_tree_path_free(path);
2288 return FALSE;
2289 }
2290
2291 gtknode = node->ui_data;
2292
2293 if (!gtknode->contact_expanded) {
2294 GtkTreeIter i;
2295
2296 gaim_gtk_blist_expand_contact_cb(NULL, node);
2297
2298 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, &gtkblist->contact_rect);
2299 gdk_drawable_get_size(GDK_DRAWABLE(tv->window), &(gtkblist->contact_rect.width), NULL);
2300 gtkblist->mouseover_contact = node;
2301 gtk_tree_path_down (path);
2302 while (gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &i, path)) {
2303 GdkRectangle rect;
2304 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, &rect);
2305 gtkblist->contact_rect.height += rect.height;
2306 gtk_tree_path_next(path);
2307 }
2308 }
2309 gtk_tree_path_free(path);
2310 return FALSE;
2311 }
2312
2313 static gboolean buddy_is_displayable(GaimBuddy *buddy)
2314 {
2315 struct _gaim_gtk_blist_node *gtknode;
2316
2317 if(!buddy)
2318 return FALSE;
2319
2320 gtknode = ((GaimBlistNode*)buddy)->ui_data;
2321
2322 return (gaim_account_is_connected(buddy->account) &&
2323 (gaim_presence_is_online(buddy->presence) ||
2324 (gtknode && gtknode->recent_signonoff) ||
2325 gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies") ||
2326 gaim_blist_node_get_bool((GaimBlistNode*)buddy, "show_offline")));
2327 }
2328
2329 static gboolean gaim_gtk_blist_tooltip_timeout(GtkWidget *tv)
2330 {
2331 GtkTreePath *path;
2332 GtkTreeIter iter;
2333 GaimBlistNode *node;
2334 GValue val;
2335 int scr_w, scr_h, w, h, x, y;
2336 #if GTK_CHECK_VERSION(2,2,0)
2337 int mon_num;
2338 GdkScreen *screen = NULL;
2339 #endif
2340 gboolean tooltip_top = FALSE;
2341 struct _gaim_gtk_blist_node *gtknode;
2342 GdkRectangle mon_size;
2343
2344 /*
2345 * Attempt to free the previous tooltip. I have a feeling
2346 * this is never needed... but just in case.
2347 */
2348 gaim_gtk_blist_tooltip_destroy();
2349
2350 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), gtkblist->tip_rect.x, gtkblist->tip_rect.y, &path, NULL, NULL, NULL))
2351 return FALSE;
2352 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path);
2353 val.g_type = 0;
2354 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val);
2355 node = g_value_get_pointer(&val);
2356
2357 gtk_tree_path_free(path);
2358
2359 gtkblist->tipwindow = gtk_window_new(GTK_WINDOW_POPUP);
2360
2361 if(GAIM_BLIST_NODE_IS_CHAT(node) || GAIM_BLIST_NODE_IS_BUDDY(node)) {
2362 struct tooltip_data *td = create_tip_for_node(node, TRUE);
2363 gtkblist->tooltipdata = g_list_append(gtkblist->tooltipdata, td);
2364 w = td->width;
2365 h = td->height;
2366 } else if(GAIM_BLIST_NODE_IS_CONTACT(node)) {
2367 GaimBlistNode *child;
2368 GaimBuddy *b = gaim_contact_get_priority_buddy((GaimContact *)node);
2369 w = h = 0;
2370 for(child = node->child; child; child = child->next)
2371 {
2372 if(GAIM_BLIST_NODE_IS_BUDDY(child) && buddy_is_displayable((GaimBuddy*)child)) {
2373 struct tooltip_data *td = create_tip_for_node(child, (b == (GaimBuddy*)child));
2374 if (b == (GaimBuddy *)child) {
2375 gtkblist->tooltipdata = g_list_prepend(gtkblist->tooltipdata, td);
2376 } else {
2377 gtkblist->tooltipdata = g_list_append(gtkblist->tooltipdata, td);
2378 }
2379 w = MAX(w, td->width);
2380 h += td->height;
2381 }
2382 }
2383 } else {
2384 gtk_widget_destroy(gtkblist->tipwindow);
2385 gtkblist->tipwindow = NULL;
2386 return FALSE;
2387 }
2388
2389 if (gtkblist->tooltipdata == NULL) {
2390 gtk_widget_destroy(gtkblist->tipwindow);
2391 gtkblist->tipwindow = NULL;
2392 return FALSE;
2393 }
2394
2395 gtknode = node->ui_data;
2396
2397 gtk_widget_set_app_paintable(gtkblist->tipwindow, TRUE);
2398 gtk_window_set_resizable(GTK_WINDOW(gtkblist->tipwindow), FALSE);
2399 gtk_widget_set_name(gtkblist->tipwindow, "gtk-tooltips");
2400 g_signal_connect(G_OBJECT(gtkblist->tipwindow), "expose_event",
2401 G_CALLBACK(gaim_gtk_blist_paint_tip), NULL);
2402 gtk_widget_ensure_style (gtkblist->tipwindow);
2403
2404
2405 #if GTK_CHECK_VERSION(2,2,0)
2406 gdk_display_get_pointer(gdk_display_get_default(), &screen, &x, &y, NULL);
2407 mon_num = gdk_screen_get_monitor_at_point(screen, x, y);
2408 gdk_screen_get_monitor_geometry(screen, mon_num, &mon_size);
2409
2410 scr_w = mon_size.width + mon_size.x;
2411 scr_h = mon_size.height + mon_size.y;
2412 #else
2413 scr_w = gdk_screen_width();
2414 scr_h = gdk_screen_height();
2415 gdk_window_get_pointer(NULL, &x, &y, NULL);
2416 mon_size.x = 0;
2417 mon_size.y = 0;
2418 #endif
2419
2420 #if GTK_CHECK_VERSION(2,2,0)
2421 if (w > mon_size.width)
2422 w = mon_size.width - 10;
2423
2424 if (h > mon_size.height)
2425 h = mon_size.height - 10;
2426 #endif
2427
2428 if (GTK_WIDGET_NO_WINDOW(gtkblist->window))
2429 y+=gtkblist->window->allocation.y;
2430
2431 x -= ((w >> 1) + 4);
2432
2433 if ((y + h + 4) > scr_h || tooltip_top)
2434 y = y - h - 5;
2435 else
2436 y = y + 6;
2437
2438 if (y < mon_size.y)
2439 y = mon_size.y;
2440
2441 if (y != mon_size.y) {
2442 if ((x + w) > scr_w)
2443 x -= (x + w + 5) - scr_w;
2444 else if (x < mon_size.x)
2445 x = mon_size.x;
2446 } else {
2447 x -= (w / 2 + 10);
2448 if (x < mon_size.x)
2449 x = mon_size.x;
2450 }
2451
2452 gtk_widget_set_size_request(gtkblist->tipwindow, w, h);
2453 gtk_window_move(GTK_WINDOW(gtkblist->tipwindow), x, y);
2454 gtk_widget_show(gtkblist->tipwindow);
2455
2456 return FALSE;
2457 }
2458
2459 static gboolean gaim_gtk_blist_drag_motion_cb(GtkWidget *tv, GdkDragContext *drag_context,
2460 gint x, gint y, guint time, gpointer user_data)
2461 {
2462 GtkTreePath *path;
2463 int delay;
2464
2465 /*
2466 * When dragging a buddy into a contact, this is the delay before
2467 * the contact auto-expands.
2468 */
2469 delay = 900;
2470
2471 if (gtkblist->drag_timeout) {
2472 if ((y > gtkblist->tip_rect.y) && ((y - gtkblist->tip_rect.height) < gtkblist->tip_rect.y))
2473 return FALSE;
2474 /* We've left the cell. Remove the timeout and create a new one below */
2475 g_source_remove(gtkblist->drag_timeout);
2476 }
2477
2478 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), x, y, &path, NULL, NULL, NULL);
2479 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, &gtkblist->tip_rect);
2480
2481 if (path)
2482 gtk_tree_path_free(path);
2483 gtkblist->drag_timeout = g_timeout_add(delay, (GSourceFunc)gaim_gtk_blist_expand_timeout, tv);
2484
2485 if (gtkblist->mouseover_contact) {
2486 if ((y < gtkblist->contact_rect.y) || ((y - gtkblist->contact_rect.height) > gtkblist->contact_rect.y)) {
2487 gaim_gtk_blist_collapse_contact_cb(NULL, gtkblist->mouseover_contact);
2488 gtkblist->mouseover_contact = NULL;
2489 }
2490 }
2491
2492 return FALSE;
2493 }
2494
2495 static gboolean gaim_gtk_blist_motion_cb (GtkWidget *tv, GdkEventMotion *event, gpointer null)
2496 {
2497 GtkTreePath *path;
2498 int delay;
2499
2500 delay = gaim_prefs_get_int("/gaim/gtk/blist/tooltip_delay");
2501
2502 if (delay == 0)
2503 return FALSE;
2504
2505 if (gtkblist->timeout) {
2506 if ((event->y > gtkblist->tip_rect.y) && ((event->y - gtkblist->tip_rect.height) < gtkblist->tip_rect.y))
2507 return FALSE;
2508 /* We've left the cell. Remove the timeout and create a new one below */
2509 gaim_gtk_blist_tooltip_destroy();
2510 g_source_remove(gtkblist->timeout);
2511 }
2512
2513 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL);
2514 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, &gtkblist->tip_rect);
2515
2516 if (path)
2517 gtk_tree_path_free(path);
2518 gtkblist->timeout = g_timeout_add(delay, (GSourceFunc)gaim_gtk_blist_tooltip_timeout, tv);
2519
2520 if (gtkblist->mouseover_contact) {
2521 if ((event->y < gtkblist->contact_rect.y) || ((event->y - gtkblist->contact_rect.height) > gtkblist->contact_rect.y)) {
2522 gaim_gtk_blist_collapse_contact_cb(NULL, gtkblist->mouseover_contact);
2523 gtkblist->mouseover_contact = NULL;
2524 }
2525 }
2526
2527 return FALSE;
2528 }
2529
2530 static void gaim_gtk_blist_leave_cb (GtkWidget *w, GdkEventCrossing *e, gpointer n)
2531 {
2532
2533 if (gtkblist->timeout) {
2534 g_source_remove(gtkblist->timeout);
2535 gtkblist->timeout = 0;
2536 }
2537
2538 if (gtkblist->drag_timeout) {
2539 g_source_remove(gtkblist->drag_timeout);
2540 gtkblist->drag_timeout = 0;
2541 }
2542
2543 gaim_gtk_blist_tooltip_destroy();
2544
2545 if (gtkblist->mouseover_contact &&
2546 !((e->x > gtkblist->contact_rect.x) && (e->x < (gtkblist->contact_rect.x + gtkblist->contact_rect.width)) &&
2547 (e->y > gtkblist->contact_rect.y) && (e->y < (gtkblist->contact_rect.y + gtkblist->contact_rect.height)))) {
2548 gaim_gtk_blist_collapse_contact_cb(NULL, gtkblist->mouseover_contact);
2549 gtkblist->mouseover_contact = NULL;
2550 }
2551 }
2552
2553 static void
2554 toggle_debug(void)
2555 {
2556 gaim_prefs_set_bool("/gaim/gtk/debug/enabled",
2557 !gaim_prefs_get_bool("/gaim/gtk/debug/enabled"));
2558 }
2559
2560
2561 /***************************************************
2562 * Crap *
2563 ***************************************************/
2564 static GtkItemFactoryEntry blist_menu[] =
2565 {
2566 /* Buddies menu */
2567 { N_("/_Buddies"), NULL, NULL, 0, "<Branch>", NULL },
2568 { N_("/Buddies/New Instant _Message..."), "<CTL>M", gaim_gtkdialogs_im, 0, "<StockItem>", GAIM_STOCK_IM },
2569 { N_("/Buddies/Join a _Chat..."), "<CTL>C", gaim_gtk_blist_joinchat_show, 0, "<StockItem>", GAIM_STOCK_CHAT },
2570 { N_("/Buddies/Get User _Info..."), "<CTL>I", gaim_gtkdialogs_info, 0, "<StockItem>", GAIM_STOCK_INFO },
2571 { N_("/Buddies/View User _Log..."), "<CTL>L", gaim_gtkdialogs_log, 0, "<StockItem>", GAIM_STOCK_LOG },
2572 { "/Buddies/sep1", NULL, NULL, 0, "<Separator>", NULL },
2573 { N_("/Buddies/Show _Offline Buddies"), NULL, gaim_gtk_blist_edit_mode_cb, 1, "<CheckItem>", NULL },
2574 { N_("/Buddies/Show _Empty Groups"), NULL, gaim_gtk_blist_show_empty_groups_cb, 1, "<CheckItem>", NULL },
2575 { N_("/Buddies/Show Buddy _Details"), NULL, gaim_gtk_blist_buddy_details_cb, 1, "<CheckItem>", NULL },
2576 { N_("/Buddies/Show Idle _Times"), NULL, gaim_gtk_blist_show_idle_time_cb, 1, "<CheckItem>", NULL },
2577 { N_("/Buddies/_Sort Buddies"), NULL, NULL, 0, "<Branch>", NULL },
2578 { "/Buddies/sep2", NULL, NULL, 0, "<Separator>", NULL },
2579 { N_("/Buddies/_Add Buddy..."), "<CTL>B", gaim_gtk_blist_add_buddy_cb, 0, "<StockItem>", GTK_STOCK_ADD },
2580 { N_("/Buddies/Add C_hat..."), NULL, gaim_gtk_blist_add_chat_cb, 0, "<StockItem>", GTK_STOCK_ADD },
2581 { N_("/Buddies/Add _Group..."), NULL, gaim_blist_request_add_group, 0, "<StockItem>", GTK_STOCK_ADD },
2582 { "/Buddies/sep3", NULL, NULL, 0, "<Separator>", NULL },
2583 { N_("/Buddies/_Quit"), "<CTL>Q", gaim_core_quit, 0, "<StockItem>", GTK_STOCK_QUIT },
2584
2585 /* Accounts menu */
2586 { N_("/_Accounts"), NULL, NULL, 0, "<Branch>", NULL },
2587 { N_("/Accounts/Add\\/Edit"), "<CTL>A", gaim_gtk_accounts_window_show, 0, "<StockItem>", GAIM_STOCK_ACCOUNTS },
2588
2589 /* Tools */
2590 { N_("/_Tools"), NULL, NULL, 0, "<Branch>", NULL },
2591 { N_("/Tools/Buddy _Pounces"), NULL, gaim_gtk_pounces_manager_show, 0, "<StockItem>", GAIM_STOCK_POUNCE },
2592 { N_("/Tools/Plu_gins"), "<CTL>U", gaim_gtk_plugin_dialog_show, 0, "<StockItem>", GAIM_STOCK_PLUGIN },
2593 { N_("/Tools/Pr_eferences"), "<CTL>P", gaim_gtk_prefs_show, 0, "<StockItem>", GTK_STOCK_PREFERENCES },
2594 { N_("/Tools/Pr_ivacy"), NULL, gaim_gtk_privacy_dialog_show, 0, "<StockItem>", GTK_STOCK_DIALOG_ERROR },
2595 { "/Tools/sep2", NULL, NULL, 0, "<Separator>", NULL },
2596 { N_("/Tools/_File Transfers"), "<CTL>T", gaim_gtkxfer_dialog_show, 0, "<StockItem>", GAIM_STOCK_FILE_TRANSFER },
2597 { N_("/Tools/R_oom List"), NULL, gaim_gtk_roomlist_dialog_show, 0, "<StockItem>", GTK_STOCK_INDEX },
2598 { N_("/Tools/System _Log"), NULL, gtk_blist_show_systemlog_cb, 0, "<StockItem>", GAIM_STOCK_LOG },
2599 { "/Tools/sep3", NULL, NULL, 0, "<Separator>", NULL },
2600 { N_("/Tools/Mute _Sounds"), "<CTL>S", gaim_gtk_blist_mute_sounds_cb, 0, "<CheckItem>", NULL },
2601
2602 /* Help */
2603 { N_("/_Help"), NULL, NULL, 0, "<Branch>", NULL },
2604 { N_("/Help/Online _Help"), "F1", gtk_blist_show_onlinehelp_cb, 0, "<StockItem>", GTK_STOCK_HELP },
2605 { N_("/Help/_Debug Window"), NULL, toggle_debug, 0, "<StockItem>", GAIM_STOCK_DEBUG },
2606 { N_("/Help/_About"), NULL, gaim_gtkdialogs_about, 0, "<StockItem>", GAIM_STOCK_ABOUT },
2607 };
2608
2609 /*********************************************************
2610 * Private Utility functions *
2611 *********************************************************/
2612
2613 static char *gaim_get_tooltip_text(GaimBlistNode *node, gboolean full)
2614 {
2615 GString *str = g_string_new("");
2616 GaimPlugin *prpl;
2617 GaimPluginProtocolInfo *prpl_info = NULL;
2618 char *tmp;
2619
2620 if (GAIM_BLIST_NODE_IS_CHAT(node))
2621 {
2622 GaimChat *chat;
2623 GList *cur;
2624 struct proto_chat_entry *pce;
2625 char *name, *value;
2626
2627 chat = (GaimChat *)node;
2628 prpl = gaim_find_prpl(gaim_account_get_protocol_id(chat->account));
2629 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
2630
2631 tmp = g_markup_escape_text(gaim_chat_get_name(chat), -1);
2632 g_string_append_printf(str, "<span size='larger' weight='bold'>%s</span>", tmp);
2633 g_free(tmp);
2634
2635 if (g_list_length(gaim_connections_get_all()) > 1)
2636 {
2637 tmp = g_markup_escape_text(chat->account->username, -1);
2638 g_string_append_printf(str, _("\n<b>Account:</b> %s"), tmp);
2639 g_free(tmp);
2640 }
2641
2642 if (prpl_info->chat_info != NULL)
2643 cur = prpl_info->chat_info(chat->account->gc);
2644 else
2645 cur = NULL;
2646
2647 while (cur != NULL)
2648 {
2649 pce = cur->data;
2650
2651 if (!pce->secret && (!pce->required &&
2652 g_hash_table_lookup(chat->components, pce->identifier) == NULL))
2653 {
2654 tmp = gaim_text_strip_mnemonic(pce->label);
2655 name = g_markup_escape_text(tmp, -1);
2656 g_free(tmp);
2657 value = g_markup_escape_text(g_hash_table_lookup(
2658 chat->components, pce->identifier), -1);
2659 g_string_append_printf(str, "\n<b>%s</b> %s",
2660 name ? name : "",
2661 value ? value : "");
2662 g_free(name);
2663 g_free(value);
2664 }
2665
2666 g_free(pce);
2667 cur = g_list_remove(cur, pce);
2668 }
2669 }
2670 else if (GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_BUDDY(node))
2671 {
2672 /* NOTE: THIS FUNCTION IS NO LONGER CALLED FOR CONTACTS.
2673 * It is only called by create_tip_for_node(), and create_tip_for_node() is never called for a contact.
2674 */
2675 GaimContact *c;
2676 GaimBuddy *b;
2677 GaimPresence *presence;
2678 GaimNotifyUserInfo *user_info;
2679 char *tmp;
2680 time_t idle_secs, signon;
2681
2682 if (GAIM_BLIST_NODE_IS_CONTACT(node))
2683 {
2684 c = (GaimContact *)node;
2685 b = gaim_contact_get_priority_buddy(c);
2686 }
2687 else
2688 {
2689 b = (GaimBuddy *)node;
2690 c = gaim_buddy_get_contact(b);
2691 }
2692
2693 prpl = gaim_find_prpl(gaim_account_get_protocol_id(b->account));
2694 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
2695
2696 presence = gaim_buddy_get_presence(b);
2697
2698 /* Buddy Name */
2699 tmp = g_markup_escape_text(gaim_buddy_get_name(b), -1);
2700 g_string_append_printf(str, "<span size='larger' weight='bold'>%s</span>\n", tmp);
2701 g_free(tmp);
2702
2703 user_info = gaim_notify_user_info_new();
2704
2705 /* Account */
2706 if (full && g_list_length(gaim_connections_get_all()) > 1)
2707 {
2708 tmp = g_markup_escape_text(gaim_account_get_username(
2709 gaim_buddy_get_account(b)), -1);
2710 gaim_notify_user_info_add_pair(user_info, _("Account"), tmp);
2711 g_free(tmp);
2712 }
2713
2714 /* Alias */
2715 /* If there's not a contact alias, the node is being displayed with
2716 * this alias, so there's no point in showing it in the tooltip. */
2717 if (full && b->alias != NULL && b->alias[0] != '\0' &&
2718 (c->alias != NULL && c->alias[0] != '\0') &&
2719 strcmp(c->alias, b->alias) != 0)
2720 {
2721 tmp = g_markup_escape_text(b->alias, -1);
2722 gaim_notify_user_info_add_pair(user_info, _("Buddy Alias"), tmp);
2723 g_free(tmp);
2724 }
2725
2726 /* Nickname/Server Alias */
2727 /* I'd like to only show this if there's a contact or buddy
2728 * alias, but many people on MSN set long nicknames, which
2729 * get ellipsized, so the only way to see the whole thing is
2730 * to look at the tooltip. */
2731 if (full && b->server_alias != NULL && b->server_alias[0] != '\0')
2732 {
2733 tmp = g_markup_escape_text(b->server_alias, -1);
2734 gaim_notify_user_info_add_pair(user_info, _("Nickname"), tmp);
2735 g_free(tmp);
2736 }
2737
2738 /* Logged In */
2739 signon = gaim_presence_get_login_time(presence);
2740 if (full && GAIM_BUDDY_IS_ONLINE(b) && signon > 0)
2741 {
2742 tmp = gaim_str_seconds_to_string(time(NULL) - signon);
2743 gaim_notify_user_info_add_pair(user_info, _("Logged In"), tmp);
2744 g_free(tmp);
2745 }
2746
2747 /* Idle */
2748 if (gaim_presence_is_idle(presence))
2749 {
2750 idle_secs = gaim_presence_get_idle_time(presence);
2751 if (idle_secs > 0)
2752 {
2753 tmp = gaim_str_seconds_to_string(time(NULL) - idle_secs);
2754 gaim_notify_user_info_add_pair(user_info, _("Idle"), tmp);
2755 g_free(tmp);
2756 }
2757 }
2758
2759 /* Last Seen */
2760 if (full && !GAIM_BUDDY_IS_ONLINE(b))
2761 {
2762 struct _gaim_gtk_blist_node *gtknode = ((GaimBlistNode *)c)->ui_data;
2763 GaimBlistNode *bnode;
2764 int lastseen = 0;
2765
2766 if (!gtknode->contact_expanded || GAIM_BLIST_NODE_IS_CONTACT(node))
2767 {
2768 /* We're either looking at a buddy for a collapsed contact or
2769 * an expanded contact itself so we show the most recent
2770 * (largest) last_seen time for any of the buddies under
2771 * the contact. */
2772 for (bnode = ((GaimBlistNode *)c)->child ; bnode != NULL ; bnode = bnode->next)
2773 {
2774 int value = gaim_blist_node_get_int(bnode, "last_seen");
2775 if (value > lastseen)
2776 lastseen = value;
2777 }
2778 }
2779 else
2780 {
2781 /* We're dealing with a buddy under an expanded contact,
2782 * so we show the last_seen time for the buddy. */
2783 lastseen = gaim_blist_node_get_int(&b->node, "last_seen");
2784 }
2785
2786 if (lastseen > 0)
2787 {
2788 tmp = gaim_str_seconds_to_string(time(NULL) - lastseen);
2789 gaim_notify_user_info_add_pair(user_info, _("Last Seen"), tmp);
2790 g_free(tmp);
2791 }
2792 }
2793
2794
2795 /* Offline? */
2796 /* FIXME: Why is this status special-cased by the core? -- rlaager */
2797 if (!GAIM_BUDDY_IS_ONLINE(b)) {
2798 gaim_notify_user_info_add_pair(user_info, _("Status"), _("Offline"));
2799 }
2800
2801 if (prpl_info && prpl_info->tooltip_text)
2802 {
2803 /* Additional text from the PRPL */
2804 prpl_info->tooltip_text(b, user_info, full);
2805 }
2806
2807 /* These are Easter Eggs. Patches to remove them will be rejected. */
2808 if (!g_ascii_strcasecmp(b->name, "robflynn"))
2809 gaim_notify_user_info_add_pair(user_info, _("Description"), _("Spooky"));
2810 if (!g_ascii_strcasecmp(b->name, "seanegn"))
2811 gaim_notify_user_info_add_pair(user_info, _("Status"), _("Awesome"));
2812 if (!g_ascii_strcasecmp(b->name, "chipx86"))
2813 gaim_notify_user_info_add_pair(user_info, _("Status"), _("Rockin'"));
2814
2815 tmp = gaim_notify_user_info_get_text_with_newline(user_info, "\n");
2816 g_string_append(str, tmp);
2817 g_free(tmp);
2818
2819 gaim_notify_user_info_destroy(user_info);
2820 }
2821
2822 gaim_signal_emit(gaim_gtk_blist_get_handle(),
2823 "drawing-tooltip", node, str, full);
2824
2825 return g_string_free(str, FALSE);
2826 }
2827
2828 struct _emblem_data {
2829 const char *filename;
2830 int x;
2831 int y;
2832 };
2833
2834 static void g_string_destroy(GString *destroyable)
2835 {
2836 g_string_free(destroyable, TRUE);
2837 }
2838
2839 static void
2840 gaim_gtk_blist_update_buddy_status_icon_key(struct _gaim_gtk_blist_node *gtkbuddynode, GaimBuddy *buddy, GaimStatusIconSize size)
2841 {
2842 GString *key = g_string_sized_new(16);
2843
2844 if(gtkbuddynode && gtkbuddynode->recent_signonoff) {
2845 if(GAIM_BUDDY_IS_ONLINE(buddy))
2846 g_string_printf(key, "login");
2847 else
2848 g_string_printf(key, "logout");
2849 } else {
2850 int i;
2851 const char *protoname = NULL;
2852 GaimAccount *account = buddy->account;
2853 GaimPlugin *prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
2854 GaimPluginProtocolInfo *prpl_info;
2855 GaimConversation *conv;
2856 struct _emblem_data emblems[4] = {{NULL, 15, 15}, {NULL, 0, 15},
2857 {NULL, 0, 0}, {NULL, 15, 0}};
2858
2859 if(!prpl)
2860 return;
2861
2862 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
2863
2864 if(prpl_info && prpl_info->list_icon) {
2865 protoname = prpl_info->list_icon(account, buddy);
2866 }
2867 if(prpl_info && prpl_info->list_emblems) {
2868 prpl_info->list_emblems(buddy, &emblems[0].filename,
2869 &emblems[1].filename, &emblems[2].filename,
2870 &emblems[3].filename);
2871 }
2872
2873 g_string_assign(key, protoname);
2874
2875 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM,
2876 gaim_buddy_get_name(buddy), account);
2877
2878 if(conv != NULL) {
2879 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv);
2880 if(gaim_gtkconv_is_hidden(gtkconv)) {
2881 /* add pending emblem */
2882 if(size == GAIM_STATUS_ICON_SMALL) {
2883 emblems[0].filename = "pending";
2884 }
2885 else {
2886 emblems[3].filename = emblems[2].filename;
2887 emblems[2].filename = "pending";
2888 }
2889 }
2890 }
2891
2892 if(size == GAIM_STATUS_ICON_SMALL) {
2893 /* So that only the se icon will composite */
2894 emblems[1].filename = emblems[2].filename = emblems[3].filename = NULL;
2895 }
2896
2897 for(i = 0; i < 4; i++) {
2898 if(emblems[i].filename)
2899 g_string_append_printf(key, "/%s", emblems[i].filename);
2900 }
2901 }
2902
2903 if (!GAIM_BUDDY_IS_ONLINE(buddy))
2904 g_string_append(key, "/off");
2905 else if (gaim_presence_is_idle(gaim_buddy_get_presence(buddy)))
2906 g_string_append(key, "/idle");
2907
2908 if (!gaim_privacy_check(buddy->account, gaim_buddy_get_name(buddy)))
2909 g_string_append(key, "/priv");
2910
2911 if (gtkbuddynode->status_icon_key)
2912 g_string_free(gtkbuddynode->status_icon_key, TRUE);
2913 gtkbuddynode->status_icon_key = key;
2914
2915 }
2916
2917 GdkPixbuf *
2918 gaim_gtk_blist_get_status_icon(GaimBlistNode *node, GaimStatusIconSize size)
2919 {
2920 GdkPixbuf *scale, *status = NULL;
2921 int i, scalesize = 30;
2922 char *filename;
2923 GString *key = g_string_sized_new(16);
2924 const char *protoname = NULL;
2925 struct _gaim_gtk_blist_node *gtknode = node->ui_data;
2926 struct _gaim_gtk_blist_node *gtkbuddynode = NULL;
2927 struct _emblem_data emblems[4] = {{NULL, 15, 15}, {NULL, 0, 15},
2928 {NULL, 0, 0}, {NULL, 15, 0}};
2929 GaimPresence *presence = NULL;
2930 GaimBuddy *buddy = NULL;
2931 GaimChat *chat = NULL;
2932
2933 if(GAIM_BLIST_NODE_IS_CONTACT(node)) {
2934 if(!gtknode->contact_expanded) {
2935 buddy = gaim_contact_get_priority_buddy((GaimContact*)node);
2936 gtkbuddynode = ((GaimBlistNode*)buddy)->ui_data;
2937 }
2938 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) {
2939 buddy = (GaimBuddy*)node;
2940 gtkbuddynode = node->ui_data;
2941 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) {
2942 chat = (GaimChat*)node;
2943 } else {
2944 return NULL;
2945 }
2946
2947 if (!status_icon_hash_table) {
2948 status_icon_hash_table = g_hash_table_new_full((GHashFunc)g_string_hash,
2949 (GEqualFunc)g_string_equal,
2950 (GDestroyNotify)g_string_destroy,
2951 (GDestroyNotify)gdk_pixbuf_unref);
2952
2953 } else if (buddy && gtkbuddynode->status_icon_key && gtkbuddynode->status_icon_key->str) {
2954 key = g_string_new(gtkbuddynode->status_icon_key->str);
2955
2956 /* Respect the size request given */
2957 if (size == GAIM_STATUS_ICON_SMALL) {
2958 g_string_append(key, "/tiny");
2959 }
2960
2961 scale = g_hash_table_lookup(status_icon_hash_table, key);
2962 if (scale) {
2963 gdk_pixbuf_ref(scale);
2964 g_string_free(key, TRUE);
2965 return scale;
2966 }
2967 }
2968
2969 if(buddy || chat) {
2970 GaimAccount *account;
2971 GaimPlugin *prpl;
2972 GaimPluginProtocolInfo *prpl_info;
2973
2974 if(buddy)
2975 account = buddy->account;
2976 else
2977 account = chat->account;
2978
2979 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
2980 if(!prpl)
2981 return NULL;
2982
2983 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
2984
2985 if(prpl_info && prpl_info->list_icon) {
2986 protoname = prpl_info->list_icon(account, buddy);
2987 }
2988 if(prpl_info && prpl_info->list_emblems && buddy) {
2989 if(gtknode && !gtknode->recent_signonoff)
2990 prpl_info->list_emblems(buddy, &emblems[0].filename,
2991 &emblems[1].filename, &emblems[2].filename,
2992 &emblems[3].filename);
2993 }
2994 }
2995
2996 /* Begin Generating Lookup Key */
2997 if (buddy) {
2998 gaim_gtk_blist_update_buddy_status_icon_key(gtkbuddynode, buddy, size);
2999 g_string_assign(key, gtkbuddynode->status_icon_key->str);
3000 }
3001 /* There are only two options for chat or gaimdude - big or small */
3002 else if (chat) {
3003 GaimAccount *account;
3004 GaimPlugin *prpl;
3005 GaimPluginProtocolInfo *prpl_info;
3006
3007 account = chat->account;
3008
3009 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
3010 if(!prpl)
3011 return NULL;
3012
3013 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
3014
3015 if(prpl_info && prpl_info->list_icon) {
3016 protoname = prpl_info->list_icon(account, NULL);
3017 }
3018 g_string_append_printf(key, "%s-chat", protoname);
3019 }
3020 else
3021 g_string_append(key, "gaimdude");
3022
3023 /* If the icon is small, we do not store this into the status_icon_key
3024 * in the gtkbuddynode. This way we can respect the size value on cache
3025 * lookup. Otherwise, different sized icons could not be stored easily.
3026 */
3027 if (size == GAIM_STATUS_ICON_SMALL) {
3028 g_string_append(key, "/tiny");
3029 }
3030
3031 /* End Generating Lookup Key */
3032
3033 /* If we already know this icon, just return it */
3034 scale = g_hash_table_lookup(status_icon_hash_table, key);
3035 if (scale) {
3036 gdk_pixbuf_ref(scale);
3037 g_string_free(key, TRUE);
3038 return scale;
3039 }
3040
3041 /* Create a new composite icon */
3042
3043 if(buddy) {
3044 GaimAccount *account;
3045 GaimPlugin *prpl;
3046 GaimPluginProtocolInfo *prpl_info;
3047 GaimConversation *conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM,
3048 gaim_buddy_get_name(buddy),
3049 gaim_buddy_get_account(buddy));
3050
3051 account = buddy->account;
3052
3053 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
3054 if(!prpl)
3055 return NULL;
3056
3057 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
3058
3059 if(prpl_info && prpl_info->list_icon) {
3060 protoname = prpl_info->list_icon(account, buddy);
3061 }
3062 if(prpl_info && prpl_info->list_emblems) {
3063 if(gtknode && !gtknode->recent_signonoff)
3064 prpl_info->list_emblems(buddy, &emblems[0].filename,
3065 &emblems[1].filename, &emblems[2].filename,
3066 &emblems[3].filename);
3067 }
3068
3069 if(conv != NULL) {
3070 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv);
3071 if(gtkconv != NULL && gaim_gtkconv_is_hidden(gtkconv)) {
3072 /* add pending emblem */
3073 if(size == GAIM_STATUS_ICON_SMALL) {
3074 emblems[0].filename="pending";
3075 }
3076 else {
3077 emblems[3].filename=emblems[2].filename;
3078 emblems[2].filename="pending";
3079 }
3080 }
3081 }
3082 }
3083
3084 if(size == GAIM_STATUS_ICON_SMALL) {
3085 scalesize = 15;
3086 /* So that only the se icon will composite */
3087 emblems[1].filename = emblems[2].filename = emblems[3].filename = NULL;
3088 }
3089
3090 if(buddy && GAIM_BUDDY_IS_ONLINE(buddy) && gtkbuddynode && gtkbuddynode->recent_signonoff) {
3091 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "login.png", NULL);
3092 } else if(buddy && !GAIM_BUDDY_IS_ONLINE(buddy) && gtkbuddynode && gtkbuddynode->recent_signonoff) {
3093 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "logout.png", NULL);
3094 } else if(buddy || chat) {
3095 char *image = g_strdup_printf("%s.png", protoname);
3096 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL);
3097 g_free(image);
3098 } else {
3099 /* gaim dude */
3100 filename = g_build_filename(DATADIR, "pixmaps", "gaim.png", NULL);
3101 }
3102
3103 status = gdk_pixbuf_new_from_file(filename, NULL);
3104 g_free(filename);
3105
3106 if(!status) {
3107 g_string_free(key, TRUE);
3108 return NULL;
3109 }
3110
3111 scale = gdk_pixbuf_scale_simple(status, scalesize, scalesize,
3112 GDK_INTERP_BILINEAR);
3113 g_object_unref(status);
3114
3115 for(i=0; i<4; i++) {
3116 if(emblems[i].filename) {
3117 GdkPixbuf *emblem;
3118 char *image = g_strdup_printf("%s.png", emblems[i].filename);
3119 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL);
3120 g_free(image);
3121 emblem = gdk_pixbuf_new_from_file(filename, NULL);
3122 g_free(filename);
3123 if(emblem) {
3124 if(i == 0 && size == GAIM_STATUS_ICON_SMALL) {
3125 double scale_factor = 0.6;
3126 if(gdk_pixbuf_get_width(emblem) > 20)
3127 scale_factor = 9.0 / gdk_pixbuf_get_width(emblem);
3128
3129 gdk_pixbuf_composite(emblem,
3130 scale, 5, 5,
3131 10, 10,
3132 5, 5,
3133 scale_factor, scale_factor,
3134 GDK_INTERP_BILINEAR,
3135 255);
3136 } else {
3137 double scale_factor = 1.0;
3138 if(gdk_pixbuf_get_width(emblem) > 20)
3139 scale_factor = 15.0 / gdk_pixbuf_get_width(emblem);
3140
3141 gdk_pixbuf_composite(emblem,
3142 scale, emblems[i].x, emblems[i].y,
3143 15, 15,
3144 emblems[i].x, emblems[i].y,
3145 scale_factor, scale_factor,
3146 GDK_INTERP_BILINEAR,
3147 255);
3148 }
3149 g_object_unref(emblem);
3150 }
3151 }
3152 }
3153
3154 if(buddy) {
3155 presence = gaim_buddy_get_presence(buddy);
3156 if (!GAIM_BUDDY_IS_ONLINE(buddy))
3157 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE);
3158 else if (gaim_presence_is_idle(presence))
3159 {
3160 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.25, FALSE);
3161 }
3162
3163 if (!gaim_privacy_check(buddy->account, gaim_buddy_get_name(buddy)))
3164 {
3165 GdkPixbuf *emblem;
3166 char *filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "blocked.png", NULL);
3167
3168 emblem = gdk_pixbuf_new_from_file(filename, NULL);
3169 g_free(filename);
3170
3171 if (emblem)
3172 {
3173 gdk_pixbuf_composite(emblem, scale,
3174 0, 0, scalesize, scalesize,
3175 0, 0,
3176 (double)scalesize / gdk_pixbuf_get_width(emblem),
3177 (double)scalesize / gdk_pixbuf_get_height(emblem),
3178 GDK_INTERP_BILINEAR,
3179 224);
3180 g_object_unref(emblem);
3181 }
3182 }
3183 }
3184
3185 /* Insert the new icon into the status icon hash table */
3186 g_hash_table_insert (status_icon_hash_table, key, scale);
3187 gdk_pixbuf_ref(scale);
3188
3189 return scale;
3190 }
3191
3192 static gchar *gaim_gtk_blist_get_name_markup(GaimBuddy *b, gboolean selected)
3193 {
3194 const char *name;
3195 char *esc, *text = NULL;
3196 GaimPlugin *prpl;
3197 GaimPluginProtocolInfo *prpl_info = NULL;
3198 GaimContact *contact;
3199 GaimPresence *presence;
3200 struct _gaim_gtk_blist_node *gtkcontactnode = NULL;
3201 char *idletime = NULL, *statustext = NULL;
3202 time_t t;
3203 /* XXX Good luck cleaning up this crap */
3204
3205 contact = (GaimContact*)((GaimBlistNode*)b)->parent;
3206 if(contact)
3207 gtkcontactnode = ((GaimBlistNode*)contact)->ui_data;
3208
3209 if(gtkcontactnode && !gtkcontactnode->contact_expanded && contact->alias)
3210 name = contact->alias;
3211 else
3212 name = gaim_buddy_get_alias(b);
3213 esc = g_markup_escape_text(name, strlen(name));
3214
3215 presence = gaim_buddy_get_presence(b);
3216
3217 if (!gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons"))
3218 {
3219 if (!selected && gaim_presence_is_idle(presence))
3220 {
3221 text = g_strdup_printf("<span color='%s'>%s</span>",
3222 dim_grey(), esc);
3223 g_free(esc);
3224 return text;
3225 }
3226 else
3227 return esc;
3228 }
3229
3230 prpl = gaim_find_prpl(gaim_account_get_protocol_id(b->account));
3231
3232 if (prpl != NULL)
3233 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
3234
3235 if (prpl_info && prpl_info->status_text && b->account->gc) {
3236 char *tmp = prpl_info->status_text(b);
3237 const char *end;
3238
3239 if(tmp && !g_utf8_validate(tmp, -1, &end)) {
3240 char *new = g_strndup(tmp,
3241 g_utf8_pointer_to_offset(tmp, end));
3242 g_free(tmp);
3243 tmp = new;
3244 }
3245
3246 #if !GTK_CHECK_VERSION(2,6,0)
3247 if(tmp) {
3248 char buf[32];
3249 char *c = tmp;
3250 int length = 0, vis=0;
3251 gboolean inside = FALSE;
3252 g_strdelimit(tmp, "\n", ' ');
3253 gaim_str_strip_char(tmp, '\r');
3254
3255 while(*c && vis < 20) {
3256 if(*c == '&')
3257 inside = TRUE;
3258 else if(*c == ';')
3259 inside = FALSE;
3260 if(!inside)
3261 vis++;
3262 c = g_utf8_next_char(c); /* this is fun */
3263 }
3264
3265 length = c - tmp;
3266
3267 if(vis == 20)
3268 g_snprintf(buf, sizeof(buf), "%%.%ds...", length);
3269 else
3270 g_snprintf(buf, sizeof(buf), "%%s ");
3271
3272 statustext = g_strdup_printf(buf, tmp);
3273
3274 g_free(tmp);
3275 }
3276 #else
3277 if(tmp) {
3278 g_strdelimit(tmp, "\n", ' ');
3279 gaim_str_strip_char(tmp, '\r');
3280 }
3281 statustext = tmp;
3282 #endif
3283 }
3284
3285 if(!gaim_presence_is_online(presence) && !statustext)
3286 statustext = g_strdup(_("Offline"));
3287 else if (!statustext)
3288 text = g_strdup(esc);
3289
3290 if (gaim_presence_is_idle(presence)) {
3291 if (gaim_prefs_get_bool("/gaim/gtk/blist/show_idle_time")) {
3292 time_t idle_secs = gaim_presence_get_idle_time(presence);
3293
3294 if (idle_secs > 0) {
3295 int ihrs, imin;
3296
3297 time(&t);
3298 ihrs = (t - idle_secs) / 3600;
3299 imin = ((t - idle_secs) / 60) % 60;
3300
3301 if (ihrs)
3302 idletime = g_strdup_printf(_("Idle %dh %02dm"), ihrs, imin);
3303 else
3304 idletime = g_strdup_printf(_("Idle %dm"), imin);
3305 }
3306 else
3307 idletime = g_strdup(_("Idle"));
3308
3309 if (!selected)
3310 text = g_strdup_printf("<span color='%s'>%s</span>\n"
3311 "<span color='%s' size='smaller'>%s%s%s</span>",
3312 dim_grey(), esc, dim_grey(),
3313 idletime != NULL ? idletime : "",
3314 (idletime != NULL && statustext != NULL) ? " - " : "",
3315 statustext != NULL ? statustext : "");
3316 }
3317 else if (!selected && !statustext) /* We handle selected text later */
3318 text = g_strdup_printf("<span color='%s'>%s</span>", dim_grey(), esc);
3319 else if (!selected && !text)
3320 text = g_strdup_printf("<span color='%s'>%s</span>\n"
3321 "<span color='%s' size='smaller'>%s</span>",
3322 dim_grey(), esc, dim_grey(),
3323 statustext != NULL ? statustext : "");
3324 }
3325
3326 /* Not idle and not selected */
3327 else if (!selected && !text)
3328 {
3329 text = g_strdup_printf("%s\n"
3330 "<span color='%s' size='smaller'>%s</span>",
3331 esc, dim_grey(),
3332 statustext != NULL ? statustext : "");
3333 }
3334
3335 /* It is selected. */
3336 if ((selected && !text) || (selected && idletime))
3337 text = g_strdup_printf("%s\n"
3338 "<span size='smaller'>%s%s%s</span>",
3339 esc,
3340 idletime != NULL ? idletime : "",
3341 (idletime != NULL && statustext != NULL) ? " - " : "",
3342 statustext != NULL ? statustext : "");
3343
3344 g_free(idletime);
3345 g_free(statustext);
3346 g_free(esc);
3347
3348 return text;
3349 }
3350
3351 static void gaim_gtk_blist_restore_position()
3352 {
3353 int blist_x, blist_y, blist_width, blist_height;
3354
3355 blist_width = gaim_prefs_get_int("/gaim/gtk/blist/width");
3356
3357 /* if the window exists, is hidden, we're saving positions, and the
3358 * position is sane... */
3359 if (gtkblist && gtkblist->window &&
3360 !GTK_WIDGET_VISIBLE(gtkblist->window) && blist_width != 0) {
3361
3362 blist_x = gaim_prefs_get_int("/gaim/gtk/blist/x");
3363 blist_y = gaim_prefs_get_int("/gaim/gtk/blist/y");
3364 blist_height = gaim_prefs_get_int("/gaim/gtk/blist/height");
3365
3366 /* ...check position is on screen... */
3367 if (blist_x >= gdk_screen_width())
3368 blist_x = gdk_screen_width() - 100;
3369 else if (blist_x + blist_width < 0)
3370 blist_x = 100;
3371
3372 if (blist_y >= gdk_screen_height())
3373 blist_y = gdk_screen_height() - 100;
3374 else if (blist_y + blist_height < 0)
3375 blist_y = 100;
3376
3377 /* ...and move it back. */
3378 gtk_window_move(GTK_WINDOW(gtkblist->window), blist_x, blist_y);
3379 gtk_window_resize(GTK_WINDOW(gtkblist->window), blist_width, blist_height);
3380 if (gaim_prefs_get_bool("/gaim/gtk/blist/list_maximized"))
3381 gtk_window_maximize(GTK_WINDOW(gtkblist->window));
3382 }
3383 }
3384
3385 static gboolean gaim_gtk_blist_refresh_timer(GaimBuddyList *list)
3386 {
3387 GaimBlistNode *gnode, *cnode;
3388
3389 if (gtk_blist_obscured || !GTK_WIDGET_VISIBLE(gtkblist->window))
3390 return TRUE;
3391
3392 for(gnode = list->root; gnode; gnode = gnode->next) {
3393 if(!GAIM_BLIST_NODE_IS_GROUP(gnode))
3394 continue;
3395 for(cnode = gnode->child; cnode; cnode = cnode->next) {
3396 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) {
3397 GaimBuddy *buddy;
3398
3399 buddy = gaim_contact_get_priority_buddy((GaimContact*)cnode);
3400
3401 if (buddy &&
3402 gaim_presence_is_idle(gaim_buddy_get_presence(buddy)))
3403 gaim_gtk_blist_update_contact(list, (GaimBlistNode*)buddy);
3404 }
3405 }
3406 }
3407
3408 /* keep on going */
3409 return TRUE;
3410 }
3411
3412 static void gaim_gtk_blist_hide_node(GaimBuddyList *list, GaimBlistNode *node, gboolean update)
3413 {
3414 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data;
3415 GtkTreeIter iter;
3416
3417 if (!gtknode || !gtknode->row || !gtkblist)
3418 return;
3419
3420 if(gtkblist->selected_node == node)
3421 gtkblist->selected_node = NULL;
3422 if (get_iter_from_node(node, &iter)) {
3423 gtk_tree_store_remove(gtkblist->treemodel, &iter);
3424 if(update && (GAIM_BLIST_NODE_IS_CONTACT(node) ||
3425 GAIM_BLIST_NODE_IS_BUDDY(node) || GAIM_BLIST_NODE_IS_CHAT(node))) {
3426 gaim_gtk_blist_update(list, node->parent);
3427 }
3428 }
3429 gtk_tree_row_reference_free(gtknode->row);
3430 gtknode->row = NULL;
3431 }
3432
3433 static const char *require_connection[] =
3434 {
3435 N_("/Buddies/New Instant Message..."),
3436 N_("/Buddies/Join a Chat..."),
3437 N_("/Buddies/Get User Info..."),
3438 N_("/Buddies/Add Buddy..."),
3439 N_("/Buddies/Add Chat..."),
3440 N_("/Buddies/Add Group..."),
3441 };
3442
3443 static const int require_connection_size = sizeof(require_connection)
3444 / sizeof(*require_connection);
3445
3446 /**
3447 * Rebuild dynamic menus and make menu items sensitive/insensitive
3448 * where appropriate.
3449 */
3450 static void
3451 update_menu_bar(GaimGtkBuddyList *gtkblist)
3452 {
3453 GtkWidget *widget;
3454 gboolean sensitive;
3455 int i;
3456
3457 g_return_if_fail(gtkblist != NULL);
3458
3459 gaim_gtk_blist_update_accounts_menu();
3460
3461 sensitive = (gaim_connections_get_all() != NULL);
3462
3463 for (i = 0; i < require_connection_size; i++)
3464 {
3465 widget = gtk_item_factory_get_widget(gtkblist->ift, require_connection[i]);
3466 gtk_widget_set_sensitive(widget, sensitive);
3467 }
3468
3469 widget = gtk_item_factory_get_widget(gtkblist->ift, N_("/Buddies/Join a Chat..."));
3470 gtk_widget_set_sensitive(widget, gaim_gtk_blist_joinchat_is_showable());
3471
3472 widget = gtk_item_factory_get_widget(gtkblist->ift, N_("/Buddies/Add Chat..."));
3473 gtk_widget_set_sensitive(widget, gaim_gtk_blist_joinchat_is_showable());
3474
3475 widget = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Buddy Pounces"));
3476 gtk_widget_set_sensitive(widget, (gaim_accounts_get_all() != NULL));
3477
3478 widget = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Privacy"));
3479 gtk_widget_set_sensitive(widget, (gaim_connections_get_all() != NULL));
3480
3481 widget = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Room List"));
3482 gtk_widget_set_sensitive(widget, gaim_gtk_roomlist_is_showable());
3483 }
3484
3485 static void
3486 sign_on_off_cb(GaimConnection *gc, GaimBuddyList *blist)
3487 {
3488 GaimGtkBuddyList *gtkblist = GAIM_GTK_BLIST(blist);
3489
3490 update_menu_bar(gtkblist);
3491 }
3492
3493 static void
3494 plugin_changed_cb(GaimPlugin *p, gpointer *data)
3495 {
3496 gaim_gtk_blist_update_plugin_actions();
3497 }
3498
3499 static void
3500 unseen_conv_menu()
3501 {
3502 static GtkWidget *menu = NULL;
3503 GList *convs = NULL;
3504
3505 if (menu) {
3506 gtk_widget_destroy(menu);
3507 menu = NULL;
3508 }
3509
3510 convs = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM, GAIM_UNSEEN_TEXT, TRUE, 0);
3511 if (!convs)
3512 /* no conversations added, don't show the menu */
3513 return;
3514
3515 menu = gtk_menu_new();
3516
3517 gaim_gtk_conversations_fill_menu(menu, convs);
3518 g_list_free(convs);
3519 gtk_widget_show_all(menu);
3520 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3,
3521 gtk_get_current_event_time());
3522 }
3523
3524 static gboolean
3525 menutray_press_cb(GtkWidget *widget, GdkEventButton *event)
3526 {
3527 GList *convs;
3528
3529 switch (event->button) {
3530 case 1:
3531 convs = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM,
3532 GAIM_UNSEEN_TEXT, TRUE, 1);
3533 if (convs) {
3534 gaim_gtkconv_present_conversation((GaimConversation*)convs->data);
3535 g_list_free(convs);
3536 }
3537 break;
3538 case 3:
3539 unseen_conv_menu();
3540 break;
3541 }
3542 return TRUE;
3543 }
3544
3545 static void
3546 conversation_updated_cb(GaimConversation *conv, GaimConvUpdateType type,
3547 GaimGtkBuddyList *gtkblist)
3548 {
3549 GList *convs = NULL;
3550 GList *l = NULL;
3551
3552 if (type != GAIM_CONV_UPDATE_UNSEEN)
3553 return;
3554
3555 if(conv->account != NULL && conv->name != NULL) {
3556 GaimBuddy *buddy = gaim_find_buddy(conv->account, conv->name);
3557 if(buddy != NULL)
3558 gaim_gtk_blist_update_buddy(NULL, (GaimBlistNode *)buddy, TRUE);
3559 }
3560
3561 if (gtkblist->menutrayicon) {
3562 gtk_widget_destroy(gtkblist->menutrayicon);
3563 gtkblist->menutrayicon = NULL;
3564 }
3565
3566 convs = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM, GAIM_UNSEEN_TEXT, TRUE, 0);
3567 if (convs) {
3568 GtkWidget *img = NULL;
3569 GString *tooltip_text = NULL;
3570
3571 tooltip_text = g_string_new("");
3572 l = convs;
3573 while (l != NULL) {
3574 if (GAIM_IS_GTK_CONVERSATION(l->data)) {
3575 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION((GaimConversation *)l->data);
3576
3577 g_string_append_printf(tooltip_text,
3578 ngettext("%d unread message from %s\n", "%d unread messages from %s\n", gtkconv->unseen_count),
3579 gtkconv->unseen_count,
3580 gtk_label_get_text(GTK_LABEL(gtkconv->tab_label)));
3581 }
3582 l = l->next;
3583 }
3584 if(tooltip_text->len > 0) {
3585 /* get rid of the last newline */
3586 g_string_truncate(tooltip_text, tooltip_text->len -1);
3587 img = gtk_image_new_from_stock(GAIM_STOCK_PENDING, GTK_ICON_SIZE_MENU);
3588
3589 gtkblist->menutrayicon = gtk_event_box_new();
3590 gtk_container_add(GTK_CONTAINER(gtkblist->menutrayicon), img);
3591 gtk_widget_show(img);
3592 gtk_widget_show(gtkblist->menutrayicon);
3593 g_signal_connect(G_OBJECT(gtkblist->menutrayicon), "button-press-event", G_CALLBACK(menutray_press_cb), NULL);
3594
3595 gaim_gtk_menu_tray_append(GAIM_GTK_MENU_TRAY(gtkblist->menutray), gtkblist->menutrayicon, tooltip_text->str);
3596 }
3597 g_string_free(tooltip_text, TRUE);
3598 g_list_free(convs);
3599 }
3600 }
3601
3602 static void
3603 conversation_deleting_cb(GaimConversation *conv, GaimGtkBuddyList *gtkblist)
3604 {
3605 conversation_updated_cb(conv, GAIM_CONV_UPDATE_UNSEEN, gtkblist);
3606 }
3607
3608 /**********************************************************************************
3609 * Public API Functions *
3610 **********************************************************************************/
3611
3612 static void gaim_gtk_blist_new_list(GaimBuddyList *blist)
3613 {
3614 GaimGtkBuddyList *gtkblist;
3615
3616 gtkblist = g_new0(GaimGtkBuddyList, 1);
3617 gtkblist->connection_errors = g_hash_table_new_full(g_direct_hash,
3618 g_direct_equal, NULL, g_free);
3619 blist->ui_data = gtkblist;
3620 }
3621
3622 static void gaim_gtk_blist_new_node(GaimBlistNode *node)
3623 {
3624 node->ui_data = g_new0(struct _gaim_gtk_blist_node, 1);
3625 }
3626
3627 gboolean gaim_gtk_blist_node_is_contact_expanded(GaimBlistNode *node)
3628 {
3629 if GAIM_BLIST_NODE_IS_BUDDY(node)
3630 node = node->parent;
3631
3632 g_return_val_if_fail(GAIM_BLIST_NODE_IS_CONTACT(node), FALSE);
3633
3634 return ((struct _gaim_gtk_blist_node *)node->ui_data)->contact_expanded;
3635 }
3636
3637 enum {
3638 DRAG_BUDDY,
3639 DRAG_ROW,
3640 DRAG_VCARD,
3641 DRAG_TEXT,
3642 DRAG_URI,
3643 NUM_TARGETS
3644 };
3645
3646 static const char *
3647 item_factory_translate_func (const char *path, gpointer func_data)
3648 {
3649 return _((char *)path);
3650 }
3651
3652 void gaim_gtk_blist_setup_sort_methods()
3653 {
3654 gaim_gtk_blist_sort_method_reg("none", _("Manually"), sort_method_none);
3655 #if GTK_CHECK_VERSION(2,2,1)
3656 gaim_gtk_blist_sort_method_reg("alphabetical", _("Alphabetically"), sort_method_alphabetical);
3657 gaim_gtk_blist_sort_method_reg("status", _("By status"), sort_method_status);
3658 gaim_gtk_blist_sort_method_reg("log_size", _("By log size"), sort_method_log);
3659 #endif
3660 gaim_gtk_blist_sort_method_set(gaim_prefs_get_string("/gaim/gtk/blist/sort_type"));
3661 }
3662
3663 static void _prefs_change_redo_list()
3664 {
3665 GtkTreeSelection *sel;
3666 GtkTreeIter iter;
3667 GaimBlistNode *node = NULL;
3668
3669 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview));
3670 if (gtk_tree_selection_get_selected(sel, NULL, &iter))
3671 {
3672 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1);
3673 }
3674
3675 redo_buddy_list(gaim_get_blist(), FALSE, FALSE);
3676 #if GTK_CHECK_VERSION(2,6,0)
3677 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(gtkblist->treeview));
3678 #endif
3679
3680 if (node)
3681 {
3682 struct _gaim_gtk_blist_node *gtknode;
3683 GtkTreePath *path;
3684
3685 gtknode = node->ui_data;
3686 if (gtknode && gtknode->row)
3687 {
3688 path = gtk_tree_row_reference_get_path(gtknode->row);
3689 gtk_tree_selection_select_path(sel, path);
3690 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(gtkblist->treeview), path, NULL, FALSE, 0, 0);
3691 gtk_tree_path_free(path);
3692 }
3693 }
3694 }
3695
3696 static void _prefs_change_sort_method(const char *pref_name, GaimPrefType type,
3697 gconstpointer val, gpointer data)
3698 {
3699 if(!strcmp(pref_name, "/gaim/gtk/blist/sort_type"))
3700 gaim_gtk_blist_sort_method_set(val);
3701 }
3702
3703 static void account_modified(GaimAccount *account, GaimGtkBuddyList *gtkblist)
3704 {
3705 GList *list;
3706 if (!gtkblist)
3707 return;
3708
3709 if ((list = gaim_accounts_get_all_active()) != NULL) {
3710 gtk_notebook_set_current_page(GTK_NOTEBOOK(gtkblist->notebook), 1);
3711 g_list_free(list);
3712 } else
3713 gtk_notebook_set_current_page(GTK_NOTEBOOK(gtkblist->notebook), 0);
3714
3715 update_menu_bar(gtkblist);
3716 }
3717
3718 static void
3719 account_status_changed(GaimAccount *account, GaimStatus *old,
3720 GaimStatus *new, GaimGtkBuddyList *gtkblist)
3721 {
3722 if (!gtkblist)
3723 return;
3724
3725 update_menu_bar(gtkblist);
3726 }
3727
3728 static gboolean
3729 gtk_blist_window_key_press_cb(GtkWidget *w, GdkEventKey *event, GaimGtkBuddyList *gtkblist)
3730 {
3731 GtkWidget *imhtml;
3732
3733 if (!gtkblist)
3734 return FALSE;
3735
3736 imhtml = gtk_window_get_focus(GTK_WINDOW(gtkblist->window));
3737
3738 if (GTK_IS_IMHTML(imhtml) && gtk_bindings_activate(GTK_OBJECT(imhtml), event->keyval, event->state))
3739 return TRUE;
3740 return FALSE;
3741 }
3742
3743 static gboolean
3744 headline_hover_close(int x, int y)
3745 {
3746 GtkWidget *w = gtkblist->headline_hbox;
3747 if (x <= w->allocation.width && x >= w->allocation.width - HEADLINE_CLOSE_SIZE &&
3748 y >= 0 && y <= HEADLINE_CLOSE_SIZE)
3749 return TRUE;
3750 return FALSE;
3751 }
3752
3753 static gboolean
3754 headline_box_enter_cb(GtkWidget *widget, GdkEventCrossing *event, GaimGtkBuddyList *gtkblist)
3755 {
3756 gdk_window_set_cursor(widget->window, gtkblist->hand_cursor);
3757
3758 if (gtkblist->headline_close) {
3759 #if GTK_CHECK_VERSION(2,2,0)
3760 gdk_draw_pixbuf(widget->window, NULL, gtkblist->headline_close,
3761 #else
3762 gdk_pixbuf_render_to_drawable(gtkblist->headline_close,
3763 GDK_DRAWABLE(widget->window), NULL,
3764 #endif
3765 0, 0,
3766 widget->allocation.width - 2 - HEADLINE_CLOSE_SIZE, 2,
3767 HEADLINE_CLOSE_SIZE, HEADLINE_CLOSE_SIZE,
3768 GDK_RGB_DITHER_NONE, 0, 0);
3769 gtk_paint_focus(widget->style, widget->window, GTK_STATE_PRELIGHT,
3770 NULL, widget, NULL,
3771 widget->allocation.width - HEADLINE_CLOSE_SIZE - 3, 1,
3772 HEADLINE_CLOSE_SIZE + 2, HEADLINE_CLOSE_SIZE + 2);
3773 }
3774
3775 return FALSE;
3776 }
3777
3778 #if 0
3779 static gboolean
3780 headline_box_motion_cb(GtkWidget *widget, GdkEventMotion *event, GaimGtkBuddyList *gtkblist)
3781 {
3782 gaim_debug_fatal("motion", "%d %d\n", (int)event->x, (int)event->y);
3783 if (headline_hover_close((int)event->x, (int)event->y))
3784 gtk_paint_focus(widget->style, widget->window, GTK_STATE_PRELIGHT,
3785 NULL, widget, NULL,
3786 widget->allocation.width - HEADLINE_CLOSE_SIZE - 3, 1,
3787 HEADLINE_CLOSE_SIZE + 2, HEADLINE_CLOSE_SIZE + 2);
3788 return FALSE;
3789 }
3790 #endif
3791
3792 static gboolean
3793 headline_box_leave_cb(GtkWidget *widget, GdkEventCrossing *event, GaimGtkBuddyList *gtkblist)
3794 {
3795 gdk_window_set_cursor(widget->window, gtkblist->arrow_cursor);
3796 if (gtkblist->headline_close) {
3797 GdkRectangle rect = {widget->allocation.width - 3 - HEADLINE_CLOSE_SIZE, 1,
3798 HEADLINE_CLOSE_SIZE + 2, HEADLINE_CLOSE_SIZE + 2};
3799 gdk_window_invalidate_rect(widget->window, &rect, TRUE);
3800 }
3801 return FALSE;
3802 }
3803
3804 static void
3805 reset_headline(GaimGtkBuddyList *gtkblist)
3806 {
3807 gtkblist->headline_callback = NULL;
3808 gtkblist->headline_data = NULL;
3809 gtkblist->headline_destroy = NULL;
3810 gaim_gtk_set_urgent(GTK_WINDOW(gtkblist->window), FALSE);
3811 }
3812
3813 static gboolean
3814 headline_click_callback(gpointer data)
3815 {
3816 ((GSourceFunc)gtkblist->headline_callback)(gtkblist->headline_data);
3817 reset_headline(gtkblist);
3818 return FALSE;
3819 }
3820
3821 static gboolean
3822 headline_box_press_cb(GtkWidget *widget, GdkEventButton *event, GaimGtkBuddyList *gtkblist)
3823 {
3824 gtk_widget_hide(gtkblist->headline_hbox);
3825 if (gtkblist->headline_callback && !headline_hover_close((int)event->x, (int)event->y))
3826 g_idle_add((GSourceFunc)headline_click_callback, gtkblist->headline_data);
3827 else {
3828 if (gtkblist->headline_destroy)
3829 gtkblist->headline_destroy(gtkblist->headline_data);
3830 reset_headline(gtkblist);
3831 }
3832 return TRUE;
3833 }
3834
3835 /***********************************/
3836 /* Connection error handling stuff */
3837 /***********************************/
3838
3839 static void
3840 ce_modify_account_cb(GaimAccount *account)
3841 {
3842 gaim_gtk_account_dialog_show(GAIM_GTK_MODIFY_ACCOUNT_DIALOG, account);
3843 }
3844
3845 static void
3846 ce_enable_account_cb(GaimAccount *account)
3847 {
3848 gaim_account_set_enabled(account, gaim_core_get_ui(), TRUE);
3849 }
3850
3851 static void
3852 connection_error_button_clicked_cb(GtkButton *widget, gpointer user_data)
3853 {
3854 GaimAccount *account;
3855 char *primary;
3856 const char *text;
3857 gboolean enabled;
3858
3859 account = user_data;
3860 primary = g_strdup_printf(_("%s disconnected"),
3861 gaim_account_get_username(account));
3862 text = g_hash_table_lookup(gtkblist->connection_errors, account);
3863
3864 enabled = gaim_account_get_enabled(account, gaim_core_get_ui());
3865 gaim_request_action(account, _("Connection Error"), primary, text, 2,
3866 account, 3,
3867 _("OK"), NULL,
3868 _("Modify Account"), GAIM_CALLBACK(ce_modify_account_cb),
3869 enabled ? _("Connect") : _("Re-enable Account"),
3870 enabled ? GAIM_CALLBACK(gaim_account_connect) :
3871 GAIM_CALLBACK(ce_enable_account_cb));
3872 g_free(primary);
3873 gtk_widget_destroy(GTK_WIDGET(widget));
3874 g_hash_table_remove(gtkblist->connection_errors, account);
3875 }
3876
3877 /* Add some buttons that show connection errors */
3878 static void
3879 create_connection_error_buttons(gpointer key, gpointer value,
3880 gpointer user_data)
3881 {
3882 GaimAccount *account;
3883 GaimStatusType *status_type;
3884 gchar *escaped, *text;
3885 GtkWidget *button, *label, *image, *hbox;
3886 GdkPixbuf *pixbuf;
3887
3888 account = key;
3889 escaped = g_markup_escape_text((const gchar *)value, -1);
3890 text = g_strdup_printf(_("<span color=\"red\">%s disconnected: %s</span>"),
3891 gaim_account_get_username(account),
3892 escaped);
3893 g_free(escaped);
3894
3895 hbox = gtk_hbox_new(FALSE, 0);
3896
3897 /* Create the icon */
3898 if ((status_type = gaim_account_get_status_type_with_primitive(account,
3899 GAIM_STATUS_OFFLINE))) {
3900 pixbuf = gaim_gtk_create_prpl_icon_with_status(account, status_type, 0.5);
3901 if (pixbuf != NULL) {
3902 image = gtk_image_new_from_pixbuf(pixbuf);
3903 g_object_unref(pixbuf);
3904
3905 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE,
3906 GAIM_HIG_BOX_SPACE);
3907 }
3908 }
3909
3910 /* Create the text */
3911 label = gtk_label_new("");
3912 gtk_label_set_markup(GTK_LABEL(label), text);
3913 g_free(text);
3914 #if GTK_CHECK_VERSION(2,6,0)
3915 g_object_set(label, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
3916 #endif
3917 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE,
3918 GAIM_HIG_BOX_SPACE);
3919
3920 /* Create the actual button and put the icon and text on it */
3921 button = gtk_button_new();
3922 gtk_container_add(GTK_CONTAINER(button), hbox);
3923 g_signal_connect(G_OBJECT(button), "clicked",
3924 G_CALLBACK(connection_error_button_clicked_cb),
3925 account);
3926 gtk_widget_show_all(button);
3927 gtk_box_pack_end(GTK_BOX(gtkblist->error_buttons), button,
3928 FALSE, FALSE, 0);
3929 }
3930
3931 void
3932 gaim_gtk_blist_update_account_error_state(GaimAccount *account, const char *text)
3933 {
3934 GList *l;
3935
3936 if (text == NULL)
3937 g_hash_table_remove(gtkblist->connection_errors, account);
3938 else
3939 g_hash_table_insert(gtkblist->connection_errors, account, g_strdup(text));
3940
3941 /* Remove the old error buttons */
3942 for (l = gtk_container_get_children(GTK_CONTAINER(gtkblist->error_buttons));
3943 l != NULL;
3944 l = l->next)
3945 {
3946 gtk_widget_destroy(GTK_WIDGET(l->data));
3947 }
3948
3949 /* Add new error buttons */
3950 g_hash_table_foreach(gtkblist->connection_errors,
3951 create_connection_error_buttons, NULL);
3952 }
3953
3954 static gboolean
3955 paint_headline_hbox (GtkWidget *widget,
3956 GdkEventExpose *event,
3957 gpointer user_data)
3958 {
3959 gtk_paint_flat_box (widget->style,
3960 widget->window,
3961 GTK_STATE_NORMAL,
3962 GTK_SHADOW_OUT,
3963 NULL,
3964 widget,
3965 "tooltip",
3966 widget->allocation.x + 1,
3967 widget->allocation.y + 1,
3968 widget->allocation.width - 2,
3969 widget->allocation.height - 2);
3970 return FALSE;
3971 }
3972
3973 static void
3974 headline_style_set (GtkWidget *widget,
3975 GtkStyle *prev_style)
3976 {
3977 GtkTooltips *tooltips;
3978 GtkStyle *style;
3979
3980 if (gtkblist->changing_style)
3981 return;
3982
3983 tooltips = gtk_tooltips_new ();
3984 #if GLIB_CHECK_VERSION(2,10,0)
3985 g_object_ref_sink (tooltips);
3986 #else
3987 g_object_ref(tooltips);
3988 gtk_object_sink(GTK_OBJECT(tooltips));
3989 #endif
3990
3991 gtk_tooltips_force_window (tooltips);
3992 gtk_widget_ensure_style (tooltips->tip_window);
3993 style = gtk_widget_get_style (tooltips->tip_window);
3994
3995 gtkblist->changing_style = TRUE;
3996 gtk_widget_set_style (gtkblist->headline_hbox, style);
3997 gtkblist->changing_style = FALSE;
3998
3999 g_object_unref (tooltips);
4000 }
4001
4002 /******************************************/
4003 /* End of connection error handling stuff */
4004 /******************************************/
4005
4006 static int
4007 blist_focus_cb(GtkWidget *widget, gpointer data, GaimGtkBuddyList *gtkblist)
4008 {
4009 gaim_gtk_set_urgent(GTK_WINDOW(gtkblist->window), FALSE);
4010 return 0;
4011 }
4012
4013 #if 0
4014 static GtkWidget *
4015 kiosk_page()
4016 {
4017 GtkWidget *ret = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE);
4018 GtkWidget *label;
4019 GtkWidget *entry;
4020 GtkWidget *bbox;
4021 GtkWidget *button;
4022
4023 label = gtk_label_new(NULL);
4024 gtk_box_pack_start(GTK_BOX(ret), label, TRUE, TRUE, 0);
4025
4026 label = gtk_label_new(NULL);
4027 gtk_label_set_markup(GTK_LABEL(label), _("<b>Username:</b>"));
4028 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
4029 gtk_box_pack_start(GTK_BOX(ret), label, FALSE, FALSE, 0);
4030 entry = gtk_entry_new();
4031 gtk_box_pack_start(GTK_BOX(ret), entry, FALSE, FALSE, 0);
4032
4033 label = gtk_label_new(NULL);
4034 gtk_label_set_markup(GTK_LABEL(label), _("<b>Password:</b>"));
4035 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
4036 gtk_box_pack_start(GTK_BOX(ret), label, FALSE, FALSE, 0);
4037 entry = gtk_entry_new();
4038 gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
4039 gtk_box_pack_start(GTK_BOX(ret), entry, FALSE, FALSE, 0);
4040
4041 label = gtk_label_new(" ");
4042 gtk_box_pack_start(GTK_BOX(ret), label, FALSE, FALSE, 0);
4043
4044 bbox = gtk_hbutton_box_new();
4045 button = gtk_button_new_with_mnemonic(_("_Login"));
4046 gtk_box_pack_start(GTK_BOX(ret), bbox, FALSE, FALSE, 0);
4047 gtk_container_add(GTK_CONTAINER(bbox), button);
4048
4049
4050 label = gtk_label_new(NULL);
4051 gtk_box_pack_start(GTK_BOX(ret), label, TRUE, TRUE, 0);
4052
4053 gtk_container_set_border_width(GTK_CONTAINER(ret), GAIM_HIG_BORDER);
4054
4055 gtk_widget_show_all(ret);
4056 return ret;
4057 }
4058 #endif
4059
4060 static void gaim_gtk_blist_show(GaimBuddyList *list)
4061 {
4062 void *handle;
4063 GtkCellRenderer *rend;
4064 GtkTreeViewColumn *column;
4065 GtkWidget *menu;
4066 GtkWidget *ebox;
4067 GtkWidget *sw;
4068 GtkWidget *sep;
4069 GtkWidget *label;
4070 GList *accounts;
4071 char *pretty;
4072 GtkAccelGroup *accel_group;
4073 GtkTreeSelection *selection;
4074 GtkTargetEntry dte[] = {{"GAIM_BLIST_NODE", GTK_TARGET_SAME_APP, DRAG_ROW},
4075 {"application/x-im-contact", 0, DRAG_BUDDY},
4076 {"text/x-vcard", 0, DRAG_VCARD },
4077 {"text/uri-list", 0, DRAG_URI},
4078 {"text/plain", 0, DRAG_TEXT}};
4079 GtkTargetEntry ste[] = {{"GAIM_BLIST_NODE", GTK_TARGET_SAME_APP, DRAG_ROW},
4080 {"application/x-im-contact", 0, DRAG_BUDDY},
4081 {"text/x-vcard", 0, DRAG_VCARD }};
4082 if (gtkblist && gtkblist->window) {
4083 gaim_blist_set_visible(gaim_prefs_get_bool("/gaim/gtk/blist/list_visible"));
4084 return;
4085 }
4086
4087 gtkblist = GAIM_GTK_BLIST(list);
4088
4089 gtkblist->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4090 gtk_window_set_role(GTK_WINDOW(gtkblist->window), "buddy_list");
4091 gtk_window_set_title(GTK_WINDOW(gtkblist->window), _("Buddy List"));
4092 g_signal_connect(G_OBJECT(gtkblist->window), "focus-in-event",
4093 G_CALLBACK(blist_focus_cb), gtkblist);
4094 GTK_WINDOW(gtkblist->window)->allow_shrink = TRUE;
4095
4096 gtkblist->main_vbox = gtk_vbox_new(FALSE, 0);
4097 gtk_widget_show(gtkblist->main_vbox);
4098 gtk_container_add(GTK_CONTAINER(gtkblist->window), gtkblist->main_vbox);
4099
4100 g_signal_connect(G_OBJECT(gtkblist->window), "delete_event", G_CALLBACK(gtk_blist_delete_cb), NULL);
4101 g_signal_connect(G_OBJECT(gtkblist->window), "configure_event", G_CALLBACK(gtk_blist_configure_cb), NULL);
4102 g_signal_connect(G_OBJECT(gtkblist->window), "visibility_notify_event", G_CALLBACK(gtk_blist_visibility_cb), NULL);
4103 g_signal_connect(G_OBJECT(gtkblist->window), "window_state_event", G_CALLBACK(gtk_blist_window_state_cb), NULL);
4104 g_signal_connect(G_OBJECT(gtkblist->window), "key_press_event", G_CALLBACK(gtk_blist_window_key_press_cb), gtkblist);
4105 gtk_widget_add_events(gtkblist->window, GDK_VISIBILITY_NOTIFY_MASK);
4106
4107 /******************************* Menu bar *************************************/
4108 accel_group = gtk_accel_group_new();
4109 gtk_window_add_accel_group(GTK_WINDOW (gtkblist->window), accel_group);
4110 g_object_unref(accel_group);
4111 gtkblist->ift = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GaimMain>", accel_group);
4112 gtk_item_factory_set_translate_func(gtkblist->ift,
4113 (GtkTranslateFunc)item_factory_translate_func,
4114 NULL, NULL);
4115 gtk_item_factory_create_items(gtkblist->ift, sizeof(blist_menu) / sizeof(*blist_menu),
4116 blist_menu, NULL);
4117 gaim_gtk_load_accels();
4118 g_signal_connect(G_OBJECT(accel_group), "accel-changed",
4119 G_CALLBACK(gaim_gtk_save_accels_cb), NULL);
4120 menu = gtk_item_factory_get_widget(gtkblist->ift, "<GaimMain>");
4121 gtkblist->menutray = gaim_gtk_menu_tray_new();
4122 gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtkblist->menutray);
4123 gtk_widget_show(gtkblist->menutray);
4124 gtk_widget_show(menu);
4125 gtk_box_pack_start(GTK_BOX(gtkblist->main_vbox), menu, FALSE, FALSE, 0);
4126
4127 accountmenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Accounts"));
4128
4129
4130 /****************************** Notebook *************************************/
4131 gtkblist->notebook = gtk_notebook_new();
4132 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gtkblist->notebook), FALSE);
4133 gtk_notebook_set_show_border(GTK_NOTEBOOK(gtkblist->notebook), FALSE);
4134 gtk_box_pack_start(GTK_BOX(gtkblist->main_vbox), gtkblist->notebook, TRUE, TRUE, 0);
4135
4136 #if 0
4137 gtk_notebook_append_page(GTK_NOTEBOOK(gtkblist->notebook), kiosk_page(), NULL);
4138 #endif
4139
4140 /* Translators: Please maintain the use of -> and <- to refer to menu heirarchy */
4141 pretty = gaim_gtk_make_pretty_arrows(_("<span weight='bold' size='larger'>Welcome to Gaim!</span>\n\n"
4142
4143 "You have no accounts enabled. Enable your IM accounts from the "
4144 "<b>Accounts</b> window at <b>Accounts->Add/Edit</b>. Once you "
4145 "enable accounts, you'll be able to sign on, set your status, "
4146 "and talk to your friends."));
4147 label = gtk_label_new(NULL);
4148 gtk_widget_set_size_request(label, gaim_prefs_get_int("/gaim/gtk/blist/width") - 12, -1);
4149 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
4150 gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.2);
4151 gtk_label_set_markup(GTK_LABEL(label), pretty);
4152 g_free(pretty);
4153 gtk_notebook_append_page(GTK_NOTEBOOK(gtkblist->notebook),label, NULL);
4154 gtkblist->vbox = gtk_vbox_new(FALSE, 0);
4155 gtk_notebook_append_page(GTK_NOTEBOOK(gtkblist->notebook), gtkblist->vbox, NULL);
4156 gtk_widget_show_all(gtkblist->notebook);
4157 if ((accounts = gaim_accounts_get_all_active())) {
4158 g_list_free(accounts);
4159 gtk_notebook_set_current_page(GTK_NOTEBOOK(gtkblist->notebook), 1);
4160 }
4161
4162 ebox = gtk_event_box_new();
4163 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), ebox, FALSE, FALSE, 0);
4164 gtkblist->headline_hbox = gtk_hbox_new(FALSE, 3);
4165 gtk_container_set_border_width(GTK_CONTAINER(gtkblist->headline_hbox), 6);
4166 gtk_container_add(GTK_CONTAINER(ebox), gtkblist->headline_hbox);
4167 gtkblist->headline_image = gtk_image_new_from_pixbuf(NULL);
4168 gtk_misc_set_alignment(GTK_MISC(gtkblist->headline_image), 0.0, 0);
4169 gtkblist->headline_label = gtk_label_new(NULL);
4170 gtk_widget_set_size_request(gtkblist->headline_label,
4171 gaim_prefs_get_int("/gaim/gtk/blist/width")-25,-1);
4172 gtk_label_set_line_wrap(GTK_LABEL(gtkblist->headline_label), TRUE);
4173 gtk_box_pack_start(GTK_BOX(gtkblist->headline_hbox), gtkblist->headline_image, FALSE, FALSE, 0);
4174 gtk_box_pack_start(GTK_BOX(gtkblist->headline_hbox), gtkblist->headline_label, TRUE, TRUE, 0);
4175 g_signal_connect(gtkblist->headline_hbox,
4176 "style-set",
4177 G_CALLBACK(headline_style_set),
4178 NULL);
4179 g_signal_connect (gtkblist->headline_hbox,
4180 "expose_event",
4181 G_CALLBACK (paint_headline_hbox),
4182 NULL);
4183 gtk_widget_set_name(gtkblist->headline_hbox, "gtk-tooltips");
4184
4185 gtkblist->headline_close = gtk_widget_render_icon(ebox, GTK_STOCK_CLOSE, -1, NULL);
4186 if (gtkblist->headline_close) {
4187 GdkPixbuf *scale = gdk_pixbuf_scale_simple(gtkblist->headline_close,
4188 HEADLINE_CLOSE_SIZE, HEADLINE_CLOSE_SIZE, GDK_INTERP_BILINEAR);
4189 gdk_pixbuf_unref(gtkblist->headline_close);
4190 gtkblist->headline_close = scale;
4191 }
4192
4193 gtkblist->hand_cursor = gdk_cursor_new (GDK_HAND2);
4194 gtkblist->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR);
4195
4196 g_signal_connect(G_OBJECT(ebox), "enter-notify-event", G_CALLBACK(headline_box_enter_cb), gtkblist);
4197 g_signal_connect(G_OBJECT(ebox), "leave-notify-event", G_CALLBACK(headline_box_leave_cb), gtkblist);
4198 g_signal_connect(G_OBJECT(ebox), "button-press-event", G_CALLBACK(headline_box_press_cb), gtkblist);
4199 #if 0
4200 /* I couldn't get this to work. The idea was to draw the focus-border only
4201 * when hovering over the close image. So for now, the focus-border is
4202 * always there. -- sad */
4203 gtk_widget_set_events(ebox, gtk_widget_get_events(ebox) | GDK_POINTER_MOTION_HINT_MASK);
4204 g_signal_connect(G_OBJECT(ebox), "motion-notify-event", G_CALLBACK(headline_box_motion_cb), gtkblist);
4205 #endif
4206
4207 /****************************** GtkTreeView **********************************/
4208 sw = gtk_scrolled_window_new(NULL,NULL);
4209 gtk_widget_show(sw);
4210 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_NONE);
4211 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
4212
4213 gtkblist->treemodel = gtk_tree_store_new(BLIST_COLUMNS,
4214 GDK_TYPE_PIXBUF, /* Status icon */
4215 G_TYPE_BOOLEAN, /* Status icon visible */
4216 G_TYPE_STRING, /* Name */
4217 G_TYPE_STRING, /* Idle */
4218 G_TYPE_BOOLEAN, /* Idle visible */
4219 GDK_TYPE_PIXBUF, /* Buddy icon */
4220 G_TYPE_BOOLEAN, /* Buddy icon visible */
4221 G_TYPE_POINTER, /* Node */
4222 GDK_TYPE_COLOR, /* bgcolor */
4223 G_TYPE_BOOLEAN, /* Group expander */
4224 G_TYPE_BOOLEAN, /* Contact expander */
4225 G_TYPE_BOOLEAN); /* Contact expander visible */
4226
4227 gtkblist->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(gtkblist->treemodel));
4228
4229 gtk_widget_show(gtkblist->treeview);
4230 gtk_widget_set_name(gtkblist->treeview, "gaim_gtkblist_treeview");
4231 /* gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(gtkblist->treeview), TRUE); */
4232
4233 /* Set up selection stuff */
4234 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview));
4235 g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(gaim_gtk_blist_selection_changed), NULL);
4236
4237 /* Set up dnd */
4238 gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(gtkblist->treeview),
4239 GDK_BUTTON1_MASK, ste, 3,
4240 GDK_ACTION_COPY);
4241 gtk_tree_view_enable_model_drag_dest(GTK_TREE_VIEW(gtkblist->treeview),
4242 dte, 5,
4243 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4244
4245 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-received", G_CALLBACK(gaim_gtk_blist_drag_data_rcv_cb), NULL);
4246 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-get", G_CALLBACK(gaim_gtk_blist_drag_data_get_cb), NULL);
4247 #ifdef _WIN32
4248 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-begin", G_CALLBACK(gaim_gtk_blist_drag_begin), NULL);
4249 #endif
4250
4251 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-motion", G_CALLBACK(gaim_gtk_blist_drag_motion_cb), NULL);
4252
4253 /* Tooltips */
4254 g_signal_connect(G_OBJECT(gtkblist->treeview), "motion-notify-event", G_CALLBACK(gaim_gtk_blist_motion_cb), NULL);
4255 g_signal_connect(G_OBJECT(gtkblist->treeview), "leave-notify-event", G_CALLBACK(gaim_gtk_blist_leave_cb), NULL);
4256
4257 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(gtkblist->treeview), FALSE);
4258
4259 column = gtk_tree_view_column_new();
4260 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column);
4261 gtk_tree_view_column_set_visible(column, FALSE);
4262 gtk_tree_view_set_expander_column(GTK_TREE_VIEW(gtkblist->treeview), column);
4263
4264 gtkblist->text_column = column = gtk_tree_view_column_new ();
4265 rend = gaim_gtk_cell_renderer_expander_new();
4266 gtk_tree_view_column_pack_start(column, rend, FALSE);
4267 gtk_tree_view_column_set_attributes(column, rend,
4268 "expander-visible", GROUP_EXPANDER_COLUMN,
4269 #if GTK_CHECK_VERSION(2,6,0)
4270 "sensitive", GROUP_EXPANDER_COLUMN,
4271 "cell-background-gdk", BGCOLOR_COLUMN,
4272 #endif
4273 NULL);
4274
4275 rend = gaim_gtk_cell_renderer_expander_new();
4276 gtk_tree_view_column_pack_start(column, rend, FALSE);
4277 gtk_tree_view_column_set_attributes(column, rend,
4278 "expander-visible", CONTACT_EXPANDER_COLUMN,
4279 #if GTK_CHECK_VERSION(2,6,0)
4280 "sensitive", CONTACT_EXPANDER_COLUMN,
4281 "cell-background-gdk", BGCOLOR_COLUMN,
4282 #endif
4283 "visible", CONTACT_EXPANDER_VISIBLE_COLUMN,
4284 NULL);
4285
4286 rend = gtk_cell_renderer_pixbuf_new();
4287 gtk_tree_view_column_pack_start(column, rend, FALSE);
4288 gtk_tree_view_column_set_attributes(column, rend,
4289 "pixbuf", STATUS_ICON_COLUMN,
4290 "visible", STATUS_ICON_VISIBLE_COLUMN,
4291 #if GTK_CHECK_VERSION(2,6,0)
4292 "cell-background-gdk", BGCOLOR_COLUMN,
4293 #endif
4294 NULL);
4295 g_object_set(rend, "xalign", 0.0, "ypad", 0, NULL);
4296
4297 gtkblist->text_rend = rend = gtk_cell_renderer_text_new();
4298 gtk_tree_view_column_pack_start (column, rend, TRUE);
4299 gtk_tree_view_column_set_attributes(column, rend,
4300 #if GTK_CHECK_VERSION(2,6,0)
4301 "cell-background-gdk", BGCOLOR_COLUMN,
4302 #endif
4303 "markup", NAME_COLUMN,
4304 NULL);
4305 g_signal_connect(G_OBJECT(rend), "edited", G_CALLBACK(gtk_blist_renderer_edited_cb), NULL);
4306 g_object_set(rend, "ypad", 0, "yalign", 0.5, NULL);
4307 #if GTK_CHECK_VERSION(2,6,0)
4308 g_object_set(rend, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
4309 #endif
4310 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column);
4311
4312 rend = gtk_cell_renderer_text_new();
4313 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL);
4314 gtk_tree_view_column_pack_start(column, rend, FALSE);
4315 gtk_tree_view_column_set_attributes(column, rend,
4316 "markup", IDLE_COLUMN,
4317 "visible", IDLE_VISIBLE_COLUMN,
4318 #if GTK_CHECK_VERSION(2,6,0)
4319 "cell-background-gdk", BGCOLOR_COLUMN,
4320 #endif
4321 NULL);
4322
4323 rend = gtk_cell_renderer_pixbuf_new();
4324 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL);
4325 gtk_tree_view_column_pack_start(column, rend, FALSE);
4326 gtk_tree_view_column_set_attributes(column, rend, "pixbuf", BUDDY_ICON_COLUMN,
4327 #if GTK_CHECK_VERSION(2,6,0)
4328 "cell-background-gdk", BGCOLOR_COLUMN,
4329 #endif
4330 "visible", BUDDY_ICON_VISIBLE_COLUMN,
4331 NULL);
4332
4333
4334 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-activated", G_CALLBACK(gtk_blist_row_activated_cb), NULL);
4335 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-expanded", G_CALLBACK(gtk_blist_row_expanded_cb), NULL);
4336 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-collapsed", G_CALLBACK(gtk_blist_row_collapsed_cb), NULL);
4337 g_signal_connect(G_OBJECT(gtkblist->treeview), "button-press-event", G_CALLBACK(gtk_blist_button_press_cb), NULL);
4338 g_signal_connect(G_OBJECT(gtkblist->treeview), "key-press-event", G_CALLBACK(gtk_blist_key_press_cb), NULL);
4339 g_signal_connect(G_OBJECT(gtkblist->treeview), "popup-menu", G_CALLBACK(gaim_gtk_blist_popup_menu_cb), NULL);
4340
4341 /* Enable CTRL+F searching */
4342 gtk_tree_view_set_search_column(GTK_TREE_VIEW(gtkblist->treeview), NAME_COLUMN);
4343 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(gtkblist->treeview), gaim_gtk_tree_view_search_equal_func, NULL, NULL);
4344
4345 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), sw, TRUE, TRUE, 0);
4346 gtk_container_add(GTK_CONTAINER(sw), gtkblist->treeview);
4347
4348 sep = gtk_hseparator_new();
4349 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), sep, FALSE, FALSE, 0);
4350
4351 gtkblist->scrollbook = gtk_gaim_scroll_book_new();
4352 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtkblist->scrollbook, FALSE, FALSE, 0);
4353
4354 /* Create an empty vbox used for showing connection errors */
4355 gtkblist->error_buttons = gtk_vbox_new(FALSE, 0);
4356 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtkblist->error_buttons, FALSE, FALSE, 0);
4357
4358 /* Add the statusbox */
4359 gtkblist->statusbox = gtk_gaim_status_box_new();
4360 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtkblist->statusbox, FALSE, TRUE, 0);
4361 gtk_widget_set_name(gtkblist->statusbox, "gaim_gtkblist_statusbox");
4362 gtk_container_set_border_width(GTK_CONTAINER(gtkblist->statusbox), 3);
4363 gtk_widget_show(gtkblist->statusbox);
4364
4365 /* set the Show Offline Buddies option. must be done
4366 * after the treeview or faceprint gets mad. -Robot101
4367 */
4368 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Buddies/Show Offline Buddies"))),
4369 gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies"));
4370
4371 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Buddies/Show Empty Groups"))),
4372 gaim_prefs_get_bool("/gaim/gtk/blist/show_empty_groups"));
4373
4374 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Tools/Mute Sounds"))),
4375 gaim_prefs_get_bool("/gaim/gtk/sound/mute"));
4376
4377 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Buddies/Show Buddy Details"))),
4378 gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons"));
4379
4380 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Buddies/Show Idle Times"))),
4381 gaim_prefs_get_bool("/gaim/gtk/blist/show_idle_time"));
4382
4383 if(!strcmp(gaim_prefs_get_string("/gaim/gtk/sound/method"), "none"))
4384 gtk_widget_set_sensitive(gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Mute Sounds")), FALSE);
4385
4386 /* Update some dynamic things */
4387 update_menu_bar(gtkblist);
4388 gaim_gtk_blist_update_plugin_actions();
4389 gaim_gtk_blist_update_sort_methods();
4390
4391 /* OK... let's show this bad boy. */
4392 gaim_gtk_blist_refresh(list);
4393 gaim_gtk_blist_restore_position();
4394 gtk_widget_show_all(GTK_WIDGET(gtkblist->vbox));
4395 gtk_widget_realize(GTK_WIDGET(gtkblist->window));
4396 gaim_blist_set_visible(gaim_prefs_get_bool("/gaim/gtk/blist/list_visible"));
4397
4398 /* start the refresh timer */
4399 gtkblist->refresh_timer = g_timeout_add(30000, (GSourceFunc)gaim_gtk_blist_refresh_timer, list);
4400
4401 handle = gaim_gtk_blist_get_handle();
4402
4403 /* things that affect how buddies are displayed */
4404 gaim_prefs_connect_callback(handle, "/gaim/gtk/blist/show_buddy_icons",
4405 _prefs_change_redo_list, NULL);
4406 gaim_prefs_connect_callback(handle, "/gaim/gtk/blist/show_idle_time",
4407 _prefs_change_redo_list, NULL);
4408 gaim_prefs_connect_callback(handle, "/gaim/gtk/blist/show_empty_groups",
4409 _prefs_change_redo_list, NULL);
4410 gaim_prefs_connect_callback(handle, "/gaim/gtk/blist/show_offline_buddies",
4411 _prefs_change_redo_list, NULL);
4412
4413 /* sorting */
4414 gaim_prefs_connect_callback(handle, "/gaim/gtk/blist/sort_type",
4415 _prefs_change_sort_method, NULL);
4416
4417 /* menus */
4418 gaim_prefs_connect_callback(handle, "/gaim/gtk/sound/mute",
4419 gaim_gtk_blist_mute_pref_cb, NULL);
4420 gaim_prefs_connect_callback(handle, "/gaim/gtk/sound/method",
4421 gaim_gtk_blist_sound_method_pref_cb, NULL);
4422
4423 /* Setup some gaim signal handlers. */
4424 gaim_signal_connect(gaim_accounts_get_handle(), "account-enabled",
4425 gtkblist, GAIM_CALLBACK(account_modified), gtkblist);
4426 gaim_signal_connect(gaim_accounts_get_handle(), "account-disabled",
4427 gtkblist, GAIM_CALLBACK(account_modified), gtkblist);
4428 gaim_signal_connect(gaim_accounts_get_handle(), "account-removed",
4429 gtkblist, GAIM_CALLBACK(account_modified), gtkblist);
4430 gaim_signal_connect(gaim_accounts_get_handle(), "account-status-changed",
4431 gtkblist, GAIM_CALLBACK(account_status_changed), gtkblist);
4432
4433 gaim_signal_connect(gaim_gtk_account_get_handle(), "account-modified",
4434 gtkblist, GAIM_CALLBACK(account_modified), gtkblist);
4435
4436 gaim_signal_connect(gaim_connections_get_handle(), "signed-on",
4437 gtkblist, GAIM_CALLBACK(sign_on_off_cb), list);
4438 gaim_signal_connect(gaim_connections_get_handle(), "signed-off",
4439 gtkblist, GAIM_CALLBACK(sign_on_off_cb), list);
4440
4441 gaim_signal_connect(gaim_plugins_get_handle(), "plugin-load",
4442 gtkblist, GAIM_CALLBACK(plugin_changed_cb), NULL);
4443 gaim_signal_connect(gaim_plugins_get_handle(), "plugin-unload",
4444 gtkblist, GAIM_CALLBACK(plugin_changed_cb), NULL);
4445
4446 gaim_signal_connect(gaim_conversations_get_handle(), "conversation-updated",
4447 gtkblist, GAIM_CALLBACK(conversation_updated_cb),
4448 gtkblist);
4449 gaim_signal_connect(gaim_conversations_get_handle(), "deleting-conversation",
4450 gtkblist, GAIM_CALLBACK(conversation_deleting_cb),
4451 gtkblist);
4452
4453 // gtk_widget_hide(gtkblist->scrollbook);
4454 gtk_widget_hide(gtkblist->headline_hbox);
4455
4456 /* emit our created signal */
4457 gaim_signal_emit(handle, "gtkblist-created", list);
4458 }
4459
4460 static void redo_buddy_list(GaimBuddyList *list, gboolean remove, gboolean rerender)
4461 {
4462 GaimBlistNode *node;
4463
4464 gtkblist = GAIM_GTK_BLIST(list);
4465 if(!gtkblist || !gtkblist->treeview)
4466 return;
4467
4468 node = list->root;
4469
4470 while (node)
4471 {
4472 /* This is only needed when we're reverting to a non-GTK+ sorted
4473 * status. We shouldn't need to remove otherwise.
4474 */
4475 if (remove && !GAIM_BLIST_NODE_IS_GROUP(node))
4476 gaim_gtk_blist_hide_node(list, node, FALSE);
4477
4478 if (GAIM_BLIST_NODE_IS_BUDDY(node))
4479 gaim_gtk_blist_update_buddy(list, node, rerender);
4480 else if (GAIM_BLIST_NODE_IS_CHAT(node))
4481 gaim_gtk_blist_update(list, node);
4482 else if (GAIM_BLIST_NODE_IS_GROUP(node))
4483 gaim_gtk_blist_update(list, node);
4484 node = gaim_blist_node_next(node, FALSE);
4485 }
4486
4487 /* There is no hash table if there is nothing in the buddy list to update */
4488 if (status_icon_hash_table) {
4489 g_hash_table_destroy(status_icon_hash_table);
4490 status_icon_hash_table = NULL;
4491 }
4492
4493 }
4494
4495 void gaim_gtk_blist_refresh(GaimBuddyList *list)
4496 {
4497 redo_buddy_list(list, FALSE, TRUE);
4498 }
4499
4500 void
4501 gaim_gtk_blist_update_refresh_timeout()
4502 {
4503 GaimBuddyList *blist;
4504 GaimGtkBuddyList *gtkblist;
4505
4506 blist = gaim_get_blist();
4507 gtkblist = GAIM_GTK_BLIST(gaim_get_blist());
4508
4509 gtkblist->refresh_timer = g_timeout_add(30000,(GSourceFunc)gaim_gtk_blist_refresh_timer, blist);
4510 }
4511
4512 static gboolean get_iter_from_node(GaimBlistNode *node, GtkTreeIter *iter) {
4513 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data;
4514 GtkTreePath *path;
4515
4516 if (!gtknode) {
4517 return FALSE;
4518 }
4519
4520 if (!gtkblist) {
4521 gaim_debug_error("gtkblist", "get_iter_from_node was called, but we don't seem to have a blist\n");
4522 return FALSE;
4523 }
4524
4525 if (!gtknode->row)
4526 return FALSE;
4527
4528
4529 if ((path = gtk_tree_row_reference_get_path(gtknode->row)) == NULL)
4530 return FALSE;
4531
4532 if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), iter, path)) {
4533 gtk_tree_path_free(path);
4534 return FALSE;
4535 }
4536 gtk_tree_path_free(path);
4537 return TRUE;
4538 }
4539
4540 static void gaim_gtk_blist_remove(GaimBuddyList *list, GaimBlistNode *node)
4541 {
4542 struct _gaim_gtk_blist_node *gtknode = node->ui_data;
4543
4544 gaim_request_close_with_handle(node);
4545
4546 gaim_gtk_blist_hide_node(list, node, TRUE);
4547
4548 if(node->parent)
4549 gaim_gtk_blist_update(list, node->parent);
4550
4551 /* There's something I don't understand here - Ethan */
4552 /* Ethan said that back in 2003, but this g_free has been left commented
4553 * out ever since. I can't find any reason at all why this is bad and
4554 * valgrind found several reasons why it's good. If this causes problems
4555 * comment it out again. Stu */
4556 /* Of course it still causes problems - this breaks dragging buddies into
4557 * contacts, the dragged buddy mysteriously 'disappears'. Stu. */
4558 /* I think it's fixed now. Stu. */
4559
4560 if(gtknode) {
4561 if(gtknode->recent_signonoff_timer > 0)
4562 gaim_timeout_remove(gtknode->recent_signonoff_timer);
4563
4564 g_free(node->ui_data);
4565 node->ui_data = NULL;
4566 }
4567 }
4568
4569 static gboolean do_selection_changed(GaimBlistNode *new_selection)
4570 {
4571 GaimBlistNode *old_selection = NULL;
4572
4573 /* test for gtkblist because crazy timeout means we can be called after the blist is gone */
4574 if (gtkblist && new_selection != gtkblist->selected_node) {
4575 old_selection = gtkblist->selected_node;
4576 gtkblist->selected_node = new_selection;
4577 if(new_selection)
4578 gaim_gtk_blist_update(NULL, new_selection);
4579 if(old_selection)
4580 gaim_gtk_blist_update(NULL, old_selection);
4581 }
4582
4583 return FALSE;
4584 }
4585
4586 static void gaim_gtk_blist_selection_changed(GtkTreeSelection *selection, gpointer data)
4587 {
4588 GaimBlistNode *new_selection = NULL;
4589 GtkTreeIter iter;
4590
4591 if(gtk_tree_selection_get_selected(selection, NULL, &iter)){
4592 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter,
4593 NODE_COLUMN, &new_selection, -1);
4594 }
4595
4596 /* we set this up as a timeout, otherwise the blist flickers */
4597 g_timeout_add(0, (GSourceFunc)do_selection_changed, new_selection);
4598 }
4599
4600 static gboolean insert_node(GaimBuddyList *list, GaimBlistNode *node, GtkTreeIter *iter)
4601 {
4602 GtkTreeIter parent_iter, cur, *curptr = NULL;
4603 struct _gaim_gtk_blist_node *gtknode = node->ui_data;
4604 GtkTreePath *newpath;
4605
4606 if(!iter)
4607 return FALSE;
4608
4609 if(node->parent && !get_iter_from_node(node->parent, &parent_iter))
4610 return FALSE;
4611
4612 if(get_iter_from_node(node, &cur))
4613 curptr = &cur;
4614
4615 if(GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_CHAT(node)) {
4616 current_sort_method->func(node, list, parent_iter, curptr, iter);
4617 } else {
4618 sort_method_none(node, list, parent_iter, curptr, iter);
4619 }
4620
4621 if(gtknode != NULL) {
4622 gtk_tree_row_reference_free(gtknode->row);
4623 } else {
4624 gaim_gtk_blist_new_node(node);
4625 gtknode = (struct _gaim_gtk_blist_node *)node->ui_data;
4626 }
4627
4628 newpath = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel),
4629 iter);
4630 gtknode->row =
4631 gtk_tree_row_reference_new(GTK_TREE_MODEL(gtkblist->treemodel),
4632 newpath);
4633
4634 gtk_tree_path_free(newpath);
4635
4636 gtk_tree_store_set(gtkblist->treemodel, iter,
4637 NODE_COLUMN, node,
4638 -1);
4639
4640 if(node->parent) {
4641 GtkTreePath *expand = NULL;
4642 struct _gaim_gtk_blist_node *gtkparentnode = node->parent->ui_data;
4643
4644 if(GAIM_BLIST_NODE_IS_GROUP(node->parent)) {
4645 if(!gaim_blist_node_get_bool(node->parent, "collapsed"))
4646 expand = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &parent_iter);
4647 } else if(GAIM_BLIST_NODE_IS_CONTACT(node->parent) &&
4648 gtkparentnode->contact_expanded) {
4649 expand = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &parent_iter);
4650 }
4651 if(expand) {
4652 gtk_tree_view_expand_row(GTK_TREE_VIEW(gtkblist->treeview), expand, FALSE);
4653 gtk_tree_path_free(expand);
4654 }
4655 }
4656
4657 return TRUE;
4658 }
4659
4660 /*This version of gaim_gtk_blist_update_group can take the original buddy
4661 or a group, but has much better algorithmic performance with a pre-known buddy*/
4662 static void gaim_gtk_blist_update_group(GaimBuddyList *list, GaimBlistNode *node)
4663 {
4664 GaimGroup *group;
4665 int count;
4666 gboolean show = FALSE;
4667 GaimBlistNode* gnode;
4668
4669 g_return_if_fail(node != NULL);
4670
4671 if (GAIM_BLIST_NODE_IS_GROUP(node))
4672 gnode = node;
4673 else if (GAIM_BLIST_NODE_IS_BUDDY(node))
4674 gnode = node->parent->parent;
4675 else if (GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_CHAT(node))
4676 gnode = node->parent;
4677 else
4678 return;
4679
4680 group = (GaimGroup*)gnode;
4681
4682 if(gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies"))
4683 count = gaim_blist_get_group_size(group, FALSE);
4684 else
4685 count = gaim_blist_get_group_online_count(group);
4686
4687 if (count > 0 || gaim_prefs_get_bool("/gaim/gtk/blist/show_empty_groups"))
4688 show = TRUE;
4689 else if (GAIM_BLIST_NODE_IS_BUDDY(node)){ /* Or chat? */
4690 if (buddy_is_displayable((GaimBuddy*)node))
4691 show = TRUE;}
4692
4693 if (show) {
4694 GtkTreeIter iter;
4695 GtkTreePath *path;
4696 gboolean expanded;
4697 GdkColor bgcolor;
4698 char *title;
4699
4700
4701 if(!insert_node(list, gnode, &iter))
4702 return;
4703
4704 bgcolor = gtkblist->treeview->style->bg[GTK_STATE_ACTIVE];
4705
4706 path = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &iter);
4707 expanded = gtk_tree_view_row_expanded(GTK_TREE_VIEW(gtkblist->treeview), path);
4708 gtk_tree_path_free(path);
4709
4710 title = gaim_get_group_title(gnode, expanded);
4711
4712 gtk_tree_store_set(gtkblist->treemodel, &iter,
4713 STATUS_ICON_VISIBLE_COLUMN, FALSE,
4714 STATUS_ICON_COLUMN, NULL,
4715 NAME_COLUMN, title,
4716 NODE_COLUMN, gnode,
4717 BGCOLOR_COLUMN, &bgcolor,
4718 GROUP_EXPANDER_COLUMN, TRUE,
4719 CONTACT_EXPANDER_VISIBLE_COLUMN, FALSE,
4720 BUDDY_ICON_VISIBLE_COLUMN, FALSE,
4721 IDLE_VISIBLE_COLUMN, FALSE,
4722 -1);
4723 g_free(title);
4724 } else {
4725 gaim_gtk_blist_hide_node(list, gnode, TRUE);
4726 }
4727 }
4728
4729 static char *gaim_get_group_title(GaimBlistNode *gnode, gboolean expanded)
4730 {
4731 GaimGroup *group;
4732 GdkColor textcolor;
4733 gboolean selected;
4734 char group_count[12] = "";
4735 char *mark, *esc;
4736
4737 group = (GaimGroup*)gnode;
4738 textcolor = gtkblist->treeview->style->fg[GTK_STATE_ACTIVE];
4739 selected = gtkblist ? (gtkblist->selected_node == gnode) : FALSE;
4740
4741 if (!expanded) {
4742 g_snprintf(group_count, sizeof(group_count), " (%d/%d)",
4743 gaim_blist_get_group_online_count(group),
4744 gaim_blist_get_group_size(group, FALSE));
4745 }
4746
4747 esc = g_markup_escape_text(group->name, -1);
4748 if (selected)
4749 mark = g_strdup_printf("<span weight='bold'>%s</span>%s", esc, group_count);
4750 else
4751 mark = g_strdup_printf("<span color='#%02x%02x%02x' weight='bold'>%s</span>%s",
4752 textcolor.red>>8, textcolor.green>>8, textcolor.blue>>8,
4753 esc, group_count);
4754
4755 g_free(esc);
4756 return mark;
4757 }
4758
4759 static void buddy_node(GaimBuddy *buddy, GtkTreeIter *iter, GaimBlistNode *node)
4760 {
4761 GaimPresence *presence;
4762 GdkPixbuf *status, *avatar;
4763 char *mark;
4764 char *idle = NULL;
4765 gboolean expanded = ((struct _gaim_gtk_blist_node *)(node->parent->ui_data))->contact_expanded;
4766 gboolean selected = (gtkblist->selected_node == node);
4767 gboolean biglist = gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons");
4768 presence = gaim_buddy_get_presence(buddy);
4769
4770 status = gaim_gtk_blist_get_status_icon((GaimBlistNode*)buddy,
4771 biglist ? GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL);
4772
4773 avatar = gaim_gtk_blist_get_buddy_icon((GaimBlistNode *)buddy, TRUE, TRUE, TRUE);
4774 mark = gaim_gtk_blist_get_name_markup(buddy, selected);
4775
4776 if (gaim_prefs_get_bool("/gaim/gtk/blist/show_idle_time") &&
4777 gaim_presence_is_idle(presence) &&
4778 !gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons"))
4779 {
4780 time_t idle_secs = gaim_presence_get_idle_time(presence);
4781
4782 if (idle_secs > 0)
4783 {
4784 time_t t;
4785 int ihrs, imin;
4786 time(&t);
4787 ihrs = (t - idle_secs) / 3600;
4788 imin = ((t - idle_secs) / 60) % 60;
4789 idle = g_strdup_printf("%d:%02d", ihrs, imin);
4790 }
4791 }
4792
4793 if (gaim_presence_is_idle(presence))
4794 {
4795 if (idle && !selected) {
4796 char *i2 = g_strdup_printf("<span color='%s'>%s</span>",
4797 dim_grey(), idle);
4798 g_free(idle);
4799 idle = i2;
4800 }
4801 }
4802
4803 gtk_tree_store_set(gtkblist->treemodel, iter,
4804 STATUS_ICON_COLUMN, status,
4805 STATUS_ICON_VISIBLE_COLUMN, TRUE,
4806 NAME_COLUMN, mark,
4807 IDLE_COLUMN, idle,
4808 IDLE_VISIBLE_COLUMN, !biglist && idle,
4809 BUDDY_ICON_COLUMN, avatar,
4810 BUDDY_ICON_VISIBLE_COLUMN, biglist,
4811 BGCOLOR_COLUMN, NULL,
4812 CONTACT_EXPANDER_COLUMN, NULL,
4813 CONTACT_EXPANDER_VISIBLE_COLUMN, expanded,
4814 -1);
4815
4816 g_free(mark);
4817 g_free(idle);
4818 if(status)
4819 g_object_unref(status);
4820 if(avatar)
4821 g_object_unref(avatar);
4822 }
4823
4824 /* This is a variation on the original gtk_blist_update_contact. Here we
4825 can know in advance which buddy has changed so we can just update that */
4826 static void gaim_gtk_blist_update_contact(GaimBuddyList *list, GaimBlistNode *node)
4827 {
4828 GaimBlistNode *cnode;
4829 GaimContact *contact;
4830 GaimBuddy *buddy;
4831 struct _gaim_gtk_blist_node *gtknode;
4832
4833 if (GAIM_BLIST_NODE_IS_BUDDY(node))
4834 cnode = node->parent;
4835 else
4836 cnode = node;
4837
4838 g_return_if_fail(GAIM_BLIST_NODE_IS_CONTACT(cnode));
4839
4840 /* First things first, update the group */
4841 if (GAIM_BLIST_NODE_IS_BUDDY(node))
4842 gaim_gtk_blist_update_group(list, node);
4843 else
4844 gaim_gtk_blist_update_group(list, cnode->parent);
4845
4846 contact = (GaimContact*)cnode;
4847 buddy = gaim_contact_get_priority_buddy(contact);
4848
4849 if (buddy_is_displayable(buddy))
4850 {
4851 GtkTreeIter iter;
4852
4853 if(!insert_node(list, cnode, &iter))
4854 return;
4855
4856 gtknode = (struct _gaim_gtk_blist_node *)cnode->ui_data;
4857
4858 if(gtknode->contact_expanded) {
4859 GdkPixbuf *status;
4860 char *mark;
4861
4862 status = gaim_gtk_blist_get_status_icon(cnode,
4863 (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons") ?
4864 GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL));
4865
4866 mark = g_markup_escape_text(gaim_contact_get_alias(contact), -1);
4867 gtk_tree_store_set(gtkblist->treemodel, &iter,
4868 STATUS_ICON_COLUMN, status,
4869 STATUS_ICON_VISIBLE_COLUMN, TRUE,
4870 NAME_COLUMN, mark,
4871 IDLE_COLUMN, NULL,
4872 IDLE_VISIBLE_COLUMN, FALSE,
4873 BGCOLOR_COLUMN, NULL,
4874 BUDDY_ICON_COLUMN, NULL,
4875 CONTACT_EXPANDER_COLUMN, TRUE,
4876 CONTACT_EXPANDER_VISIBLE_COLUMN, TRUE,
4877 -1);
4878 g_free(mark);
4879 if(status)
4880 g_object_unref(status);
4881 } else {
4882 buddy_node(buddy, &iter, cnode);
4883 }
4884 } else {
4885 gaim_gtk_blist_hide_node(list, cnode, TRUE);
4886 }
4887 }
4888
4889
4890
4891 static void gaim_gtk_blist_update_buddy(GaimBuddyList *list, GaimBlistNode *node, gboolean statusChange)
4892 {
4893 GaimBuddy *buddy;
4894 struct _gaim_gtk_blist_node *gtkparentnode;
4895 struct _gaim_gtk_blist_node *gtknode = node->ui_data;
4896
4897 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
4898
4899 if (node->parent == NULL)
4900 return;
4901
4902 buddy = (GaimBuddy*)node;
4903
4904 if (statusChange)
4905 gaim_gtk_blist_update_buddy_status_icon_key(gtknode, buddy,
4906 (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")
4907 ? GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL));
4908
4909 /* First things first, update the contact */
4910 gaim_gtk_blist_update_contact(list, node);
4911
4912 gtkparentnode = (struct _gaim_gtk_blist_node *)node->parent->ui_data;
4913
4914 if (gtkparentnode->contact_expanded && buddy_is_displayable(buddy))
4915 {
4916 GtkTreeIter iter;
4917
4918 if (!insert_node(list, node, &iter))
4919 return;
4920
4921 buddy_node(buddy, &iter, node);
4922
4923 } else {
4924 gaim_gtk_blist_hide_node(list, node, TRUE);
4925 }
4926
4927 }
4928
4929 static void gaim_gtk_blist_update_chat(GaimBuddyList *list, GaimBlistNode *node)
4930 {
4931 GaimChat *chat;
4932
4933 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
4934
4935 /* First things first, update the group */
4936 gaim_gtk_blist_update_group(list, node->parent);
4937
4938 chat = (GaimChat*)node;
4939
4940 if(gaim_account_is_connected(chat->account)) {
4941 GtkTreeIter iter;
4942 GdkPixbuf *status;
4943 char *mark;
4944
4945 if(!insert_node(list, node, &iter))
4946 return;
4947
4948 status = gaim_gtk_blist_get_status_icon(node,
4949 (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons") ?
4950 GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL));
4951
4952 mark = g_markup_escape_text(gaim_chat_get_name(chat), -1);
4953
4954 gtk_tree_store_set(gtkblist->treemodel, &iter,
4955 STATUS_ICON_COLUMN, status,
4956 STATUS_ICON_VISIBLE_COLUMN, TRUE,
4957 NAME_COLUMN, mark,
4958 -1);
4959
4960 g_free(mark);
4961 if(status)
4962 g_object_unref(status);
4963 } else {
4964 gaim_gtk_blist_hide_node(list, node, TRUE);
4965 }
4966 }
4967
4968 static void gaim_gtk_blist_update(GaimBuddyList *list, GaimBlistNode *node)
4969 {
4970 if (list)
4971 gtkblist = GAIM_GTK_BLIST(list);
4972 if(!gtkblist || !gtkblist->treeview || !node)
4973 return;
4974
4975 if (node->ui_data == NULL)
4976 gaim_gtk_blist_new_node(node);
4977
4978 switch(node->type) {
4979 case GAIM_BLIST_GROUP_NODE:
4980 gaim_gtk_blist_update_group(list, node);
4981 break;
4982 case GAIM_BLIST_CONTACT_NODE:
4983 gaim_gtk_blist_update_contact(list, node);
4984 break;
4985 case GAIM_BLIST_BUDDY_NODE:
4986 gaim_gtk_blist_update_buddy(list, node, TRUE);
4987 break;
4988 case GAIM_BLIST_CHAT_NODE:
4989 gaim_gtk_blist_update_chat(list, node);
4990 break;
4991 case GAIM_BLIST_OTHER_NODE:
4992 return;
4993 }
4994
4995 #if !GTK_CHECK_VERSION(2,6,0)
4996 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(gtkblist->treeview));
4997 #endif
4998 }
4999
5000
5001 static void gaim_gtk_blist_destroy(GaimBuddyList *list)
5002 {
5003 if (!gtkblist)
5004 return;
5005
5006 gaim_signals_disconnect_by_handle(gtkblist);
5007
5008 if (gtkblist->headline_close)
5009 gdk_pixbuf_unref(gtkblist->headline_close);
5010
5011 gtk_widget_destroy(gtkblist->window);
5012
5013 gaim_gtk_blist_tooltip_destroy();
5014
5015 if (gtkblist->refresh_timer)
5016 g_source_remove(gtkblist->refresh_timer);
5017 if (gtkblist->timeout)
5018 g_source_remove(gtkblist->timeout);
5019 if (gtkblist->drag_timeout)
5020 g_source_remove(gtkblist->drag_timeout);
5021
5022 g_hash_table_destroy(gtkblist->connection_errors);
5023 gtkblist->refresh_timer = 0;
5024 gtkblist->timeout = 0;
5025 gtkblist->drag_timeout = 0;
5026 gtkblist->window = gtkblist->vbox = gtkblist->treeview = NULL;
5027 gtkblist->treemodel = NULL;
5028 g_object_unref(G_OBJECT(gtkblist->ift));
5029
5030 gdk_cursor_unref(gtkblist->hand_cursor);
5031 gdk_cursor_unref(gtkblist->arrow_cursor);
5032 gtkblist->hand_cursor = NULL;
5033 gtkblist->arrow_cursor = NULL;
5034
5035 g_free(gtkblist);
5036 accountmenu = NULL;
5037 gtkblist = NULL;
5038 gaim_prefs_disconnect_by_handle(gaim_gtk_blist_get_handle());
5039 }
5040
5041 static void gaim_gtk_blist_set_visible(GaimBuddyList *list, gboolean show)
5042 {
5043 if (!(gtkblist && gtkblist->window))
5044 return;
5045
5046 if (show) {
5047 if(!GAIM_WINDOW_ICONIFIED(gtkblist->window) && !GTK_WIDGET_VISIBLE(gtkblist->window))
5048 gaim_signal_emit(gaim_gtk_blist_get_handle(), "gtkblist-unhiding", gtkblist);
5049 gaim_gtk_blist_restore_position();
5050 gtk_window_present(GTK_WINDOW(gtkblist->window));
5051 } else {
5052 if(visibility_manager_count) {
5053 gaim_signal_emit(gaim_gtk_blist_get_handle(), "gtkblist-hiding", gtkblist);
5054 gtk_widget_hide(gtkblist->window);
5055 } else {
5056 if (!GTK_WIDGET_VISIBLE(gtkblist->window))
5057 gtk_widget_show(gtkblist->window);
5058 gtk_window_iconify(GTK_WINDOW(gtkblist->window));
5059 }
5060 }
5061 }
5062
5063 static GList *
5064 groups_tree(void)
5065 {
5066 GList *tmp = NULL;
5067 char *tmp2;
5068 GaimGroup *g;
5069 GaimBlistNode *gnode;
5070
5071 if (gaim_get_blist()->root == NULL)
5072 {
5073 tmp2 = g_strdup(_("Buddies"));
5074 tmp = g_list_append(tmp, tmp2);
5075 }
5076 else
5077 {
5078 for (gnode = gaim_get_blist()->root;
5079 gnode != NULL;
5080 gnode = gnode->next)
5081 {
5082 if (GAIM_BLIST_NODE_IS_GROUP(gnode))
5083 {
5084 g = (GaimGroup *)gnode;
5085 tmp2 = g->name;
5086 tmp = g_list_append(tmp, tmp2);
5087 }
5088 }
5089 }
5090
5091 return tmp;
5092 }
5093
5094 static void
5095 add_buddy_select_account_cb(GObject *w, GaimAccount *account,
5096 GaimGtkAddBuddyData *data)
5097 {
5098 /* Save our account */
5099 data->account = account;
5100 }
5101
5102 static void
5103 destroy_add_buddy_dialog_cb(GtkWidget *win, GaimGtkAddBuddyData *data)
5104 {
5105 g_free(data);
5106 }
5107
5108 static void
5109 add_buddy_cb(GtkWidget *w, int resp, GaimGtkAddBuddyData *data)
5110 {
5111 const char *grp, *who, *whoalias;
5112 GaimGroup *g;
5113 GaimBuddy *b;
5114 GaimConversation *c;
5115 GaimBuddyIcon *icon;
5116
5117 if (resp == GTK_RESPONSE_OK)
5118 {
5119 who = gtk_entry_get_text(GTK_ENTRY(data->entry));
5120 grp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(data->combo)->entry));
5121 whoalias = gtk_entry_get_text(GTK_ENTRY(data->entry_for_alias));
5122 if (*whoalias == '\0')
5123 whoalias = NULL;
5124
5125 if ((g = gaim_find_group(grp)) == NULL)
5126 {
5127 g = gaim_group_new(grp);
5128 gaim_blist_add_group(g, NULL);
5129 }
5130
5131 b = gaim_buddy_new(data->account, who, whoalias);
5132 gaim_blist_add_buddy(b, NULL, g, NULL);
5133 gaim_account_add_buddy(data->account, b);
5134
5135 /*
5136 * XXX
5137 * It really seems like it would be better if the call to
5138 * gaim_account_add_buddy() and gaim_conversation_update() were done in
5139 * blist.c, possibly in the gaim_blist_add_buddy() function. Maybe
5140 * gaim_account_add_buddy() should be renamed to
5141 * gaim_blist_add_new_buddy() or something, and have it call
5142 * gaim_blist_add_buddy() after it creates it. --Mark
5143 *
5144 * No that's not good. blist.c should only deal with adding nodes to the
5145 * local list. We need a new, non-gtk file that calls both
5146 * gaim_account_add_buddy and gaim_blist_add_buddy().
5147 * Or something. --Mark
5148 */
5149
5150 c = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, who, data->account);
5151 if (c != NULL) {
5152 icon = gaim_conv_im_get_icon(GAIM_CONV_IM(c));
5153 if (icon != NULL)
5154 gaim_buddy_icon_update(icon);
5155 }
5156 }
5157
5158 gtk_widget_destroy(data->window);
5159 }
5160
5161 static void
5162 gaim_gtk_blist_request_add_buddy(GaimAccount *account, const char *username,
5163 const char *group, const char *alias)
5164 {
5165 GtkWidget *table;
5166 GtkWidget *label;
5167 GtkWidget *hbox;
5168 GtkWidget *vbox;
5169 GtkWidget *img;
5170 GaimGtkBuddyList *gtkblist;
5171 GaimGtkAddBuddyData *data = g_new0(GaimGtkAddBuddyData, 1);
5172
5173 data->account =
5174 (account != NULL
5175 ? account
5176 : gaim_connection_get_account(gaim_connections_get_all()->data));
5177
5178 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION,
5179 GTK_ICON_SIZE_DIALOG);
5180
5181 gtkblist = GAIM_GTK_BLIST(gaim_get_blist());
5182
5183 data->window = gtk_dialog_new_with_buttons(_("Add Buddy"),
5184 NULL, GTK_DIALOG_NO_SEPARATOR,
5185 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
5186 GTK_STOCK_ADD, GTK_RESPONSE_OK,
5187 NULL);
5188
5189 gtk_dialog_set_default_response(GTK_DIALOG(data->window), GTK_RESPONSE_OK);
5190 gtk_container_set_border_width(GTK_CONTAINER(data->window), GAIM_HIG_BOX_SPACE);
5191 gtk_window_set_resizable(GTK_WINDOW(data->window), FALSE);
5192 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(data->window)->vbox), GAIM_HIG_BORDER);
5193 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), GAIM_HIG_BOX_SPACE);
5194 gtk_window_set_role(GTK_WINDOW(data->window), "add_buddy");
5195 gtk_window_set_type_hint(GTK_WINDOW(data->window),
5196 GDK_WINDOW_TYPE_HINT_DIALOG);
5197
5198 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BORDER);
5199 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), hbox);
5200 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
5201 gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
5202
5203 vbox = gtk_vbox_new(FALSE, 0);
5204 gtk_container_add(GTK_CONTAINER(hbox), vbox);
5205
5206 label = gtk_label_new(
5207 _("Please enter the screen name of the person you would like "
5208 "to add to your buddy list. You may optionally enter an alias, "
5209 "or nickname, for the buddy. The alias will be displayed in "
5210 "place of the screen name whenever possible.\n"));
5211
5212 gtk_widget_set_size_request(GTK_WIDGET(label), 400, -1);
5213 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
5214 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
5215 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
5216
5217 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE);
5218 gtk_container_add(GTK_CONTAINER(vbox), hbox);
5219
5220 g_signal_connect(G_OBJECT(data->window), "destroy",
5221 G_CALLBACK(destroy_add_buddy_dialog_cb), data);
5222
5223 table = gtk_table_new(4, 2, FALSE);
5224 gtk_table_set_row_spacings(GTK_TABLE(table), 5);
5225 gtk_table_set_col_spacings(GTK_TABLE(table), 5);
5226 gtk_container_set_border_width(GTK_CONTAINER(table), 0);
5227 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5228
5229 label = gtk_label_new(_("Screen name:"));
5230 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5231 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
5232
5233 data->entry = gtk_entry_new();
5234 gtk_table_attach_defaults(GTK_TABLE(table), data->entry, 1, 2, 0, 1);
5235 gtk_widget_grab_focus(data->entry);
5236
5237 if (username != NULL)
5238 gtk_entry_set_text(GTK_ENTRY(data->entry), username);
5239 else
5240 gtk_dialog_set_response_sensitive(GTK_DIALOG(data->window),
5241 GTK_RESPONSE_OK, FALSE);
5242
5243 gtk_entry_set_activates_default (GTK_ENTRY(data->entry), TRUE);
5244 gaim_set_accessible_label (data->entry, label);
5245
5246 g_signal_connect(G_OBJECT(data->entry), "changed",
5247 G_CALLBACK(gaim_gtk_set_sensitive_if_input),
5248 data->window);
5249
5250 label = gtk_label_new(_("Alias:"));
5251 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5252 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
5253
5254 data->entry_for_alias = gtk_entry_new();
5255 gtk_table_attach_defaults(GTK_TABLE(table),
5256 data->entry_for_alias, 1, 2, 1, 2);
5257
5258 if (alias != NULL)
5259 gtk_entry_set_text(GTK_ENTRY(data->entry_for_alias), alias);
5260
5261 if (username != NULL)
5262 gtk_widget_grab_focus(GTK_WIDGET(data->entry_for_alias));
5263
5264 gtk_entry_set_activates_default (GTK_ENTRY(data->entry_for_alias), TRUE);
5265 gaim_set_accessible_label (data->entry_for_alias, label);
5266
5267 label = gtk_label_new(_("Group:"));
5268 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5269 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3);
5270
5271 data->combo = gtk_combo_new();
5272 gtk_combo_set_popdown_strings(GTK_COMBO(data->combo), groups_tree());
5273 gtk_table_attach_defaults(GTK_TABLE(table), data->combo, 1, 2, 2, 3);
5274 gaim_set_accessible_label (data->combo, label);
5275
5276 /* Set up stuff for the account box */
5277 label = gtk_label_new(_("Account:"));
5278 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5279 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4);
5280
5281 data->account_box = gaim_gtk_account_option_menu_new(account, FALSE,
5282 G_CALLBACK(add_buddy_select_account_cb), NULL, data);
5283
5284 gtk_table_attach_defaults(GTK_TABLE(table), data->account_box, 1, 2, 3, 4);
5285 gaim_set_accessible_label (data->account_box, label);
5286 /* End of account box */
5287
5288 g_signal_connect(G_OBJECT(data->window), "response",
5289 G_CALLBACK(add_buddy_cb), data);
5290
5291 gtk_widget_show_all(data->window);
5292
5293 if (group != NULL)
5294 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(data->combo)->entry), group);
5295 }
5296
5297 static void
5298 add_chat_cb(GtkWidget *w, GaimGtkAddChatData *data)
5299 {
5300 GHashTable *components;
5301 GList *tmp;
5302 GaimChat *chat;
5303 GaimGroup *group;
5304 const char *group_name;
5305 const char *value;
5306
5307 components = g_hash_table_new_full(g_str_hash, g_str_equal,
5308 g_free, g_free);
5309
5310 for (tmp = data->entries; tmp; tmp = tmp->next)
5311 {
5312 if (g_object_get_data(tmp->data, "is_spin"))
5313 {
5314 g_hash_table_replace(components,
5315 g_strdup(g_object_get_data(tmp->data, "identifier")),
5316 g_strdup_printf("%d",
5317 gtk_spin_button_get_value_as_int(tmp->data)));
5318 }
5319 else
5320 {
5321 value = gtk_entry_get_text(tmp->data);
5322 if (*value != '\0')
5323 g_hash_table_replace(components,
5324 g_strdup(g_object_get_data(tmp->data, "identifier")),
5325 g_strdup(value));
5326 }
5327 }
5328
5329 chat = gaim_chat_new(data->account,
5330 gtk_entry_get_text(GTK_ENTRY(data->alias_entry)),
5331 components);
5332
5333 group_name = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(data->group_combo)->entry));
5334
5335 if ((group = gaim_find_group(group_name)) == NULL)
5336 {
5337 group = gaim_group_new(group_name);
5338 gaim_blist_add_group(group, NULL);
5339 }
5340
5341 if (chat != NULL)
5342 {
5343 gaim_blist_add_chat(chat, group, NULL);
5344 }
5345
5346 gtk_widget_destroy(data->window);
5347 g_free(data->default_chat_name);
5348 g_list_free(data->entries);
5349 g_free(data);
5350 }
5351
5352 static void
5353 add_chat_resp_cb(GtkWidget *w, int resp, GaimGtkAddChatData *data)
5354 {
5355 if (resp == GTK_RESPONSE_OK)
5356 {
5357 add_chat_cb(NULL, data);
5358 }
5359 else
5360 {
5361 gtk_widget_destroy(data->window);
5362 g_free(data->default_chat_name);
5363 g_list_free(data->entries);
5364 g_free(data);
5365 }
5366 }
5367
5368 /*
5369 * Check the values of all the text entry boxes. If any required input
5370 * strings are empty then don't allow the user to click on "OK."
5371 */
5372 static void
5373 addchat_set_sensitive_if_input_cb(GtkWidget *entry, gpointer user_data)
5374 {
5375 GaimGtkAddChatData *data;
5376 GList *tmp;
5377 const char *text;
5378 gboolean required;
5379 gboolean sensitive = TRUE;
5380
5381 data = user_data;
5382
5383 for (tmp = data->entries; tmp != NULL; tmp = tmp->next)
5384 {
5385 if (!g_object_get_data(tmp->data, "is_spin"))
5386 {
5387 required = GPOINTER_TO_INT(g_object_get_data(tmp->data, "required"));
5388 text = gtk_entry_get_text(tmp->data);
5389 if (required && (*text == '\0'))
5390 sensitive = FALSE;
5391 }
5392 }
5393
5394 gtk_dialog_set_response_sensitive(GTK_DIALOG(data->window), GTK_RESPONSE_OK, sensitive);
5395 }
5396
5397 static void
5398 rebuild_addchat_entries(GaimGtkAddChatData *data)
5399 {
5400 GaimConnection *gc;
5401 GList *list = NULL, *tmp;
5402 GHashTable *defaults = NULL;
5403 struct proto_chat_entry *pce;
5404 gboolean focus = TRUE;
5405
5406 g_return_if_fail(data->account != NULL);
5407
5408 gc = gaim_account_get_connection(data->account);
5409
5410 while ((tmp = gtk_container_get_children(GTK_CONTAINER(data->entries_box))))
5411 gtk_widget_destroy(tmp->data);
5412
5413 g_list_free(data->entries);
5414
5415 data->entries = NULL;
5416
5417 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info != NULL)
5418 list = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info(gc);
5419
5420 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults != NULL)
5421 defaults = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, data->default_chat_name);
5422
5423 for (tmp = list; tmp; tmp = tmp->next)
5424 {
5425 GtkWidget *label;
5426 GtkWidget *rowbox;
5427 GtkWidget *input;
5428
5429 pce = tmp->data;
5430
5431 rowbox = gtk_hbox_new(FALSE, 5);
5432 gtk_box_pack_start(GTK_BOX(data->entries_box), rowbox, FALSE, FALSE, 0);
5433
5434 label = gtk_label_new_with_mnemonic(pce->label);
5435 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5436 gtk_size_group_add_widget(data->sg, label);
5437 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0);
5438
5439 if (pce->is_int)
5440 {
5441 GtkObject *adjust;
5442 adjust = gtk_adjustment_new(pce->min, pce->min, pce->max,
5443 1, 10, 10);
5444 input = gtk_spin_button_new(GTK_ADJUSTMENT(adjust), 1, 0);
5445 gtk_widget_set_size_request(input, 50, -1);
5446 gtk_box_pack_end(GTK_BOX(rowbox), input, FALSE, FALSE, 0);
5447 }
5448 else
5449 {
5450 char *value;
5451 input = gtk_entry_new();
5452 gtk_entry_set_activates_default(GTK_ENTRY(input), TRUE);
5453 value = g_hash_table_lookup(defaults, pce->identifier);
5454 if (value != NULL)
5455 gtk_entry_set_text(GTK_ENTRY(input), value);
5456 if (pce->secret)
5457 {
5458 gtk_entry_set_visibility(GTK_ENTRY(input), FALSE);
5459 if (gtk_entry_get_invisible_char(GTK_ENTRY(input)) == '*')
5460 gtk_entry_set_invisible_char(GTK_ENTRY(input), GAIM_INVISIBLE_CHAR);
5461 }
5462 gtk_box_pack_end(GTK_BOX(rowbox), input, TRUE, TRUE, 0);
5463 g_signal_connect(G_OBJECT(input), "changed",
5464 G_CALLBACK(addchat_set_sensitive_if_input_cb), data);
5465 }
5466
5467 /* Do the following for any type of input widget */
5468 if (focus)
5469 {
5470 gtk_widget_grab_focus(input);
5471 focus = FALSE;
5472 }
5473 gtk_label_set_mnemonic_widget(GTK_LABEL(label), input);
5474 gaim_set_accessible_label(input, label);
5475 g_object_set_data(G_OBJECT(input), "identifier", (gpointer)pce->identifier);
5476 g_object_set_data(G_OBJECT(input), "is_spin", GINT_TO_POINTER(pce->is_int));
5477 g_object_set_data(G_OBJECT(input), "required", GINT_TO_POINTER(pce->required));
5478 data->entries = g_list_append(data->entries, input);
5479
5480 g_free(pce);
5481 }
5482
5483 g_list_free(list);
5484 g_hash_table_destroy(defaults);
5485
5486 /* Set whether the "OK" button should be clickable initially */
5487 addchat_set_sensitive_if_input_cb(NULL, data);
5488
5489 gtk_widget_show_all(data->entries_box);
5490 }
5491
5492 static void
5493 addchat_select_account_cb(GObject *w, GaimAccount *account,
5494 GaimGtkAddChatData *data)
5495 {
5496 if (strcmp(gaim_account_get_protocol_id(data->account),
5497 gaim_account_get_protocol_id(account)) == 0)
5498 {
5499 data->account = account;
5500 }
5501 else
5502 {
5503 data->account = account;
5504 rebuild_addchat_entries(data);
5505 }
5506 }
5507
5508 static void
5509 gaim_gtk_blist_request_add_chat(GaimAccount *account, GaimGroup *group,
5510 const char *alias, const char *name)
5511 {
5512 GaimGtkAddChatData *data;
5513 GaimGtkBuddyList *gtkblist;
5514 GList *l;
5515 GaimConnection *gc;
5516 GtkWidget *label;
5517 GtkWidget *rowbox;
5518 GtkWidget *hbox;
5519 GtkWidget *vbox;
5520 GtkWidget *img;
5521
5522 if (account != NULL) {
5523 gc = gaim_account_get_connection(account);
5524
5525 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->join_chat == NULL) {
5526 gaim_notify_error(gc, NULL, _("This protocol does not support chat rooms."), NULL);
5527 return;
5528 }
5529 } else {
5530 /* Find an account with chat capabilities */
5531 for (l = gaim_connections_get_all(); l != NULL; l = l->next) {
5532 gc = (GaimConnection *)l->data;
5533
5534 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->join_chat != NULL) {
5535 account = gaim_connection_get_account(gc);
5536 break;
5537 }
5538 }
5539
5540 if (account == NULL) {
5541 gaim_notify_error(NULL, NULL,
5542 _("You are not currently signed on with any "
5543 "protocols that have the ability to chat."), NULL);
5544 return;
5545 }
5546 }
5547
5548 data = g_new0(GaimGtkAddChatData, 1);
5549 data->account = account;
5550 data->default_chat_name = g_strdup(name);
5551
5552 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION,
5553 GTK_ICON_SIZE_DIALOG);
5554
5555 gtkblist = GAIM_GTK_BLIST(gaim_get_blist());
5556
5557 data->sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
5558
5559 data->window = gtk_dialog_new_with_buttons(_("Add Chat"),
5560 NULL, GTK_DIALOG_NO_SEPARATOR,
5561 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
5562 GTK_STOCK_ADD, GTK_RESPONSE_OK,
5563 NULL);
5564
5565 gtk_dialog_set_default_response(GTK_DIALOG(data->window), GTK_RESPONSE_OK);
5566 gtk_container_set_border_width(GTK_CONTAINER(data->window), GAIM_HIG_BOX_SPACE);
5567 gtk_window_set_resizable(GTK_WINDOW(data->window), FALSE);
5568 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(data->window)->vbox), GAIM_HIG_BORDER);
5569 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), GAIM_HIG_BOX_SPACE);
5570 gtk_window_set_role(GTK_WINDOW(data->window), "add_chat");
5571 gtk_window_set_type_hint(GTK_WINDOW(data->window),
5572 GDK_WINDOW_TYPE_HINT_DIALOG);
5573
5574 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BORDER);
5575 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), hbox);
5576 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
5577 gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
5578
5579 vbox = gtk_vbox_new(FALSE, 5);
5580 gtk_container_add(GTK_CONTAINER(hbox), vbox);
5581
5582 label = gtk_label_new(
5583 _("Please enter an alias, and the appropriate information "
5584 "about the chat you would like to add to your buddy list.\n"));
5585 gtk_widget_set_size_request(label, 400, -1);
5586 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
5587 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
5588 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
5589
5590 rowbox = gtk_hbox_new(FALSE, 5);
5591 gtk_box_pack_start(GTK_BOX(vbox), rowbox, FALSE, FALSE, 0);
5592
5593 label = gtk_label_new(_("Account:"));
5594 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5595 gtk_size_group_add_widget(data->sg, label);
5596 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0);
5597
5598 data->account_menu = gaim_gtk_account_option_menu_new(account, FALSE,
5599 G_CALLBACK(addchat_select_account_cb),
5600 chat_account_filter_func, data);
5601 gtk_box_pack_start(GTK_BOX(rowbox), data->account_menu, TRUE, TRUE, 0);
5602 gaim_set_accessible_label (data->account_menu, label);
5603
5604 data->entries_box = gtk_vbox_new(FALSE, 5);
5605 gtk_container_set_border_width(GTK_CONTAINER(data->entries_box), 0);
5606 gtk_box_pack_start(GTK_BOX(vbox), data->entries_box, TRUE, TRUE, 0);
5607
5608 rebuild_addchat_entries(data);
5609
5610 rowbox = gtk_hbox_new(FALSE, 5);
5611 gtk_box_pack_start(GTK_BOX(vbox), rowbox, FALSE, FALSE, 0);
5612
5613 label = gtk_label_new(_("Alias:"));
5614 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5615 gtk_size_group_add_widget(data->sg, label);
5616 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0);
5617
5618 data->alias_entry = gtk_entry_new();
5619 if (alias != NULL)
5620 gtk_entry_set_text(GTK_ENTRY(data->alias_entry), alias);
5621 gtk_box_pack_end(GTK_BOX(rowbox), data->alias_entry, TRUE, TRUE, 0);
5622 gtk_entry_set_activates_default(GTK_ENTRY(data->alias_entry), TRUE);
5623 gaim_set_accessible_label (data->alias_entry, label);
5624
5625 rowbox = gtk_hbox_new(FALSE, 5);
5626 gtk_box_pack_start(GTK_BOX(vbox), rowbox, FALSE, FALSE, 0);
5627
5628 label = gtk_label_new(_("Group:"));
5629 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5630 gtk_size_group_add_widget(data->sg, label);
5631 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0);
5632
5633 data->group_combo = gtk_combo_new();
5634 gtk_combo_set_popdown_strings(GTK_COMBO(data->group_combo), groups_tree());
5635 gtk_box_pack_end(GTK_BOX(rowbox), data->group_combo, TRUE, TRUE, 0);
5636
5637 if (group)
5638 {
5639 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(data->group_combo)->entry),
5640 group->name);
5641 }
5642 gaim_set_accessible_label (data->group_combo, label);
5643
5644 g_signal_connect(G_OBJECT(data->window), "response",
5645 G_CALLBACK(add_chat_resp_cb), data);
5646
5647 gtk_widget_show_all(data->window);
5648 }
5649
5650 static void
5651 add_group_cb(GaimConnection *gc, const char *group_name)
5652 {
5653 GaimGroup *group;
5654
5655 if ((group_name == NULL) || (*group_name == '\0'))
5656 return;
5657
5658 group = gaim_group_new(group_name);
5659 gaim_blist_add_group(group, NULL);
5660 }
5661
5662 static void
5663 gaim_gtk_blist_request_add_group(void)
5664 {
5665 gaim_request_input(NULL, _("Add Group"), NULL,
5666 _("Please enter the name of the group to be added."),
5667 NULL, FALSE, FALSE, NULL,
5668 _("Add"), G_CALLBACK(add_group_cb),
5669 _("Cancel"), NULL, NULL);
5670 }
5671
5672 void
5673 gaim_gtk_blist_toggle_visibility()
5674 {
5675 if (gtkblist && gtkblist->window) {
5676 if (GTK_WIDGET_VISIBLE(gtkblist->window)) {
5677 gaim_blist_set_visible(GAIM_WINDOW_ICONIFIED(gtkblist->window) || gtk_blist_obscured);
5678 } else {
5679 gaim_blist_set_visible(TRUE);
5680 }
5681 }
5682 }
5683
5684 void
5685 gaim_gtk_blist_visibility_manager_add()
5686 {
5687 visibility_manager_count++;
5688 gaim_debug_info("gtkblist", "added visibility manager: %d\n", visibility_manager_count);
5689 }
5690
5691 void
5692 gaim_gtk_blist_visibility_manager_remove()
5693 {
5694 if (visibility_manager_count)
5695 visibility_manager_count--;
5696 if (!visibility_manager_count)
5697 gaim_blist_set_visible(TRUE);
5698 gaim_debug_info("gtkblist", "removed visibility manager: %d\n", visibility_manager_count);
5699 }
5700
5701 void gaim_gtk_blist_add_alert(GtkWidget *widget)
5702 {
5703 gtk_container_add(GTK_CONTAINER(gtkblist->scrollbook), widget);
5704 if (!GTK_WIDGET_HAS_FOCUS(gtkblist->window))
5705 gaim_gtk_set_urgent(GTK_WINDOW(gtkblist->window), TRUE);
5706 }
5707
5708 void
5709 gaim_gtk_blist_set_headline(const char *text, GdkPixbuf *pixbuf, GCallback callback,
5710 gpointer user_data, GDestroyNotify destroy)
5711 {
5712 /* Destroy any existing headline first */
5713 if (gtkblist->headline_destroy)
5714 gtkblist->headline_destroy(gtkblist->headline_data);
5715
5716 gtk_label_set_markup(GTK_LABEL(gtkblist->headline_label), text);
5717 gtk_image_set_from_pixbuf(GTK_IMAGE(gtkblist->headline_image), pixbuf);
5718
5719 gtkblist->headline_callback = callback;
5720 gtkblist->headline_data = user_data;
5721 gtkblist->headline_destroy = destroy;
5722 if (!GTK_WIDGET_HAS_FOCUS(gtkblist->window))
5723 gaim_gtk_set_urgent(GTK_WINDOW(gtkblist->window), TRUE);
5724 gtk_widget_show_all(gtkblist->headline_hbox);
5725 }
5726
5727 static GaimBlistUiOps blist_ui_ops =
5728 {
5729 gaim_gtk_blist_new_list,
5730 gaim_gtk_blist_new_node,
5731 gaim_gtk_blist_show,
5732 gaim_gtk_blist_update,
5733 gaim_gtk_blist_remove,
5734 gaim_gtk_blist_destroy,
5735 gaim_gtk_blist_set_visible,
5736 gaim_gtk_blist_request_add_buddy,
5737 gaim_gtk_blist_request_add_chat,
5738 gaim_gtk_blist_request_add_group
5739 };
5740
5741
5742 GaimBlistUiOps *
5743 gaim_gtk_blist_get_ui_ops(void)
5744 {
5745 return &blist_ui_ops;
5746 }
5747
5748 GaimGtkBuddyList *gaim_gtk_blist_get_default_gtk_blist()
5749 {
5750 return gtkblist;
5751 }
5752
5753 static void account_signon_cb(GaimConnection *gc, gpointer z)
5754 {
5755 GaimAccount *account = gaim_connection_get_account(gc);
5756 GaimBlistNode *gnode, *cnode;
5757 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next)
5758 {
5759 if(!GAIM_BLIST_NODE_IS_GROUP(gnode))
5760 continue;
5761 for(cnode = gnode->child; cnode; cnode = cnode->next)
5762 {
5763 GaimChat *chat;
5764
5765 if(!GAIM_BLIST_NODE_IS_CHAT(cnode))
5766 continue;
5767
5768 chat = (GaimChat *)cnode;
5769
5770 if(chat->account != account)
5771 continue;
5772
5773 if(gaim_blist_node_get_bool((GaimBlistNode*)chat, "gtk-autojoin") ||
5774 (gaim_blist_node_get_string((GaimBlistNode*)chat,
5775 "gtk-autojoin") != NULL))
5776 serv_join_chat(gc, chat->components);
5777 }
5778 }
5779 }
5780
5781 void *
5782 gaim_gtk_blist_get_handle() {
5783 static int handle;
5784
5785 return &handle;
5786 }
5787
5788 static gboolean buddy_signonoff_timeout_cb(GaimBuddy *buddy)
5789 {
5790 struct _gaim_gtk_blist_node *gtknode = ((GaimBlistNode*)buddy)->ui_data;
5791
5792 gtknode->recent_signonoff = FALSE;
5793 gtknode->recent_signonoff_timer = 0;
5794
5795 gaim_gtk_blist_update(NULL, (GaimBlistNode*)buddy);
5796
5797 return FALSE;
5798 }
5799
5800 static void buddy_signonoff_cb(GaimBuddy *buddy)
5801 {
5802 struct _gaim_gtk_blist_node *gtknode;
5803
5804 if(!((GaimBlistNode*)buddy)->ui_data) {
5805 gaim_gtk_blist_new_node((GaimBlistNode*)buddy);
5806 }
5807
5808 gtknode = ((GaimBlistNode*)buddy)->ui_data;
5809
5810 gtknode->recent_signonoff = TRUE;
5811
5812 if(gtknode->recent_signonoff_timer > 0)
5813 gaim_timeout_remove(gtknode->recent_signonoff_timer);
5814 gtknode->recent_signonoff_timer = gaim_timeout_add(10000,
5815 (GSourceFunc)buddy_signonoff_timeout_cb, buddy);
5816 }
5817
5818 void gaim_gtk_blist_init(void)
5819 {
5820 void *gtk_blist_handle = gaim_gtk_blist_get_handle();
5821
5822 gaim_signal_connect(gaim_connections_get_handle(), "signed-on",
5823 gtk_blist_handle, GAIM_CALLBACK(account_signon_cb),
5824 NULL);
5825
5826 /* Initialize prefs */
5827 gaim_prefs_add_none("/gaim/gtk/blist");
5828 gaim_prefs_add_bool("/gaim/gtk/blist/show_buddy_icons", TRUE);
5829 gaim_prefs_add_bool("/gaim/gtk/blist/show_empty_groups", FALSE);
5830 gaim_prefs_add_bool("/gaim/gtk/blist/show_idle_time", TRUE);
5831 gaim_prefs_add_bool("/gaim/gtk/blist/show_offline_buddies", FALSE);
5832 gaim_prefs_add_bool("/gaim/gtk/blist/list_visible", TRUE);
5833 gaim_prefs_add_bool("/gaim/gtk/blist/list_maximized", FALSE);
5834 gaim_prefs_add_string("/gaim/gtk/blist/sort_type", "alphabetical");
5835 gaim_prefs_add_int("/gaim/gtk/blist/x", 0);
5836 gaim_prefs_add_int("/gaim/gtk/blist/y", 0);
5837 gaim_prefs_add_int("/gaim/gtk/blist/width", 250); /* Golden ratio, baby */
5838 gaim_prefs_add_int("/gaim/gtk/blist/height", 405); /* Golden ratio, baby */
5839 gaim_prefs_add_int("/gaim/gtk/blist/tooltip_delay", 500);
5840
5841 /* Register our signals */
5842 gaim_signal_register(gtk_blist_handle, "gtkblist-hiding",
5843 gaim_marshal_VOID__POINTER, NULL, 1,
5844 gaim_value_new(GAIM_TYPE_SUBTYPE,
5845 GAIM_SUBTYPE_BLIST));
5846
5847 gaim_signal_register(gtk_blist_handle, "gtkblist-unhiding",
5848 gaim_marshal_VOID__POINTER, NULL, 1,
5849 gaim_value_new(GAIM_TYPE_SUBTYPE,
5850 GAIM_SUBTYPE_BLIST));
5851
5852 gaim_signal_register(gtk_blist_handle, "gtkblist-created",
5853 gaim_marshal_VOID__POINTER, NULL, 1,
5854 gaim_value_new(GAIM_TYPE_SUBTYPE,
5855 GAIM_SUBTYPE_BLIST));
5856
5857 gaim_signal_register(gtk_blist_handle, "drawing-tooltip",
5858 gaim_marshal_VOID__POINTER_POINTER_UINT, NULL, 3,
5859 gaim_value_new(GAIM_TYPE_SUBTYPE,
5860 GAIM_SUBTYPE_BLIST_NODE),
5861 gaim_value_new_outgoing(GAIM_TYPE_BOXED, "GString *"),
5862 gaim_value_new(GAIM_TYPE_BOOLEAN));
5863
5864
5865 gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-on", gtk_blist_handle, GAIM_CALLBACK(buddy_signonoff_cb), NULL);
5866 gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-off", gtk_blist_handle, GAIM_CALLBACK(buddy_signonoff_cb), NULL);
5867 gaim_signal_connect(gaim_blist_get_handle(), "buddy-privacy-changed", gtk_blist_handle, GAIM_CALLBACK(gaim_gtk_blist_update_privacy_cb), NULL);
5868 }
5869
5870 void
5871 gaim_gtk_blist_uninit(void) {
5872 gaim_signals_unregister_by_instance(gaim_gtk_blist_get_handle());
5873 gaim_signals_disconnect_by_handle(gaim_gtk_blist_get_handle());
5874 }
5875
5876 /*********************************************************************
5877 * Buddy List sorting functions *
5878 *********************************************************************/
5879
5880 GList *gaim_gtk_blist_get_sort_methods()
5881 {
5882 return gaim_gtk_blist_sort_methods;
5883 }
5884
5885 void gaim_gtk_blist_sort_method_reg(const char *id, const char *name, gaim_gtk_blist_sort_function func)
5886 {
5887 struct gaim_gtk_blist_sort_method *method = g_new0(struct gaim_gtk_blist_sort_method, 1);
5888 method->id = g_strdup(id);
5889 method->name = g_strdup(name);
5890 method->func = func;
5891 gaim_gtk_blist_sort_methods = g_list_append(gaim_gtk_blist_sort_methods, method);
5892 gaim_gtk_blist_update_sort_methods();
5893 }
5894
5895 void gaim_gtk_blist_sort_method_unreg(const char *id){
5896 GList *l = gaim_gtk_blist_sort_methods;
5897
5898 while(l) {
5899 struct gaim_gtk_blist_sort_method *method = l->data;
5900 if(!strcmp(method->id, id)) {
5901 gaim_gtk_blist_sort_methods = g_list_delete_link(gaim_gtk_blist_sort_methods, l);
5902 g_free(method->id);
5903 g_free(method->name);
5904 g_free(method);
5905 break;
5906 }
5907 }
5908 gaim_gtk_blist_update_sort_methods();
5909 }
5910
5911 void gaim_gtk_blist_sort_method_set(const char *id){
5912 GList *l = gaim_gtk_blist_sort_methods;
5913
5914 if(!id)
5915 id = "none";
5916
5917 while (l && strcmp(((struct gaim_gtk_blist_sort_method*)l->data)->id, id))
5918 l = l->next;
5919
5920 if (l) {
5921 current_sort_method = l->data;
5922 } else if (!current_sort_method) {
5923 gaim_gtk_blist_sort_method_set("none");
5924 return;
5925 }
5926 if (!strcmp(id, "none")) {
5927 redo_buddy_list(gaim_get_blist(), TRUE, FALSE);
5928 } else {
5929 redo_buddy_list(gaim_get_blist(), FALSE, FALSE);
5930 }
5931 }
5932
5933 /******************************************
5934 ** Sort Methods
5935 ******************************************/
5936
5937 static void sort_method_none(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter parent_iter, GtkTreeIter *cur, GtkTreeIter *iter)
5938 {
5939 GaimBlistNode *sibling = node->prev;
5940 GtkTreeIter sibling_iter;
5941
5942 if (cur != NULL) {
5943 *iter = *cur;
5944 return;
5945 }
5946
5947 while (sibling && !get_iter_from_node(sibling, &sibling_iter)) {
5948 sibling = sibling->prev;
5949 }
5950
5951 gtk_tree_store_insert_after(gtkblist->treemodel, iter,
5952 node->parent ? &parent_iter : NULL,
5953 sibling ? &sibling_iter : NULL);
5954 }
5955
5956 #if GTK_CHECK_VERSION(2,2,1)
5957
5958 static void sort_method_alphabetical(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur, GtkTreeIter *iter)
5959 {
5960 GtkTreeIter more_z;
5961
5962 const char *my_name;
5963
5964 if(GAIM_BLIST_NODE_IS_CONTACT(node)) {
5965 my_name = gaim_contact_get_alias((GaimContact*)node);
5966 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) {
5967 my_name = gaim_chat_get_name((GaimChat*)node);
5968 } else {
5969 sort_method_none(node, blist, groupiter, cur, iter);
5970 return;
5971 }
5972
5973
5974 if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &more_z, &groupiter)) {
5975 gtk_tree_store_insert(gtkblist->treemodel, iter, &groupiter, 0);
5976 return;
5977 }
5978
5979 do {
5980 GValue val;
5981 GaimBlistNode *n;
5982 const char *this_name;
5983 int cmp;
5984
5985 val.g_type = 0;
5986 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &more_z, NODE_COLUMN, &val);
5987 n = g_value_get_pointer(&val);
5988
5989 if(GAIM_BLIST_NODE_IS_CONTACT(n)) {
5990 this_name = gaim_contact_get_alias((GaimContact*)n);
5991 } else if(GAIM_BLIST_NODE_IS_CHAT(n)) {
5992 this_name = gaim_chat_get_name((GaimChat*)n);
5993 } else {
5994 this_name = NULL;
5995 }
5996
5997 cmp = gaim_utf8_strcasecmp(my_name, this_name);
5998
5999 if(this_name && (cmp < 0 || (cmp == 0 && node < n))) {
6000 if(cur) {
6001 gtk_tree_store_move_before(gtkblist->treemodel, cur, &more_z);
6002 *iter = *cur;
6003 return;
6004 } else {
6005 gtk_tree_store_insert_before(gtkblist->treemodel, iter,
6006 &groupiter, &more_z);
6007 return;
6008 }
6009 }
6010 g_value_unset(&val);
6011 } while (gtk_tree_model_iter_next (GTK_TREE_MODEL(gtkblist->treemodel), &more_z));
6012
6013 if(cur) {
6014 gtk_tree_store_move_before(gtkblist->treemodel, cur, NULL);
6015 *iter = *cur;
6016 return;
6017 } else {
6018 gtk_tree_store_append(gtkblist->treemodel, iter, &groupiter);
6019 return;
6020 }
6021 }
6022
6023 static void sort_method_status(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur, GtkTreeIter *iter)
6024 {
6025 GtkTreeIter more_z;
6026
6027 GaimBuddy *my_buddy, *this_buddy;
6028
6029 if(GAIM_BLIST_NODE_IS_CONTACT(node)) {
6030 my_buddy = gaim_contact_get_priority_buddy((GaimContact*)node);
6031 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) {
6032 if (cur != NULL) {
6033 *iter = *cur;
6034 return;
6035 }
6036
6037 gtk_tree_store_append(gtkblist->treemodel, iter, &groupiter);
6038 return;
6039 } else {
6040 sort_method_none(node, blist, groupiter, cur, iter);
6041 return;
6042 }
6043
6044
6045 if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &more_z, &groupiter)) {
6046 gtk_tree_store_insert(gtkblist->treemodel, iter, &groupiter, 0);
6047 return;
6048 }
6049
6050 do {
6051 GValue val;
6052 GaimBlistNode *n;
6053 gint name_cmp;
6054 gint presence_cmp;
6055
6056 val.g_type = 0;
6057 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &more_z, NODE_COLUMN, &val);
6058 n = g_value_get_pointer(&val);
6059
6060 if(GAIM_BLIST_NODE_IS_CONTACT(n)) {
6061 this_buddy = gaim_contact_get_priority_buddy((GaimContact*)n);
6062 } else {
6063 this_buddy = NULL;
6064 }
6065
6066 name_cmp = gaim_utf8_strcasecmp(
6067 gaim_contact_get_alias(gaim_buddy_get_contact(my_buddy)),
6068 (this_buddy
6069 ? gaim_contact_get_alias(gaim_buddy_get_contact(this_buddy))
6070 : NULL));
6071
6072 presence_cmp = gaim_presence_compare(
6073 gaim_buddy_get_presence(my_buddy),
6074 this_buddy ? gaim_buddy_get_presence(this_buddy) : NULL);
6075
6076 if (this_buddy == NULL ||
6077 (presence_cmp < 0 ||
6078 (presence_cmp == 0 &&
6079 (name_cmp < 0 || (name_cmp == 0 && node < n)))))
6080 {
6081 if (cur != NULL)
6082 {
6083 gtk_tree_store_move_before(gtkblist->treemodel, cur, &more_z);
6084 *iter = *cur;
6085 return;
6086 }
6087 else
6088 {
6089 gtk_tree_store_insert_before(gtkblist->treemodel, iter,
6090 &groupiter, &more_z);
6091 return;
6092 }
6093 }
6094
6095 g_value_unset(&val);
6096 }
6097 while (gtk_tree_model_iter_next(GTK_TREE_MODEL(gtkblist->treemodel),
6098 &more_z));
6099
6100 if (cur) {
6101 gtk_tree_store_move_before(gtkblist->treemodel, cur, NULL);
6102 *iter = *cur;
6103 return;
6104 } else {
6105 gtk_tree_store_append(gtkblist->treemodel, iter, &groupiter);
6106 return;
6107 }
6108 }
6109
6110 static void sort_method_log(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur, GtkTreeIter *iter)
6111 {
6112 GtkTreeIter more_z;
6113
6114 int log_size = 0, this_log_size = 0;
6115 const char *buddy_name, *this_buddy_name;
6116
6117 if(cur && (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(gtkblist->treemodel), &groupiter) == 1)) {
6118 *iter = *cur;
6119 return;
6120 }
6121
6122 if(GAIM_BLIST_NODE_IS_CONTACT(node)) {
6123 GaimBlistNode *n;
6124 for (n = node->child; n; n = n->next)
6125 log_size += gaim_log_get_total_size(GAIM_LOG_IM, ((GaimBuddy*)(n))->name, ((GaimBuddy*)(n))->account);
6126 buddy_name = gaim_contact_get_alias((GaimContact*)node);
6127 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) {
6128 /* we don't have a reliable way of getting the log filename
6129 * from the chat info in the blist, yet */
6130 if (cur != NULL) {
6131 *iter = *cur;
6132 return;
6133 }
6134
6135 gtk_tree_store_append(gtkblist->treemodel, iter, &groupiter);
6136 return;
6137 } else {
6138 sort_method_none(node, blist, groupiter, cur, iter);
6139 return;
6140 }
6141
6142
6143 if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &more_z, &groupiter)) {
6144 gtk_tree_store_insert(gtkblist->treemodel, iter, &groupiter, 0);
6145 return;
6146 }
6147
6148 do {
6149 GValue val;
6150 GaimBlistNode *n;
6151 GaimBlistNode *n2;
6152 int cmp;
6153
6154 val.g_type = 0;
6155 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &more_z, NODE_COLUMN, &val);
6156 n = g_value_get_pointer(&val);
6157 this_log_size = 0;
6158
6159 if(GAIM_BLIST_NODE_IS_CONTACT(n)) {
6160 for (n2 = n->child; n2; n2 = n2->next)
6161 this_log_size += gaim_log_get_total_size(GAIM_LOG_IM, ((GaimBuddy*)(n2))->name, ((GaimBuddy*)(n2))->account);
6162 this_buddy_name = gaim_contact_get_alias((GaimContact*)n);
6163 } else {
6164 this_buddy_name = NULL;
6165 }
6166
6167 cmp = gaim_utf8_strcasecmp(buddy_name, this_buddy_name);
6168
6169 if (!GAIM_BLIST_NODE_IS_CONTACT(n) || log_size > this_log_size ||
6170 ((log_size == this_log_size) &&
6171 (cmp < 0 || (cmp == 0 && node < n)))) {
6172 if (cur != NULL) {
6173 gtk_tree_store_move_before(gtkblist->treemodel, cur, &more_z);
6174 *iter = *cur;
6175 return;
6176 } else {
6177 gtk_tree_store_insert_before(gtkblist->treemodel, iter,
6178 &groupiter, &more_z);
6179 return;
6180 }
6181 }
6182 g_value_unset(&val);
6183 } while (gtk_tree_model_iter_next (GTK_TREE_MODEL(gtkblist->treemodel), &more_z));
6184
6185 if (cur != NULL) {
6186 gtk_tree_store_move_before(gtkblist->treemodel, cur, NULL);
6187 *iter = *cur;
6188 return;
6189 } else {
6190 gtk_tree_store_append(gtkblist->treemodel, iter, &groupiter);
6191 return;
6192 }
6193 }
6194
6195 #endif
6196
6197 static void
6198 plugin_act(GtkObject *obj, GaimPluginAction *pam)
6199 {
6200 if (pam && pam->callback)
6201 pam->callback(pam);
6202 }
6203
6204 static void
6205 build_plugin_actions(GtkWidget *menu, GaimPlugin *plugin)
6206 {
6207 GtkWidget *menuitem;
6208 GaimPluginAction *action = NULL;
6209 GList *actions, *l;
6210
6211 actions = GAIM_PLUGIN_ACTIONS(plugin, NULL);
6212
6213 for (l = actions; l != NULL; l = l->next)
6214 {
6215 if (l->data)
6216 {
6217 action = (GaimPluginAction *) l->data;
6218 action->plugin = plugin;
6219 action->context = NULL;
6220
6221 menuitem = gtk_menu_item_new_with_label(action->label);
6222 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
6223
6224 g_signal_connect(G_OBJECT(menuitem), "activate",
6225 G_CALLBACK(plugin_act), action);
6226 g_object_set_data_full(G_OBJECT(menuitem), "plugin_action",
6227 action,
6228 (GDestroyNotify)gaim_plugin_action_free);
6229 gtk_widget_show(menuitem);
6230 }
6231 else
6232 gaim_separator(menu);
6233 }
6234
6235 g_list_free(actions);
6236 }
6237
6238 static void
6239 modify_account_cb(GtkWidget *widget, gpointer data)
6240 {
6241 gaim_gtk_account_dialog_show(GAIM_GTK_MODIFY_ACCOUNT_DIALOG, data);
6242 }
6243
6244 static void
6245 enable_account_cb(GtkCheckMenuItem *widget, gpointer data)
6246 {
6247 GaimAccount *account = data;
6248 const GaimSavedStatus *saved_status;
6249
6250 saved_status = gaim_savedstatus_get_current();
6251 gaim_savedstatus_activate_for_account(saved_status, account);
6252
6253 gaim_account_set_enabled(account, GAIM_GTK_UI, TRUE);
6254 }
6255
6256 static void
6257 disable_account_cb(GtkCheckMenuItem *widget, gpointer data)
6258 {
6259 GaimAccount *account = data;
6260
6261 gaim_account_set_enabled(account, GAIM_GTK_UI, FALSE);
6262 }
6263
6264 void
6265 gaim_gtk_blist_update_accounts_menu(void)
6266 {
6267 GtkWidget *menuitem = NULL, *submenu = NULL;
6268 GtkAccelGroup *accel_group = NULL;
6269 GList *l = NULL, *accounts = NULL;
6270 gboolean disabled_accounts = FALSE;
6271
6272 if (accountmenu == NULL)
6273 return;
6274
6275 /* Clear the old Accounts menu */
6276 for (l = gtk_container_get_children(GTK_CONTAINER(accountmenu)); l; l = l->next) {
6277 menuitem = l->data;
6278
6279 if (menuitem != gtk_item_factory_get_widget(gtkblist->ift, N_("/Accounts/Add\\/Edit")))
6280 gtk_widget_destroy(menuitem);
6281 }
6282
6283 for (accounts = gaim_accounts_get_all(); accounts; accounts = accounts->next) {
6284 char *buf = NULL;
6285 char *accel_path_buf = NULL;
6286 GtkWidget *image = NULL;
6287 GaimConnection *gc = NULL;
6288 GaimAccount *account = NULL;
6289 GaimStatus *status = NULL;
6290 GdkPixbuf *pixbuf = NULL;
6291
6292 account = accounts->data;
6293 accel_group = gtk_menu_get_accel_group(GTK_MENU(accountmenu));
6294
6295 if(gaim_account_get_enabled(account, GAIM_GTK_UI)) {
6296 buf = g_strconcat(gaim_account_get_username(account), " (",
6297 gaim_account_get_protocol_name(account), ")", NULL);
6298 menuitem = gtk_image_menu_item_new_with_label(buf);
6299 accel_path_buf = g_strconcat(N_("<GaimMain>/Accounts/"), buf, NULL);
6300 g_free(buf);
6301 status = gaim_account_get_active_status(account);
6302 pixbuf = gaim_gtk_create_prpl_icon_with_status(account, gaim_status_get_type(status), 0.5);
6303 if (pixbuf != NULL)
6304 {
6305 if (!gaim_account_is_connected(account))
6306 gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf,
6307 0.0, FALSE);
6308 image = gtk_image_new_from_pixbuf(pixbuf);
6309 g_object_unref(G_OBJECT(pixbuf));
6310 gtk_widget_show(image);
6311 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);
6312 }
6313 gtk_menu_shell_append(GTK_MENU_SHELL(accountmenu), menuitem);
6314 gtk_widget_show(menuitem);
6315
6316 submenu = gtk_menu_new();
6317 gtk_menu_set_accel_group(GTK_MENU(submenu), accel_group);
6318 gtk_menu_set_accel_path(GTK_MENU(submenu), accel_path_buf);
6319 g_free(accel_path_buf);
6320 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu);
6321 gtk_widget_show(submenu);
6322
6323
6324 menuitem = gtk_menu_item_new_with_mnemonic(_("_Edit Account"));
6325 g_signal_connect(G_OBJECT(menuitem), "activate",
6326 G_CALLBACK(modify_account_cb), account);
6327 gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem);
6328 gtk_widget_show(menuitem);
6329
6330 gaim_separator(submenu);
6331
6332 gc = gaim_account_get_connection(account);
6333 if (gc && GAIM_CONNECTION_IS_CONNECTED(gc)) {
6334 GaimPlugin *plugin = NULL;
6335
6336 plugin = gc->prpl;
6337 if (GAIM_PLUGIN_HAS_ACTIONS(plugin)) {
6338 GList *l, *ll = NULL;
6339 GaimPluginAction *action = NULL;
6340
6341 for (l = ll = GAIM_PLUGIN_ACTIONS(plugin, gc); l; l = l->next) {
6342 if (l->data) {
6343 action = (GaimPluginAction *)l->data;
6344 action->plugin = plugin;
6345 action->context = gc;
6346
6347 menuitem = gtk_menu_item_new_with_label(action->label);
6348 gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem);
6349 g_signal_connect(G_OBJECT(menuitem), "activate",
6350 G_CALLBACK(plugin_act), action);
6351 g_object_set_data_full(G_OBJECT(menuitem), "plugin_action", action, (GDestroyNotify)gaim_plugin_action_free);
6352 gtk_widget_show(menuitem);
6353 } else
6354 gaim_separator(submenu);
6355 }
6356 } else {
6357 menuitem = gtk_menu_item_new_with_label(_("No actions available"));
6358 gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem);
6359 gtk_widget_set_sensitive(menuitem, FALSE);
6360 gtk_widget_show(menuitem);
6361 }
6362 } else {
6363 menuitem = gtk_menu_item_new_with_label(_("No actions available"));
6364 gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem);
6365 gtk_widget_set_sensitive(menuitem, FALSE);
6366 gtk_widget_show(menuitem);
6367 }
6368
6369 gaim_separator(submenu);
6370
6371 menuitem = gtk_menu_item_new_with_mnemonic(_("_Disable"));
6372 g_signal_connect(G_OBJECT(menuitem), "activate",
6373 G_CALLBACK(disable_account_cb), account);
6374 gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem);
6375 gtk_widget_show(menuitem);
6376 } else {
6377 disabled_accounts = TRUE;
6378 }
6379 }
6380
6381 if(disabled_accounts) {
6382 gaim_separator(accountmenu);
6383 menuitem = gtk_menu_item_new_with_label(_("Enable Account"));
6384 gtk_menu_shell_append(GTK_MENU_SHELL(accountmenu), menuitem);
6385 gtk_widget_show(menuitem);
6386
6387 submenu = gtk_menu_new();
6388 gtk_menu_set_accel_group(GTK_MENU(submenu), accel_group);
6389 gtk_menu_set_accel_path(GTK_MENU(submenu), N_("<GaimMain>/Accounts/Enable Account"));
6390 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu);
6391 gtk_widget_show(submenu);
6392
6393 for (accounts = gaim_accounts_get_all(); accounts; accounts = accounts->next) {
6394 char *buf = NULL;
6395 GtkWidget *image = NULL;
6396 GaimAccount *account = NULL;
6397 GdkPixbuf *pixbuf = NULL;
6398
6399 account = accounts->data;
6400
6401 if(!gaim_account_get_enabled(account, GAIM_GTK_UI)) {
6402
6403 disabled_accounts = TRUE;
6404
6405 buf = g_strconcat(gaim_account_get_username(account), " (",
6406 gaim_account_get_protocol_name(account), ")", NULL);
6407 menuitem = gtk_image_menu_item_new_with_label(buf);
6408 g_free(buf);
6409 pixbuf = gaim_gtk_create_prpl_icon(account, 0.5);
6410 if (pixbuf != NULL)
6411 {
6412 if (!gaim_account_is_connected(account))
6413 gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE);
6414 image = gtk_image_new_from_pixbuf(pixbuf);
6415 g_object_unref(G_OBJECT(pixbuf));
6416 gtk_widget_show(image);
6417 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);
6418 }
6419 g_signal_connect(G_OBJECT(menuitem), "activate",
6420 G_CALLBACK(enable_account_cb), account);
6421 gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem);
6422 gtk_widget_show(menuitem);
6423 }
6424 }
6425 }
6426 }
6427
6428 static GList *plugin_submenus = NULL;
6429
6430 void
6431 gaim_gtk_blist_update_plugin_actions(void)
6432 {
6433 GtkWidget *menuitem, *submenu;
6434 GaimPlugin *plugin = NULL;
6435 GList *l;
6436 GtkAccelGroup *accel_group;
6437
6438 GtkWidget *pluginmenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools"));
6439
6440 g_return_if_fail(pluginmenu != NULL);
6441
6442 /* Remove old plugin action submenus from the Tools menu */
6443 for (l = plugin_submenus; l; l = l->next)
6444 gtk_widget_destroy(GTK_WIDGET(l->data));
6445 g_list_free(plugin_submenus);
6446 plugin_submenus = NULL;
6447
6448 accel_group = gtk_menu_get_accel_group(GTK_MENU(pluginmenu));
6449
6450 /* Add a submenu for each plugin with custom actions */
6451 for (l = gaim_plugins_get_loaded(); l; l = l->next) {
6452 char *path;
6453
6454 plugin = (GaimPlugin *) l->data;
6455
6456 if (GAIM_IS_PROTOCOL_PLUGIN(plugin))
6457 continue;
6458
6459 if (!GAIM_PLUGIN_HAS_ACTIONS(plugin))
6460 continue;
6461
6462 menuitem = gtk_image_menu_item_new_with_label(_(plugin->info->name));
6463 gtk_menu_shell_append(GTK_MENU_SHELL(pluginmenu), menuitem);
6464 gtk_widget_show(menuitem);
6465
6466 plugin_submenus = g_list_append(plugin_submenus, menuitem);
6467
6468 submenu = gtk_menu_new();
6469 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu);
6470 gtk_widget_show(submenu);
6471
6472 gtk_menu_set_accel_group(GTK_MENU(submenu), accel_group);
6473 path = g_strdup_printf("%s/Tools/%s", gtkblist->ift->path, plugin->info->name);
6474 gtk_menu_set_accel_path(GTK_MENU(submenu), path);
6475 g_free(path);
6476
6477 build_plugin_actions(submenu, plugin);
6478 }
6479 }
6480
6481 static void
6482 sortmethod_act(GtkCheckMenuItem *checkmenuitem, char *id)
6483 {
6484 if (gtk_check_menu_item_get_active(checkmenuitem))
6485 {
6486 gaim_gtk_set_cursor(gtkblist->window, GDK_WATCH);
6487 /* This is redundant. I think. */
6488 /* gaim_gtk_blist_sort_method_set(id); */
6489 gaim_prefs_set_string("/gaim/gtk/blist/sort_type", id);
6490
6491 gaim_gtk_clear_cursor(gtkblist->window);
6492 }
6493 }
6494
6495 void
6496 gaim_gtk_blist_update_sort_methods(void)
6497 {
6498 GtkWidget *menuitem = NULL, *activeitem = NULL;
6499 GaimGtkBlistSortMethod *method = NULL;
6500 GList *l;
6501 GSList *sl = NULL;
6502 GtkWidget *sortmenu;
6503 const char *m = gaim_prefs_get_string("/gaim/gtk/blist/sort_type");
6504
6505 if ((gtkblist == NULL) || (gtkblist->ift == NULL))
6506 return;
6507
6508 sortmenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Buddies/Sort Buddies"));
6509
6510 if (sortmenu == NULL)
6511 return;
6512
6513 /* Clear the old menu */
6514 for (l = gtk_container_get_children(GTK_CONTAINER(sortmenu)); l; l = l->next) {
6515 menuitem = l->data;
6516 gtk_widget_destroy(GTK_WIDGET(menuitem));
6517 }
6518
6519 for (l = gaim_gtk_blist_sort_methods; l; l = l->next) {
6520 method = (GaimGtkBlistSortMethod *) l->data;
6521 menuitem = gtk_radio_menu_item_new_with_label(sl, _(method->name));
6522 if (!strcmp(m, method->id))
6523 activeitem = menuitem;
6524 sl = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(menuitem));
6525 gtk_menu_shell_append(GTK_MENU_SHELL(sortmenu), menuitem);
6526 g_signal_connect(G_OBJECT(menuitem), "toggled",
6527 G_CALLBACK(sortmethod_act), method->id);
6528 gtk_widget_show(menuitem);
6529 }
6530 if (activeitem)
6531 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(activeitem), TRUE);
6532 }