annotate src/buddyicon.c @ 8697:725413cc9fb9

[gaim-migrate @ 9450] WYSIWYG info editing from Jon Oberheide We need separate gc flags for conversation HTML and user info HTML, or something. It seems like there should be a better way to do that... Hint hint wink wink nudge nudge I kick your foot, under the table You kick me back, I can't say I'm able To stand for you, or fall for you Ever again I wish for, a perfect setting Wishing that I'm letting you take me Where you want me, all over again committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 18 Apr 2004 06:22:42 +0000
parents 52dca2f38956
children 7a8aa87164ae
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;
8550
52dca2f38956 [gaim-migrate @ 9292]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
153 GSList *sl, *list;
6846
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
8550
52dca2f38956 [gaim-migrate @ 9292]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
160 for (list =sl = gaim_find_buddies(account, username); sl != NULL;
52dca2f38956 [gaim-migrate @ 9292]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
161 sl = sl->next)
6846
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 GaimBuddy *buddy = (GaimBuddy *)sl->data;
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_set_icon(buddy, 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
8550
52dca2f38956 [gaim-migrate @ 9292]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
168 g_slist_free(list);
52dca2f38956 [gaim-migrate @ 9292]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
169
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
170 conv = gaim_find_conversation_with_account(username, account);
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 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
173 gaim_conv_im_set_icon(GAIM_CONV_IM(conv), icon);
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
174 }
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 void
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
177 gaim_buddy_icon_cache(GaimBuddyIcon *icon, GaimBuddy *buddy)
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 const void *data;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
180 const char *dirname;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
181 char *random;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
182 char *filename;
7125
208cb260d7a7 [gaim-migrate @ 7692]
Nathan Walp <nwalp@pidgin.im>
parents: 7118
diff changeset
183 const char *old_icon;
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
184 size_t len;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
185 FILE *file = 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 g_return_if_fail(icon != NULL);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
188 g_return_if_fail(buddy != NULL);
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 (!gaim_buddy_icons_is_caching())
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
191 return;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
192
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
193 data = gaim_buddy_icon_get_data(icon, &len);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
194
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
195 random = g_strdup_printf("%x", g_random_int());
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
196 dirname = gaim_buddy_icons_get_cache_dir();
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
197 filename = g_build_filename(dirname, random, NULL);
7721
20d0c025312a [gaim-migrate @ 8366]
Nathan Walp <nwalp@pidgin.im>
parents: 7311
diff changeset
198 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
199
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
200 g_free(random);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
201
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
202 if (!g_file_test(dirname, G_FILE_TEST_IS_DIR))
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 gaim_debug_info("buddy icons", "Creating icon cache directory.\n");
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 if (mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
207 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
208 gaim_debug_error("buddy icons",
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
209 "Unable to create directory %s: %s\n",
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
210 dirname, strerror(errno));
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
211 }
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
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
214 if ((file = fopen(filename, "wb")) != NULL)
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 fwrite(data, 1, len, file);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
217 fclose(file);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
218 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
219
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
220 if (old_icon != NULL)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
221 unlink(old_icon);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
222
7721
20d0c025312a [gaim-migrate @ 8366]
Nathan Walp <nwalp@pidgin.im>
parents: 7311
diff changeset
223 gaim_blist_node_set_string((GaimBlistNode*)buddy, "buddy_icon", filename);
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
224 gaim_blist_save();
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 g_free(filename);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
227 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
228
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
229 void
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
230 gaim_buddy_icon_set_account(GaimBuddyIcon *icon, GaimAccount *account)
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 g_return_if_fail(icon != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
233 g_return_if_fail(account != NULL);
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 icon->account = account;
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
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
238 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
239 gaim_buddy_icon_set_username(GaimBuddyIcon *icon, const char *username)
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 g_return_if_fail(icon != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
242 g_return_if_fail(username != NULL);
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 if (icon->username != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
245 g_free(icon->username);
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->username = g_strdup(username);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
248 }
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 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
251 gaim_buddy_icon_set_data(GaimBuddyIcon *icon, void *data, size_t len)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
252 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
253 g_return_if_fail(icon != NULL);
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 (icon->data != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
256 g_free(icon->data);
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 if (data != NULL && len > 0)
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 icon->data = g_memdup(data, len);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
261 icon->len = len;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
262 }
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
263 else
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 icon->data = NULL;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
266 icon->len = 0;
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 gaim_buddy_icon_update(icon);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
270 }
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 GaimAccount *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
273 gaim_buddy_icon_get_account(const GaimBuddyIcon *icon)
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 g_return_val_if_fail(icon != NULL, NULL);
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 return icon->account;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
278 }
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 const char *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
281 gaim_buddy_icon_get_username(const GaimBuddyIcon *icon)
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 g_return_val_if_fail(icon != NULL, NULL);
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 return icon->username;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
286 }
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 const void *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
289 gaim_buddy_icon_get_data(const GaimBuddyIcon *icon, size_t *len)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
290 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
291 g_return_val_if_fail(icon != NULL, 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 if (len != NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
294 *len = icon->len;
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 return icon->data;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
297 }
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 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
300 gaim_buddy_icons_set_for_user(GaimAccount *account, const char *username,
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
301 void *icon_data, size_t icon_len)
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 g_return_if_fail(account != NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
304 g_return_if_fail(username != NULL);
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 gaim_buddy_icon_new(account, username, icon_data, icon_len);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
307 }
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 GaimBuddyIcon *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
310 gaim_buddy_icons_find(const GaimAccount *account, const char *username)
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 GHashTable *icon_cache;
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 g_return_val_if_fail(account != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
315 g_return_val_if_fail(username != NULL, NULL);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
316
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
317 icon_cache = g_hash_table_lookup(account_cache, account);
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 if (icon_cache == NULL)
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
320 return NULL;
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
321
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
322 return g_hash_table_lookup(icon_cache, username);
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
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
325 void
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
326 gaim_buddy_icons_set_caching(gboolean caching)
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 icon_caching = caching;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
329 }
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 gboolean
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
332 gaim_buddy_icons_is_caching(void)
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 return icon_caching;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
335 }
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 void
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
338 gaim_buddy_icons_set_cache_dir(const char *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 g_return_if_fail(cache_dir != NULL);
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 if (cache_dir != NULL)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
343 g_free(cache_dir);
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 cache_dir = g_strdup(dir);
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
346 }
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 const char *
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
349 gaim_buddy_icons_get_cache_dir(void)
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
350 {
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
351 return cache_dir;
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
352 }
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
353
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
354 void *
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
355 gaim_buddy_icons_get_handle()
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 static int handle;
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 &handle;
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
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
362 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
363 gaim_buddy_icons_init()
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 account_cache = g_hash_table_new_full(
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
366 g_direct_hash, g_direct_equal,
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
367 NULL, (GFreeFunc)g_hash_table_destroy);
6886
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
368
b5fb1d5282e5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
369 cache_dir = g_build_filename(gaim_user_dir(), "icons", NULL);
6846
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
370 }
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 void
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
373 gaim_buddy_icons_uninit()
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
374 {
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
375 g_hash_table_destroy(account_cache);
8ab95f4c9800 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
376 }