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