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