annotate src/buddyicon.c @ 13811:e0e8959d92a0

[gaim-migrate @ 16241] autotools continues to confuse me committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sat, 10 Jun 2006 18:09:57 +0000
parents 52985bb3ec70
children d1da27a099d2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1 /**
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
2 * @file icon.c Buddy Icon API
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
3 * @ingroup core
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
4 *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
5 * gaim
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
6 *
8046
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 7721
diff changeset
7 * Gaim is the legal property of its developers, whose names are too numerous
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 7721
diff changeset
8 * to list here. Please refer to the COPYRIGHT file distributed with this
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 7721
diff changeset
9 * source distribution.
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
10 *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
14 * (at your option) any later version.
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
15 *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
19 * GNU General Public License for more details.
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
20 *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
24 */
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
25 #include "internal.h"
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
26 #include "buddyicon.h"
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
27 #include "conversation.h"
13554
52985bb3ec70 [gaim-migrate @ 15932]
Richard Laager <rlaager@wiktel.com>
parents: 12996
diff changeset
28 #include "dbus-maybe.h"
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
29 #include "debug.h"
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
30 #include "util.h"
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
31
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
32 static GHashTable *account_cache = NULL;
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
33 static char *cache_dir = NULL;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
34 static gboolean icon_caching = TRUE;
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
35
9396
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
36 static GaimBuddyIcon *
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
37 gaim_buddy_icon_create(GaimAccount *account, const char *username)
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
38 {
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
39 GaimBuddyIcon *icon;
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
40 GHashTable *icon_cache;
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
41
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
42 icon = g_new0(GaimBuddyIcon, 1);
13554
52985bb3ec70 [gaim-migrate @ 15932]
Richard Laager <rlaager@wiktel.com>
parents: 12996
diff changeset
43 GAIM_DBUS_REGISTER_POINTER(icon, GaimBuddyIcon);
9396
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
44
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
45 gaim_buddy_icon_set_account(icon, account);
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
46 gaim_buddy_icon_set_username(icon, username);
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
47
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
48 icon_cache = g_hash_table_lookup(account_cache, account);
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
49
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
50 if (icon_cache == NULL)
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
51 {
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
52 icon_cache = g_hash_table_new(g_str_hash, g_str_equal);
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
53
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
54 g_hash_table_insert(account_cache, account, icon_cache);
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
55 }
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
56
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
57 g_hash_table_insert(icon_cache,
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
58 (char *)gaim_buddy_icon_get_username(icon), icon);
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
59 return icon;
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
60 }
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
61
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
62 GaimBuddyIcon *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
63 gaim_buddy_icon_new(GaimAccount *account, const char *username,
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
64 void *icon_data, size_t icon_len)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
65 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
66 GaimBuddyIcon *icon;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
67
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
68 g_return_val_if_fail(account != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
69 g_return_val_if_fail(username != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
70 g_return_val_if_fail(icon_data != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
71 g_return_val_if_fail(icon_len > 0, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
72
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
73 icon = gaim_buddy_icons_find(account, username);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
74
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
75 if (icon == NULL)
9396
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
76 icon = gaim_buddy_icon_create(account, username);
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
77
9327
ef8e4740254d [gaim-migrate @ 10135]
Tim Ringenbach <marv@pidgin.im>
parents: 9323
diff changeset
78 gaim_buddy_icon_ref(icon);
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
79 gaim_buddy_icon_set_data(icon, icon_data, icon_len);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
80
11423
202a3b3c5a88 [gaim-migrate @ 13660]
Richard Laager <rlaager@wiktel.com>
parents: 11338
diff changeset
81 /* gaim_buddy_icon_set_data() makes blist.c or
202a3b3c5a88 [gaim-migrate @ 13660]
Richard Laager <rlaager@wiktel.com>
parents: 11338
diff changeset
82 * conversation.c, or both, take a reference.
202a3b3c5a88 [gaim-migrate @ 13660]
Richard Laager <rlaager@wiktel.com>
parents: 11338
diff changeset
83 *
202a3b3c5a88 [gaim-migrate @ 13660]
Richard Laager <rlaager@wiktel.com>
parents: 11338
diff changeset
84 * Plus, we leave one for the caller of this function.
9323
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
85 */
11423
202a3b3c5a88 [gaim-migrate @ 13660]
Richard Laager <rlaager@wiktel.com>
parents: 11338
diff changeset
86
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
87 return icon;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
88 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
89
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
90 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
91 gaim_buddy_icon_destroy(GaimBuddyIcon *icon)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
92 {
7311
1c8830db0189 [gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents: 7125
diff changeset
93 GaimConversation *conv;
1c8830db0189 [gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents: 7125
diff changeset
94 GaimAccount *account;
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
95 GHashTable *icon_cache;
7311
1c8830db0189 [gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents: 7125
diff changeset
96 const char *username;
9305
0c201a2386c7 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
97 GSList *sl, *list;
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
98
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
99 g_return_if_fail(icon != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
100
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
101 if (icon->ref_count > 0)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
102 {
9323
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
103 /* If the ref count is greater than 0, then we weren't called from
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
104 * gaim_buddy_icon_unref(). So we go through and ask everyone to
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
105 * unref us. Then we return, since we know somewhere along the
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
106 * line we got called recursively by one of the unrefs, and the
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
107 * icon is already destroyed.
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
108 */
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
109 account = gaim_buddy_icon_get_account(icon);
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
110 username = gaim_buddy_icon_get_username(icon);
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
111
11338
17142948653e [gaim-migrate @ 13551]
Mark Doliner <mark@kingant.net>
parents: 11303
diff changeset
112 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, username, account);
10246
a66cf83552dc [gaim-migrate @ 11386]
Mark Doliner <mark@kingant.net>
parents: 9801
diff changeset
113 if (conv != NULL)
9323
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
114 gaim_conv_im_set_icon(GAIM_CONV_IM(conv), NULL);
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
115
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
116 for (list = sl = gaim_find_buddies(account, username); sl != NULL;
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
117 sl = sl->next)
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
118 {
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
119 GaimBuddy *buddy = (GaimBuddy *)sl->data;
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
120
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
121 gaim_buddy_set_icon(buddy, NULL);
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
122 }
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
123
59bca4e8678c [gaim-migrate @ 10131]
Tim Ringenbach <marv@pidgin.im>
parents: 9305
diff changeset
124 g_slist_free(list);
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
125
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
126 return;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
127 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
128
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
129 icon_cache = g_hash_table_lookup(account_cache,
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
130 gaim_buddy_icon_get_account(icon));
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
131
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
132 if (icon_cache != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
133 g_hash_table_remove(icon_cache, gaim_buddy_icon_get_username(icon));
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
134
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
135 if (icon->username != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
136 g_free(icon->username);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
137
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
138 if (icon->data != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
139 g_free(icon->data);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
140
13554
52985bb3ec70 [gaim-migrate @ 15932]
Richard Laager <rlaager@wiktel.com>
parents: 12996
diff changeset
141 GAIM_DBUS_UNREGISTER_POINTER(icon);
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
142 g_free(icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
143 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
144
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
145 GaimBuddyIcon *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
146 gaim_buddy_icon_ref(GaimBuddyIcon *icon)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
147 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
148 g_return_val_if_fail(icon != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
149
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
150 icon->ref_count++;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
151
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
152 return icon;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
153 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
154
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
155 GaimBuddyIcon *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
156 gaim_buddy_icon_unref(GaimBuddyIcon *icon)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
157 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
158 g_return_val_if_fail(icon != NULL, NULL);
12250
5e2a365af01b [gaim-migrate @ 14552]
Richard Laager <rlaager@wiktel.com>
parents: 12097
diff changeset
159 g_return_val_if_fail(icon->ref_count > 0, NULL);
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
160
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
161 icon->ref_count--;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
162
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
163 if (icon->ref_count == 0)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
164 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
165 gaim_buddy_icon_destroy(icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
166
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
167 return NULL;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
168 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
169
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
170 return icon;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
171 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
172
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
173 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
174 gaim_buddy_icon_update(GaimBuddyIcon *icon)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
175 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
176 GaimConversation *conv;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
177 GaimAccount *account;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
178 const char *username;
8550
52dca2f38956 [gaim-migrate @ 9292]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
179 GSList *sl, *list;
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
180
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
181 g_return_if_fail(icon != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
182
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
183 account = gaim_buddy_icon_get_account(icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
184 username = gaim_buddy_icon_get_username(icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
185
9305
0c201a2386c7 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
186 for (list = sl = gaim_find_buddies(account, username); sl != NULL;
0c201a2386c7 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
187 sl = sl->next)
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
188 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
189 GaimBuddy *buddy = (GaimBuddy *)sl->data;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
190
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
191 gaim_buddy_set_icon(buddy, icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
192 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
193
8550
52dca2f38956 [gaim-migrate @ 9292]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
194 g_slist_free(list);
52dca2f38956 [gaim-migrate @ 9292]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
195
11338
17142948653e [gaim-migrate @ 13551]
Mark Doliner <mark@kingant.net>
parents: 11303
diff changeset
196 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, username, account);
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
197
10246
a66cf83552dc [gaim-migrate @ 11386]
Mark Doliner <mark@kingant.net>
parents: 9801
diff changeset
198 if (conv != NULL)
7118
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 6886
diff changeset
199 gaim_conv_im_set_icon(GAIM_CONV_IM(conv), icon);
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
200 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
201
11040
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
202 static void
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
203 delete_icon_cache_file(const char *dirname, const char *old_icon)
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
204 {
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
205 struct stat st;
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
206
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
207 g_return_if_fail(dirname != NULL);
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
208 g_return_if_fail(old_icon != NULL);
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
209
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
210 if (g_stat(old_icon, &st) == 0)
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
211 g_unlink(old_icon);
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
212 else
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
213 {
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
214 char *filename = g_build_filename(dirname, old_icon, NULL);
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
215 if (g_stat(filename, &st) == 0)
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
216 g_unlink(filename);
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
217 g_free(filename);
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
218 }
12996
fbdc9e7ef77a [gaim-migrate @ 15349]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12995
diff changeset
219 gaim_debug_info("buddyicon", "Uncached file %s\n", old_icon);
11040
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
220 }
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
221
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
222 void
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
223 gaim_buddy_icon_cache(GaimBuddyIcon *icon, GaimBuddy *buddy)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
224 {
11137
096020ae09a9 [gaim-migrate @ 13201]
Mark Doliner <mark@kingant.net>
parents: 11040
diff changeset
225 const guchar *data;
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
226 const char *dirname;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
227 char *random;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
228 char *filename;
7125
208cb260d7a7 [gaim-migrate @ 7692]
Nathan Walp <nwalp@pidgin.im>
parents: 7118
diff changeset
229 const char *old_icon;
12995
595f690399e4 [gaim-migrate @ 15348]
Richard Laager <rlaager@wiktel.com>
parents: 12250
diff changeset
230 size_t len = 0;
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
231 FILE *file = NULL;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
232
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
233 g_return_if_fail(icon != NULL);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
234 g_return_if_fail(buddy != NULL);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
235
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
236 if (!gaim_buddy_icons_is_caching())
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
237 return;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
238
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
239 data = gaim_buddy_icon_get_data(icon, &len);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
240
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
241 random = g_strdup_printf("%x", g_random_int());
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
242 dirname = gaim_buddy_icons_get_cache_dir();
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
243 filename = g_build_filename(dirname, random, NULL);
7721
20d0c025312a [gaim-migrate @ 8366]
Nathan Walp <nwalp@pidgin.im>
parents: 7311
diff changeset
244 old_icon = gaim_blist_node_get_string((GaimBlistNode*)buddy, "buddy_icon");
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
245
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
246 if (!g_file_test(dirname, G_FILE_TEST_IS_DIR))
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
247 {
12996
fbdc9e7ef77a [gaim-migrate @ 15349]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12995
diff changeset
248 gaim_debug_info("buddyicon", "Creating icon cache directory.\n");
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
249
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10523
diff changeset
250 if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0)
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
251 {
12996
fbdc9e7ef77a [gaim-migrate @ 15349]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12995
diff changeset
252 gaim_debug_error("buddyicon",
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
253 "Unable to create directory %s: %s\n",
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
254 dirname, strerror(errno));
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
255 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
256 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
257
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10523
diff changeset
258 if ((file = g_fopen(filename, "wb")) != NULL)
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
259 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
260 fwrite(data, 1, len, file);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
261 fclose(file);
12996
fbdc9e7ef77a [gaim-migrate @ 15349]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12995
diff changeset
262 gaim_debug_info("buddyicon", "Wrote file %s\n", filename);
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
263 }
11021
dd5c802baf7b [gaim-migrate @ 12892]
Mark Doliner <mark@kingant.net>
parents: 10953
diff changeset
264 else
dd5c802baf7b [gaim-migrate @ 12892]
Mark Doliner <mark@kingant.net>
parents: 10953
diff changeset
265 {
12996
fbdc9e7ef77a [gaim-migrate @ 15349]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12995
diff changeset
266 gaim_debug_error("buddyicon", "Unable to create file %s: %s\n",
11021
dd5c802baf7b [gaim-migrate @ 12892]
Mark Doliner <mark@kingant.net>
parents: 10953
diff changeset
267 filename, strerror(errno));
dd5c802baf7b [gaim-migrate @ 12892]
Mark Doliner <mark@kingant.net>
parents: 10953
diff changeset
268 }
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
269
9747
e0060f3b6d92 [gaim-migrate @ 10613]
Luke Schierer <lschiere@pidgin.im>
parents: 9396
diff changeset
270 g_free(filename);
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
271
9747
e0060f3b6d92 [gaim-migrate @ 10613]
Luke Schierer <lschiere@pidgin.im>
parents: 9396
diff changeset
272 if (old_icon != NULL)
11040
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
273 delete_icon_cache_file(dirname, old_icon);
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
274
9747
e0060f3b6d92 [gaim-migrate @ 10613]
Luke Schierer <lschiere@pidgin.im>
parents: 9396
diff changeset
275 gaim_blist_node_set_string((GaimBlistNode *)buddy, "buddy_icon", random);
e0060f3b6d92 [gaim-migrate @ 10613]
Luke Schierer <lschiere@pidgin.im>
parents: 9396
diff changeset
276
e0060f3b6d92 [gaim-migrate @ 10613]
Luke Schierer <lschiere@pidgin.im>
parents: 9396
diff changeset
277 g_free(random);
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
278 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
279
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
280 void
11040
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
281 gaim_buddy_icon_uncache(GaimBuddy *buddy)
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
282 {
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
283 const char *old_icon;
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
284
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
285 g_return_if_fail(buddy != NULL);
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
286
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
287 old_icon = gaim_blist_node_get_string((GaimBlistNode *)buddy, "buddy_icon");
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
288
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
289 if (old_icon != NULL)
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
290 delete_icon_cache_file(gaim_buddy_icons_get_cache_dir(), old_icon);
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
291
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
292 gaim_blist_node_remove_setting((GaimBlistNode *)buddy, "buddy_icon");
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
293
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
294 /* Unset the icon in case this function is called from
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
295 * something other than gaim_buddy_set_icon(). */
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
296 if (buddy->icon != NULL)
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
297 {
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
298 gaim_buddy_icon_unref(buddy->icon);
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
299 buddy->icon = NULL;
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
300 }
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
301 }
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
302
3428ad6f5049 [gaim-migrate @ 12940]
Richard Laager <rlaager@wiktel.com>
parents: 11033
diff changeset
303 void
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
304 gaim_buddy_icon_set_account(GaimBuddyIcon *icon, GaimAccount *account)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
305 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
306 g_return_if_fail(icon != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
307 g_return_if_fail(account != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
308
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
309 icon->account = account;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
310 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
311
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
312 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
313 gaim_buddy_icon_set_username(GaimBuddyIcon *icon, const char *username)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
314 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
315 g_return_if_fail(icon != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
316 g_return_if_fail(username != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
317
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
318 if (icon->username != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
319 g_free(icon->username);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
320
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
321 icon->username = g_strdup(username);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
322 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
323
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
324 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
325 gaim_buddy_icon_set_data(GaimBuddyIcon *icon, void *data, size_t len)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
326 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
327 g_return_if_fail(icon != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
328
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
329 if (icon->data != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
330 g_free(icon->data);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
331
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
332 if (data != NULL && len > 0)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
333 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
334 icon->data = g_memdup(data, len);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
335 icon->len = len;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
336 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
337 else
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
338 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
339 icon->data = NULL;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
340 icon->len = 0;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
341 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
342
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
343 gaim_buddy_icon_update(icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
344 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
345
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
346 GaimAccount *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
347 gaim_buddy_icon_get_account(const GaimBuddyIcon *icon)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
348 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
349 g_return_val_if_fail(icon != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
350
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
351 return icon->account;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
352 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
353
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
354 const char *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
355 gaim_buddy_icon_get_username(const GaimBuddyIcon *icon)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
356 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
357 g_return_val_if_fail(icon != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
358
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
359 return icon->username;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
360 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
361
11137
096020ae09a9 [gaim-migrate @ 13201]
Mark Doliner <mark@kingant.net>
parents: 11040
diff changeset
362 const guchar *
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
363 gaim_buddy_icon_get_data(const GaimBuddyIcon *icon, size_t *len)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
364 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
365 g_return_val_if_fail(icon != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
366
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
367 if (len != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
368 *len = icon->len;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
369
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
370 return icon->data;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
371 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
372
10953
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
373 const char *
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
374 gaim_buddy_icon_get_type(const GaimBuddyIcon *icon)
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
375 {
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
376 const void *data;
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
377 size_t len;
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
378
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
379 g_return_val_if_fail(icon != NULL, NULL);
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
380
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
381 data = gaim_buddy_icon_get_data(icon, &len);
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
382
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
383 /* TODO: Find a way to do this with GDK */
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
384 if (len >= 4)
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
385 {
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
386 if (!strncmp(data, "BM", 2))
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
387 return "bmp";
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
388 else if (!strncmp(data, "GIF8", 4))
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
389 return "gif";
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
390 else if (!strncmp(data, "\xff\xd8\xff\xe0", 4))
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
391 return "jpg";
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
392 else if (!strncmp(data, "\x89PNG", 4))
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
393 return "png";
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
394 }
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
395
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
396 return NULL;
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
397 }
e8e535ad720b [gaim-migrate @ 12753]
Mark Doliner <mark@kingant.net>
parents: 10934
diff changeset
398
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
399 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
400 gaim_buddy_icons_set_for_user(GaimAccount *account, const char *username,
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
401 void *icon_data, size_t icon_len)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
402 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
403 g_return_if_fail(account != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
404 g_return_if_fail(username != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
405
9305
0c201a2386c7 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
406 if (icon_data == NULL || icon_len == 0)
0c201a2386c7 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
407 {
0c201a2386c7 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
408 GaimBuddyIcon *buddy_icon;
0c201a2386c7 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
409
0c201a2386c7 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
410 buddy_icon = gaim_buddy_icons_find(account, username);
0c201a2386c7 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
411
0c201a2386c7 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
412 if (buddy_icon != NULL)
0c201a2386c7 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
413 gaim_buddy_icon_destroy(buddy_icon);
0c201a2386c7 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
414 }
0c201a2386c7 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
415 else
0c201a2386c7 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
416 {
11423
202a3b3c5a88 [gaim-migrate @ 13660]
Richard Laager <rlaager@wiktel.com>
parents: 11338
diff changeset
417 GaimBuddyIcon *icon = gaim_buddy_icon_new(account, username, icon_data, icon_len);
202a3b3c5a88 [gaim-migrate @ 13660]
Richard Laager <rlaager@wiktel.com>
parents: 11338
diff changeset
418 gaim_buddy_icon_unref(icon);
9305
0c201a2386c7 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
419 }
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
420 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
421
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
422 GaimBuddyIcon *
9396
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
423 gaim_buddy_icons_find(GaimAccount *account, const char *username)
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
424 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
425 GHashTable *icon_cache;
9396
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
426 GaimBuddyIcon *ret = NULL;
9747
e0060f3b6d92 [gaim-migrate @ 10613]
Luke Schierer <lschiere@pidgin.im>
parents: 9396
diff changeset
427 char *filename = NULL;
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
428
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
429 g_return_val_if_fail(account != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
430 g_return_val_if_fail(username != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
431
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
432 icon_cache = g_hash_table_lookup(account_cache, account);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
433
9396
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
434 if ((icon_cache == NULL) || ((ret = g_hash_table_lookup(icon_cache, username)) == NULL)) {
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
435 const char *file;
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
436 struct stat st;
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
437 GaimBuddy *b = gaim_find_buddy(account, username);
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
438
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
439 if (!b)
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
440 return NULL;
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
441
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
442 if ((file = gaim_blist_node_get_string((GaimBlistNode*)b, "buddy_icon")) == NULL)
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
443 return NULL;
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
444
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10523
diff changeset
445 if (!g_stat(file, &st))
9747
e0060f3b6d92 [gaim-migrate @ 10613]
Luke Schierer <lschiere@pidgin.im>
parents: 9396
diff changeset
446 filename = g_strdup(file);
e0060f3b6d92 [gaim-migrate @ 10613]
Luke Schierer <lschiere@pidgin.im>
parents: 9396
diff changeset
447 else
e0060f3b6d92 [gaim-migrate @ 10613]
Luke Schierer <lschiere@pidgin.im>
parents: 9396
diff changeset
448 filename = g_build_filename(gaim_buddy_icons_get_cache_dir(), file, NULL);
e0060f3b6d92 [gaim-migrate @ 10613]
Luke Schierer <lschiere@pidgin.im>
parents: 9396
diff changeset
449
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10523
diff changeset
450 if (!g_stat(filename, &st)) {
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10523
diff changeset
451 FILE *f = g_fopen(filename, "rb");
9396
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
452 if (f) {
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
453 char *data = g_malloc(st.st_size);
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
454 fread(data, 1, st.st_size, f);
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
455 fclose(f);
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
456 ret = gaim_buddy_icon_create(account, username);
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
457 gaim_buddy_icon_ref(ret);
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
458 gaim_buddy_icon_set_data(ret, data, st.st_size);
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
459 gaim_buddy_icon_unref(ret);
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
460 g_free(data);
9747
e0060f3b6d92 [gaim-migrate @ 10613]
Luke Schierer <lschiere@pidgin.im>
parents: 9396
diff changeset
461 g_free(filename);
9396
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
462 return ret;
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
463 }
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
464 }
9747
e0060f3b6d92 [gaim-migrate @ 10613]
Luke Schierer <lschiere@pidgin.im>
parents: 9396
diff changeset
465 g_free(filename);
9396
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
466 }
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
467
84594a281500 [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
468 return ret;
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
469 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
470
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
471 void
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
472 gaim_buddy_icons_set_caching(gboolean caching)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
473 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
474 icon_caching = caching;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
475 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
476
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
477 gboolean
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
478 gaim_buddy_icons_is_caching(void)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
479 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
480 return icon_caching;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
481 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
482
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
483 void
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
484 gaim_buddy_icons_set_cache_dir(const char *dir)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
485 {
10811
dc59482c8d37 [gaim-migrate @ 12464]
Luke Schierer <lschiere@pidgin.im>
parents: 10589
diff changeset
486 g_return_if_fail(dir != NULL);
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
487
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
488 if (cache_dir != NULL)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
489 g_free(cache_dir);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
490
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
491 cache_dir = g_strdup(dir);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
492 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
493
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
494 const char *
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
495 gaim_buddy_icons_get_cache_dir(void)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
496 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
497 return cache_dir;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
498 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
499
11303
10066662176a [gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
500 char *gaim_buddy_icons_get_full_path(const char *icon) {
10066662176a [gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
501 struct stat st;
10066662176a [gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
502
10066662176a [gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
503 if (icon == NULL)
10066662176a [gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
504 return NULL;
10066662176a [gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
505
10066662176a [gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
506 if (g_stat(icon, &st) == 0)
10066662176a [gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
507 return g_strdup(icon);
10066662176a [gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
508 else
10066662176a [gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
509 return g_build_filename(gaim_buddy_icons_get_cache_dir(), icon, NULL);
10066662176a [gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
510 }
10066662176a [gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents: 11256
diff changeset
511
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
512 void *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
513 gaim_buddy_icons_get_handle()
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
514 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
515 static int handle;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
516
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
517 return &handle;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
518 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
519
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
520 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
521 gaim_buddy_icons_init()
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
522 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
523 account_cache = g_hash_table_new_full(
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
524 g_direct_hash, g_direct_equal,
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
525 NULL, (GFreeFunc)g_hash_table_destroy);
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
526
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
527 cache_dir = g_build_filename(gaim_user_dir(), "icons", NULL);
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
528 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
529
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
530 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
531 gaim_buddy_icons_uninit()
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
532 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
533 g_hash_table_destroy(account_cache);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
534 }
10483
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
535
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
536 void gaim_buddy_icon_get_scale_size(GaimBuddyIconSpec *spec, int *width, int *height)
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
537 {
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
538 if(spec && spec->scale_rules & GAIM_ICON_SCALE_DISPLAY) {
10523
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
539 int new_width, new_height;
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
540
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
541 new_width = *width;
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
542 new_height = *height;
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
543
10483
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
544 if(*width < spec->min_width)
10523
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
545 new_width = spec->min_width;
10483
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
546 else if(*width > spec->max_width)
10523
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
547 new_width = spec->max_width;
10483
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
548
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
549 if(*height < spec->min_height)
10523
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
550 new_height = spec->min_height;
10483
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
551 else if(*height > spec->max_height)
10523
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
552 new_height = spec->max_height;
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
553
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
554 /* preserve aspect ratio */
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
555 if ((double)*height * (double)new_width >
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
556 (double)*width * (double)new_height) {
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
557 new_width = 0.5 + (double)*width * (double)new_height / (double)*height;
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
558 } else {
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
559 new_height = 0.5 + (double)*height * (double)new_width / (double)*width;
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
560 }
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
561
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
562 *width = new_width;
f5c9438982f8 [gaim-migrate @ 11840]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
563 *height = new_height;
10483
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
564 }
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
565 }
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
566