Mercurial > pidgin.yaz
annotate src/buddy.c @ 4810:0abbbeec0ee8
[gaim-migrate @ 5130]
This will make grey text revert back to the "normal" color when you click on it, which lets gtk handle making it legible. Or something cool like that.
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Mon, 17 Mar 2003 07:21:13 +0000 |
parents | 315ef59a5031 |
children | f9cc606607dc |
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 |
4698 | 59 /* Docklet nonsense */ |
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); | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
66 |
4687 | 67 /*************************************************** |
68 * Callbacks * | |
69 ***************************************************/ | |
3869 | 70 |
4698 | 71 static void gaim_gtk_blist_destroy_cb() |
72 { | |
73 if (docklet_count) | |
74 gaim_blist_set_visible(FALSE); | |
75 else | |
76 do_quit(); | |
77 } | |
78 | |
4732 | 79 static void gtk_blist_menu_info_cb(GtkWidget *w, struct buddy *b) |
80 { | |
81 serv_get_info(b->account->gc, b->name); | |
82 } | |
83 | |
4697 | 84 static void gtk_blist_menu_im_cb(GtkWidget *w, struct buddy *b) |
85 { | |
86 gaim_conversation_new(GAIM_CONV_IM, b->account, b->name); | |
87 } | |
88 | |
89 static void gtk_blist_menu_alias_cb(GtkWidget *w, struct buddy *b) | |
90 { | |
91 alias_dialog_bud(b); | |
92 } | |
93 | |
94 static void gtk_blist_menu_bp_cb(GtkWidget *w, struct buddy *b) | |
95 { | |
96 show_new_bp(b->name, b->account->gc, b->idle, | |
97 b->uc & UC_UNAVAILABLE, NULL); | |
98 } | |
99 | |
100 static void gtk_blist_menu_showlog_cb(GtkWidget *w, struct buddy *b) | |
101 { | |
102 show_log(b->name); | |
103 } | |
104 | |
105 static void gtk_blist_show_systemlog_cb() | |
106 { | |
107 show_log(NULL); | |
108 } | |
109 | |
4776 | 110 static void gtk_blist_show_onlinehelp_cb() |
111 { | |
112 open_url(NULL, "http://gaim.sourceforge.net/documentation.php"); | |
113 } | |
114 | |
4692 | 115 static void gtk_blist_button_im_cb(GtkWidget *w, GtkTreeView *tv) |
116 { | |
117 GtkTreeIter iter; | |
118 GtkTreeModel *model = gtk_tree_view_get_model(tv); | |
119 GtkTreeSelection *sel = gtk_tree_view_get_selection(tv); | |
120 | |
121 if(gtk_tree_selection_get_selected(sel, &model, &iter)){ | |
122 GaimBlistNode *node; | |
123 | |
124 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
125 if (GAIM_BLIST_NODE_IS_BUDDY(node)) | |
126 gaim_conversation_new(GAIM_CONV_IM, ((struct buddy*)node)->account, ((struct buddy*)node)->name); | |
127 } | |
4694 | 128 } |
4692 | 129 |
4694 | 130 static void gtk_blist_button_info_cb(GtkWidget *w, GtkTreeView *tv) |
131 { | |
132 GtkTreeIter iter; | |
133 GtkTreeModel *model = gtk_tree_view_get_model(tv); | |
134 GtkTreeSelection *sel = gtk_tree_view_get_selection(tv); | |
4692 | 135 |
4694 | 136 if(gtk_tree_selection_get_selected(sel, &model, &iter)){ |
137 GaimBlistNode *node; | |
138 | |
139 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
140 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
141 serv_get_info(((struct buddy*)node)->account->gc, ((struct buddy*)node)->name); | |
142 return; | |
143 } | |
144 } | |
145 show_info_dialog(); | |
146 } | |
147 | |
148 static void gtk_blist_button_chat_cb(GtkWidget *w, gpointer data) | |
149 { | |
150 /* FIXME: someday, we can check to see if we've selected a chat node */ | |
151 join_chat(); | |
152 } | |
153 | |
154 static void gtk_blist_button_away_cb(GtkWidget *w, gpointer data) | |
155 { | |
156 gtk_menu_popup(GTK_MENU(awaymenu), NULL, NULL, NULL, NULL, 1, GDK_CURRENT_TIME); | |
4692 | 157 } |
158 | |
4687 | 159 static void gtk_blist_row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) { |
160 GaimBlistNode *node; | |
161 GtkTreeIter iter; | |
162 GValue val = { 0, }; | |
3154 | 163 |
4687 | 164 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); |
165 | |
166 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
167 node = g_value_get_pointer(&val); | |
168 | |
169 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
170 gaim_conversation_new(GAIM_CONV_IM, ((struct buddy*)node)->account, ((struct buddy*)node)->name); | |
4697 | 171 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
172 if (gtk_tree_view_row_expanded(tv, path)) | |
173 gtk_tree_view_collapse_row(tv, path); | |
174 else | |
175 gtk_tree_view_expand_row(tv,path,FALSE); | |
1 | 176 } |
177 } | |
178 | |
4687 | 179 static void gaim_proto_menu_cb(GtkMenuItem *item, struct buddy *b) |
1 | 180 { |
4687 | 181 struct proto_buddy_menu *pbm = g_object_get_data(G_OBJECT(item), "gaimcallback"); |
182 if (pbm->callback) | |
183 pbm->callback(pbm->gc, b->name); | |
1396
df7c3cacac92
[gaim-migrate @ 1406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1392
diff
changeset
|
184 } |
1 | 185 |
4687 | 186 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
|
187 { |
4687 | 188 GtkTreePath *path; |
189 GaimBlistNode *node; | |
190 GValue val = { 0, }; | |
191 GtkTreeIter iter; | |
192 GtkWidget *menu, *menuitem; | |
193 GtkWidget *image; | |
4702 | 194 GtkTreeSelection *sel; |
4687 | 195 GList *list; |
196 struct prpl *prpl; | |
1391
d606da211acb
[gaim-migrate @ 1401]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1376
diff
changeset
|
197 |
4687 | 198 if (event->button != 3) |
199 return FALSE; | |
4718 | 200 |
4687 | 201 /* Here we figure out which node was clicked */ |
202 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL)) | |
203 return FALSE; | |
204 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
205 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
206 node = g_value_get_pointer(&val); | |
4718 | 207 |
4721 | 208 if (!GAIM_BLIST_NODE_IS_BUDDY(node)) { |
209 gtk_tree_path_free(path); | |
4687 | 210 return FALSE; |
4721 | 211 } |
4718 | 212 |
4687 | 213 menu = gtk_menu_new(); |
3251 | 214 |
4687 | 215 /* Protocol specific options */ |
216 prpl = find_prpl(((struct buddy*)node)->account->protocol); | |
4732 | 217 |
218 if(prpl && prpl->get_info) { | |
219 menuitem = gtk_image_menu_item_new_with_mnemonic("_Get Info"); | |
220 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_info_cb), node); | |
221 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
222 } | |
223 | |
224 menuitem = gtk_image_menu_item_new_with_mnemonic("_IM"); | |
225 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_im_cb), node); | |
226 image = gtk_image_new_from_stock(GAIM_STOCK_IM, GTK_ICON_SIZE_MENU); | |
227 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); | |
228 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
229 | |
230 menuitem = gtk_image_menu_item_new_with_mnemonic("_Alias"); | |
231 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_alias_cb), node); | |
232 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
233 | |
234 menuitem = gtk_image_menu_item_new_with_mnemonic("Add Buddy _Pounce"); | |
235 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_bp_cb), node); | |
236 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
237 | |
238 menuitem = gtk_image_menu_item_new_with_mnemonic("View _Log"); | |
239 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_showlog_cb), node); | |
240 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
241 | |
4687 | 242 if (prpl) { |
243 list = prpl->buddy_menu(((struct buddy*)node)->account->gc, ((struct buddy*)node)->name); | |
244 while (list) { | |
245 struct proto_buddy_menu *pbm = list->data; | |
246 menuitem = gtk_menu_item_new_with_mnemonic(pbm->label); | |
247 g_object_set_data(G_OBJECT(menuitem), "gaimcallback", pbm); | |
248 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gaim_proto_menu_cb), node); | |
249 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
250 list = list->next; | |
3313 | 251 } |
3251 | 252 } |
1 | 253 |
4687 | 254 gtk_widget_show_all(menu); |
255 | |
256 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time); | |
1 | 257 |
4702 | 258 #if (1) /* This code only exists because GTK doesn't work. If we return FALSE here, as would be normal |
259 * the event propoagates down and somehow gets interpreted as the start of a drag event. */ | |
260 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)); | |
261 gtk_tree_selection_select_path(sel, path); | |
4721 | 262 gtk_tree_path_free(path); |
4702 | 263 return TRUE; |
264 #endif | |
1 | 265 } |
266 | |
4687 | 267 /* This is called 10 seconds after the buddy logs in. It removes the "logged in" icon and replaces it with |
268 * the normal status icon */ | |
1072
81d19577285a
[gaim-migrate @ 1082]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1070
diff
changeset
|
269 |
4687 | 270 static gboolean gaim_reset_present_icon(GaimBlistNode *b) |
271 { | |
272 ((struct buddy*)b)->present = 1; | |
273 gaim_gtk_blist_update(NULL, b); | |
274 return FALSE; | |
577
aa9a8bcddd80
[gaim-migrate @ 587]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
544
diff
changeset
|
275 } |
aa9a8bcddd80
[gaim-migrate @ 587]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
544
diff
changeset
|
276 |
4687 | 277 static void gaim_gtk_blist_add_buddy_cb() |
935
5e6ca3dd4d02
[gaim-migrate @ 945]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
921
diff
changeset
|
278 { |
4690 | 279 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); |
4687 | 280 GtkTreeIter iter; |
281 GaimBlistNode *node; | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4349
diff
changeset
|
282 |
4692 | 283 if(gtk_tree_selection_get_selected(sel, NULL, &iter)){ |
284 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
4691 | 285 if (GAIM_BLIST_NODE_IS_BUDDY(node)) |
286 show_add_buddy(NULL, NULL, ((struct group*)node->parent)->name, NULL); | |
287 else if (GAIM_BLIST_NODE_IS_GROUP(node)) | |
288 show_add_buddy(NULL, NULL, ((struct group*)node)->name, NULL); | |
289 } | |
4697 | 290 else { |
4692 | 291 show_add_buddy(NULL, NULL, NULL, NULL); |
292 } | |
1 | 293 } |
294 | |
4697 | 295 static void gaim_gtk_blist_update_toolbar_icons (GtkWidget *widget, gpointer data) { |
296 if (GTK_IS_IMAGE(widget)) { | |
297 if (blist_options & OPT_BLIST_SHOW_BUTTON_XPM) | |
298 gtk_widget_show(widget); | |
299 else | |
300 gtk_widget_hide(widget); | |
301 } else if (GTK_IS_CONTAINER(widget)) { | |
302 gtk_container_foreach(GTK_CONTAINER(widget), gaim_gtk_blist_update_toolbar_icons, NULL); | |
303 } | |
304 } | |
1 | 305 |
4702 | 306 static void gaim_gtk_blist_drag_data_get_cb (GtkWidget *widget, |
307 GdkDragContext *dc, | |
308 GtkSelectionData *data, | |
309 guint info, | |
310 guint time, | |
311 gpointer *null) | |
312 { | |
4781 | 313 if (data->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE)) { |
4702 | 314 GtkTreeRowReference *ref = g_object_get_data(G_OBJECT(dc), "gtk-tree-view-source-row"); |
315 GtkTreePath *sourcerow = gtk_tree_row_reference_get_path(ref); | |
316 GtkTreeIter iter; | |
317 GaimBlistNode *node = NULL; | |
318 GValue val = {0}; | |
319 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, sourcerow); | |
320 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
321 node = g_value_get_pointer(&val); | |
4781 | 322 gtk_selection_data_set (data, |
323 gdk_atom_intern ("GAIM_BLIST_NODE", FALSE), | |
324 8, /* bits */ | |
325 (void*)&node, | |
326 sizeof (node)); | |
327 | |
4721 | 328 gtk_tree_path_free(sourcerow); |
4702 | 329 } |
4781 | 330 |
4702 | 331 } |
332 | |
333 static void gaim_gtk_blist_drag_data_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, | |
334 GtkSelectionData *sd, guint info, guint t) | |
335 { | |
4781 | 336 if (sd->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE) && sd->data) { |
337 GaimBlistNode *n = NULL; | |
4702 | 338 GtkTreePath *path = NULL; |
4704 | 339 GtkTreeViewDropPosition position; |
4781 | 340 memcpy(&n, sd->data, sizeof(n)); |
4704 | 341 if(gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), x, y, &path, &position)) { |
342 /* if we're here, I think it means the drop is ok */ | |
4770 | 343 GtkTreeIter iter; |
344 GaimBlistNode *node; | |
345 GValue val = {0}; | |
346 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
347 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
348 node = g_value_get_pointer(&val); | |
4781 | 349 |
350 if (GAIM_BLIST_NODE_IS_BUDDY(n)) { | |
351 struct buddy *b = (struct buddy*)n; | |
352 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
4795 | 353 switch(position) { |
354 case GTK_TREE_VIEW_DROP_AFTER: | |
355 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
356 gaim_blist_add_buddy(b, (struct group*)node->parent, node); | |
357 break; | |
358 case GTK_TREE_VIEW_DROP_BEFORE: | |
359 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
360 gaim_blist_add_buddy(b, (struct group*)node->parent, node->prev); | |
361 break; | |
4781 | 362 } |
363 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
364 gaim_blist_add_buddy(b, (struct group*)node, NULL); | |
4795 | 365 } |
4781 | 366 } else if (GAIM_BLIST_NODE_IS_GROUP(n)) { |
367 struct group *g = (struct group*)n; | |
368 if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
369 switch (position) { | |
370 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
371 case GTK_TREE_VIEW_DROP_AFTER: | |
372 gaim_blist_add_group(g, node); | |
373 break; | |
374 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
375 case GTK_TREE_VIEW_DROP_BEFORE: | |
376 gaim_blist_add_group(g, node->prev); | |
377 break; | |
378 } | |
379 | |
4770 | 380 } |
4781 | 381 |
4777 | 382 } |
4781 | 383 |
4721 | 384 gtk_tree_path_free(path); |
4704 | 385 } |
4702 | 386 } |
387 } | |
388 | |
4724 | 389 static void gaim_gtk_blist_paint_tip(GtkWidget *widget, GdkEventExpose *event, struct buddy *b) |
390 { | |
391 GtkStyle *style; | |
392 GdkPixbuf *pixbuf = gaim_gtk_blist_get_status_icon(b, GAIM_STATUS_ICON_LARGE); | |
393 PangoLayout *layout; | |
394 char *tooltiptext = gaim_get_tooltip_text(b); | |
395 | |
396 layout = gtk_widget_create_pango_layout (gtkblist->tipwindow, NULL); | |
397 pango_layout_set_markup(layout, tooltiptext, strlen(tooltiptext)); | |
4732 | 398 pango_layout_set_wrap(layout, PANGO_WRAP_WORD); |
4733 | 399 pango_layout_set_width(layout, 300000); |
4724 | 400 style = gtkblist->tipwindow->style; |
4732 | 401 |
4724 | 402 gtk_paint_flat_box (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, |
403 NULL, gtkblist->tipwindow, "tooltip", 0, 0, -1, -1); | |
4729 | 404 |
405 #if GTK_CHECK_VERSION(2,2,0) | |
4724 | 406 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, pixbuf, |
407 0, 0, 4, 4, -1 , -1, GDK_RGB_DITHER_NONE, 0, 0); | |
4729 | 408 #else |
4758 | 409 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 | 410 #endif |
4724 | 411 |
412 gtk_paint_layout (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, TRUE, | |
413 NULL, gtkblist->tipwindow, "tooltip", 38, 4, layout); | |
414 | |
415 g_object_unref (pixbuf); | |
416 g_object_unref (layout); | |
417 g_free(tooltiptext); | |
418 return; | |
419 } | |
420 | |
421 static gboolean gaim_gtk_blist_tooltip_timeout(GtkWidget *tv) | |
422 { | |
423 GtkTreePath *path; | |
424 GtkTreeIter iter; | |
425 GaimBlistNode *node; | |
426 GValue val = {0}; | |
427 | |
428 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), gtkblist->rect.x, gtkblist->rect.y, &path, NULL, NULL, NULL)) | |
429 return FALSE; | |
430 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
431 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
432 node = g_value_get_pointer(&val); | |
433 | |
434 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
435 int scr_w,scr_h, w, h, x, y; | |
436 PangoLayout *layout; | |
437 struct buddy *buddy = (struct buddy*)node; | |
438 char *tooltiptext = gaim_get_tooltip_text(buddy); | |
439 gtkblist->tipwindow = gtk_window_new(GTK_WINDOW_POPUP); | |
440 gtk_widget_set_app_paintable(gtkblist->tipwindow, TRUE); | |
4729 | 441 gtk_window_set_resizable(GTK_WINDOW(gtkblist->tipwindow), FALSE); |
4724 | 442 gtk_widget_set_name(gtkblist->tipwindow, "gtk-tooltips"); |
443 g_signal_connect(G_OBJECT(gtkblist->tipwindow), "expose_event", | |
444 G_CALLBACK(gaim_gtk_blist_paint_tip), buddy); | |
445 gtk_widget_ensure_style (gtkblist->tipwindow); | |
446 | |
447 layout = gtk_widget_create_pango_layout (gtkblist->tipwindow, NULL); | |
4733 | 448 pango_layout_set_wrap(layout, PANGO_WRAP_WORD); |
449 pango_layout_set_width(layout, 300000); | |
4724 | 450 pango_layout_set_markup(layout, tooltiptext, strlen(tooltiptext)); |
451 scr_w = gdk_screen_width(); | |
452 scr_h = gdk_screen_height(); | |
453 pango_layout_get_size (layout, &w, &h); | |
454 w = PANGO_PIXELS(w) + 8; | |
455 h = PANGO_PIXELS(h) + 8; | |
456 | |
457 /* 38 is the size of a large status icon plus 4 pixels padding on each side. | |
458 I should #define this or something */ | |
459 w = w + 38; | |
460 h = MAX(h, 38); | |
461 | |
462 gdk_window_get_pointer(NULL, &x, &y, NULL); | |
463 if (GTK_WIDGET_NO_WINDOW(gtkblist->window)) | |
464 y+=gtkblist->window->allocation.y; | |
465 | |
466 x -= ((w >> 1) + 4); | |
467 | |
468 if ((x + w) > scr_w) | |
469 x -= (x + w) - scr_w; | |
470 else if (x < 0) | |
471 x = 0; | |
472 | |
473 if ((y + h + 4) > scr_h) | |
474 y = y - h; | |
475 else | |
476 y = y + 6; | |
477 g_object_unref (layout); | |
478 g_free(tooltiptext); | |
479 gtk_widget_set_size_request(gtkblist->tipwindow, w, h); | |
4729 | 480 gtk_window_move(GTK_WINDOW(gtkblist->tipwindow), x, y); |
4724 | 481 gtk_widget_show(gtkblist->tipwindow); |
482 } | |
4729 | 483 |
4724 | 484 gtk_tree_path_free(path); |
485 return FALSE; | |
486 } | |
487 | |
4730 | 488 static gboolean gaim_gtk_blist_motion_cb (GtkWidget *tv, GdkEventMotion *event, gpointer null) |
4724 | 489 { |
490 GtkTreePath *path; | |
491 | |
492 if (gtkblist->timeout) { | |
493 if ((event->y > gtkblist->rect.y) && ((event->y - gtkblist->rect.height) < gtkblist->rect.y)) | |
4732 | 494 return FALSE; |
4724 | 495 /* We've left the cell. Remove the timeout and create a new one below */ |
496 if (gtkblist->tipwindow) { | |
497 gtk_widget_destroy(gtkblist->tipwindow); | |
498 gtkblist->tipwindow = NULL; | |
499 } | |
500 | |
501 g_source_remove(gtkblist->timeout); | |
502 } | |
503 | |
504 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL); | |
505 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, >kblist->rect); | |
506 if (path) | |
507 gtk_tree_path_free(path); | |
508 gtkblist->timeout = g_timeout_add(500, (GSourceFunc)gaim_gtk_blist_tooltip_timeout, tv); | |
4730 | 509 return FALSE; |
4724 | 510 } |
511 | |
512 static void gaim_gtk_blist_leave_cb (GtkWidget *w, GdkEventCrossing *e, gpointer n) | |
513 { | |
514 if (gtkblist->timeout == 0) | |
515 return; | |
516 if (gtkblist->tipwindow) { | |
517 gtk_widget_destroy(gtkblist->tipwindow); | |
518 gtkblist->tipwindow = NULL; | |
519 } | |
520 g_source_remove(gtkblist->timeout); | |
521 gtkblist->timeout = 0; | |
522 } | |
523 | |
4687 | 524 /*************************************************** |
525 * Crap * | |
526 ***************************************************/ | |
527 static GtkItemFactoryEntry blist_menu[] = | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
528 { |
4687 | 529 /* Buddies menu */ |
530 { N_("/_Buddies"), NULL, NULL, 0, "<Branch>" }, | |
531 { N_("/Buddies/_Add A Buddy..."), "<CTL>B", gaim_gtk_blist_add_buddy_cb, 0, | |
532 "<StockItem>", GTK_STOCK_ADD }, | |
533 { N_("/Buddies/New _Instant Message..."), "<CTL>I", show_im_dialog, 0, | |
534 "<StockItem>", GAIM_STOCK_IM }, | |
535 { N_("/Buddies/Join a _Chat..."), "<CTL>C", join_chat, 0, | |
536 "<StockItem>", GAIM_STOCK_CHAT }, | |
537 { N_("/Buddies/sep1"), NULL, NULL, 0, "<Separator>" }, | |
538 { N_("/Buddies/Get _User Info..."), "<CTL>J", show_info_dialog, 0, | |
539 "<StockItem>", GAIM_STOCK_INFO }, | |
540 { N_("/Buddies/sep2"), NULL, NULL, 0, "<Separator>" }, | |
541 { N_("/Buddies/_Signoff"), "<CTL>D", signoff_all, 0, NULL }, | |
542 { N_("/Buddies/_Quit"), "<CTL>Q", do_quit, 0, | |
543 "<StockItem>", GTK_STOCK_QUIT }, | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
544 |
4687 | 545 /* Tools */ |
546 { N_("/_Tools"), NULL, NULL, 0, "<Branch>" }, | |
547 { N_("/Tools/_Away"), NULL, NULL, 0, "<Branch>" }, | |
548 { N_("/Tools/Buddy _Pounce"), NULL, NULL, 0, "<Branch>" }, | |
549 { N_("/Tools/sep1"), NULL, NULL, 0, "<Separator>" }, | |
550 { N_("/Tools/A_ccounts"), "<CTL>A", account_editor, 0, NULL }, | |
4694 | 551 { N_("/Tools/Preferences"), "<CTL>P", show_prefs, 0, |
4687 | 552 "<StockItem>", GTK_STOCK_PREFERENCES }, |
4698 | 553 { N_("/Tools/_File Transfers"), NULL, gaim_show_xfer_dialog, 0, |
4687 | 554 "<StockItem>", GTK_STOCK_REVERT_TO_SAVED }, |
555 { N_("/Tools/sep2"), NULL, NULL, 0, "<Separator>" }, | |
556 { N_("/Tools/P_rotocol Actions"), NULL, NULL, 0, "<Branch>" }, | |
557 { N_("/Tools/Pr_ivacy"), NULL, show_privacy_options, 0, NULL }, | |
4697 | 558 { N_("/Tools/View System _Log"), NULL, gtk_blist_show_systemlog_cb, 0, NULL }, |
3251 | 559 |
4687 | 560 /* Help */ |
561 { N_("/_Help"), NULL, NULL, 0, "<Branch>" }, | |
4776 | 562 { N_("/Help/Online _Help"), "F1", gtk_blist_show_onlinehelp_cb, 0, |
4687 | 563 "<StockItem>", GTK_STOCK_HELP }, |
4755 | 564 { N_("/Help/_Debug Window"), NULL, toggle_debug, 0, NULL }, |
4687 | 565 { N_("/Help/_About"), NULL, show_about, 0, NULL }, |
566 | |
567 }; | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
568 |
4687 | 569 /********************************************************* |
570 * Private Utility functions * | |
571 *********************************************************/ | |
572 | |
4724 | 573 static char *gaim_get_tooltip_text(struct buddy *b) |
574 { | |
575 char *text = NULL; | |
576 struct prpl* prpl = find_prpl(b->account->protocol); | |
577 char *statustext = NULL; | |
578 char *warning = NULL, *idletime = NULL; | |
579 | |
580 if (prpl->tooltip_text) { | |
4732 | 581 statustext = prpl->tooltip_text(b); |
4724 | 582 } |
4732 | 583 |
4724 | 584 if (b->idle) { |
585 int ihrs, imin; | |
586 time_t t; | |
587 time(&t); | |
588 ihrs = (t - b->idle) / 3600; | |
589 imin = ((t - b->idle) / 60) % 60; | |
590 if (ihrs) | |
4744 | 591 idletime = g_strdup_printf(_("%dh%02dm"), ihrs, imin); |
4724 | 592 else |
4744 | 593 idletime = g_strdup_printf(_("%dm"), imin); |
4724 | 594 } |
4732 | 595 |
4724 | 596 if (b->evil > 0) |
4744 | 597 warning = g_strdup_printf(_("%d%%"), b->evil); |
4732 | 598 |
4724 | 599 text = g_strdup_printf("<span size='larger' weight='bold'>%s</span>" |
4744 | 600 "%s %s" /* Alias */ |
601 "%s %s" /* Nickname */ | |
602 "%s %s" /* Idle */ | |
603 "%s %s" /* Warning */ | |
4741 | 604 "%s%s", /* Status */ |
4724 | 605 b->name, |
4744 | 606 b->alias && b->alias[0] ? _("\n<b>Alias:</b>") : "", b->alias ? b->alias : "", |
607 b->server_alias ? _("\n<b>Nickname:</b>") : "", b->server_alias ? b->server_alias : "", | |
608 b->idle ? _("\n<b>Idle:</b>") : "", b->idle ? idletime : "", | |
609 b->evil ? _("\n<b>Warned:</b>") : "", b->evil ? warning : "", | |
4724 | 610 statustext ? "\n" : "", statustext ? statustext : ""); |
4737 | 611 if(warning) |
612 g_free(warning); | |
613 if(idletime) | |
614 g_free(idletime); | |
615 if(statustext) | |
616 g_free(statustext); | |
617 | |
4724 | 618 return text; |
619 | |
620 } | |
621 | |
622 static GdkPixbuf *gaim_gtk_blist_get_status_icon(struct buddy *b, GaimStatusIconSize size) | |
4687 | 623 { |
624 GdkPixbuf *status = NULL; | |
625 GdkPixbuf *scale = NULL; | |
626 GdkPixbuf *emblem = NULL; | |
4737 | 627 gchar *filename = NULL; |
4687 | 628 const char *protoname = NULL; |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
629 |
4691 | 630 char *se = NULL, *sw = NULL ,*nw = NULL ,*ne = NULL; |
4737 | 631 |
4687 | 632 int scalesize = 30; |
633 | |
634 struct prpl* prpl = find_prpl(b->account->protocol); | |
635 if (prpl->list_icon) | |
636 protoname = prpl->list_icon(b->account, b); | |
637 if (prpl->list_emblems) | |
638 prpl->list_emblems(b, &se, &sw, &nw, &ne); | |
4737 | 639 |
4724 | 640 if (size == GAIM_STATUS_ICON_SMALL) { |
4687 | 641 scalesize = 15; |
642 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
|
643 } |
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
644 |
4701 | 645 |
4687 | 646 if (b->present == 2) { |
4701 | 647 struct gaim_gtk_blist_node *gtknode; |
4687 | 648 /* If b->present is 2, that means this buddy has just signed on. We use the "login" icon for the |
649 * status, and we set a timeout to change it to a normal icon after 10 seconds. */ | |
650 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "login.png", NULL); | |
651 status = gdk_pixbuf_new_from_file(filename,NULL); | |
652 g_free(filename); | |
4701 | 653 |
654 gtknode = GAIM_GTK_BLIST_NODE((GaimBlistNode*)b); | |
4773 | 655 if (gtknode->timer > 0) |
656 g_source_remove(gtknode->timer); | |
4701 | 657 gtknode->timer = g_timeout_add(10000, (GSourceFunc)gaim_reset_present_icon, b); |
658 | |
4737 | 659 /* "Hey, what's all this crap?" you ask. Status icons will be themeable too, and |
4687 | 660 then it will look up protoname from the theme */ |
661 } else { | |
662 char *image = g_strdup_printf("%s.png", protoname); | |
663 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
664 status = gdk_pixbuf_new_from_file(filename,NULL); | |
665 g_free(image); | |
666 g_free(filename); | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
667 |
4687 | 668 } |
4737 | 669 |
4687 | 670 if (!status) |
671 return NULL; | |
4737 | 672 |
4687 | 673 scale = gdk_pixbuf_scale_simple(status, scalesize, scalesize, GDK_INTERP_BILINEAR); |
4737 | 674 |
675 g_object_unref(G_OBJECT(status)); | |
676 | |
4687 | 677 /* Emblems */ |
4737 | 678 |
4687 | 679 /* Each protocol can specify up to four "emblems" to composite over the base icon. "away", "busy", "mobile user" |
680 * are all examples of states represented by emblems. I'm not even really sure I like this yet. */ | |
4737 | 681 |
4687 | 682 /* XXX Clean this crap up, yo. */ |
683 if (se) { | |
684 char *image = g_strdup_printf("%s.png", se); | |
685 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
686 g_free(image); | |
687 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
688 g_free(filename); | |
689 if (emblem) { | |
4724 | 690 if (size == GAIM_STATUS_ICON_LARGE) |
4687 | 691 gdk_pixbuf_composite (emblem, |
692 scale, 15, 15, | |
693 15, 15, | |
694 15, 15, | |
695 1, 1, | |
696 GDK_INTERP_BILINEAR, | |
697 255); | |
698 else | |
699 gdk_pixbuf_composite (emblem, | |
700 scale, 0, 0, | |
701 15, 15, | |
702 0, 0, | |
703 1, 1, | |
704 GDK_INTERP_BILINEAR, | |
705 255); | |
4737 | 706 g_object_unref(G_OBJECT(emblem)); |
4687 | 707 } |
708 } | |
709 if (sw) { | |
710 char *image = g_strdup_printf("%s.png", sw); | |
711 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
712 g_free(image); | |
713 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
714 g_free(filename); | |
715 if (emblem) { | |
4737 | 716 gdk_pixbuf_composite (emblem, |
717 scale, 0, 15, | |
718 15, 15, | |
719 0, 15, | |
720 1, 1, | |
721 GDK_INTERP_BILINEAR, | |
722 255); | |
723 g_object_unref(G_OBJECT(emblem)); | |
4687 | 724 } |
725 } | |
726 if (nw) { | |
727 char *image = g_strdup_printf("%s.png", nw); | |
728 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
729 g_free(image); | |
730 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
731 g_free(filename); | |
732 if (emblem) { | |
733 gdk_pixbuf_composite (emblem, | |
734 scale, 0, 0, | |
735 15, 15, | |
736 0, 0, | |
737 1, 1, | |
738 GDK_INTERP_BILINEAR, | |
739 255); | |
4737 | 740 g_object_unref(G_OBJECT(emblem)); |
4687 | 741 } |
742 } | |
743 if (ne) { | |
744 char *image = g_strdup_printf("%s.png", ne); | |
745 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
746 g_free(image); | |
747 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
748 g_free(filename); | |
749 if (emblem) { | |
750 gdk_pixbuf_composite (emblem, | |
751 scale, 15, 0, | |
752 15, 15, | |
753 15, 0, | |
754 1, 1, | |
755 GDK_INTERP_BILINEAR, | |
756 255); | |
757 } | |
4737 | 758 } |
4687 | 759 |
4737 | 760 |
4718 | 761 /* Idle grey buddies affects the whole row. This converts the status icon to greyscale. */ |
4699 | 762 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS) |
4687 | 763 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0, FALSE); |
764 return scale; | |
1 | 765 } |
766 | |
4737 | 767 static GdkPixbuf *gaim_gtk_blist_get_buddy_icon(struct buddy *b) |
1 | 768 { |
4687 | 769 /* This just opens a file from ~/.gaim/icons/screenname. This needs to change to be more gooder. */ |
4737 | 770 char *file; |
771 GdkPixbuf *buf, *ret; | |
772 | |
4687 | 773 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) |
774 return NULL; | |
4737 | 775 |
4757 | 776 if ((file = gaim_buddy_get_setting(b, "buddy_icon")) == NULL) |
777 return NULL; | |
778 | |
4737 | 779 buf = gdk_pixbuf_new_from_file(file, NULL); |
780 g_free(file); | |
781 | |
782 | |
4687 | 783 if (buf) { |
4699 | 784 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS) { |
4687 | 785 gdk_pixbuf_saturate_and_pixelate(buf, buf, 0, FALSE); |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
786 } |
4737 | 787 ret = gdk_pixbuf_scale_simple(buf,30,30, GDK_INTERP_BILINEAR); |
788 g_object_unref(G_OBJECT(buf)); | |
789 return ret; | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
790 } |
4687 | 791 return NULL; |
2986 | 792 } |
793 | |
4810 | 794 static gchar *gaim_gtk_blist_get_name_markup(struct buddy *b, gboolean selected) |
1 | 795 { |
4687 | 796 char *name = gaim_get_buddy_alias(b); |
797 char *esc = g_markup_escape_text(name, strlen(name)), *text = NULL; | |
4722 | 798 struct prpl* prpl = find_prpl(b->account->protocol); |
799 | |
4687 | 800 /* XXX Clean up this crap */ |
4699 | 801 |
4687 | 802 int ihrs, imin; |
4724 | 803 char *idletime = NULL, *warning = NULL, *statustext = NULL; |
4732 | 804 time_t t; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
805 |
4687 | 806 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) { |
4810 | 807 if (b->idle > 0 && blist_options & OPT_BLIST_GREY_IDLERS && !selected) { |
4718 | 808 text = g_strdup_printf("<span color='dim grey'>%s</span>", |
4699 | 809 esc); |
4687 | 810 g_free(esc); |
811 return text; | |
812 } else { | |
813 return esc; | |
814 } | |
1 | 815 } |
816 | |
4687 | 817 time(&t); |
818 ihrs = (t - b->idle) / 3600; | |
819 imin = ((t - b->idle) / 60) % 60; | |
4699 | 820 |
4722 | 821 if (prpl->status_text) { |
4732 | 822 char *tmp = prpl->status_text(b); |
823 | |
824 if(tmp) { | |
4806 | 825 g_strdelimit(tmp, "\n", ' '); |
4732 | 826 if(strlen(tmp) > 20) |
4757 | 827 statustext = g_strdup_printf("%.20s... ", tmp); |
4732 | 828 else |
4757 | 829 statustext = g_strdup_printf("%s ", tmp); |
4732 | 830 g_free(tmp); |
831 } | |
4722 | 832 } |
4732 | 833 |
4687 | 834 if (b->idle) { |
835 if (ihrs) | |
4757 | 836 idletime = g_strdup_printf(_("Idle (%dh%02dm) "), ihrs, imin); |
4687 | 837 else |
4757 | 838 idletime = g_strdup_printf(_("Idle (%dm) "), imin); |
4687 | 839 } |
4757 | 840 |
4687 | 841 if (b->evil > 0) |
4757 | 842 warning = g_strdup_printf(_("Warned (%d%%) "), b->evil); |
843 | |
4810 | 844 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS && !selected) { |
4757 | 845 text = g_strdup_printf("<span color='dim grey'>%s</span>\n<span color='dim grey' size='smaller'>%s%s%s</span>", |
4687 | 846 esc, |
4722 | 847 statustext != NULL ? statustext : "", |
848 idletime != NULL ? idletime : "", | |
849 warning != NULL ? warning : ""); | |
4797 | 850 } else if (statustext == NULL && idletime == NULL && warning == NULL) { |
851 text = g_strdup_printf("%s", esc); | |
852 } else { | |
4810 | 853 text = g_strdup_printf("%s\n<span %s size='smaller'>%s%s%s</span>", esc, |
854 selected ? "" : "color='dim grey'", | |
855 statustext != NULL ? statustext : "", | |
856 idletime != NULL ? idletime : "", | |
857 warning != NULL ? warning : ""); | |
4797 | 858 } |
4722 | 859 if (idletime) |
4687 | 860 g_free(idletime); |
4722 | 861 if (warning) |
4687 | 862 g_free(warning); |
4722 | 863 if (statustext) |
864 g_free(statustext); | |
4737 | 865 if (esc) |
866 g_free(esc); | |
4699 | 867 |
4687 | 868 return text; |
869 } | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
870 |
4687 | 871 /********************************************************************************** |
872 * Public API Functions * | |
873 **********************************************************************************/ | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
874 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
|
875 { |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
876 blist->ui_data = g_new0(struct gaim_gtk_buddy_list, 1); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
877 } |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
878 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
879 static void gaim_gtk_blist_new_node(GaimBlistNode *node) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
880 { |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
881 node->ui_data = g_new0(struct gaim_gtk_blist_node, 1); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
882 } |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
883 |
4729 | 884 void gaim_gtk_blist_update_columns() |
885 { | |
886 if (blist_options & OPT_BLIST_SHOW_ICONS) { | |
887 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, TRUE); | |
888 gtk_tree_view_column_set_visible(gtkblist->idle_column, FALSE); | |
889 gtk_tree_view_column_set_visible(gtkblist->warning_column, FALSE); | |
890 } else { | |
891 gtk_tree_view_column_set_visible(gtkblist->idle_column, blist_options & OPT_BLIST_SHOW_IDLETIME); | |
892 gtk_tree_view_column_set_visible(gtkblist->warning_column, blist_options & OPT_BLIST_SHOW_WARN); | |
893 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, FALSE); | |
894 } | |
895 } | |
896 | |
4702 | 897 enum {DRAG_BUDDY, DRAG_ROW}; |
898 | |
4687 | 899 static void gaim_gtk_blist_show(struct gaim_buddy_list *list) |
900 { | |
901 GtkItemFactory *ift; | |
902 GtkCellRenderer *rend; | |
903 GtkTreeViewColumn *column; | |
904 GtkWidget *sw; | |
905 GtkWidget *button; | |
4694 | 906 GtkSizeGroup *sg; |
4810 | 907 GtkTreeSelection *selection; |
4781 | 908 GtkTargetEntry gte[] = {{"GAIM_BLIST_NODE", GTK_TARGET_SAME_APP, DRAG_ROW}, |
4702 | 909 {"application/x-im-contact", 0, DRAG_BUDDY}}; |
4690 | 910 |
4745 | 911 if (gtkblist && gtkblist->window) { |
4687 | 912 gtk_widget_show(gtkblist->window); |
913 return; | |
914 } | |
4690 | 915 |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
916 gtkblist = GAIM_GTK_BLIST(list); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
917 |
4687 | 918 gtkblist->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
919 gtk_window_set_title(GTK_WINDOW(gtkblist->window), _("Buddy List")); | |
4690 | 920 |
4687 | 921 gtkblist->vbox = gtk_vbox_new(FALSE, 6); |
922 gtk_container_add(GTK_CONTAINER(gtkblist->window), gtkblist->vbox); | |
1 | 923 |
4698 | 924 g_signal_connect(G_OBJECT(gtkblist->window), "delete_event", G_CALLBACK(gaim_gtk_blist_destroy_cb), NULL); |
925 | |
4687 | 926 /******************************* Menu bar *************************************/ |
927 ift = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GaimMain>", NULL); | |
928 gtk_item_factory_create_items(ift, sizeof(blist_menu) / sizeof(*blist_menu), | |
929 blist_menu, NULL); | |
930 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtk_item_factory_get_widget(ift, "<GaimMain>"), FALSE, FALSE, 0); | |
1 | 931 |
4694 | 932 awaymenu = gtk_item_factory_get_widget(ift, "/Tools/Away"); |
933 do_away_menu(); | |
934 | |
4696 | 935 bpmenu = gtk_item_factory_get_widget(ift, "/Tools/Buddy Pounce"); |
936 do_bp_menu(); | |
937 | |
938 protomenu = gtk_item_factory_get_widget(ift, "/Tools/Protocol Actions"); | |
939 do_proto_menu(); | |
940 | |
4687 | 941 /****************************** GtkTreeView **********************************/ |
942 sw = gtk_scrolled_window_new(NULL,NULL); | |
943 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); | |
944 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
4690 | 945 gtk_widget_set_size_request(sw, 200, 200); |
4687 | 946 |
4729 | 947 gtkblist->treemodel = gtk_tree_store_new(BLIST_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, |
4687 | 948 G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_POINTER); |
4702 | 949 |
4687 | 950 gtkblist->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(gtkblist->treemodel)); |
4704 | 951 |
4810 | 952 /* Set up selection stuff */ |
953 | |
954 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); | |
955 g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(gaim_gtk_blist_selection_changed), NULL); | |
956 | |
957 | |
4702 | 958 /* Set up dnd */ |
959 gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(gtkblist->treeview), GDK_BUTTON1_MASK, gte, | |
960 2, GDK_ACTION_COPY); | |
4704 | 961 gtk_tree_view_enable_model_drag_dest(GTK_TREE_VIEW(gtkblist->treeview), gte, 2, |
4702 | 962 GDK_ACTION_COPY | GDK_ACTION_MOVE); |
4704 | 963 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-received", G_CALLBACK(gaim_gtk_blist_drag_data_rcv_cb), NULL); |
964 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-get", G_CALLBACK(gaim_gtk_blist_drag_data_get_cb), NULL); | |
965 | |
4724 | 966 /* Tooltips */ |
967 g_signal_connect(G_OBJECT(gtkblist->treeview), "motion-notify-event", G_CALLBACK(gaim_gtk_blist_motion_cb), NULL); | |
968 g_signal_connect(G_OBJECT(gtkblist->treeview), "leave-notify-event", G_CALLBACK(gaim_gtk_blist_leave_cb), NULL); | |
4687 | 969 |
970 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(gtkblist->treeview), FALSE); | |
1 | 971 |
4687 | 972 rend = gtk_cell_renderer_pixbuf_new(); |
973 column = gtk_tree_view_column_new_with_attributes("Status", rend, "pixbuf", STATUS_ICON_COLUMN, NULL); | |
974 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); | |
4796 | 975 g_object_set(rend, "ypad", 0, NULL); |
4706 | 976 |
4687 | 977 rend = gtk_cell_renderer_text_new(); |
978 column = gtk_tree_view_column_new_with_attributes("Name", rend, "markup", NAME_COLUMN, NULL); | |
979 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); | |
4797 | 980 g_object_set(rend, "ypad", 0, "yalign", 0.5, NULL); |
4706 | 981 |
4687 | 982 rend = gtk_cell_renderer_text_new(); |
4725 | 983 gtkblist->warning_column = gtk_tree_view_column_new_with_attributes("Warning", rend, "markup", WARNING_COLUMN, NULL); |
984 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->warning_column); | |
4796 | 985 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); |
4687 | 986 |
987 rend = gtk_cell_renderer_text_new(); | |
4725 | 988 gtkblist->idle_column = gtk_tree_view_column_new_with_attributes("Idle", rend, "markup", IDLE_COLUMN, NULL); |
989 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->idle_column); | |
4796 | 990 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); |
1 | 991 |
4687 | 992 rend = gtk_cell_renderer_pixbuf_new(); |
4725 | 993 gtkblist->buddy_icon_column = gtk_tree_view_column_new_with_attributes("Buddy Icon", rend, "pixbuf", BUDDY_ICON_COLUMN, NULL); |
4796 | 994 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); |
4725 | 995 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->buddy_icon_column); |
4718 | 996 |
4687 | 997 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-activated", G_CALLBACK(gtk_blist_row_activated_cb), NULL); |
998 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
|
999 |
4687 | 1000 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), sw, TRUE, TRUE, 0); |
1001 gtk_container_add(GTK_CONTAINER(sw), gtkblist->treeview); | |
4725 | 1002 gaim_gtk_blist_update_columns(); |
4687 | 1003 /**************************** Button Box **************************************/ |
4694 | 1004 |
1005 sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); | |
4687 | 1006 gtkblist->bbox = gtk_hbox_new(TRUE, 0); |
1007 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtkblist->bbox, FALSE, FALSE, 0); | |
1008 button = gaim_pixbuf_button_from_stock(_("IM"), GAIM_STOCK_IM, GAIM_BUTTON_VERTICAL); | |
1009 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1010 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 1011 gtk_size_group_add_widget(sg, button); |
4692 | 1012 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_im_cb), |
4697 | 1013 gtkblist->treeview); |
1014 | |
4687 | 1015 button = gaim_pixbuf_button_from_stock(_("Get Info"), GAIM_STOCK_INFO, GAIM_BUTTON_VERTICAL); |
1016 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1017 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 1018 gtk_size_group_add_widget(sg, button); |
1019 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_info_cb), | |
4697 | 1020 gtkblist->treeview); |
4729 | 1021 |
4687 | 1022 button = gaim_pixbuf_button_from_stock(_("Chat"), GAIM_STOCK_CHAT, GAIM_BUTTON_VERTICAL); |
1023 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1024 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 1025 gtk_size_group_add_widget(sg, button); |
1026 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_chat_cb), NULL); | |
1027 | |
4687 | 1028 button = gaim_pixbuf_button_from_stock(_("Away"), GAIM_STOCK_AWAY, GAIM_BUTTON_VERTICAL); |
1029 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1030 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 1031 gtk_size_group_add_widget(sg, button); |
1032 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_away_cb), NULL); | |
4687 | 1033 |
1034 /* OK... let's show this bad boy. */ | |
1035 gaim_gtk_blist_refresh(list); | |
1036 gtk_widget_show_all(gtkblist->window); | |
4729 | 1037 |
4697 | 1038 gaim_gtk_blist_update_toolbar(); |
1039 | |
4687 | 1040 } |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
1041 |
4687 | 1042 void gaim_gtk_blist_refresh(struct gaim_buddy_list *list) |
1043 { | |
1044 GaimBlistNode *group = list->root; | |
1045 GaimBlistNode *buddy; | |
4690 | 1046 |
4687 | 1047 while (group) { |
1048 gaim_gtk_blist_update(list, group); | |
1049 buddy = group->child; | |
1050 while (buddy) { | |
4699 | 1051 gaim_gtk_blist_update(list, buddy); |
4687 | 1052 buddy = buddy->next; |
1053 } | |
1054 group = group->next; | |
1055 } | |
1056 } | |
1 | 1057 |
4699 | 1058 static gboolean get_iter_from_node_helper(GaimBlistNode *node, GtkTreeIter *iter, GtkTreeIter *root) { |
1059 do { | |
1060 GaimBlistNode *n; | |
1061 GtkTreeIter child; | |
1062 | |
1063 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), root, NODE_COLUMN, &n, -1); | |
1064 if(n == node) { | |
1065 *iter = *root; | |
1066 return TRUE; | |
1067 } | |
1068 | |
1069 if(gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &child, root)) { | |
1070 if(get_iter_from_node_helper(node,iter,&child)) | |
1071 return TRUE; | |
1072 } | |
1073 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(gtkblist->treemodel), root)); | |
1074 | |
1075 return FALSE; | |
1076 } | |
1077 | |
1078 static gboolean get_iter_from_node(GaimBlistNode *node, GtkTreeIter *iter) { | |
1079 GtkTreeIter root; | |
1080 | |
1081 if (!gtkblist) | |
1082 return FALSE; | |
1083 | |
1084 if(!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(gtkblist->treemodel), &root)) | |
1085 return FALSE; | |
1086 | |
1087 return get_iter_from_node_helper(node, iter, &root); | |
1088 } | |
1089 | |
4697 | 1090 void gaim_gtk_blist_update_toolbar() { |
1091 if (!gtkblist) | |
1092 return; | |
4699 | 1093 |
4697 | 1094 gtk_container_foreach(GTK_CONTAINER(gtkblist->bbox), gaim_gtk_blist_update_toolbar_icons, NULL); |
4699 | 1095 |
4697 | 1096 if (blist_options & OPT_BLIST_NO_BUTTONS) |
1097 gtk_widget_hide(gtkblist->bbox); | |
1098 else | |
1099 gtk_widget_show_all(gtkblist->bbox); | |
1100 } | |
1101 | |
4701 | 1102 static void gaim_gtk_blist_remove(struct gaim_buddy_list *list, GaimBlistNode *node) |
1103 { | |
1104 struct gaim_gtk_blist_node *gtknode; | |
1105 GtkTreeIter iter; | |
1106 | |
1107 if (!node->ui_data) | |
1108 return; | |
1109 | |
1110 gtknode = (struct gaim_gtk_blist_node *)node->ui_data; | |
1111 | |
1112 if (gtknode->timer > 0) { | |
1113 g_source_remove(gtknode->timer); | |
1114 gtknode->timer = 0; | |
1115 } | |
1116 | |
1117 if (get_iter_from_node(node, &iter)) { | |
1118 gtk_tree_store_remove(gtkblist->treemodel, &iter); | |
1119 if(GAIM_BLIST_NODE_IS_BUDDY(node) && gaim_blist_get_group_online_count((struct group *)node->parent) == 0) { | |
1120 GtkTreeIter groupiter; | |
1121 if(get_iter_from_node(node->parent, &groupiter)) | |
1122 gtk_tree_store_remove(gtkblist->treemodel, &groupiter); | |
1123 } | |
1124 } | |
1125 } | |
1126 | |
4810 | 1127 static gboolean do_selection_changed(GaimBlistNode *new_selection) |
1128 { | |
1129 GaimBlistNode *old_selection = gtkblist->selected_node; | |
1130 | |
1131 if(new_selection != gtkblist->selected_node) { | |
1132 gtkblist->selected_node = new_selection; | |
1133 if(new_selection) | |
1134 gaim_gtk_blist_update(NULL, new_selection); | |
1135 if(old_selection) | |
1136 gaim_gtk_blist_update(NULL, old_selection); | |
1137 } | |
1138 | |
1139 return FALSE; | |
1140 } | |
1141 | |
1142 static void gaim_gtk_blist_selection_changed(GtkTreeSelection *selection, gpointer data) | |
1143 { | |
1144 GaimBlistNode *new_selection = NULL; | |
1145 GtkTreeIter iter; | |
1146 | |
1147 if(gtk_tree_selection_get_selected(selection, NULL, &iter)){ | |
1148 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, | |
1149 NODE_COLUMN, &new_selection, -1); | |
1150 } | |
1151 /* we set this up as a timeout, otherwise the blist flickers */ | |
1152 g_timeout_add(0, (GSourceFunc)do_selection_changed, new_selection); | |
1153 } | |
1154 | |
4701 | 1155 |
4687 | 1156 static void gaim_gtk_blist_update(struct gaim_buddy_list *list, GaimBlistNode *node) |
1157 { | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1158 struct gaim_gtk_blist_node *gtknode; |
4699 | 1159 GtkTreeIter iter; |
4687 | 1160 gboolean expand = FALSE; |
4699 | 1161 gboolean new_entry = FALSE; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
1162 |
4687 | 1163 if (!gtkblist) |
1164 return; | |
4699 | 1165 |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1166 gtknode = GAIM_GTK_BLIST_NODE(node); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1167 |
4690 | 1168 |
4699 | 1169 if (!get_iter_from_node(node, &iter)) { /* This is a newly added node */ |
1170 new_entry = TRUE; | |
4687 | 1171 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { |
1172 if (((struct buddy*)node)->present) { | |
4699 | 1173 GtkTreeIter groupiter; |
1174 GaimBlistNode *oldersibling; | |
1175 GtkTreeIter oldersiblingiter; | |
4690 | 1176 |
4699 | 1177 if(node->parent && !get_iter_from_node(node->parent, &groupiter)) { |
1178 /* This buddy's group has not yet been added. We do that here */ | |
4757 | 1179 GdkPixbuf *groupicon = gtk_widget_render_icon(gtkblist->treeview, |
1180 GTK_STOCK_OPEN, GTK_ICON_SIZE_SMALL_TOOLBAR, NULL); | |
4794 | 1181 char *esc = g_markup_escape_text(((struct group*)node->parent)->name, -1); |
1182 char *mark = g_strdup_printf("<span weight='bold'>%s</span>", esc); | |
1183 g_free(esc); | |
4699 | 1184 oldersibling = node->parent->prev; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
1185 |
4687 | 1186 /* We traverse backwards through the buddy list to find the node in the tree to insert it after */ |
4699 | 1187 while (oldersibling && !get_iter_from_node(oldersibling, &oldersiblingiter)) |
1188 oldersibling = oldersibling->prev; | |
4690 | 1189 |
4687 | 1190 /* This is where we create the node and add it. */ |
4699 | 1191 gtk_tree_store_insert_after(gtkblist->treemodel, &groupiter, NULL, oldersibling ? &oldersiblingiter : NULL); |
1192 gtk_tree_store_set(gtkblist->treemodel, &groupiter, | |
4757 | 1193 STATUS_ICON_COLUMN, groupicon, |
4687 | 1194 NAME_COLUMN, mark, |
1195 NODE_COLUMN, node->parent, | |
1196 -1); | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1197 |
4737 | 1198 g_free(mark); |
4757 | 1199 g_object_unref(G_OBJECT(groupicon)); |
4737 | 1200 |
4687 | 1201 expand = TRUE; |
1202 } | |
4810 | 1203 |
4699 | 1204 oldersibling = node->prev; |
1205 while (oldersibling && !get_iter_from_node(oldersibling, &oldersiblingiter)) | |
1206 oldersibling = oldersibling->prev; | |
1207 | |
1208 gtk_tree_store_insert_after(gtkblist->treemodel, &iter, &groupiter, oldersibling ? &oldersiblingiter : NULL); | |
4810 | 1209 |
4767 | 1210 if (blist_options & OPT_BLIST_POPUP) |
1211 gtk_window_present(GTK_WINDOW(gtkblist->window)); | |
4699 | 1212 |
4687 | 1213 if (expand) { /* expand was set to true if this is the first element added to a group. In such case |
1214 * we expand the group node */ | |
4699 | 1215 GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &groupiter); |
1216 gtk_tree_view_expand_row(GTK_TREE_VIEW(gtkblist->treeview), path, TRUE); | |
4721 | 1217 gtk_tree_path_free(path); |
4687 | 1218 } |
4699 | 1219 } |
1220 } | |
1221 } | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1222 |
4687 | 1223 if (GAIM_BLIST_NODE_IS_BUDDY(node) && ((struct buddy*)node)->present) { |
1224 GdkPixbuf *status, *avatar; | |
1225 char *mark; | |
4697 | 1226 char *warning = NULL, *idle = NULL; |
1227 | |
4810 | 1228 gboolean selected = (gtkblist->selected_node == node); |
1229 | |
1230 status = gaim_gtk_blist_get_status_icon((struct buddy*)node, | |
4724 | 1231 blist_options & OPT_BLIST_SHOW_ICONS ? GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL); |
4687 | 1232 avatar = gaim_gtk_blist_get_buddy_icon((struct buddy*)node); |
4810 | 1233 mark = gaim_gtk_blist_get_name_markup((struct buddy*)node, selected); |
4697 | 1234 |
4725 | 1235 if (((struct buddy*)node)->idle > 0) { |
4697 | 1236 time_t t; |
1237 int ihrs, imin; | |
1238 time(&t); | |
1239 ihrs = (t - ((struct buddy *)node)->idle) / 3600; | |
1240 imin = ((t - ((struct buddy*)node)->idle) / 60) % 60; | |
4718 | 1241 if(ihrs > 0) |
1242 idle = g_strdup_printf("(%d:%02d)", ihrs, imin); | |
1243 else | |
1244 idle = g_strdup_printf("(%d)", imin); | |
4697 | 1245 } |
1246 | |
4725 | 1247 if (((struct buddy*)node)->evil > 0) |
4699 | 1248 warning = g_strdup_printf("%d%%", ((struct buddy*)node)->evil); |
4810 | 1249 |
4697 | 1250 |
4718 | 1251 if((blist_options & OPT_BLIST_GREY_IDLERS) |
1252 && ((struct buddy *)node)->idle) { | |
4810 | 1253 if(warning && !selected) { |
4718 | 1254 char *w2 = g_strdup_printf("<span color='dim grey'>%s</span>", |
1255 warning); | |
1256 g_free(warning); | |
1257 warning = w2; | |
1258 } | |
1259 | |
4810 | 1260 if(idle && !selected) { |
4718 | 1261 char *i2 = g_strdup_printf("<span color='dim grey'>%s</span>", |
1262 idle); | |
1263 g_free(idle); | |
1264 idle = i2; | |
1265 } | |
1266 } | |
1267 | |
1268 | |
4699 | 1269 gtk_tree_store_set(gtkblist->treemodel, &iter, |
4687 | 1270 STATUS_ICON_COLUMN, status, |
1271 NAME_COLUMN, mark, | |
4697 | 1272 WARNING_COLUMN, warning, |
1273 IDLE_COLUMN, idle, | |
4699 | 1274 BUDDY_ICON_COLUMN, avatar, |
4687 | 1275 NODE_COLUMN, node, |
1276 -1); | |
4699 | 1277 |
4687 | 1278 g_free(mark); |
4697 | 1279 if (idle) |
1280 g_free(idle); | |
1281 if (warning) | |
1282 g_free(warning); | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1283 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1284 if (status != NULL) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1285 g_object_unref(status); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1286 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1287 if (avatar != NULL) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1288 g_object_unref(avatar); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1289 |
4701 | 1290 } else if (GAIM_BLIST_NODE_IS_BUDDY(node) && !new_entry) { |
1291 gaim_gtk_blist_remove(list, node); | |
4767 | 1292 if (blist_options & OPT_BLIST_POPUP) |
1293 gtk_window_present(GTK_WINDOW(gtkblist->window)); | |
4781 | 1294 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
1295 GaimBlistNode *afsad = node->child; | |
1296 while (afsad) { | |
1297 gaim_gtk_blist_update(list, afsad); | |
1298 afsad = afsad->next; | |
1299 } | |
4687 | 1300 } |
4786 | 1301 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(gtkblist->treeview)); |
4687 | 1302 } |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
1303 |
4687 | 1304 static void gaim_gtk_blist_destroy(struct gaim_buddy_list *list) |
1305 { | |
4770 | 1306 if (!gtkblist) |
1307 return; | |
4687 | 1308 gtk_widget_destroy(gtkblist->window); |
4745 | 1309 |
1310 gtkblist->window = gtkblist->vbox = gtkblist->treeview = NULL; | |
1311 gtkblist->treemodel = NULL; | |
1312 gtkblist->idle_column = NULL; | |
1313 gtkblist->warning_column = gtkblist->buddy_icon_column = NULL; | |
1314 gtkblist->bbox = gtkblist->tipwindow = NULL; | |
1315 protomenu = NULL; | |
1316 awaymenu = NULL; | |
1317 bpmenu = NULL; | |
1318 | |
1319 gtkblist->timeout = 0; | |
4687 | 1320 } |
1 | 1321 |
4687 | 1322 static void gaim_gtk_blist_set_visible(struct gaim_buddy_list *list, gboolean show) |
1323 { | |
4698 | 1324 if (show) { |
4699 | 1325 gtk_window_present(GTK_WINDOW(gtkblist->window)); |
4698 | 1326 } else { |
1327 if (!connections || docklet_count) { | |
1328 #ifdef _WIN32 | |
4711
0c1f3e651d3e
[gaim-migrate @ 5022]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4706
diff
changeset
|
1329 wgaim_systray_minimize(gtkblist->window); |
4698 | 1330 #endif |
1331 gtk_widget_hide(gtkblist->window); | |
1332 } else { | |
1333 gtk_window_iconify(GTK_WINDOW(gtkblist->window)); | |
1334 } | |
1335 } | |
1336 } | |
1337 | |
1338 void gaim_gtk_blist_docklet_toggle() { | |
1339 /* Useful for the docklet plugin and also for the win32 tray icon*/ | |
1340 /* This is called when one of those is clicked--it will show/hide the | |
1341 buddy list/login window--depending on which is active */ | |
1342 if (connections && gtkblist) { | |
1343 if (GTK_WIDGET_VISIBLE(gtkblist->window)) { | |
1344 gaim_blist_set_visible(GAIM_WINDOW_ICONIFIED(gtkblist->window) || gaim_gtk_blist_obscured); | |
1345 } else { | |
1346 #if _WIN32 | |
4711
0c1f3e651d3e
[gaim-migrate @ 5022]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4706
diff
changeset
|
1347 wgaim_systray_maximize(gtkblist->window); |
4698 | 1348 #endif |
1349 gaim_blist_set_visible(TRUE); | |
1350 } | |
1351 } else if (connections) { | |
1352 /* we're logging in or something... do nothing */ | |
1353 debug_printf("docklet_toggle called with connections but no blist!\n"); | |
1354 } else { | |
1355 if (GTK_WIDGET_VISIBLE(mainwindow)) { | |
1356 if (GAIM_WINDOW_ICONIFIED(mainwindow)) { | |
1357 gtk_window_present(GTK_WINDOW(mainwindow)); | |
1358 } else { | |
1359 #if _WIN32 | |
1360 wgaim_systray_minimize(mainwindow); | |
1361 #endif | |
1362 gtk_widget_hide(mainwindow); | |
1363 } | |
1364 } else { | |
1365 #if _WIN32 | |
1366 wgaim_systray_maximize(mainwindow); | |
1367 #endif | |
1368 gtk_window_present(GTK_WINDOW(mainwindow)); | |
1369 } | |
1370 } | |
1371 } | |
1372 | |
1373 void gaim_gtk_blist_docklet_add() | |
1374 { | |
1375 docklet_count++; | |
1376 } | |
1377 | |
1378 void gaim_gtk_blist_docklet_remove() | |
1379 { | |
1380 docklet_count--; | |
1381 if (!docklet_count) { | |
1382 if (connections) { | |
1383 gaim_blist_set_visible(TRUE); | |
4745 | 1384 } else if(gtkblist && gtkblist->window) { |
4698 | 1385 gtk_window_present(GTK_WINDOW(gtkblist->window)); |
1386 } | |
1387 } | |
4687 | 1388 } |
1 | 1389 |
4687 | 1390 static struct gaim_blist_ui_ops blist_ui_ops = |
1391 { | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1392 gaim_gtk_blist_new_list, |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1393 gaim_gtk_blist_new_node, |
4687 | 1394 gaim_gtk_blist_show, |
1395 gaim_gtk_blist_update, | |
1396 gaim_gtk_blist_remove, | |
1397 gaim_gtk_blist_destroy, | |
1398 gaim_gtk_blist_set_visible | |
1399 }; | |
1 | 1400 |
1401 | |
4687 | 1402 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
|
1403 { |
4687 | 1404 return &blist_ui_ops; |
1037
1c663beef29d
[gaim-migrate @ 1047]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1036
diff
changeset
|
1405 } |
1c663beef29d
[gaim-migrate @ 1047]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1036
diff
changeset
|
1406 |
3131 | 1407 |
1408 | |
4687 | 1409 /********************************************************************* |
1410 * Public utility functions * | |
1411 *********************************************************************/ | |
1058
4927ce25d8cc
[gaim-migrate @ 1068]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1412 |
4687 | 1413 GdkPixbuf * |
1414 create_prpl_icon(struct gaim_account *account) | |
4553
d03fcb3f4be2
[gaim-migrate @ 4833]
Christian Hammond <chipx86@chipx86.com>
parents:
4525
diff
changeset
|
1415 { |
4687 | 1416 struct prpl *prpl = find_prpl(account->protocol); |
1417 GdkPixbuf *status = NULL; | |
1418 char *filename = NULL; | |
1419 const char *protoname = prpl->list_icon(account, NULL); | |
1420 /* "Hey, what's all this crap?" you ask. Status icons will be themeable too, and | |
1421 then it will look up protoname from the theme */ | |
1422 if (!strcmp(protoname, "aim")) { | |
1423 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "aim.png", NULL); | |
1424 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1425 g_free(filename); | |
1426 } else if (!strcmp(protoname, "yahoo")) { | |
1427 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "yahoo.png", NULL); | |
1428 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1429 g_free(filename); | |
1430 } else if (!strcmp(protoname, "msn")) { | |
1431 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "msn.png", NULL); | |
1432 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1433 g_free(filename); | |
1434 } else if (!strcmp(protoname, "jabber")) { | |
1435 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "jabber.png", NULL); | |
1436 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1437 g_free(filename); | |
1438 } else if (!strcmp(protoname, "icq")) { | |
1439 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "icq.png", NULL); | |
1440 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1441 g_free(filename); | |
1442 } else if (!strcmp(protoname, "gadu-gadu")) { | |
1443 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "gadugadu.png", NULL); | |
1444 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1445 g_free(filename); | |
1446 } else if (!strcmp(protoname, "napster")) { | |
1447 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "napster.png", NULL); | |
1448 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1449 g_free(filename); | |
1450 } else if (!strcmp(protoname, "irc")) { | |
1451 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "irc.png", NULL); | |
1452 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1453 g_free(filename); | |
960
fa681641643d
[gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
945
diff
changeset
|
1454 } |
4687 | 1455 return status; |
1 | 1456 } |
4699 | 1457 |