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