annotate src/buddyicon.c @ 6947:6777368cc2ba

[gaim-migrate @ 7494] apparently i missed an email containing a dutch translation, but the translator was kind enough to notice and resend it :-) committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Wed, 24 Sep 2003 19:10:21 +0000
parents b5fb1d5282e5
children bf630f7dfdcd
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 *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
7 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org>
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
8 *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
10 * 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
11 * the Free Software Foundation; either version 2 of the License, or
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
12 * (at your option) any later version.
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
13 *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
17 * GNU General Public License for more details.
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
18 *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
22 */
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
23 #include "internal.h"
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
24 #include "buddyicon.h"
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
25 #include "conversation.h"
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
26 #include "debug.h"
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
27 #include "util.h"
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
28
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
29 static GHashTable *account_cache = NULL;
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
30 static char *cache_dir = NULL;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
31 static gboolean icon_caching = TRUE;
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
32
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
33 GaimBuddyIcon *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
34 gaim_buddy_icon_new(GaimAccount *account, const char *username,
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
35 void *icon_data, size_t icon_len)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
36 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
37 GaimBuddyIcon *icon;
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 g_return_val_if_fail(account != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
40 g_return_val_if_fail(username != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
41 g_return_val_if_fail(icon_data != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
42 g_return_val_if_fail(icon_len > 0, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
43
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
44 icon = gaim_buddy_icons_find(account, username);
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 if (icon == NULL)
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 GHashTable *icon_cache;
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 icon = g_new0(GaimBuddyIcon, 1);
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 gaim_buddy_icon_set_account(icon, account);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
53 gaim_buddy_icon_set_username(icon, username);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
54
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
55 icon_cache = g_hash_table_lookup(account_cache, account);
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 if (icon_cache == NULL)
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 icon_cache = g_hash_table_new(g_str_hash, g_str_equal);
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 g_hash_table_insert(account_cache, account, icon_cache);
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
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
64 g_hash_table_insert(icon_cache,
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
65 (char *)gaim_buddy_icon_get_username(icon), icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
66 }
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 gaim_buddy_icon_set_data(icon, icon_data, icon_len);
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_ref(icon);
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 return 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
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
75 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
76 gaim_buddy_icon_destroy(GaimBuddyIcon *icon)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
77 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
78 GHashTable *icon_cache;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
79
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
80 g_return_if_fail(icon != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
81
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
82 if (icon->ref_count > 0)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
83 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
84 gaim_buddy_icon_unref(icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
85
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
86 return;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
87 }
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 icon_cache = g_hash_table_lookup(account_cache,
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
90 gaim_buddy_icon_get_account(icon));
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
91
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
92 if (icon_cache != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
93 g_hash_table_remove(icon_cache, gaim_buddy_icon_get_username(icon));
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
94
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
95 if (icon->username != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
96 g_free(icon->username);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
97
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
98 if (icon->data != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
99 g_free(icon->data);
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 g_free(icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
102 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
103
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
104 GaimBuddyIcon *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
105 gaim_buddy_icon_ref(GaimBuddyIcon *icon)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
106 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
107 g_return_val_if_fail(icon != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
108
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
109 icon->ref_count++;
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 return icon;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
112 }
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 GaimBuddyIcon *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
115 gaim_buddy_icon_unref(GaimBuddyIcon *icon)
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 g_return_val_if_fail(icon != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
118
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
119 if (icon->ref_count <= 0)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
120 return 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 if (icon->ref_count == 0)
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 gaim_buddy_icon_destroy(icon);
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 return NULL;
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
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
131 return icon;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
132 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
133
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
134 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
135 gaim_buddy_icon_update(GaimBuddyIcon *icon)
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 GaimConversation *conv;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
138 GaimAccount *account;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
139 const char *username;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
140 GSList *sl;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
141
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
142 g_return_if_fail(icon != NULL);
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 account = gaim_buddy_icon_get_account(icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
145 username = gaim_buddy_icon_get_username(icon);
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 for (sl = gaim_find_buddies(account, username); sl != NULL; sl = sl->next)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
148 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
149 GaimBuddy *buddy = (GaimBuddy *)sl->data;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
150
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
151 gaim_buddy_set_icon(buddy, icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
152 }
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 conv = gaim_find_conversation_with_account(username, account);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
155
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
156 if (conv != NULL && gaim_conversation_get_type(conv) == GAIM_CONV_IM)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
157 gaim_im_set_icon(GAIM_IM(conv), icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
158 }
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 void
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
161 gaim_buddy_icon_cache(GaimBuddyIcon *icon, GaimBuddy *buddy)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
162 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
163 const void *data;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
164 const char *dirname;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
165 char *random;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
166 char *filename;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
167 char *old_icon;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
168 size_t len;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
169 FILE *file = NULL;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
170
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
171 g_return_if_fail(icon != NULL);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
172 g_return_if_fail(buddy != NULL);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
173
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
174 if (!gaim_buddy_icons_is_caching())
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
175 return;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
176
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
177 data = gaim_buddy_icon_get_data(icon, &len);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
178
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
179 random = g_strdup_printf("%x", g_random_int());
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
180 dirname = gaim_buddy_icons_get_cache_dir();
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
181 filename = g_build_filename(dirname, random, NULL);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
182 old_icon = gaim_buddy_get_setting(buddy, "buddy_icon");
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_free(random);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
185
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
186 if (!g_file_test(dirname, G_FILE_TEST_IS_DIR))
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
187 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
188 gaim_debug_info("buddy icons", "Creating icon cache directory.\n");
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 if (mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0)
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 gaim_debug_error("buddy icons",
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
193 "Unable to create directory %s: %s\n",
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
194 dirname, strerror(errno));
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
195 }
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
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
198 if ((file = fopen(filename, "wb")) != NULL)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
199 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
200 fwrite(data, 1, len, file);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
201 fclose(file);
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
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
204 if (old_icon != NULL)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
205 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
206 unlink(old_icon);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
207 g_free(old_icon);
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 gaim_buddy_set_setting(buddy, "buddy_icon", filename);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
211 gaim_blist_save();
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 g_free(filename);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
214 }
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 void
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
217 gaim_buddy_icon_set_account(GaimBuddyIcon *icon, GaimAccount *account)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
218 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
219 g_return_if_fail(icon != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
220 g_return_if_fail(account != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
221
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
222 icon->account = account;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
223 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
224
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
225 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
226 gaim_buddy_icon_set_username(GaimBuddyIcon *icon, const char *username)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
227 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
228 g_return_if_fail(icon != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
229 g_return_if_fail(username != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
230
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
231 if (icon->username != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
232 g_free(icon->username);
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 icon->username = g_strdup(username);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
235 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
236
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
237 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
238 gaim_buddy_icon_set_data(GaimBuddyIcon *icon, void *data, size_t len)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
239 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
240 g_return_if_fail(icon != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
241
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
242 if (icon->data != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
243 g_free(icon->data);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
244
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
245 if (data != NULL && len > 0)
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 icon->data = g_memdup(data, len);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
248 icon->len = 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 else
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 icon->data = NULL;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
253 icon->len = 0;
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
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
256 gaim_buddy_icon_update(icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
257 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
258
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
259 GaimAccount *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
260 gaim_buddy_icon_get_account(const GaimBuddyIcon *icon)
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 g_return_val_if_fail(icon != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
263
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
264 return icon->account;
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
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
267 const char *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
268 gaim_buddy_icon_get_username(const GaimBuddyIcon *icon)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
269 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
270 g_return_val_if_fail(icon != NULL, NULL);
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 return icon->username;
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
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
275 const void *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
276 gaim_buddy_icon_get_data(const GaimBuddyIcon *icon, size_t *len)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
277 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
278 g_return_val_if_fail(icon != NULL, NULL);
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 if (len != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
281 *len = icon->len;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
282
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
283 return icon->data;
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
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
286 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
287 gaim_buddy_icons_set_for_user(GaimAccount *account, const char *username,
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
288 void *icon_data, size_t icon_len)
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 g_return_if_fail(account != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
291 g_return_if_fail(username != NULL);
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 gaim_buddy_icon_new(account, username, icon_data, icon_len);
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 GaimBuddyIcon *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
297 gaim_buddy_icons_find(const GaimAccount *account, const char *username)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
298 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
299 GHashTable *icon_cache;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
300
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
301 g_return_val_if_fail(account != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
302 g_return_val_if_fail(username != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
303
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
304 icon_cache = g_hash_table_lookup(account_cache, 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 if (icon_cache == NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
307 return 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 return g_hash_table_lookup(icon_cache, username);
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
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
312 void
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
313 gaim_buddy_icons_set_caching(gboolean caching)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
314 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
315 icon_caching = caching;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
316 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
317
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
318 gboolean
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
319 gaim_buddy_icons_is_caching(void)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
320 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
321 return icon_caching;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
322 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
323
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
324 void
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
325 gaim_buddy_icons_set_cache_dir(const char *dir)
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 g_return_if_fail(cache_dir != NULL);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
328
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
329 if (cache_dir != NULL)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
330 g_free(cache_dir);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
331
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
332 cache_dir = g_strdup(dir);
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
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
335 const char *
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
336 gaim_buddy_icons_get_cache_dir(void)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
337 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
338 return cache_dir;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
339 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
340
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
341 void *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
342 gaim_buddy_icons_get_handle()
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
343 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
344 static int handle;
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 return &handle;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
347 }
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 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
350 gaim_buddy_icons_init()
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
351 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
352 account_cache = g_hash_table_new_full(
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
353 g_direct_hash, g_direct_equal,
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
354 NULL, (GFreeFunc)g_hash_table_destroy);
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
355
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
356 cache_dir = g_build_filename(gaim_user_dir(), "icons", NULL);
6846
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_uninit()
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 g_hash_table_destroy(account_cache);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
363 }