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