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