libpurple/buddyicon.c

Tue, 24 Apr 2007 03:57:07 +0000

author
Richard Laager <rlaager@pidgin.im>
date
Tue, 24 Apr 2007 03:57:07 +0000
branch
rlaager.gaim_migration
changeset 16437
7ff7c3405ea2
parent 16421
f9218e1c4703
child 16438
64e892ac6180
permissions
-rw-r--r--

Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
imgstore subsystem to not require IDs for everything.

6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1 /**
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
2 * @file icon.c Buddy Icon API
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
3 * @ingroup core
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
4 *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
5 * purple
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
6 *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
7 * Purple is the legal property of its developers, whose names are too numerous
8046
c581b20a47d6 [gaim-migrate @ 8730]
Sean Egan <seanegan@pidgin.im>
parents: 7721
diff changeset
8 * to list here. Please refer to the COPYRIGHT file distributed with this
c581b20a47d6 [gaim-migrate @ 8730]
Sean Egan <seanegan@pidgin.im>
parents: 7721
diff changeset
9 * source distribution.
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
10 *
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
14 * (at your option) any later version.
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
15 *
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
19 * GNU General Public License for more details.
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
20 *
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
24 */
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
25 #include "internal.h"
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
26 #include "buddyicon.h"
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
27 #include "cipher.h"
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
28 #include "conversation.h"
13555
b4d6a5e6853a [gaim-migrate @ 15932]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12996
diff changeset
29 #include "dbus-maybe.h"
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
30 #include "debug.h"
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
31 #include "imgstore.h"
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
32 #include "util.h"
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
33
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
34 typedef struct _PurpleBuddyIconData PurpleBuddyIconData;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
35
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
36 /* NOTE: Instances of this struct are allocated without zeroing the memory, so
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
37 * NOTE: be sure to update purple_buddy_icon_new() if you add members. */
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
38 struct _PurpleBuddyIcon
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
39 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
40 PurpleAccount *account; /**< The account the user is on. */
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
41 char *username; /**< The username the icon belongs to. */
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
42 PurpleStoredImage *img; /**< The id of the stored image with the
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
43 the icon data. */
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
44 int ref_count; /**< The buddy icon reference count. */
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
45 };
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
46
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
47 static GHashTable *account_cache = NULL;
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
48 static GHashTable *icon_data_cache = NULL;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
49 static GHashTable *icon_file_cache = NULL;
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
50 static GHashTable *custom_icon_cache = NULL;
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
51 static char *cache_dir = NULL;
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
52 static gboolean icon_caching = TRUE;
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
53
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
54 /* For ~/.gaim to ~/.purple migration. */
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
55 static char *old_icons_dir = NULL;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
56
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
57 static void
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
58 ref_filename(const char *filename)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
59 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
60 int refs;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
61
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
62 g_return_if_fail(filename != NULL);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
63
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
64 refs = GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
65
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
66 g_hash_table_insert(icon_file_cache, g_strdup(filename),
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
67 GINT_TO_POINTER(refs + 1));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
68 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
69
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
70 static void
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
71 unref_filename(const char *filename)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
72 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
73 int refs;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
74
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
75 if (filename == NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
76 return;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
77
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
78 refs = GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
79
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
80 if (refs == 1)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
81 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
82 g_hash_table_remove(icon_file_cache, filename);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
83 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
84 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
85 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
86 g_hash_table_insert(icon_file_cache, g_strdup(filename),
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
87 GINT_TO_POINTER(refs - 1));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
88 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
89 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
90
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
91 static char *
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
92 purple_buddy_icon_data_calculate_filename(guchar *icon_data, size_t icon_len)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
93 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
94 PurpleCipherContext *context;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
95 gchar digest[41];
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
96
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
97 context = purple_cipher_context_new_by_name("sha1", NULL);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
98 if (context == NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
99 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
100 purple_debug_error("buddyicon", "Could not find sha1 cipher\n");
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
101 g_return_val_if_reached(NULL);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
102 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
103
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
104 /* Hash the icon data */
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
105 purple_cipher_context_append(context, icon_data, icon_len);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
106 if (!purple_cipher_context_digest_to_str(context, sizeof(digest), digest, NULL))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
107 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
108 purple_debug_error("buddyicon", "Failed to get SHA-1 digest.\n");
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
109 g_return_val_if_reached(NULL);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
110 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
111 purple_cipher_context_destroy(context);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
112
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
113 /* Return the filename */
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
114 return g_strdup_printf("%s.%s", digest,
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
115 purple_util_get_image_extension(icon_data, icon_len));
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
116 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
117
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
118 static void
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
119 purple_buddy_icon_data_cache(PurpleStoredImage *img)
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
120 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
121 const char *dirname;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
122 char *path;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
123 FILE *file = NULL;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
124
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
125 g_return_if_fail(img != NULL);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
126
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
127 if (!purple_buddy_icons_is_caching())
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
128 return;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
129
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
130 dirname = purple_buddy_icons_get_cache_dir();
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
131 path = g_build_filename(dirname, purple_imgstore_get_filename(img), NULL);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
132
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
133 if (!g_file_test(dirname, G_FILE_TEST_IS_DIR))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
134 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
135 purple_debug_info("buddyicon", "Creating icon cache directory.\n");
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
136
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
137 if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
138 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
139 purple_debug_error("buddyicon",
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
140 "Unable to create directory %s: %s\n",
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
141 dirname, strerror(errno));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
142 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
143 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
144
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
145 if ((file = g_fopen(path, "wb")) != NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
146 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
147 if (!fwrite(purple_imgstore_get_data(img), purple_imgstore_get_size(img), 1, file))
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
148 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
149 purple_debug_error("buddyicon", "Error writing %s: %s\n",
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
150 path, strerror(errno));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
151 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
152 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
153 purple_debug_info("buddyicon", "Wrote cache file: %s\n", path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
154
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
155 fclose(file);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
156 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
157 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
158 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
159 purple_debug_error("buddyicon", "Unable to create file %s: %s\n",
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
160 path, strerror(errno));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
161 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
162 return;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
163 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
164 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
165 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
166
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
167 static void
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
168 purple_buddy_icon_data_uncache_file(const char *filename)
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
169 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
170 const char *dirname;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
171 char *path;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
172
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
173 g_return_if_fail(filename != NULL);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
174
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
175 /* It's possible that there are other references to this icon
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
176 * cache file that are not currently loaded into memory. */
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
177 if (g_hash_table_lookup(icon_file_cache, filename))
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
178 return;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
179
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
180 dirname = purple_buddy_icons_get_cache_dir();
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
181 path = g_build_filename(dirname, filename, NULL);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
182
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
183 if (g_file_test(path, G_FILE_TEST_EXISTS))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
184 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
185 if (g_unlink(path))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
186 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
187 purple_debug_error("buddyicon", "Failed to delete %s: %s\n",
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
188 path, strerror(errno));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
189 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
190 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
191 purple_debug_info("buddyicon", "Deleted cache file: %s\n", path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
192 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
193
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
194 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
195 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
196
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
197 static void
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
198 image_deleting_cb(PurpleStoredImage *img, gpointer data)
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
199 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
200 const char *filename = purple_imgstore_get_filename(img);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
201
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
202 if (img == g_hash_table_lookup(icon_data_cache, filename))
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
203 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
204 purple_buddy_icon_data_uncache_file(filename);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
205 g_hash_table_remove(icon_data_cache, filename);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
206 }
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
207 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
208
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
209 static PurpleStoredImage *
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
210 purple_buddy_icon_data_new(guchar *icon_data, size_t icon_len, const char *filename)
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
211 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
212 char *file;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
213 PurpleStoredImage *img;
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
214
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
215 g_return_val_if_fail(icon_data != NULL, NULL);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
216 g_return_val_if_fail(icon_len > 0, NULL);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
217
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
218 if (filename == NULL)
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
219 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
220 file = purple_buddy_icon_data_calculate_filename(icon_data, icon_len);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
221 if (file == NULL)
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
222 return NULL;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
223 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
224 else
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
225 file = g_strdup(filename);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
226
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
227 if ((img = g_hash_table_lookup(icon_data_cache, file)))
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
228 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
229 g_free(file);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
230 return purple_imgstore_ref(img);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
231 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
232
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
233 img = purple_imgstore_add(icon_data, icon_len, file);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
234
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
235 /* This will take ownership of file and g_free it either now or later. */
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
236 g_hash_table_insert(icon_data_cache, file, img);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
237
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
238 purple_buddy_icon_data_cache(img);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
239
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
240 return img;
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
241 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
242
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
243 static PurpleBuddyIcon *
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
244 purple_buddy_icon_create(PurpleAccount *account, const char *username)
9396
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
245 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
246 PurpleBuddyIcon *icon;
9396
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
247 GHashTable *icon_cache;
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
248
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
249 /* This does not zero. See purple_buddy_icon_new() for
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
250 * information on which function allocates which member. */
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
251 icon = g_slice_new(PurpleBuddyIcon);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
252 PURPLE_DBUS_REGISTER_POINTER(icon, PurpleBuddyIcon);
9396
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
253
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
254 icon->account = account;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
255 icon->username = g_strdup(username);
9396
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
256
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
257 icon_cache = g_hash_table_lookup(account_cache, account);
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
258
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
259 if (icon_cache == NULL)
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
260 {
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
261 icon_cache = g_hash_table_new(g_str_hash, g_str_equal);
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
262
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
263 g_hash_table_insert(account_cache, account, icon_cache);
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
264 }
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
265
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
266 g_hash_table_insert(icon_cache,
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
267 (char *)purple_buddy_icon_get_username(icon), icon);
9396
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
268 return icon;
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
269 }
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
270
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
271 PurpleBuddyIcon *
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
272 purple_buddy_icon_new(PurpleAccount *account, const char *username,
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
273 void *icon_data, size_t icon_len)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
274 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
275 PurpleBuddyIcon *icon;
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
276
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
277 g_return_val_if_fail(account != NULL, NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
278 g_return_val_if_fail(username != NULL, NULL);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
279 g_return_val_if_fail(icon_data != NULL, NULL);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
280 g_return_val_if_fail(icon_len > 0, NULL);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
281
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
282 icon = purple_buddy_icons_find(account, username);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
283
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
284 /* purple_buddy_icon_create() sets account & username */
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
285 if (icon == NULL)
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
286 icon = purple_buddy_icon_create(account, username);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
287
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
288 /* Take a reference for the caller of this function. */
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
289 icon->ref_count = 1;
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
290
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
291 /* purple_buddy_icon_set_data() sets img */
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
292 purple_buddy_icon_set_data(icon, icon_data, icon_len);
11423
45f4ca09d1d6 [gaim-migrate @ 13660]
Richard Laager <rlaager@pidgin.im>
parents: 11338
diff changeset
293
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
294 return icon;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
295 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
296
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
297 PurpleBuddyIcon *
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
298 purple_buddy_icon_ref(PurpleBuddyIcon *icon)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
299 {
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
300 g_return_val_if_fail(icon != NULL, NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
301
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
302 icon->ref_count++;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
303
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
304 return icon;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
305 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
306
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
307 PurpleBuddyIcon *
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
308 purple_buddy_icon_unref(PurpleBuddyIcon *icon)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
309 {
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
310 if (icon == NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
311 return NULL;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
312
12250
5b14301dd1ec [gaim-migrate @ 14552]
Richard Laager <rlaager@pidgin.im>
parents: 12097
diff changeset
313 g_return_val_if_fail(icon->ref_count > 0, NULL);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
314
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
315 icon->ref_count--;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
316
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
317 if (icon->ref_count == 0)
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
318 {
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
319 GHashTable *icon_cache = g_hash_table_lookup(account_cache, purple_buddy_icon_get_account(icon));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
320
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
321 if (icon_cache != NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
322 g_hash_table_remove(icon_cache, purple_buddy_icon_get_username(icon));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
323
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
324 g_free(icon->username);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
325 purple_imgstore_unref(icon->img);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
326
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
327 PURPLE_DBUS_UNREGISTER_POINTER(icon);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
328 g_slice_free(PurpleBuddyIcon, icon);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
329
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
330 return NULL;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
331 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
332
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
333 return icon;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
334 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
335
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
336 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
337 purple_buddy_icon_update(PurpleBuddyIcon *icon)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
338 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
339 PurpleConversation *conv;
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
340 PurpleAccount *account;
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
341 const char *username;
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
342 PurpleBuddyIcon *icon_to_set;
8550
0e3fd4e193f4 [gaim-migrate @ 9292]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
343 GSList *sl, *list;
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
344
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
345 g_return_if_fail(icon != NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
346
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
347 account = purple_buddy_icon_get_account(icon);
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
348 username = purple_buddy_icon_get_username(icon);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
349
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
350 /* If no data exists, then call the functions below with NULL to
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
351 * unset the icon. They will then unref the icon and it should be
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
352 * destroyed. The only way it wouldn't be destroyed is if someone
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
353 * else is holding a reference to it, in which case they can kill
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
354 * the icon when they realize it has no data. */
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
355 icon_to_set = icon->img ? icon : NULL;
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
356
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
357 for (list = sl = purple_find_buddies(account, username);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
358 sl != NULL;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
359 sl = sl->next)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
360 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
361 PurpleBuddy *buddy = (PurpleBuddy *)sl->data;
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
362 char *old_icon;
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
363
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
364 purple_buddy_set_icon(buddy, icon_to_set);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
365
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
366
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
367 old_icon = g_strdup(purple_blist_node_get_string((PurpleBlistNode *)buddy,
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
368 "buddy_icon"));
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
369 if (icon->img)
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
370 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
371 const char *filename = purple_imgstore_get_filename(icon->img);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
372 purple_blist_node_set_string((PurpleBlistNode *)buddy,
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
373 "buddy_icon",
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
374 filename);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
375 ref_filename(filename);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
376 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
377 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
378 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
379 purple_blist_node_remove_setting((PurpleBlistNode *)buddy, "buddy_icon");
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
380 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
381 unref_filename(old_icon);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
382 g_free(old_icon);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
383 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
384
8550
0e3fd4e193f4 [gaim-migrate @ 9292]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
385 g_slist_free(list);
0e3fd4e193f4 [gaim-migrate @ 9292]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
386
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
387 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, username, account);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
388
10246
aa5bff72f94c [gaim-migrate @ 11386]
Mark Doliner <markdoliner@pidgin.im>
parents: 9801
diff changeset
389 if (conv != NULL)
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
390 purple_conv_im_set_icon(PURPLE_CONV_IM(conv), icon_to_set);
11040
37e247d18e78 [gaim-migrate @ 12940]
Richard Laager <rlaager@pidgin.im>
parents: 11033
diff changeset
391 }
37e247d18e78 [gaim-migrate @ 12940]
Richard Laager <rlaager@pidgin.im>
parents: 11033
diff changeset
392
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
393 void
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
394 purple_buddy_icon_set_data(PurpleBuddyIcon *icon, guchar *data, size_t len)
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
395 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
396 PurpleStoredImage *old_img;
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
397
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
398 g_return_if_fail(icon != NULL);
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
399
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
400 old_img = icon->img;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
401 icon->img = NULL;
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
402
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
403 if (data != NULL && len > 0)
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
404 icon->img = purple_buddy_icon_data_new(data, len, NULL);
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
405
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
406 purple_buddy_icon_update(icon);
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
407
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
408 purple_imgstore_unref(old_img);
15132
672c39839af1 [gaim-migrate @ 17854]
Mark Huetsch <markhuetsch@users.sourceforge.net>
parents: 15117
diff changeset
409 }
672c39839af1 [gaim-migrate @ 17854]
Mark Huetsch <markhuetsch@users.sourceforge.net>
parents: 15117
diff changeset
410
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
411 PurpleAccount *
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
412 purple_buddy_icon_get_account(const PurpleBuddyIcon *icon)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
413 {
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
414 g_return_val_if_fail(icon != NULL, NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
415
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
416 return icon->account;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
417 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
418
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
419 const char *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
420 purple_buddy_icon_get_username(const PurpleBuddyIcon *icon)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
421 {
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
422 g_return_val_if_fail(icon != NULL, NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
423
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
424 return icon->username;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
425 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
426
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
427 gconstpointer
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
428 purple_buddy_icon_get_data(const PurpleBuddyIcon *icon, size_t *len)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
429 {
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
430 g_return_val_if_fail(icon != NULL, NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
431
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
432 if (icon->img)
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
433 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
434 if (len != NULL)
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
435 *len = purple_imgstore_get_size(icon->img);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
436
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
437 return purple_imgstore_get_data(icon->img);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
438 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
439
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
440 return NULL;
15132
672c39839af1 [gaim-migrate @ 17854]
Mark Huetsch <markhuetsch@users.sourceforge.net>
parents: 15117
diff changeset
441 }
672c39839af1 [gaim-migrate @ 17854]
Mark Huetsch <markhuetsch@users.sourceforge.net>
parents: 15117
diff changeset
442
672c39839af1 [gaim-migrate @ 17854]
Mark Huetsch <markhuetsch@users.sourceforge.net>
parents: 15117
diff changeset
443 const char *
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
444 purple_buddy_icon_get_extension(const PurpleBuddyIcon *icon)
10953
e5987ea70985 [gaim-migrate @ 12753]
Richard Laager <rlaager@pidgin.im>
parents: 10934
diff changeset
445 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
446 if (icon->img != NULL)
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
447 return purple_imgstore_get_extension(icon->img);
10953
e5987ea70985 [gaim-migrate @ 12753]
Richard Laager <rlaager@pidgin.im>
parents: 10934
diff changeset
448
e5987ea70985 [gaim-migrate @ 12753]
Richard Laager <rlaager@pidgin.im>
parents: 10934
diff changeset
449 return NULL;
e5987ea70985 [gaim-migrate @ 12753]
Richard Laager <rlaager@pidgin.im>
parents: 10934
diff changeset
450 }
e5987ea70985 [gaim-migrate @ 12753]
Richard Laager <rlaager@pidgin.im>
parents: 10934
diff changeset
451
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
452 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
453 purple_buddy_icons_set_for_user(PurpleAccount *account, const char *username,
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
454 void *icon_data, size_t icon_len)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
455 {
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
456 g_return_if_fail(account != NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
457 g_return_if_fail(username != NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
458
9305
63a1b462a208 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
459 if (icon_data == NULL || icon_len == 0)
63a1b462a208 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
460 {
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
461 PurpleBuddyIcon *icon;
9305
63a1b462a208 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
462
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
463 icon = purple_buddy_icons_find(account, username);
9305
63a1b462a208 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
464
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
465 if (icon != NULL)
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
466 purple_buddy_icon_set_data(icon, icon_data, icon_len);
9305
63a1b462a208 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
467 }
63a1b462a208 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
468 else
63a1b462a208 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
469 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
470 PurpleBuddyIcon *icon = purple_buddy_icon_new(account, username, icon_data, icon_len);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
471 purple_buddy_icon_unref(icon);
9305
63a1b462a208 [gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents: 9285
diff changeset
472 }
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
473 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
474
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
475 static gboolean
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
476 read_icon_file(const char *path, guchar **data, size_t *len)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
477 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
478 struct stat st;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
479
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
480 if (!g_stat(path, &st))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
481 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
482 FILE *f = g_fopen(path, "rb");
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
483 if (f)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
484 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
485 *data = g_malloc(st.st_size);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
486 if (!fread(*data, st.st_size, 1, f))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
487 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
488 purple_debug_error("buddyicon", "Error reading %s: %s\n",
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
489 path, strerror(errno));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
490 g_free(*data);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
491 return FALSE;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
492 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
493 fclose(f);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
494
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
495 *len = st.st_size;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
496 return TRUE;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
497 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
498 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
499 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
500 purple_debug_error("buddyicon", "Unable to open file %s for reading: %s\n",
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
501 path, strerror(errno));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
502 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
503 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
504 return FALSE;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
505 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
506
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
507 PurpleBuddyIcon *
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
508 purple_buddy_icons_find(PurpleAccount *account, const char *username)
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
509 {
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
510 GHashTable *icon_cache;
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
511 PurpleBuddyIcon *icon = NULL;
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
512
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
513 g_return_val_if_fail(account != NULL, NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
514 g_return_val_if_fail(username != NULL, NULL);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
515
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
516 icon_cache = g_hash_table_lookup(account_cache, account);
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
517
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
518 if ((icon_cache == NULL) || ((icon = g_hash_table_lookup(icon_cache, username)) == NULL))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
519 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
520 PurpleBuddy *b = purple_find_buddy(account, username);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
521 const char *protocol_icon_file;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
522 const char *dirname;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
523 gboolean caching;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
524 guchar *data;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
525 size_t len;
9396
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
526
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
527 if (!b)
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
528 return NULL;
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
529
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
530 protocol_icon_file = purple_blist_node_get_string((PurpleBlistNode*)b, "buddy_icon");
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
531
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
532 if (protocol_icon_file == NULL)
9396
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
533 return NULL;
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
534
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
535 dirname = purple_buddy_icons_get_cache_dir();
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
536
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
537 caching = purple_buddy_icons_is_caching();
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
538 /* By disabling caching temporarily, we avoid a loop
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
539 * and don't have to add special code through several
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
540 * functions. */
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
541 purple_buddy_icons_set_caching(FALSE);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
542
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
543 if (protocol_icon_file != NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
544 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
545 char *path = g_build_filename(dirname, protocol_icon_file, NULL);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
546 if (read_icon_file(path, &data, &len))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
547 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
548 if (icon == NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
549 icon = purple_buddy_icon_create(account, username);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
550 purple_buddy_icon_set_data(icon, data, len);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
551 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
552 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
553 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
554
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
555 purple_buddy_icons_set_caching(caching);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
556 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
557
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
558 return icon;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
559 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
560
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
561 gboolean
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
562 purple_buddy_icons_has_custom_icon(PurpleContact *contact)
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
563 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
564 g_return_val_if_fail(contact != NULL, FALSE);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
565
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
566 return (purple_blist_node_get_string((PurpleBlistNode*)contact, "custom_buddy_icon") != NULL);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
567 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
568
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
569 PurpleStoredImage *
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
570 purple_buddy_icons_find_custom_icon(PurpleContact *contact)
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
571 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
572 PurpleStoredImage *img;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
573 const char *custom_icon_file;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
574 const char *dirname;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
575 char *path;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
576 guchar *data;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
577 size_t len;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
578
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
579 g_return_val_if_fail(contact != NULL, NULL);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
580
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
581 if ((img = g_hash_table_lookup(custom_icon_cache, contact)))
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
582 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
583 return purple_imgstore_ref(img);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
584 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
585
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
586 custom_icon_file = purple_blist_node_get_string((PurpleBlistNode*)contact, "custom_buddy_icon");
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
587
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
588 if (custom_icon_file == NULL)
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
589 return NULL;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
590
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
591 dirname = purple_buddy_icons_get_cache_dir();
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
592 path = g_build_filename(dirname, custom_icon_file, NULL);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
593
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
594 if (read_icon_file(path, &data, &len))
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
595 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
596 g_free(path);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
597 img = purple_buddy_icon_data_new(data, len, custom_icon_file);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
598 g_hash_table_insert(custom_icon_cache, contact, img);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
599 return img;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
600 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
601 g_free(path);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
602
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
603 return NULL;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
604 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
605
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
606 void
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
607 purple_buddy_icons_set_custom_icon(PurpleContact *contact,
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
608 guchar *icon_data, size_t icon_len)
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
609 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
610 PurpleStoredImage *old_img;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
611 PurpleStoredImage *img = NULL;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
612 char *old_icon;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
613
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
614 old_img = g_hash_table_lookup(custom_icon_cache, contact);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
615
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
616 if (icon_data != NULL && icon_len > 0)
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
617 img = purple_buddy_icon_data_new(icon_data, icon_len, NULL);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
618
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
619 old_icon = g_strdup(purple_blist_node_get_string((PurpleBlistNode *)contact,
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
620 "custom_buddy_icon"));
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
621 if (img)
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
622 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
623 const char *filename = purple_imgstore_get_filename(img);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
624 purple_blist_node_set_string((PurpleBlistNode *)contact,
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
625 "custom_buddy_icon",
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
626 filename);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
627 ref_filename(filename);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
628 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
629 else
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
630 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
631 purple_blist_node_remove_setting((PurpleBlistNode *)contact,
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
632 "custom_buddy_icon");
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
633 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
634 unref_filename(old_icon);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
635 g_free(old_icon);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
636
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
637
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
638 g_hash_table_insert(custom_icon_cache, contact, img);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
639 purple_imgstore_unref(old_img);
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
640 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
641
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
642 void
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
643 purple_buddy_icon_set_old_icons_dir(const char *dirname)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
644 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
645 old_icons_dir = g_strdup(dirname);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
646 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
647
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
648 static void
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
649 migrate_buddy_icon(PurpleBlistNode *node, const char *setting_name,
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
650 const char *dirname, const char *filename)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
651 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
652 char *path;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
653
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
654 if (filename[0] != '/')
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
655 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
656 path = g_build_filename(dirname, filename, NULL);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
657 if (g_file_test(path, G_FILE_TEST_EXISTS))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
658 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
659 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
660 return;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
661 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
662 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
663
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
664 path = g_build_filename(old_icons_dir, filename, NULL);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
665 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
666 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
667 path = g_strdup(filename);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
668
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
669 if (g_file_test(path, G_FILE_TEST_EXISTS))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
670 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
671 guchar *icon_data;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
672 size_t icon_len;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
673 FILE *file;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
674 char *new_filename;
9747
5c89f93ad4dc [gaim-migrate @ 10613]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 9396
diff changeset
675
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
676 if (!read_icon_file(path, &icon_data, &icon_len))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
677 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
678 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
679 return;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
680 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
681
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
682 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
683
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
684 new_filename = purple_buddy_icon_data_calculate_filename(icon_data, icon_len);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
685 if (new_filename == NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
686 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
687 return;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
688 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
689
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
690 path = g_build_filename(dirname, new_filename, NULL);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
691 if ((file = g_fopen(path, "wb")) != NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
692 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
693 if (!fwrite(icon_data, icon_len, 1, file))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
694 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
695 purple_debug_error("buddyicon", "Error writing %s: %s\n",
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
696 path, strerror(errno));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
697 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
698 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
699 purple_debug_info("buddyicon", "Wrote migrated cache file: %s\n", path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
700
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
701 fclose(file);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
702 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
703 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
704 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
705 purple_debug_error("buddyicon", "Unable to create file %s: %s\n",
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
706 path, strerror(errno));
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
707 g_free(new_filename);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
708 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
709 return;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
710 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
711 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
712
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
713 purple_blist_node_set_string(node,
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
714 setting_name,
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
715 new_filename);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
716 ref_filename(new_filename);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
717
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
718 g_free(new_filename);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
719 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
720 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
721 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
722 /* If the icon is gone, drop the setting... */
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
723 purple_blist_node_remove_setting(node,
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
724 setting_name);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
725 g_free(path);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
726 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
727 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
728
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
729 void
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
730 purple_buddy_icons_blist_loaded_cb()
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
731 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
732 PurpleBlistNode *node = purple_blist_get_root();
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
733 const char *dirname = purple_buddy_icons_get_cache_dir();
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
734
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
735 // TODO: TEMP
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
736 old_icons_dir = g_strdup("/home/rlaager/.gaim/icons");
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
737
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
738 /* Doing this once here saves having to check it inside a loop. */
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
739 if (old_icons_dir != NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
740 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
741 if (!g_file_test(dirname, G_FILE_TEST_IS_DIR))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
742 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
743 purple_debug_info("buddyicon", "Creating icon cache directory.\n");
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
744
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
745 if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
746 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
747 purple_debug_error("buddyicon",
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
748 "Unable to create directory %s: %s\n",
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
749 dirname, strerror(errno));
9396
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
750 }
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
751 }
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
752 }
b559fae057ee [gaim-migrate @ 10208]
Tim Ringenbach <marv@pidgin.im>
parents: 9327
diff changeset
753
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
754 while (node != NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
755 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
756 if (PURPLE_BLIST_NODE_IS_BUDDY(node))
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
757 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
758 const char *filename;
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
759
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
760 filename = purple_blist_node_get_string(node, "buddy_icon");
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
761 if (filename != NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
762 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
763 if (old_icons_dir != NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
764 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
765 migrate_buddy_icon(node,
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
766 "buddy_icon",
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
767 dirname, filename);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
768 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
769 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
770 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
771 if (!g_file_test(filename, G_FILE_TEST_EXISTS))
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
772 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
773 purple_blist_node_remove_setting(node,
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
774 "buddy_icon");
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
775 }
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
776 ref_filename(filename);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
777 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
778 }
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
779 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
780 else if (PURPLE_BLIST_NODE_IS_CONTACT(node))
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
781 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
782 const char *filename;
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
783
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
784 filename = purple_blist_node_get_string(node, "custom_buddy_icon");
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
785 if (filename != NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
786 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
787 if (old_icons_dir != NULL)
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
788 {
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
789 migrate_buddy_icon(node,
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
790 "custom_buddy_icon",
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
791 dirname, filename);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
792 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
793 else
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
794 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
795 if (!g_file_test(filename, G_FILE_TEST_EXISTS))
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
796 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
797 purple_blist_node_remove_setting(node,
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
798 "custom_buddy_icon");
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
799 }
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
800 ref_filename(filename);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
801 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
802 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
803 }
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
804 node = purple_blist_node_next(node, TRUE);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
805 }
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
806 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
807
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
808 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
809 purple_buddy_icons_set_caching(gboolean caching)
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
810 {
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
811 icon_caching = caching;
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
812 }
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
813
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
814 gboolean
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
815 purple_buddy_icons_is_caching(void)
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
816 {
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
817 return icon_caching;
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
818 }
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
819
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
820 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
821 purple_buddy_icons_set_cache_dir(const char *dir)
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
822 {
10811
6b7ac5a9dd35 [gaim-migrate @ 12464]
Richard Laager <rlaager@pidgin.im>
parents: 10589
diff changeset
823 g_return_if_fail(dir != NULL);
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
824
13934
c554909e9ff6 [gaim-migrate @ 16342]
Mark Doliner <markdoliner@pidgin.im>
parents: 13555
diff changeset
825 g_free(cache_dir);
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
826 cache_dir = g_strdup(dir);
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
827 }
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
828
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
829 const char *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
830 purple_buddy_icons_get_cache_dir(void)
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
831 {
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
832 return cache_dir;
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
833 }
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
834
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
835 // TODO: Deal with this
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
836 char *purple_buddy_icons_get_full_path(const char *icon) {
11303
448b8bae1ca7 [gaim-migrate @ 13503]
Richard Laager <rlaager@pidgin.im>
parents: 11256
diff changeset
837 if (icon == NULL)
448b8bae1ca7 [gaim-migrate @ 13503]
Richard Laager <rlaager@pidgin.im>
parents: 11256
diff changeset
838 return NULL;
448b8bae1ca7 [gaim-migrate @ 13503]
Richard Laager <rlaager@pidgin.im>
parents: 11256
diff changeset
839
15117
01f77aba34e8 [gaim-migrate @ 17839]
Mark Doliner <markdoliner@pidgin.im>
parents: 14744
diff changeset
840 if (g_file_test(icon, G_FILE_TEST_IS_REGULAR))
11303
448b8bae1ca7 [gaim-migrate @ 13503]
Richard Laager <rlaager@pidgin.im>
parents: 11256
diff changeset
841 return g_strdup(icon);
448b8bae1ca7 [gaim-migrate @ 13503]
Richard Laager <rlaager@pidgin.im>
parents: 11256
diff changeset
842 else
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
843 return g_build_filename(purple_buddy_icons_get_cache_dir(), icon, NULL);
11303
448b8bae1ca7 [gaim-migrate @ 13503]
Richard Laager <rlaager@pidgin.im>
parents: 11256
diff changeset
844 }
448b8bae1ca7 [gaim-migrate @ 13503]
Richard Laager <rlaager@pidgin.im>
parents: 11256
diff changeset
845
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
846 void *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
847 purple_buddy_icons_get_handle()
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
848 {
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
849 static int handle;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
850
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
851 return &handle;
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
852 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
853
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
854 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
855 purple_buddy_icons_init()
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
856 {
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
857 account_cache = g_hash_table_new_full(
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
858 g_direct_hash, g_direct_equal,
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
859 NULL, (GFreeFunc)g_hash_table_destroy);
6886
97734a57c0f5 [gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
860
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
861 icon_data_cache = g_hash_table_new(g_str_hash, g_str_equal);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
862 icon_file_cache = g_hash_table_new_full(g_str_hash, g_str_equal,
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
863 g_free, NULL);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
864 custom_icon_cache = g_hash_table_new(g_direct_hash, g_direct_equal);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
865
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
866 cache_dir = g_build_filename(purple_user_dir(), "icons", NULL);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
867
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
868 purple_signal_connect(purple_imgstore_get_handle(), "image-deleting",
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
869 purple_buddy_icons_get_handle(),
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
870 G_CALLBACK(image_deleting_cb), NULL);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
871 }
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
872
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
873 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
874 purple_buddy_icons_uninit()
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
875 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
876 purple_signals_disconnect_by_handle(purple_buddy_icons_get_handle());
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
877
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
878 g_hash_table_destroy(account_cache);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
879 g_hash_table_destroy(icon_data_cache);
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
880 g_hash_table_destroy(icon_file_cache);
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 16421
diff changeset
881 g_hash_table_destroy(custom_icon_cache);
16421
f9218e1c4703 The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
882 g_free(old_icons_dir);
6846
f814f02dca87 [gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
883 }
10483
e7b09a8b1f52 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
884
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
885 void purple_buddy_icon_get_scale_size(PurpleBuddyIconSpec *spec, int *width, int *height)
10483
e7b09a8b1f52 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
886 {
15284
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
887 int new_width, new_height;
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
888
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
889 new_width = *width;
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
890 new_height = *height;
10523
ef52a88a8512 [gaim-migrate @ 11840]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10483
diff changeset
891
15284
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
892 if (*width < spec->min_width)
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
893 new_width = spec->min_width;
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
894 else if (*width > spec->max_width)
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
895 new_width = spec->max_width;
10483
e7b09a8b1f52 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
896
15284
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
897 if (*height < spec->min_height)
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
898 new_height = spec->min_height;
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
899 else if (*height > spec->max_height)
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
900 new_height = spec->max_height;
10523
ef52a88a8512 [gaim-migrate @ 11840]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10483
diff changeset
901
15284
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
902 /* preserve aspect ratio */
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
903 if ((double)*height * (double)new_width >
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
904 (double)*width * (double)new_height) {
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
905 new_width = 0.5 + (double)*width * (double)new_height / (double)*height;
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
906 } else {
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
907 new_height = 0.5 + (double)*height * (double)new_width / (double)*width;
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
908 }
10523
ef52a88a8512 [gaim-migrate @ 11840]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10483
diff changeset
909
15284
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
910 *width = new_width;
98e8f9912107 [gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents: 15135
diff changeset
911 *height = new_height;
10483
e7b09a8b1f52 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10246
diff changeset
912 }

mercurial