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