annotate libpurple/buddyicon.c @ 24942:7d6866244106

make this togglable via env rather than #define
author Ka-Hing Cheung <khc@hxbc.us>
date Sun, 11 Jan 2009 22:27:23 +0000
parents 8282911d5e17
children 5ebfa814b9e8 9c0337d4b878
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /**
22606
76af23621e19 Better documentation.
Mark Doliner <mark@kingant.net>
parents: 22405
diff changeset
2 * @file buddyicon.c Buddy Icon API
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 * @ingroup core
20074
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 19680
diff changeset
4 */
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 19680
diff changeset
5
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 19680
diff changeset
6 /* purple
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
8 * Purple is the legal property of its developers, whose names are too numerous
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 * to list here. Please refer to the COPYRIGHT file distributed with this
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 * source distribution.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 * This program is free software; you can redistribute it and/or modify
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 * it under the terms of the GNU General Public License as published by
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 * the Free Software Foundation; either version 2 of the License, or
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 * (at your option) any later version.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 * This program is distributed in the hope that it will be useful,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 * GNU General Public License for more details.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 * You should have received a copy of the GNU General Public License
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 * along with this program; if not, write to the Free Software
19680
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 18063
diff changeset
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 */
24292
8282911d5e17 Build everything with the *_DISABLE_DEPRECATED flags set. This allows us
Richard Laager <rlaager@wiktel.com>
parents: 24005
diff changeset
26 #define _PURPLE_BUDDYICON_C_
8282911d5e17 Build everything with the *_DISABLE_DEPRECATED flags set. This allows us
Richard Laager <rlaager@wiktel.com>
parents: 24005
diff changeset
27
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28 #include "internal.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 #include "buddyicon.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 #include "conversation.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 #include "dbus-maybe.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 #include "debug.h"
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
33 #include "imgstore.h"
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 #include "util.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
36 /* NOTE: Instances of this struct are allocated without zeroing the memory, so
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
37 * NOTE: be sure to update purple_buddy_icon_new() if you add members. */
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
38 struct _PurpleBuddyIcon
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
39 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
40 PurpleAccount *account; /**< The account the user is on. */
22609
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
41 PurpleStoredImage *img; /**< The stored image containing
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
42 the icon data. */
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
43 char *username; /**< The username the icon belongs to. */
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
44 char *checksum; /**< The protocol checksum. */
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
45 int ref_count; /**< The buddy icon reference count. */
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
46 };
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
47
22609
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
48 /**
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
49 * This is the big grand daddy hash table that contains references to
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
50 * everybody's buddy icons.
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
51 *
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
52 * Key is a PurpleAccount.
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
53 * Value is another hash table, usually referred to as "icon_cache."
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
54 * For this inner hash table:
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
55 * Key is the username of the buddy whose icon is being stored.
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
56 * Value is the PurpleBuddyIcon for this buddy.
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
57 */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 static GHashTable *account_cache = NULL;
22609
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
59
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
60 /**
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
61 * This hash table contains a bunch of PurpleStoredImages that are
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
62 * shared across all accounts.
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
63 *
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
64 * Key is the filename for this image as constructed by
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
65 * purple_util_get_image_filename(). So it is the base16 encoded
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
66 * sha-1 hash plus an appropriate file extension. For example:
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
67 * "0f4972d17d1e70e751c43c90c948e72efbff9796.gif"
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
68 *
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
69 * The value is a PurpleStoredImage containing the icon data. These
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
70 * images are reference counted, and when the count reaches 0
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
71 * imgstore.c emits the image-deleting signal and we remove the image
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
72 * from the hash table (but it might still be saved on disk, if the
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
73 * icon is being used by offline accounts or some such).
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
74 */
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
75 static GHashTable *icon_data_cache = NULL;
22609
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
76
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
77 /**
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
78 * This hash table contains references counts for how many times each
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
79 * icon in the ~/.purple/icons/ directory is being used. It's pretty
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
80 * crazy. It maintains the reference count across sessions, too, so
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
81 * if you exit Pidgin then this hash table is reconstructed the next
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
82 * time Pidgin starts.
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
83 *
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
84 * Key is the filename for this image as constructed by
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
85 * purple_util_get_image_filename(). So it is the base16 encoded
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
86 * sha-1 hash plus an appropriate file extension. For example:
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
87 * "0f4972d17d1e70e751c43c90c948e72efbff9796.gif"
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
88 *
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
89 * The value is a GINT_TO_POINTER count of the number of times this
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
90 * icon is used. So if four of your buddies are using an icon, and
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
91 * you have the icon set for two of your accounts, then this number
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
92 * will be six. When this reference count reaches 0 the icon will
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
93 * be deleted from disk.
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
94 */
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
95 static GHashTable *icon_file_cache = NULL;
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
96
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
97 /**
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
98 * This hash table is used for both custom buddy icons on PurpleBlistNodes and
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
99 * account icons.
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
100 */
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
101 static GHashTable *pointer_icon_cache = NULL;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
102
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
103 static char *cache_dir = NULL;
22609
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
104
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
105 /** "Should icons be cached to disk?" */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106 static gboolean icon_caching = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
108 /* For ~/.gaim to ~/.purple migration. */
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
109 static char *old_icons_dir = NULL;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
110
22609
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
111 static void delete_buddy_icon_settings(PurpleBlistNode *node, const char *setting_name);
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
112
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
113 /*
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
114 * Begin functions for dealing with the on-disk icon cache
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
115 */
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
116
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
117 static void
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
118 ref_filename(const char *filename)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
119 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
120 int refs;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
121
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
122 g_return_if_fail(filename != NULL);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
123
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
124 refs = GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename));
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
125
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
126 g_hash_table_insert(icon_file_cache, g_strdup(filename),
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
127 GINT_TO_POINTER(refs + 1));
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
128 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
129
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
130 static void
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
131 unref_filename(const char *filename)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
132 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
133 int refs;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
134
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
135 if (filename == NULL)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
136 return;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
137
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
138 refs = GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename));
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
139
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
140 if (refs == 1)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
141 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
142 g_hash_table_remove(icon_file_cache, filename);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
143 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
144 else
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
145 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
146 g_hash_table_insert(icon_file_cache, g_strdup(filename),
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
147 GINT_TO_POINTER(refs - 1));
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
148 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
149 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
150
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
151 static void
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
152 purple_buddy_icon_data_cache(PurpleStoredImage *img)
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
153 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
154 const char *dirname;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
155 char *path;
21843
a3bc0682e98d Patch from eperez to make writing to buddy icon files atomic. Fixes #3528.
Sean Egan <seanegan@gmail.com>
parents: 21588
diff changeset
156
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
157 g_return_if_fail(img != NULL);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
158
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
159 if (!purple_buddy_icons_is_caching())
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
160 return;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
161
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
162 dirname = purple_buddy_icons_get_cache_dir();
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
163 path = g_build_filename(dirname, purple_imgstore_get_filename(img), NULL);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
164
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
165 if (!g_file_test(dirname, G_FILE_TEST_IS_DIR))
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
166 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
167 purple_debug_info("buddyicon", "Creating icon cache directory.\n");
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
168
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
169 if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
170 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
171 purple_debug_error("buddyicon",
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
172 "Unable to create directory %s: %s\n",
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20350
diff changeset
173 dirname, g_strerror(errno));
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
174 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
175 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
176
22405
9a12b7f5b1f5 Just write out the buddy icon file; there's no need to check to see if it exists. This is for the cache, and if the blist.xml gets out of sync with the cache on disk (for example, because the user moves the blist.xml file out of the way), the existing code will never update the cached icon again.
Evan Schoenberg <evan.s@dreskin.net>
parents: 22401
diff changeset
177 purple_util_write_data_to_file_absolute(path, purple_imgstore_get_data(img),
9a12b7f5b1f5 Just write out the buddy icon file; there's no need to check to see if it exists. This is for the cache, and if the blist.xml gets out of sync with the cache on disk (for example, because the user moves the blist.xml file out of the way), the existing code will never update the cached icon again.
Evan Schoenberg <evan.s@dreskin.net>
parents: 22401
diff changeset
178 purple_imgstore_get_size(img));
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
179 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
180 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
181
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
182 static void
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
183 purple_buddy_icon_data_uncache_file(const char *filename)
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
184 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
185 const char *dirname;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
186 char *path;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
187
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
188 g_return_if_fail(filename != NULL);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
189
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
190 /* It's possible that there are other references to this icon
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
191 * cache file that are not currently loaded into memory. */
16376
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
192 if (GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename)))
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
193 return;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
194
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
195 dirname = purple_buddy_icons_get_cache_dir();
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
196 path = g_build_filename(dirname, filename, NULL);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
197
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
198 if (g_file_test(path, G_FILE_TEST_EXISTS))
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
199 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
200 if (g_unlink(path))
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
201 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
202 purple_debug_error("buddyicon", "Failed to delete %s: %s\n",
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20350
diff changeset
203 path, g_strerror(errno));
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
204 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
205 else
16376
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
206 {
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
207 purple_debug_info("buddyicon", "Deleted cache file: %s\n", path);
16376
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
208 }
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
209 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
210
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
211 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
212 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
213
22609
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
214 /*
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
215 * End functions for dealing with the on-disk icon cache
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
216 */
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
217
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
218 /*
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
219 * Begin functions for dealing with the in-memory icon cache
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
220 */
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
221
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
222 static gboolean
16383
05033ae856b2 Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
223 value_equals(gpointer key, gpointer value, gpointer user_data)
05033ae856b2 Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
224 {
05033ae856b2 Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
225 return (value == user_data);
05033ae856b2 Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
226 }
05033ae856b2 Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
227
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
228 static void
16688
61ddeb85ab86 Document the image-deleting signal.
Richard Laager <rlaager@wiktel.com>
parents: 16667
diff changeset
229 image_deleting_cb(const PurpleStoredImage *img, gpointer data)
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
230 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
231 const char *filename = purple_imgstore_get_filename(img);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
232
16628
36981d83b20c Fix a crash when removing a per-account icon. Here's my explanation:
Richard Laager <rlaager@wiktel.com>
parents: 16622
diff changeset
233 /* If there's no filename, it can't be one of our images. */
36981d83b20c Fix a crash when removing a per-account icon. Here's my explanation:
Richard Laager <rlaager@wiktel.com>
parents: 16622
diff changeset
234 if (filename == NULL)
36981d83b20c Fix a crash when removing a per-account icon. Here's my explanation:
Richard Laager <rlaager@wiktel.com>
parents: 16622
diff changeset
235 return;
36981d83b20c Fix a crash when removing a per-account icon. Here's my explanation:
Richard Laager <rlaager@wiktel.com>
parents: 16622
diff changeset
236
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
237 if (img == g_hash_table_lookup(icon_data_cache, filename))
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
238 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
239 purple_buddy_icon_data_uncache_file(filename);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
240 g_hash_table_remove(icon_data_cache, filename);
16383
05033ae856b2 Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
241
05033ae856b2 Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
242 /* We could make this O(1) by using another hash table, but
05033ae856b2 Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
243 * this is probably good enough. */
16710
77cfd9bd6536 Get rid of two harmless warnings:
Mark Doliner <mark@kingant.net>
parents: 16688
diff changeset
244 g_hash_table_foreach_remove(pointer_icon_cache, value_equals, (gpointer)img);
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
245 }
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
246 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
247
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
248 static PurpleStoredImage *
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
249 purple_buddy_icon_data_new(guchar *icon_data, size_t icon_len, const char *filename)
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
250 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
251 char *file;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
252 PurpleStoredImage *img;
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
253
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
254 g_return_val_if_fail(icon_data != NULL, NULL);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
255 g_return_val_if_fail(icon_len > 0, NULL);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
256
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
257 if (filename == NULL)
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
258 {
18039
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 16981
diff changeset
259 file = purple_util_get_image_filename(icon_data, icon_len);
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
260 if (file == NULL)
16391
24bbd7e46bfe Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@wiktel.com>
parents: 16390
diff changeset
261 {
24bbd7e46bfe Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@wiktel.com>
parents: 16390
diff changeset
262 g_free(icon_data);
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
263 return NULL;
16391
24bbd7e46bfe Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@wiktel.com>
parents: 16390
diff changeset
264 }
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
265 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
266 else
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
267 file = g_strdup(filename);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
268
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
269 if ((img = g_hash_table_lookup(icon_data_cache, file)))
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
270 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
271 g_free(file);
16391
24bbd7e46bfe Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@wiktel.com>
parents: 16390
diff changeset
272 g_free(icon_data);
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
273 return purple_imgstore_ref(img);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
274 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
275
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
276 img = purple_imgstore_add(icon_data, icon_len, file);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
277
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
278 /* This will take ownership of file and g_free it either now or later. */
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
279 g_hash_table_insert(icon_data_cache, file, img);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
280
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
281 purple_buddy_icon_data_cache(img);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
282
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
283 return img;
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
284 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
285
22609
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
286 /*
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
287 * End functions for dealing with the in-memory icon cache
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
288 */
eccdd341dc6e Documentation changes
Mark Doliner <mark@kingant.net>
parents: 22606
diff changeset
289
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
290 static PurpleBuddyIcon *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
291 purple_buddy_icon_create(PurpleAccount *account, const char *username)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
292 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
293 PurpleBuddyIcon *icon;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
294 GHashTable *icon_cache;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
295
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
296 /* This does not zero. See purple_buddy_icon_new() for
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
297 * information on which function allocates which member. */
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
298 icon = g_slice_new(PurpleBuddyIcon);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
299 PURPLE_DBUS_REGISTER_POINTER(icon, PurpleBuddyIcon);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
300
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
301 icon->account = account;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
302 icon->username = g_strdup(username);
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
303 icon->checksum = NULL;
16879
a1858493abe2 Fix a reference counting bug.
Richard Laager <rlaager@wiktel.com>
parents: 16858
diff changeset
304 icon->ref_count = 1;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
305
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
306 icon_cache = g_hash_table_lookup(account_cache, account);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
307
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
308 if (icon_cache == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
309 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
310 icon_cache = g_hash_table_new(g_str_hash, g_str_equal);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
311
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
312 g_hash_table_insert(account_cache, account, icon_cache);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
313 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
314
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
315 g_hash_table_insert(icon_cache,
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
316 (char *)purple_buddy_icon_get_username(icon), icon);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
317 return icon;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
318 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
319
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
320 PurpleBuddyIcon *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
321 purple_buddy_icon_new(PurpleAccount *account, const char *username,
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
322 void *icon_data, size_t icon_len,
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
323 const char *checksum)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
324 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
325 PurpleBuddyIcon *icon;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
326
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
327 g_return_val_if_fail(account != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
328 g_return_val_if_fail(username != NULL, NULL);
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
329 g_return_val_if_fail(icon_data != NULL, NULL);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
330 g_return_val_if_fail(icon_len > 0, NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
331
16376
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
332 /* purple_buddy_icons_find() does allocation, so be
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
333 * sure to update it as well when members are added. */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
334 icon = purple_buddy_icons_find(account, username);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
335
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
336 /* purple_buddy_icon_create() sets account & username */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
337 if (icon == NULL)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
338 icon = purple_buddy_icon_create(account, username);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
339
16376
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
340 /* purple_buddy_icon_set_data() sets img, but it
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
341 * references img first, so we need to initialize it */
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
342 icon->img = NULL;
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
343 purple_buddy_icon_set_data(icon, icon_data, icon_len, checksum);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
344
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
345 return icon;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
346 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
347
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
348 PurpleBuddyIcon *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
349 purple_buddy_icon_ref(PurpleBuddyIcon *icon)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
350 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
351 g_return_val_if_fail(icon != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
352
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
353 icon->ref_count++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
354
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
355 return icon;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
356 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
357
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
358 PurpleBuddyIcon *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
359 purple_buddy_icon_unref(PurpleBuddyIcon *icon)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
360 {
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
361 if (icon == NULL)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
362 return NULL;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
363
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
364 g_return_val_if_fail(icon->ref_count > 0, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
365
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
366 icon->ref_count--;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
367
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
368 if (icon->ref_count == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
369 {
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
370 GHashTable *icon_cache = g_hash_table_lookup(account_cache, purple_buddy_icon_get_account(icon));
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
371
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
372 if (icon_cache != NULL)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
373 g_hash_table_remove(icon_cache, purple_buddy_icon_get_username(icon));
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
374
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
375 g_free(icon->username);
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
376 g_free(icon->checksum);
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
377 purple_imgstore_unref(icon->img);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
378
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
379 PURPLE_DBUS_UNREGISTER_POINTER(icon);
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
380 g_slice_free(PurpleBuddyIcon, icon);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
381
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
382 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
383 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
384
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
385 return icon;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
386 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
387
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
388 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
389 purple_buddy_icon_update(PurpleBuddyIcon *icon)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
390 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
391 PurpleConversation *conv;
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
392 PurpleAccount *account;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
393 const char *username;
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
394 PurpleBuddyIcon *icon_to_set;
16817
10f175539cfe Change a few functions to free a linked list while iterating through
Mark Doliner <mark@kingant.net>
parents: 16710
diff changeset
395 GSList *buddies;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
396
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
397 g_return_if_fail(icon != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
398
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
399 account = purple_buddy_icon_get_account(icon);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
400 username = purple_buddy_icon_get_username(icon);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
401
16833
52c776782b95 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 <evan.s@dreskin.net>
parents: 16832
diff changeset
402 /* If no data exists (icon->img == NULL), then call the functions below
52c776782b95 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 <evan.s@dreskin.net>
parents: 16832
diff changeset
403 * with NULL to unset the icon. They will then unref the icon and it should
52c776782b95 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 <evan.s@dreskin.net>
parents: 16832
diff changeset
404 * be destroyed. The only way it wouldn't be destroyed is if someone
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
405 * else is holding a reference to it, in which case they can kill
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
406 * the icon when they realize it has no data. */
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
407 icon_to_set = icon->img ? icon : NULL;
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
408
16833
52c776782b95 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 <evan.s@dreskin.net>
parents: 16832
diff changeset
409 /* Ensure that icon remains valid throughout */
52c776782b95 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 <evan.s@dreskin.net>
parents: 16832
diff changeset
410 if (icon) purple_buddy_icon_ref(icon);
52c776782b95 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 <evan.s@dreskin.net>
parents: 16832
diff changeset
411
16817
10f175539cfe Change a few functions to free a linked list while iterating through
Mark Doliner <mark@kingant.net>
parents: 16710
diff changeset
412 buddies = purple_find_buddies(account, username);
10f175539cfe Change a few functions to free a linked list while iterating through
Mark Doliner <mark@kingant.net>
parents: 16710
diff changeset
413 while (buddies != NULL)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
414 {
16817
10f175539cfe Change a few functions to free a linked list while iterating through
Mark Doliner <mark@kingant.net>
parents: 16710
diff changeset
415 PurpleBuddy *buddy = (PurpleBuddy *)buddies->data;
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
416 char *old_icon;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
417
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
418 purple_buddy_set_icon(buddy, icon_to_set);
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
419 old_icon = g_strdup(purple_blist_node_get_string((PurpleBlistNode *)buddy,
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
420 "buddy_icon"));
16378
bae921154351 If we're not caching icons, then don't save the filename.
Richard Laager <rlaager@wiktel.com>
parents: 16377
diff changeset
421 if (icon->img && purple_buddy_icons_is_caching())
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
422 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
423 const char *filename = purple_imgstore_get_filename(icon->img);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
424 purple_blist_node_set_string((PurpleBlistNode *)buddy,
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
425 "buddy_icon",
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
426 filename);
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
427
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
428 if (icon->checksum && *icon->checksum)
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
429 {
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
430 purple_blist_node_set_string((PurpleBlistNode *)buddy,
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
431 "icon_checksum",
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
432 icon->checksum);
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
433 }
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
434 else
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
435 {
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
436 purple_blist_node_remove_setting((PurpleBlistNode *)buddy,
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
437 "icon_checksum");
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
438 }
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
439 ref_filename(filename);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
440 }
16981
a520e48dbfef Patch from ticket #819 from vampire
Richard Laager <rlaager@wiktel.com>
parents: 16879
diff changeset
441 else if (!icon->img)
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
442 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
443 purple_blist_node_remove_setting((PurpleBlistNode *)buddy, "buddy_icon");
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
444 purple_blist_node_remove_setting((PurpleBlistNode *)buddy, "icon_checksum");
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
445 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
446 unref_filename(old_icon);
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
447 g_free(old_icon);
16817
10f175539cfe Change a few functions to free a linked list while iterating through
Mark Doliner <mark@kingant.net>
parents: 16710
diff changeset
448
10f175539cfe Change a few functions to free a linked list while iterating through
Mark Doliner <mark@kingant.net>
parents: 16710
diff changeset
449 buddies = g_slist_delete_link(buddies, buddies);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
450 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
451
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
452 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, username, account);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
453
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
454 if (conv != NULL)
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
455 purple_conv_im_set_icon(PURPLE_CONV_IM(conv), icon_to_set);
16833
52c776782b95 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 <evan.s@dreskin.net>
parents: 16832
diff changeset
456
52c776782b95 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 <evan.s@dreskin.net>
parents: 16832
diff changeset
457 /* icon's refcount was incremented above */
52c776782b95 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 <evan.s@dreskin.net>
parents: 16832
diff changeset
458 if (icon) purple_buddy_icon_unref(icon);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
459 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
460
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
461 void
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
462 purple_buddy_icon_set_data(PurpleBuddyIcon *icon, guchar *data,
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
463 size_t len, const char *checksum)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
464 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
465 PurpleStoredImage *old_img;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
466
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
467 g_return_if_fail(icon != NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
468
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
469 old_img = icon->img;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
470 icon->img = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
471
16391
24bbd7e46bfe Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@wiktel.com>
parents: 16390
diff changeset
472 if (data != NULL)
16482
3be560001d26 Kill some compiler warnings and TODOs of mine.
Richard Laager <rlaager@wiktel.com>
parents: 16391
diff changeset
473 {
16391
24bbd7e46bfe Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@wiktel.com>
parents: 16390
diff changeset
474 if (len > 0)
24bbd7e46bfe Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@wiktel.com>
parents: 16390
diff changeset
475 icon->img = purple_buddy_icon_data_new(data, len, NULL);
24bbd7e46bfe Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@wiktel.com>
parents: 16390
diff changeset
476 else
24bbd7e46bfe Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@wiktel.com>
parents: 16390
diff changeset
477 g_free(data);
16482
3be560001d26 Kill some compiler warnings and TODOs of mine.
Richard Laager <rlaager@wiktel.com>
parents: 16391
diff changeset
478 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
479
16832
844ed0418744 Remove two warnings, one compile-time, one runtime. Plug two leaks, both runtime.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 16817
diff changeset
480 g_free(icon->checksum);
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
481 icon->checksum = g_strdup(checksum);
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
482
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
483 purple_buddy_icon_update(icon);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
484
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
485 purple_imgstore_unref(old_img);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
486 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
487
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
488 PurpleAccount *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
489 purple_buddy_icon_get_account(const PurpleBuddyIcon *icon)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
490 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
491 g_return_val_if_fail(icon != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
492
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
493 return icon->account;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
494 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
495
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
496 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
497 purple_buddy_icon_get_username(const PurpleBuddyIcon *icon)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
498 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
499 g_return_val_if_fail(icon != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
500
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
501 return icon->username;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
502 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
503
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
504 const char *
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
505 purple_buddy_icon_get_checksum(const PurpleBuddyIcon *icon)
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
506 {
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
507 g_return_val_if_fail(icon != NULL, NULL);
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
508
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
509 return icon->checksum;
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
510 }
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
511
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
512 gconstpointer
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
513 purple_buddy_icon_get_data(const PurpleBuddyIcon *icon, size_t *len)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
514 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
515 g_return_val_if_fail(icon != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
516
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
517 if (icon->img)
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
518 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
519 if (len != NULL)
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
520 *len = purple_imgstore_get_size(icon->img);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
521
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
522 return purple_imgstore_get_data(icon->img);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
523 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
524
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
525 return NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
526 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
527
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
528 const char *
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
529 purple_buddy_icon_get_extension(const PurpleBuddyIcon *icon)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
530 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
531 if (icon->img != NULL)
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
532 return purple_imgstore_get_extension(icon->img);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
533
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
534 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
535 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
536
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
537 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
538 purple_buddy_icons_set_for_user(PurpleAccount *account, const char *username,
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
539 void *icon_data, size_t icon_len,
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
540 const char *checksum)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
541 {
16828
56823a55581a Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@wiktel.com>
parents: 16817
diff changeset
542 GHashTable *icon_cache;
56823a55581a Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@wiktel.com>
parents: 16817
diff changeset
543 PurpleBuddyIcon *icon = NULL;
16389
493ca924c199 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@wiktel.com>
parents: 16386
diff changeset
544
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
545 g_return_if_fail(account != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
546 g_return_if_fail(username != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
547
16828
56823a55581a Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@wiktel.com>
parents: 16817
diff changeset
548 icon_cache = g_hash_table_lookup(account_cache, account);
56823a55581a Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@wiktel.com>
parents: 16817
diff changeset
549
56823a55581a Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@wiktel.com>
parents: 16817
diff changeset
550 if (icon_cache != NULL)
56823a55581a Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@wiktel.com>
parents: 16817
diff changeset
551 icon = g_hash_table_lookup(icon_cache, username);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
552
16389
493ca924c199 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@wiktel.com>
parents: 16386
diff changeset
553 if (icon != NULL)
493ca924c199 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@wiktel.com>
parents: 16386
diff changeset
554 purple_buddy_icon_set_data(icon, icon_data, icon_len, checksum);
16832
844ed0418744 Remove two warnings, one compile-time, one runtime. Plug two leaks, both runtime.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 16817
diff changeset
555 else if (icon_data && icon_len > 0)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
556 {
20350
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
557 PurpleBuddyIcon *icon = purple_buddy_icon_new(account, username, icon_data, icon_len, checksum);
16828
56823a55581a Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@wiktel.com>
parents: 16817
diff changeset
558
20350
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
559 /* purple_buddy_icon_new() calls
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
560 * purple_buddy_icon_set_data(), which calls
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
561 * purple_buddy_icon_update(), which has the buddy list
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
562 * and conversations take references as appropriate.
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
563 * This function doesn't return icon, so we can't
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
564 * leave a reference dangling. */
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
565 purple_buddy_icon_unref(icon);
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
566 }
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
567 else
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
568 {
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
569 /* If the buddy list or a conversation was holding a
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
570 * reference, we'd have found the icon in the cache.
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
571 * Since we know we're deleting the icon, we only
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
572 * need a subset of purple_buddy_icon_update(). */
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
573
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
574 GSList *buddies = purple_find_buddies(account, username);
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
575 while (buddies != NULL)
16828
56823a55581a Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@wiktel.com>
parents: 16817
diff changeset
576 {
20350
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
577 PurpleBuddy *buddy = (PurpleBuddy *)buddies->data;
16828
56823a55581a Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@wiktel.com>
parents: 16817
diff changeset
578
20350
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
579 unref_filename(purple_blist_node_get_string((PurpleBlistNode *)buddy, "buddy_icon"));
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
580 purple_blist_node_remove_setting((PurpleBlistNode *)buddy, "buddy_icon");
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
581 purple_blist_node_remove_setting((PurpleBlistNode *)buddy, "icon_checksum");
16828
56823a55581a Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@wiktel.com>
parents: 16817
diff changeset
582
20350
4d4eb6831722 applied changes from 3ae1e4b3dac8092886b4b8ab961d8d505433b4c4
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
583 buddies = g_slist_delete_link(buddies, buddies);
16828
56823a55581a Rework purple_buddy_icons_find() to return a reference for the caller, which
Richard Laager <rlaager@wiktel.com>
parents: 16817
diff changeset
584 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
585 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
586 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
587
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
588 char *purple_buddy_icon_get_full_path(PurpleBuddyIcon *icon)
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
589 {
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
590 char *path;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
591
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
592 g_return_val_if_fail(icon != NULL, NULL);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
593
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
594 if (icon->img == NULL)
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
595 return NULL;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
596
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
597 path = g_build_filename(purple_buddy_icons_get_cache_dir(),
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
598 purple_imgstore_get_filename(icon->img), NULL);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
599 if (!g_file_test(path, G_FILE_TEST_EXISTS))
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
600 {
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
601 g_free(path);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
602 return NULL;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
603 }
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
604 return path;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
605 }
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
606
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
607 const char *
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
608 purple_buddy_icons_get_checksum_for_user(PurpleBuddy *buddy)
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
609 {
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
610 return purple_blist_node_get_string((PurpleBlistNode*)buddy,
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
611 "icon_checksum");
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
612 }
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
613
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
614 static gboolean
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
615 read_icon_file(const char *path, guchar **data, size_t *len)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
616 {
16384
54ea8863b8e8 Switch to using g_file_get_contents() instead of our own code.
Richard Laager <rlaager@wiktel.com>
parents: 16383
diff changeset
617 GError *err = NULL;
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
618
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
619 if (!g_file_get_contents(path, (gchar **)data, len, &err))
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
620 {
16384
54ea8863b8e8 Switch to using g_file_get_contents() instead of our own code.
Richard Laager <rlaager@wiktel.com>
parents: 16383
diff changeset
621 purple_debug_error("buddyicon", "Error reading %s: %s\n",
54ea8863b8e8 Switch to using g_file_get_contents() instead of our own code.
Richard Laager <rlaager@wiktel.com>
parents: 16383
diff changeset
622 path, err->message);
54ea8863b8e8 Switch to using g_file_get_contents() instead of our own code.
Richard Laager <rlaager@wiktel.com>
parents: 16383
diff changeset
623 g_error_free(err);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
624
16384
54ea8863b8e8 Switch to using g_file_get_contents() instead of our own code.
Richard Laager <rlaager@wiktel.com>
parents: 16383
diff changeset
625 return FALSE;
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
626 }
16384
54ea8863b8e8 Switch to using g_file_get_contents() instead of our own code.
Richard Laager <rlaager@wiktel.com>
parents: 16383
diff changeset
627
54ea8863b8e8 Switch to using g_file_get_contents() instead of our own code.
Richard Laager <rlaager@wiktel.com>
parents: 16383
diff changeset
628 return TRUE;
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
629 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
630
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
631 PurpleBuddyIcon *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
632 purple_buddy_icons_find(PurpleAccount *account, const char *username)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
633 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
634 GHashTable *icon_cache;
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
635 PurpleBuddyIcon *icon = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
636
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
637 g_return_val_if_fail(account != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
638 g_return_val_if_fail(username != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
639
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
640 icon_cache = g_hash_table_lookup(account_cache, account);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
641
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
642 if ((icon_cache == NULL) || ((icon = g_hash_table_lookup(icon_cache, username)) == NULL))
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
643 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
644 PurpleBuddy *b = purple_find_buddy(account, username);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
645 const char *protocol_icon_file;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
646 const char *dirname;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
647 gboolean caching;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
648 guchar *data;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
649 size_t len;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
650
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
651 if (!b)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
652 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
653
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
654 protocol_icon_file = purple_blist_node_get_string((PurpleBlistNode*)b, "buddy_icon");
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
655
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
656 if (protocol_icon_file == NULL)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
657 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
658
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
659 dirname = purple_buddy_icons_get_cache_dir();
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
660
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
661 caching = purple_buddy_icons_is_caching();
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
662 /* By disabling caching temporarily, we avoid a loop
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
663 * and don't have to add special code through several
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
664 * functions. */
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
665 purple_buddy_icons_set_caching(FALSE);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
666
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
667 if (protocol_icon_file != NULL)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
668 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
669 char *path = g_build_filename(dirname, protocol_icon_file, NULL);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
670 if (read_icon_file(path, &data, &len))
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
671 {
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
672 const char *checksum;
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
673
16832
844ed0418744 Remove two warnings, one compile-time, one runtime. Plug two leaks, both runtime.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 16817
diff changeset
674 icon = purple_buddy_icon_create(account, username);
16376
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
675 icon->img = NULL;
16832
844ed0418744 Remove two warnings, one compile-time, one runtime. Plug two leaks, both runtime.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 16817
diff changeset
676 checksum = purple_blist_node_get_string((PurpleBlistNode*)b, "icon_checksum");
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
677 purple_buddy_icon_set_data(icon, data, len, checksum);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
678 }
22025
6f452e8d13a2 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 <evan.s@dreskin.net>
parents: 21988
diff changeset
679 else
6f452e8d13a2 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 <evan.s@dreskin.net>
parents: 21988
diff changeset
680 delete_buddy_icon_settings((PurpleBlistNode*)b, "buddy_icon");
22033
684f9228ae92 Remove spurious braces
Evan Schoenberg <evan.s@dreskin.net>
parents: 22027
diff changeset
681
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
682 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
683 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
684
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
685 purple_buddy_icons_set_caching(caching);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
686 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
687
22040
72712558e2be Apparently "nil" is an Objective-C thing
Stu Tomlinson <stu@nosnilmot.com>
parents: 22035
diff changeset
688 return (icon ? purple_buddy_icon_ref(icon) : NULL);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
689 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
690
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
691 PurpleStoredImage *
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
692 purple_buddy_icons_find_account_icon(PurpleAccount *account)
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
693 {
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
694 PurpleStoredImage *img;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
695 const char *account_icon_file;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
696 const char *dirname;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
697 char *path;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
698 guchar *data;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
699 size_t len;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
700
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
701 g_return_val_if_fail(account != NULL, NULL);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
702
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
703 if ((img = g_hash_table_lookup(pointer_icon_cache, account)))
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
704 {
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
705 return purple_imgstore_ref(img);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
706 }
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
707
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
708 account_icon_file = purple_account_get_string(account, "buddy_icon", NULL);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
709
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
710 if (account_icon_file == NULL)
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
711 return NULL;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
712
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
713 dirname = purple_buddy_icons_get_cache_dir();
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
714 path = g_build_filename(dirname, account_icon_file, NULL);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
715
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
716 if (read_icon_file(path, &data, &len))
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
717 {
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
718 g_free(path);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
719 img = purple_buddy_icon_data_new(data, len, account_icon_file);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
720 g_hash_table_insert(pointer_icon_cache, account, img);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
721 return img;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
722 }
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
723 g_free(path);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
724
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
725 return NULL;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
726 }
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
727
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
728 PurpleStoredImage *
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
729 purple_buddy_icons_set_account_icon(PurpleAccount *account,
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
730 guchar *icon_data, size_t icon_len)
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
731 {
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
732 PurpleStoredImage *old_img;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
733 PurpleStoredImage *img = NULL;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
734 char *old_icon;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
735
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
736 if (icon_data != NULL && icon_len > 0)
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
737 {
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
738 img = purple_buddy_icon_data_new(icon_data, icon_len, NULL);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
739 }
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
740
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
741 old_icon = g_strdup(purple_account_get_string(account, "buddy_icon", NULL));
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
742 if (img && purple_buddy_icons_is_caching())
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
743 {
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
744 const char *filename = purple_imgstore_get_filename(img);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
745 purple_account_set_string(account, "buddy_icon", filename);
16621
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
746 purple_account_set_int(account, "buddy_icon_timestamp", time(NULL));
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
747 ref_filename(filename);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
748 }
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
749 else
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
750 {
16482
3be560001d26 Kill some compiler warnings and TODOs of mine.
Richard Laager <rlaager@wiktel.com>
parents: 16391
diff changeset
751 purple_account_set_string(account, "buddy_icon", NULL);
16621
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
752 purple_account_set_int(account, "buddy_icon_timestamp", 0);
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
753 }
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
754 unref_filename(old_icon);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
755
22401
d9105ead88dc When purple_buddy_icons_set_account_icon() is called, it unrefs the old PurpleStoredImage and refs the new one. Previously, it notified the prpl of the change in the buddy icon before updating pointer_icon_cache, which meant that if the prpl then called purple_buddy_icons_find_account_icon() it would get the old PurpleStoredImage (which is at this point not only old but also a pointer to invalid memory if unref'ing it caused it to be destroyed). This happens in jabber_set_info() as of 2.4.0, causing a crash when setting no-buddy-icon for an account after it has previously had an icon. I think this also means that XMPP accounts in 2.4.0 will also always set serverside the *last* icon set, not the current one, when changing icons, but I didn't test that.
Evan Schoenberg <evan.s@dreskin.net>
parents: 22262
diff changeset
756 if (img)
d9105ead88dc When purple_buddy_icons_set_account_icon() is called, it unrefs the old PurpleStoredImage and refs the new one. Previously, it notified the prpl of the change in the buddy icon before updating pointer_icon_cache, which meant that if the prpl then called purple_buddy_icons_find_account_icon() it would get the old PurpleStoredImage (which is at this point not only old but also a pointer to invalid memory if unref'ing it caused it to be destroyed). This happens in jabber_set_info() as of 2.4.0, causing a crash when setting no-buddy-icon for an account after it has previously had an icon. I think this also means that XMPP accounts in 2.4.0 will also always set serverside the *last* icon set, not the current one, when changing icons, but I didn't test that.
Evan Schoenberg <evan.s@dreskin.net>
parents: 22262
diff changeset
757 g_hash_table_insert(pointer_icon_cache, account, img);
d9105ead88dc When purple_buddy_icons_set_account_icon() is called, it unrefs the old PurpleStoredImage and refs the new one. Previously, it notified the prpl of the change in the buddy icon before updating pointer_icon_cache, which meant that if the prpl then called purple_buddy_icons_find_account_icon() it would get the old PurpleStoredImage (which is at this point not only old but also a pointer to invalid memory if unref'ing it caused it to be destroyed). This happens in jabber_set_info() as of 2.4.0, causing a crash when setting no-buddy-icon for an account after it has previously had an icon. I think this also means that XMPP accounts in 2.4.0 will also always set serverside the *last* icon set, not the current one, when changing icons, but I didn't test that.
Evan Schoenberg <evan.s@dreskin.net>
parents: 22262
diff changeset
758 else
d9105ead88dc When purple_buddy_icons_set_account_icon() is called, it unrefs the old PurpleStoredImage and refs the new one. Previously, it notified the prpl of the change in the buddy icon before updating pointer_icon_cache, which meant that if the prpl then called purple_buddy_icons_find_account_icon() it would get the old PurpleStoredImage (which is at this point not only old but also a pointer to invalid memory if unref'ing it caused it to be destroyed). This happens in jabber_set_info() as of 2.4.0, causing a crash when setting no-buddy-icon for an account after it has previously had an icon. I think this also means that XMPP accounts in 2.4.0 will also always set serverside the *last* icon set, not the current one, when changing icons, but I didn't test that.
Evan Schoenberg <evan.s@dreskin.net>
parents: 22262
diff changeset
759 g_hash_table_remove(pointer_icon_cache, account);
d9105ead88dc When purple_buddy_icons_set_account_icon() is called, it unrefs the old PurpleStoredImage and refs the new one. Previously, it notified the prpl of the change in the buddy icon before updating pointer_icon_cache, which meant that if the prpl then called purple_buddy_icons_find_account_icon() it would get the old PurpleStoredImage (which is at this point not only old but also a pointer to invalid memory if unref'ing it caused it to be destroyed). This happens in jabber_set_info() as of 2.4.0, causing a crash when setting no-buddy-icon for an account after it has previously had an icon. I think this also means that XMPP accounts in 2.4.0 will also always set serverside the *last* icon set, not the current one, when changing icons, but I didn't test that.
Evan Schoenberg <evan.s@dreskin.net>
parents: 22262
diff changeset
760
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
761 if (purple_account_is_connected(account))
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
762 {
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
763 PurpleConnection *gc;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
764 PurplePluginProtocolInfo *prpl_info;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
765
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
766 gc = purple_account_get_connection(account);
22262
edca47ee06c5 Kill off gc->prpl in the core everywhere but connection.c (when the struct
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22185
diff changeset
767 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc));
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
768
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
769 if (prpl_info && prpl_info->set_buddy_icon)
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
770 prpl_info->set_buddy_icon(gc, img);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
771 }
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
772
21588
837c382af6a4 prpl->set_buddy_icon may keep a reference to PurpleStoredImage, move the
Ka-Hing Cheung <khc@hxbc.us>
parents: 21121
diff changeset
773 if ((old_img = g_hash_table_lookup(pointer_icon_cache, account)))
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
774 purple_imgstore_unref(old_img);
16616
4eb08fcc16d8 Fix assertion when creating a new account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 16596
diff changeset
775 else if (old_icon)
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
776 {
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
777 /* The old icon may not have been loaded into memory. In that
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
778 * case, we'll need to uncache the filename. The filenames
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
779 * are ref-counted, so this is safe. */
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
780 purple_buddy_icon_data_uncache_file(old_icon);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
781 }
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
782 g_free(old_icon);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
783
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
784 return img;
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
785 }
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
786
16621
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
787 time_t
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
788 purple_buddy_icons_get_account_icon_timestamp(PurpleAccount *account)
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
789 {
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
790 time_t ret;
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
791
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
792 g_return_val_if_fail(account != NULL, 0);
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
793
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
794 ret = purple_account_get_int(account, "buddy_icon_timestamp", 0);
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
795
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
796 /* This deals with migration cases. */
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
797 if (ret == 0 && purple_account_get_string(account, "buddy_icon", NULL) != NULL)
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
798 {
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
799 ret = time(NULL);
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
800 purple_account_set_int(account, "buddy_icon_timestamp", ret);
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
801 }
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
802
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
803 return ret;
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
804 }
dbd0a01a9a81 The OSCAR timestamp stuff.
Richard Laager <rlaager@wiktel.com>
parents: 16611
diff changeset
805
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
806 gboolean
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
807 purple_buddy_icons_node_has_custom_icon(PurpleBlistNode *node)
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
808 {
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
809 g_return_val_if_fail(node != NULL, FALSE);
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
810
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
811 return (purple_blist_node_get_string(node, "custom_buddy_icon") != NULL);
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
812 }
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
813
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
814 PurpleStoredImage *
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
815 purple_buddy_icons_node_find_custom_icon(PurpleBlistNode *node)
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
816 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
817 char *path;
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
818 size_t len;
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
819 guchar *data;
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
820 PurpleStoredImage *img;
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
821 const char *custom_icon_file, *dirname;
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
822
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
823 g_return_val_if_fail(node != NULL, NULL);
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
824
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
825 if ((img = g_hash_table_lookup(pointer_icon_cache, node)))
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
826 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
827 return purple_imgstore_ref(img);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
828 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
829
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
830 custom_icon_file = purple_blist_node_get_string(node,
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
831 "custom_buddy_icon");
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
832
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
833 if (custom_icon_file == NULL)
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
834 return NULL;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
835
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
836 dirname = purple_buddy_icons_get_cache_dir();
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
837 path = g_build_filename(dirname, custom_icon_file, NULL);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
838
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
839 if (read_icon_file(path, &data, &len))
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
840 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
841 g_free(path);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
842 img = purple_buddy_icon_data_new(data, len, custom_icon_file);
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
843 g_hash_table_insert(pointer_icon_cache, node, img);
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
844 return img;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
845 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
846 g_free(path);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
847
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
848 return NULL;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
849 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
850
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
851 PurpleStoredImage *
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
852 purple_buddy_icons_node_set_custom_icon(PurpleBlistNode *node,
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
853 guchar *icon_data, size_t icon_len)
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
854 {
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
855 char *old_icon;
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
856 PurpleStoredImage *old_img;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
857 PurpleStoredImage *img = NULL;
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
858
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
859 g_return_val_if_fail(node != NULL, NULL);
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
860
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
861 if (!PURPLE_BLIST_NODE_IS_CONTACT(node) &&
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
862 !PURPLE_BLIST_NODE_IS_CHAT(node) &&
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
863 !PURPLE_BLIST_NODE_IS_GROUP(node)) {
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
864 return NULL;
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
865 }
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
866
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
867 old_img = g_hash_table_lookup(pointer_icon_cache, node);
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
868
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
869 if (icon_data != NULL && icon_len > 0) {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
870 img = purple_buddy_icon_data_new(icon_data, icon_len, NULL);
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
871 }
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
872
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
873 old_icon = g_strdup(purple_blist_node_get_string(node,
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
874 "custom_buddy_icon"));
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
875 if (img && purple_buddy_icons_is_caching()) {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
876 const char *filename = purple_imgstore_get_filename(img);
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
877 purple_blist_node_set_string(node, "custom_buddy_icon",
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
878 filename);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
879 ref_filename(filename);
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
880 } else {
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
881 purple_blist_node_remove_setting(node, "custom_buddy_icon");
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
882 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
883 unref_filename(old_icon);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
884
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
885 if (img)
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
886 g_hash_table_insert(pointer_icon_cache, node, img);
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
887 else
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
888 g_hash_table_remove(pointer_icon_cache, node);
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
889
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
890 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) {
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
891 PurpleBlistNode *child;
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
892 for (child = node->child ; child ; child = child->next)
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
893 {
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
894 PurpleBuddy *buddy;
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
895 PurpleConversation *conv;
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
896
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
897 if (!PURPLE_BLIST_NODE_IS_BUDDY(child))
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
898 continue;
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
899
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
900 buddy = (PurpleBuddy *)child;
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
901
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
902 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, purple_buddy_get_name(buddy), purple_buddy_get_account(buddy));
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
903 if (conv)
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
904 purple_conversation_update(conv, PURPLE_CONV_UPDATE_ICON);
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
905
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
906 /* Is this call necessary anymore? Can the buddies
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
907 * themselves need updating when the custom buddy
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
908 * icon changes? */
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
909 purple_blist_update_node_icon((PurpleBlistNode*)buddy);
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
910 }
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
911 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
912 PurpleConversation *conv = NULL;
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
913
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
914 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, purple_chat_get_name((PurpleChat*)node), purple_chat_get_account((PurpleChat*)node));
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
915 if (conv) {
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
916 purple_conversation_update(conv, PURPLE_CONV_UPDATE_ICON);
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
917 }
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
918 }
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
919
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
920 purple_blist_update_node_icon(node);
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
921
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
922 if (old_img) {
16385
a0df0eb75e1b Fix a bug with removing custom buddy icons.
Richard Laager <rlaager@wiktel.com>
parents: 16384
diff changeset
923 purple_imgstore_unref(old_img);
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
924 } else if (old_icon) {
16385
a0df0eb75e1b Fix a bug with removing custom buddy icons.
Richard Laager <rlaager@wiktel.com>
parents: 16384
diff changeset
925 /* The old icon may not have been loaded into memory. In that
a0df0eb75e1b Fix a bug with removing custom buddy icons.
Richard Laager <rlaager@wiktel.com>
parents: 16384
diff changeset
926 * case, we'll need to uncache the filename. The filenames
a0df0eb75e1b Fix a bug with removing custom buddy icons.
Richard Laager <rlaager@wiktel.com>
parents: 16384
diff changeset
927 * are ref-counted, so this is safe. */
a0df0eb75e1b Fix a bug with removing custom buddy icons.
Richard Laager <rlaager@wiktel.com>
parents: 16384
diff changeset
928 purple_buddy_icon_data_uncache_file(old_icon);
a0df0eb75e1b Fix a bug with removing custom buddy icons.
Richard Laager <rlaager@wiktel.com>
parents: 16384
diff changeset
929 }
a0df0eb75e1b Fix a bug with removing custom buddy icons.
Richard Laager <rlaager@wiktel.com>
parents: 16384
diff changeset
930 g_free(old_icon);
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
931
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
932 return img;
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
933 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
934
23120
4044655e5615 Add a purple_buddy_icons_node_set_custom_icon_from_file convenience function.
Etan Reisner <pidgin@unreliablesource.net>
parents: 23118
diff changeset
935 PurpleStoredImage *
4044655e5615 Add a purple_buddy_icons_node_set_custom_icon_from_file convenience function.
Etan Reisner <pidgin@unreliablesource.net>
parents: 23118
diff changeset
936 purple_buddy_icons_node_set_custom_icon_from_file(PurpleBlistNode *node,
4044655e5615 Add a purple_buddy_icons_node_set_custom_icon_from_file convenience function.
Etan Reisner <pidgin@unreliablesource.net>
parents: 23118
diff changeset
937 const gchar *filename)
4044655e5615 Add a purple_buddy_icons_node_set_custom_icon_from_file convenience function.
Etan Reisner <pidgin@unreliablesource.net>
parents: 23118
diff changeset
938 {
24005
2ecdd0403dc1 Don't try to read data from a NULL filename in
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23120
diff changeset
939 size_t len = 0;
2ecdd0403dc1 Don't try to read data from a NULL filename in
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23120
diff changeset
940 guchar *data = NULL;
23120
4044655e5615 Add a purple_buddy_icons_node_set_custom_icon_from_file convenience function.
Etan Reisner <pidgin@unreliablesource.net>
parents: 23118
diff changeset
941
4044655e5615 Add a purple_buddy_icons_node_set_custom_icon_from_file convenience function.
Etan Reisner <pidgin@unreliablesource.net>
parents: 23118
diff changeset
942 g_return_val_if_fail(node != NULL, NULL);
4044655e5615 Add a purple_buddy_icons_node_set_custom_icon_from_file convenience function.
Etan Reisner <pidgin@unreliablesource.net>
parents: 23118
diff changeset
943
4044655e5615 Add a purple_buddy_icons_node_set_custom_icon_from_file convenience function.
Etan Reisner <pidgin@unreliablesource.net>
parents: 23118
diff changeset
944 if (!PURPLE_BLIST_NODE_IS_CONTACT(node) &&
4044655e5615 Add a purple_buddy_icons_node_set_custom_icon_from_file convenience function.
Etan Reisner <pidgin@unreliablesource.net>
parents: 23118
diff changeset
945 !PURPLE_BLIST_NODE_IS_CHAT(node) &&
4044655e5615 Add a purple_buddy_icons_node_set_custom_icon_from_file convenience function.
Etan Reisner <pidgin@unreliablesource.net>
parents: 23118
diff changeset
946 !PURPLE_BLIST_NODE_IS_GROUP(node)) {
4044655e5615 Add a purple_buddy_icons_node_set_custom_icon_from_file convenience function.
Etan Reisner <pidgin@unreliablesource.net>
parents: 23118
diff changeset
947 return NULL;
4044655e5615 Add a purple_buddy_icons_node_set_custom_icon_from_file convenience function.
Etan Reisner <pidgin@unreliablesource.net>
parents: 23118
diff changeset
948 }
4044655e5615 Add a purple_buddy_icons_node_set_custom_icon_from_file convenience function.
Etan Reisner <pidgin@unreliablesource.net>
parents: 23118
diff changeset
949
24005
2ecdd0403dc1 Don't try to read data from a NULL filename in
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23120
diff changeset
950 if (filename != NULL) {
2ecdd0403dc1 Don't try to read data from a NULL filename in
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23120
diff changeset
951 if (!read_icon_file(filename, &data, &len)) {
2ecdd0403dc1 Don't try to read data from a NULL filename in
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23120
diff changeset
952 return NULL;
2ecdd0403dc1 Don't try to read data from a NULL filename in
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23120
diff changeset
953 }
23120
4044655e5615 Add a purple_buddy_icons_node_set_custom_icon_from_file convenience function.
Etan Reisner <pidgin@unreliablesource.net>
parents: 23118
diff changeset
954 }
4044655e5615 Add a purple_buddy_icons_node_set_custom_icon_from_file convenience function.
Etan Reisner <pidgin@unreliablesource.net>
parents: 23118
diff changeset
955
4044655e5615 Add a purple_buddy_icons_node_set_custom_icon_from_file convenience function.
Etan Reisner <pidgin@unreliablesource.net>
parents: 23118
diff changeset
956 return purple_buddy_icons_node_set_custom_icon(node, data, len);
4044655e5615 Add a purple_buddy_icons_node_set_custom_icon_from_file convenience function.
Etan Reisner <pidgin@unreliablesource.net>
parents: 23118
diff changeset
957 }
4044655e5615 Add a purple_buddy_icons_node_set_custom_icon_from_file convenience function.
Etan Reisner <pidgin@unreliablesource.net>
parents: 23118
diff changeset
958
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
959 gboolean
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
960 purple_buddy_icons_has_custom_icon(PurpleContact *contact)
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
961 {
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
962 return purple_buddy_icons_node_has_custom_icon((PurpleBlistNode*)contact);
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
963 }
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
964
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
965 PurpleStoredImage *
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
966 purple_buddy_icons_find_custom_icon(PurpleContact *contact)
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
967 {
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
968 return purple_buddy_icons_node_find_custom_icon((PurpleBlistNode*)contact);
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
969 }
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
970
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
971 PurpleStoredImage *
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
972 purple_buddy_icons_set_custom_icon(PurpleContact *contact, guchar *icon_data,
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
973 size_t icon_len)
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
974 {
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
975 return purple_buddy_icons_node_set_custom_icon((PurpleBlistNode*)contact, icon_data, icon_len);
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
976 }
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
977
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
978 void
16637
250623ba4218 The GNOME coding guidelines recommend prefixing internal symbols with an underscore.
Richard Laager <rlaager@wiktel.com>
parents: 16631
diff changeset
979 _purple_buddy_icon_set_old_icons_dir(const char *dirname)
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
980 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
981 old_icons_dir = g_strdup(dirname);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
982 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
983
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
984 static void
16551
175eadaead53 nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@wiktel.com>
parents: 16537
diff changeset
985 delete_buddy_icon_settings(PurpleBlistNode *node, const char *setting_name)
175eadaead53 nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@wiktel.com>
parents: 16537
diff changeset
986 {
175eadaead53 nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@wiktel.com>
parents: 16537
diff changeset
987 purple_blist_node_remove_setting(node, setting_name);
175eadaead53 nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@wiktel.com>
parents: 16537
diff changeset
988
175eadaead53 nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@wiktel.com>
parents: 16537
diff changeset
989 if (!strcmp(setting_name, "buddy_icon"))
175eadaead53 nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@wiktel.com>
parents: 16537
diff changeset
990 {
175eadaead53 nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@wiktel.com>
parents: 16537
diff changeset
991 purple_blist_node_remove_setting(node, "avatar_hash");
175eadaead53 nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@wiktel.com>
parents: 16537
diff changeset
992 purple_blist_node_remove_setting(node, "icon_checksum");
175eadaead53 nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@wiktel.com>
parents: 16537
diff changeset
993 }
175eadaead53 nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@wiktel.com>
parents: 16537
diff changeset
994 }
175eadaead53 nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@wiktel.com>
parents: 16537
diff changeset
995
175eadaead53 nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@wiktel.com>
parents: 16537
diff changeset
996 static void
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
997 migrate_buddy_icon(PurpleBlistNode *node, const char *setting_name,
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
998 const char *dirname, const char *filename)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
999 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1000 char *path;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1001
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1002 if (filename[0] != '/')
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1003 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1004 path = g_build_filename(dirname, filename, NULL);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1005 if (g_file_test(path, G_FILE_TEST_EXISTS))
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1006 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1007 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1008 return;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1009 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1010 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1011
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1012 path = g_build_filename(old_icons_dir, filename, NULL);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1013 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1014 else
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1015 path = g_strdup(filename);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1016
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1017 if (g_file_test(path, G_FILE_TEST_EXISTS))
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1018 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1019 guchar *icon_data;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1020 size_t icon_len;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1021 FILE *file;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1022 char *new_filename;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1023
16629
898019538f44 Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@wiktel.com>
parents: 16628
diff changeset
1024 if (!read_icon_file(path, &icon_data, &icon_len))
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1025 {
16629
898019538f44 Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@wiktel.com>
parents: 16628
diff changeset
1026 g_free(path);
898019538f44 Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@wiktel.com>
parents: 16628
diff changeset
1027 delete_buddy_icon_settings(node, setting_name);
898019538f44 Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@wiktel.com>
parents: 16628
diff changeset
1028 return;
898019538f44 Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@wiktel.com>
parents: 16628
diff changeset
1029 }
898019538f44 Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@wiktel.com>
parents: 16628
diff changeset
1030
898019538f44 Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@wiktel.com>
parents: 16628
diff changeset
1031 if (icon_data == NULL || icon_len <= 0)
898019538f44 Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@wiktel.com>
parents: 16628
diff changeset
1032 {
898019538f44 Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@wiktel.com>
parents: 16628
diff changeset
1033 /* This really applies to the icon_len check.
898019538f44 Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@wiktel.com>
parents: 16628
diff changeset
1034 * icon_data should never be NULL if
898019538f44 Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@wiktel.com>
parents: 16628
diff changeset
1035 * read_icon_file() returns TRUE. */
898019538f44 Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@wiktel.com>
parents: 16628
diff changeset
1036 purple_debug_error("buddyicon", "Empty buddy icon file: %s\n", path);
16551
175eadaead53 nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@wiktel.com>
parents: 16537
diff changeset
1037 delete_buddy_icon_settings(node, setting_name);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1038 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1039 return;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1040 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1041
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1042 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1043
18039
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 16981
diff changeset
1044 new_filename = purple_util_get_image_filename(icon_data, icon_len);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1045 if (new_filename == NULL)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1046 {
16629
898019538f44 Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@wiktel.com>
parents: 16628
diff changeset
1047 purple_debug_error("buddyicon",
898019538f44 Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@wiktel.com>
parents: 16628
diff changeset
1048 "New icon filename is NULL. This should never happen! "
898019538f44 Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@wiktel.com>
parents: 16628
diff changeset
1049 "The old filename was: %s\n", path);
16551
175eadaead53 nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@wiktel.com>
parents: 16537
diff changeset
1050 delete_buddy_icon_settings(node, setting_name);
16629
898019538f44 Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@wiktel.com>
parents: 16628
diff changeset
1051 g_return_if_reached();
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1052 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1053
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1054 path = g_build_filename(dirname, new_filename, NULL);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1055 if ((file = g_fopen(path, "wb")) != NULL)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1056 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1057 if (!fwrite(icon_data, icon_len, 1, file))
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1058 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1059 purple_debug_error("buddyicon", "Error writing %s: %s\n",
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20350
diff changeset
1060 path, g_strerror(errno));
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1061 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1062 else
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1063 purple_debug_info("buddyicon", "Wrote migrated cache file: %s\n", path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1064
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1065 fclose(file);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1066 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1067 else
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1068 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1069 purple_debug_error("buddyicon", "Unable to create file %s: %s\n",
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20350
diff changeset
1070 path, g_strerror(errno));
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1071 g_free(new_filename);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1072 g_free(path);
16551
175eadaead53 nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@wiktel.com>
parents: 16537
diff changeset
1073
175eadaead53 nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@wiktel.com>
parents: 16537
diff changeset
1074 delete_buddy_icon_settings(node, setting_name);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1075 return;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1076 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1077 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1078
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1079 purple_blist_node_set_string(node,
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1080 setting_name,
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1081 new_filename);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1082 ref_filename(new_filename);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1083
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1084 g_free(new_filename);
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1085
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1086 if (!strcmp(setting_name, "buddy_icon"))
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1087 {
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1088 const char *hash;
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1089
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1090 hash = purple_blist_node_get_string(node, "avatar_hash");
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1091 if (hash != NULL)
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1092 {
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1093 purple_blist_node_set_string(node, "icon_checksum", hash);
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1094 purple_blist_node_remove_setting(node, "avatar_hash");
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1095 }
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1096 else
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1097 {
16569
d212880d8d5b Make this yahoo hack compile.
Richard Laager <rlaager@wiktel.com>
parents: 16568
diff changeset
1098 PurpleAccount *account = purple_buddy_get_account((PurpleBuddy *)node);
16568
8cd67084833c In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@wiktel.com>
parents: 16553
diff changeset
1099 const char *prpl_id = purple_account_get_protocol_id(account);
8cd67084833c In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@wiktel.com>
parents: 16553
diff changeset
1100
8cd67084833c In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@wiktel.com>
parents: 16553
diff changeset
1101 if (!strcmp(prpl_id, "prpl-yahoo"))
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1102 {
16568
8cd67084833c In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@wiktel.com>
parents: 16553
diff changeset
1103 int checksum = purple_blist_node_get_int(node, "icon_checksum");
8cd67084833c In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@wiktel.com>
parents: 16553
diff changeset
1104 if (checksum != 0)
8cd67084833c In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@wiktel.com>
parents: 16553
diff changeset
1105 {
8cd67084833c In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@wiktel.com>
parents: 16553
diff changeset
1106 char *checksum_str = g_strdup_printf("%i", checksum);
8cd67084833c In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@wiktel.com>
parents: 16553
diff changeset
1107 purple_blist_node_remove_setting(node, "icon_checksum");
8cd67084833c In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@wiktel.com>
parents: 16553
diff changeset
1108 purple_blist_node_set_string(node, "icon_checksum", checksum_str);
8cd67084833c In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@wiktel.com>
parents: 16553
diff changeset
1109 g_free(checksum_str);
8cd67084833c In theory, this solves the massive pile of g_log errors that occur when
Richard Laager <rlaager@wiktel.com>
parents: 16553
diff changeset
1110 }
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1111 }
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1112 }
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1113 }
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1114 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1115 else
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1116 {
16629
898019538f44 Add more error checking to the buddy icon migration code.
Richard Laager <rlaager@wiktel.com>
parents: 16628
diff changeset
1117 purple_debug_error("buddyicon", "Old icon file doesn't exist: %s\n", path);
16551
175eadaead53 nosnilmot had a problem with empty icon files.
Richard Laager <rlaager@wiktel.com>
parents: 16537
diff changeset
1118 delete_buddy_icon_settings(node, setting_name);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1119 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1120 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1121 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1122
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1123 void
16637
250623ba4218 The GNOME coding guidelines recommend prefixing internal symbols with an underscore.
Richard Laager <rlaager@wiktel.com>
parents: 16631
diff changeset
1124 _purple_buddy_icons_account_loaded_cb()
16505
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1125 {
16508
c8bc8048f264 This is probably needed to compile.
Richard Laager <rlaager@wiktel.com>
parents: 16506
diff changeset
1126 const char *dirname = purple_buddy_icons_get_cache_dir();
18063
926ccb104da0 disapproval of revision '1411afd7660760db59966c3a9f18e2adab8eb27e'
Richard Laager <rlaager@wiktel.com>
parents: 18058
diff changeset
1127 GList *cur;
16505
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1128
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1129 for (cur = purple_accounts_get_all(); cur != NULL; cur = cur->next)
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1130 {
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1131 PurpleAccount *account = cur->data;
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1132 const char *account_icon_file = purple_account_get_string(account, "buddy_icon", NULL);
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1133
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1134 if (account_icon_file != NULL)
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1135 {
16510
c01528418cc2 I really shouldn't commit before compiling.
Richard Laager <rlaager@wiktel.com>
parents: 16508
diff changeset
1136 char *path = g_build_filename(dirname, account_icon_file, NULL);
c01528418cc2 I really shouldn't commit before compiling.
Richard Laager <rlaager@wiktel.com>
parents: 16508
diff changeset
1137 if (!g_file_test(path, G_FILE_TEST_EXISTS))
16505
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1138 {
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1139 purple_account_set_string(account, "buddy_icon", NULL);
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1140 } else {
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1141 ref_filename(account_icon_file);
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1142 }
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1143 g_free(path);
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1144 }
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1145 }
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1146 }
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1147
1d1ddf972ac8 Ref the filenames for account buddy icons on load.
Richard Laager <rlaager@wiktel.com>
parents: 16482
diff changeset
1148 void
16637
250623ba4218 The GNOME coding guidelines recommend prefixing internal symbols with an underscore.
Richard Laager <rlaager@wiktel.com>
parents: 16631
diff changeset
1149 _purple_buddy_icons_blist_loaded_cb()
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1150 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1151 PurpleBlistNode *node = purple_blist_get_root();
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1152 const char *dirname = purple_buddy_icons_get_cache_dir();
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1153
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1154 /* Doing this once here saves having to check it inside a loop. */
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1155 if (old_icons_dir != NULL)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1156 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1157 if (!g_file_test(dirname, G_FILE_TEST_IS_DIR))
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1158 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1159 purple_debug_info("buddyicon", "Creating icon cache directory.\n");
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1160
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1161 if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1162 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1163 purple_debug_error("buddyicon",
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1164 "Unable to create directory %s: %s\n",
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 20350
diff changeset
1165 dirname, g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1166 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1167 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1168 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1169
16596
63a1de71e389 Whitespace fix from patch in ticket #383
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 16569
diff changeset
1170 while (node != NULL)
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1171 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1172 if (PURPLE_BLIST_NODE_IS_BUDDY(node))
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1173 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1174 const char *filename;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1175
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1176 filename = purple_blist_node_get_string(node, "buddy_icon");
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1177 if (filename != NULL)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1178 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1179 if (old_icons_dir != NULL)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1180 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1181 migrate_buddy_icon(node,
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1182 "buddy_icon",
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1183 dirname, filename);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1184 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1185 else
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1186 {
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
1187 char *path = g_build_filename(dirname, filename, NULL);
16506
d6b81413ef79 Fix a small-but-serious bug with the code to ref the buddy icons at load.
Richard Laager <rlaager@wiktel.com>
parents: 16505
diff changeset
1188 if (!g_file_test(path, G_FILE_TEST_EXISTS))
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
1189 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
1190 purple_blist_node_remove_setting(node,
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
1191 "buddy_icon");
16386
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1192 purple_blist_node_remove_setting(node,
e0c9a46b459f Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@wiktel.com>
parents: 16385
diff changeset
1193 "icon_checksum");
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
1194 }
16383
05033ae856b2 Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
1195 else
05033ae856b2 Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
1196 ref_filename(filename);
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
1197 g_free(path);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1198 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1199 }
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
1200 }
23118
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
1201 else if (PURPLE_BLIST_NODE_IS_CONTACT(node) ||
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
1202 PURPLE_BLIST_NODE_IS_CHAT(node) ||
944059cb7807 Add the purple_buddy_icons_node_has_custom_icon,
Etan Reisner <pidgin@unreliablesource.net>
parents: 22609
diff changeset
1203 PURPLE_BLIST_NODE_IS_GROUP(node))
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
1204 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
1205 const char *filename;
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1206
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1207 filename = purple_blist_node_get_string(node, "custom_buddy_icon");
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1208 if (filename != NULL)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1209 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1210 if (old_icons_dir != NULL)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1211 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1212 migrate_buddy_icon(node,
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1213 "custom_buddy_icon",
16552
e98cd6ed5c13 Minor whitespace tweak.
Richard Laager <rlaager@wiktel.com>
parents: 16551
diff changeset
1214 dirname, filename);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1215 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1216 else
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1217 {
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
1218 char *path = g_build_filename(dirname, filename, NULL);
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
1219 if (!g_file_test(path, G_FILE_TEST_EXISTS))
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
1220 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
1221 purple_blist_node_remove_setting(node,
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
1222 "custom_buddy_icon");
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
1223 }
16383
05033ae856b2 Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
1224 else
05033ae856b2 Fix the memory leaking and improper calls to ref_filename(). Also, remove some debugging code.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
1225 ref_filename(filename);
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
1226 g_free(path);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1227 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1228 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1229 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1230 node = purple_blist_node_next(node, TRUE);
16596
63a1de71e389 Whitespace fix from patch in ticket #383
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 16569
diff changeset
1231 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1232 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1233
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1234 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1235 purple_buddy_icons_set_caching(gboolean caching)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1236 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1237 icon_caching = caching;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1238 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1239
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1240 gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1241 purple_buddy_icons_is_caching(void)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1242 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1243 return icon_caching;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1244 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1245
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1246 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1247 purple_buddy_icons_set_cache_dir(const char *dir)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1248 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1249 g_return_if_fail(dir != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1250
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1251 g_free(cache_dir);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1252 cache_dir = g_strdup(dir);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1253 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1254
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1255 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1256 purple_buddy_icons_get_cache_dir(void)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1257 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1258 return cache_dir;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1259 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1260
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1261 void *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1262 purple_buddy_icons_get_handle()
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1263 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1264 static int handle;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1265
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1266 return &handle;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1267 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1268
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1269 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1270 purple_buddy_icons_init()
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1271 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1272 account_cache = g_hash_table_new_full(
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1273 g_direct_hash, g_direct_equal,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1274 NULL, (GFreeFunc)g_hash_table_destroy);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1275
16611
f130f097e378 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@wiktel.com>
parents: 16596
diff changeset
1276 icon_data_cache = g_hash_table_new_full(g_str_hash, g_str_equal,
f130f097e378 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@wiktel.com>
parents: 16596
diff changeset
1277 g_free, NULL);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1278 icon_file_cache = g_hash_table_new_full(g_str_hash, g_str_equal,
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1279 g_free, NULL);
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
1280 pointer_icon_cache = g_hash_table_new(g_direct_hash, g_direct_equal);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1281
22036
f4c0a7014498 If the UI sets a cache directory before purple_buddy_icons_init() is called
Evan Schoenberg <evan.s@dreskin.net>
parents: 22035
diff changeset
1282 if (!cache_dir)
f4c0a7014498 If the UI sets a cache directory before purple_buddy_icons_init() is called
Evan Schoenberg <evan.s@dreskin.net>
parents: 22035
diff changeset
1283 cache_dir = g_build_filename(purple_user_dir(), "icons", NULL);
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
1284
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
1285 purple_signal_connect(purple_imgstore_get_handle(), "image-deleting",
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
1286 purple_buddy_icons_get_handle(),
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
1287 G_CALLBACK(image_deleting_cb), NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1288 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1289
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1290 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1291 purple_buddy_icons_uninit()
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1292 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
1293 purple_signals_disconnect_by_handle(purple_buddy_icons_get_handle());
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
1294
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1295 g_hash_table_destroy(account_cache);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1296 g_hash_table_destroy(icon_data_cache);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1297 g_hash_table_destroy(icon_file_cache);
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16389
diff changeset
1298 g_hash_table_destroy(pointer_icon_cache);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15823
diff changeset
1299 g_free(old_icons_dir);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1300 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1301
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1302 void purple_buddy_icon_get_scale_size(PurpleBuddyIconSpec *spec, int *width, int *height)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1303 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1304 int new_width, new_height;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1305
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1306 new_width = *width;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1307 new_height = *height;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1308
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1309 if (*width < spec->min_width)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1310 new_width = spec->min_width;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1311 else if (*width > spec->max_width)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1312 new_width = spec->max_width;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1313
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1314 if (*height < spec->min_height)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1315 new_height = spec->min_height;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1316 else if (*height > spec->max_height)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1317 new_height = spec->max_height;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1318
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1319 /* preserve aspect ratio */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1320 if ((double)*height * (double)new_width >
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1321 (double)*width * (double)new_height) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1322 new_width = 0.5 + (double)*width * (double)new_height / (double)*height;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1323 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1324 new_height = 0.5 + (double)*height * (double)new_width / (double)*width;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1325 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1326
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1327 *width = new_width;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1328 *height = new_height;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1329 }