libpurple/buddyicon.c

Wed, 06 Feb 2008 18:06:44 +0000

author
John Bailey <rekkanoryo@rekkanoryo.org>
date
Wed, 06 Feb 2008 18:06:44 +0000
branch
cpw.rekkanoryo.yahoop15ft
changeset 22401
5fe1761a4a15
parent 22390
d22357d5c7ba
child 22547
342b81d25863
permissions
-rw-r--r--

Simplified version of the newest patch on #4533 to not try Yahoo protocol
version 15 file transfer on Yahoo Japan.

6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1 /**
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
2 * @file icon.c Buddy Icon API
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
3 * @ingroup core
20147
66f05a854eee applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
4 */
66f05a854eee applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
5
66f05a854eee applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
6 /* purple
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
7 *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
8 * Purple is the legal property of its developers, whose names are too numerous
8046
c581b20a47d6 [gaim-migrate @ 8730]
Sean Egan <seanegan@pidgin.im>
parents: 7721
diff changeset
9 * to list here. Please refer to the COPYRIGHT file distributed with this
c581b20a47d6 [gaim-migrate @ 8730]
Sean Egan <seanegan@pidgin.im>
parents: 7721
diff changeset
10 * source distribution.
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
11 *
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
12 * This program is free software; you can redistribute it and/or modify
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
13 * it under the terms of the GNU General Public License as published by
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
14 * the Free Software Foundation; either version 2 of the License, or
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
15 * (at your option) any later version.
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
16 *
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
17 * This program is distributed in the hope that it will be useful,
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
20 * GNU General Public License for more details.
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
21 *
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
22 * You should have received a copy of the GNU General Public License
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
23 * along with this program; if not, write to the Free Software
19859
71d37b57eff2 The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 18122
diff changeset
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
25 */
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
26 #include "internal.h"
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
27 #include "buddyicon.h"
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
28 #include "conversation.h"
13555
b4d6a5e6853a [gaim-migrate @ 15932]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12996
diff changeset
29 #include "dbus-maybe.h"
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
30 #include "debug.h"
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
31 #include "imgstore.h"
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
32 #include "util.h"
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
33
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
34 typedef struct _PurpleBuddyIconData PurpleBuddyIconData;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
35
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
36 /* NOTE: Instances of this struct are allocated without zeroing the memory, so
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
37 * NOTE: be sure to update purple_buddy_icon_new() if you add members. */
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
38 struct _PurpleBuddyIcon
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
39 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
40 PurpleAccount *account; /**< The account the user is on. */
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
41 PurpleStoredImage *img; /**< The id of the stored image with the
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
42 the icon data. */
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
43 char *username; /**< The username the icon belongs to. */
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
44 char *checksum; /**< The protocol checksum. */
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
45 int ref_count; /**< The buddy icon reference count. */
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
46 };
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
47
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
48 static GHashTable *account_cache = NULL;
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
49 static GHashTable *icon_data_cache = NULL;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
50 static GHashTable *icon_file_cache = NULL;
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
51
22150
5743945cd926 compile
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22148
diff changeset
52 static void delete_buddy_icon_settings(PurpleBlistNode *node, const char *setting_name);
5743945cd926 compile
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22148
diff changeset
53
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
54 /* This one is used for both custom buddy icons
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
55 * on PurpleContacts and account icons. */
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
56 static GHashTable *pointer_icon_cache = NULL;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
57
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
58 static char *cache_dir = NULL;
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
59 static gboolean icon_caching = TRUE;
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
60
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
61 /* For ~/.gaim to ~/.purple migration. */
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
62 static char *old_icons_dir = NULL;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
63
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
64 static void
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
65 ref_filename(const char *filename)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
66 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
67 int refs;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
68
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
69 g_return_if_fail(filename != NULL);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
70
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
71 refs = GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
72
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
73 g_hash_table_insert(icon_file_cache, g_strdup(filename),
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
74 GINT_TO_POINTER(refs + 1));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
75 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
76
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
77 static void
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
78 unref_filename(const char *filename)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
79 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
80 int refs;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
81
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
82 if (filename == NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
83 return;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
84
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
85 refs = GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
86
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
87 if (refs == 1)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
88 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
89 g_hash_table_remove(icon_file_cache, filename);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
90 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
91 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
92 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
93 g_hash_table_insert(icon_file_cache, g_strdup(filename),
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
94 GINT_TO_POINTER(refs - 1));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
95 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
96 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
97
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
98 static void
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
99 purple_buddy_icon_data_cache(PurpleStoredImage *img)
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
100 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
101 const char *dirname;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
102 char *path;
21958
666685c4f8a9 Patch from eperez to make writing to buddy icon files atomic. Fixes #3528.
Sean Egan <seanegan@pidgin.im>
parents: 21673
diff changeset
103
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
104 g_return_if_fail(img != NULL);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
105
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
106 if (!purple_buddy_icons_is_caching())
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
107 return;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
108
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
109 dirname = purple_buddy_icons_get_cache_dir();
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
110 path = g_build_filename(dirname, purple_imgstore_get_filename(img), NULL);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
111
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
112 if (!g_file_test(dirname, G_FILE_TEST_IS_DIR))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
113 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
114 purple_debug_info("buddyicon", "Creating icon cache directory.\n");
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
115
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
116 if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
117 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
118 purple_debug_error("buddyicon",
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
119 "Unable to create directory %s: %s\n",
21389
e1dd8142bb87 replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20242
diff changeset
120 dirname, g_strerror(errno));
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
121 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
122 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
123
21958
666685c4f8a9 Patch from eperez to make writing to buddy icon files atomic. Fixes #3528.
Sean Egan <seanegan@pidgin.im>
parents: 21673
diff changeset
124 if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
666685c4f8a9 Patch from eperez to make writing to buddy icon files atomic. Fixes #3528.
Sean Egan <seanegan@pidgin.im>
parents: 21673
diff changeset
125 purple_util_write_data_to_file_absolute(path, purple_imgstore_get_data(img),
666685c4f8a9 Patch from eperez to make writing to buddy icon files atomic. Fixes #3528.
Sean Egan <seanegan@pidgin.im>
parents: 21673
diff changeset
126 purple_imgstore_get_size(img));
666685c4f8a9 Patch from eperez to make writing to buddy icon files atomic. Fixes #3528.
Sean Egan <seanegan@pidgin.im>
parents: 21673
diff changeset
127 } else {
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
128 purple_debug_error("buddyicon", "Unable to create file %s: %s\n",
22120
0b1eb3d12d1b We can't rely on g_strerror() being set by g_file_test().
Daniel Atallah <datallah@pidgin.im>
parents: 21958
diff changeset
129 path, "File already exists.");
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
130 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
131 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
132 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
133
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
134 static void
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
135 purple_buddy_icon_data_uncache_file(const char *filename)
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
136 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
137 const char *dirname;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
138 char *path;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
139
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
140 g_return_if_fail(filename != NULL);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
141
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
142 /* It's possible that there are other references to this icon
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
143 * cache file that are not currently loaded into memory. */
16438
64e892ac6180 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents: 16437
diff changeset
144 if (GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename)))
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
145 return;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
146
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
147 dirname = purple_buddy_icons_get_cache_dir();
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
148 path = g_build_filename(dirname, filename, NULL);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
149
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
150 if (g_file_test(path, G_FILE_TEST_EXISTS))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
151 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
152 if (g_unlink(path))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
153 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
154 purple_debug_error("buddyicon", "Failed to delete %s: %s\n",
21389
e1dd8142bb87 replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20242
diff changeset
155 path, g_strerror(errno));
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
156 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
157 else
16438
64e892ac6180 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents: 16437
diff changeset
158 {
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
159 purple_debug_info("buddyicon", "Deleted cache file: %s\n", path);
16438
64e892ac6180 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents: 16437
diff changeset
160 }
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
161 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
162
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
163 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
164 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
165
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
166 static gboolean
16531
98363f6cdc6c Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@pidgin.im>
parents: 16446
diff changeset
167 value_equals(gpointer key, gpointer value, gpointer user_data)
98363f6cdc6c Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@pidgin.im>
parents: 16446
diff changeset
168 {
98363f6cdc6c Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@pidgin.im>
parents: 16446
diff changeset
169 return (value == user_data);
98363f6cdc6c Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@pidgin.im>
parents: 16446
diff changeset
170 }
98363f6cdc6c Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@pidgin.im>
parents: 16446
diff changeset
171
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
172 static void
16740
c95b1a276ea1 Document the image-deleting signal.
Richard Laager <rlaager@pidgin.im>
parents: 16727
diff changeset
173 image_deleting_cb(const PurpleStoredImage *img, gpointer data)
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
174 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
175 const char *filename = purple_imgstore_get_filename(img);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
176
16679
59e879c13ee8 Fix a crash when removing a per-account icon. Here's my explanation:
Richard Laager <rlaager@pidgin.im>
parents: 16678
diff changeset
177 /* If there's no filename, it can't be one of our images. */
59e879c13ee8 Fix a crash when removing a per-account icon. Here's my explanation:
Richard Laager <rlaager@pidgin.im>
parents: 16678
diff changeset
178 if (filename == NULL)
59e879c13ee8 Fix a crash when removing a per-account icon. Here's my explanation:
Richard Laager <rlaager@pidgin.im>
parents: 16678
diff changeset
179 return;
59e879c13ee8 Fix a crash when removing a per-account icon. Here's my explanation:
Richard Laager <rlaager@pidgin.im>
parents: 16678
diff changeset
180
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
181 if (img == g_hash_table_lookup(icon_data_cache, filename))
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
182 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
183 purple_buddy_icon_data_uncache_file(filename);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
184 g_hash_table_remove(icon_data_cache, filename);
16531
98363f6cdc6c Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@pidgin.im>
parents: 16446
diff changeset
185
98363f6cdc6c Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@pidgin.im>
parents: 16446
diff changeset
186 /* We could make this O(1) by using another hash table, but
98363f6cdc6c Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@pidgin.im>
parents: 16446
diff changeset
187 * this is probably good enough. */
16775
8627d2560d40 Get rid of two harmless warnings:
Mark Doliner <markdoliner@pidgin.im>
parents: 16740
diff changeset
188 g_hash_table_foreach_remove(pointer_icon_cache, value_equals, (gpointer)img);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
189 }
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
190 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
191
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
192 static PurpleStoredImage *
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
193 purple_buddy_icon_data_new(guchar *icon_data, size_t icon_len, const char *filename)
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
194 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
195 char *file;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
196 PurpleStoredImage *img;
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
197
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
198 g_return_val_if_fail(icon_data != NULL, NULL);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
199 g_return_val_if_fail(icon_len > 0, NULL);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
200
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
201 if (filename == NULL)
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
202 {
18101
3ce21b5a182c A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents: 17033
diff changeset
203 file = purple_util_get_image_filename(icon_data, icon_len);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
204 if (file == NULL)
16539
75a20ae3a527 Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@pidgin.im>
parents: 16538
diff changeset
205 {
75a20ae3a527 Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@pidgin.im>
parents: 16538
diff changeset
206 g_free(icon_data);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
207 return NULL;
16539
75a20ae3a527 Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@pidgin.im>
parents: 16538
diff changeset
208 }
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
209 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
210 else
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
211 file = g_strdup(filename);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
212
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
213 if ((img = g_hash_table_lookup(icon_data_cache, file)))
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
214 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
215 g_free(file);
16539
75a20ae3a527 Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@pidgin.im>
parents: 16538
diff changeset
216 g_free(icon_data);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
217 return purple_imgstore_ref(img);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
218 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
219
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
220 img = purple_imgstore_add(icon_data, icon_len, file);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
221
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
222 /* This will take ownership of file and g_free it either now or later. */
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
223 g_hash_table_insert(icon_data_cache, file, img);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
224
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
225 purple_buddy_icon_data_cache(img);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
226
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
227 return img;
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
228 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
229
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
230 static PurpleBuddyIcon *
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
231 purple_buddy_icon_create(PurpleAccount *account, const char *username)
9396
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
232 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
233 PurpleBuddyIcon *icon;
9396
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
234 GHashTable *icon_cache;
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
235
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
236 /* This does not zero. See purple_buddy_icon_new() for
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
237 * information on which function allocates which member. */
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
238 icon = g_slice_new(PurpleBuddyIcon);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
239 PURPLE_DBUS_REGISTER_POINTER(icon, PurpleBuddyIcon);
9396
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
240
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
241 icon->account = account;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
242 icon->username = g_strdup(username);
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
243 icon->checksum = NULL;
16924
a061b2ff4cf7 Fix a reference counting bug.
Richard Laager <rlaager@pidgin.im>
parents: 16903
diff changeset
244 icon->ref_count = 1;
9396
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
245
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
246 icon_cache = g_hash_table_lookup(account_cache, account);
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
247
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
248 if (icon_cache == NULL)
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
249 {
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
250 icon_cache = g_hash_table_new(g_str_hash, g_str_equal);
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
251
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
252 g_hash_table_insert(account_cache, account, icon_cache);
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
253 }
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
254
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
255 g_hash_table_insert(icon_cache,
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
256 (char *)purple_buddy_icon_get_username(icon), icon);
9396
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
257 return icon;
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
258 }
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
259
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
260 PurpleBuddyIcon *
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
261 purple_buddy_icon_new(PurpleAccount *account, const char *username,
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
262 void *icon_data, size_t icon_len,
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
263 const char *checksum)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
264 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
265 PurpleBuddyIcon *icon;
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
266
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
267 g_return_val_if_fail(account != NULL, NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
268 g_return_val_if_fail(username != NULL, NULL);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
269 g_return_val_if_fail(icon_data != NULL, NULL);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
270 g_return_val_if_fail(icon_len > 0, NULL);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
271
16438
64e892ac6180 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents: 16437
diff changeset
272 /* purple_buddy_icons_find() does allocation, so be
64e892ac6180 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents: 16437
diff changeset
273 * sure to update it as well when members are added. */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
274 icon = purple_buddy_icons_find(account, username);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
275
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
276 /* purple_buddy_icon_create() sets account & username */
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
277 if (icon == NULL)
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
278 icon = purple_buddy_icon_create(account, username);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
279
16438
64e892ac6180 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents: 16437
diff changeset
280 /* purple_buddy_icon_set_data() sets img, but it
64e892ac6180 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents: 16437
diff changeset
281 * references img first, so we need to initialize it */
64e892ac6180 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents: 16437
diff changeset
282 icon->img = NULL;
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
283 purple_buddy_icon_set_data(icon, icon_data, icon_len, checksum);
11423
45f4ca09d1d6 [gaim-migrate @ 13660]
Richard Laager <rlaager@pidgin.im>
parents: 11338
diff changeset
284
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
285 return icon;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
286 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
287
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
288 PurpleBuddyIcon *
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
289 purple_buddy_icon_ref(PurpleBuddyIcon *icon)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
290 {
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
291 g_return_val_if_fail(icon != NULL, NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
292
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
293 icon->ref_count++;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
294
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
295 return icon;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
296 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
297
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
298 PurpleBuddyIcon *
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
299 purple_buddy_icon_unref(PurpleBuddyIcon *icon)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
300 {
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
301 if (icon == NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
302 return NULL;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
303
12250
5b14301dd1ec [gaim-migrate @ 14552]
Richard Laager <rlaager@pidgin.im>
parents: 12097
diff changeset
304 g_return_val_if_fail(icon->ref_count > 0, NULL);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
305
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
306 icon->ref_count--;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
307
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
308 if (icon->ref_count == 0)
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
309 {
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
310 GHashTable *icon_cache = g_hash_table_lookup(account_cache, purple_buddy_icon_get_account(icon));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
311
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
312 if (icon_cache != NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
313 g_hash_table_remove(icon_cache, purple_buddy_icon_get_username(icon));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
314
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
315 g_free(icon->username);
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
316 g_free(icon->checksum);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
317 purple_imgstore_unref(icon->img);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
318
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
319 PURPLE_DBUS_UNREGISTER_POINTER(icon);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
320 g_slice_free(PurpleBuddyIcon, icon);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
321
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
322 return NULL;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
323 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
324
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
325 return icon;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
326 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
327
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
328 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
329 purple_buddy_icon_update(PurpleBuddyIcon *icon)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
330 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
331 PurpleConversation *conv;
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
332 PurpleAccount *account;
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
333 const char *username;
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
334 PurpleBuddyIcon *icon_to_set;
16863
b98303c15033 Change a few functions to free a linked list while iterating through
Mark Doliner <markdoliner@pidgin.im>
parents: 16775
diff changeset
335 GSList *buddies;
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
336
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
337 g_return_if_fail(icon != NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
338
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
339 account = purple_buddy_icon_get_account(icon);
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
340 username = purple_buddy_icon_get_username(icon);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
341
16875
e1c6d9541cb9 Protect icon with ref/unref guards since it may be freed over the course of the while() loop. I thought this would fix #398, but something else is wrong, too.
Evan Schoenberg <evands@pidgin.im>
parents: 16874
diff changeset
342 /* If no data exists (icon->img == NULL), then call the functions below
e1c6d9541cb9 Protect icon with ref/unref guards since it may be freed over the course of the while() loop. I thought this would fix #398, but something else is wrong, too.
Evan Schoenberg <evands@pidgin.im>
parents: 16874
diff changeset
343 * with NULL to unset the icon. They will then unref the icon and it should
e1c6d9541cb9 Protect icon with ref/unref guards since it may be freed over the course of the while() loop. I thought this would fix #398, but something else is wrong, too.
Evan Schoenberg <evands@pidgin.im>
parents: 16874
diff changeset
344 * be destroyed. The only way it wouldn't be destroyed is if someone
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
345 * else is holding a reference to it, in which case they can kill
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
346 * the icon when they realize it has no data. */
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
347 icon_to_set = icon->img ? icon : NULL;
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
348
16875
e1c6d9541cb9 Protect icon with ref/unref guards since it may be freed over the course of the while() loop. I thought this would fix #398, but something else is wrong, too.
Evan Schoenberg <evands@pidgin.im>
parents: 16874
diff changeset
349 /* Ensure that icon remains valid throughout */
e1c6d9541cb9 Protect icon with ref/unref guards since it may be freed over the course of the while() loop. I thought this would fix #398, but something else is wrong, too.
Evan Schoenberg <evands@pidgin.im>
parents: 16874
diff changeset
350 if (icon) purple_buddy_icon_ref(icon);
e1c6d9541cb9 Protect icon with ref/unref guards since it may be freed over the course of the while() loop. I thought this would fix #398, but something else is wrong, too.
Evan Schoenberg <evands@pidgin.im>
parents: 16874
diff changeset
351
16863
b98303c15033 Change a few functions to free a linked list while iterating through
Mark Doliner <markdoliner@pidgin.im>
parents: 16775
diff changeset
352 buddies = purple_find_buddies(account, username);
b98303c15033 Change a few functions to free a linked list while iterating through
Mark Doliner <markdoliner@pidgin.im>
parents: 16775
diff changeset
353 while (buddies != NULL)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
354 {
16863
b98303c15033 Change a few functions to free a linked list while iterating through
Mark Doliner <markdoliner@pidgin.im>
parents: 16775
diff changeset
355 PurpleBuddy *buddy = (PurpleBuddy *)buddies->data;
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
356 char *old_icon;
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
357
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
358 purple_buddy_set_icon(buddy, icon_to_set);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
359 old_icon = g_strdup(purple_blist_node_get_string((PurpleBlistNode *)buddy,
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
360 "buddy_icon"));
16440
d4e3c52ce58b If we're not caching icons, then don't save the filename.
Richard Laager <rlaager@pidgin.im>
parents: 16439
diff changeset
361 if (icon->img && purple_buddy_icons_is_caching())
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
362 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
363 const char *filename = purple_imgstore_get_filename(icon->img);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
364 purple_blist_node_set_string((PurpleBlistNode *)buddy,
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
365 "buddy_icon",
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
366 filename);
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
367
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
368 if (icon->checksum && *icon->checksum)
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
369 {
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
370 purple_blist_node_set_string((PurpleBlistNode *)buddy,
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
371 "icon_checksum",
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
372 icon->checksum);
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
373 }
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
374 else
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
375 {
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
376 purple_blist_node_remove_setting((PurpleBlistNode *)buddy,
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
377 "icon_checksum");
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
378 }
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
379 ref_filename(filename);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
380 }
17033
27d9faa34ad1 Patch from ticket #819 from vampire
Richard Laager <rlaager@pidgin.im>
parents: 16924
diff changeset
381 else if (!icon->img)
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
382 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
383 purple_blist_node_remove_setting((PurpleBlistNode *)buddy, "buddy_icon");
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
384 purple_blist_node_remove_setting((PurpleBlistNode *)buddy, "icon_checksum");
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
385 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
386 unref_filename(old_icon);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
387 g_free(old_icon);
16863
b98303c15033 Change a few functions to free a linked list while iterating through
Mark Doliner <markdoliner@pidgin.im>
parents: 16775
diff changeset
388
b98303c15033 Change a few functions to free a linked list while iterating through
Mark Doliner <markdoliner@pidgin.im>
parents: 16775
diff changeset
389 buddies = g_slist_delete_link(buddies, buddies);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
390 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
391
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
392 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, username, account);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
393
10246
aa5bff72f94c [gaim-migrate @ 11386]
Mark Doliner <markdoliner@pidgin.im>
parents: 9801
diff changeset
394 if (conv != NULL)
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
395 purple_conv_im_set_icon(PURPLE_CONV_IM(conv), icon_to_set);
16875
e1c6d9541cb9 Protect icon with ref/unref guards since it may be freed over the course of the while() loop. I thought this would fix #398, but something else is wrong, too.
Evan Schoenberg <evands@pidgin.im>
parents: 16874
diff changeset
396
e1c6d9541cb9 Protect icon with ref/unref guards since it may be freed over the course of the while() loop. I thought this would fix #398, but something else is wrong, too.
Evan Schoenberg <evands@pidgin.im>
parents: 16874
diff changeset
397 /* icon's refcount was incremented above */
e1c6d9541cb9 Protect icon with ref/unref guards since it may be freed over the course of the while() loop. I thought this would fix #398, but something else is wrong, too.
Evan Schoenberg <evands@pidgin.im>
parents: 16874
diff changeset
398 if (icon) purple_buddy_icon_unref(icon);
11040
37e247d18e78 [gaim-migrate @ 12940]
Richard Laager <rlaager@pidgin.im>
parents: 11033
diff changeset
399 }
37e247d18e78 [gaim-migrate @ 12940]
Richard Laager <rlaager@pidgin.im>
parents: 11033
diff changeset
400
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
401 void
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
402 purple_buddy_icon_set_data(PurpleBuddyIcon *icon, guchar *data,
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
403 size_t len, const char *checksum)
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
404 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
405 PurpleStoredImage *old_img;
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
406
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
407 g_return_if_fail(icon != NULL);
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
408
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
409 old_img = icon->img;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
410 icon->img = NULL;
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
411
16539
75a20ae3a527 Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@pidgin.im>
parents: 16538
diff changeset
412 if (data != NULL)
16544
945caa0d6436 Kill some compiler warnings and TODOs of mine.
Richard Laager <rlaager@pidgin.im>
parents: 16539
diff changeset
413 {
16539
75a20ae3a527 Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@pidgin.im>
parents: 16538
diff changeset
414 if (len > 0)
75a20ae3a527 Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@pidgin.im>
parents: 16538
diff changeset
415 icon->img = purple_buddy_icon_data_new(data, len, NULL);
75a20ae3a527 Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@pidgin.im>
parents: 16538
diff changeset
416 else
75a20ae3a527 Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@pidgin.im>
parents: 16538
diff changeset
417 g_free(data);
16544
945caa0d6436 Kill some compiler warnings and TODOs of mine.
Richard Laager <rlaager@pidgin.im>
parents: 16539
diff changeset
418 }
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
419
16874
cd539323cabe Remove two warnings, one compile-time, one runtime. Plug two leaks, both runtime.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16863
diff changeset
420 g_free(icon->checksum);
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
421 icon->checksum = g_strdup(checksum);
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
422
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
423 purple_buddy_icon_update(icon);
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
424
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
425 purple_imgstore_unref(old_img);
15132
672c39839af1 [gaim-migrate @ 17854]
Mark Huetsch <markhuetsch@users.sourceforge.net>
parents: 15117
diff changeset
426 }
672c39839af1 [gaim-migrate @ 17854]
Mark Huetsch <markhuetsch@users.sourceforge.net>
parents: 15117
diff changeset
427
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
428 PurpleAccount *
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
429 purple_buddy_icon_get_account(const PurpleBuddyIcon *icon)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
430 {
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
431 g_return_val_if_fail(icon != NULL, NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
432
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
433 return icon->account;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
434 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
435
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
436 const char *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
437 purple_buddy_icon_get_username(const PurpleBuddyIcon *icon)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
438 {
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
439 g_return_val_if_fail(icon != NULL, NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
440
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
441 return icon->username;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
442 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
443
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
444 const char *
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
445 purple_buddy_icon_get_checksum(const PurpleBuddyIcon *icon)
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
446 {
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
447 g_return_val_if_fail(icon != NULL, NULL);
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
448
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
449 return icon->checksum;
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
450 }
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
451
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
452 gconstpointer
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
453 purple_buddy_icon_get_data(const PurpleBuddyIcon *icon, size_t *len)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
454 {
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
455 g_return_val_if_fail(icon != NULL, NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
456
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
457 if (icon->img)
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
458 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
459 if (len != NULL)
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
460 *len = purple_imgstore_get_size(icon->img);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
461
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
462 return purple_imgstore_get_data(icon->img);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
463 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
464
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
465 return NULL;
15132
672c39839af1 [gaim-migrate @ 17854]
Mark Huetsch <markhuetsch@users.sourceforge.net>
parents: 15117
diff changeset
466 }
672c39839af1 [gaim-migrate @ 17854]
Mark Huetsch <markhuetsch@users.sourceforge.net>
parents: 15117
diff changeset
467
672c39839af1 [gaim-migrate @ 17854]
Mark Huetsch <markhuetsch@users.sourceforge.net>
parents: 15117
diff changeset
468 const char *
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
469 purple_buddy_icon_get_extension(const PurpleBuddyIcon *icon)
10953
e5987ea70985 [gaim-migrate @ 12753]
Richard Laager <rlaager@pidgin.im>
parents: 10934
diff changeset
470 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
471 if (icon->img != NULL)
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
472 return purple_imgstore_get_extension(icon->img);
10953
e5987ea70985 [gaim-migrate @ 12753]
Richard Laager <rlaager@pidgin.im>
parents: 10934
diff changeset
473
e5987ea70985 [gaim-migrate @ 12753]
Richard Laager <rlaager@pidgin.im>
parents: 10934
diff changeset
474 return NULL;
e5987ea70985 [gaim-migrate @ 12753]
Richard Laager <rlaager@pidgin.im>
parents: 10934
diff changeset
475 }
e5987ea70985 [gaim-migrate @ 12753]
Richard Laager <rlaager@pidgin.im>
parents: 10934
diff changeset
476
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
477 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
478 purple_buddy_icons_set_for_user(PurpleAccount *account, const char *username,
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
479 void *icon_data, size_t icon_len,
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
480 const char *checksum)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
481 {
16900
e9f12eb06c5b Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@pidgin.im>
parents: 16863
diff changeset
482 GHashTable *icon_cache;
e9f12eb06c5b Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@pidgin.im>
parents: 16863
diff changeset
483 PurpleBuddyIcon *icon = NULL;
16537
763d885ff7a2 I'm stupid. If an icon doesn't exist, it's a good idea to create it when we want to fill it with data, not when we don't.
Richard Laager <rlaager@pidgin.im>
parents: 16534
diff changeset
484
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
485 g_return_if_fail(account != NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
486 g_return_if_fail(username != NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
487
16900
e9f12eb06c5b Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@pidgin.im>
parents: 16863
diff changeset
488 icon_cache = g_hash_table_lookup(account_cache, account);
e9f12eb06c5b Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@pidgin.im>
parents: 16863
diff changeset
489
e9f12eb06c5b Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@pidgin.im>
parents: 16863
diff changeset
490 if (icon_cache != NULL)
e9f12eb06c5b Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@pidgin.im>
parents: 16863
diff changeset
491 icon = g_hash_table_lookup(icon_cache, username);
9305
63a1b462a208 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
492
16537
763d885ff7a2 I'm stupid. If an icon doesn't exist, it's a good idea to create it when we want to fill it with data, not when we don't.
Richard Laager <rlaager@pidgin.im>
parents: 16534
diff changeset
493 if (icon != NULL)
763d885ff7a2 I'm stupid. If an icon doesn't exist, it's a good idea to create it when we want to fill it with data, not when we don't.
Richard Laager <rlaager@pidgin.im>
parents: 16534
diff changeset
494 purple_buddy_icon_set_data(icon, icon_data, icon_len, checksum);
16874
cd539323cabe Remove two warnings, one compile-time, one runtime. Plug two leaks, both runtime.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16863
diff changeset
495 else if (icon_data && icon_len > 0)
9305
63a1b462a208 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
496 {
20242
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
497 PurpleBuddyIcon *icon = purple_buddy_icon_new(account, username, icon_data, icon_len, checksum);
16900
e9f12eb06c5b Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@pidgin.im>
parents: 16863
diff changeset
498
20242
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
499 /* purple_buddy_icon_new() calls
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
500 * purple_buddy_icon_set_data(), which calls
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
501 * purple_buddy_icon_update(), which has the buddy list
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
502 * and conversations take references as appropriate.
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
503 * This function doesn't return icon, so we can't
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
504 * leave a reference dangling. */
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
505 purple_buddy_icon_unref(icon);
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
506 }
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
507 else
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
508 {
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
509 /* If the buddy list or a conversation was holding a
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
510 * reference, we'd have found the icon in the cache.
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
511 * Since we know we're deleting the icon, we only
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
512 * need a subset of purple_buddy_icon_update(). */
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
513
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
514 GSList *buddies = purple_find_buddies(account, username);
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
515 while (buddies != NULL)
16900
e9f12eb06c5b Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@pidgin.im>
parents: 16863
diff changeset
516 {
20242
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
517 PurpleBuddy *buddy = (PurpleBuddy *)buddies->data;
16900
e9f12eb06c5b Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@pidgin.im>
parents: 16863
diff changeset
518
20242
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
519 unref_filename(purple_blist_node_get_string((PurpleBlistNode *)buddy, "buddy_icon"));
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
520 purple_blist_node_remove_setting((PurpleBlistNode *)buddy, "buddy_icon");
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
521 purple_blist_node_remove_setting((PurpleBlistNode *)buddy, "icon_checksum");
16900
e9f12eb06c5b Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@pidgin.im>
parents: 16863
diff changeset
522
20242
a1310a256a1a applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20147
diff changeset
523 buddies = g_slist_delete_link(buddies, buddies);
16900
e9f12eb06c5b Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@pidgin.im>
parents: 16863
diff changeset
524 }
9305
63a1b462a208 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
525 }
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
526 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
527
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
528 char *purple_buddy_icon_get_full_path(PurpleBuddyIcon *icon)
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
529 {
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
530 char *path;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
531
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
532 g_return_val_if_fail(icon != NULL, NULL);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
533
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
534 if (icon->img == NULL)
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
535 return NULL;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
536
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
537 path = g_build_filename(purple_buddy_icons_get_cache_dir(),
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
538 purple_imgstore_get_filename(icon->img), NULL);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
539 if (!g_file_test(path, G_FILE_TEST_EXISTS))
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
540 {
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
541 g_free(path);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
542 return NULL;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
543 }
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
544 return path;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
545 }
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
546
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
547 const char *
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
548 purple_buddy_icons_get_checksum_for_user(PurpleBuddy *buddy)
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
549 {
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
550 return purple_blist_node_get_string((PurpleBlistNode*)buddy,
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
551 "icon_checksum");
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
552 }
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
553
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
554 static gboolean
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
555 read_icon_file(const char *path, guchar **data, size_t *len)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
556 {
16532
070f046b1316 Switch to using g_file_get_contents() instead of our own code.
Richard Laager <rlaager@pidgin.im>
parents: 16531
diff changeset
557 GError *err = NULL;
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
558
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
559 if (!g_file_get_contents(path, (gchar **)data, len, &err))
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
560 {
16532
070f046b1316 Switch to using g_file_get_contents() instead of our own code.
Richard Laager <rlaager@pidgin.im>
parents: 16531
diff changeset
561 purple_debug_error("buddyicon", "Error reading %s: %s\n",
070f046b1316 Switch to using g_file_get_contents() instead of our own code.
Richard Laager <rlaager@pidgin.im>
parents: 16531
diff changeset
562 path, err->message);
070f046b1316 Switch to using g_file_get_contents() instead of our own code.
Richard Laager <rlaager@pidgin.im>
parents: 16531
diff changeset
563 g_error_free(err);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
564
16532
070f046b1316 Switch to using g_file_get_contents() instead of our own code.
Richard Laager <rlaager@pidgin.im>
parents: 16531
diff changeset
565 return FALSE;
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
566 }
16532
070f046b1316 Switch to using g_file_get_contents() instead of our own code.
Richard Laager <rlaager@pidgin.im>
parents: 16531
diff changeset
567
070f046b1316 Switch to using g_file_get_contents() instead of our own code.
Richard Laager <rlaager@pidgin.im>
parents: 16531
diff changeset
568 return TRUE;
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
569 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
570
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
571 PurpleBuddyIcon *
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
572 purple_buddy_icons_find(PurpleAccount *account, const char *username)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
573 {
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
574 GHashTable *icon_cache;
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
575 PurpleBuddyIcon *icon = NULL;
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
576
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
577 g_return_val_if_fail(account != NULL, NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
578 g_return_val_if_fail(username != NULL, NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
579
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
580 icon_cache = g_hash_table_lookup(account_cache, account);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
581
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
582 if ((icon_cache == NULL) || ((icon = g_hash_table_lookup(icon_cache, username)) == NULL))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
583 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
584 PurpleBuddy *b = purple_find_buddy(account, username);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
585 const char *protocol_icon_file;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
586 const char *dirname;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
587 gboolean caching;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
588 guchar *data;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
589 size_t len;
9396
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
590
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
591 if (!b)
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
592 return NULL;
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
593
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
594 protocol_icon_file = purple_blist_node_get_string((PurpleBlistNode*)b, "buddy_icon");
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
595
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
596 if (protocol_icon_file == NULL)
9396
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
597 return NULL;
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
598
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
599 dirname = purple_buddy_icons_get_cache_dir();
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
600
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
601 caching = purple_buddy_icons_is_caching();
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
602 /* By disabling caching temporarily, we avoid a loop
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
603 * and don't have to add special code through several
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
604 * functions. */
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
605 purple_buddy_icons_set_caching(FALSE);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
606
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
607 if (protocol_icon_file != NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
608 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
609 char *path = g_build_filename(dirname, protocol_icon_file, NULL);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
610 if (read_icon_file(path, &data, &len))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
611 {
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
612 const char *checksum;
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
613
16874
cd539323cabe Remove two warnings, one compile-time, one runtime. Plug two leaks, both runtime.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16863
diff changeset
614 icon = purple_buddy_icon_create(account, username);
16438
64e892ac6180 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents: 16437
diff changeset
615 icon->img = NULL;
16874
cd539323cabe Remove two warnings, one compile-time, one runtime. Plug two leaks, both runtime.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16863
diff changeset
616 checksum = purple_blist_node_get_string((PurpleBlistNode*)b, "icon_checksum");
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
617 purple_buddy_icon_set_data(icon, data, len, checksum);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
618 }
22148
66b0ed947da5 If the cached buddy icon can't be loaded, delete the preferences which point to it. Among other things, this fixes OSCAR buddy icon retrieval when the cache has been removed - since previously the icon hash was kept around and was used to determine that (so far as the prpl could tell) no icon retrieval was needed, libpurple would never have an icon for the contact.
Evan Schoenberg <evands@pidgin.im>
parents: 22120
diff changeset
619 else
66b0ed947da5 If the cached buddy icon can't be loaded, delete the preferences which point to it. Among other things, this fixes OSCAR buddy icon retrieval when the cache has been removed - since previously the icon hash was kept around and was used to determine that (so far as the prpl could tell) no icon retrieval was needed, libpurple would never have an icon for the contact.
Evan Schoenberg <evands@pidgin.im>
parents: 22120
diff changeset
620 delete_buddy_icon_settings((PurpleBlistNode*)b, "buddy_icon");
22154
b7ab5a12d97a Remove spurious braces
Evan Schoenberg <evands@pidgin.im>
parents: 22150
diff changeset
621
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
622 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
623 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
624
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
625 purple_buddy_icons_set_caching(caching);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
626 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
627
22161
be6ccc274119 Apparently "nil" is an Objective-C thing
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 22158
diff changeset
628 return (icon ? purple_buddy_icon_ref(icon) : NULL);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
629 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
630
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
631 gboolean
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
632 purple_buddy_icons_has_custom_icon(PurpleContact *contact)
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
633 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
634 g_return_val_if_fail(contact != NULL, FALSE);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
635
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
636 return (purple_blist_node_get_string((PurpleBlistNode*)contact, "custom_buddy_icon") != NULL);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
637 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
638
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
639 PurpleStoredImage *
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
640 purple_buddy_icons_find_account_icon(PurpleAccount *account)
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
641 {
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
642 PurpleStoredImage *img;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
643 const char *account_icon_file;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
644 const char *dirname;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
645 char *path;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
646 guchar *data;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
647 size_t len;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
648
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
649 g_return_val_if_fail(account != NULL, NULL);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
650
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
651 if ((img = g_hash_table_lookup(pointer_icon_cache, account)))
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
652 {
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
653 return purple_imgstore_ref(img);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
654 }
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
655
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
656 account_icon_file = purple_account_get_string(account, "buddy_icon", NULL);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
657
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
658 if (account_icon_file == NULL)
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
659 return NULL;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
660
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
661 dirname = purple_buddy_icons_get_cache_dir();
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
662 path = g_build_filename(dirname, account_icon_file, NULL);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
663
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
664 if (read_icon_file(path, &data, &len))
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
665 {
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
666 g_free(path);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
667 img = purple_buddy_icon_data_new(data, len, account_icon_file);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
668 g_hash_table_insert(pointer_icon_cache, account, img);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
669 return img;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
670 }
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
671 g_free(path);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
672
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
673 return NULL;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
674 }
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
675
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
676 PurpleStoredImage *
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
677 purple_buddy_icons_set_account_icon(PurpleAccount *account,
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
678 guchar *icon_data, size_t icon_len)
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
679 {
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
680 PurpleStoredImage *old_img;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
681 PurpleStoredImage *img = NULL;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
682 char *old_icon;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
683
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
684 if (icon_data != NULL && icon_len > 0)
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
685 {
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
686 img = purple_buddy_icon_data_new(icon_data, icon_len, NULL);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
687 }
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
688
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
689 old_icon = g_strdup(purple_account_get_string(account, "buddy_icon", NULL));
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
690 if (img && purple_buddy_icons_is_caching())
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
691 {
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
692 const char *filename = purple_imgstore_get_filename(img);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
693 purple_account_set_string(account, "buddy_icon", filename);
16677
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
694 purple_account_set_int(account, "buddy_icon_timestamp", time(NULL));
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
695 ref_filename(filename);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
696 }
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
697 else
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
698 {
16544
945caa0d6436 Kill some compiler warnings and TODOs of mine.
Richard Laager <rlaager@pidgin.im>
parents: 16539
diff changeset
699 purple_account_set_string(account, "buddy_icon", NULL);
16677
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
700 purple_account_set_int(account, "buddy_icon_timestamp", 0);
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
701 }
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
702 unref_filename(old_icon);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
703
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
704 if (purple_account_is_connected(account))
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
705 {
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
706 PurpleConnection *gc;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
707 PurplePluginProtocolInfo *prpl_info;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
708
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
709 gc = purple_account_get_connection(account);
22390
d22357d5c7ba Kill off gc->prpl in the core everywhere but connection.c (when the struct
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22307
diff changeset
710 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc));
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
711
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
712 if (prpl_info && prpl_info->set_buddy_icon)
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
713 prpl_info->set_buddy_icon(gc, img);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
714 }
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
715
21673
f26901ad164e prpl->set_buddy_icon may keep a reference to PurpleStoredImage, move the
Ka-Hing Cheung <khc@pidgin.im>
parents: 21389
diff changeset
716 if ((old_img = g_hash_table_lookup(pointer_icon_cache, account)))
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
717 purple_imgstore_unref(old_img);
16674
95bfc8f3775c Fix assertion when creating a new account.
Daniel Atallah <datallah@pidgin.im>
parents: 16657
diff changeset
718 else if (old_icon)
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
719 {
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
720 /* The old icon may not have been loaded into memory. In that
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
721 * case, we'll need to uncache the filename. The filenames
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
722 * are ref-counted, so this is safe. */
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
723 purple_buddy_icon_data_uncache_file(old_icon);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
724 }
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
725 g_free(old_icon);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
726
22307
a74a3d935fc8 We need to store the img in the hashtable only after we have removed the old
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22168
diff changeset
727 if (img)
a74a3d935fc8 We need to store the img in the hashtable only after we have removed the old
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22168
diff changeset
728 g_hash_table_insert(pointer_icon_cache, account, img);
a74a3d935fc8 We need to store the img in the hashtable only after we have removed the old
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22168
diff changeset
729 else
a74a3d935fc8 We need to store the img in the hashtable only after we have removed the old
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22168
diff changeset
730 g_hash_table_remove(pointer_icon_cache, account);
a74a3d935fc8 We need to store the img in the hashtable only after we have removed the old
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22168
diff changeset
731
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
732 return img;
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
733 }
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
734
16677
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
735 time_t
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
736 purple_buddy_icons_get_account_icon_timestamp(PurpleAccount *account)
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
737 {
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
738 time_t ret;
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
739
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
740 g_return_val_if_fail(account != NULL, 0);
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
741
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
742 ret = purple_account_get_int(account, "buddy_icon_timestamp", 0);
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
743
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
744 /* This deals with migration cases. */
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
745 if (ret == 0 && purple_account_get_string(account, "buddy_icon", NULL) != NULL)
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
746 {
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
747 ret = time(NULL);
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
748 purple_account_set_int(account, "buddy_icon_timestamp", ret);
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
749 }
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
750
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
751 return ret;
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
752 }
7cd57586cdbf The OSCAR timestamp stuff.
Richard Laager <rlaager@pidgin.im>
parents: 16669
diff changeset
753
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
754 PurpleStoredImage *
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
755 purple_buddy_icons_find_custom_icon(PurpleContact *contact)
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
756 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
757 PurpleStoredImage *img;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
758 const char *custom_icon_file;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
759 const char *dirname;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
760 char *path;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
761 guchar *data;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
762 size_t len;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
763
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
764 g_return_val_if_fail(contact != NULL, NULL);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
765
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
766 if ((img = g_hash_table_lookup(pointer_icon_cache, contact)))
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
767 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
768 return purple_imgstore_ref(img);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
769 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
770
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
771 custom_icon_file = purple_blist_node_get_string((PurpleBlistNode*)contact, "custom_buddy_icon");
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
772
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
773 if (custom_icon_file == NULL)
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
774 return NULL;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
775
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
776 dirname = purple_buddy_icons_get_cache_dir();
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
777 path = g_build_filename(dirname, custom_icon_file, NULL);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
778
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
779 if (read_icon_file(path, &data, &len))
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
780 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
781 g_free(path);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
782 img = purple_buddy_icon_data_new(data, len, custom_icon_file);
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
783 g_hash_table_insert(pointer_icon_cache, contact, img);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
784 return img;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
785 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
786 g_free(path);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
787
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
788 return NULL;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
789 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
790
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
791 PurpleStoredImage *
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
792 purple_buddy_icons_set_custom_icon(PurpleContact *contact,
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
793 guchar *icon_data, size_t icon_len)
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
794 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
795 PurpleStoredImage *old_img;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
796 PurpleStoredImage *img = NULL;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
797 char *old_icon;
16446
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
798 PurpleBlistNode *child;
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
799
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
800 old_img = g_hash_table_lookup(pointer_icon_cache, contact);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
801
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
802 if (icon_data != NULL && icon_len > 0)
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
803 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
804 img = purple_buddy_icon_data_new(icon_data, icon_len, NULL);
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
805 }
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
806
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
807 old_icon = g_strdup(purple_blist_node_get_string((PurpleBlistNode *)contact,
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
808 "custom_buddy_icon"));
16440
d4e3c52ce58b If we're not caching icons, then don't save the filename.
Richard Laager <rlaager@pidgin.im>
parents: 16439
diff changeset
809 if (img && purple_buddy_icons_is_caching())
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
810 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
811 const char *filename = purple_imgstore_get_filename(img);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
812 purple_blist_node_set_string((PurpleBlistNode *)contact,
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
813 "custom_buddy_icon",
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
814 filename);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
815 ref_filename(filename);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
816 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
817 else
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
818 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
819 purple_blist_node_remove_setting((PurpleBlistNode *)contact,
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
820 "custom_buddy_icon");
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
821 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
822 unref_filename(old_icon);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
823
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
824 if (img)
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
825 g_hash_table_insert(pointer_icon_cache, contact, img);
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
826 else
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
827 g_hash_table_remove(pointer_icon_cache, contact);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
828
16446
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
829 for (child = contact->node.child ; child ; child = child->next)
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
830 {
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
831 PurpleBuddy *buddy;
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
832 PurpleConversation *conv;
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
833
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
834 if (!PURPLE_BLIST_NODE_IS_BUDDY(child))
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
835 continue;
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
836
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
837 buddy = (PurpleBuddy *)child;
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
838
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
839 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
840 purple_buddy_get_name(buddy),
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
841 purple_buddy_get_account(buddy));
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
842 if (conv)
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
843 purple_conversation_update(conv, PURPLE_CONV_UPDATE_ICON);
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
844
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
845 purple_blist_update_buddy_icon(buddy);
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
846 }
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
847
16533
91e3e84b05f2 Fix a bug with removing custom buddy icons.
Richard Laager <rlaager@pidgin.im>
parents: 16532
diff changeset
848 if (old_img)
91e3e84b05f2 Fix a bug with removing custom buddy icons.
Richard Laager <rlaager@pidgin.im>
parents: 16532
diff changeset
849 purple_imgstore_unref(old_img);
16727
01a24ea58d60 This gets rid of a g_log error when uncache-ing a NULL file.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16696
diff changeset
850 else if (old_icon)
16533
91e3e84b05f2 Fix a bug with removing custom buddy icons.
Richard Laager <rlaager@pidgin.im>
parents: 16532
diff changeset
851 {
91e3e84b05f2 Fix a bug with removing custom buddy icons.
Richard Laager <rlaager@pidgin.im>
parents: 16532
diff changeset
852 /* The old icon may not have been loaded into memory. In that
91e3e84b05f2 Fix a bug with removing custom buddy icons.
Richard Laager <rlaager@pidgin.im>
parents: 16532
diff changeset
853 * case, we'll need to uncache the filename. The filenames
91e3e84b05f2 Fix a bug with removing custom buddy icons.
Richard Laager <rlaager@pidgin.im>
parents: 16532
diff changeset
854 * are ref-counted, so this is safe. */
91e3e84b05f2 Fix a bug with removing custom buddy icons.
Richard Laager <rlaager@pidgin.im>
parents: 16532
diff changeset
855 purple_buddy_icon_data_uncache_file(old_icon);
91e3e84b05f2 Fix a bug with removing custom buddy icons.
Richard Laager <rlaager@pidgin.im>
parents: 16532
diff changeset
856 }
91e3e84b05f2 Fix a bug with removing custom buddy icons.
Richard Laager <rlaager@pidgin.im>
parents: 16532
diff changeset
857 g_free(old_icon);
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
858
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
859 return img;
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
860 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
861
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
862 void
16696
450ba3bd5b63 The GNOME coding guidelines recommend prefixing internal symbols with an underscore.
Richard Laager <rlaager@pidgin.im>
parents: 16690
diff changeset
863 _purple_buddy_icon_set_old_icons_dir(const char *dirname)
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
864 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
865 old_icons_dir = g_strdup(dirname);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
866 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
867
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
868 static void
16614
1cca48d1018b nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@pidgin.im>
parents: 16597
diff changeset
869 delete_buddy_icon_settings(PurpleBlistNode *node, const char *setting_name)
1cca48d1018b nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@pidgin.im>
parents: 16597
diff changeset
870 {
1cca48d1018b nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@pidgin.im>
parents: 16597
diff changeset
871 purple_blist_node_remove_setting(node, setting_name);
1cca48d1018b nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@pidgin.im>
parents: 16597
diff changeset
872
1cca48d1018b nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@pidgin.im>
parents: 16597
diff changeset
873 if (!strcmp(setting_name, "buddy_icon"))
1cca48d1018b nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@pidgin.im>
parents: 16597
diff changeset
874 {
1cca48d1018b nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@pidgin.im>
parents: 16597
diff changeset
875 purple_blist_node_remove_setting(node, "avatar_hash");
1cca48d1018b nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@pidgin.im>
parents: 16597
diff changeset
876 purple_blist_node_remove_setting(node, "icon_checksum");
1cca48d1018b nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@pidgin.im>
parents: 16597
diff changeset
877 }
1cca48d1018b nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@pidgin.im>
parents: 16597
diff changeset
878 }
1cca48d1018b nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@pidgin.im>
parents: 16597
diff changeset
879
1cca48d1018b nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@pidgin.im>
parents: 16597
diff changeset
880 static void
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
881 migrate_buddy_icon(PurpleBlistNode *node, const char *setting_name,
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
882 const char *dirname, const char *filename)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
883 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
884 char *path;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
885
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
886 if (filename[0] != '/')
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
887 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
888 path = g_build_filename(dirname, filename, NULL);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
889 if (g_file_test(path, G_FILE_TEST_EXISTS))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
890 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
891 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
892 return;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
893 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
894 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
895
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
896 path = g_build_filename(old_icons_dir, filename, NULL);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
897 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
898 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
899 path = g_strdup(filename);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
900
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
901 if (g_file_test(path, G_FILE_TEST_EXISTS))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
902 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
903 guchar *icon_data;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
904 size_t icon_len;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
905 FILE *file;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
906 char *new_filename;
9747
5c89f93ad4dc [gaim-migrate @ 10613]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 9396
diff changeset
907
16680
3a672630db5a Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@pidgin.im>
parents: 16679
diff changeset
908 if (!read_icon_file(path, &icon_data, &icon_len))
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
909 {
16680
3a672630db5a Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@pidgin.im>
parents: 16679
diff changeset
910 g_free(path);
3a672630db5a Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@pidgin.im>
parents: 16679
diff changeset
911 delete_buddy_icon_settings(node, setting_name);
3a672630db5a Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@pidgin.im>
parents: 16679
diff changeset
912 return;
3a672630db5a Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@pidgin.im>
parents: 16679
diff changeset
913 }
3a672630db5a Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@pidgin.im>
parents: 16679
diff changeset
914
3a672630db5a Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@pidgin.im>
parents: 16679
diff changeset
915 if (icon_data == NULL || icon_len <= 0)
3a672630db5a Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@pidgin.im>
parents: 16679
diff changeset
916 {
3a672630db5a Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@pidgin.im>
parents: 16679
diff changeset
917 /* This really applies to the icon_len check.
3a672630db5a Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@pidgin.im>
parents: 16679
diff changeset
918 * icon_data should never be NULL if
3a672630db5a Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@pidgin.im>
parents: 16679
diff changeset
919 * read_icon_file() returns TRUE. */
3a672630db5a Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@pidgin.im>
parents: 16679
diff changeset
920 purple_debug_error("buddyicon", "Empty buddy icon file: %s\n", path);
16614
1cca48d1018b nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@pidgin.im>
parents: 16597
diff changeset
921 delete_buddy_icon_settings(node, setting_name);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
922 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
923 return;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
924 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
925
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
926 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
927
18101
3ce21b5a182c A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@pidgin.im>
parents: 17033
diff changeset
928 new_filename = purple_util_get_image_filename(icon_data, icon_len);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
929 if (new_filename == NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
930 {
16680
3a672630db5a Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@pidgin.im>
parents: 16679
diff changeset
931 purple_debug_error("buddyicon",
3a672630db5a Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@pidgin.im>
parents: 16679
diff changeset
932 "New icon filename is NULL. This should never happen! "
3a672630db5a Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@pidgin.im>
parents: 16679
diff changeset
933 "The old filename was: %s\n", path);
16614
1cca48d1018b nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@pidgin.im>
parents: 16597
diff changeset
934 delete_buddy_icon_settings(node, setting_name);
16680
3a672630db5a Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@pidgin.im>
parents: 16679
diff changeset
935 g_return_if_reached();
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
936 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
937
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
938 path = g_build_filename(dirname, new_filename, NULL);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
939 if ((file = g_fopen(path, "wb")) != NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
940 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
941 if (!fwrite(icon_data, icon_len, 1, file))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
942 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
943 purple_debug_error("buddyicon", "Error writing %s: %s\n",
21389
e1dd8142bb87 replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20242
diff changeset
944 path, g_strerror(errno));
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
945 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
946 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
947 purple_debug_info("buddyicon", "Wrote migrated cache file: %s\n", path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
948
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
949 fclose(file);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
950 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
951 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
952 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
953 purple_debug_error("buddyicon", "Unable to create file %s: %s\n",
21389
e1dd8142bb87 replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20242
diff changeset
954 path, g_strerror(errno));
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
955 g_free(new_filename);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
956 g_free(path);
16614
1cca48d1018b nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@pidgin.im>
parents: 16597
diff changeset
957
1cca48d1018b nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@pidgin.im>
parents: 16597
diff changeset
958 delete_buddy_icon_settings(node, setting_name);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
959 return;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
960 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
961 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
962
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
963 purple_blist_node_set_string(node,
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
964 setting_name,
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
965 new_filename);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
966 ref_filename(new_filename);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
967
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
968 g_free(new_filename);
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
969
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
970 if (!strcmp(setting_name, "buddy_icon"))
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
971 {
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
972 const char *hash;
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
973
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
974 hash = purple_blist_node_get_string(node, "avatar_hash");
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
975 if (hash != NULL)
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
976 {
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
977 purple_blist_node_set_string(node, "icon_checksum", hash);
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
978 purple_blist_node_remove_setting(node, "avatar_hash");
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
979 }
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
980 else
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
981 {
16632
799021ef0cf4 Make this yahoo hack compile.
Richard Laager <rlaager@pidgin.im>
parents: 16631
diff changeset
982 PurpleAccount *account = purple_buddy_get_account((PurpleBuddy *)node);
16631
a3f6bf325328 In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@pidgin.im>
parents: 16616
diff changeset
983 const char *prpl_id = purple_account_get_protocol_id(account);
a3f6bf325328 In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@pidgin.im>
parents: 16616
diff changeset
984
a3f6bf325328 In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@pidgin.im>
parents: 16616
diff changeset
985 if (!strcmp(prpl_id, "prpl-yahoo"))
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
986 {
16631
a3f6bf325328 In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@pidgin.im>
parents: 16616
diff changeset
987 int checksum = purple_blist_node_get_int(node, "icon_checksum");
a3f6bf325328 In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@pidgin.im>
parents: 16616
diff changeset
988 if (checksum != 0)
a3f6bf325328 In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@pidgin.im>
parents: 16616
diff changeset
989 {
a3f6bf325328 In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@pidgin.im>
parents: 16616
diff changeset
990 char *checksum_str = g_strdup_printf("%i", checksum);
a3f6bf325328 In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@pidgin.im>
parents: 16616
diff changeset
991 purple_blist_node_remove_setting(node, "icon_checksum");
a3f6bf325328 In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@pidgin.im>
parents: 16616
diff changeset
992 purple_blist_node_set_string(node, "icon_checksum", checksum_str);
a3f6bf325328 In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@pidgin.im>
parents: 16616
diff changeset
993 g_free(checksum_str);
a3f6bf325328 In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@pidgin.im>
parents: 16616
diff changeset
994 }
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
995 }
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
996 }
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
997 }
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
998 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
999 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1000 {
16680
3a672630db5a Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@pidgin.im>
parents: 16679
diff changeset
1001 purple_debug_error("buddyicon", "Old icon file doesn't exist: %s\n", path);
16614
1cca48d1018b nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@pidgin.im>
parents: 16597
diff changeset
1002 delete_buddy_icon_settings(node, setting_name);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1003 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1004 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1005 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1006
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1007 void
16696
450ba3bd5b63 The GNOME coding guidelines recommend prefixing internal symbols with an underscore.
Richard Laager <rlaager@pidgin.im>
parents: 16690
diff changeset
1008 _purple_buddy_icons_account_loaded_cb()
16565
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1009 {
16567
4d79ee03965d This is probably needed to compile.
Richard Laager <rlaager@pidgin.im>
parents: 16566
diff changeset
1010 const char *dirname = purple_buddy_icons_get_cache_dir();
18122
9bf9970c1b6a disapproval of revision '2d8ea56b90971e7851442d96b7d74ecb4f052126'
Richard Laager <rlaager@pidgin.im>
parents: 18121
diff changeset
1011 GList *cur;
16565
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1012
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1013 for (cur = purple_accounts_get_all(); cur != NULL; cur = cur->next)
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1014 {
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1015 PurpleAccount *account = cur->data;
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1016 const char *account_icon_file = purple_account_get_string(account, "buddy_icon", NULL);
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1017
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1018 if (account_icon_file != NULL)
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1019 {
16568
b26c36d6cf2d I really shouldn't commit before compiling.
Richard Laager <rlaager@pidgin.im>
parents: 16567
diff changeset
1020 char *path = g_build_filename(dirname, account_icon_file, NULL);
b26c36d6cf2d I really shouldn't commit before compiling.
Richard Laager <rlaager@pidgin.im>
parents: 16567
diff changeset
1021 if (!g_file_test(path, G_FILE_TEST_EXISTS))
16565
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1022 {
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1023 purple_account_set_string(account, "buddy_icon", NULL);
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1024 } else {
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1025 ref_filename(account_icon_file);
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1026 }
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1027 g_free(path);
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1028 }
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1029 }
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1030 }
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1031
f5cd28cc7367 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@pidgin.im>
parents: 16544
diff changeset
1032 void
16696
450ba3bd5b63 The GNOME coding guidelines recommend prefixing internal symbols with an underscore.
Richard Laager <rlaager@pidgin.im>
parents: 16690
diff changeset
1033 _purple_buddy_icons_blist_loaded_cb()
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1034 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1035 PurpleBlistNode *node = purple_blist_get_root();
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1036 const char *dirname = purple_buddy_icons_get_cache_dir();
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1037
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1038 /* Doing this once here saves having to check it inside a loop. */
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1039 if (old_icons_dir != NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1040 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1041 if (!g_file_test(dirname, G_FILE_TEST_IS_DIR))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1042 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1043 purple_debug_info("buddyicon", "Creating icon cache directory.\n");
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1044
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1045 if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1046 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1047 purple_debug_error("buddyicon",
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1048 "Unable to create directory %s: %s\n",
21389
e1dd8142bb87 replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20242
diff changeset
1049 dirname, g_strerror(errno));
9396
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
1050 }
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
1051 }
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
1052 }
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
1053
16657
63e53570702c Whitespace fix from patch in ticket #383
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16632
diff changeset
1054 while (node != NULL)
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1055 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1056 if (PURPLE_BLIST_NODE_IS_BUDDY(node))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1057 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1058 const char *filename;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1059
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1060 filename = purple_blist_node_get_string(node, "buddy_icon");
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1061 if (filename != NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1062 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1063 if (old_icons_dir != NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1064 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1065 migrate_buddy_icon(node,
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1066 "buddy_icon",
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1067 dirname, filename);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1068 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1069 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1070 {
16446
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
1071 char *path = g_build_filename(dirname, filename, NULL);
16566
98c93d211a45 Fix a small-but-serious bug with the code to ref the buddy icons at load.
Richard Laager <rlaager@pidgin.im>
parents: 16565
diff changeset
1072 if (!g_file_test(path, G_FILE_TEST_EXISTS))
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
1073 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
1074 purple_blist_node_remove_setting(node,
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
1075 "buddy_icon");
16534
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
1076 purple_blist_node_remove_setting(node,
2ab9e23f99d9 Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents: 16533
diff changeset
1077 "icon_checksum");
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
1078 }
16531
98363f6cdc6c Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@pidgin.im>
parents: 16446
diff changeset
1079 else
98363f6cdc6c Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@pidgin.im>
parents: 16446
diff changeset
1080 ref_filename(filename);
16446
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
1081 g_free(path);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1082 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1083 }
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
1084 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
1085 else if (PURPLE_BLIST_NODE_IS_CONTACT(node))
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
1086 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
1087 const char *filename;
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1088
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1089 filename = purple_blist_node_get_string(node, "custom_buddy_icon");
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1090 if (filename != NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1091 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1092 if (old_icons_dir != NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1093 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1094 migrate_buddy_icon(node,
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1095 "custom_buddy_icon",
16615
179e7ea58483 Minor whitespace tweak.
Richard Laager <rlaager@pidgin.im>
parents: 16614
diff changeset
1096 dirname, filename);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1097 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1098 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1099 {
16446
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
1100 char *path = g_build_filename(dirname, filename, NULL);
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
1101 if (!g_file_test(path, G_FILE_TEST_EXISTS))
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
1102 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
1103 purple_blist_node_remove_setting(node,
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
1104 "custom_buddy_icon");
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
1105 }
16531
98363f6cdc6c Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@pidgin.im>
parents: 16446
diff changeset
1106 else
98363f6cdc6c Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@pidgin.im>
parents: 16446
diff changeset
1107 ref_filename(filename);
16446
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16440
diff changeset
1108 g_free(path);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1109 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1110 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1111 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1112 node = purple_blist_node_next(node, TRUE);
16657
63e53570702c Whitespace fix from patch in ticket #383
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16632
diff changeset
1113 }
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1114 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1115
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1116 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1117 purple_buddy_icons_set_caching(gboolean caching)
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1118 {
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1119 icon_caching = caching;
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1120 }
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1121
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1122 gboolean
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1123 purple_buddy_icons_is_caching(void)
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1124 {
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1125 return icon_caching;
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1126 }
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1127
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1128 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1129 purple_buddy_icons_set_cache_dir(const char *dir)
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1130 {
10811
6b7ac5a9dd35 [gaim-migrate @ 12464]
Richard Laager <rlaager@pidgin.im>
parents: 10589
diff changeset
1131 g_return_if_fail(dir != NULL);
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1132
13934
c554909e9ff6 [gaim-migrate @ 16342]
Mark Doliner <markdoliner@pidgin.im>
parents: 13555
diff changeset
1133 g_free(cache_dir);
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1134 cache_dir = g_strdup(dir);
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1135 }
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1136
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1137 const char *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1138 purple_buddy_icons_get_cache_dir(void)
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1139 {
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1140 return cache_dir;
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1141 }
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1142
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1143 void *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1144 purple_buddy_icons_get_handle()
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1145 {
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1146 static int handle;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1147
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1148 return &handle;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1149 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1150
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1151 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1152 purple_buddy_icons_init()
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1153 {
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1154 account_cache = g_hash_table_new_full(
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1155 g_direct_hash, g_direct_equal,
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1156 NULL, (GFreeFunc)g_hash_table_destroy);
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
1157
16669
69babfdf63e6 19:00:43 Ka-Hing Cheung (khc): rlaager: shouldn't we give g_free as the key free function for icon_data_cache?
Richard Laager <rlaager@pidgin.im>
parents: 16657
diff changeset
1158 icon_data_cache = g_hash_table_new_full(g_str_hash, g_str_equal,
69babfdf63e6 19:00:43 Ka-Hing Cheung (khc): rlaager: shouldn't we give g_free as the key free function for icon_data_cache?
Richard Laager <rlaager@pidgin.im>
parents: 16657
diff changeset
1159 g_free, NULL);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1160 icon_file_cache = g_hash_table_new_full(g_str_hash, g_str_equal,
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1161 g_free, NULL);
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
1162 pointer_icon_cache = g_hash_table_new(g_direct_hash, g_direct_equal);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1163
22159
9539d60302c9 If the UI sets a cache directory before purple_buddy_icons_init() is called
Evan Schoenberg <evands@pidgin.im>
parents: 22158
diff changeset
1164 if (!cache_dir)
9539d60302c9 If the UI sets a cache directory before purple_buddy_icons_init() is called
Evan Schoenberg <evands@pidgin.im>
parents: 22158
diff changeset
1165 cache_dir = g_build_filename(purple_user_dir(), "icons", NULL);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
1166
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
1167 purple_signal_connect(purple_imgstore_get_handle(), "image-deleting",
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
1168 purple_buddy_icons_get_handle(),
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
1169 G_CALLBACK(image_deleting_cb), NULL);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1170 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1171
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1172 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1173 purple_buddy_icons_uninit()
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1174 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
1175 purple_signals_disconnect_by_handle(purple_buddy_icons_get_handle());
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
1176
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1177 g_hash_table_destroy(account_cache);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1178 g_hash_table_destroy(icon_data_cache);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1179 g_hash_table_destroy(icon_file_cache);
16538
c7e61e2917c9 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents: 16537
diff changeset
1180 g_hash_table_destroy(pointer_icon_cache);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
1181 g_free(old_icons_dir);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1182 }
10483
e7b09a8b1f52 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
1183
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1184 void purple_buddy_icon_get_scale_size(PurpleBuddyIconSpec *spec, int *width, int *height)
10483
e7b09a8b1f52 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
1185 {
15284
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1186 int new_width, new_height;
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1187
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1188 new_width = *width;
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1189 new_height = *height;
10523
ef52a88a8512 [gaim-migrate @ 11840]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10483
diff changeset
1190
15284
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1191 if (*width < spec->min_width)
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1192 new_width = spec->min_width;
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1193 else if (*width > spec->max_width)
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1194 new_width = spec->max_width;
10483
e7b09a8b1f52 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
1195
15284
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1196 if (*height < spec->min_height)
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1197 new_height = spec->min_height;
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1198 else if (*height > spec->max_height)
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1199 new_height = spec->max_height;
10523
ef52a88a8512 [gaim-migrate @ 11840]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10483
diff changeset
1200
15284
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1201 /* preserve aspect ratio */
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1202 if ((double)*height * (double)new_width >
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1203 (double)*width * (double)new_height) {
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1204 new_width = 0.5 + (double)*width * (double)new_height / (double)*height;
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1205 } else {
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1206 new_height = 0.5 + (double)*height * (double)new_width / (double)*width;
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1207 }
10523
ef52a88a8512 [gaim-migrate @ 11840]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10483
diff changeset
1208
15284
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1209 *width = new_width;
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
1210 *height = new_height;
10483
e7b09a8b1f52 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
1211 }

mercurial