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