Mercurial > pidgin.yaz
annotate src/gtkblist.c @ 5381:aa1cf48f76eb
[gaim-migrate @ 5757]
Correct me if I'm wrong, but I don't think we want to call list_emblems if
the user is offline?
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Thu, 15 May 2003 19:29:07 +0000 |
parents | c4e7a079cc04 |
children | 965c339fd74c |
rev | line source |
---|---|
5228 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
22 #ifdef HAVE_CONFIG_H | |
23 #include <config.h> | |
24 #endif | |
25 #ifdef GAIM_PLUGINS | |
26 #ifndef _WIN32 | |
27 #include <dlfcn.h> | |
28 #endif | |
29 #endif /* GAIM_PLUGINS */ | |
30 #include <string.h> | |
31 #include <stdio.h> | |
32 #include <stdlib.h> | |
33 #include <ctype.h> | |
34 #include <math.h> | |
35 #include <time.h> | |
36 #include <ctype.h> | |
37 | |
38 #ifdef _WIN32 | |
39 #include <gdk/gdkwin32.h> | |
40 #else | |
41 #include <unistd.h> | |
42 #include <gdk/gdkx.h> | |
43 #endif | |
44 | |
45 #include <gdk/gdkkeysyms.h> | |
46 #include <gtk/gtk.h> | |
47 #include "prpl.h" | |
48 #include "sound.h" | |
49 #include "gaim.h" | |
50 #include "gtkblist.h" | |
51 #include "gtkpounce.h" | |
52 #include "gtkft.h" | |
5234 | 53 #include "gtkdebug.h" |
5228 | 54 |
55 #ifdef _WIN32 | |
56 #include "win32dep.h" | |
57 #endif | |
58 | |
59 static struct gaim_gtk_buddy_list *gtkblist = NULL; | |
60 | |
61 /* part of the best damn Docklet code this side of Tahiti */ | |
62 static gboolean gaim_gtk_blist_obscured = FALSE; | |
63 | |
64 static void gaim_gtk_blist_selection_changed(GtkTreeSelection *selection, gpointer data); | |
65 static void gaim_gtk_blist_update(struct gaim_buddy_list *list, GaimBlistNode *node); | |
5234 | 66 static char *gaim_get_tooltip_text(GaimBlistNode *node); |
5228 | 67 static char *item_factory_translate_func (const char *path, gpointer func_data); |
5273 | 68 static gboolean get_iter_from_node(GaimBlistNode *node, GtkTreeIter *iter); |
5228 | 69 |
5256 | 70 struct _gaim_gtk_blist_node { |
71 GtkTreeRowReference *row; | |
72 }; | |
73 | |
5228 | 74 /*************************************************** |
75 * Callbacks * | |
76 ***************************************************/ | |
77 | |
78 static gboolean gtk_blist_delete_cb(GtkWidget *w, GdkEventAny *event, gpointer data) | |
79 { | |
80 if (docklet_count) | |
81 gaim_blist_set_visible(FALSE); | |
82 else | |
83 do_quit(); | |
84 | |
85 /* we handle everything, event should not propogate further */ | |
86 return TRUE; | |
87 } | |
88 | |
89 static gboolean gtk_blist_save_prefs_cb(gpointer data) | |
90 { | |
91 save_prefs(); | |
92 | |
93 /* only run once */ | |
94 return FALSE; | |
95 } | |
96 | |
97 static gboolean gtk_blist_configure_cb(GtkWidget *w, GdkEventConfigure *event, gpointer data) | |
98 { | |
99 /* unfortunately GdkEventConfigure ignores the window gravity, but * | |
100 * the only way we have of setting the position doesn't. we have to * | |
101 * call get_position and get_size because they do pay attention to * | |
102 * the gravity. this is inefficient and I agree it sucks, but it's * | |
103 * more likely to work correctly. - Robot101 */ | |
104 gint x, y; | |
105 | |
106 /* check for visibility because when we aren't visible, this will * | |
107 * give us bogus (0,0) coordinates. - xOr */ | |
108 if (GTK_WIDGET_VISIBLE(w)) { | |
109 gtk_window_get_position(GTK_WINDOW(w), &x, &y); | |
110 | |
111 if (x != blist_pos.x || | |
112 y != blist_pos.y || | |
113 event->width != blist_pos.width || | |
114 event->height != blist_pos.height) { | |
115 blist_pos.x = x; | |
116 blist_pos.y = y; | |
117 blist_pos.width = event->width; | |
118 blist_pos.height = event->height; | |
119 | |
120 if (!g_main_context_find_source_by_user_data(NULL, >k_blist_save_prefs_cb)) { | |
121 g_timeout_add(5000, gtk_blist_save_prefs_cb, >k_blist_save_prefs_cb); | |
122 } | |
123 } | |
124 } | |
125 | |
126 /* continue to handle event normally */ | |
127 return FALSE; | |
128 } | |
129 | |
130 static gboolean gtk_blist_visibility_cb(GtkWidget *w, GdkEventVisibility *event, gpointer data) | |
131 { | |
132 if (event->state == GDK_VISIBILITY_FULLY_OBSCURED) | |
133 gaim_gtk_blist_obscured = TRUE; | |
134 else | |
135 gaim_gtk_blist_obscured = FALSE; | |
136 | |
137 /* continue to handle event normally */ | |
138 return FALSE; | |
139 } | |
140 | |
141 static void gtk_blist_menu_info_cb(GtkWidget *w, struct buddy *b) | |
142 { | |
143 serv_get_info(b->account->gc, b->name); | |
144 } | |
145 | |
146 static void gtk_blist_menu_im_cb(GtkWidget *w, struct buddy *b) | |
147 { | |
5234 | 148 gaim_conversation_new(GAIM_CONV_IM, b->account, b->name); |
5228 | 149 } |
150 | |
5234 | 151 static void gtk_blist_menu_join_cb(GtkWidget *w, struct chat *chat) |
5228 | 152 { |
5234 | 153 serv_join_chat(chat->account->gc, chat->components); |
154 } | |
155 | |
156 static void gtk_blist_menu_alias_cb(GtkWidget *w, GaimBlistNode *node) | |
157 { | |
158 if(GAIM_BLIST_NODE_IS_BUDDY(node)) | |
159 alias_dialog_bud((struct buddy*)node); | |
160 else if(GAIM_BLIST_NODE_IS_CHAT(node)) | |
161 alias_dialog_chat((struct chat*)node); | |
5228 | 162 } |
163 | |
164 static void gtk_blist_menu_bp_cb(GtkWidget *w, struct buddy *b) | |
165 { | |
166 gaim_gtkpounce_dialog_show(b, NULL); | |
167 } | |
168 | |
169 static void gtk_blist_menu_showlog_cb(GtkWidget *w, struct buddy *b) | |
170 { | |
5234 | 171 show_log(b->name); |
5228 | 172 } |
173 | |
174 static void gtk_blist_show_systemlog_cb() | |
175 { | |
5234 | 176 show_log(NULL); |
5228 | 177 } |
178 | |
179 static void gtk_blist_show_onlinehelp_cb() | |
180 { | |
5234 | 181 open_url(NULL, WEBSITE "documentation.php"); |
5228 | 182 } |
183 | |
184 static void gtk_blist_button_im_cb(GtkWidget *w, GtkTreeView *tv) | |
185 { | |
186 GtkTreeIter iter; | |
187 GtkTreeModel *model = gtk_tree_view_get_model(tv); | |
188 GtkTreeSelection *sel = gtk_tree_view_get_selection(tv); | |
189 | |
190 if(gtk_tree_selection_get_selected(sel, &model, &iter)){ | |
191 GaimBlistNode *node; | |
192 | |
193 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
194 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
195 gaim_conversation_new(GAIM_CONV_IM, ((struct buddy*)node)->account, ((struct buddy*)node)->name); | |
196 return; | |
197 } | |
198 } | |
199 show_im_dialog(); | |
200 } | |
201 | |
202 static void gtk_blist_button_info_cb(GtkWidget *w, GtkTreeView *tv) | |
203 { | |
204 GtkTreeIter iter; | |
205 GtkTreeModel *model = gtk_tree_view_get_model(tv); | |
206 GtkTreeSelection *sel = gtk_tree_view_get_selection(tv); | |
207 | |
208 if(gtk_tree_selection_get_selected(sel, &model, &iter)){ | |
209 GaimBlistNode *node; | |
210 | |
211 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
212 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
213 serv_get_info(((struct buddy*)node)->account->gc, ((struct buddy*)node)->name); | |
214 return; | |
215 } | |
216 } | |
217 show_info_dialog(); | |
218 } | |
219 | |
5234 | 220 static void gtk_blist_button_chat_cb(GtkWidget *w, GtkTreeView *tv) |
5228 | 221 { |
5234 | 222 GtkTreeIter iter; |
223 GtkTreeModel *model = gtk_tree_view_get_model(tv); | |
224 GtkTreeSelection *sel = gtk_tree_view_get_selection(tv); | |
225 | |
226 if(gtk_tree_selection_get_selected(sel, &model, &iter)){ | |
227 GaimBlistNode *node; | |
228 | |
229 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
230 if (GAIM_BLIST_NODE_IS_CHAT(node)) { | |
231 serv_join_chat(((struct chat *)node)->account->gc, ((struct chat*)node)->components); | |
232 return; | |
233 } | |
234 } | |
5228 | 235 join_chat(); |
236 } | |
237 | |
238 static void gtk_blist_button_away_cb(GtkWidget *w, gpointer data) | |
239 { | |
240 gtk_menu_popup(GTK_MENU(awaymenu), NULL, NULL, NULL, NULL, 1, GDK_CURRENT_TIME); | |
241 } | |
242 | |
243 static void gtk_blist_row_expanded_cb(GtkTreeView *tv, GtkTreeIter *iter, GtkTreePath *path, gpointer user_data) { | |
244 GaimBlistNode *node; | |
245 GValue val = {0,}; | |
246 | |
247 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), iter, NODE_COLUMN, &val); | |
248 | |
249 node = g_value_get_pointer(&val); | |
250 | |
251 if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
252 gaim_group_set_setting((struct group *)node, "collapsed", NULL); | |
253 gaim_blist_save(); | |
254 } | |
255 } | |
256 | |
257 static void gtk_blist_row_collapsed_cb(GtkTreeView *tv, GtkTreeIter *iter, GtkTreePath *path, gpointer user_data) { | |
258 GaimBlistNode *node; | |
259 GValue val = {0,}; | |
260 | |
261 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), iter, NODE_COLUMN, &val); | |
262 | |
263 node = g_value_get_pointer(&val); | |
264 | |
265 if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
266 gaim_group_set_setting((struct group *)node, "collapsed", "true"); | |
267 gaim_blist_save(); | |
268 } | |
269 } | |
270 | |
271 static void gtk_blist_row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) { | |
272 GaimBlistNode *node; | |
273 GtkTreeIter iter; | |
274 GValue val = { 0, }; | |
275 | |
276 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
277 | |
278 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
279 node = g_value_get_pointer(&val); | |
280 | |
281 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
282 struct gaim_conversation *conv = | |
283 gaim_conversation_new(GAIM_CONV_IM, ((struct buddy*)node)->account, ((struct buddy*)node)->name); | |
284 if(conv) { | |
285 gaim_window_raise(gaim_conversation_get_window(conv)); | |
286 gaim_window_switch_conversation( | |
287 gaim_conversation_get_window(conv), | |
288 gaim_conversation_get_index(conv)); | |
289 } | |
5234 | 290 } else if (GAIM_BLIST_NODE_IS_CHAT(node)) { |
291 serv_join_chat(((struct chat *)node)->account->gc, ((struct chat*)node)->components); | |
5228 | 292 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
293 if (gtk_tree_view_row_expanded(tv, path)) | |
294 gtk_tree_view_collapse_row(tv, path); | |
295 else | |
296 gtk_tree_view_expand_row(tv,path,FALSE); | |
297 } | |
298 } | |
299 | |
5234 | 300 static void gaim_gtk_blist_add_chat_cb() |
301 { | |
302 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); | |
303 GtkTreeIter iter; | |
304 GaimBlistNode *node; | |
305 | |
306 if(gtk_tree_selection_get_selected(sel, NULL, &iter)){ | |
307 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
308 if (GAIM_BLIST_NODE_IS_BUDDY(node) || GAIM_BLIST_NODE_IS_CHAT(node)) | |
309 show_add_chat(NULL, (struct group*)node->parent); | |
310 else if (GAIM_BLIST_NODE_IS_GROUP(node)) | |
311 show_add_chat(NULL, (struct group*)node); | |
312 } | |
313 else { | |
314 show_add_chat(NULL, NULL); | |
315 } | |
316 } | |
317 | |
5228 | 318 static void gaim_gtk_blist_add_buddy_cb() |
319 { | |
320 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); | |
321 GtkTreeIter iter; | |
322 GaimBlistNode *node; | |
323 | |
324 if(gtk_tree_selection_get_selected(sel, NULL, &iter)){ | |
325 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
5234 | 326 if (GAIM_BLIST_NODE_IS_BUDDY(node) || GAIM_BLIST_NODE_IS_CHAT(node)) |
5228 | 327 show_add_buddy(NULL, NULL, ((struct group*)node->parent)->name, NULL); |
328 else if (GAIM_BLIST_NODE_IS_GROUP(node)) | |
329 show_add_buddy(NULL, NULL, ((struct group*)node)->name, NULL); | |
330 } | |
331 else { | |
332 show_add_buddy(NULL, NULL, NULL, NULL); | |
333 } | |
334 } | |
335 | |
336 static void | |
337 gaim_gtk_blist_remove_cb (GtkWidget *w, GaimBlistNode *node) | |
338 { | |
339 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
340 struct buddy *b = (struct buddy*)node; | |
341 show_confirm_del(b->account->gc, b->name); | |
5234 | 342 } else if (GAIM_BLIST_NODE_IS_CHAT(node)) { |
343 struct chat *chat = (struct chat*)node; | |
344 show_confirm_del_chat(chat); | |
5228 | 345 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
346 struct group *g = (struct group*)node; | |
347 show_confirm_del_group(g); | |
348 } | |
349 } | |
350 | |
351 static void gaim_proto_menu_cb(GtkMenuItem *item, struct buddy *b) | |
352 { | |
353 struct proto_buddy_menu *pbm = g_object_get_data(G_OBJECT(item), "gaimcallback"); | |
354 if (pbm->callback) | |
355 pbm->callback(pbm->gc, b->name); | |
356 } | |
357 | |
358 static gboolean gtk_blist_button_press_cb(GtkWidget *tv, GdkEventButton *event, gpointer null) | |
359 { | |
360 GtkTreePath *path; | |
361 GaimBlistNode *node; | |
362 GValue val = { 0, }; | |
363 GtkTreeIter iter; | |
364 GtkWidget *menu, *menuitem; | |
365 GtkTreeSelection *sel; | |
366 GList *list; | |
367 GaimPlugin *prpl = NULL; | |
368 GaimPluginProtocolInfo *prpl_info = NULL; | |
369 | |
370 if (event->button != 3) | |
371 return FALSE; | |
372 | |
373 /* Here we figure out which node was clicked */ | |
374 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL)) | |
375 return FALSE; | |
376 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
377 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
378 node = g_value_get_pointer(&val); | |
379 menu = gtk_menu_new(); | |
380 | |
381 if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
5366 | 382 gaim_new_item_from_stock(menu, _("Add a _Buddy"), GTK_STOCK_ADD, G_CALLBACK(gaim_gtk_blist_add_buddy_cb), node, 0, 0, NULL); |
5307 | 383 gaim_new_item_from_stock(menu, _("Add a C_hat"), GTK_STOCK_ADD, G_CALLBACK(gaim_gtk_blist_add_chat_cb), node, 0, 0, NULL); |
5228 | 384 gaim_new_item_from_stock(menu, _("_Delete Group"), GTK_STOCK_REMOVE, G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL); |
385 gaim_new_item_from_stock(menu, _("_Rename"), NULL, G_CALLBACK(show_rename_group), node, 0, 0, NULL); | |
5234 | 386 } else if (GAIM_BLIST_NODE_IS_CHAT(node)) { |
387 gaim_new_item_from_stock(menu, _("_Join"), GAIM_STOCK_CHAT, G_CALLBACK(gtk_blist_menu_join_cb), node, 0, 0, NULL); | |
388 gaim_new_item_from_stock(menu, _("_Alias"), GAIM_STOCK_EDIT, G_CALLBACK(gtk_blist_menu_alias_cb), node, 0, 0, NULL); | |
389 gaim_new_item_from_stock(menu, _("_Remove"), GTK_STOCK_REMOVE, G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL); | |
5228 | 390 } else if (GAIM_BLIST_NODE_IS_BUDDY(node)) { |
391 /* Protocol specific options */ | |
392 prpl = gaim_find_prpl(((struct buddy*)node)->account->protocol); | |
393 | |
394 if (prpl != NULL) | |
395 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
396 | |
397 if (prpl && prpl_info->get_info) | |
398 gaim_new_item_from_stock(menu, _("_Get Info"), GAIM_STOCK_INFO, G_CALLBACK(gtk_blist_menu_info_cb), node, 0, 0, NULL); | |
399 | |
400 gaim_new_item_from_stock(menu, _("_IM"), GAIM_STOCK_IM, G_CALLBACK(gtk_blist_menu_im_cb), node, 0, 0, NULL); | |
401 gaim_new_item_from_stock(menu, _("Add Buddy _Pounce"), NULL, G_CALLBACK(gtk_blist_menu_bp_cb), node, 0, 0, NULL); | |
402 gaim_new_item_from_stock(menu, _("View _Log"), NULL, G_CALLBACK(gtk_blist_menu_showlog_cb), node, 0, 0, NULL); | |
403 | |
5290 | 404 if (prpl && prpl_info->buddy_menu) { |
5228 | 405 list = prpl_info->buddy_menu(((struct buddy*)node)->account->gc, ((struct buddy*)node)->name); |
406 while (list) { | |
407 struct proto_buddy_menu *pbm = list->data; | |
408 menuitem = gtk_menu_item_new_with_mnemonic(pbm->label); | |
409 g_object_set_data(G_OBJECT(menuitem), "gaimcallback", pbm); | |
410 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gaim_proto_menu_cb), node); | |
411 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
412 list = list->next; | |
413 } | |
414 } | |
415 | |
416 gaim_event_broadcast (event_draw_menu, menu, ((struct buddy *) node)->name); | |
417 | |
418 gaim_separator(menu); | |
419 gaim_new_item_from_stock(menu, _("_Alias"), GAIM_STOCK_EDIT, G_CALLBACK(gtk_blist_menu_alias_cb), node, 0, 0, NULL); | |
420 gaim_new_item_from_stock(menu, _("_Remove"), GTK_STOCK_REMOVE, G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL); | |
421 } | |
422 | |
423 gtk_widget_show_all(menu); | |
424 | |
425 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time); | |
426 | |
427 #if (1) /* This code only exists because GTK doesn't work. If we return FALSE here, as would be normal | |
428 * the event propoagates down and somehow gets interpreted as the start of a drag event. */ | |
429 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)); | |
430 gtk_tree_selection_select_path(sel, path); | |
431 gtk_tree_path_free(path); | |
432 return TRUE; | |
433 #endif | |
434 } | |
435 | |
436 static void gaim_gtk_blist_show_empty_groups_cb(gpointer data, guint action, GtkWidget *item) | |
437 { | |
438 if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item))) | |
439 blist_options &= ~OPT_BLIST_NO_MT_GRP; | |
440 else | |
441 blist_options |= OPT_BLIST_NO_MT_GRP; | |
442 save_prefs(); | |
443 gaim_gtk_blist_refresh(gaim_get_blist()); | |
444 } | |
445 | |
446 static void gaim_gtk_blist_edit_mode_cb(gpointer callback_data, guint callback_action, | |
447 GtkWidget *checkitem) { | |
448 if(gtkblist->window->window) { | |
449 GdkCursor *cursor = gdk_cursor_new(GDK_WATCH); | |
450 gdk_window_set_cursor(gtkblist->window->window, cursor); | |
451 while (gtk_events_pending()) | |
452 gtk_main_iteration(); | |
453 gdk_cursor_unref(cursor); | |
454 } | |
455 | |
456 if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(checkitem))) | |
457 blist_options |= OPT_BLIST_SHOW_OFFLINE; | |
458 else | |
459 blist_options &= ~OPT_BLIST_SHOW_OFFLINE; | |
460 save_prefs(); | |
461 | |
462 if(gtkblist->window->window) { | |
463 GdkCursor *cursor = gdk_cursor_new(GDK_LEFT_PTR); | |
464 gdk_window_set_cursor(gtkblist->window->window, cursor); | |
465 gdk_cursor_unref(cursor); | |
466 } | |
467 | |
468 gaim_gtk_blist_refresh(gaim_get_blist()); | |
469 } | |
470 | |
471 static void gaim_gtk_blist_drag_data_get_cb (GtkWidget *widget, | |
472 GdkDragContext *dc, | |
473 GtkSelectionData *data, | |
474 guint info, | |
475 guint time, | |
476 gpointer *null) | |
477 { | |
478 if (data->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE)) { | |
479 GtkTreeRowReference *ref = g_object_get_data(G_OBJECT(dc), "gtk-tree-view-source-row"); | |
480 GtkTreePath *sourcerow = gtk_tree_row_reference_get_path(ref); | |
481 GtkTreeIter iter; | |
482 GaimBlistNode *node = NULL; | |
483 GValue val = {0}; | |
5273 | 484 if(!sourcerow) |
485 return; | |
5228 | 486 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, sourcerow); |
487 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
488 node = g_value_get_pointer(&val); | |
489 gtk_selection_data_set (data, | |
490 gdk_atom_intern ("GAIM_BLIST_NODE", FALSE), | |
491 8, /* bits */ | |
492 (void*)&node, | |
493 sizeof (node)); | |
5273 | 494 |
5228 | 495 gtk_tree_path_free(sourcerow); |
496 } | |
5273 | 497 |
5228 | 498 } |
499 | |
500 static void gaim_gtk_blist_drag_data_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, | |
501 GtkSelectionData *sd, guint info, guint t) | |
502 { | |
503 if (sd->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE) && sd->data) { | |
504 GaimBlistNode *n = NULL; | |
505 GtkTreePath *path = NULL; | |
506 GtkTreeViewDropPosition position; | |
507 memcpy(&n, sd->data, sizeof(n)); | |
508 if(gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), x, y, &path, &position)) { | |
509 /* if we're here, I think it means the drop is ok */ | |
510 GtkTreeIter iter; | |
511 GaimBlistNode *node; | |
512 GValue val = {0}; | |
513 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
514 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
515 node = g_value_get_pointer(&val); | |
516 | |
517 if (GAIM_BLIST_NODE_IS_BUDDY(n)) { | |
518 struct buddy *b = (struct buddy*)n; | |
5234 | 519 if (GAIM_BLIST_NODE_IS_BUDDY(node) || |
520 GAIM_BLIST_NODE_IS_CHAT(node)) { | |
5228 | 521 switch(position) { |
522 case GTK_TREE_VIEW_DROP_AFTER: | |
523 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
524 gaim_blist_add_buddy(b, (struct group*)node->parent, node); | |
525 break; | |
526 case GTK_TREE_VIEW_DROP_BEFORE: | |
527 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
528 gaim_blist_add_buddy(b, (struct group*)node->parent, node->prev); | |
529 break; | |
530 } | |
531 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
532 gaim_blist_add_buddy(b, (struct group*)node, NULL); | |
533 } | |
5234 | 534 } else if (GAIM_BLIST_NODE_IS_CHAT(n)) { |
535 struct chat *chat = (struct chat*)n; | |
536 if (GAIM_BLIST_NODE_IS_BUDDY(node) || | |
537 GAIM_BLIST_NODE_IS_CHAT(node)) { | |
538 switch(position) { | |
539 case GTK_TREE_VIEW_DROP_AFTER: | |
540 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
541 gaim_blist_add_chat(chat, (struct group*)node->parent, node); | |
542 break; | |
543 case GTK_TREE_VIEW_DROP_BEFORE: | |
544 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
545 gaim_blist_add_chat(chat, (struct group*)node->parent, node->prev); | |
546 break; | |
547 } | |
548 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
549 gaim_blist_add_chat(chat, (struct group*)node, NULL); | |
550 } | |
5228 | 551 } else if (GAIM_BLIST_NODE_IS_GROUP(n)) { |
552 struct group *g = (struct group*)n; | |
553 if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
554 switch (position) { | |
555 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
556 case GTK_TREE_VIEW_DROP_AFTER: | |
557 gaim_blist_add_group(g, node); | |
558 break; | |
559 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
560 case GTK_TREE_VIEW_DROP_BEFORE: | |
561 gaim_blist_add_group(g, node->prev); | |
562 break; | |
563 } | |
564 | |
5234 | 565 } else if(GAIM_BLIST_NODE_IS_BUDDY(node) || |
566 GAIM_BLIST_NODE_IS_CHAT(node)) { | |
5228 | 567 gaim_blist_add_group(g, node->parent); |
568 } | |
569 | |
570 } | |
571 | |
572 gtk_tree_path_free(path); | |
573 gaim_blist_save(); | |
574 } | |
575 } | |
576 } | |
577 | |
5234 | 578 static void gaim_gtk_blist_paint_tip(GtkWidget *widget, GdkEventExpose *event, GaimBlistNode *node) |
5228 | 579 { |
580 GtkStyle *style; | |
5234 | 581 GdkPixbuf *pixbuf = gaim_gtk_blist_get_status_icon(node, GAIM_STATUS_ICON_LARGE); |
5228 | 582 PangoLayout *layout; |
5234 | 583 char *tooltiptext = gaim_get_tooltip_text(node); |
5228 | 584 |
585 layout = gtk_widget_create_pango_layout (gtkblist->tipwindow, NULL); | |
586 pango_layout_set_markup(layout, tooltiptext, strlen(tooltiptext)); | |
587 pango_layout_set_wrap(layout, PANGO_WRAP_WORD); | |
588 pango_layout_set_width(layout, 300000); | |
589 style = gtkblist->tipwindow->style; | |
590 | |
591 gtk_paint_flat_box (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, | |
592 NULL, gtkblist->tipwindow, "tooltip", 0, 0, -1, -1); | |
593 | |
594 #if GTK_CHECK_VERSION(2,2,0) | |
595 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, pixbuf, | |
596 0, 0, 4, 4, -1 , -1, GDK_RGB_DITHER_NONE, 0, 0); | |
597 #else | |
598 gdk_pixbuf_render_to_drawable(pixbuf, GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, 0, 0, 4, 4, -1, -1, GDK_RGB_DITHER_NONE, 0, 0); | |
599 #endif | |
600 | |
601 gtk_paint_layout (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, TRUE, | |
602 NULL, gtkblist->tipwindow, "tooltip", 38, 4, layout); | |
603 | |
604 g_object_unref (pixbuf); | |
605 g_object_unref (layout); | |
606 g_free(tooltiptext); | |
607 return; | |
608 } | |
609 | |
610 static gboolean gaim_gtk_blist_tooltip_timeout(GtkWidget *tv) | |
611 { | |
612 GtkTreePath *path; | |
613 GtkTreeIter iter; | |
614 GaimBlistNode *node; | |
615 GValue val = {0}; | |
5234 | 616 int scr_w,scr_h, w, h, x, y; |
617 PangoLayout *layout; | |
618 char *tooltiptext = NULL; | |
5228 | 619 |
620 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), gtkblist->rect.x, gtkblist->rect.y, &path, NULL, NULL, NULL)) | |
621 return FALSE; | |
622 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
623 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
624 node = g_value_get_pointer(&val); | |
5234 | 625 if(!GAIM_BLIST_NODE_IS_BUDDY(node) && !GAIM_BLIST_NODE_IS_CHAT(node)) |
626 return FALSE; | |
5228 | 627 |
5234 | 628 tooltiptext = gaim_get_tooltip_text(node); |
629 gtkblist->tipwindow = gtk_window_new(GTK_WINDOW_POPUP); | |
630 gtkblist->tipwindow->parent = tv; | |
631 gtk_widget_set_app_paintable(gtkblist->tipwindow, TRUE); | |
632 gtk_window_set_resizable(GTK_WINDOW(gtkblist->tipwindow), FALSE); | |
633 gtk_widget_set_name(gtkblist->tipwindow, "gtk-tooltips"); | |
634 g_signal_connect(G_OBJECT(gtkblist->tipwindow), "expose_event", | |
635 G_CALLBACK(gaim_gtk_blist_paint_tip), node); | |
636 gtk_widget_ensure_style (gtkblist->tipwindow); | |
637 | |
638 layout = gtk_widget_create_pango_layout (gtkblist->tipwindow, NULL); | |
639 pango_layout_set_wrap(layout, PANGO_WRAP_WORD); | |
640 pango_layout_set_width(layout, 300000); | |
641 pango_layout_set_markup(layout, tooltiptext, strlen(tooltiptext)); | |
642 scr_w = gdk_screen_width(); | |
643 scr_h = gdk_screen_height(); | |
644 pango_layout_get_size (layout, &w, &h); | |
645 w = PANGO_PIXELS(w) + 8; | |
646 h = PANGO_PIXELS(h) + 8; | |
5228 | 647 |
5234 | 648 /* 38 is the size of a large status icon plus 4 pixels padding on each side. |
649 * I should #define this or something */ | |
650 w = w + 38; | |
651 h = MAX(h, 38); | |
652 | |
653 gdk_window_get_pointer(NULL, &x, &y, NULL); | |
654 if (GTK_WIDGET_NO_WINDOW(gtkblist->window)) | |
655 y+=gtkblist->window->allocation.y; | |
656 | |
657 x -= ((w >> 1) + 4); | |
5228 | 658 |
5234 | 659 if ((x + w) > scr_w) |
660 x -= (x + w) - scr_w; | |
661 else if (x < 0) | |
662 x = 0; | |
5228 | 663 |
5234 | 664 if ((y + h + 4) > scr_h) |
665 y = y - h; | |
666 else | |
667 y = y + 6; | |
668 g_object_unref (layout); | |
669 g_free(tooltiptext); | |
670 gtk_widget_set_size_request(gtkblist->tipwindow, w, h); | |
671 gtk_window_move(GTK_WINDOW(gtkblist->tipwindow), x, y); | |
672 gtk_widget_show(gtkblist->tipwindow); | |
5228 | 673 |
674 gtk_tree_path_free(path); | |
675 return FALSE; | |
676 } | |
677 | |
678 static gboolean gaim_gtk_blist_motion_cb (GtkWidget *tv, GdkEventMotion *event, gpointer null) | |
679 { | |
680 GtkTreePath *path; | |
681 if (gtkblist->timeout) { | |
682 if ((event->y > gtkblist->rect.y) && ((event->y - gtkblist->rect.height) < gtkblist->rect.y)) | |
683 return FALSE; | |
684 /* We've left the cell. Remove the timeout and create a new one below */ | |
685 if (gtkblist->tipwindow) { | |
686 gtk_widget_destroy(gtkblist->tipwindow); | |
687 gtkblist->tipwindow = NULL; | |
688 } | |
689 | |
690 g_source_remove(gtkblist->timeout); | |
691 } | |
692 | |
693 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL); | |
694 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, >kblist->rect); | |
695 if (path) | |
696 gtk_tree_path_free(path); | |
697 gtkblist->timeout = g_timeout_add(500, (GSourceFunc)gaim_gtk_blist_tooltip_timeout, tv); | |
698 return FALSE; | |
699 } | |
700 | |
701 static void gaim_gtk_blist_leave_cb (GtkWidget *w, GdkEventCrossing *e, gpointer n) | |
702 { | |
703 if (gtkblist->timeout) { | |
704 g_source_remove(gtkblist->timeout); | |
705 gtkblist->timeout = 0; | |
706 } | |
707 if (gtkblist->tipwindow) { | |
708 gtk_widget_destroy(gtkblist->tipwindow); | |
709 gtkblist->tipwindow = NULL; | |
710 } | |
711 } | |
712 | |
713 static void | |
714 toggle_debug(void) | |
715 { | |
716 misc_options ^= OPT_MISC_DEBUG; | |
717 | |
718 if ((misc_options & OPT_MISC_DEBUG)) | |
719 gaim_gtk_debug_window_show(); | |
720 else | |
721 gaim_gtk_debug_window_hide(); | |
722 | |
723 save_prefs(); | |
724 } | |
725 | |
726 | |
727 /*************************************************** | |
728 * Crap * | |
729 ***************************************************/ | |
730 static GtkItemFactoryEntry blist_menu[] = | |
731 { | |
732 /* Buddies menu */ | |
733 { N_("/_Buddies"), NULL, NULL, 0, "<Branch>" }, | |
734 { N_("/Buddies/New _Instant Message..."), "<CTL>I", show_im_dialog, 0, "<StockItem>", GAIM_STOCK_IM }, | |
735 { N_("/Buddies/Join a _Chat..."), "<CTL>C", join_chat, 0, "<StockItem>", GAIM_STOCK_CHAT }, | |
736 { N_("/Buddies/Get _User Info..."), "<CTL>J", show_info_dialog, 0, "<StockItem>", GAIM_STOCK_INFO }, | |
737 { "/Buddies/sep1", NULL, NULL, 0, "<Separator>" }, | |
738 { N_("/Buddies/_Show Offline Buddies"), NULL, gaim_gtk_blist_edit_mode_cb, 1, "<CheckItem>"}, | |
739 { N_("/Buddies/Show _Empty Groups"), NULL, gaim_gtk_blist_show_empty_groups_cb, 1, "<CheckItem>"}, | |
5307 | 740 { N_("/Buddies/_Add a Buddy..."), "<CTL>B", gaim_gtk_blist_add_buddy_cb, 0, "<StockItem>", GTK_STOCK_ADD }, |
741 { N_("/Buddies/Add a C_hat..."), NULL, gaim_gtk_blist_add_chat_cb, 0, "<StockItem>", GTK_STOCK_ADD }, | |
5228 | 742 { N_("/Buddies/Add a _Group..."), NULL, show_add_group, 0, NULL}, |
743 { "/Buddies/sep2", NULL, NULL, 0, "<Separator>" }, | |
744 { N_("/Buddies/_Signoff"), "<CTL>D", signoff_all, 0, "<StockItem>", GAIM_STOCK_SIGN_OFF }, | |
745 { N_("/Buddies/_Quit"), "<CTL>Q", do_quit, 0, "<StockItem>", GTK_STOCK_QUIT }, | |
746 | |
747 /* Tools */ | |
748 { N_("/_Tools"), NULL, NULL, 0, "<Branch>" }, | |
749 { N_("/Tools/_Away"), NULL, NULL, 0, "<Branch>" }, | |
750 { N_("/Tools/Buddy _Pounce"), NULL, NULL, 0, "<Branch>" }, | |
751 { N_("/Tools/P_rotocol Actions"), NULL, NULL, 0, "<Branch>" }, | |
752 { "/Tools/sep1", NULL, NULL, 0, "<Separator>" }, | |
753 { N_("/Tools/A_ccounts..."), "<CTL>A", account_editor, 0, "<StockItem>", GAIM_STOCK_ACCOUNTS }, | |
754 { N_("/Tools/_File Transfers..."), NULL, gaim_show_xfer_dialog, 0, "<StockItem>", GAIM_STOCK_FILE_TRANSFER }, | |
755 { N_("/Tools/Preferences..."), "<CTL>P", show_prefs, 0, "<StockItem>", GTK_STOCK_PREFERENCES }, | |
756 { N_("/Tools/Pr_ivacy..."), NULL, show_privacy_options, 0, "<StockItem>", GAIM_STOCK_PRIVACY }, | |
757 { "/Tools/sep2", NULL, NULL, 0, "<Separator>" }, | |
758 { N_("/Tools/View System _Log..."), NULL, gtk_blist_show_systemlog_cb, 0, NULL }, | |
759 | |
760 /* Help */ | |
761 { N_("/_Help"), NULL, NULL, 0, "<Branch>" }, | |
762 { N_("/Help/Online _Help"), "F1", gtk_blist_show_onlinehelp_cb, 0, "<StockItem>", GTK_STOCK_HELP }, | |
763 { N_("/Help/_Debug Window..."), NULL, toggle_debug, 0, NULL }, | |
5307 | 764 { N_("/Help/_About..."), "<CTL>F1", show_about, 0, "<StockItem>", GAIM_STOCK_ABOUT }, |
5228 | 765 }; |
766 | |
767 /********************************************************* | |
768 * Private Utility functions * | |
769 *********************************************************/ | |
770 | |
5234 | 771 static char *gaim_get_tooltip_text(GaimBlistNode *node) |
5228 | 772 { |
5237 | 773 GaimPlugin *prpl; |
774 GaimPluginProtocolInfo *prpl_info = NULL; | |
5228 | 775 char *text = NULL; |
776 | |
5234 | 777 if(GAIM_BLIST_NODE_IS_CHAT(node)) { |
778 struct chat *chat = (struct chat *)node; | |
5237 | 779 char *name = NULL; |
5274 | 780 struct proto_chat_entry *pce; |
781 GList *parts, *tmp; | |
782 GString *parts_text = g_string_new(""); | |
783 | |
784 prpl = gaim_find_prpl(chat->account->protocol); | |
785 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
786 | |
787 parts = prpl_info->chat_info(chat->account->gc); | |
5237 | 788 |
789 if(chat->alias) { | |
790 name = g_markup_escape_text(chat->alias, -1); | |
791 } else { | |
792 pce = parts->data; | |
793 name = g_markup_escape_text(g_hash_table_lookup(chat->components, | |
794 pce->identifier), -1); | |
5274 | 795 } |
796 if(g_slist_length(connections) > 1) { | |
797 char *account = g_markup_escape_text(chat->account->username, -1); | |
798 g_string_append_printf(parts_text, _("\n<b>Account:</b> %s"), | |
799 account); | |
800 g_free(account); | |
5237 | 801 } |
5274 | 802 for(tmp = parts; tmp; tmp = tmp->next) { |
803 char *label, *value; | |
804 pce = tmp->data; | |
5237 | 805 |
5274 | 806 label = g_markup_escape_text(pce->label, -1); |
807 | |
808 value = g_markup_escape_text(g_hash_table_lookup(chat->components, | |
809 pce->identifier), -1); | |
810 | |
811 g_string_append_printf(parts_text, "\n<b>%s</b> %s", label, value); | |
812 g_free(label); | |
813 g_free(value); | |
814 g_free(pce); | |
815 } | |
816 g_list_free(parts); | |
817 | |
818 text = g_strdup_printf("<span size='larger' weight='bold'>%s</span>%s", | |
819 name, parts_text->str); | |
820 g_string_free(parts_text, TRUE); | |
5237 | 821 g_free(name); |
5234 | 822 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) { |
823 struct buddy *b = (struct buddy *)node; | |
824 char *statustext = NULL; | |
825 char *aliastext = NULL, *nicktext = NULL; | |
826 char *warning = NULL, *idletime = NULL; | |
5274 | 827 char *accounttext = NULL; |
5228 | 828 |
5234 | 829 prpl = gaim_find_prpl(b->account->protocol); |
830 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
831 | |
832 if (prpl_info->tooltip_text) { | |
833 const char *end; | |
834 statustext = prpl_info->tooltip_text(b); | |
5228 | 835 |
5234 | 836 if(statustext && !g_utf8_validate(statustext, -1, &end)) { |
837 char *new = g_strndup(statustext, | |
838 g_utf8_pointer_to_offset(statustext, end)); | |
839 g_free(statustext); | |
840 statustext = new; | |
841 } | |
842 } | |
843 | |
844 if (!statustext && !GAIM_BUDDY_IS_ONLINE(b)) | |
845 statustext = g_strdup(_("<b>Status:</b> Offline")); | |
5228 | 846 |
5341 | 847 if (b->idle > 0) |
848 idletime = sec_to_text(time(NULL) - b->idle); | |
5228 | 849 |
5234 | 850 if(b->alias && b->alias[0]) |
851 aliastext = g_markup_escape_text(b->alias, -1); | |
5228 | 852 |
5234 | 853 if(b->server_alias) |
854 nicktext = g_markup_escape_text(b->server_alias, -1); | |
5228 | 855 |
5234 | 856 if (b->evil > 0) |
857 warning = g_strdup_printf(_("%d%%"), b->evil); | |
5228 | 858 |
5274 | 859 if(g_slist_length(connections) > 1) |
860 accounttext = g_markup_escape_text(b->account->username, -1); | |
861 | |
5234 | 862 text = g_strdup_printf("<span size='larger' weight='bold'>%s</span>" |
5274 | 863 "%s %s" /* Account */ |
5228 | 864 "%s %s" /* Alias */ |
5234 | 865 "%s %s" /* Nickname */ |
5228 | 866 "%s %s" /* Idle */ |
867 "%s %s" /* Warning */ | |
868 "%s%s" /* Status */ | |
869 "%s", | |
870 b->name, | |
5274 | 871 accounttext ? _("\n<b>Account:</b>") : "", accounttext ? accounttext : "", |
5228 | 872 aliastext ? _("\n<b>Alias:</b>") : "", aliastext ? aliastext : "", |
873 nicktext ? _("\n<b>Nickname:</b>") : "", nicktext ? nicktext : "", | |
874 idletime ? _("\n<b>Idle:</b>") : "", idletime ? idletime : "", | |
875 b->evil ? _("\n<b>Warned:</b>") : "", b->evil ? warning : "", | |
876 statustext ? "\n" : "", statustext ? statustext : "", | |
877 !g_ascii_strcasecmp(b->name, "robflynn") ? _("\n<b>Description:</b> Spooky") : ""); | |
5234 | 878 |
879 if(warning) | |
880 g_free(warning); | |
881 if(idletime) | |
882 g_free(idletime); | |
883 if(statustext) | |
884 g_free(statustext); | |
885 if(nicktext) | |
886 g_free(nicktext); | |
887 if(aliastext) | |
888 g_free(aliastext); | |
5274 | 889 if(accounttext) |
890 g_free(accounttext); | |
5234 | 891 } |
5228 | 892 |
893 return text; | |
894 } | |
895 | |
5234 | 896 GdkPixbuf *gaim_gtk_blist_get_status_icon(GaimBlistNode *node, GaimStatusIconSize size) |
5228 | 897 { |
898 GdkPixbuf *status = NULL; | |
899 GdkPixbuf *scale = NULL; | |
900 GdkPixbuf *emblem = NULL; | |
901 gchar *filename = NULL; | |
902 const char *protoname = NULL; | |
903 | |
904 char *se = NULL, *sw = NULL ,*nw = NULL ,*ne = NULL; | |
905 | |
906 int scalesize = 30; | |
907 | |
5234 | 908 GaimPlugin *prpl = NULL; |
5228 | 909 GaimPluginProtocolInfo *prpl_info = NULL; |
910 | |
5234 | 911 if(GAIM_BLIST_NODE_IS_BUDDY(node)) |
912 prpl = gaim_find_prpl(((struct buddy *)node)->account->protocol); | |
913 else if(GAIM_BLIST_NODE_IS_CHAT(node)) | |
914 prpl = gaim_find_prpl(((struct chat *)node)->account->protocol); | |
5228 | 915 |
5234 | 916 if (!prpl) |
5228 | 917 return NULL; |
918 | |
919 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
920 | |
5234 | 921 if (prpl_info->list_icon) { |
922 if(GAIM_BLIST_NODE_IS_BUDDY(node)) | |
923 protoname = prpl_info->list_icon(((struct buddy*)node)->account, | |
924 (struct buddy *)node); | |
925 else if(GAIM_BLIST_NODE_IS_CHAT(node)) | |
926 protoname = prpl_info->list_icon(((struct chat*)node)->account, NULL); | |
927 } | |
928 | |
929 if (GAIM_BLIST_NODE_IS_BUDDY(node) && | |
930 ((struct buddy *)node)->present != GAIM_BUDDY_SIGNING_OFF && | |
5381
aa1cf48f76eb
[gaim-migrate @ 5757]
Christian Hammond <chipx86@chipx86.com>
parents:
5368
diff
changeset
|
931 ((struct buddy *)node)->present != GAIM_BUDDY_OFFLINE && |
5234 | 932 prpl_info->list_emblems) { |
933 prpl_info->list_emblems((struct buddy*)node, &se, &sw, &nw, &ne); | |
934 } | |
5228 | 935 |
936 if (size == GAIM_STATUS_ICON_SMALL) { | |
937 scalesize = 15; | |
938 sw = nw = ne = NULL; /* So that only the se icon will composite */ | |
939 } | |
940 | |
941 | |
5234 | 942 if (GAIM_BLIST_NODE_IS_BUDDY(node) && |
943 ((struct buddy*)node)->present == GAIM_BUDDY_SIGNING_ON) { | |
5228 | 944 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "login.png", NULL); |
945 status = gdk_pixbuf_new_from_file(filename,NULL); | |
946 g_free(filename); | |
5234 | 947 } else if (GAIM_BLIST_NODE_IS_BUDDY(node) && |
948 ((struct buddy *)node)->present == GAIM_BUDDY_SIGNING_OFF) { | |
5228 | 949 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "logout.png", NULL); |
950 status = gdk_pixbuf_new_from_file(filename,NULL); | |
951 g_free(filename); | |
952 | |
953 /* "Hey, what's all this crap?" you ask. Status icons will be themeable too, and | |
954 then it will look up protoname from the theme */ | |
955 } else { | |
956 char *image = g_strdup_printf("%s.png", protoname); | |
957 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
958 status = gdk_pixbuf_new_from_file(filename,NULL); | |
959 g_free(image); | |
960 g_free(filename); | |
961 | |
962 } | |
963 | |
964 if (!status) | |
965 return NULL; | |
966 | |
967 scale = gdk_pixbuf_scale_simple(status, scalesize, scalesize, GDK_INTERP_BILINEAR); | |
968 | |
969 g_object_unref(G_OBJECT(status)); | |
970 | |
971 /* Emblems */ | |
972 | |
973 /* Each protocol can specify up to four "emblems" to composite over the base icon. "away", "busy", "mobile user" | |
974 * are all examples of states represented by emblems. I'm not even really sure I like this yet. */ | |
975 | |
976 /* XXX Clean this crap up, yo. */ | |
977 if (se) { | |
978 char *image = g_strdup_printf("%s.png", se); | |
979 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
980 g_free(image); | |
981 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
982 g_free(filename); | |
983 if (emblem) { | |
984 if (size == GAIM_STATUS_ICON_LARGE) | |
985 gdk_pixbuf_composite (emblem, | |
986 scale, 15, 15, | |
987 15, 15, | |
988 15, 15, | |
989 1, 1, | |
990 GDK_INTERP_BILINEAR, | |
991 255); | |
992 else | |
993 gdk_pixbuf_composite (emblem, | |
994 scale, 5, 5, | |
995 10, 10, | |
996 5, 5, | |
997 .6, .6, | |
998 GDK_INTERP_BILINEAR, | |
999 255); | |
1000 g_object_unref(G_OBJECT(emblem)); | |
1001 } | |
1002 } | |
1003 if (sw) { | |
1004 char *image = g_strdup_printf("%s.png", sw); | |
1005 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
1006 g_free(image); | |
1007 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
1008 g_free(filename); | |
1009 if (emblem) { | |
1010 gdk_pixbuf_composite (emblem, | |
1011 scale, 0, 15, | |
1012 15, 15, | |
1013 0, 15, | |
1014 1, 1, | |
1015 GDK_INTERP_BILINEAR, | |
1016 255); | |
1017 g_object_unref(G_OBJECT(emblem)); | |
1018 } | |
1019 } | |
1020 if (nw) { | |
1021 char *image = g_strdup_printf("%s.png", nw); | |
1022 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
1023 g_free(image); | |
1024 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
1025 g_free(filename); | |
1026 if (emblem) { | |
1027 gdk_pixbuf_composite (emblem, | |
1028 scale, 0, 0, | |
1029 15, 15, | |
1030 0, 0, | |
1031 1, 1, | |
1032 GDK_INTERP_BILINEAR, | |
1033 255); | |
1034 g_object_unref(G_OBJECT(emblem)); | |
1035 } | |
1036 } | |
1037 if (ne) { | |
1038 char *image = g_strdup_printf("%s.png", ne); | |
1039 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
1040 g_free(image); | |
1041 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
1042 g_free(filename); | |
1043 if (emblem) { | |
1044 gdk_pixbuf_composite (emblem, | |
1045 scale, 15, 0, | |
1046 15, 15, | |
1047 15, 0, | |
1048 1, 1, | |
1049 GDK_INTERP_BILINEAR, | |
1050 255); | |
1051 g_object_unref(G_OBJECT(emblem)); | |
1052 } | |
1053 } | |
1054 | |
1055 | |
1056 /* Idle grey buddies affects the whole row. This converts the status icon to greyscale. */ | |
5234 | 1057 if (GAIM_BLIST_NODE_IS_BUDDY(node) && |
1058 ((struct buddy *)node)->present == GAIM_BUDDY_OFFLINE) | |
5228 | 1059 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); |
5234 | 1060 else if (GAIM_BLIST_NODE_IS_BUDDY(node) && |
1061 ((struct buddy *)node)->idle && | |
1062 blist_options & OPT_BLIST_GREY_IDLERS) | |
5228 | 1063 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.25, FALSE); |
1064 return scale; | |
1065 } | |
1066 | |
1067 static GdkPixbuf *gaim_gtk_blist_get_buddy_icon(struct buddy *b) | |
1068 { | |
1069 /* This just opens a file from ~/.gaim/icons/screenname. This needs to change to be more gooder. */ | |
1070 char *file; | |
1071 GdkPixbuf *buf, *ret; | |
1072 | |
1073 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) | |
1074 return NULL; | |
1075 | |
1076 if ((file = gaim_buddy_get_setting(b, "buddy_icon")) == NULL) | |
1077 return NULL; | |
1078 | |
1079 buf = gdk_pixbuf_new_from_file(file, NULL); | |
1080 g_free(file); | |
1081 | |
1082 | |
1083 if (buf) { | |
1084 if (!GAIM_BUDDY_IS_ONLINE(b)) | |
1085 gdk_pixbuf_saturate_and_pixelate(buf, buf, 0.0, FALSE); | |
1086 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS) | |
1087 gdk_pixbuf_saturate_and_pixelate(buf, buf, 0.25, FALSE); | |
1088 | |
1089 ret = gdk_pixbuf_scale_simple(buf,30,30, GDK_INTERP_BILINEAR); | |
1090 g_object_unref(G_OBJECT(buf)); | |
1091 return ret; | |
1092 } | |
1093 return NULL; | |
1094 } | |
1095 | |
1096 static gchar *gaim_gtk_blist_get_name_markup(struct buddy *b, gboolean selected) | |
1097 { | |
1098 char *name = gaim_get_buddy_alias(b); | |
1099 char *esc = g_markup_escape_text(name, strlen(name)), *text = NULL; | |
1100 GaimPlugin *prpl; | |
1101 GaimPluginProtocolInfo *prpl_info = NULL; | |
1102 /* XXX Clean up this crap */ | |
1103 | |
1104 int ihrs, imin; | |
1105 char *idletime = NULL, *warning = NULL, *statustext = NULL; | |
1106 time_t t; | |
1107 | |
1108 prpl = gaim_find_prpl(b->account->protocol); | |
1109 | |
1110 if (prpl != NULL) | |
1111 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
1112 | |
1113 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) { | |
1114 if ((b->idle && blist_options & OPT_BLIST_GREY_IDLERS && !selected) || !GAIM_BUDDY_IS_ONLINE(b)) { | |
1115 text = g_strdup_printf("<span color='dim grey'>%s</span>", | |
1116 esc); | |
1117 g_free(esc); | |
1118 return text; | |
1119 } else { | |
1120 return esc; | |
1121 } | |
1122 } | |
1123 | |
1124 time(&t); | |
1125 ihrs = (t - b->idle) / 3600; | |
1126 imin = ((t - b->idle) / 60) % 60; | |
1127 | |
1128 if (prpl && prpl_info->status_text) { | |
1129 char *tmp = prpl_info->status_text(b); | |
1130 const char *end; | |
1131 | |
1132 if(tmp && !g_utf8_validate(tmp, -1, &end)) { | |
1133 char *new = g_strndup(tmp, | |
1134 g_utf8_pointer_to_offset(tmp, end)); | |
1135 g_free(tmp); | |
1136 tmp = new; | |
1137 } | |
1138 | |
1139 if(tmp) { | |
1140 char buf[32]; | |
1141 char *c = tmp; | |
1142 int length = 0, vis=0; | |
1143 gboolean inside = FALSE; | |
1144 g_strdelimit(tmp, "\n", ' '); | |
1145 | |
1146 while(*c && vis < 20) { | |
1147 if(*c == '&') | |
1148 inside = TRUE; | |
1149 else if(*c == ';') | |
1150 inside = FALSE; | |
1151 if(!inside) | |
1152 vis++; | |
1153 length++; | |
1154 c++; /* this is fun */ | |
1155 } | |
1156 | |
1157 if(vis == 20) | |
1158 g_snprintf(buf, sizeof(buf), "%%.%ds...", length); | |
1159 else | |
1160 g_snprintf(buf, sizeof(buf), "%%s "); | |
1161 | |
1162 statustext = g_strdup_printf(buf, tmp); | |
1163 | |
1164 g_free(tmp); | |
1165 } | |
1166 } | |
1167 | |
1168 if (b->idle > 0) { | |
1169 if (ihrs) | |
1170 idletime = g_strdup_printf(_("Idle (%dh%02dm) "), ihrs, imin); | |
1171 else | |
1172 idletime = g_strdup_printf(_("Idle (%dm) "), imin); | |
1173 } | |
1174 | |
1175 if (b->evil > 0) | |
1176 warning = g_strdup_printf(_("Warned (%d%%) "), b->evil); | |
1177 | |
1178 if(!GAIM_BUDDY_IS_ONLINE(b) && !statustext) | |
1179 statustext = g_strdup("Offline "); | |
1180 | |
1181 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS && !selected) { | |
1182 text = g_strdup_printf("<span color='dim grey'>%s</span>\n" | |
1183 "<span color='dim grey' size='smaller'>%s%s%s</span>", | |
1184 esc, | |
1185 statustext != NULL ? statustext : "", | |
1186 idletime != NULL ? idletime : "", | |
1187 warning != NULL ? warning : ""); | |
1188 } else if (statustext == NULL && idletime == NULL && warning == NULL && GAIM_BUDDY_IS_ONLINE(b)) { | |
1189 text = g_strdup(esc); | |
1190 } else { | |
1191 text = g_strdup_printf("%s\n" | |
1192 "<span %s size='smaller'>%s%s%s</span>", esc, | |
1193 selected ? "" : "color='dim grey'", | |
1194 statustext != NULL ? statustext : "", | |
1195 idletime != NULL ? idletime : "", | |
1196 warning != NULL ? warning : ""); | |
1197 } | |
1198 if (idletime) | |
1199 g_free(idletime); | |
1200 if (warning) | |
1201 g_free(warning); | |
1202 if (statustext) | |
1203 g_free(statustext); | |
1204 if (esc) | |
1205 g_free(esc); | |
1206 | |
1207 return text; | |
1208 } | |
1209 | |
1210 static void gaim_gtk_blist_restore_position() | |
1211 { | |
1212 /* if the window exists, is hidden, we're saving positions, and the position is sane... */ | |
1213 if(gtkblist && gtkblist->window && | |
1214 !GTK_WIDGET_VISIBLE(gtkblist->window) && | |
1215 blist_pos.width != 0) { | |
1216 /* ...check position is on screen... */ | |
1217 if (blist_pos.x >= gdk_screen_width()) | |
1218 blist_pos.x = gdk_screen_width() - 100; | |
1219 else if (blist_pos.x < 0) | |
1220 blist_pos.x = 100; | |
1221 | |
1222 if (blist_pos.y >= gdk_screen_height()) | |
1223 blist_pos.y = gdk_screen_height() - 100; | |
1224 else if (blist_pos.y < 0) | |
1225 blist_pos.y = 100; | |
1226 | |
1227 /* ...and move it back. */ | |
1228 gtk_window_move(GTK_WINDOW(gtkblist->window), blist_pos.x, blist_pos.y); | |
1229 gtk_window_resize(GTK_WINDOW(gtkblist->window), blist_pos.width, blist_pos.height); | |
1230 } | |
1231 } | |
1232 | |
1233 static gboolean gaim_gtk_blist_refresh_timer(struct gaim_buddy_list *list) | |
1234 { | |
5234 | 1235 GaimBlistNode *group, *buddy; |
5228 | 1236 |
5234 | 1237 for(group = list->root; group; group = group->next) { |
1238 if(!GAIM_BLIST_NODE_IS_GROUP(group)) | |
1239 continue; | |
1240 for(buddy = group->child; buddy; buddy = buddy->next) { | |
1241 if(!GAIM_BLIST_NODE_IS_BUDDY(buddy)) | |
1242 continue; | |
5228 | 1243 if (((struct buddy *)buddy)->idle) |
1244 gaim_gtk_blist_update(list, buddy); | |
1245 } | |
1246 } | |
1247 | |
1248 /* keep on going */ | |
1249 return TRUE; | |
1250 } | |
1251 | |
5260 | 1252 static void gaim_gtk_blist_hide_node(struct gaim_buddy_list *list, GaimBlistNode *node) |
1253 { | |
1254 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
1255 GtkTreeIter iter; | |
1256 | |
1257 if (!gtknode || !gtknode->row || !gtkblist) | |
1258 return; | |
1259 | |
1260 if(gtkblist->selected_node == node) | |
1261 gtkblist->selected_node = NULL; | |
1262 | |
1263 if (get_iter_from_node(node, &iter)) { | |
1264 gtk_tree_store_remove(gtkblist->treemodel, &iter); | |
1265 if(GAIM_BLIST_NODE_IS_BUDDY(node) || GAIM_BLIST_NODE_IS_CHAT(node)) { | |
1266 gaim_gtk_blist_update(list, node->parent); | |
1267 } | |
1268 } | |
1269 gtk_tree_row_reference_free(gtknode->row); | |
1270 gtknode->row = NULL; | |
1271 } | |
1272 | |
1273 | |
5228 | 1274 /********************************************************************************** |
1275 * Public API Functions * | |
1276 **********************************************************************************/ | |
1277 static void gaim_gtk_blist_new_list(struct gaim_buddy_list *blist) | |
1278 { | |
1279 blist->ui_data = g_new0(struct gaim_gtk_buddy_list, 1); | |
1280 } | |
1281 | |
5256 | 1282 static void gaim_gtk_blist_new_node(GaimBlistNode *node) |
1283 { | |
1284 node->ui_data = g_new0(struct _gaim_gtk_blist_node, 1); | |
1285 } | |
1286 | |
5228 | 1287 void gaim_gtk_blist_update_columns() |
1288 { | |
1289 if(!gtkblist) | |
1290 return; | |
1291 | |
1292 if (blist_options & OPT_BLIST_SHOW_ICONS) { | |
1293 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, TRUE); | |
1294 gtk_tree_view_column_set_visible(gtkblist->idle_column, FALSE); | |
1295 gtk_tree_view_column_set_visible(gtkblist->warning_column, FALSE); | |
1296 } else { | |
1297 gtk_tree_view_column_set_visible(gtkblist->idle_column, blist_options & OPT_BLIST_SHOW_IDLETIME); | |
1298 gtk_tree_view_column_set_visible(gtkblist->warning_column, blist_options & OPT_BLIST_SHOW_WARN); | |
1299 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, FALSE); | |
1300 } | |
1301 } | |
1302 | |
1303 enum {DRAG_BUDDY, DRAG_ROW}; | |
1304 | |
1305 static char * | |
1306 item_factory_translate_func (const char *path, gpointer func_data) | |
1307 { | |
1308 return _(path); | |
1309 } | |
1310 | |
1311 static void gaim_gtk_blist_show(struct gaim_buddy_list *list) | |
1312 { | |
1313 GtkItemFactory *ift; | |
1314 GtkCellRenderer *rend; | |
1315 GtkTreeViewColumn *column; | |
1316 GtkWidget *sw; | |
1317 GtkWidget *button; | |
1318 GtkSizeGroup *sg; | |
1319 GtkAccelGroup *accel_group; | |
1320 GtkTreeSelection *selection; | |
1321 GtkTargetEntry gte[] = {{"GAIM_BLIST_NODE", GTK_TARGET_SAME_APP, DRAG_ROW}, | |
1322 {"application/x-im-contact", 0, DRAG_BUDDY}}; | |
1323 | |
1324 if (gtkblist && gtkblist->window) { | |
1325 gtk_widget_show(gtkblist->window); | |
1326 return; | |
1327 } | |
1328 | |
1329 gtkblist = GAIM_GTK_BLIST(list); | |
1330 | |
1331 gtkblist->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
1332 gtk_window_set_role(GTK_WINDOW(gtkblist->window), "buddy_list"); | |
1333 gtk_window_set_title(GTK_WINDOW(gtkblist->window), _("Buddy List")); | |
1334 | |
1335 GTK_WINDOW(gtkblist->window)->allow_shrink = TRUE; | |
1336 | |
1337 gtkblist->vbox = gtk_vbox_new(FALSE, 0); | |
1338 gtk_container_add(GTK_CONTAINER(gtkblist->window), gtkblist->vbox); | |
1339 | |
1340 g_signal_connect(G_OBJECT(gtkblist->window), "delete_event", G_CALLBACK(gtk_blist_delete_cb), NULL); | |
1341 g_signal_connect(G_OBJECT(gtkblist->window), "configure_event", G_CALLBACK(gtk_blist_configure_cb), NULL); | |
1342 g_signal_connect(G_OBJECT(gtkblist->window), "visibility_notify_event", G_CALLBACK(gtk_blist_visibility_cb), NULL); | |
1343 gtk_widget_add_events(gtkblist->window, GDK_VISIBILITY_NOTIFY_MASK); | |
1344 | |
1345 /******************************* Menu bar *************************************/ | |
1346 accel_group = gtk_accel_group_new(); | |
1347 gtk_window_add_accel_group(GTK_WINDOW (gtkblist->window), accel_group); | |
1348 g_object_unref(accel_group); | |
1349 ift = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GaimMain>", accel_group); | |
1350 gtk_item_factory_set_translate_func (ift, | |
1351 item_factory_translate_func, | |
1352 NULL, NULL); | |
1353 gtk_item_factory_create_items(ift, sizeof(blist_menu) / sizeof(*blist_menu), | |
1354 blist_menu, NULL); | |
1355 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtk_item_factory_get_widget(ift, "<GaimMain>"), FALSE, FALSE, 0); | |
1356 | |
1357 awaymenu = gtk_item_factory_get_widget(ift, N_("/Tools/Away")); | |
1358 do_away_menu(); | |
1359 | |
1360 gtkblist->bpmenu = gtk_item_factory_get_widget(ift, N_("/Tools/Buddy Pounce")); | |
1361 gaim_gtkpounce_menu_build(gtkblist->bpmenu); | |
1362 | |
1363 protomenu = gtk_item_factory_get_widget(ift, N_("/Tools/Protocol Actions")); | |
1364 do_proto_menu(); | |
1365 | |
1366 /****************************** GtkTreeView **********************************/ | |
1367 sw = gtk_scrolled_window_new(NULL,NULL); | |
1368 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); | |
1369 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
1370 | |
1371 gtkblist->treemodel = gtk_tree_store_new(BLIST_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_BOOLEAN, G_TYPE_STRING, | |
1372 G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_POINTER); | |
1373 | |
1374 gtkblist->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(gtkblist->treemodel)); | |
1375 gtk_widget_set_size_request(gtkblist->treeview, -1, 200); | |
1376 | |
1377 /* Set up selection stuff */ | |
1378 | |
1379 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); | |
1380 g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(gaim_gtk_blist_selection_changed), NULL); | |
1381 | |
1382 | |
1383 /* Set up dnd */ | |
1384 gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(gtkblist->treeview), GDK_BUTTON1_MASK, gte, | |
1385 2, GDK_ACTION_COPY); | |
1386 gtk_tree_view_enable_model_drag_dest(GTK_TREE_VIEW(gtkblist->treeview), gte, 2, | |
1387 GDK_ACTION_COPY | GDK_ACTION_MOVE); | |
1388 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-received", G_CALLBACK(gaim_gtk_blist_drag_data_rcv_cb), NULL); | |
1389 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-get", G_CALLBACK(gaim_gtk_blist_drag_data_get_cb), NULL); | |
1390 | |
1391 /* Tooltips */ | |
1392 g_signal_connect(G_OBJECT(gtkblist->treeview), "motion-notify-event", G_CALLBACK(gaim_gtk_blist_motion_cb), NULL); | |
1393 g_signal_connect(G_OBJECT(gtkblist->treeview), "leave-notify-event", G_CALLBACK(gaim_gtk_blist_leave_cb), NULL); | |
1394 | |
1395 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(gtkblist->treeview), FALSE); | |
1396 | |
1397 column = gtk_tree_view_column_new (); | |
1398 | |
1399 rend = gtk_cell_renderer_pixbuf_new(); | |
1400 gtk_tree_view_column_pack_start (column, rend, FALSE); | |
1401 gtk_tree_view_column_set_attributes (column, rend, | |
1402 "pixbuf", STATUS_ICON_COLUMN, | |
1403 "visible", STATUS_ICON_VISIBLE_COLUMN, | |
1404 NULL); | |
1405 g_object_set(rend, "xalign", 0.0, "ypad", 0, NULL); | |
1406 | |
1407 rend = gtk_cell_renderer_text_new(); | |
1408 gtk_tree_view_column_pack_start (column, rend, TRUE); | |
1409 gtk_tree_view_column_set_attributes (column, rend, | |
1410 "markup", NAME_COLUMN, | |
1411 NULL); | |
1412 g_object_set(rend, "ypad", 0, "yalign", 0.5, NULL); | |
1413 | |
1414 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); | |
1415 | |
1416 rend = gtk_cell_renderer_text_new(); | |
1417 gtkblist->warning_column = gtk_tree_view_column_new_with_attributes("Warning", rend, "markup", WARNING_COLUMN, NULL); | |
1418 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->warning_column); | |
1419 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); | |
1420 | |
1421 rend = gtk_cell_renderer_text_new(); | |
1422 gtkblist->idle_column = gtk_tree_view_column_new_with_attributes("Idle", rend, "markup", IDLE_COLUMN, NULL); | |
1423 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->idle_column); | |
1424 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); | |
1425 | |
1426 rend = gtk_cell_renderer_pixbuf_new(); | |
1427 gtkblist->buddy_icon_column = gtk_tree_view_column_new_with_attributes("Buddy Icon", rend, "pixbuf", BUDDY_ICON_COLUMN, NULL); | |
1428 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); | |
1429 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->buddy_icon_column); | |
1430 | |
1431 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-activated", G_CALLBACK(gtk_blist_row_activated_cb), NULL); | |
1432 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-expanded", G_CALLBACK(gtk_blist_row_expanded_cb), NULL); | |
1433 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-collapsed", G_CALLBACK(gtk_blist_row_collapsed_cb), NULL); | |
1434 g_signal_connect(G_OBJECT(gtkblist->treeview), "button-press-event", G_CALLBACK(gtk_blist_button_press_cb), NULL); | |
1435 | |
1436 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), sw, TRUE, TRUE, 0); | |
1437 gtk_container_add(GTK_CONTAINER(sw), gtkblist->treeview); | |
1438 gaim_gtk_blist_update_columns(); | |
1439 | |
1440 /* set the Show Offline Buddies option. must be done | |
1441 * after the treeview or faceprint gets mad. -Robot101 | |
1442 */ | |
1443 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (ift, N_("/Buddies/Show Offline Buddies"))), | |
1444 blist_options & OPT_BLIST_SHOW_OFFLINE); | |
1445 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (ift, N_("/Buddies/Show Empty Groups"))), | |
1446 !(blist_options & OPT_BLIST_NO_MT_GRP)); | |
1447 | |
1448 /* OK... let's show this bad boy. */ | |
1449 gaim_gtk_blist_refresh(list); | |
1450 gaim_gtk_blist_restore_position(); | |
1451 gtk_widget_show_all(gtkblist->window); | |
1452 | |
1453 /**************************** Button Box **************************************/ | |
1454 /* add this afterwards so it doesn't force up the width of the window */ | |
1455 | |
1456 gtkblist->tooltips = gtk_tooltips_new(); | |
1457 | |
1458 sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); | |
1459 gtkblist->bbox = gtk_hbox_new(TRUE, 0); | |
1460 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtkblist->bbox, FALSE, FALSE, 0); | |
1461 gtk_widget_show(gtkblist->bbox); | |
1462 | |
1463 button = gaim_pixbuf_button_from_stock(_("IM"), GAIM_STOCK_IM, GAIM_BUTTON_VERTICAL); | |
1464 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1465 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
1466 gtk_size_group_add_widget(sg, button); | |
1467 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_im_cb), | |
1468 gtkblist->treeview); | |
1469 gtk_tooltips_set_tip(GTK_TOOLTIPS(gtkblist->tooltips), button, _("Send a message to the selected buddy"), NULL); | |
1470 gtk_widget_show(button); | |
1471 | |
1472 button = gaim_pixbuf_button_from_stock(_("Get Info"), GAIM_STOCK_INFO, GAIM_BUTTON_VERTICAL); | |
1473 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1474 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
1475 gtk_size_group_add_widget(sg, button); | |
1476 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_info_cb), | |
1477 gtkblist->treeview); | |
1478 gtk_tooltips_set_tip(GTK_TOOLTIPS(gtkblist->tooltips), button, _("Get information on the selected buddy"), NULL); | |
1479 gtk_widget_show(button); | |
1480 | |
1481 button = gaim_pixbuf_button_from_stock(_("Chat"), GAIM_STOCK_CHAT, GAIM_BUTTON_VERTICAL); | |
1482 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1483 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
1484 gtk_size_group_add_widget(sg, button); | |
5234 | 1485 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_chat_cb), gtkblist->treeview); |
5228 | 1486 gtk_tooltips_set_tip(GTK_TOOLTIPS(gtkblist->tooltips), button, _("Join a chat room"), NULL); |
1487 gtk_widget_show(button); | |
1488 | |
1489 button = gaim_pixbuf_button_from_stock(_("Away"), GAIM_STOCK_ICON_AWAY, GAIM_BUTTON_VERTICAL); | |
1490 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1491 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
1492 gtk_size_group_add_widget(sg, button); | |
1493 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_away_cb), NULL); | |
1494 gtk_tooltips_set_tip(GTK_TOOLTIPS(gtkblist->tooltips), button, _("Set an away message"), NULL); | |
1495 gtk_widget_show(button); | |
1496 | |
1497 /* this will show the right image/label widgets for us */ | |
1498 gaim_gtk_blist_update_toolbar(); | |
1499 | |
1500 /* start the refresh timer */ | |
5297 | 1501 if (blist_options & (OPT_BLIST_SHOW_IDLETIME | OPT_BLIST_SHOW_ICONS)) |
1502 gtkblist->refresh_timer = g_timeout_add(30000, (GSourceFunc)gaim_gtk_blist_refresh_timer, list); | |
5228 | 1503 } |
1504 | |
1505 void gaim_gtk_blist_refresh(struct gaim_buddy_list *list) | |
1506 { | |
5234 | 1507 GaimBlistNode *group, *buddy; |
5228 | 1508 |
5234 | 1509 for(group = list->root; group; group = group->next) { |
1510 if(!GAIM_BLIST_NODE_IS_GROUP(group)) | |
1511 continue; | |
5228 | 1512 gaim_gtk_blist_update(list, group); |
5234 | 1513 for(buddy = group->child; buddy; buddy = buddy->next) { |
5228 | 1514 gaim_gtk_blist_update(list, buddy); |
1515 } | |
1516 } | |
1517 } | |
1518 | |
5297 | 1519 void |
1520 gaim_gtk_blist_update_refresh_timeout() | |
1521 { | |
1522 struct gaim_buddy_list *blist; | |
1523 struct gaim_gtk_buddy_list *gtkblist; | |
1524 | |
1525 blist = gaim_get_blist(); | |
1526 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); | |
1527 | |
1528 if (blist_options & (OPT_BLIST_SHOW_IDLETIME | OPT_BLIST_SHOW_ICONS)) { | |
1529 gtkblist->refresh_timer = g_timeout_add(30000, (GSourceFunc)gaim_gtk_blist_refresh_timer, blist); | |
1530 } else { | |
1531 g_source_remove(gtkblist->refresh_timer); | |
1532 gtkblist->refresh_timer = 0; | |
1533 } | |
1534 } | |
1535 | |
5256 | 1536 static gboolean get_iter_from_node(GaimBlistNode *node, GtkTreeIter *iter) { |
1537 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
1538 GtkTreePath *path; | |
5228 | 1539 |
5263 | 1540 if (!gtknode) { |
1541 gaim_debug(GAIM_DEBUG_ERROR, "gtkblist", "buddy %s has no ui_data\n", ((struct buddy *)node)->name); | |
1542 return FALSE; | |
1543 } | |
1544 | |
1545 if (!gtkblist) { | |
1546 gaim_debug(GAIM_DEBUG_ERROR, "gtkblist", "get_iter_from_node was called, but we don't seem to have a blist\n"); | |
1547 return FALSE; | |
1548 } | |
1549 | |
1550 if (!gtknode->row) | |
5228 | 1551 return FALSE; |
1552 | |
5256 | 1553 if ((path = gtk_tree_row_reference_get_path(gtknode->row)) == NULL) |
5228 | 1554 return FALSE; |
5256 | 1555 if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), iter, path)) { |
1556 gtk_tree_path_free(path); | |
1557 return FALSE; | |
1558 } | |
1559 gtk_tree_path_free(path); | |
1560 return TRUE; | |
5228 | 1561 } |
1562 | |
1563 /* | |
1564 * These state assignments suck. I'm sorry. They're for historical reasons. | |
1565 * Roll on new prefs. -Robot101 | |
1566 * | |
1567 * NO_BUTTON_TEXT && SHOW_BUTTON_XPM - image | |
1568 * !NO_BUTTON_TEXT && !SHOW_BUTTON_XPM - text | |
1569 * !NO_BUTTON_TEXT && SHOW_BUTTON_XPM - text & images | |
1570 * NO_BUTTON_TEXT && !SHOW_BUTTON_XPM - none | |
1571 */ | |
1572 | |
1573 static void gaim_gtk_blist_update_toolbar_icons (GtkWidget *widget, gpointer data) { | |
1574 if (GTK_IS_IMAGE(widget)) { | |
1575 if (blist_options & OPT_BLIST_SHOW_BUTTON_XPM) | |
1576 gtk_widget_show(widget); | |
1577 else | |
1578 gtk_widget_hide(widget); | |
1579 } else if (GTK_IS_LABEL(widget)) { | |
1580 if (blist_options & OPT_BLIST_NO_BUTTON_TEXT) | |
1581 gtk_widget_hide(widget); | |
1582 else | |
1583 gtk_widget_show(widget); | |
1584 } else if (GTK_IS_CONTAINER(widget)) { | |
1585 gtk_container_foreach(GTK_CONTAINER(widget), gaim_gtk_blist_update_toolbar_icons, NULL); | |
1586 } | |
1587 } | |
1588 | |
1589 void gaim_gtk_blist_update_toolbar() { | |
1590 if (!gtkblist) | |
1591 return; | |
1592 | |
1593 if (blist_options & OPT_BLIST_NO_BUTTON_TEXT && !(blist_options & OPT_BLIST_SHOW_BUTTON_XPM)) | |
1594 gtk_widget_hide(gtkblist->bbox); | |
1595 else { | |
1596 gtk_container_foreach(GTK_CONTAINER(gtkblist->bbox), gaim_gtk_blist_update_toolbar_icons, NULL); | |
1597 gtk_widget_show(gtkblist->bbox); | |
1598 } | |
1599 } | |
1600 | |
1601 static void gaim_gtk_blist_remove(struct gaim_buddy_list *list, GaimBlistNode *node) | |
1602 { | |
5260 | 1603 gaim_gtk_blist_hide_node(list, node); |
5228 | 1604 |
5263 | 1605 /* There's something I don't understand here */ |
1606 /* g_free(node->ui_data); | |
1607 node->ui_data = NULL; */ | |
5228 | 1608 } |
1609 | |
1610 static gboolean do_selection_changed(GaimBlistNode *new_selection) | |
1611 { | |
5254 | 1612 GaimBlistNode *old_selection = NULL; |
5228 | 1613 |
5254 | 1614 /* test for gtkblist because crazy timeout means we can be called after the blist is gone */ |
1615 if (gtkblist && new_selection != gtkblist->selected_node) { | |
1616 old_selection = gtkblist->selected_node; | |
5228 | 1617 gtkblist->selected_node = new_selection; |
1618 if(new_selection) | |
1619 gaim_gtk_blist_update(NULL, new_selection); | |
1620 if(old_selection) | |
1621 gaim_gtk_blist_update(NULL, old_selection); | |
1622 } | |
1623 | |
1624 return FALSE; | |
1625 } | |
1626 | |
1627 static void gaim_gtk_blist_selection_changed(GtkTreeSelection *selection, gpointer data) | |
1628 { | |
1629 GaimBlistNode *new_selection = NULL; | |
1630 GtkTreeIter iter; | |
1631 | |
1632 if(gtk_tree_selection_get_selected(selection, NULL, &iter)){ | |
1633 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, | |
1634 NODE_COLUMN, &new_selection, -1); | |
1635 } | |
5254 | 1636 |
5228 | 1637 /* we set this up as a timeout, otherwise the blist flickers */ |
1638 g_timeout_add(0, (GSourceFunc)do_selection_changed, new_selection); | |
1639 } | |
1640 | |
1641 static void make_a_group(GaimBlistNode *node, GtkTreeIter *iter) { | |
1642 GaimBlistNode *sibling; | |
1643 GtkTreeIter siblingiter; | |
5256 | 1644 GtkTreePath *newpath; |
5228 | 1645 struct group *group = (struct group *)node; |
5256 | 1646 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; |
5228 | 1647 char *esc = g_markup_escape_text(group->name, -1); |
1648 char *mark; | |
1649 | |
1650 if(blist_options & OPT_BLIST_SHOW_GRPNUM) | |
1651 mark = g_strdup_printf("<span weight='bold'>%s</span> (%d/%d)", esc, gaim_blist_get_group_online_count(group), gaim_blist_get_group_size(group, FALSE)); | |
1652 else | |
1653 mark = g_strdup_printf("<span weight='bold'>%s</span>", esc); | |
1654 | |
1655 g_free(esc); | |
1656 | |
1657 sibling = node->prev; | |
1658 while (sibling && !get_iter_from_node(sibling, &siblingiter)) { | |
1659 sibling = sibling->prev; | |
1660 } | |
1661 | |
1662 gtk_tree_store_insert_after(gtkblist->treemodel, iter, NULL, | |
1663 sibling ? &siblingiter : NULL); | |
5256 | 1664 newpath = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), iter); |
1665 gtknode->row = gtk_tree_row_reference_new(GTK_TREE_MODEL(gtkblist->treemodel), newpath); | |
1666 gtk_tree_path_free(newpath); | |
1667 | |
5228 | 1668 gtk_tree_store_set(gtkblist->treemodel, iter, |
1669 STATUS_ICON_COLUMN, NULL, | |
1670 STATUS_ICON_VISIBLE_COLUMN, FALSE, | |
1671 NAME_COLUMN, mark, | |
1672 NODE_COLUMN, node, | |
1673 -1); | |
1674 g_free(mark); | |
1675 } | |
1676 | |
1677 | |
1678 static void gaim_gtk_blist_update(struct gaim_buddy_list *list, GaimBlistNode *node) | |
1679 { | |
1680 GtkTreeIter iter; | |
5256 | 1681 GtkTreePath *expand = NULL, *newpath = NULL; |
1682 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
5228 | 1683 gboolean new_entry = FALSE; |
1684 | |
5256 | 1685 if (!gtkblist || !gtknode) |
5228 | 1686 return; |
1687 | |
5256 | 1688 if (!get_iter_from_node(node, &iter)) { |
5228 | 1689 new_entry = TRUE; |
1690 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
1691 if (((struct buddy*)node)->present != GAIM_BUDDY_OFFLINE || ((blist_options & OPT_BLIST_SHOW_OFFLINE) && ((struct buddy*)node)->account->gc)) { | |
1692 GtkTreeIter groupiter; | |
1693 GaimBlistNode *oldersibling; | |
1694 GtkTreeIter oldersiblingiter; | |
1695 char *collapsed = gaim_group_get_setting((struct group *)node->parent, "collapsed"); | |
1696 | |
1697 if(node->parent && | |
1698 !get_iter_from_node(node->parent, &groupiter)) { | |
1699 /* This buddy's group has not yet been added. | |
1700 * We do that here */ | |
1701 make_a_group(node->parent, &groupiter); | |
1702 } | |
1703 if(!collapsed) | |
1704 expand = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &groupiter); | |
1705 else | |
1706 g_free(collapsed); | |
1707 | |
1708 oldersibling = node->prev; | |
1709 while (oldersibling && !get_iter_from_node(oldersibling, &oldersiblingiter)) { | |
1710 oldersibling = oldersibling->prev; | |
1711 } | |
1712 | |
1713 gtk_tree_store_insert_after(gtkblist->treemodel, &iter, &groupiter, oldersibling ? &oldersiblingiter : NULL); | |
5256 | 1714 newpath = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &iter); |
1715 gtknode->row = gtk_tree_row_reference_new(GTK_TREE_MODEL(gtkblist->treemodel), newpath); | |
1716 gtk_tree_path_free(newpath); | |
5228 | 1717 |
1718 if (blist_options & OPT_BLIST_POPUP) { | |
1719 gtk_widget_show(gtkblist->window); | |
1720 gtk_window_deiconify(GTK_WINDOW(gtkblist->window)); | |
1721 gdk_window_raise(gtkblist->window->window); | |
1722 } | |
1723 | |
1724 } | |
5234 | 1725 } else if (GAIM_BLIST_NODE_IS_CHAT(node) && |
1726 ((struct chat *)node)->account->gc) { | |
1727 GtkTreeIter groupiter; | |
1728 GaimBlistNode *oldersibling; | |
1729 GtkTreeIter oldersiblingiter; | |
1730 char *collapsed = gaim_group_get_setting((struct group *)node->parent, "collapsed"); | |
1731 | |
1732 if(node->parent && | |
1733 !get_iter_from_node(node->parent, &groupiter)) { | |
1734 /* This buddy's group has not yet been added. | |
1735 * We do that here */ | |
1736 make_a_group(node->parent, &groupiter); | |
1737 } | |
1738 if(!collapsed) | |
1739 expand = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &groupiter); | |
1740 else | |
1741 g_free(collapsed); | |
1742 | |
1743 oldersibling = node->prev; | |
1744 while (oldersibling && !get_iter_from_node(oldersibling, &oldersiblingiter)) { | |
1745 oldersibling = oldersibling->prev; | |
1746 } | |
1747 | |
1748 gtk_tree_store_insert_after(gtkblist->treemodel, &iter, &groupiter, oldersibling ? &oldersiblingiter : NULL); | |
5256 | 1749 newpath = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &iter); |
1750 gtknode->row = gtk_tree_row_reference_new(GTK_TREE_MODEL(gtkblist->treemodel), newpath); | |
1751 gtk_tree_path_free(newpath); | |
5234 | 1752 |
1753 } else if (GAIM_BLIST_NODE_IS_GROUP(node) && | |
5228 | 1754 ((blist_options & OPT_BLIST_SHOW_OFFLINE) || |
1755 !(blist_options & OPT_BLIST_NO_MT_GRP))) { | |
1756 make_a_group(node, &iter); | |
1757 expand = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &iter); | |
1758 } | |
1759 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
1760 if((blist_options & OPT_BLIST_NO_MT_GRP) && !(blist_options & OPT_BLIST_SHOW_OFFLINE) && !gaim_blist_get_group_online_count((struct group *)node)) { | |
1761 gtk_tree_store_remove(gtkblist->treemodel, &iter); | |
1762 } else { | |
1763 struct group *group = (struct group *)node; | |
1764 char *esc = g_markup_escape_text(group->name, -1); | |
1765 char *mark; | |
1766 | |
1767 if(blist_options & OPT_BLIST_SHOW_GRPNUM) | |
1768 mark = g_strdup_printf("<span weight='bold'>%s</span> (%d/%d)", esc, gaim_blist_get_group_online_count(group), gaim_blist_get_group_size(group, FALSE)); | |
1769 else | |
1770 mark = g_strdup_printf("<span weight='bold'>%s</span>", esc); | |
1771 | |
1772 g_free(esc); | |
1773 gtk_tree_store_set(gtkblist->treemodel, &iter, | |
1774 NAME_COLUMN, mark, | |
1775 -1); | |
1776 g_free(mark); | |
1777 } | |
1778 } | |
1779 | |
5234 | 1780 if (GAIM_BLIST_NODE_IS_CHAT(node) && ((struct chat*)node)->account->gc) { |
1781 GdkPixbuf *status; | |
5237 | 1782 struct chat *chat = (struct chat *)node; |
1783 char *name; | |
5234 | 1784 |
1785 status = gaim_gtk_blist_get_status_icon(node, | |
1786 blist_options & OPT_BLIST_SHOW_ICONS ? GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL); | |
5237 | 1787 if(chat->alias) { |
1788 name = g_markup_escape_text(chat->alias, -1); | |
1789 } else { | |
1790 struct proto_chat_entry *pce; | |
5241 | 1791 GList *parts, *tmp; |
5237 | 1792 |
1793 parts = GAIM_PLUGIN_PROTOCOL_INFO(chat->account->gc->prpl)->chat_info(chat->account->gc); | |
1794 pce = parts->data; | |
1795 name = g_markup_escape_text(g_hash_table_lookup(chat->components, | |
1796 pce->identifier), -1); | |
5241 | 1797 for(tmp = parts; tmp; tmp = tmp->next) |
1798 g_free(tmp->data); | |
5237 | 1799 g_list_free(parts); |
1800 } | |
1801 | |
5234 | 1802 |
1803 gtk_tree_store_set(gtkblist->treemodel, &iter, | |
1804 STATUS_ICON_COLUMN, status, | |
1805 STATUS_ICON_VISIBLE_COLUMN, TRUE, | |
5237 | 1806 NAME_COLUMN, name, |
5234 | 1807 NODE_COLUMN, node, |
1808 -1); | |
1809 | |
5237 | 1810 g_free(name); |
5234 | 1811 if (status != NULL) |
1812 g_object_unref(status); | |
1813 } else if(GAIM_BLIST_NODE_IS_CHAT(node) && !((struct chat *)node)->account->gc) { | |
5260 | 1814 gaim_gtk_blist_hide_node(list, node); |
5234 | 1815 } else if (GAIM_BLIST_NODE_IS_BUDDY(node) && (((struct buddy*)node)->present != GAIM_BUDDY_OFFLINE || ((blist_options & OPT_BLIST_SHOW_OFFLINE) && ((struct buddy*)node)->account->gc))) { |
5228 | 1816 GdkPixbuf *status, *avatar; |
1817 char *mark; | |
1818 char *warning = NULL, *idle = NULL; | |
1819 | |
1820 gboolean selected = (gtkblist->selected_node == node); | |
1821 | |
5234 | 1822 status = gaim_gtk_blist_get_status_icon(node, |
5228 | 1823 blist_options & OPT_BLIST_SHOW_ICONS ? GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL); |
1824 avatar = gaim_gtk_blist_get_buddy_icon((struct buddy*)node); | |
1825 mark = gaim_gtk_blist_get_name_markup((struct buddy*)node, selected); | |
1826 | |
1827 if (((struct buddy*)node)->idle > 0) { | |
1828 time_t t; | |
1829 int ihrs, imin; | |
1830 time(&t); | |
1831 ihrs = (t - ((struct buddy *)node)->idle) / 3600; | |
1832 imin = ((t - ((struct buddy*)node)->idle) / 60) % 60; | |
1833 if(ihrs > 0) | |
1834 idle = g_strdup_printf("(%d:%02d)", ihrs, imin); | |
1835 else | |
1836 idle = g_strdup_printf("(%d)", imin); | |
1837 } | |
1838 | |
1839 if (((struct buddy*)node)->evil > 0) | |
1840 warning = g_strdup_printf("%d%%", ((struct buddy*)node)->evil); | |
1841 | |
1842 | |
1843 if((blist_options & OPT_BLIST_GREY_IDLERS) | |
1844 && ((struct buddy *)node)->idle) { | |
1845 if(warning && !selected) { | |
1846 char *w2 = g_strdup_printf("<span color='dim grey'>%s</span>", | |
1847 warning); | |
1848 g_free(warning); | |
1849 warning = w2; | |
1850 } | |
1851 | |
1852 if(idle && !selected) { | |
1853 char *i2 = g_strdup_printf("<span color='dim grey'>%s</span>", | |
1854 idle); | |
1855 g_free(idle); | |
1856 idle = i2; | |
1857 } | |
1858 } | |
1859 | |
1860 gtk_tree_store_set(gtkblist->treemodel, &iter, | |
1861 STATUS_ICON_COLUMN, status, | |
1862 STATUS_ICON_VISIBLE_COLUMN, TRUE, | |
1863 NAME_COLUMN, mark, | |
1864 WARNING_COLUMN, warning, | |
1865 IDLE_COLUMN, idle, | |
1866 BUDDY_ICON_COLUMN, avatar, | |
1867 NODE_COLUMN, node, | |
1868 -1); | |
1869 | |
1870 if (blist_options & OPT_BLIST_POPUP && | |
1871 ((struct buddy *)node)->present == GAIM_BUDDY_SIGNING_OFF) { | |
1872 gtk_widget_show(gtkblist->window); | |
1873 gtk_window_deiconify(GTK_WINDOW(gtkblist->window)); | |
1874 gdk_window_raise(gtkblist->window->window); | |
1875 } | |
1876 | |
1877 g_free(mark); | |
1878 if (idle) | |
1879 g_free(idle); | |
1880 if (warning) | |
1881 g_free(warning); | |
1882 | |
1883 if (status != NULL) | |
1884 g_object_unref(status); | |
1885 | |
1886 if (avatar != NULL) | |
1887 g_object_unref(avatar); | |
1888 | |
1889 } else if (GAIM_BLIST_NODE_IS_BUDDY(node) && !new_entry) { | |
5260 | 1890 gaim_gtk_blist_hide_node(list, node); |
5228 | 1891 } |
5234 | 1892 |
5228 | 1893 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(gtkblist->treeview)); |
1894 | |
1895 | |
1896 if(expand) { | |
1897 gtk_tree_view_expand_row(GTK_TREE_VIEW(gtkblist->treeview), expand, TRUE); | |
1898 gtk_tree_path_free(expand); | |
1899 } | |
1900 | |
5234 | 1901 if(GAIM_BLIST_NODE_IS_BUDDY(node) || GAIM_BLIST_NODE_IS_CHAT(node)) |
5228 | 1902 gaim_gtk_blist_update(list, node->parent); |
1903 } | |
1904 | |
1905 static void gaim_gtk_blist_destroy(struct gaim_buddy_list *list) | |
1906 { | |
1907 if (!gtkblist) | |
1908 return; | |
1909 | |
1910 gtk_widget_destroy(gtkblist->window); | |
1911 gtk_object_sink(GTK_OBJECT(gtkblist->tooltips)); | |
1912 | |
1913 if (gtkblist->refresh_timer) | |
1914 g_source_remove(gtkblist->refresh_timer); | |
1915 if (gtkblist->timeout) | |
1916 g_source_remove(gtkblist->timeout); | |
1917 | |
1918 gtkblist->refresh_timer = 0; | |
1919 gtkblist->timeout = 0; | |
1920 gtkblist->window = gtkblist->vbox = gtkblist->treeview = NULL; | |
1921 gtkblist->treemodel = NULL; | |
1922 gtkblist->idle_column = NULL; | |
1923 gtkblist->warning_column = gtkblist->buddy_icon_column = NULL; | |
1924 gtkblist->bbox = gtkblist->tipwindow = NULL; | |
1925 protomenu = NULL; | |
1926 awaymenu = NULL; | |
1927 gtkblist = NULL; | |
1928 } | |
1929 | |
1930 static void gaim_gtk_blist_set_visible(struct gaim_buddy_list *list, gboolean show) | |
1931 { | |
1932 if (!(gtkblist && gtkblist->window)) | |
1933 return; | |
1934 | |
1935 if (show) { | |
1936 gaim_gtk_blist_restore_position(); | |
1937 gtk_window_present(GTK_WINDOW(gtkblist->window)); | |
1938 } else { | |
1939 if (!connections || docklet_count) { | |
1940 #ifdef _WIN32 | |
1941 wgaim_systray_minimize(gtkblist->window); | |
1942 #endif | |
1943 gtk_widget_hide(gtkblist->window); | |
1944 } else { | |
1945 gtk_window_iconify(GTK_WINDOW(gtkblist->window)); | |
1946 } | |
1947 } | |
1948 } | |
1949 | |
1950 void gaim_gtk_blist_docklet_toggle() { | |
1951 /* Useful for the docklet plugin and also for the win32 tray icon*/ | |
1952 /* This is called when one of those is clicked--it will show/hide the | |
1953 buddy list/login window--depending on which is active */ | |
1954 if (connections) { | |
1955 if (gtkblist && gtkblist->window) { | |
1956 if (GTK_WIDGET_VISIBLE(gtkblist->window)) { | |
1957 gaim_blist_set_visible(GAIM_WINDOW_ICONIFIED(gtkblist->window) || gaim_gtk_blist_obscured); | |
1958 } else { | |
1959 #if _WIN32 | |
1960 wgaim_systray_maximize(gtkblist->window); | |
1961 #endif | |
1962 gaim_blist_set_visible(TRUE); | |
1963 } | |
1964 } else { | |
1965 /* we're logging in or something... do nothing */ | |
1966 /* or should I make the blist? */ | |
1967 gaim_debug(GAIM_DEBUG_WARNING, "blist", | |
1968 "docklet_toggle called with connections " | |
1969 "but no blist!\n"); | |
1970 } | |
1971 } else if (mainwindow) { | |
1972 if (GTK_WIDGET_VISIBLE(mainwindow)) { | |
1973 if (GAIM_WINDOW_ICONIFIED(mainwindow)) { | |
1974 gtk_window_present(GTK_WINDOW(mainwindow)); | |
1975 } else { | |
1976 #if _WIN32 | |
1977 wgaim_systray_minimize(mainwindow); | |
1978 #endif | |
1979 gtk_widget_hide(mainwindow); | |
1980 } | |
1981 } else { | |
1982 #if _WIN32 | |
1983 wgaim_systray_maximize(mainwindow); | |
1984 #endif | |
1985 show_login(); | |
1986 } | |
1987 } else { | |
1988 show_login(); | |
1989 } | |
1990 } | |
1991 | |
1992 void gaim_gtk_blist_docklet_add() | |
1993 { | |
1994 docklet_count++; | |
1995 } | |
1996 | |
1997 void gaim_gtk_blist_docklet_remove() | |
1998 { | |
1999 docklet_count--; | |
2000 if (!docklet_count) { | |
2001 if (connections) | |
2002 gaim_blist_set_visible(TRUE); | |
2003 else if (mainwindow) | |
2004 gtk_window_present(GTK_WINDOW(mainwindow)); | |
2005 else | |
2006 show_login(); | |
2007 } | |
2008 } | |
2009 | |
2010 static struct gaim_blist_ui_ops blist_ui_ops = | |
2011 { | |
2012 gaim_gtk_blist_new_list, | |
5256 | 2013 gaim_gtk_blist_new_node, |
5228 | 2014 gaim_gtk_blist_show, |
2015 gaim_gtk_blist_update, | |
2016 gaim_gtk_blist_remove, | |
2017 gaim_gtk_blist_destroy, | |
2018 gaim_gtk_blist_set_visible | |
2019 }; | |
2020 | |
2021 | |
2022 struct gaim_blist_ui_ops *gaim_get_gtk_blist_ui_ops() | |
2023 { | |
2024 return &blist_ui_ops; | |
2025 } | |
2026 | |
2027 | |
2028 | |
2029 /********************************************************************* | |
2030 * Public utility functions * | |
2031 *********************************************************************/ | |
2032 | |
2033 GdkPixbuf * | |
2034 create_prpl_icon(struct gaim_account *account) | |
2035 { | |
2036 GaimPlugin *prpl; | |
2037 GaimPluginProtocolInfo *prpl_info = NULL; | |
2038 GdkPixbuf *status = NULL; | |
2039 char *filename = NULL; | |
2040 const char *protoname = NULL; | |
2041 char buf[256]; | |
2042 | |
2043 prpl = gaim_find_prpl(account->protocol); | |
2044 | |
2045 if (prpl != NULL) { | |
2046 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
2047 | |
2048 if (prpl_info->list_icon != NULL) | |
2049 protoname = prpl_info->list_icon(account, NULL); | |
2050 } | |
2051 | |
2052 if (protoname == NULL) | |
2053 return NULL; | |
2054 | |
2055 /* | |
2056 * Status icons will be themeable too, and then it will look up | |
2057 * protoname from the theme | |
2058 */ | |
2059 g_snprintf(buf, sizeof(buf), "%s.png", protoname); | |
2060 | |
2061 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", | |
2062 "default", buf, NULL); | |
2063 status = gdk_pixbuf_new_from_file(filename, NULL); | |
2064 g_free(filename); | |
2065 | |
2066 return status; | |
2067 } | |
2068 |