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