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