Mercurial > pidgin.yaz
annotate src/buddy.c @ 4714:51ce3eb7e0bf
[gaim-migrate @ 5025]
including io.h
committer: Tailor Script <tailor@pidgin.im>
author | Herman Bloggs <hermanator12002@yahoo.com> |
---|---|
date | Tue, 11 Mar 2003 20:36:54 +0000 |
parents | 0c1f3e651d3e |
children | 3fa8596a45dc |
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 | |
4687 | 62 static void gaim_gtk_blist_update(struct gaim_buddy_list *list, GaimBlistNode *node); |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
63 |
4687 | 64 /*************************************************** |
65 * Callbacks * | |
66 ***************************************************/ | |
3869 | 67 |
4698 | 68 static void gaim_gtk_blist_destroy_cb() |
69 { | |
70 if (docklet_count) | |
71 gaim_blist_set_visible(FALSE); | |
72 else | |
73 do_quit(); | |
74 } | |
75 | |
4697 | 76 static void gtk_blist_menu_im_cb(GtkWidget *w, struct buddy *b) |
77 { | |
78 gaim_conversation_new(GAIM_CONV_IM, b->account, b->name); | |
79 } | |
80 | |
81 static void gtk_blist_menu_alias_cb(GtkWidget *w, struct buddy *b) | |
82 { | |
83 alias_dialog_bud(b); | |
84 } | |
85 | |
86 static void gtk_blist_menu_bp_cb(GtkWidget *w, struct buddy *b) | |
87 { | |
88 show_new_bp(b->name, b->account->gc, b->idle, | |
89 b->uc & UC_UNAVAILABLE, NULL); | |
90 } | |
91 | |
92 static void gtk_blist_menu_showlog_cb(GtkWidget *w, struct buddy *b) | |
93 { | |
94 show_log(b->name); | |
95 } | |
96 | |
97 static void gtk_blist_show_systemlog_cb() | |
98 { | |
99 show_log(NULL); | |
100 } | |
101 | |
4692 | 102 static void gtk_blist_button_im_cb(GtkWidget *w, GtkTreeView *tv) |
103 { | |
104 GtkTreeIter iter; | |
105 GtkTreeModel *model = gtk_tree_view_get_model(tv); | |
106 GtkTreeSelection *sel = gtk_tree_view_get_selection(tv); | |
107 | |
108 if(gtk_tree_selection_get_selected(sel, &model, &iter)){ | |
109 GaimBlistNode *node; | |
110 | |
111 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
112 if (GAIM_BLIST_NODE_IS_BUDDY(node)) | |
113 gaim_conversation_new(GAIM_CONV_IM, ((struct buddy*)node)->account, ((struct buddy*)node)->name); | |
114 } | |
4694 | 115 } |
4692 | 116 |
4694 | 117 static void gtk_blist_button_info_cb(GtkWidget *w, GtkTreeView *tv) |
118 { | |
119 GtkTreeIter iter; | |
120 GtkTreeModel *model = gtk_tree_view_get_model(tv); | |
121 GtkTreeSelection *sel = gtk_tree_view_get_selection(tv); | |
4692 | 122 |
4694 | 123 if(gtk_tree_selection_get_selected(sel, &model, &iter)){ |
124 GaimBlistNode *node; | |
125 | |
126 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
127 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
128 serv_get_info(((struct buddy*)node)->account->gc, ((struct buddy*)node)->name); | |
129 return; | |
130 } | |
131 } | |
132 show_info_dialog(); | |
133 } | |
134 | |
135 static void gtk_blist_button_chat_cb(GtkWidget *w, gpointer data) | |
136 { | |
137 /* FIXME: someday, we can check to see if we've selected a chat node */ | |
138 join_chat(); | |
139 } | |
140 | |
141 static void gtk_blist_button_away_cb(GtkWidget *w, gpointer data) | |
142 { | |
143 gtk_menu_popup(GTK_MENU(awaymenu), NULL, NULL, NULL, NULL, 1, GDK_CURRENT_TIME); | |
4692 | 144 } |
145 | |
4687 | 146 static void gtk_blist_row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) { |
147 GaimBlistNode *node; | |
148 GtkTreeIter iter; | |
149 GValue val = { 0, }; | |
3154 | 150 |
4687 | 151 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); |
152 | |
153 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
154 node = g_value_get_pointer(&val); | |
155 | |
156 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
157 gaim_conversation_new(GAIM_CONV_IM, ((struct buddy*)node)->account, ((struct buddy*)node)->name); | |
4697 | 158 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
159 if (gtk_tree_view_row_expanded(tv, path)) | |
160 gtk_tree_view_collapse_row(tv, path); | |
161 else | |
162 gtk_tree_view_expand_row(tv,path,FALSE); | |
1 | 163 } |
164 } | |
165 | |
4687 | 166 static void gaim_proto_menu_cb(GtkMenuItem *item, struct buddy *b) |
1 | 167 { |
4687 | 168 struct proto_buddy_menu *pbm = g_object_get_data(G_OBJECT(item), "gaimcallback"); |
169 if (pbm->callback) | |
170 pbm->callback(pbm->gc, b->name); | |
1396
df7c3cacac92
[gaim-migrate @ 1406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1392
diff
changeset
|
171 } |
1 | 172 |
4687 | 173 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
|
174 { |
4687 | 175 GtkTreePath *path; |
176 GaimBlistNode *node; | |
177 GValue val = { 0, }; | |
178 GtkTreeIter iter; | |
179 GtkWidget *menu, *menuitem; | |
180 GtkWidget *image; | |
4702 | 181 GtkTreeSelection *sel; |
4687 | 182 GList *list; |
183 struct prpl *prpl; | |
1391
d606da211acb
[gaim-migrate @ 1401]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1376
diff
changeset
|
184 |
4687 | 185 if (event->button != 3) |
186 return FALSE; | |
187 | |
188 /* Here we figure out which node was clicked */ | |
189 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL)) | |
190 return FALSE; | |
191 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
192 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
193 node = g_value_get_pointer(&val); | |
194 | |
195 if (!GAIM_BLIST_NODE_IS_BUDDY(node)) | |
196 return FALSE; | |
197 | |
198 menu = gtk_menu_new(); | |
3251 | 199 |
4687 | 200 /* Protocol specific options */ |
201 prpl = find_prpl(((struct buddy*)node)->account->protocol); | |
202 if (prpl) { | |
203 list = prpl->buddy_menu(((struct buddy*)node)->account->gc, ((struct buddy*)node)->name); | |
204 while (list) { | |
205 struct proto_buddy_menu *pbm = list->data; | |
206 menuitem = gtk_menu_item_new_with_mnemonic(pbm->label); | |
207 g_object_set_data(G_OBJECT(menuitem), "gaimcallback", pbm); | |
208 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gaim_proto_menu_cb), node); | |
209 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
210 list = list->next; | |
3313 | 211 } |
3251 | 212 } |
4687 | 213 |
214 menuitem = gtk_image_menu_item_new_with_mnemonic("_IM"); | |
4697 | 215 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_im_cb), node); |
216 image = gtk_image_new_from_stock(GAIM_STOCK_IM, GTK_ICON_SIZE_MENU); | |
4687 | 217 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); |
218 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
219 | |
220 menuitem = gtk_image_menu_item_new_with_mnemonic("_Alias"); | |
4697 | 221 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_alias_cb), node); |
4687 | 222 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
223 | |
224 menuitem = gtk_image_menu_item_new_with_mnemonic("Add Buddy _Pounce"); | |
4697 | 225 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_bp_cb), node); |
4687 | 226 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
227 | |
228 menuitem = gtk_image_menu_item_new_with_mnemonic("View _Log"); | |
4697 | 229 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_showlog_cb), node); |
4687 | 230 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
1 | 231 |
4687 | 232 gtk_widget_show_all(menu); |
233 | |
234 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time); | |
1 | 235 |
4702 | 236 #if (1) /* This code only exists because GTK doesn't work. If we return FALSE here, as would be normal |
237 * the event propoagates down and somehow gets interpreted as the start of a drag event. */ | |
238 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)); | |
239 gtk_tree_selection_select_path(sel, path); | |
240 return TRUE; | |
241 #endif | |
1 | 242 } |
243 | |
4687 | 244 static void gaim_gtk_blist_reordered_cb(GtkTreeModel *model, |
245 GtkTreePath *path, | |
246 GtkTreeIter *iter, | |
247 gint *neworder, | |
248 gpointer null) | |
3111 | 249 { |
4687 | 250 debug_printf("This doesn't work because GTK is broken\n"); |
1 | 251 |
252 } | |
253 | |
4687 | 254 /* This is called 10 seconds after the buddy logs in. It removes the "logged in" icon and replaces it with |
255 * the normal status icon */ | |
1072
81d19577285a
[gaim-migrate @ 1082]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1070
diff
changeset
|
256 |
4687 | 257 static gboolean gaim_reset_present_icon(GaimBlistNode *b) |
258 { | |
259 ((struct buddy*)b)->present = 1; | |
260 gaim_gtk_blist_update(NULL, b); | |
261 return FALSE; | |
577
aa9a8bcddd80
[gaim-migrate @ 587]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
544
diff
changeset
|
262 } |
aa9a8bcddd80
[gaim-migrate @ 587]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
544
diff
changeset
|
263 |
4687 | 264 static void gaim_gtk_blist_add_buddy_cb() |
935
5e6ca3dd4d02
[gaim-migrate @ 945]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
921
diff
changeset
|
265 { |
4690 | 266 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); |
4687 | 267 GtkTreeIter iter; |
268 GaimBlistNode *node; | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4349
diff
changeset
|
269 |
4692 | 270 if(gtk_tree_selection_get_selected(sel, NULL, &iter)){ |
271 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
4691 | 272 if (GAIM_BLIST_NODE_IS_BUDDY(node)) |
273 show_add_buddy(NULL, NULL, ((struct group*)node->parent)->name, NULL); | |
274 else if (GAIM_BLIST_NODE_IS_GROUP(node)) | |
275 show_add_buddy(NULL, NULL, ((struct group*)node)->name, NULL); | |
276 } | |
4697 | 277 else { |
4692 | 278 show_add_buddy(NULL, NULL, NULL, NULL); |
279 } | |
1 | 280 } |
281 | |
4697 | 282 static void gaim_gtk_blist_update_toolbar_icons (GtkWidget *widget, gpointer data) { |
283 if (GTK_IS_IMAGE(widget)) { | |
284 if (blist_options & OPT_BLIST_SHOW_BUTTON_XPM) | |
285 gtk_widget_show(widget); | |
286 else | |
287 gtk_widget_hide(widget); | |
288 } else if (GTK_IS_CONTAINER(widget)) { | |
289 gtk_container_foreach(GTK_CONTAINER(widget), gaim_gtk_blist_update_toolbar_icons, NULL); | |
290 } | |
291 } | |
1 | 292 |
4702 | 293 static void gaim_gtk_blist_drag_data_get_cb (GtkWidget *widget, |
294 GdkDragContext *dc, | |
295 GtkSelectionData *data, | |
296 guint info, | |
297 guint time, | |
298 gpointer *null) | |
299 { | |
300 if (data->target == gdk_atom_intern("GAIM_BUDDY", FALSE)) { | |
301 GtkTreeRowReference *ref = g_object_get_data(G_OBJECT(dc), "gtk-tree-view-source-row"); | |
302 GtkTreePath *sourcerow = gtk_tree_row_reference_get_path(ref); | |
303 GtkTreeIter iter; | |
304 GaimBlistNode *node = NULL; | |
305 GValue val = {0}; | |
306 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, sourcerow); | |
307 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
308 node = g_value_get_pointer(&val); | |
309 if (GAIM_BLIST_NODE_IS_BUDDY(node)) | |
310 gtk_selection_data_set (data, | |
311 gdk_atom_intern ("GAIM_BUDDY", FALSE), | |
312 8, /* bits */ | |
313 (void*)&node, | |
314 sizeof (node)); | |
315 } | |
316 | |
317 } | |
318 | |
319 static void gaim_gtk_blist_drag_data_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, | |
320 GtkSelectionData *sd, guint info, guint t) | |
321 { | |
322 if (sd->target == gdk_atom_intern("GAIM_BUDDY", FALSE)) { | |
323 struct buddy *b = NULL; | |
324 GtkTreePath *path = NULL; | |
4704 | 325 GtkTreeViewDropPosition position; |
4702 | 326 memcpy(&b, sd->data, sizeof(b)); |
4704 | 327 if(gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), x, y, &path, &position)) { |
328 /* if we're here, I think it means the drop is ok */ | |
329 } | |
4702 | 330 } |
331 } | |
332 | |
4687 | 333 /*************************************************** |
334 * Crap * | |
335 ***************************************************/ | |
336 static GtkItemFactoryEntry blist_menu[] = | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
337 { |
4687 | 338 /* Buddies menu */ |
339 { N_("/_Buddies"), NULL, NULL, 0, "<Branch>" }, | |
340 { N_("/Buddies/_Add A Buddy..."), "<CTL>B", gaim_gtk_blist_add_buddy_cb, 0, | |
341 "<StockItem>", GTK_STOCK_ADD }, | |
342 { N_("/Buddies/New _Instant Message..."), "<CTL>I", show_im_dialog, 0, | |
343 "<StockItem>", GAIM_STOCK_IM }, | |
344 { N_("/Buddies/Join a _Chat..."), "<CTL>C", join_chat, 0, | |
345 "<StockItem>", GAIM_STOCK_CHAT }, | |
346 { N_("/Buddies/sep1"), NULL, NULL, 0, "<Separator>" }, | |
347 { N_("/Buddies/Get _User Info..."), "<CTL>J", show_info_dialog, 0, | |
348 "<StockItem>", GAIM_STOCK_INFO }, | |
349 { N_("/Buddies/sep2"), NULL, NULL, 0, "<Separator>" }, | |
350 { N_("/Buddies/_Signoff"), "<CTL>D", signoff_all, 0, NULL }, | |
351 { N_("/Buddies/_Quit"), "<CTL>Q", do_quit, 0, | |
352 "<StockItem>", GTK_STOCK_QUIT }, | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
353 |
4687 | 354 /* Tools */ |
355 { N_("/_Tools"), NULL, NULL, 0, "<Branch>" }, | |
356 { N_("/Tools/_Away"), NULL, NULL, 0, "<Branch>" }, | |
357 { N_("/Tools/Buddy _Pounce"), NULL, NULL, 0, "<Branch>" }, | |
358 { N_("/Tools/sep1"), NULL, NULL, 0, "<Separator>" }, | |
359 { N_("/Tools/A_ccounts"), "<CTL>A", account_editor, 0, NULL }, | |
4694 | 360 { N_("/Tools/Preferences"), "<CTL>P", show_prefs, 0, |
4687 | 361 "<StockItem>", GTK_STOCK_PREFERENCES }, |
4698 | 362 { N_("/Tools/_File Transfers"), NULL, gaim_show_xfer_dialog, 0, |
4687 | 363 "<StockItem>", GTK_STOCK_REVERT_TO_SAVED }, |
364 { N_("/Tools/sep2"), NULL, NULL, 0, "<Separator>" }, | |
365 { N_("/Tools/P_rotocol Actions"), NULL, NULL, 0, "<Branch>" }, | |
366 { N_("/Tools/Pr_ivacy"), NULL, show_privacy_options, 0, NULL }, | |
4697 | 367 { N_("/Tools/View System _Log"), NULL, gtk_blist_show_systemlog_cb, 0, NULL }, |
3251 | 368 |
4687 | 369 /* Help */ |
370 { N_("/_Help"), NULL, NULL, 0, "<Branch>" }, | |
371 { N_("/Help/Online _Help"), "F1", NULL, 0, | |
372 "<StockItem>", GTK_STOCK_HELP }, | |
4697 | 373 { N_("/Help/_Debug Window"), NULL, show_debug, 0, NULL }, |
4687 | 374 { N_("/Help/_About"), NULL, show_about, 0, NULL }, |
375 | |
376 }; | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
377 |
4687 | 378 /********************************************************* |
379 * Private Utility functions * | |
380 *********************************************************/ | |
381 | |
382 static GdkPixbuf *gaim_gtk_blist_get_status_icon(struct buddy *b) | |
383 { | |
384 GdkPixbuf *status = NULL; | |
385 GdkPixbuf *scale = NULL; | |
386 GdkPixbuf *emblem = NULL; | |
387 gchar *filename = NULL; | |
388 const char *protoname = NULL; | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
389 |
4691 | 390 char *se = NULL, *sw = NULL ,*nw = NULL ,*ne = NULL; |
4687 | 391 |
392 int scalesize = 30; | |
393 | |
394 struct prpl* prpl = find_prpl(b->account->protocol); | |
395 if (prpl->list_icon) | |
396 protoname = prpl->list_icon(b->account, b); | |
397 if (prpl->list_emblems) | |
398 prpl->list_emblems(b, &se, &sw, &nw, &ne); | |
399 | |
400 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) { | |
401 scalesize = 15; | |
402 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
|
403 } |
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
404 |
4701 | 405 |
4687 | 406 if (b->present == 2) { |
4701 | 407 struct gaim_gtk_blist_node *gtknode; |
4687 | 408 /* If b->present is 2, that means this buddy has just signed on. We use the "login" icon for the |
409 * status, and we set a timeout to change it to a normal icon after 10 seconds. */ | |
410 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "login.png", NULL); | |
411 status = gdk_pixbuf_new_from_file(filename,NULL); | |
412 g_free(filename); | |
4701 | 413 |
414 gtknode = GAIM_GTK_BLIST_NODE((GaimBlistNode*)b); | |
415 gtknode->timer = g_timeout_add(10000, (GSourceFunc)gaim_reset_present_icon, b); | |
416 | |
4687 | 417 /* "Hey, what's all this crap?" you ask. Status icons will be themeable too, and |
418 then it will look up protoname from the theme */ | |
419 } else { | |
420 char *image = g_strdup_printf("%s.png", protoname); | |
421 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
422 status = gdk_pixbuf_new_from_file(filename,NULL); | |
423 g_free(image); | |
424 g_free(filename); | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
425 |
4687 | 426 } |
427 | |
428 if (!status) | |
429 return NULL; | |
430 | |
431 scale = gdk_pixbuf_scale_simple(status, scalesize, scalesize, GDK_INTERP_BILINEAR); | |
432 | |
433 /* Emblems */ | |
434 | |
435 /* Each protocol can specify up to four "emblems" to composite over the base icon. "away", "busy", "mobile user" | |
436 * are all examples of states represented by emblems. I'm not even really sure I like this yet. */ | |
437 | |
438 /* XXX Clean this crap up, yo. */ | |
439 if (se) { | |
440 char *image = g_strdup_printf("%s.png", se); | |
441 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
442 g_free(image); | |
443 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
444 g_free(filename); | |
445 if (emblem) { | |
446 if (blist_options & OPT_BLIST_SHOW_ICONS) | |
447 gdk_pixbuf_composite (emblem, | |
448 scale, 15, 15, | |
449 15, 15, | |
450 15, 15, | |
451 1, 1, | |
452 GDK_INTERP_BILINEAR, | |
453 255); | |
454 else | |
455 gdk_pixbuf_composite (emblem, | |
456 scale, 0, 0, | |
457 15, 15, | |
458 0, 0, | |
459 1, 1, | |
460 GDK_INTERP_BILINEAR, | |
461 255); | |
462 } | |
463 } | |
464 if (sw) { | |
465 char *image = g_strdup_printf("%s.png", sw); | |
466 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
467 g_free(image); | |
468 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
469 g_free(filename); | |
470 if (emblem) { | |
471 gdk_pixbuf_composite (emblem, | |
472 scale, 0, 15, | |
473 15, 15, | |
474 0, 15, | |
475 1, 1, | |
476 GDK_INTERP_BILINEAR, | |
477 255); | |
478 } | |
479 } | |
480 if (nw) { | |
481 char *image = g_strdup_printf("%s.png", nw); | |
482 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
483 g_free(image); | |
484 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
485 g_free(filename); | |
486 if (emblem) { | |
487 gdk_pixbuf_composite (emblem, | |
488 scale, 0, 0, | |
489 15, 15, | |
490 0, 0, | |
491 1, 1, | |
492 GDK_INTERP_BILINEAR, | |
493 255); | |
494 } | |
495 } | |
496 if (ne) { | |
497 char *image = g_strdup_printf("%s.png", ne); | |
498 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
499 g_free(image); | |
500 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
501 g_free(filename); | |
502 if (emblem) { | |
503 gdk_pixbuf_composite (emblem, | |
504 scale, 15, 0, | |
505 15, 15, | |
506 15, 0, | |
507 1, 1, | |
508 GDK_INTERP_BILINEAR, | |
509 255); | |
510 } | |
511 } | |
512 | |
513 | |
514 /* Idle gray buddies affects the whole row. This converts the status icon to greyscale. */ | |
4699 | 515 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS) |
4687 | 516 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0, FALSE); |
517 return scale; | |
1 | 518 } |
519 | |
4687 | 520 static GdkPixbuf *gaim_gtk_blist_get_buddy_icon(struct buddy *b) |
1 | 521 { |
4687 | 522 /* This just opens a file from ~/.gaim/icons/screenname. This needs to change to be more gooder. */ |
523 char *file = g_build_filename(gaim_user_dir(), "icons", normalize(b->name), NULL); | |
524 GdkPixbuf *buf = gdk_pixbuf_new_from_file(file, NULL); | |
525 | |
526 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) | |
527 return NULL; | |
528 | |
529 if (buf) { | |
4699 | 530 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS) { |
4687 | 531 gdk_pixbuf_saturate_and_pixelate(buf, buf, 0, FALSE); |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
532 } |
4687 | 533 return gdk_pixbuf_scale_simple(buf,30,30, GDK_INTERP_BILINEAR); |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
534 } |
4687 | 535 return NULL; |
2986 | 536 } |
537 | |
4687 | 538 static gchar *gaim_gtk_blist_get_name_markup(struct buddy *b) |
1 | 539 { |
4687 | 540 char *name = gaim_get_buddy_alias(b); |
541 char *esc = g_markup_escape_text(name, strlen(name)), *text = NULL; | |
542 /* XXX Clean up this crap */ | |
4699 | 543 |
4687 | 544 int ihrs, imin; |
545 char *idletime = ""; | |
546 char *warning = idletime; | |
4699 | 547 time_t t; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
548 |
4687 | 549 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) { |
4699 | 550 if (b->idle > 0 && blist_options & OPT_BLIST_GREY_IDLERS) { |
4687 | 551 text = g_strdup_printf("<span color='gray'>%s</span>", |
4699 | 552 esc); |
4687 | 553 g_free(esc); |
554 return text; | |
555 } else { | |
556 return esc; | |
557 } | |
1 | 558 } |
559 | |
4687 | 560 time(&t); |
561 ihrs = (t - b->idle) / 3600; | |
562 imin = ((t - b->idle) / 60) % 60; | |
4699 | 563 |
4687 | 564 if (b->idle) { |
565 if (ihrs) | |
566 idletime = g_strdup_printf(_("Idle (%dh%02dm)"), ihrs, imin); | |
567 else | |
568 idletime = g_strdup_printf(_("Idle (%dm)"), imin); | |
569 } | |
4699 | 570 |
4687 | 571 if (b->evil > 0) |
572 warning = g_strdup_printf(_("Warned (%d%%)"), b->evil); | |
4699 | 573 |
574 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS) | |
4687 | 575 text = g_strdup_printf("<span color='grey'>%s</span>\n<span color='gray' size='smaller'>%s %s</span>", |
576 esc, | |
577 idletime, warning); | |
578 else | |
4699 | 579 text = g_strdup_printf("%s\n<span color='gray' size='smaller'>%s %s</span>", esc, idletime, warning); |
4687 | 580 |
581 if (idletime[0]) | |
582 g_free(idletime); | |
583 if (warning[0]) | |
584 g_free(warning); | |
4699 | 585 |
4687 | 586 return text; |
587 } | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
588 |
4687 | 589 /********************************************************************************** |
590 * Public API Functions * | |
591 **********************************************************************************/ | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
592 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
|
593 { |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
594 blist->ui_data = g_new0(struct gaim_gtk_buddy_list, 1); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
595 } |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
596 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
597 static void gaim_gtk_blist_new_node(GaimBlistNode *node) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
598 { |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
599 node->ui_data = g_new0(struct gaim_gtk_blist_node, 1); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
600 } |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
601 |
4702 | 602 enum {DRAG_BUDDY, DRAG_ROW}; |
603 | |
4687 | 604 static void gaim_gtk_blist_show(struct gaim_buddy_list *list) |
605 { | |
606 GtkItemFactory *ift; | |
607 GtkCellRenderer *rend; | |
608 GtkTreeViewColumn *column; | |
609 GtkWidget *sw; | |
610 GtkWidget *button; | |
4694 | 611 GtkSizeGroup *sg; |
4702 | 612 GtkTargetEntry gte[] = {{"GAIM_BUDDY", GTK_TARGET_SAME_APP, DRAG_ROW}, |
613 {"application/x-im-contact", 0, DRAG_BUDDY}}; | |
4690 | 614 |
4687 | 615 if (gtkblist) { |
616 gtk_widget_show(gtkblist->window); | |
617 return; | |
618 } | |
4690 | 619 |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
620 gtkblist = GAIM_GTK_BLIST(list); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
621 |
4687 | 622 gtkblist->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
623 gtk_window_set_title(GTK_WINDOW(gtkblist->window), _("Buddy List")); | |
4690 | 624 |
4687 | 625 gtkblist->vbox = gtk_vbox_new(FALSE, 6); |
626 gtk_container_add(GTK_CONTAINER(gtkblist->window), gtkblist->vbox); | |
1 | 627 |
4698 | 628 g_signal_connect(G_OBJECT(gtkblist->window), "delete_event", G_CALLBACK(gaim_gtk_blist_destroy_cb), NULL); |
629 | |
4687 | 630 /******************************* Menu bar *************************************/ |
631 ift = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GaimMain>", NULL); | |
632 gtk_item_factory_create_items(ift, sizeof(blist_menu) / sizeof(*blist_menu), | |
633 blist_menu, NULL); | |
634 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtk_item_factory_get_widget(ift, "<GaimMain>"), FALSE, FALSE, 0); | |
1 | 635 |
4694 | 636 awaymenu = gtk_item_factory_get_widget(ift, "/Tools/Away"); |
637 do_away_menu(); | |
638 | |
4696 | 639 bpmenu = gtk_item_factory_get_widget(ift, "/Tools/Buddy Pounce"); |
640 do_bp_menu(); | |
641 | |
642 protomenu = gtk_item_factory_get_widget(ift, "/Tools/Protocol Actions"); | |
643 do_proto_menu(); | |
644 | |
4687 | 645 /****************************** GtkTreeView **********************************/ |
646 sw = gtk_scrolled_window_new(NULL,NULL); | |
647 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); | |
648 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
4690 | 649 gtk_widget_set_size_request(sw, 200, 200); |
4687 | 650 |
651 gtkblist->treemodel = gtk_tree_store_new(BLIST_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, | |
652 G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_POINTER); | |
4702 | 653 |
4687 | 654 gtkblist->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(gtkblist->treemodel)); |
4704 | 655 |
4702 | 656 /* Set up dnd */ |
657 gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(gtkblist->treeview), GDK_BUTTON1_MASK, gte, | |
658 2, GDK_ACTION_COPY); | |
4704 | 659 gtk_tree_view_enable_model_drag_dest(GTK_TREE_VIEW(gtkblist->treeview), gte, 2, |
4702 | 660 GDK_ACTION_COPY | GDK_ACTION_MOVE); |
4704 | 661 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-received", G_CALLBACK(gaim_gtk_blist_drag_data_rcv_cb), NULL); |
662 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-get", G_CALLBACK(gaim_gtk_blist_drag_data_get_cb), NULL); | |
663 | |
4687 | 664 |
665 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(gtkblist->treeview), FALSE); | |
1 | 666 |
4687 | 667 rend = gtk_cell_renderer_pixbuf_new(); |
668 column = gtk_tree_view_column_new_with_attributes("Status", rend, "pixbuf", STATUS_ICON_COLUMN, NULL); | |
669 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); | |
4706 | 670 g_object_set(rend, "ypad", 0.0, NULL); |
671 | |
4687 | 672 rend = gtk_cell_renderer_text_new(); |
673 column = gtk_tree_view_column_new_with_attributes("Name", rend, "markup", NAME_COLUMN, NULL); | |
674 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); | |
4706 | 675 g_object_set(rend, "ypad", 0.0, NULL); |
676 | |
4687 | 677 rend = gtk_cell_renderer_text_new(); |
678 column = gtk_tree_view_column_new_with_attributes("Warning", rend, "text", WARNING_COLUMN, NULL); | |
679 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); | |
4706 | 680 g_object_set(rend, "ypad", 0.0, NULL); |
4687 | 681 |
682 rend = gtk_cell_renderer_text_new(); | |
683 column = gtk_tree_view_column_new_with_attributes("Idle", rend, "text", IDLE_COLUMN, NULL); | |
684 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); | |
4706 | 685 g_object_set(rend, "ypad", 0.0, NULL); |
1 | 686 |
4687 | 687 rend = gtk_cell_renderer_pixbuf_new(); |
688 column = gtk_tree_view_column_new_with_attributes("Buddy Icon", rend, "pixbuf", BUDDY_ICON_COLUMN, NULL); | |
4706 | 689 g_object_set(rend, "xalign", 1.0, "ypad", 0.0, NULL); |
4687 | 690 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); |
691 | |
692 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-activated", G_CALLBACK(gtk_blist_row_activated_cb), NULL); | |
693 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
|
694 |
4687 | 695 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), sw, TRUE, TRUE, 0); |
696 gtk_container_add(GTK_CONTAINER(sw), gtkblist->treeview); | |
697 | |
698 /**************************** Button Box **************************************/ | |
4694 | 699 |
700 sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); | |
4687 | 701 gtkblist->bbox = gtk_hbox_new(TRUE, 0); |
702 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtkblist->bbox, FALSE, FALSE, 0); | |
703 button = gaim_pixbuf_button_from_stock(_("IM"), GAIM_STOCK_IM, GAIM_BUTTON_VERTICAL); | |
704 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
705 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 706 gtk_size_group_add_widget(sg, button); |
4692 | 707 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_im_cb), |
4697 | 708 gtkblist->treeview); |
709 | |
4687 | 710 button = gaim_pixbuf_button_from_stock(_("Get Info"), GAIM_STOCK_INFO, GAIM_BUTTON_VERTICAL); |
711 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
712 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 713 gtk_size_group_add_widget(sg, button); |
714 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_info_cb), | |
4697 | 715 gtkblist->treeview); |
716 | |
4687 | 717 button = gaim_pixbuf_button_from_stock(_("Chat"), GAIM_STOCK_CHAT, GAIM_BUTTON_VERTICAL); |
718 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
719 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 720 gtk_size_group_add_widget(sg, button); |
721 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_chat_cb), NULL); | |
722 | |
4687 | 723 button = gaim_pixbuf_button_from_stock(_("Away"), GAIM_STOCK_AWAY, GAIM_BUTTON_VERTICAL); |
724 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
725 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 726 gtk_size_group_add_widget(sg, button); |
727 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_away_cb), NULL); | |
4687 | 728 |
729 /* OK... let's show this bad boy. */ | |
730 gaim_gtk_blist_refresh(list); | |
731 gtk_widget_show_all(gtkblist->window); | |
4697 | 732 |
733 gaim_gtk_blist_update_toolbar(); | |
734 | |
4687 | 735 } |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
736 |
4687 | 737 void gaim_gtk_blist_refresh(struct gaim_buddy_list *list) |
738 { | |
739 GaimBlistNode *group = list->root; | |
740 GaimBlistNode *buddy; | |
4690 | 741 |
4687 | 742 while (group) { |
743 gaim_gtk_blist_update(list, group); | |
744 buddy = group->child; | |
745 while (buddy) { | |
4699 | 746 gaim_gtk_blist_update(list, buddy); |
4687 | 747 buddy = buddy->next; |
748 } | |
749 group = group->next; | |
750 } | |
751 } | |
1 | 752 |
4699 | 753 static gboolean get_iter_from_node_helper(GaimBlistNode *node, GtkTreeIter *iter, GtkTreeIter *root) { |
754 do { | |
755 GaimBlistNode *n; | |
756 GtkTreeIter child; | |
757 | |
758 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), root, NODE_COLUMN, &n, -1); | |
759 if(n == node) { | |
760 *iter = *root; | |
761 return TRUE; | |
762 } | |
763 | |
764 if(gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &child, root)) { | |
765 if(get_iter_from_node_helper(node,iter,&child)) | |
766 return TRUE; | |
767 } | |
768 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(gtkblist->treemodel), root)); | |
769 | |
770 return FALSE; | |
771 } | |
772 | |
773 static gboolean get_iter_from_node(GaimBlistNode *node, GtkTreeIter *iter) { | |
774 GtkTreeIter root; | |
775 | |
776 if (!gtkblist) | |
777 return FALSE; | |
778 | |
779 if(!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(gtkblist->treemodel), &root)) | |
780 return FALSE; | |
781 | |
782 return get_iter_from_node_helper(node, iter, &root); | |
783 } | |
784 | |
4697 | 785 void gaim_gtk_blist_update_toolbar() { |
786 if (!gtkblist) | |
787 return; | |
4699 | 788 |
4697 | 789 gtk_container_foreach(GTK_CONTAINER(gtkblist->bbox), gaim_gtk_blist_update_toolbar_icons, NULL); |
4699 | 790 |
4697 | 791 if (blist_options & OPT_BLIST_NO_BUTTONS) |
792 gtk_widget_hide(gtkblist->bbox); | |
793 else | |
794 gtk_widget_show_all(gtkblist->bbox); | |
795 } | |
796 | |
4701 | 797 static void gaim_gtk_blist_remove(struct gaim_buddy_list *list, GaimBlistNode *node) |
798 { | |
799 struct gaim_gtk_blist_node *gtknode; | |
800 GtkTreeIter iter; | |
801 | |
802 if (!node->ui_data) | |
803 return; | |
804 | |
805 gtknode = (struct gaim_gtk_blist_node *)node->ui_data; | |
806 | |
807 if (gtknode->timer > 0) { | |
808 g_source_remove(gtknode->timer); | |
809 gtknode->timer = 0; | |
810 } | |
811 | |
812 if (get_iter_from_node(node, &iter)) { | |
813 gtk_tree_store_remove(gtkblist->treemodel, &iter); | |
814 if(GAIM_BLIST_NODE_IS_BUDDY(node) && gaim_blist_get_group_online_count((struct group *)node->parent) == 0) { | |
815 GtkTreeIter groupiter; | |
816 if(get_iter_from_node(node->parent, &groupiter)) | |
817 gtk_tree_store_remove(gtkblist->treemodel, &groupiter); | |
818 } | |
819 } | |
820 } | |
821 | |
822 | |
4687 | 823 static void gaim_gtk_blist_update(struct gaim_buddy_list *list, GaimBlistNode *node) |
824 { | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
825 struct gaim_gtk_blist_node *gtknode; |
4699 | 826 GtkTreeIter iter; |
4687 | 827 gboolean expand = FALSE; |
4699 | 828 gboolean new_entry = FALSE; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
829 |
4687 | 830 if (!gtkblist) |
831 return; | |
4699 | 832 |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
833 gtknode = GAIM_GTK_BLIST_NODE(node); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
834 |
4690 | 835 |
4699 | 836 if (!get_iter_from_node(node, &iter)) { /* This is a newly added node */ |
837 new_entry = TRUE; | |
4687 | 838 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { |
839 if (((struct buddy*)node)->present) { | |
4699 | 840 GtkTreeIter groupiter; |
841 GaimBlistNode *oldersibling; | |
842 GtkTreeIter oldersiblingiter; | |
4690 | 843 |
4699 | 844 if(node->parent && !get_iter_from_node(node->parent, &groupiter)) { |
845 /* This buddy's group has not yet been added. We do that here */ | |
4687 | 846 char *mark = g_strdup_printf("<span weight='bold'>%s</span>", ((struct group*)node->parent)->name); |
4699 | 847 oldersibling = node->parent->prev; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
848 |
4687 | 849 /* We traverse backwards through the buddy list to find the node in the tree to insert it after */ |
4699 | 850 while (oldersibling && !get_iter_from_node(oldersibling, &oldersiblingiter)) |
851 oldersibling = oldersibling->prev; | |
4690 | 852 |
4687 | 853 /* This is where we create the node and add it. */ |
4699 | 854 gtk_tree_store_insert_after(gtkblist->treemodel, &groupiter, NULL, oldersibling ? &oldersiblingiter : NULL); |
855 gtk_tree_store_set(gtkblist->treemodel, &groupiter, | |
4687 | 856 STATUS_ICON_COLUMN, gtk_widget_render_icon |
4691 | 857 (gtkblist->treeview,GTK_STOCK_OPEN,GTK_ICON_SIZE_SMALL_TOOLBAR,NULL), |
4687 | 858 NAME_COLUMN, mark, |
859 NODE_COLUMN, node->parent, | |
860 -1); | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
861 |
4687 | 862 expand = TRUE; |
863 } | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
864 |
4699 | 865 oldersibling = node->prev; |
866 while (oldersibling && !get_iter_from_node(oldersibling, &oldersiblingiter)) | |
867 oldersibling = oldersibling->prev; | |
868 | |
869 gtk_tree_store_insert_after(gtkblist->treemodel, &iter, &groupiter, oldersibling ? &oldersiblingiter : NULL); | |
870 | |
4687 | 871 if (expand) { /* expand was set to true if this is the first element added to a group. In such case |
872 * we expand the group node */ | |
4699 | 873 GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &groupiter); |
874 gtk_tree_view_expand_row(GTK_TREE_VIEW(gtkblist->treeview), path, TRUE); | |
4687 | 875 } |
4699 | 876 } |
877 } | |
878 } | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
879 |
4687 | 880 if (GAIM_BLIST_NODE_IS_BUDDY(node) && ((struct buddy*)node)->present) { |
881 GdkPixbuf *status, *avatar; | |
882 char *mark; | |
4697 | 883 char *warning = NULL, *idle = NULL; |
884 | |
4687 | 885 status = gaim_gtk_blist_get_status_icon((struct buddy*)node); |
886 avatar = gaim_gtk_blist_get_buddy_icon((struct buddy*)node); | |
887 mark = gaim_gtk_blist_get_name_markup((struct buddy*)node); | |
4697 | 888 |
4699 | 889 if ((((struct buddy*)node)->idle > 0) && |
4697 | 890 (!(blist_options & OPT_BLIST_SHOW_ICONS) && (blist_options & OPT_BLIST_SHOW_IDLETIME))) { |
891 time_t t; | |
892 int ihrs, imin; | |
893 time(&t); | |
894 ihrs = (t - ((struct buddy *)node)->idle) / 3600; | |
895 imin = ((t - ((struct buddy*)node)->idle) / 60) % 60; | |
4699 | 896 idle = g_strdup_printf("%d:%02d", ihrs, imin); |
4697 | 897 } |
898 | |
4699 | 899 if ((((struct buddy*)node)->evil > 0) && |
4697 | 900 (!(blist_options & OPT_BLIST_SHOW_ICONS) && (blist_options & OPT_BLIST_SHOW_WARN))) { |
4699 | 901 warning = g_strdup_printf("%d%%", ((struct buddy*)node)->evil); |
4697 | 902 } |
903 | |
4699 | 904 gtk_tree_store_set(gtkblist->treemodel, &iter, |
4687 | 905 STATUS_ICON_COLUMN, status, |
906 NAME_COLUMN, mark, | |
4697 | 907 WARNING_COLUMN, warning, |
908 IDLE_COLUMN, idle, | |
4699 | 909 BUDDY_ICON_COLUMN, avatar, |
4687 | 910 NODE_COLUMN, node, |
911 -1); | |
4699 | 912 |
4687 | 913 g_free(mark); |
4697 | 914 if (idle) |
915 g_free(idle); | |
916 if (warning) | |
917 g_free(warning); | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
918 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
919 if (status != NULL) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
920 g_object_unref(status); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
921 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
922 if (avatar != NULL) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
923 g_object_unref(avatar); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
924 |
4701 | 925 } else if (GAIM_BLIST_NODE_IS_BUDDY(node) && !new_entry) { |
926 gaim_gtk_blist_remove(list, node); | |
4687 | 927 } |
928 } | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
929 |
4687 | 930 static void gaim_gtk_blist_destroy(struct gaim_buddy_list *list) |
931 { | |
932 gtk_widget_destroy(gtkblist->window); | |
933 } | |
1 | 934 |
4687 | 935 static void gaim_gtk_blist_set_visible(struct gaim_buddy_list *list, gboolean show) |
936 { | |
4698 | 937 if (show) { |
4699 | 938 gtk_window_present(GTK_WINDOW(gtkblist->window)); |
4698 | 939 } else { |
940 if (!connections || docklet_count) { | |
941 #ifdef _WIN32 | |
4711
0c1f3e651d3e
[gaim-migrate @ 5022]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4706
diff
changeset
|
942 wgaim_systray_minimize(gtkblist->window); |
4698 | 943 #endif |
944 gtk_widget_hide(gtkblist->window); | |
945 } else { | |
946 gtk_window_iconify(GTK_WINDOW(gtkblist->window)); | |
947 } | |
948 } | |
949 } | |
950 | |
951 void gaim_gtk_blist_docklet_toggle() { | |
952 /* Useful for the docklet plugin and also for the win32 tray icon*/ | |
953 /* This is called when one of those is clicked--it will show/hide the | |
954 buddy list/login window--depending on which is active */ | |
955 if (connections && gtkblist) { | |
956 if (GTK_WIDGET_VISIBLE(gtkblist->window)) { | |
957 gaim_blist_set_visible(GAIM_WINDOW_ICONIFIED(gtkblist->window) || gaim_gtk_blist_obscured); | |
958 } else { | |
959 #if _WIN32 | |
4711
0c1f3e651d3e
[gaim-migrate @ 5022]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4706
diff
changeset
|
960 wgaim_systray_maximize(gtkblist->window); |
4698 | 961 #endif |
962 gaim_blist_set_visible(TRUE); | |
963 } | |
964 } else if (connections) { | |
965 /* we're logging in or something... do nothing */ | |
966 debug_printf("docklet_toggle called with connections but no blist!\n"); | |
967 } else { | |
968 if (GTK_WIDGET_VISIBLE(mainwindow)) { | |
969 if (GAIM_WINDOW_ICONIFIED(mainwindow)) { | |
970 gtk_window_present(GTK_WINDOW(mainwindow)); | |
971 } else { | |
972 #if _WIN32 | |
973 wgaim_systray_minimize(mainwindow); | |
974 #endif | |
975 gtk_widget_hide(mainwindow); | |
976 } | |
977 } else { | |
978 #if _WIN32 | |
979 wgaim_systray_maximize(mainwindow); | |
980 #endif | |
981 gtk_window_present(GTK_WINDOW(mainwindow)); | |
982 } | |
983 } | |
984 } | |
985 | |
986 void gaim_gtk_blist_docklet_add() | |
987 { | |
988 docklet_count++; | |
989 } | |
990 | |
991 void gaim_gtk_blist_docklet_remove() | |
992 { | |
993 docklet_count--; | |
994 if (!docklet_count) { | |
995 if (connections) { | |
996 gaim_blist_set_visible(TRUE); | |
997 } else { | |
998 gtk_window_present(GTK_WINDOW(gtkblist->window)); | |
999 } | |
1000 } | |
4687 | 1001 } |
1 | 1002 |
4687 | 1003 static struct gaim_blist_ui_ops blist_ui_ops = |
1004 { | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1005 gaim_gtk_blist_new_list, |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1006 gaim_gtk_blist_new_node, |
4687 | 1007 gaim_gtk_blist_show, |
1008 gaim_gtk_blist_update, | |
1009 gaim_gtk_blist_remove, | |
1010 gaim_gtk_blist_destroy, | |
1011 gaim_gtk_blist_set_visible | |
1012 }; | |
1 | 1013 |
1014 | |
4687 | 1015 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
|
1016 { |
4687 | 1017 return &blist_ui_ops; |
1037
1c663beef29d
[gaim-migrate @ 1047]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1036
diff
changeset
|
1018 } |
1c663beef29d
[gaim-migrate @ 1047]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1036
diff
changeset
|
1019 |
3131 | 1020 |
1021 | |
4687 | 1022 /********************************************************************* |
1023 * Public utility functions * | |
1024 *********************************************************************/ | |
1058
4927ce25d8cc
[gaim-migrate @ 1068]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1025 |
4687 | 1026 GdkPixbuf * |
1027 create_prpl_icon(struct gaim_account *account) | |
4553
d03fcb3f4be2
[gaim-migrate @ 4833]
Christian Hammond <chipx86@chipx86.com>
parents:
4525
diff
changeset
|
1028 { |
4687 | 1029 struct prpl *prpl = find_prpl(account->protocol); |
1030 GdkPixbuf *status = NULL; | |
1031 char *filename = NULL; | |
1032 const char *protoname = prpl->list_icon(account, NULL); | |
1033 /* "Hey, what's all this crap?" you ask. Status icons will be themeable too, and | |
1034 then it will look up protoname from the theme */ | |
1035 if (!strcmp(protoname, "aim")) { | |
1036 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "aim.png", NULL); | |
1037 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1038 g_free(filename); | |
1039 } else if (!strcmp(protoname, "yahoo")) { | |
1040 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "yahoo.png", NULL); | |
1041 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1042 g_free(filename); | |
1043 } else if (!strcmp(protoname, "msn")) { | |
1044 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "msn.png", NULL); | |
1045 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1046 g_free(filename); | |
1047 } else if (!strcmp(protoname, "jabber")) { | |
1048 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "jabber.png", NULL); | |
1049 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1050 g_free(filename); | |
1051 } else if (!strcmp(protoname, "icq")) { | |
1052 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "icq.png", NULL); | |
1053 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1054 g_free(filename); | |
1055 } else if (!strcmp(protoname, "gadu-gadu")) { | |
1056 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "gadugadu.png", NULL); | |
1057 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1058 g_free(filename); | |
1059 } else if (!strcmp(protoname, "napster")) { | |
1060 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "napster.png", NULL); | |
1061 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1062 g_free(filename); | |
1063 } else if (!strcmp(protoname, "irc")) { | |
1064 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "irc.png", NULL); | |
1065 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1066 g_free(filename); | |
960
fa681641643d
[gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
945
diff
changeset
|
1067 } |
4687 | 1068 return status; |
1 | 1069 } |
4699 | 1070 |