annotate src/buddyicon.c @ 8411:34896b4a0da3

[gaim-migrate @ 9141] I promised to fix things... committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Mon, 08 Mar 2004 19:09:30 +0000
parents fa6395637e2c
children 52dca2f38956
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"
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
28 #include "debug.h"
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
29 #include "util.h"
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
30
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
31 static GHashTable *account_cache = NULL;
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
32 static char *cache_dir = NULL;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
33 static gboolean icon_caching = TRUE;
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
34
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
35 GaimBuddyIcon *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
36 gaim_buddy_icon_new(GaimAccount *account, const char *username,
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
37 void *icon_data, size_t icon_len)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
38 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
39 GaimBuddyIcon *icon;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
40
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
41 g_return_val_if_fail(account != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
42 g_return_val_if_fail(username != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
43 g_return_val_if_fail(icon_data != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
44 g_return_val_if_fail(icon_len > 0, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
45
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
46 icon = gaim_buddy_icons_find(account, username);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
47
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
48 if (icon == NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
49 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
50 GHashTable *icon_cache;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
51
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
52 icon = g_new0(GaimBuddyIcon, 1);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
53
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
54 gaim_buddy_icon_set_account(icon, account);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
55 gaim_buddy_icon_set_username(icon, username);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
56
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
57 icon_cache = g_hash_table_lookup(account_cache, account);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
58
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
59 if (icon_cache == NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
60 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
61 icon_cache = g_hash_table_new(g_str_hash, g_str_equal);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
62
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
63 g_hash_table_insert(account_cache, account, icon_cache);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
64 }
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 g_hash_table_insert(icon_cache,
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
67 (char *)gaim_buddy_icon_get_username(icon), icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
68 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
69
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
70 gaim_buddy_icon_set_data(icon, icon_data, icon_len);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
71
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
72 gaim_buddy_icon_ref(icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
73
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
74 return icon;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
75 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
76
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
77 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
78 gaim_buddy_icon_destroy(GaimBuddyIcon *icon)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
79 {
7311
1c8830db0189 [gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents: 7125
diff changeset
80 GaimConversation *conv;
1c8830db0189 [gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents: 7125
diff changeset
81 GaimAccount *account;
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
82 GHashTable *icon_cache;
7311
1c8830db0189 [gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents: 7125
diff changeset
83 const char *username;
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
84
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
85 g_return_if_fail(icon != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
86
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
87 if (icon->ref_count > 0)
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 gaim_buddy_icon_unref(icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
90
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
91 return;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
92 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
93
7311
1c8830db0189 [gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents: 7125
diff changeset
94 account = gaim_buddy_icon_get_account(icon);
1c8830db0189 [gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents: 7125
diff changeset
95 username = gaim_buddy_icon_get_username(icon);
1c8830db0189 [gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents: 7125
diff changeset
96
1c8830db0189 [gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents: 7125
diff changeset
97 conv = gaim_find_conversation_with_account(username, account);
1c8830db0189 [gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents: 7125
diff changeset
98
1c8830db0189 [gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents: 7125
diff changeset
99 if (conv != NULL && gaim_conversation_get_type(conv) == GAIM_CONV_IM)
1c8830db0189 [gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents: 7125
diff changeset
100 gaim_conv_im_set_icon(GAIM_CONV_IM(conv), NULL);
1c8830db0189 [gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents: 7125
diff changeset
101
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
102 icon_cache = g_hash_table_lookup(account_cache,
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
103 gaim_buddy_icon_get_account(icon));
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
104
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
105 if (icon_cache != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
106 g_hash_table_remove(icon_cache, gaim_buddy_icon_get_username(icon));
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
107
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
108 if (icon->username != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
109 g_free(icon->username);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
110
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
111 if (icon->data != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
112 g_free(icon->data);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
113
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
114 g_free(icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
115 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
116
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
117 GaimBuddyIcon *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
118 gaim_buddy_icon_ref(GaimBuddyIcon *icon)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
119 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
120 g_return_val_if_fail(icon != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
121
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
122 icon->ref_count++;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
123
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
124 return icon;
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
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
127 GaimBuddyIcon *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
128 gaim_buddy_icon_unref(GaimBuddyIcon *icon)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
129 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
130 g_return_val_if_fail(icon != NULL, NULL);
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->ref_count <= 0)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
133 return NULL;
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 icon->ref_count--;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
136
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
137 if (icon->ref_count == 0)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
138 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
139 gaim_buddy_icon_destroy(icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
140
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
141 return NULL;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
142 }
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 return icon;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
145 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
146
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
147 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
148 gaim_buddy_icon_update(GaimBuddyIcon *icon)
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 GaimConversation *conv;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
151 GaimAccount *account;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
152 const char *username;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
153 GSList *sl;
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 g_return_if_fail(icon != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
156
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
157 account = gaim_buddy_icon_get_account(icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
158 username = gaim_buddy_icon_get_username(icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
159
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
160 for (sl = gaim_find_buddies(account, username); sl != NULL; sl = sl->next)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
161 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
162 GaimBuddy *buddy = (GaimBuddy *)sl->data;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
163
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
164 gaim_buddy_set_icon(buddy, icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
165 }
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 conv = gaim_find_conversation_with_account(username, account);
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 if (conv != NULL && gaim_conversation_get_type(conv) == GAIM_CONV_IM)
7118
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 6886
diff changeset
170 gaim_conv_im_set_icon(GAIM_CONV_IM(conv), icon);
6846
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
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
174 gaim_buddy_icon_cache(GaimBuddyIcon *icon, GaimBuddy *buddy)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
175 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
176 const void *data;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
177 const char *dirname;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
178 char *random;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
179 char *filename;
7125
208cb260d7a7 [gaim-migrate @ 7692]
Nathan Walp <nwalp@pidgin.im>
parents: 7118
diff changeset
180 const char *old_icon;
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
181 size_t len;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
182 FILE *file = NULL;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
183
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
184 g_return_if_fail(icon != NULL);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
185 g_return_if_fail(buddy != NULL);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
186
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
187 if (!gaim_buddy_icons_is_caching())
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
188 return;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
189
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
190 data = gaim_buddy_icon_get_data(icon, &len);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
191
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
192 random = g_strdup_printf("%x", g_random_int());
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
193 dirname = gaim_buddy_icons_get_cache_dir();
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
194 filename = g_build_filename(dirname, random, NULL);
7721
20d0c025312a [gaim-migrate @ 8366]
Nathan Walp <nwalp@pidgin.im>
parents: 7311
diff changeset
195 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
196
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
197 g_free(random);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
198
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
199 if (!g_file_test(dirname, G_FILE_TEST_IS_DIR))
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
200 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
201 gaim_debug_info("buddy icons", "Creating icon cache directory.\n");
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
202
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
203 if (mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
204 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
205 gaim_debug_error("buddy icons",
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
206 "Unable to create directory %s: %s\n",
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
207 dirname, strerror(errno));
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
208 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
209 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
210
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
211 if ((file = fopen(filename, "wb")) != NULL)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
212 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
213 fwrite(data, 1, len, file);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
214 fclose(file);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
215 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
216
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
217 if (old_icon != NULL)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
218 unlink(old_icon);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
219
7721
20d0c025312a [gaim-migrate @ 8366]
Nathan Walp <nwalp@pidgin.im>
parents: 7311
diff changeset
220 gaim_blist_node_set_string((GaimBlistNode*)buddy, "buddy_icon", filename);
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
221 gaim_blist_save();
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
222
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
223 g_free(filename);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
224 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
225
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
226 void
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
227 gaim_buddy_icon_set_account(GaimBuddyIcon *icon, GaimAccount *account)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
228 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
229 g_return_if_fail(icon != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
230 g_return_if_fail(account != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
231
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
232 icon->account = account;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
233 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
234
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
235 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
236 gaim_buddy_icon_set_username(GaimBuddyIcon *icon, const char *username)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
237 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
238 g_return_if_fail(icon != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
239 g_return_if_fail(username != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
240
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
241 if (icon->username != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
242 g_free(icon->username);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
243
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
244 icon->username = g_strdup(username);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
245 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
246
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
247 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
248 gaim_buddy_icon_set_data(GaimBuddyIcon *icon, void *data, size_t len)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
249 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
250 g_return_if_fail(icon != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
251
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
252 if (icon->data != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
253 g_free(icon->data);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
254
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
255 if (data != NULL && len > 0)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
256 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
257 icon->data = g_memdup(data, len);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
258 icon->len = len;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
259 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
260 else
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
261 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
262 icon->data = NULL;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
263 icon->len = 0;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
264 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
265
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
266 gaim_buddy_icon_update(icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
267 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
268
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
269 GaimAccount *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
270 gaim_buddy_icon_get_account(const GaimBuddyIcon *icon)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
271 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
272 g_return_val_if_fail(icon != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
273
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
274 return icon->account;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
275 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
276
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
277 const char *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
278 gaim_buddy_icon_get_username(const GaimBuddyIcon *icon)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
279 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
280 g_return_val_if_fail(icon != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
281
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
282 return icon->username;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
283 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
284
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
285 const void *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
286 gaim_buddy_icon_get_data(const GaimBuddyIcon *icon, size_t *len)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
287 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
288 g_return_val_if_fail(icon != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
289
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
290 if (len != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
291 *len = icon->len;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
292
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
293 return icon->data;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
294 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
295
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
296 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
297 gaim_buddy_icons_set_for_user(GaimAccount *account, const char *username,
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
298 void *icon_data, size_t icon_len)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
299 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
300 g_return_if_fail(account != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
301 g_return_if_fail(username != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
302
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
303 gaim_buddy_icon_new(account, username, icon_data, icon_len);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
304 }
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 GaimBuddyIcon *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
307 gaim_buddy_icons_find(const GaimAccount *account, const char *username)
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 GHashTable *icon_cache;
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 g_return_val_if_fail(account != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
312 g_return_val_if_fail(username != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
313
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
314 icon_cache = g_hash_table_lookup(account_cache, account);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
315
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
316 if (icon_cache == NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
317 return NULL;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
318
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
319 return g_hash_table_lookup(icon_cache, 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
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
322 void
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
323 gaim_buddy_icons_set_caching(gboolean caching)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
324 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
325 icon_caching = caching;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
326 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
327
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
328 gboolean
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
329 gaim_buddy_icons_is_caching(void)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
330 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
331 return icon_caching;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
332 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
333
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
334 void
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
335 gaim_buddy_icons_set_cache_dir(const char *dir)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
336 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
337 g_return_if_fail(cache_dir != NULL);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
338
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
339 if (cache_dir != NULL)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
340 g_free(cache_dir);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
341
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
342 cache_dir = g_strdup(dir);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
343 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
344
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
345 const char *
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
346 gaim_buddy_icons_get_cache_dir(void)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
347 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
348 return cache_dir;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
349 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
350
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
351 void *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
352 gaim_buddy_icons_get_handle()
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 static int handle;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
355
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
356 return &handle;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
357 }
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 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
360 gaim_buddy_icons_init()
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
361 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
362 account_cache = g_hash_table_new_full(
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
363 g_direct_hash, g_direct_equal,
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
364 NULL, (GFreeFunc)g_hash_table_destroy);
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
365
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
366 cache_dir = g_build_filename(gaim_user_dir(), "icons", NULL);
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
367 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
368
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
369 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
370 gaim_buddy_icons_uninit()
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 g_hash_table_destroy(account_cache);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
373 }