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