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)) {
|
|
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);
|
5234
|
383 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
|
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>"},
|
5234
|
740 { N_("/Buddies/_Add a Buddy..."), NULL, gaim_gtk_blist_add_buddy_cb, 0, "<StockItem>", GTK_STOCK_ADD },
|
|
741 { N_("/Buddies/_Add a Chat..."), 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 },
|
|
764 { N_("/Help/_About..."), NULL, show_about, 0, "<StockItem>", GAIM_STOCK_ABOUT },
|
|
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
|
5234
|
847 if (b->idle > 0) {
|
|
848 int ihrs, imin;
|
|
849 time_t t;
|
|
850 time(&t);
|
|
851 ihrs = (t - b->idle) / 3600;
|
|
852 imin = ((t - b->idle) / 60) % 60;
|
|
853 if (ihrs)
|
|
854 idletime = g_strdup_printf(_("%dh%02dm"), ihrs, imin);
|
|
855 else
|
|
856 idletime = g_strdup_printf(_("%dm"), imin);
|
|
857 }
|
5228
|
858
|
5234
|
859 if(b->alias && b->alias[0])
|
|
860 aliastext = g_markup_escape_text(b->alias, -1);
|
5228
|
861
|
5234
|
862 if(b->server_alias)
|
|
863 nicktext = g_markup_escape_text(b->server_alias, -1);
|
5228
|
864
|
5234
|
865 if (b->evil > 0)
|
|
866 warning = g_strdup_printf(_("%d%%"), b->evil);
|
5228
|
867
|
5274
|
868 if(g_slist_length(connections) > 1)
|
|
869 accounttext = g_markup_escape_text(b->account->username, -1);
|
|
870
|
5234
|
871 text = g_strdup_printf("<span size='larger' weight='bold'>%s</span>"
|
5274
|
872 "%s %s" /* Account */
|
5228
|
873 "%s %s" /* Alias */
|
5234
|
874 "%s %s" /* Nickname */
|
5228
|
875 "%s %s" /* Idle */
|
|
876 "%s %s" /* Warning */
|
|
877 "%s%s" /* Status */
|
|
878 "%s",
|
|
879 b->name,
|
5274
|
880 accounttext ? _("\n<b>Account:</b>") : "", accounttext ? accounttext : "",
|
5228
|
881 aliastext ? _("\n<b>Alias:</b>") : "", aliastext ? aliastext : "",
|
|
882 nicktext ? _("\n<b>Nickname:</b>") : "", nicktext ? nicktext : "",
|
|
883 idletime ? _("\n<b>Idle:</b>") : "", idletime ? idletime : "",
|
|
884 b->evil ? _("\n<b>Warned:</b>") : "", b->evil ? warning : "",
|
|
885 statustext ? "\n" : "", statustext ? statustext : "",
|
|
886 !g_ascii_strcasecmp(b->name, "robflynn") ? _("\n<b>Description:</b> Spooky") : "");
|
5234
|
887
|
|
888 if(warning)
|
|
889 g_free(warning);
|
|
890 if(idletime)
|
|
891 g_free(idletime);
|
|
892 if(statustext)
|
|
893 g_free(statustext);
|
|
894 if(nicktext)
|
|
895 g_free(nicktext);
|
|
896 if(aliastext)
|
|
897 g_free(aliastext);
|
5274
|
898 if(accounttext)
|
|
899 g_free(accounttext);
|
5234
|
900 }
|
5228
|
901
|
|
902 return text;
|
|
903 }
|
|
904
|
5234
|
905 GdkPixbuf *gaim_gtk_blist_get_status_icon(GaimBlistNode *node, GaimStatusIconSize size)
|
5228
|
906 {
|
|
907 GdkPixbuf *status = NULL;
|
|
908 GdkPixbuf *scale = NULL;
|
|
909 GdkPixbuf *emblem = NULL;
|
|
910 gchar *filename = NULL;
|
|
911 const char *protoname = NULL;
|
|
912
|
|
913 char *se = NULL, *sw = NULL ,*nw = NULL ,*ne = NULL;
|
|
914
|
|
915 int scalesize = 30;
|
|
916
|
5234
|
917 GaimPlugin *prpl = NULL;
|
5228
|
918 GaimPluginProtocolInfo *prpl_info = NULL;
|
|
919
|
5234
|
920 if(GAIM_BLIST_NODE_IS_BUDDY(node))
|
|
921 prpl = gaim_find_prpl(((struct buddy *)node)->account->protocol);
|
|
922 else if(GAIM_BLIST_NODE_IS_CHAT(node))
|
|
923 prpl = gaim_find_prpl(((struct chat *)node)->account->protocol);
|
5228
|
924
|
5234
|
925 if (!prpl)
|
5228
|
926 return NULL;
|
|
927
|
|
928 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
|
|
929
|
5234
|
930 if (prpl_info->list_icon) {
|
|
931 if(GAIM_BLIST_NODE_IS_BUDDY(node))
|
|
932 protoname = prpl_info->list_icon(((struct buddy*)node)->account,
|
|
933 (struct buddy *)node);
|
|
934 else if(GAIM_BLIST_NODE_IS_CHAT(node))
|
|
935 protoname = prpl_info->list_icon(((struct chat*)node)->account, NULL);
|
|
936 }
|
|
937
|
|
938 if (GAIM_BLIST_NODE_IS_BUDDY(node) &&
|
|
939 ((struct buddy *)node)->present != GAIM_BUDDY_SIGNING_OFF &&
|
|
940 prpl_info->list_emblems) {
|
|
941 prpl_info->list_emblems((struct buddy*)node, &se, &sw, &nw, &ne);
|
|
942 }
|
5228
|
943
|
|
944 if (size == GAIM_STATUS_ICON_SMALL) {
|
|
945 scalesize = 15;
|
|
946 sw = nw = ne = NULL; /* So that only the se icon will composite */
|
|
947 }
|
|
948
|
|
949
|
5234
|
950 if (GAIM_BLIST_NODE_IS_BUDDY(node) &&
|
|
951 ((struct buddy*)node)->present == GAIM_BUDDY_SIGNING_ON) {
|
5228
|
952 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "login.png", NULL);
|
|
953 status = gdk_pixbuf_new_from_file(filename,NULL);
|
|
954 g_free(filename);
|
5234
|
955 } else if (GAIM_BLIST_NODE_IS_BUDDY(node) &&
|
|
956 ((struct buddy *)node)->present == GAIM_BUDDY_SIGNING_OFF) {
|
5228
|
957 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "logout.png", NULL);
|
|
958 status = gdk_pixbuf_new_from_file(filename,NULL);
|
|
959 g_free(filename);
|
|
960
|
|
961 /* "Hey, what's all this crap?" you ask. Status icons will be themeable too, and
|
|
962 then it will look up protoname from the theme */
|
|
963 } else {
|
|
964 char *image = g_strdup_printf("%s.png", protoname);
|
|
965 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL);
|
|
966 status = gdk_pixbuf_new_from_file(filename,NULL);
|
|
967 g_free(image);
|
|
968 g_free(filename);
|
|
969
|
|
970 }
|
|
971
|
|
972 if (!status)
|
|
973 return NULL;
|
|
974
|
|
975 scale = gdk_pixbuf_scale_simple(status, scalesize, scalesize, GDK_INTERP_BILINEAR);
|
|
976
|
|
977 g_object_unref(G_OBJECT(status));
|
|
978
|
|
979 /* Emblems */
|
|
980
|
|
981 /* Each protocol can specify up to four "emblems" to composite over the base icon. "away", "busy", "mobile user"
|
|
982 * are all examples of states represented by emblems. I'm not even really sure I like this yet. */
|
|
983
|
|
984 /* XXX Clean this crap up, yo. */
|
|
985 if (se) {
|
|
986 char *image = g_strdup_printf("%s.png", se);
|
|
987 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL);
|
|
988 g_free(image);
|
|
989 emblem = gdk_pixbuf_new_from_file(filename,NULL);
|
|
990 g_free(filename);
|
|
991 if (emblem) {
|
|
992 if (size == GAIM_STATUS_ICON_LARGE)
|
|
993 gdk_pixbuf_composite (emblem,
|
|
994 scale, 15, 15,
|
|
995 15, 15,
|
|
996 15, 15,
|
|
997 1, 1,
|
|
998 GDK_INTERP_BILINEAR,
|
|
999 255);
|
|
1000 else
|
|
1001 gdk_pixbuf_composite (emblem,
|
|
1002 scale, 5, 5,
|
|
1003 10, 10,
|
|
1004 5, 5,
|
|
1005 .6, .6,
|
|
1006 GDK_INTERP_BILINEAR,
|
|
1007 255);
|
|
1008 g_object_unref(G_OBJECT(emblem));
|
|
1009 }
|
|
1010 }
|
|
1011 if (sw) {
|
|
1012 char *image = g_strdup_printf("%s.png", sw);
|
|
1013 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL);
|
|
1014 g_free(image);
|
|
1015 emblem = gdk_pixbuf_new_from_file(filename,NULL);
|
|
1016 g_free(filename);
|
|
1017 if (emblem) {
|
|
1018 gdk_pixbuf_composite (emblem,
|
|
1019 scale, 0, 15,
|
|
1020 15, 15,
|
|
1021 0, 15,
|
|
1022 1, 1,
|
|
1023 GDK_INTERP_BILINEAR,
|
|
1024 255);
|
|
1025 g_object_unref(G_OBJECT(emblem));
|
|
1026 }
|
|
1027 }
|
|
1028 if (nw) {
|
|
1029 char *image = g_strdup_printf("%s.png", nw);
|
|
1030 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL);
|
|
1031 g_free(image);
|
|
1032 emblem = gdk_pixbuf_new_from_file(filename,NULL);
|
|
1033 g_free(filename);
|
|
1034 if (emblem) {
|
|
1035 gdk_pixbuf_composite (emblem,
|
|
1036 scale, 0, 0,
|
|
1037 15, 15,
|
|
1038 0, 0,
|
|
1039 1, 1,
|
|
1040 GDK_INTERP_BILINEAR,
|
|
1041 255);
|
|
1042 g_object_unref(G_OBJECT(emblem));
|
|
1043 }
|
|
1044 }
|
|
1045 if (ne) {
|
|
1046 char *image = g_strdup_printf("%s.png", ne);
|
|
1047 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL);
|
|
1048 g_free(image);
|
|
1049 emblem = gdk_pixbuf_new_from_file(filename,NULL);
|
|
1050 g_free(filename);
|
|
1051 if (emblem) {
|
|
1052 gdk_pixbuf_composite (emblem,
|
|
1053 scale, 15, 0,
|
|
1054 15, 15,
|
|
1055 15, 0,
|
|
1056 1, 1,
|
|
1057 GDK_INTERP_BILINEAR,
|
|
1058 255);
|
|
1059 g_object_unref(G_OBJECT(emblem));
|
|
1060 }
|
|
1061 }
|
|
1062
|
|
1063
|
|
1064 /* Idle grey buddies affects the whole row. This converts the status icon to greyscale. */
|
5234
|
1065 if (GAIM_BLIST_NODE_IS_BUDDY(node) &&
|
|
1066 ((struct buddy *)node)->present == GAIM_BUDDY_OFFLINE)
|
5228
|
1067 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE);
|
5234
|
1068 else if (GAIM_BLIST_NODE_IS_BUDDY(node) &&
|
|
1069 ((struct buddy *)node)->idle &&
|
|
1070 blist_options & OPT_BLIST_GREY_IDLERS)
|
5228
|
1071 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.25, FALSE);
|
|
1072 return scale;
|
|
1073 }
|
|
1074
|
|
1075 static GdkPixbuf *gaim_gtk_blist_get_buddy_icon(struct buddy *b)
|
|
1076 {
|
|
1077 /* This just opens a file from ~/.gaim/icons/screenname. This needs to change to be more gooder. */
|
|
1078 char *file;
|
|
1079 GdkPixbuf *buf, *ret;
|
|
1080
|
|
1081 if (!(blist_options & OPT_BLIST_SHOW_ICONS))
|
|
1082 return NULL;
|
|
1083
|
|
1084 if ((file = gaim_buddy_get_setting(b, "buddy_icon")) == NULL)
|
|
1085 return NULL;
|
|
1086
|
|
1087 buf = gdk_pixbuf_new_from_file(file, NULL);
|
|
1088 g_free(file);
|
|
1089
|
|
1090
|
|
1091 if (buf) {
|
|
1092 if (!GAIM_BUDDY_IS_ONLINE(b))
|
|
1093 gdk_pixbuf_saturate_and_pixelate(buf, buf, 0.0, FALSE);
|
|
1094 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS)
|
|
1095 gdk_pixbuf_saturate_and_pixelate(buf, buf, 0.25, FALSE);
|
|
1096
|
|
1097 ret = gdk_pixbuf_scale_simple(buf,30,30, GDK_INTERP_BILINEAR);
|
|
1098 g_object_unref(G_OBJECT(buf));
|
|
1099 return ret;
|
|
1100 }
|
|
1101 return NULL;
|
|
1102 }
|
|
1103
|
|
1104 static gchar *gaim_gtk_blist_get_name_markup(struct buddy *b, gboolean selected)
|
|
1105 {
|
|
1106 char *name = gaim_get_buddy_alias(b);
|
|
1107 char *esc = g_markup_escape_text(name, strlen(name)), *text = NULL;
|
|
1108 GaimPlugin *prpl;
|
|
1109 GaimPluginProtocolInfo *prpl_info = NULL;
|
|
1110 /* XXX Clean up this crap */
|
|
1111
|
|
1112 int ihrs, imin;
|
|
1113 char *idletime = NULL, *warning = NULL, *statustext = NULL;
|
|
1114 time_t t;
|
|
1115
|
|
1116 prpl = gaim_find_prpl(b->account->protocol);
|
|
1117
|
|
1118 if (prpl != NULL)
|
|
1119 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
|
|
1120
|
|
1121 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) {
|
|
1122 if ((b->idle && blist_options & OPT_BLIST_GREY_IDLERS && !selected) || !GAIM_BUDDY_IS_ONLINE(b)) {
|
|
1123 text = g_strdup_printf("<span color='dim grey'>%s</span>",
|
|
1124 esc);
|
|
1125 g_free(esc);
|
|
1126 return text;
|
|
1127 } else {
|
|
1128 return esc;
|
|
1129 }
|
|
1130 }
|
|
1131
|
|
1132 time(&t);
|
|
1133 ihrs = (t - b->idle) / 3600;
|
|
1134 imin = ((t - b->idle) / 60) % 60;
|
|
1135
|
|
1136 if (prpl && prpl_info->status_text) {
|
|
1137 char *tmp = prpl_info->status_text(b);
|
|
1138 const char *end;
|
|
1139
|
|
1140 if(tmp && !g_utf8_validate(tmp, -1, &end)) {
|
|
1141 char *new = g_strndup(tmp,
|
|
1142 g_utf8_pointer_to_offset(tmp, end));
|
|
1143 g_free(tmp);
|
|
1144 tmp = new;
|
|
1145 }
|
|
1146
|
|
1147 if(tmp) {
|
|
1148 char buf[32];
|
|
1149 char *c = tmp;
|
|
1150 int length = 0, vis=0;
|
|
1151 gboolean inside = FALSE;
|
|
1152 g_strdelimit(tmp, "\n", ' ');
|
|
1153
|
|
1154 while(*c && vis < 20) {
|
|
1155 if(*c == '&')
|
|
1156 inside = TRUE;
|
|
1157 else if(*c == ';')
|
|
1158 inside = FALSE;
|
|
1159 if(!inside)
|
|
1160 vis++;
|
|
1161 length++;
|
|
1162 c++; /* this is fun */
|
|
1163 }
|
|
1164
|
|
1165 if(vis == 20)
|
|
1166 g_snprintf(buf, sizeof(buf), "%%.%ds...", length);
|
|
1167 else
|
|
1168 g_snprintf(buf, sizeof(buf), "%%s ");
|
|
1169
|
|
1170 statustext = g_strdup_printf(buf, tmp);
|
|
1171
|
|
1172 g_free(tmp);
|
|
1173 }
|
|
1174 }
|
|
1175
|
|
1176 if (b->idle > 0) {
|
|
1177 if (ihrs)
|
|
1178 idletime = g_strdup_printf(_("Idle (%dh%02dm) "), ihrs, imin);
|
|
1179 else
|
|
1180 idletime = g_strdup_printf(_("Idle (%dm) "), imin);
|
|
1181 }
|
|
1182
|
|
1183 if (b->evil > 0)
|
|
1184 warning = g_strdup_printf(_("Warned (%d%%) "), b->evil);
|
|
1185
|
|
1186 if(!GAIM_BUDDY_IS_ONLINE(b) && !statustext)
|
|
1187 statustext = g_strdup("Offline ");
|
|
1188
|
|
1189 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS && !selected) {
|
|
1190 text = g_strdup_printf("<span color='dim grey'>%s</span>\n"
|
|
1191 "<span color='dim grey' size='smaller'>%s%s%s</span>",
|
|
1192 esc,
|
|
1193 statustext != NULL ? statustext : "",
|
|
1194 idletime != NULL ? idletime : "",
|
|
1195 warning != NULL ? warning : "");
|
|
1196 } else if (statustext == NULL && idletime == NULL && warning == NULL && GAIM_BUDDY_IS_ONLINE(b)) {
|
|
1197 text = g_strdup(esc);
|
|
1198 } else {
|
|
1199 text = g_strdup_printf("%s\n"
|
|
1200 "<span %s size='smaller'>%s%s%s</span>", esc,
|
|
1201 selected ? "" : "color='dim grey'",
|
|
1202 statustext != NULL ? statustext : "",
|
|
1203 idletime != NULL ? idletime : "",
|
|
1204 warning != NULL ? warning : "");
|
|
1205 }
|
|
1206 if (idletime)
|
|
1207 g_free(idletime);
|
|
1208 if (warning)
|
|
1209 g_free(warning);
|
|
1210 if (statustext)
|
|
1211 g_free(statustext);
|
|
1212 if (esc)
|
|
1213 g_free(esc);
|
|
1214
|
|
1215 return text;
|
|
1216 }
|
|
1217
|
|
1218 static void gaim_gtk_blist_restore_position()
|
|
1219 {
|
|
1220 /* if the window exists, is hidden, we're saving positions, and the position is sane... */
|
|
1221 if(gtkblist && gtkblist->window &&
|
|
1222 !GTK_WIDGET_VISIBLE(gtkblist->window) &&
|
|
1223 blist_pos.width != 0) {
|
|
1224 /* ...check position is on screen... */
|
|
1225 if (blist_pos.x >= gdk_screen_width())
|
|
1226 blist_pos.x = gdk_screen_width() - 100;
|
|
1227 else if (blist_pos.x < 0)
|
|
1228 blist_pos.x = 100;
|
|
1229
|
|
1230 if (blist_pos.y >= gdk_screen_height())
|
|
1231 blist_pos.y = gdk_screen_height() - 100;
|
|
1232 else if (blist_pos.y < 0)
|
|
1233 blist_pos.y = 100;
|
|
1234
|
|
1235 /* ...and move it back. */
|
|
1236 gtk_window_move(GTK_WINDOW(gtkblist->window), blist_pos.x, blist_pos.y);
|
|
1237 gtk_window_resize(GTK_WINDOW(gtkblist->window), blist_pos.width, blist_pos.height);
|
|
1238 }
|
|
1239 }
|
|
1240
|
|
1241 static gboolean gaim_gtk_blist_refresh_timer(struct gaim_buddy_list *list)
|
|
1242 {
|
5234
|
1243 GaimBlistNode *group, *buddy;
|
5228
|
1244
|
5297
|
1245 gaim_debug(GAIM_DEBUG_INFO, "refresh_timer", "called\n");
|
|
1246
|
5234
|
1247 for(group = list->root; group; group = group->next) {
|
|
1248 if(!GAIM_BLIST_NODE_IS_GROUP(group))
|
|
1249 continue;
|
|
1250 for(buddy = group->child; buddy; buddy = buddy->next) {
|
|
1251 if(!GAIM_BLIST_NODE_IS_BUDDY(buddy))
|
|
1252 continue;
|
5228
|
1253 if (((struct buddy *)buddy)->idle)
|
|
1254 gaim_gtk_blist_update(list, buddy);
|
|
1255 }
|
|
1256 }
|
|
1257
|
|
1258 /* keep on going */
|
|
1259 return TRUE;
|
|
1260 }
|
|
1261
|
5260
|
1262 static void gaim_gtk_blist_hide_node(struct gaim_buddy_list *list, GaimBlistNode *node)
|
|
1263 {
|
|
1264 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data;
|
|
1265 GtkTreeIter iter;
|
|
1266
|
|
1267 if (!gtknode || !gtknode->row || !gtkblist)
|
|
1268 return;
|
|
1269
|
|
1270 if(gtkblist->selected_node == node)
|
|
1271 gtkblist->selected_node = NULL;
|
|
1272
|
|
1273 if (get_iter_from_node(node, &iter)) {
|
|
1274 gtk_tree_store_remove(gtkblist->treemodel, &iter);
|
|
1275 if(GAIM_BLIST_NODE_IS_BUDDY(node) || GAIM_BLIST_NODE_IS_CHAT(node)) {
|
|
1276 gaim_gtk_blist_update(list, node->parent);
|
|
1277 }
|
|
1278 }
|
|
1279 gtk_tree_row_reference_free(gtknode->row);
|
|
1280 gtknode->row = NULL;
|
|
1281 }
|
|
1282
|
|
1283
|
5228
|
1284 /**********************************************************************************
|
|
1285 * Public API Functions *
|
|
1286 **********************************************************************************/
|
|
1287 static void gaim_gtk_blist_new_list(struct gaim_buddy_list *blist)
|
|
1288 {
|
|
1289 blist->ui_data = g_new0(struct gaim_gtk_buddy_list, 1);
|
|
1290 }
|
|
1291
|
5256
|
1292 static void gaim_gtk_blist_new_node(GaimBlistNode *node)
|
|
1293 {
|
|
1294 node->ui_data = g_new0(struct _gaim_gtk_blist_node, 1);
|
|
1295 }
|
|
1296
|
5228
|
1297 void gaim_gtk_blist_update_columns()
|
|
1298 {
|
|
1299 if(!gtkblist)
|
|
1300 return;
|
|
1301
|
|
1302 if (blist_options & OPT_BLIST_SHOW_ICONS) {
|
|
1303 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, TRUE);
|
|
1304 gtk_tree_view_column_set_visible(gtkblist->idle_column, FALSE);
|
|
1305 gtk_tree_view_column_set_visible(gtkblist->warning_column, FALSE);
|
|
1306 } else {
|
|
1307 gtk_tree_view_column_set_visible(gtkblist->idle_column, blist_options & OPT_BLIST_SHOW_IDLETIME);
|
|
1308 gtk_tree_view_column_set_visible(gtkblist->warning_column, blist_options & OPT_BLIST_SHOW_WARN);
|
|
1309 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, FALSE);
|
|
1310 }
|
|
1311 }
|
|
1312
|
|
1313 enum {DRAG_BUDDY, DRAG_ROW};
|
|
1314
|
|
1315 static char *
|
|
1316 item_factory_translate_func (const char *path, gpointer func_data)
|
|
1317 {
|
|
1318 return _(path);
|
|
1319 }
|
|
1320
|
|
1321 static void gaim_gtk_blist_show(struct gaim_buddy_list *list)
|
|
1322 {
|
|
1323 GtkItemFactory *ift;
|
|
1324 GtkCellRenderer *rend;
|
|
1325 GtkTreeViewColumn *column;
|
|
1326 GtkWidget *sw;
|
|
1327 GtkWidget *button;
|
|
1328 GtkSizeGroup *sg;
|
|
1329 GtkAccelGroup *accel_group;
|
|
1330 GtkTreeSelection *selection;
|
|
1331 GtkTargetEntry gte[] = {{"GAIM_BLIST_NODE", GTK_TARGET_SAME_APP, DRAG_ROW},
|
|
1332 {"application/x-im-contact", 0, DRAG_BUDDY}};
|
|
1333
|
|
1334 if (gtkblist && gtkblist->window) {
|
|
1335 gtk_widget_show(gtkblist->window);
|
|
1336 return;
|
|
1337 }
|
|
1338
|
|
1339 gtkblist = GAIM_GTK_BLIST(list);
|
|
1340
|
|
1341 gtkblist->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
1342 gtk_window_set_role(GTK_WINDOW(gtkblist->window), "buddy_list");
|
|
1343 gtk_window_set_title(GTK_WINDOW(gtkblist->window), _("Buddy List"));
|
|
1344
|
|
1345 GTK_WINDOW(gtkblist->window)->allow_shrink = TRUE;
|
|
1346
|
|
1347 gtkblist->vbox = gtk_vbox_new(FALSE, 0);
|
|
1348 gtk_container_add(GTK_CONTAINER(gtkblist->window), gtkblist->vbox);
|
|
1349
|
|
1350 g_signal_connect(G_OBJECT(gtkblist->window), "delete_event", G_CALLBACK(gtk_blist_delete_cb), NULL);
|
|
1351 g_signal_connect(G_OBJECT(gtkblist->window), "configure_event", G_CALLBACK(gtk_blist_configure_cb), NULL);
|
|
1352 g_signal_connect(G_OBJECT(gtkblist->window), "visibility_notify_event", G_CALLBACK(gtk_blist_visibility_cb), NULL);
|
|
1353 gtk_widget_add_events(gtkblist->window, GDK_VISIBILITY_NOTIFY_MASK);
|
|
1354
|
|
1355 /******************************* Menu bar *************************************/
|
|
1356 accel_group = gtk_accel_group_new();
|
|
1357 gtk_window_add_accel_group(GTK_WINDOW (gtkblist->window), accel_group);
|
|
1358 g_object_unref(accel_group);
|
|
1359 ift = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GaimMain>", accel_group);
|
|
1360 gtk_item_factory_set_translate_func (ift,
|
|
1361 item_factory_translate_func,
|
|
1362 NULL, NULL);
|
|
1363 gtk_item_factory_create_items(ift, sizeof(blist_menu) / sizeof(*blist_menu),
|
|
1364 blist_menu, NULL);
|
|
1365 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtk_item_factory_get_widget(ift, "<GaimMain>"), FALSE, FALSE, 0);
|
|
1366
|
|
1367 awaymenu = gtk_item_factory_get_widget(ift, N_("/Tools/Away"));
|
|
1368 do_away_menu();
|
|
1369
|
|
1370 gtkblist->bpmenu = gtk_item_factory_get_widget(ift, N_("/Tools/Buddy Pounce"));
|
|
1371 gaim_gtkpounce_menu_build(gtkblist->bpmenu);
|
|
1372
|
|
1373 protomenu = gtk_item_factory_get_widget(ift, N_("/Tools/Protocol Actions"));
|
|
1374 do_proto_menu();
|
|
1375
|
|
1376 /****************************** GtkTreeView **********************************/
|
|
1377 sw = gtk_scrolled_window_new(NULL,NULL);
|
|
1378 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN);
|
|
1379 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
1380
|
|
1381 gtkblist->treemodel = gtk_tree_store_new(BLIST_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_BOOLEAN, G_TYPE_STRING,
|
|
1382 G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_POINTER);
|
|
1383
|
|
1384 gtkblist->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(gtkblist->treemodel));
|
|
1385 gtk_widget_set_size_request(gtkblist->treeview, -1, 200);
|
|
1386
|
|
1387 /* Set up selection stuff */
|
|
1388
|
|
1389 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview));
|
|
1390 g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(gaim_gtk_blist_selection_changed), NULL);
|
|
1391
|
|
1392
|
|
1393 /* Set up dnd */
|
|
1394 gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(gtkblist->treeview), GDK_BUTTON1_MASK, gte,
|
|
1395 2, GDK_ACTION_COPY);
|
|
1396 gtk_tree_view_enable_model_drag_dest(GTK_TREE_VIEW(gtkblist->treeview), gte, 2,
|
|
1397 GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
|
1398 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-received", G_CALLBACK(gaim_gtk_blist_drag_data_rcv_cb), NULL);
|
|
1399 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-get", G_CALLBACK(gaim_gtk_blist_drag_data_get_cb), NULL);
|
|
1400
|
|
1401 /* Tooltips */
|
|
1402 g_signal_connect(G_OBJECT(gtkblist->treeview), "motion-notify-event", G_CALLBACK(gaim_gtk_blist_motion_cb), NULL);
|
|
1403 g_signal_connect(G_OBJECT(gtkblist->treeview), "leave-notify-event", G_CALLBACK(gaim_gtk_blist_leave_cb), NULL);
|
|
1404
|
|
1405 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(gtkblist->treeview), FALSE);
|
|
1406
|
|
1407 column = gtk_tree_view_column_new ();
|
|
1408
|
|
1409 rend = gtk_cell_renderer_pixbuf_new();
|
|
1410 gtk_tree_view_column_pack_start (column, rend, FALSE);
|
|
1411 gtk_tree_view_column_set_attributes (column, rend,
|
|
1412 "pixbuf", STATUS_ICON_COLUMN,
|
|
1413 "visible", STATUS_ICON_VISIBLE_COLUMN,
|
|
1414 NULL);
|
|
1415 g_object_set(rend, "xalign", 0.0, "ypad", 0, NULL);
|
|
1416
|
|
1417 rend = gtk_cell_renderer_text_new();
|
|
1418 gtk_tree_view_column_pack_start (column, rend, TRUE);
|
|
1419 gtk_tree_view_column_set_attributes (column, rend,
|
|
1420 "markup", NAME_COLUMN,
|
|
1421 NULL);
|
|
1422 g_object_set(rend, "ypad", 0, "yalign", 0.5, NULL);
|
|
1423
|
|
1424 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column);
|
|
1425
|
|
1426 rend = gtk_cell_renderer_text_new();
|
|
1427 gtkblist->warning_column = gtk_tree_view_column_new_with_attributes("Warning", rend, "markup", WARNING_COLUMN, NULL);
|
|
1428 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->warning_column);
|
|
1429 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL);
|
|
1430
|
|
1431 rend = gtk_cell_renderer_text_new();
|
|
1432 gtkblist->idle_column = gtk_tree_view_column_new_with_attributes("Idle", rend, "markup", IDLE_COLUMN, NULL);
|
|
1433 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->idle_column);
|
|
1434 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL);
|
|
1435
|
|
1436 rend = gtk_cell_renderer_pixbuf_new();
|
|
1437 gtkblist->buddy_icon_column = gtk_tree_view_column_new_with_attributes("Buddy Icon", rend, "pixbuf", BUDDY_ICON_COLUMN, NULL);
|
|
1438 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL);
|
|
1439 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->buddy_icon_column);
|
|
1440
|
|
1441 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-activated", G_CALLBACK(gtk_blist_row_activated_cb), NULL);
|
|
1442 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-expanded", G_CALLBACK(gtk_blist_row_expanded_cb), NULL);
|
|
1443 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-collapsed", G_CALLBACK(gtk_blist_row_collapsed_cb), NULL);
|
|
1444 g_signal_connect(G_OBJECT(gtkblist->treeview), "button-press-event", G_CALLBACK(gtk_blist_button_press_cb), NULL);
|
|
1445
|
|
1446 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), sw, TRUE, TRUE, 0);
|
|
1447 gtk_container_add(GTK_CONTAINER(sw), gtkblist->treeview);
|
|
1448 gaim_gtk_blist_update_columns();
|
|
1449
|
|
1450 /* set the Show Offline Buddies option. must be done
|
|
1451 * after the treeview or faceprint gets mad. -Robot101
|
|
1452 */
|
|
1453 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (ift, N_("/Buddies/Show Offline Buddies"))),
|
|
1454 blist_options & OPT_BLIST_SHOW_OFFLINE);
|
|
1455 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (ift, N_("/Buddies/Show Empty Groups"))),
|
|
1456 !(blist_options & OPT_BLIST_NO_MT_GRP));
|
|
1457
|
|
1458 /* OK... let's show this bad boy. */
|
|
1459 gaim_gtk_blist_refresh(list);
|
|
1460 gaim_gtk_blist_restore_position();
|
|
1461 gtk_widget_show_all(gtkblist->window);
|
|
1462
|
|
1463 /**************************** Button Box **************************************/
|
|
1464 /* add this afterwards so it doesn't force up the width of the window */
|
|
1465
|
|
1466 gtkblist->tooltips = gtk_tooltips_new();
|
|
1467
|
|
1468 sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
|
|
1469 gtkblist->bbox = gtk_hbox_new(TRUE, 0);
|
|
1470 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtkblist->bbox, FALSE, FALSE, 0);
|
|
1471 gtk_widget_show(gtkblist->bbox);
|
|
1472
|
|
1473 button = gaim_pixbuf_button_from_stock(_("IM"), GAIM_STOCK_IM, GAIM_BUTTON_VERTICAL);
|
|
1474 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0);
|
|
1475 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
|
|
1476 gtk_size_group_add_widget(sg, button);
|
|
1477 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_im_cb),
|
|
1478 gtkblist->treeview);
|
|
1479 gtk_tooltips_set_tip(GTK_TOOLTIPS(gtkblist->tooltips), button, _("Send a message to the selected buddy"), NULL);
|
|
1480 gtk_widget_show(button);
|
|
1481
|
|
1482 button = gaim_pixbuf_button_from_stock(_("Get Info"), GAIM_STOCK_INFO, GAIM_BUTTON_VERTICAL);
|
|
1483 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0);
|
|
1484 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
|
|
1485 gtk_size_group_add_widget(sg, button);
|
|
1486 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_info_cb),
|
|
1487 gtkblist->treeview);
|
|
1488 gtk_tooltips_set_tip(GTK_TOOLTIPS(gtkblist->tooltips), button, _("Get information on the selected buddy"), NULL);
|
|
1489 gtk_widget_show(button);
|
|
1490
|
|
1491 button = gaim_pixbuf_button_from_stock(_("Chat"), GAIM_STOCK_CHAT, GAIM_BUTTON_VERTICAL);
|
|
1492 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0);
|
|
1493 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
|
|
1494 gtk_size_group_add_widget(sg, button);
|
5234
|
1495 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_chat_cb), gtkblist->treeview);
|
5228
|
1496 gtk_tooltips_set_tip(GTK_TOOLTIPS(gtkblist->tooltips), button, _("Join a chat room"), NULL);
|
|
1497 gtk_widget_show(button);
|
|
1498
|
|
1499 button = gaim_pixbuf_button_from_stock(_("Away"), GAIM_STOCK_ICON_AWAY, GAIM_BUTTON_VERTICAL);
|
|
1500 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0);
|
|
1501 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
|
|
1502 gtk_size_group_add_widget(sg, button);
|
|
1503 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_away_cb), NULL);
|
|
1504 gtk_tooltips_set_tip(GTK_TOOLTIPS(gtkblist->tooltips), button, _("Set an away message"), NULL);
|
|
1505 gtk_widget_show(button);
|
|
1506
|
|
1507 /* this will show the right image/label widgets for us */
|
|
1508 gaim_gtk_blist_update_toolbar();
|
|
1509
|
|
1510 /* start the refresh timer */
|
5297
|
1511 if (blist_options & (OPT_BLIST_SHOW_IDLETIME | OPT_BLIST_SHOW_ICONS))
|
|
1512 gtkblist->refresh_timer = g_timeout_add(30000, (GSourceFunc)gaim_gtk_blist_refresh_timer, list);
|
5228
|
1513 }
|
|
1514
|
|
1515 void gaim_gtk_blist_refresh(struct gaim_buddy_list *list)
|
|
1516 {
|
5234
|
1517 GaimBlistNode *group, *buddy;
|
5228
|
1518
|
5234
|
1519 for(group = list->root; group; group = group->next) {
|
|
1520 if(!GAIM_BLIST_NODE_IS_GROUP(group))
|
|
1521 continue;
|
5228
|
1522 gaim_gtk_blist_update(list, group);
|
5234
|
1523 for(buddy = group->child; buddy; buddy = buddy->next) {
|
5228
|
1524 gaim_gtk_blist_update(list, buddy);
|
|
1525 }
|
|
1526 }
|
|
1527 }
|
|
1528
|
5297
|
1529 void
|
|
1530 gaim_gtk_blist_update_refresh_timeout()
|
|
1531 {
|
|
1532 struct gaim_buddy_list *blist;
|
|
1533 struct gaim_gtk_buddy_list *gtkblist;
|
|
1534
|
|
1535 gaim_debug(GAIM_DEBUG_INFO, "update_refresh_timeout", "called\n");
|
|
1536
|
|
1537 blist = gaim_get_blist();
|
|
1538 gtkblist = GAIM_GTK_BLIST(gaim_get_blist());
|
|
1539
|
|
1540 if (blist_options & (OPT_BLIST_SHOW_IDLETIME | OPT_BLIST_SHOW_ICONS)) {
|
|
1541 gtkblist->refresh_timer = g_timeout_add(30000, (GSourceFunc)gaim_gtk_blist_refresh_timer, blist);
|
|
1542 } else {
|
|
1543 g_source_remove(gtkblist->refresh_timer);
|
|
1544 gtkblist->refresh_timer = 0;
|
|
1545 }
|
|
1546 }
|
|
1547
|
5256
|
1548 static gboolean get_iter_from_node(GaimBlistNode *node, GtkTreeIter *iter) {
|
|
1549 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data;
|
|
1550 GtkTreePath *path;
|
5228
|
1551
|
5263
|
1552 if (!gtknode) {
|
|
1553 gaim_debug(GAIM_DEBUG_ERROR, "gtkblist", "buddy %s has no ui_data\n", ((struct buddy *)node)->name);
|
|
1554 return FALSE;
|
|
1555 }
|
|
1556
|
|
1557 if (!gtkblist) {
|
|
1558 gaim_debug(GAIM_DEBUG_ERROR, "gtkblist", "get_iter_from_node was called, but we don't seem to have a blist\n");
|
|
1559 return FALSE;
|
|
1560 }
|
|
1561
|
|
1562 if (!gtknode->row)
|
5228
|
1563 return FALSE;
|
|
1564
|
5256
|
1565 if ((path = gtk_tree_row_reference_get_path(gtknode->row)) == NULL)
|
5228
|
1566 return FALSE;
|
5256
|
1567 if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), iter, path)) {
|
|
1568 gtk_tree_path_free(path);
|
|
1569 return FALSE;
|
|
1570 }
|
|
1571 gtk_tree_path_free(path);
|
|
1572 return TRUE;
|
5228
|
1573 }
|
|
1574
|
|
1575 /*
|
|
1576 * These state assignments suck. I'm sorry. They're for historical reasons.
|
|
1577 * Roll on new prefs. -Robot101
|
|
1578 *
|
|
1579 * NO_BUTTON_TEXT && SHOW_BUTTON_XPM - image
|
|
1580 * !NO_BUTTON_TEXT && !SHOW_BUTTON_XPM - text
|
|
1581 * !NO_BUTTON_TEXT && SHOW_BUTTON_XPM - text & images
|
|
1582 * NO_BUTTON_TEXT && !SHOW_BUTTON_XPM - none
|
|
1583 */
|
|
1584
|
|
1585 static void gaim_gtk_blist_update_toolbar_icons (GtkWidget *widget, gpointer data) {
|
|
1586 if (GTK_IS_IMAGE(widget)) {
|
|
1587 if (blist_options & OPT_BLIST_SHOW_BUTTON_XPM)
|
|
1588 gtk_widget_show(widget);
|
|
1589 else
|
|
1590 gtk_widget_hide(widget);
|
|
1591 } else if (GTK_IS_LABEL(widget)) {
|
|
1592 if (blist_options & OPT_BLIST_NO_BUTTON_TEXT)
|
|
1593 gtk_widget_hide(widget);
|
|
1594 else
|
|
1595 gtk_widget_show(widget);
|
|
1596 } else if (GTK_IS_CONTAINER(widget)) {
|
|
1597 gtk_container_foreach(GTK_CONTAINER(widget), gaim_gtk_blist_update_toolbar_icons, NULL);
|
|
1598 }
|
|
1599 }
|
|
1600
|
|
1601 void gaim_gtk_blist_update_toolbar() {
|
|
1602 if (!gtkblist)
|
|
1603 return;
|
|
1604
|
|
1605 if (blist_options & OPT_BLIST_NO_BUTTON_TEXT && !(blist_options & OPT_BLIST_SHOW_BUTTON_XPM))
|
|
1606 gtk_widget_hide(gtkblist->bbox);
|
|
1607 else {
|
|
1608 gtk_container_foreach(GTK_CONTAINER(gtkblist->bbox), gaim_gtk_blist_update_toolbar_icons, NULL);
|
|
1609 gtk_widget_show(gtkblist->bbox);
|
|
1610 }
|
|
1611 }
|
|
1612
|
|
1613 static void gaim_gtk_blist_remove(struct gaim_buddy_list *list, GaimBlistNode *node)
|
|
1614 {
|
5260
|
1615 gaim_gtk_blist_hide_node(list, node);
|
5228
|
1616
|
5263
|
1617 /* There's something I don't understand here */
|
|
1618 /* g_free(node->ui_data);
|
|
1619 node->ui_data = NULL; */
|
5228
|
1620 }
|
|
1621
|
|
1622 static gboolean do_selection_changed(GaimBlistNode *new_selection)
|
|
1623 {
|
5254
|
1624 GaimBlistNode *old_selection = NULL;
|
5228
|
1625
|
5254
|
1626 /* test for gtkblist because crazy timeout means we can be called after the blist is gone */
|
|
1627 if (gtkblist && new_selection != gtkblist->selected_node) {
|
|
1628 old_selection = gtkblist->selected_node;
|
5228
|
1629 gtkblist->selected_node = new_selection;
|
|
1630 if(new_selection)
|
|
1631 gaim_gtk_blist_update(NULL, new_selection);
|
|
1632 if(old_selection)
|
|
1633 gaim_gtk_blist_update(NULL, old_selection);
|
|
1634 }
|
|
1635
|
|
1636 return FALSE;
|
|
1637 }
|
|
1638
|
|
1639 static void gaim_gtk_blist_selection_changed(GtkTreeSelection *selection, gpointer data)
|
|
1640 {
|
|
1641 GaimBlistNode *new_selection = NULL;
|
|
1642 GtkTreeIter iter;
|
|
1643
|
|
1644 if(gtk_tree_selection_get_selected(selection, NULL, &iter)){
|
|
1645 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter,
|
|
1646 NODE_COLUMN, &new_selection, -1);
|
|
1647 }
|
5254
|
1648
|
5228
|
1649 /* we set this up as a timeout, otherwise the blist flickers */
|
|
1650 g_timeout_add(0, (GSourceFunc)do_selection_changed, new_selection);
|
|
1651 }
|
|
1652
|
|
1653 static void make_a_group(GaimBlistNode *node, GtkTreeIter *iter) {
|
|
1654 GaimBlistNode *sibling;
|
|
1655 GtkTreeIter siblingiter;
|
5256
|
1656 GtkTreePath *newpath;
|
5228
|
1657 struct group *group = (struct group *)node;
|
5256
|
1658 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data;
|
5228
|
1659 char *esc = g_markup_escape_text(group->name, -1);
|
|
1660 char *mark;
|
|
1661
|
|
1662 if(blist_options & OPT_BLIST_SHOW_GRPNUM)
|
|
1663 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));
|
|
1664 else
|
|
1665 mark = g_strdup_printf("<span weight='bold'>%s</span>", esc);
|
|
1666
|
|
1667 g_free(esc);
|
|
1668
|
|
1669 sibling = node->prev;
|
|
1670 while (sibling && !get_iter_from_node(sibling, &siblingiter)) {
|
|
1671 sibling = sibling->prev;
|
|
1672 }
|
|
1673
|
|
1674 gtk_tree_store_insert_after(gtkblist->treemodel, iter, NULL,
|
|
1675 sibling ? &siblingiter : NULL);
|
5256
|
1676 newpath = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), iter);
|
|
1677 gtknode->row = gtk_tree_row_reference_new(GTK_TREE_MODEL(gtkblist->treemodel), newpath);
|
|
1678 gtk_tree_path_free(newpath);
|
|
1679
|
5228
|
1680 gtk_tree_store_set(gtkblist->treemodel, iter,
|
|
1681 STATUS_ICON_COLUMN, NULL,
|
|
1682 STATUS_ICON_VISIBLE_COLUMN, FALSE,
|
|
1683 NAME_COLUMN, mark,
|
|
1684 NODE_COLUMN, node,
|
|
1685 -1);
|
|
1686 g_free(mark);
|
|
1687 }
|
|
1688
|
|
1689
|
|
1690 static void gaim_gtk_blist_update(struct gaim_buddy_list *list, GaimBlistNode *node)
|
|
1691 {
|
|
1692 GtkTreeIter iter;
|
5256
|
1693 GtkTreePath *expand = NULL, *newpath = NULL;
|
|
1694 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data;
|
5228
|
1695 gboolean new_entry = FALSE;
|
|
1696
|
5256
|
1697 if (!gtkblist || !gtknode)
|
5228
|
1698 return;
|
|
1699
|
5256
|
1700 if (!get_iter_from_node(node, &iter)) {
|
5228
|
1701 new_entry = TRUE;
|
|
1702 if (GAIM_BLIST_NODE_IS_BUDDY(node)) {
|
|
1703 if (((struct buddy*)node)->present != GAIM_BUDDY_OFFLINE || ((blist_options & OPT_BLIST_SHOW_OFFLINE) && ((struct buddy*)node)->account->gc)) {
|
|
1704 GtkTreeIter groupiter;
|
|
1705 GaimBlistNode *oldersibling;
|
|
1706 GtkTreeIter oldersiblingiter;
|
|
1707 char *collapsed = gaim_group_get_setting((struct group *)node->parent, "collapsed");
|
|
1708
|
|
1709 if(node->parent &&
|
|
1710 !get_iter_from_node(node->parent, &groupiter)) {
|
|
1711 /* This buddy's group has not yet been added.
|
|
1712 * We do that here */
|
|
1713 make_a_group(node->parent, &groupiter);
|
|
1714 }
|
|
1715 if(!collapsed)
|
|
1716 expand = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &groupiter);
|
|
1717 else
|
|
1718 g_free(collapsed);
|
|
1719
|
|
1720 oldersibling = node->prev;
|
|
1721 while (oldersibling && !get_iter_from_node(oldersibling, &oldersiblingiter)) {
|
|
1722 oldersibling = oldersibling->prev;
|
|
1723 }
|
|
1724
|
|
1725 gtk_tree_store_insert_after(gtkblist->treemodel, &iter, &groupiter, oldersibling ? &oldersiblingiter : NULL);
|
5256
|
1726 newpath = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &iter);
|
|
1727 gtknode->row = gtk_tree_row_reference_new(GTK_TREE_MODEL(gtkblist->treemodel), newpath);
|
|
1728 gtk_tree_path_free(newpath);
|
5228
|
1729
|
|
1730 if (blist_options & OPT_BLIST_POPUP) {
|
|
1731 gtk_widget_show(gtkblist->window);
|
|
1732 gtk_window_deiconify(GTK_WINDOW(gtkblist->window));
|
|
1733 gdk_window_raise(gtkblist->window->window);
|
|
1734 }
|
|
1735
|
|
1736 }
|
5234
|
1737 } else if (GAIM_BLIST_NODE_IS_CHAT(node) &&
|
|
1738 ((struct chat *)node)->account->gc) {
|
|
1739 GtkTreeIter groupiter;
|
|
1740 GaimBlistNode *oldersibling;
|
|
1741 GtkTreeIter oldersiblingiter;
|
|
1742 char *collapsed = gaim_group_get_setting((struct group *)node->parent, "collapsed");
|
|
1743
|
|
1744 if(node->parent &&
|
|
1745 !get_iter_from_node(node->parent, &groupiter)) {
|
|
1746 /* This buddy's group has not yet been added.
|
|
1747 * We do that here */
|
|
1748 make_a_group(node->parent, &groupiter);
|
|
1749 }
|
|
1750 if(!collapsed)
|
|
1751 expand = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &groupiter);
|
|
1752 else
|
|
1753 g_free(collapsed);
|
|
1754
|
|
1755 oldersibling = node->prev;
|
|
1756 while (oldersibling && !get_iter_from_node(oldersibling, &oldersiblingiter)) {
|
|
1757 oldersibling = oldersibling->prev;
|
|
1758 }
|
|
1759
|
|
1760 gtk_tree_store_insert_after(gtkblist->treemodel, &iter, &groupiter, oldersibling ? &oldersiblingiter : NULL);
|
5256
|
1761 newpath = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &iter);
|
|
1762 gtknode->row = gtk_tree_row_reference_new(GTK_TREE_MODEL(gtkblist->treemodel), newpath);
|
|
1763 gtk_tree_path_free(newpath);
|
5234
|
1764
|
|
1765 } else if (GAIM_BLIST_NODE_IS_GROUP(node) &&
|
5228
|
1766 ((blist_options & OPT_BLIST_SHOW_OFFLINE) ||
|
|
1767 !(blist_options & OPT_BLIST_NO_MT_GRP))) {
|
|
1768 make_a_group(node, &iter);
|
|
1769 expand = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &iter);
|
|
1770 }
|
|
1771 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) {
|
|
1772 if((blist_options & OPT_BLIST_NO_MT_GRP) && !(blist_options & OPT_BLIST_SHOW_OFFLINE) && !gaim_blist_get_group_online_count((struct group *)node)) {
|
|
1773 gtk_tree_store_remove(gtkblist->treemodel, &iter);
|
|
1774 } else {
|
|
1775 struct group *group = (struct group *)node;
|
|
1776 char *esc = g_markup_escape_text(group->name, -1);
|
|
1777 char *mark;
|
|
1778
|
|
1779 if(blist_options & OPT_BLIST_SHOW_GRPNUM)
|
|
1780 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));
|
|
1781 else
|
|
1782 mark = g_strdup_printf("<span weight='bold'>%s</span>", esc);
|
|
1783
|
|
1784 g_free(esc);
|
|
1785 gtk_tree_store_set(gtkblist->treemodel, &iter,
|
|
1786 NAME_COLUMN, mark,
|
|
1787 -1);
|
|
1788 g_free(mark);
|
|
1789 }
|
|
1790 }
|
|
1791
|
5234
|
1792 if (GAIM_BLIST_NODE_IS_CHAT(node) && ((struct chat*)node)->account->gc) {
|
|
1793 GdkPixbuf *status;
|
5237
|
1794 struct chat *chat = (struct chat *)node;
|
|
1795 char *name;
|
5234
|
1796
|
|
1797 status = gaim_gtk_blist_get_status_icon(node,
|
|
1798 blist_options & OPT_BLIST_SHOW_ICONS ? GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL);
|
5237
|
1799 if(chat->alias) {
|
|
1800 name = g_markup_escape_text(chat->alias, -1);
|
|
1801 } else {
|
|
1802 struct proto_chat_entry *pce;
|
5241
|
1803 GList *parts, *tmp;
|
5237
|
1804
|
|
1805 parts = GAIM_PLUGIN_PROTOCOL_INFO(chat->account->gc->prpl)->chat_info(chat->account->gc);
|
|
1806 pce = parts->data;
|
|
1807 name = g_markup_escape_text(g_hash_table_lookup(chat->components,
|
|
1808 pce->identifier), -1);
|
5241
|
1809 for(tmp = parts; tmp; tmp = tmp->next)
|
|
1810 g_free(tmp->data);
|
5237
|
1811 g_list_free(parts);
|
|
1812 }
|
|
1813
|
5234
|
1814
|
|
1815 gtk_tree_store_set(gtkblist->treemodel, &iter,
|
|
1816 STATUS_ICON_COLUMN, status,
|
|
1817 STATUS_ICON_VISIBLE_COLUMN, TRUE,
|
5237
|
1818 NAME_COLUMN, name,
|
5234
|
1819 NODE_COLUMN, node,
|
|
1820 -1);
|
|
1821
|
5237
|
1822 g_free(name);
|
5234
|
1823 if (status != NULL)
|
|
1824 g_object_unref(status);
|
|
1825 } else if(GAIM_BLIST_NODE_IS_CHAT(node) && !((struct chat *)node)->account->gc) {
|
5260
|
1826 gaim_gtk_blist_hide_node(list, node);
|
5234
|
1827 } 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
|
1828 GdkPixbuf *status, *avatar;
|
|
1829 char *mark;
|
|
1830 char *warning = NULL, *idle = NULL;
|
|
1831
|
|
1832 gboolean selected = (gtkblist->selected_node == node);
|
|
1833
|
5234
|
1834 status = gaim_gtk_blist_get_status_icon(node,
|
5228
|
1835 blist_options & OPT_BLIST_SHOW_ICONS ? GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL);
|
|
1836 avatar = gaim_gtk_blist_get_buddy_icon((struct buddy*)node);
|
|
1837 mark = gaim_gtk_blist_get_name_markup((struct buddy*)node, selected);
|
|
1838
|
|
1839 if (((struct buddy*)node)->idle > 0) {
|
|
1840 time_t t;
|
|
1841 int ihrs, imin;
|
|
1842 time(&t);
|
|
1843 ihrs = (t - ((struct buddy *)node)->idle) / 3600;
|
|
1844 imin = ((t - ((struct buddy*)node)->idle) / 60) % 60;
|
|
1845 if(ihrs > 0)
|
|
1846 idle = g_strdup_printf("(%d:%02d)", ihrs, imin);
|
|
1847 else
|
|
1848 idle = g_strdup_printf("(%d)", imin);
|
|
1849 }
|
|
1850
|
|
1851 if (((struct buddy*)node)->evil > 0)
|
|
1852 warning = g_strdup_printf("%d%%", ((struct buddy*)node)->evil);
|
|
1853
|
|
1854
|
|
1855 if((blist_options & OPT_BLIST_GREY_IDLERS)
|
|
1856 && ((struct buddy *)node)->idle) {
|
|
1857 if(warning && !selected) {
|
|
1858 char *w2 = g_strdup_printf("<span color='dim grey'>%s</span>",
|
|
1859 warning);
|
|
1860 g_free(warning);
|
|
1861 warning = w2;
|
|
1862 }
|
|
1863
|
|
1864 if(idle && !selected) {
|
|
1865 char *i2 = g_strdup_printf("<span color='dim grey'>%s</span>",
|
|
1866 idle);
|
|
1867 g_free(idle);
|
|
1868 idle = i2;
|
|
1869 }
|
|
1870 }
|
|
1871
|
|
1872 gtk_tree_store_set(gtkblist->treemodel, &iter,
|
|
1873 STATUS_ICON_COLUMN, status,
|
|
1874 STATUS_ICON_VISIBLE_COLUMN, TRUE,
|
|
1875 NAME_COLUMN, mark,
|
|
1876 WARNING_COLUMN, warning,
|
|
1877 IDLE_COLUMN, idle,
|
|
1878 BUDDY_ICON_COLUMN, avatar,
|
|
1879 NODE_COLUMN, node,
|
|
1880 -1);
|
|
1881
|
|
1882 if (blist_options & OPT_BLIST_POPUP &&
|
|
1883 ((struct buddy *)node)->present == GAIM_BUDDY_SIGNING_OFF) {
|
|
1884 gtk_widget_show(gtkblist->window);
|
|
1885 gtk_window_deiconify(GTK_WINDOW(gtkblist->window));
|
|
1886 gdk_window_raise(gtkblist->window->window);
|
|
1887 }
|
|
1888
|
|
1889 g_free(mark);
|
|
1890 if (idle)
|
|
1891 g_free(idle);
|
|
1892 if (warning)
|
|
1893 g_free(warning);
|
|
1894
|
|
1895 if (status != NULL)
|
|
1896 g_object_unref(status);
|
|
1897
|
|
1898 if (avatar != NULL)
|
|
1899 g_object_unref(avatar);
|
|
1900
|
|
1901 } else if (GAIM_BLIST_NODE_IS_BUDDY(node) && !new_entry) {
|
5260
|
1902 gaim_gtk_blist_hide_node(list, node);
|
5228
|
1903 }
|
5234
|
1904
|
5228
|
1905 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(gtkblist->treeview));
|
|
1906
|
|
1907
|
|
1908 if(expand) {
|
|
1909 gtk_tree_view_expand_row(GTK_TREE_VIEW(gtkblist->treeview), expand, TRUE);
|
|
1910 gtk_tree_path_free(expand);
|
|
1911 }
|
|
1912
|
5234
|
1913 if(GAIM_BLIST_NODE_IS_BUDDY(node) || GAIM_BLIST_NODE_IS_CHAT(node))
|
5228
|
1914 gaim_gtk_blist_update(list, node->parent);
|
|
1915 }
|
|
1916
|
|
1917 static void gaim_gtk_blist_destroy(struct gaim_buddy_list *list)
|
|
1918 {
|
|
1919 if (!gtkblist)
|
|
1920 return;
|
|
1921
|
|
1922 gtk_widget_destroy(gtkblist->window);
|
|
1923 gtk_object_sink(GTK_OBJECT(gtkblist->tooltips));
|
|
1924
|
|
1925 if (gtkblist->refresh_timer)
|
|
1926 g_source_remove(gtkblist->refresh_timer);
|
|
1927 if (gtkblist->timeout)
|
|
1928 g_source_remove(gtkblist->timeout);
|
|
1929
|
|
1930 gtkblist->refresh_timer = 0;
|
|
1931 gtkblist->timeout = 0;
|
|
1932 gtkblist->window = gtkblist->vbox = gtkblist->treeview = NULL;
|
|
1933 gtkblist->treemodel = NULL;
|
|
1934 gtkblist->idle_column = NULL;
|
|
1935 gtkblist->warning_column = gtkblist->buddy_icon_column = NULL;
|
|
1936 gtkblist->bbox = gtkblist->tipwindow = NULL;
|
|
1937 protomenu = NULL;
|
|
1938 awaymenu = NULL;
|
|
1939 gtkblist = NULL;
|
|
1940 }
|
|
1941
|
|
1942 static void gaim_gtk_blist_set_visible(struct gaim_buddy_list *list, gboolean show)
|
|
1943 {
|
|
1944 if (!(gtkblist && gtkblist->window))
|
|
1945 return;
|
|
1946
|
|
1947 if (show) {
|
|
1948 gaim_gtk_blist_restore_position();
|
|
1949 gtk_window_present(GTK_WINDOW(gtkblist->window));
|
|
1950 } else {
|
|
1951 if (!connections || docklet_count) {
|
|
1952 #ifdef _WIN32
|
|
1953 wgaim_systray_minimize(gtkblist->window);
|
|
1954 #endif
|
|
1955 gtk_widget_hide(gtkblist->window);
|
|
1956 } else {
|
|
1957 gtk_window_iconify(GTK_WINDOW(gtkblist->window));
|
|
1958 }
|
|
1959 }
|
|
1960 }
|
|
1961
|
|
1962 void gaim_gtk_blist_docklet_toggle() {
|
|
1963 /* Useful for the docklet plugin and also for the win32 tray icon*/
|
|
1964 /* This is called when one of those is clicked--it will show/hide the
|
|
1965 buddy list/login window--depending on which is active */
|
|
1966 if (connections) {
|
|
1967 if (gtkblist && gtkblist->window) {
|
|
1968 if (GTK_WIDGET_VISIBLE(gtkblist->window)) {
|
|
1969 gaim_blist_set_visible(GAIM_WINDOW_ICONIFIED(gtkblist->window) || gaim_gtk_blist_obscured);
|
|
1970 } else {
|
|
1971 #if _WIN32
|
|
1972 wgaim_systray_maximize(gtkblist->window);
|
|
1973 #endif
|
|
1974 gaim_blist_set_visible(TRUE);
|
|
1975 }
|
|
1976 } else {
|
|
1977 /* we're logging in or something... do nothing */
|
|
1978 /* or should I make the blist? */
|
|
1979 gaim_debug(GAIM_DEBUG_WARNING, "blist",
|
|
1980 "docklet_toggle called with connections "
|
|
1981 "but no blist!\n");
|
|
1982 }
|
|
1983 } else if (mainwindow) {
|
|
1984 if (GTK_WIDGET_VISIBLE(mainwindow)) {
|
|
1985 if (GAIM_WINDOW_ICONIFIED(mainwindow)) {
|
|
1986 gtk_window_present(GTK_WINDOW(mainwindow));
|
|
1987 } else {
|
|
1988 #if _WIN32
|
|
1989 wgaim_systray_minimize(mainwindow);
|
|
1990 #endif
|
|
1991 gtk_widget_hide(mainwindow);
|
|
1992 }
|
|
1993 } else {
|
|
1994 #if _WIN32
|
|
1995 wgaim_systray_maximize(mainwindow);
|
|
1996 #endif
|
|
1997 show_login();
|
|
1998 }
|
|
1999 } else {
|
|
2000 show_login();
|
|
2001 }
|
|
2002 }
|
|
2003
|
|
2004 void gaim_gtk_blist_docklet_add()
|
|
2005 {
|
|
2006 docklet_count++;
|
|
2007 }
|
|
2008
|
|
2009 void gaim_gtk_blist_docklet_remove()
|
|
2010 {
|
|
2011 docklet_count--;
|
|
2012 if (!docklet_count) {
|
|
2013 if (connections)
|
|
2014 gaim_blist_set_visible(TRUE);
|
|
2015 else if (mainwindow)
|
|
2016 gtk_window_present(GTK_WINDOW(mainwindow));
|
|
2017 else
|
|
2018 show_login();
|
|
2019 }
|
|
2020 }
|
|
2021
|
|
2022 static struct gaim_blist_ui_ops blist_ui_ops =
|
|
2023 {
|
|
2024 gaim_gtk_blist_new_list,
|
5256
|
2025 gaim_gtk_blist_new_node,
|
5228
|
2026 gaim_gtk_blist_show,
|
|
2027 gaim_gtk_blist_update,
|
|
2028 gaim_gtk_blist_remove,
|
|
2029 gaim_gtk_blist_destroy,
|
|
2030 gaim_gtk_blist_set_visible
|
|
2031 };
|
|
2032
|
|
2033
|
|
2034 struct gaim_blist_ui_ops *gaim_get_gtk_blist_ui_ops()
|
|
2035 {
|
|
2036 return &blist_ui_ops;
|
|
2037 }
|
|
2038
|
|
2039
|
|
2040
|
|
2041 /*********************************************************************
|
|
2042 * Public utility functions *
|
|
2043 *********************************************************************/
|
|
2044
|
|
2045 GdkPixbuf *
|
|
2046 create_prpl_icon(struct gaim_account *account)
|
|
2047 {
|
|
2048 GaimPlugin *prpl;
|
|
2049 GaimPluginProtocolInfo *prpl_info = NULL;
|
|
2050 GdkPixbuf *status = NULL;
|
|
2051 char *filename = NULL;
|
|
2052 const char *protoname = NULL;
|
|
2053 char buf[256];
|
|
2054
|
|
2055 prpl = gaim_find_prpl(account->protocol);
|
|
2056
|
|
2057 if (prpl != NULL) {
|
|
2058 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
|
|
2059
|
|
2060 if (prpl_info->list_icon != NULL)
|
|
2061 protoname = prpl_info->list_icon(account, NULL);
|
|
2062 }
|
|
2063
|
|
2064 if (protoname == NULL)
|
|
2065 return NULL;
|
|
2066
|
|
2067 /*
|
|
2068 * Status icons will be themeable too, and then it will look up
|
|
2069 * protoname from the theme
|
|
2070 */
|
|
2071 g_snprintf(buf, sizeof(buf), "%s.png", protoname);
|
|
2072
|
|
2073 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status",
|
|
2074 "default", buf, NULL);
|
|
2075 status = gdk_pixbuf_new_from_file(filename, NULL);
|
|
2076 g_free(filename);
|
|
2077
|
|
2078 return status;
|
|
2079 }
|
|
2080
|