annotate libpurple/buddyicon.c @ 16381:72dc611f3257

Fix the custom icon stuff, and various memory leaks. At this point, custom icons work properly, EXCEPT FOR A SERIOUS LEAK which I haven't fixed yet because I'm seeing weird memory allocation issues. Once I deal with that, it's just the account icon stuff that's left.
author Richard Laager <rlaager@wiktel.com>
date Tue, 24 Apr 2007 17:00:22 +0000
parents bae921154351
children 05033ae856b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 * @file icon.c Buddy Icon API
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 * @ingroup core
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4 *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
5 * purple
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
6 *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
7 * Purple is the legal property of its developers, whose names are too numerous
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8 * 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
9 * source distribution.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 * 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
12 * 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
13 * 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
14 * (at your option) any later version.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 * 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
17 * 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
18 * 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
19 * GNU General Public License for more details.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 * 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
22 * along with this program; if not, write to the Free Software
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 #include "internal.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 #include "buddyicon.h"
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
27 #include "cipher.h"
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28 #include "conversation.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 #include "dbus-maybe.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 #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
31 #include "imgstore.h"
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 #include "util.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
34 typedef struct _PurpleBuddyIconData PurpleBuddyIconData;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
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: 15822
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: 15822
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. */
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
41 char *username; /**< The username the icon belongs to. */
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
42 PurpleStoredImage *img; /**< The id of the stored image with the
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
43 the icon data. */
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
44 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: 15822
diff changeset
45 };
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
46
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 static GHashTable *account_cache = NULL;
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
48 static GHashTable *icon_data_cache = NULL;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
49 static GHashTable *icon_file_cache = 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
50 static GHashTable *custom_icon_cache = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 static char *cache_dir = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52 static gboolean icon_caching = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
54 /* 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: 15822
diff changeset
55 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: 15822
diff changeset
56
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
57 static void
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
58 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: 15822
diff changeset
59 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
60 int refs;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
61
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
62 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: 15822
diff changeset
63
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
64 refs = GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename));
16376
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
65 printf("refs before increment = %d\n", refs);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
66
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
67 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: 15822
diff changeset
68 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: 15822
diff changeset
69 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
70
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
71 static void
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
72 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: 15822
diff changeset
73 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
74 int refs;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
75
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
76 if (filename == NULL)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
77 return;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
78
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
79 refs = GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename));
16376
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
80 printf("refs before decrement = %d\n", refs);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
81
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
82 if (refs == 1)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
83 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
84 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: 15822
diff changeset
85 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
86 else
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
87 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
88 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: 15822
diff changeset
89 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: 15822
diff changeset
90 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
91 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
92
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
93 static char *
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
94 purple_buddy_icon_data_calculate_filename(guchar *icon_data, 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: 15822
diff changeset
95 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
96 PurpleCipherContext *context;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
97 gchar digest[41];
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
98
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
99 context = purple_cipher_context_new_by_name("sha1", NULL);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
100 if (context == NULL)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
101 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
102 purple_debug_error("buddyicon", "Could not find sha1 cipher\n");
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
103 g_return_val_if_reached(NULL);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
104 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
105
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
106 /* Hash the icon data */
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
107 purple_cipher_context_append(context, icon_data, icon_len);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
108 if (!purple_cipher_context_digest_to_str(context, sizeof(digest), digest, NULL))
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
109 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
110 purple_debug_error("buddyicon", "Failed to get SHA-1 digest.\n");
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
111 g_return_val_if_reached(NULL);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
112 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
113 purple_cipher_context_destroy(context);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
114
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
115 /* Return the filename */
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
116 return g_strdup_printf("%s.%s", digest,
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
117 purple_util_get_image_extension(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: 15822
diff changeset
118 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
119
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
120 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
121 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: 15822
diff changeset
122 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
123 const char *dirname;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
124 char *path;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
125 FILE *file = NULL;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
126
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
127 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
128
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
129 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: 15822
diff changeset
130 return;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
131
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
132 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
133 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: 15822
diff changeset
134
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
135 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: 15822
diff changeset
136 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
137 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: 15822
diff changeset
138
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
139 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: 15822
diff changeset
140 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
141 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: 15822
diff changeset
142 "Unable to create directory %s: %s\n",
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
143 dirname, strerror(errno));
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
144 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
145 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
146
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
147 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: 15822
diff changeset
148 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
149 if (!fwrite(purple_imgstore_get_data(img), purple_imgstore_get_size(img), 1, file))
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
150 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
151 purple_debug_error("buddyicon", "Error writing %s: %s\n",
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
152 path, strerror(errno));
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
153 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
154 else
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
155 purple_debug_info("buddyicon", "Wrote 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: 15822
diff changeset
156
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
157 fclose(file);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
158 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
159 else
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
160 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
161 purple_debug_error("buddyicon", "Unable to create file %s: %s\n",
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
162 path, strerror(errno));
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
163 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
164 return;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
165 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
166 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
167 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
168
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
169 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
170 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: 15822
diff changeset
171 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
172 const char *dirname;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
173 char *path;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
174
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
175 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: 15822
diff changeset
176
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
177 /* 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: 15822
diff changeset
178 * 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
179 printf("file has %d refs\n", GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename)));
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
180 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: 15822
diff changeset
181 return;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
182
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
183 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
184 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: 15822
diff changeset
185
16376
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
186 printf("Going to unlink %s\n", path);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
187 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: 15822
diff changeset
188 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
189 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: 15822
diff changeset
190 {
16376
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
191 printf("Failed to unlink %s\n", path);
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
192
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
193 purple_debug_error("buddyicon", "Failed to delete %s: %s\n",
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
194 path, strerror(errno));
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
195 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
196 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
197 {
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
198 printf("Unlinked %s\n", path);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
199 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
200 }
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
201 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
202
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
203 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
204 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
205
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
206 static void
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
207 image_deleting_cb(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: 15822
diff changeset
208 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
209 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: 15822
diff changeset
210
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
211 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
212 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
213 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
214 g_hash_table_remove(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
215 }
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
216 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
217
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
218 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
219 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: 15822
diff changeset
220 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
221 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
222 PurpleStoredImage *img;
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
223
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
224 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: 15822
diff changeset
225 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: 15822
diff changeset
226
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
227 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
228 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
229 file = purple_buddy_icon_data_calculate_filename(icon_data, icon_len);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
230 if (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
231 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
232 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
233 else
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
234 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: 15822
diff changeset
235
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
236 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: 15822
diff changeset
237 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
238 g_free(file);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
239 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: 15822
diff changeset
240 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
241
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
242 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: 15822
diff changeset
243
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
244 /* 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
245 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: 15822
diff changeset
246
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
247 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
248
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
249 return img;
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
250 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
251
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
252 static PurpleBuddyIcon *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
253 purple_buddy_icon_create(PurpleAccount *account, const char *username)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
254 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
255 PurpleBuddyIcon *icon;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
256 GHashTable *icon_cache;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
257
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 /* 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
259 * 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
260 icon = g_slice_new(PurpleBuddyIcon);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
261 PURPLE_DBUS_REGISTER_POINTER(icon, PurpleBuddyIcon);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
262
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
263 icon->account = account;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
264 icon->username = g_strdup(username);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
265
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
266 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
267
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
268 if (icon_cache == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
269 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
270 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
271
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
272 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
273 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
274
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
275 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: 15822
diff changeset
276 (char *)purple_buddy_icon_get_username(icon), icon);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
277 return icon;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
278 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
279
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
280 PurpleBuddyIcon *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
281 purple_buddy_icon_new(PurpleAccount *account, const char *username,
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
282 void *icon_data, size_t icon_len)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
283 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
284 PurpleBuddyIcon *icon;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
285
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
286 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
287 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
288 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
289 g_return_val_if_fail(icon_len > 0, NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
290
16376
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
291 /* 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
292 * sure to update it as well when members are added. */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
293 icon = purple_buddy_icons_find(account, username);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
294
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
295 /* purple_buddy_icon_create() sets account & username */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
296 if (icon == NULL)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
297 icon = purple_buddy_icon_create(account, username);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
298
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
299 /* Take a reference for the caller of this function. */
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
300 icon->ref_count = 1;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
301
16376
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
302 /* 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
303 * 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
304 icon->img = 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
305 purple_buddy_icon_set_data(icon, icon_data, icon_len);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
306
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
307 return icon;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
308 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
309
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
310 PurpleBuddyIcon *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
311 purple_buddy_icon_ref(PurpleBuddyIcon *icon)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
312 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
313 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
314
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
315 icon->ref_count++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
316
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
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
320 PurpleBuddyIcon *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
321 purple_buddy_icon_unref(PurpleBuddyIcon *icon)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
322 {
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
323 if (icon == NULL)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
324 return NULL;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
325
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
326 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
327
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
328 icon->ref_count--;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
329
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
330 if (icon->ref_count == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
331 {
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
332 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: 15822
diff changeset
333
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
334 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: 15822
diff changeset
335 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: 15822
diff changeset
336
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
337 g_free(icon->username);
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
338 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: 15822
diff changeset
339
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
340 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
341 g_slice_free(PurpleBuddyIcon, icon);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
342
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
343 return NULL;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
346 return icon;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
347 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
348
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
349 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
350 purple_buddy_icon_update(PurpleBuddyIcon *icon)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
351 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
352 PurpleConversation *conv;
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
353 PurpleAccount *account;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
354 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: 15822
diff changeset
355 PurpleBuddyIcon *icon_to_set;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
356 GSList *sl, *list;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
357
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
358 g_return_if_fail(icon != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
359
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
360 account = purple_buddy_icon_get_account(icon);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
361 username = purple_buddy_icon_get_username(icon);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
362
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
363 /* If no data exists, then call the functions below with NULL to
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
364 * unset the icon. They will then unref the icon and it should be
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
365 * destroyed. The only way it wouldn't be destroyed is if someone
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
366 * 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
367 * 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
368 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: 15822
diff changeset
369
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
370 for (list = sl = purple_find_buddies(account, username);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
371 sl != NULL;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
372 sl = sl->next)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
373 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
374 PurpleBuddy *buddy = (PurpleBuddy *)sl->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
375 char *old_icon;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
376
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
377 purple_buddy_set_icon(buddy, icon_to_set);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
378
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
379
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 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
381 "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
382 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: 15822
diff changeset
383 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
384 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: 15822
diff changeset
385 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: 15822
diff changeset
386 "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
387 filename);
16376
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
388 printf("Calling ref_filename(%s)\n", filename);
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
389 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: 15822
diff changeset
390 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
391 else
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
392 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
393 purple_blist_node_remove_setting((PurpleBlistNode *)buddy, "buddy_icon");
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
394 }
16376
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
395 printf("Calling unref_filename(%s)\n", old_icon);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
396 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
397 g_free(old_icon);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
398 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
399
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
400 g_slist_free(list);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
401
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
402 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, username, account);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
403
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
404 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: 15822
diff changeset
405 purple_conv_im_set_icon(PURPLE_CONV_IM(conv), icon_to_set);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
406 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
407
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
408 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
409 purple_buddy_icon_set_data(PurpleBuddyIcon *icon, guchar *data, size_t len)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
410 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
411 PurpleStoredImage *old_img;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
412
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
413 g_return_if_fail(icon != NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
414
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
415 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
416 icon->img = NULL;
15373
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: 15822
diff changeset
418 if (data != NULL && 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
419 icon->img = purple_buddy_icon_data_new(data, len, NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
420
16376
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
421 printf("Calling purple_buddy_icon_update\n");
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
422 purple_buddy_icon_update(icon);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
423
16376
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
424 printf("Calling purple_imgstore_unref\n");
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
425 purple_imgstore_unref(old_img);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
426 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
427
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
428 PurpleAccount *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
429 purple_buddy_icon_get_account(const PurpleBuddyIcon *icon)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
430 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
431 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
432
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
433 return icon->account;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
434 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
435
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
436 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
437 purple_buddy_icon_get_username(const PurpleBuddyIcon *icon)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
438 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
439 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
440
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
441 return icon->username;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
442 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
443
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
444 gconstpointer
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
445 purple_buddy_icon_get_data(const PurpleBuddyIcon *icon, size_t *len)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
446 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
447 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
448
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
449 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: 15822
diff changeset
450 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
451 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
452 *len = purple_imgstore_get_size(icon->img);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
453
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
454 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: 15822
diff changeset
455 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
456
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
457 return NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
458 }
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 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
461 purple_buddy_icon_get_extension(const PurpleBuddyIcon *icon)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
462 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
463 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
464 return purple_imgstore_get_extension(icon->img);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
465
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
466 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
467 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
468
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
469 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
470 purple_buddy_icons_set_for_user(PurpleAccount *account, 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: 15822
diff changeset
471 void *icon_data, size_t icon_len)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
472 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
473 g_return_if_fail(account != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
474 g_return_if_fail(username != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
475
16376
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
476 if (icon_data != NULL && icon_len > 0)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
477 {
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
478 PurpleBuddyIcon *icon;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
479
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
480 icon = purple_buddy_icons_find(account, username);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
481
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
482 if (icon != 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
483 purple_buddy_icon_set_data(icon, icon_data, icon_len);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
484 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
485 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
486 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
487 PurpleBuddyIcon *icon = purple_buddy_icon_new(account, username, icon_data, icon_len);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
488 purple_buddy_icon_unref(icon);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
489 }
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
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
492 static gboolean
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
493 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: 15822
diff changeset
494 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
495 struct stat st;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
496
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
497 if (!g_stat(path, &st))
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
498 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
499 FILE *f = g_fopen(path, "rb");
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
500 if (f)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
501 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
502 *data = g_malloc(st.st_size);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
503 if (!fread(*data, st.st_size, 1, f))
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
504 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
505 purple_debug_error("buddyicon", "Error reading %s: %s\n",
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
506 path, strerror(errno));
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
507 g_free(*data);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
508 return FALSE;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
509 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
510 fclose(f);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
511
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
512 *len = st.st_size;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
513 return TRUE;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
514 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
515 else
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
516 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
517 purple_debug_error("buddyicon", "Unable to open file %s for reading: %s\n",
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
518 path, strerror(errno));
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
519 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
520 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
521 return FALSE;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
522 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
523
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
524 PurpleBuddyIcon *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
525 purple_buddy_icons_find(PurpleAccount *account, const char *username)
15373
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 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: 15822
diff changeset
528 PurpleBuddyIcon *icon = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
529
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
530 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
531 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
532
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
533 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
534
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
535 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: 15822
diff changeset
536 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
537 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: 15822
diff changeset
538 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: 15822
diff changeset
539 const char *dirname;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
540 gboolean caching;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
541 guchar *data;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
542 size_t len;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
543
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
544 if (!b)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
545 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
546
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
547 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: 15822
diff changeset
548
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
549 if (protocol_icon_file == NULL)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
550 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
551
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
552 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: 15822
diff changeset
553
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
554 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: 15822
diff changeset
555 /* 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: 15822
diff changeset
556 * 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: 15822
diff changeset
557 * functions. */
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
558 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: 15822
diff changeset
559
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
560 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: 15822
diff changeset
561 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
562 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: 15822
diff changeset
563 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: 15822
diff changeset
564 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
565 if (icon == NULL)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
566 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
567 icon->ref_count = 0;
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
568 icon->img = 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
569 purple_buddy_icon_set_data(icon, data, len);
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
570 g_free(data);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
571 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
572 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
573 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
574
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
575 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: 15822
diff changeset
576 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
577
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
578 return icon;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
579 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
580
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
581 gboolean
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
582 purple_buddy_icons_has_custom_icon(PurpleContact *contact)
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
583 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
584 g_return_val_if_fail(contact != NULL, FALSE);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
585
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
586 return (purple_blist_node_get_string((PurpleBlistNode*)contact, "custom_buddy_icon") != NULL);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
587 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
588
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
589 PurpleStoredImage *
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
590 purple_buddy_icons_find_custom_icon(PurpleContact *contact)
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
591 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
592 PurpleStoredImage *img;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
593 const char *custom_icon_file;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
594 const char *dirname;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
595 char *path;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
596 guchar *data;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
597 size_t len;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
598
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
599 g_return_val_if_fail(contact != 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
600
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
601 if ((img = g_hash_table_lookup(custom_icon_cache, contact)))
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
602 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
603 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
604 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
605
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
606 custom_icon_file = purple_blist_node_get_string((PurpleBlistNode*)contact, "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
607
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
608 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
609 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
610
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
611 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
612 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
613
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
614 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
615 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
616 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
617 img = purple_buddy_icon_data_new(data, len, custom_icon_file);
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
618 g_free(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
619 g_hash_table_insert(custom_icon_cache, contact, img);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
620 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
621 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
622 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
623
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
624 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
625 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
626
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
627 void
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
628 purple_buddy_icons_set_custom_icon(PurpleContact *contact,
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
629 guchar *icon_data, size_t icon_len)
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
630 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
631 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
632 PurpleStoredImage *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
633 char *old_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
634 PurpleBlistNode *child;
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
635
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
636 old_img = g_hash_table_lookup(custom_icon_cache, contact);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
637
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
638 if (icon_data != NULL && icon_len > 0)
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
639 img = purple_buddy_icon_data_new(icon_data, icon_len, NULL);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
640
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
641 old_icon = g_strdup(purple_blist_node_get_string((PurpleBlistNode *)contact,
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
642 "custom_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
643 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
644 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
645 const char *filename = purple_imgstore_get_filename(img);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
646 purple_blist_node_set_string((PurpleBlistNode *)contact,
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
647 "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
648 filename);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
649 ref_filename(filename);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
650 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
651 else
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
652 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
653 purple_blist_node_remove_setting((PurpleBlistNode *)contact,
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
654 "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
655 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
656 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
657 g_free(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
658
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
659 g_hash_table_insert(custom_icon_cache, contact, 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
660
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
661 for (child = contact->node.child ; child ; child = child->next)
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
662 {
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
663 PurpleBuddy *buddy;
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
664 PurpleConversation *conv;
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
665
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
666 if (!PURPLE_BLIST_NODE_IS_BUDDY(child))
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
667 continue;
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
668
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
669 buddy = (PurpleBuddy *)child;
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
670
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
671 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
672 purple_buddy_get_name(buddy),
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
673 purple_buddy_get_account(buddy));
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
674 if (conv)
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
675 purple_conversation_update(conv, PURPLE_CONV_UPDATE_ICON);
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
676
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
677 purple_blist_update_buddy_icon(buddy);
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
678 }
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
679
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
680 purple_imgstore_unref(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
681 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
682
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
683 void
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
684 purple_buddy_icon_set_old_icons_dir(const char *dirname)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
685 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
686 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: 15822
diff changeset
687 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
688
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
689 static void
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
690 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: 15822
diff changeset
691 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: 15822
diff changeset
692 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
693 char *path;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
694
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
695 if (filename[0] != '/')
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
696 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
697 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: 15822
diff changeset
698 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: 15822
diff changeset
699 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
700 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
701 return;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
702 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
703 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
704
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
705 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: 15822
diff changeset
706 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
707 else
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
708 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: 15822
diff changeset
709
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
710 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: 15822
diff changeset
711 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
712 guchar *icon_data;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
713 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: 15822
diff changeset
714 FILE *file;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
715 char *new_filename;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
716
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
717 if (!read_icon_file(path, &icon_data, &icon_len))
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
718 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
719 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
720 return;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
721 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
722
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
723 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
724
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
725 new_filename = purple_buddy_icon_data_calculate_filename(icon_data, icon_len);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
726 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: 15822
diff changeset
727 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
728 return;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
729 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
730
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
731 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: 15822
diff changeset
732 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: 15822
diff changeset
733 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
734 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: 15822
diff changeset
735 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
736 purple_debug_error("buddyicon", "Error writing %s: %s\n",
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
737 path, strerror(errno));
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
738 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
739 else
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
740 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: 15822
diff changeset
741
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
742 fclose(file);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
743 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
744 else
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
745 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
746 purple_debug_error("buddyicon", "Unable to create file %s: %s\n",
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
747 path, strerror(errno));
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
748 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: 15822
diff changeset
749 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
750 return;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
751 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
752 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
753
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
754 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: 15822
diff changeset
755 setting_name,
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
756 new_filename);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
757 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: 15822
diff changeset
758
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
759 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: 15822
diff changeset
760 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
761 else
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
762 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
763 /* If the icon is gone, drop the setting... */
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
764 purple_blist_node_remove_setting(node,
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
765 setting_name);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
766 g_free(path);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
767 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
768 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
769
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
770 void
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
771 purple_buddy_icons_blist_loaded_cb()
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
772 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
773 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: 15822
diff changeset
774 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: 15822
diff changeset
775
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
776 // TODO: TEMP
16377
44489a2123e7 Since I'm about to push this, I'm going to comment out the temp code that references my home directory.
Richard Laager <rlaager@wiktel.com>
parents: 16376
diff changeset
777 //old_icons_dir = g_strdup("/home/rlaager/.gaim/icons");
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
778
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
779 /* 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: 15822
diff changeset
780 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: 15822
diff changeset
781 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
782 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: 15822
diff changeset
783 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
784 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: 15822
diff changeset
785
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
786 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: 15822
diff changeset
787 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
788 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: 15822
diff changeset
789 "Unable to create directory %s: %s\n",
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
790 dirname, strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
791 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
792 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
793 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
794
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
795 while (node != NULL)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
796 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
797 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: 15822
diff changeset
798 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
799 const char *filename;
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
800
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
801 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: 15822
diff changeset
802 if (filename != NULL)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
803 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
804 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: 15822
diff changeset
805 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
806 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: 15822
diff changeset
807 "buddy_icon",
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
808 dirname, filename);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
809 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
810 else
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
811 {
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
812 char *path = g_build_filename(dirname, 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
813 if (!g_file_test(filename, G_FILE_TEST_EXISTS))
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
814 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
815 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
816 "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
817 }
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
818 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: 15822
diff changeset
819 ref_filename(filename);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
820 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
821 }
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 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
823 else if (PURPLE_BLIST_NODE_IS_CONTACT(node))
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
824 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
825 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: 15822
diff changeset
826
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
827 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: 15822
diff changeset
828 if (filename != NULL)
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
829 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
830 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: 15822
diff changeset
831 {
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
832 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: 15822
diff changeset
833 "custom_buddy_icon",
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
834 dirname, filename);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
835 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
836 else
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
837 {
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
838 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
839 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
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 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
842 "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
843 }
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16378
diff changeset
844 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: 15822
diff changeset
845 ref_filename(filename);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
846 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
847 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
848 }
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
849 node = purple_blist_node_next(node, TRUE);
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
850 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
851 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
852
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
853 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
854 purple_buddy_icons_set_caching(gboolean caching)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
855 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
856 icon_caching = caching;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
857 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
858
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
859 gboolean
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
860 purple_buddy_icons_is_caching(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
861 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
862 return icon_caching;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
863 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
864
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
865 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
866 purple_buddy_icons_set_cache_dir(const char *dir)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
867 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
868 g_return_if_fail(dir != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
869
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
870 g_free(cache_dir);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
871 cache_dir = g_strdup(dir);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
872 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
873
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
874 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
875 purple_buddy_icons_get_cache_dir(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
876 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
877 return cache_dir;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
878 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
879
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
880 // TODO: Deal with this
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
881 char *purple_buddy_icons_get_full_path(const char *icon) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
882 if (icon == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
883 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
884
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
885 if (g_file_test(icon, G_FILE_TEST_IS_REGULAR))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
886 return g_strdup(icon);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
887 else
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
888 return g_build_filename(purple_buddy_icons_get_cache_dir(), icon, NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
889 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
890
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
891 void *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
892 purple_buddy_icons_get_handle()
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
893 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
894 static int handle;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
895
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
896 return &handle;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
897 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
898
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
899 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
900 purple_buddy_icons_init()
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
901 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
902 account_cache = g_hash_table_new_full(
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
903 g_direct_hash, g_direct_equal,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
904 NULL, (GFreeFunc)g_hash_table_destroy);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
905
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
906 icon_data_cache = g_hash_table_new(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: 15822
diff changeset
907 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: 15822
diff changeset
908 g_free, 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
909 custom_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: 15822
diff changeset
910
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
911 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
912
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
913 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
914 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
915 G_CALLBACK(image_deleting_cb), NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
916 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
917
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
918 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
919 purple_buddy_icons_uninit()
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
920 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
921 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
922
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
923 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: 15822
diff changeset
924 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: 15822
diff changeset
925 g_hash_table_destroy(icon_file_cache);
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16373
diff changeset
926 g_hash_table_destroy(custom_icon_cache);
16373
c9b4ff420140 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
927 g_free(old_icons_dir);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
928 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
929
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
930 void purple_buddy_icon_get_scale_size(PurpleBuddyIconSpec *spec, int *width, int *height)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
931 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
932 int new_width, new_height;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
933
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
934 new_width = *width;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
935 new_height = *height;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
936
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
937 if (*width < spec->min_width)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
938 new_width = spec->min_width;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
939 else if (*width > spec->max_width)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
940 new_width = spec->max_width;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
941
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
942 if (*height < spec->min_height)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
943 new_height = spec->min_height;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
944 else if (*height > spec->max_height)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
945 new_height = spec->max_height;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
946
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
947 /* preserve aspect ratio */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
948 if ((double)*height * (double)new_width >
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
949 (double)*width * (double)new_height) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
950 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
951 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
952 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
953 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
954
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
955 *width = new_width;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
956 *height = new_height;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
957 }