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