Tue, 24 Apr 2007 13:27:42 +0000
If we're not caching icons, then don't save the filename.
| 6846 | 1 | /** |
| 2 | * @file icon.c Buddy Icon API | |
| 3 | * @ingroup core | |
| 4 | * | |
| 15884 | 5 | * purple |
| 6846 | 6 | * |
| 15884 | 7 | * Purple is the legal property of its developers, whose names are too numerous |
| 8046 | 8 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 9 | * source distribution. | |
| 6846 | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify | |
| 12 | * it under the terms of the GNU General Public License as published by | |
| 13 | * the Free Software Foundation; either version 2 of the License, or | |
| 14 | * (at your option) any later version. | |
| 15 | * | |
| 16 | * This program is distributed in the hope that it will be useful, | |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 | * GNU General Public License for more details. | |
| 20 | * | |
| 21 | * You should have received a copy of the GNU General Public License | |
| 22 | * along with this program; if not, write to the Free Software | |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 24 | */ | |
| 25 | #include "internal.h" | |
| 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 | 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 | 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 | 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 | 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)); |
|
16438
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
65 | printf("refs before increment = %d\n", refs); |
|
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
|
66 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
67 | 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
|
68 | 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
|
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 | |
|
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 | 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
|
72 | 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
|
73 | { |
|
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 | 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
|
75 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
76 | 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
|
77 | 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
|
78 | |
|
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 | refs = GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename)); |
|
16438
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
80 | printf("refs before decrement = %d\n", refs); |
|
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
|
81 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
82 | if (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
|
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 | 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
|
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 | 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
|
87 | { |
|
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 | 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
|
89 | 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
|
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 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
92 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
93 | 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
|
94 | 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
|
95 | { |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
96 | 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
|
97 | 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
|
98 | |
|
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 | 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
|
100 | 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
|
101 | { |
|
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 | 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
|
103 | 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
|
104 | } |
|
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 | |
|
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 | /* 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
|
107 | 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
|
108 | 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
|
109 | { |
|
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 | 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
|
111 | 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
|
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 | 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
|
114 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
115 | /* 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
|
116 | 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
|
117 | 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
|
118 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
119 | |
|
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 | 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
|
121 | 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
|
122 | { |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
123 | 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
|
124 | 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
|
125 | 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
|
126 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
127 | 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
|
128 | |
|
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
|
129 | 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
|
130 | 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
|
131 | |
|
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 | 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
|
133 | 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
|
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 | 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
|
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 | 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
|
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 | 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
|
140 | { |
|
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 | 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
|
142 | "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
|
143 | 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
|
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 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
146 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
147 | 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
|
148 | { |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
149 | 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
|
150 | { |
|
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 | 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
|
152 | 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
|
153 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
154 | 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
|
155 | 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
|
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 | 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
|
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 | 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
|
160 | { |
|
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 | 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
|
162 | 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
|
163 | g_free(path); |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
164 | 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
|
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 | 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
|
167 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
168 | |
|
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 | 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
|
170 | 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
|
171 | { |
|
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 | 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
|
173 | 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
|
174 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
175 | 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
|
176 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
177 | /* 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
|
178 | * cache file that are not currently loaded into memory. */ |
|
16438
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
179 | printf("file has %d refs\n", GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename))); |
|
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
180 | if (GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename))) |
|
16421
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
181 | 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
|
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 | 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
|
184 | 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
|
185 | |
|
16438
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
186 | printf("Going to unlink %s\n", path); |
|
16421
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
187 | 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
|
188 | { |
|
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 | 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
|
190 | { |
|
16438
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
191 | printf("Failed to unlink %s\n", path); |
|
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
192 | |
|
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
|
193 | 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
|
194 | 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
|
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 | else |
|
16438
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
197 | { |
|
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
198 | printf("Unlinked %s\n", path); |
|
16421
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
199 | purple_debug_info("buddyicon", "Deleted cache file: %s\n", path); |
|
16438
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
200 | } |
|
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 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
202 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
203 | 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
|
204 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
205 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
206 | 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
|
207 | 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
|
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 | 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
|
210 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
211 | 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
|
212 | { |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
213 | 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
|
214 | 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
|
215 | } |
|
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
|
216 | } |
|
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 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
218 | 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
|
219 | 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
|
220 | { |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
221 | 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
|
222 | 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
|
223 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
224 | 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
|
225 | 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
|
226 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
227 | 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
|
228 | { |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
229 | 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
|
230 | 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
|
231 | 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
|
232 | } |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
233 | else |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
234 | 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
|
235 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
236 | 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
|
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 | 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
|
239 | 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
|
240 | } |
|
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 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
242 | 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
|
243 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
244 | /* 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
|
245 | 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
|
246 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
247 | 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
|
248 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
249 | 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
|
250 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
251 | |
| 15884 | 252 | static PurpleBuddyIcon * |
| 253 | purple_buddy_icon_create(PurpleAccount *account, const char *username) | |
| 9396 | 254 | { |
| 15884 | 255 | PurpleBuddyIcon *icon; |
| 9396 | 256 | GHashTable *icon_cache; |
| 257 | ||
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
258 | /* 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
|
259 | * 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
|
260 | icon = g_slice_new(PurpleBuddyIcon); |
| 15884 | 261 | PURPLE_DBUS_REGISTER_POINTER(icon, PurpleBuddyIcon); |
| 9396 | 262 | |
|
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
|
263 | 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
|
264 | icon->username = g_strdup(username); |
| 9396 | 265 | |
| 266 | icon_cache = g_hash_table_lookup(account_cache, account); | |
| 267 | ||
| 268 | if (icon_cache == NULL) | |
| 269 | { | |
| 270 | icon_cache = g_hash_table_new(g_str_hash, g_str_equal); | |
| 271 | ||
| 272 | g_hash_table_insert(account_cache, account, icon_cache); | |
| 273 | } | |
| 274 | ||
| 275 | 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
|
276 | (char *)purple_buddy_icon_get_username(icon), icon); |
| 9396 | 277 | return icon; |
| 278 | } | |
| 279 | ||
| 15884 | 280 | PurpleBuddyIcon * |
| 281 | 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
|
282 | void *icon_data, size_t icon_len) |
| 6846 | 283 | { |
| 15884 | 284 | PurpleBuddyIcon *icon; |
| 6846 | 285 | |
| 286 | g_return_val_if_fail(account != NULL, NULL); | |
| 287 | 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
|
288 | 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
|
289 | g_return_val_if_fail(icon_len > 0, NULL); |
| 6846 | 290 | |
|
16438
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
291 | /* purple_buddy_icons_find() does allocation, so be |
|
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
292 | * sure to update it as well when members are added. */ |
| 15884 | 293 | icon = purple_buddy_icons_find(account, username); |
| 6846 | 294 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
295 | /* purple_buddy_icon_create() sets account & username */ |
| 6846 | 296 | if (icon == NULL) |
| 15884 | 297 | icon = purple_buddy_icon_create(account, username); |
| 6846 | 298 | |
|
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
|
299 | /* 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
|
300 | icon->ref_count = 1; |
| 6846 | 301 | |
|
16438
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
302 | /* purple_buddy_icon_set_data() sets img, but it |
|
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
303 | * references img first, so we need to initialize it */ |
|
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
304 | icon->img = 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
|
305 | purple_buddy_icon_set_data(icon, icon_data, icon_len); |
|
11423
45f4ca09d1d6
[gaim-migrate @ 13660]
Richard Laager <rlaager@pidgin.im>
parents:
11338
diff
changeset
|
306 | |
| 6846 | 307 | return icon; |
| 308 | } | |
| 309 | ||
| 15884 | 310 | PurpleBuddyIcon * |
| 311 | purple_buddy_icon_ref(PurpleBuddyIcon *icon) | |
| 6846 | 312 | { |
| 313 | g_return_val_if_fail(icon != NULL, NULL); | |
| 314 | ||
| 315 | icon->ref_count++; | |
| 316 | ||
| 317 | return icon; | |
| 318 | } | |
| 319 | ||
| 15884 | 320 | PurpleBuddyIcon * |
| 321 | purple_buddy_icon_unref(PurpleBuddyIcon *icon) | |
| 6846 | 322 | { |
|
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
|
323 | 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
|
324 | 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
|
325 | |
|
12250
5b14301dd1ec
[gaim-migrate @ 14552]
Richard Laager <rlaager@pidgin.im>
parents:
12097
diff
changeset
|
326 | g_return_val_if_fail(icon->ref_count > 0, NULL); |
| 6846 | 327 | |
| 328 | icon->ref_count--; | |
| 329 | ||
| 330 | if (icon->ref_count == 0) | |
| 331 | { | |
|
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
|
332 | 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
|
333 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
334 | 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
|
335 | 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
|
336 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
337 | 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
|
338 | 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
|
339 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
340 | 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
|
341 | g_slice_free(PurpleBuddyIcon, icon); |
| 6846 | 342 | |
| 343 | return NULL; | |
| 344 | } | |
| 345 | ||
| 346 | return icon; | |
| 347 | } | |
| 348 | ||
| 349 | void | |
| 15884 | 350 | purple_buddy_icon_update(PurpleBuddyIcon *icon) |
| 6846 | 351 | { |
| 15884 | 352 | PurpleConversation *conv; |
| 353 | PurpleAccount *account; | |
| 6846 | 354 | 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
|
355 | PurpleBuddyIcon *icon_to_set; |
| 8550 | 356 | GSList *sl, *list; |
| 6846 | 357 | |
| 358 | g_return_if_fail(icon != NULL); | |
| 359 | ||
| 15884 | 360 | account = purple_buddy_icon_get_account(icon); |
| 361 | username = purple_buddy_icon_get_username(icon); | |
| 6846 | 362 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
363 | /* 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
|
364 | * 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
|
365 | * 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
|
366 | * 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
|
367 | * 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
|
368 | 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
|
369 | |
|
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 | 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
|
371 | 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
|
372 | sl = sl->next) |
| 6846 | 373 | { |
| 15884 | 374 | 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
|
375 | char *old_icon; |
| 6846 | 376 | |
|
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
|
377 | 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
|
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 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
380 | 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
|
381 | "buddy_icon")); |
|
16440
d4e3c52ce58b
If we're not caching icons, then don't save the filename.
Richard Laager <rlaager@pidgin.im>
parents:
16439
diff
changeset
|
382 | if (icon->img && purple_buddy_icons_is_caching()) |
|
16421
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
383 | { |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
384 | 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
|
385 | 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
|
386 | "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
|
387 | filename); |
|
16438
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
388 | printf("Calling ref_filename(%s)\n", filename); |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
389 | 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
|
390 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
391 | 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
|
392 | { |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
393 | 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
|
394 | } |
|
16438
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
395 | printf("Calling unref_filename(%s)\n", old_icon); |
|
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
|
396 | 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
|
397 | g_free(old_icon); |
| 6846 | 398 | } |
| 399 | ||
| 8550 | 400 | g_slist_free(list); |
| 401 | ||
| 15884 | 402 | conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, username, account); |
| 6846 | 403 | |
|
10246
aa5bff72f94c
[gaim-migrate @ 11386]
Mark Doliner <markdoliner@pidgin.im>
parents:
9801
diff
changeset
|
404 | 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
|
405 | 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
|
406 | } |
|
37e247d18e78
[gaim-migrate @ 12940]
Richard Laager <rlaager@pidgin.im>
parents:
11033
diff
changeset
|
407 | |
| 6846 | 408 | 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
|
409 | 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
|
410 | { |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
411 | PurpleStoredImage *old_img; |
|
6886
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
412 | |
|
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
|
413 | g_return_if_fail(icon != NULL); |
|
6886
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
414 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
415 | 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
|
416 | icon->img = NULL; |
|
6886
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
417 | |
|
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
|
418 | 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
|
419 | icon->img = purple_buddy_icon_data_new(data, len, NULL); |
|
6886
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
420 | |
|
16438
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
421 | printf("Calling purple_buddy_icon_update\n"); |
|
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
|
422 | purple_buddy_icon_update(icon); |
|
6886
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
423 | |
|
16438
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
424 | printf("Calling purple_imgstore_unref\n"); |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
425 | purple_imgstore_unref(old_img); |
|
15132
672c39839af1
[gaim-migrate @ 17854]
Mark Huetsch <markhuetsch@users.sourceforge.net>
parents:
15117
diff
changeset
|
426 | } |
|
672c39839af1
[gaim-migrate @ 17854]
Mark Huetsch <markhuetsch@users.sourceforge.net>
parents:
15117
diff
changeset
|
427 | |
| 15884 | 428 | PurpleAccount * |
| 429 | purple_buddy_icon_get_account(const PurpleBuddyIcon *icon) | |
| 6846 | 430 | { |
| 431 | g_return_val_if_fail(icon != NULL, NULL); | |
| 432 | ||
| 433 | return icon->account; | |
| 434 | } | |
| 435 | ||
| 436 | const char * | |
| 15884 | 437 | purple_buddy_icon_get_username(const PurpleBuddyIcon *icon) |
| 6846 | 438 | { |
| 439 | g_return_val_if_fail(icon != NULL, NULL); | |
| 440 | ||
| 441 | return icon->username; | |
| 442 | } | |
| 443 | ||
|
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 | gconstpointer |
| 15884 | 445 | purple_buddy_icon_get_data(const PurpleBuddyIcon *icon, size_t *len) |
| 6846 | 446 | { |
| 447 | g_return_val_if_fail(icon != NULL, NULL); | |
| 448 | ||
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
449 | 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
|
450 | { |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
451 | 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
|
452 | *len = purple_imgstore_get_size(icon->img); |
| 6846 | 453 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
454 | 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
|
455 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
456 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
457 | return NULL; |
|
15132
672c39839af1
[gaim-migrate @ 17854]
Mark Huetsch <markhuetsch@users.sourceforge.net>
parents:
15117
diff
changeset
|
458 | } |
|
672c39839af1
[gaim-migrate @ 17854]
Mark Huetsch <markhuetsch@users.sourceforge.net>
parents:
15117
diff
changeset
|
459 | |
|
672c39839af1
[gaim-migrate @ 17854]
Mark Huetsch <markhuetsch@users.sourceforge.net>
parents:
15117
diff
changeset
|
460 | 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
|
461 | purple_buddy_icon_get_extension(const PurpleBuddyIcon *icon) |
|
10953
e5987ea70985
[gaim-migrate @ 12753]
Richard Laager <rlaager@pidgin.im>
parents:
10934
diff
changeset
|
462 | { |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
463 | 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
|
464 | return purple_imgstore_get_extension(icon->img); |
|
10953
e5987ea70985
[gaim-migrate @ 12753]
Richard Laager <rlaager@pidgin.im>
parents:
10934
diff
changeset
|
465 | |
|
e5987ea70985
[gaim-migrate @ 12753]
Richard Laager <rlaager@pidgin.im>
parents:
10934
diff
changeset
|
466 | return NULL; |
|
e5987ea70985
[gaim-migrate @ 12753]
Richard Laager <rlaager@pidgin.im>
parents:
10934
diff
changeset
|
467 | } |
|
e5987ea70985
[gaim-migrate @ 12753]
Richard Laager <rlaager@pidgin.im>
parents:
10934
diff
changeset
|
468 | |
| 6846 | 469 | void |
| 15884 | 470 | 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
|
471 | void *icon_data, size_t icon_len) |
| 6846 | 472 | { |
| 473 | g_return_if_fail(account != NULL); | |
| 474 | g_return_if_fail(username != NULL); | |
| 475 | ||
|
16438
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
476 | if (icon_data != NULL && icon_len > 0) |
|
9305
63a1b462a208
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
477 | { |
|
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
|
478 | PurpleBuddyIcon *icon; |
|
9305
63a1b462a208
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
479 | |
|
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
|
480 | icon = purple_buddy_icons_find(account, username); |
|
9305
63a1b462a208
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
481 | |
|
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
|
482 | 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
|
483 | purple_buddy_icon_set_data(icon, icon_data, icon_len); |
|
9305
63a1b462a208
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
484 | } |
|
63a1b462a208
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
485 | else |
|
63a1b462a208
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
486 | { |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
487 | PurpleBuddyIcon *icon = purple_buddy_icon_new(account, username, icon_data, icon_len); |
| 15884 | 488 | purple_buddy_icon_unref(icon); |
|
9305
63a1b462a208
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
489 | } |
| 6846 | 490 | } |
| 491 | ||
|
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
|
492 | 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
|
493 | 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
|
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 | 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
|
496 | |
|
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 | 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
|
498 | { |
|
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 | 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
|
500 | 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
|
501 | { |
|
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 | *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
|
503 | 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
|
504 | { |
|
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 | 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
|
506 | 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
|
507 | 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
|
508 | 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
|
509 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
510 | 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
|
511 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
512 | *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
|
513 | 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
|
514 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
515 | 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
|
516 | { |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
517 | 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
|
518 | 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
|
519 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
520 | } |
|
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 | 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
|
522 | } |
|
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 | |
| 15884 | 524 | PurpleBuddyIcon * |
| 525 | purple_buddy_icons_find(PurpleAccount *account, const char *username) | |
| 6846 | 526 | { |
| 527 | 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
|
528 | PurpleBuddyIcon *icon = NULL; |
| 6846 | 529 | |
| 530 | g_return_val_if_fail(account != NULL, NULL); | |
| 531 | g_return_val_if_fail(username != NULL, NULL); | |
| 532 | ||
| 533 | icon_cache = g_hash_table_lookup(account_cache, account); | |
| 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 | 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
|
536 | { |
| 15884 | 537 | 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
|
538 | 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
|
539 | 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
|
540 | 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
|
541 | 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
|
542 | size_t len; |
| 9396 | 543 | |
| 544 | if (!b) | |
| 545 | return NULL; | |
| 546 | ||
|
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
|
547 | 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
|
548 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
549 | if (protocol_icon_file == NULL) |
| 9396 | 550 | return NULL; |
| 6846 | 551 | |
|
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
|
552 | 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
|
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 | 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
|
555 | /* 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
|
556 | * 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
|
557 | * 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
|
558 | 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
|
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 | 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
|
561 | { |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
562 | 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
|
563 | 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
|
564 | { |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
565 | 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
|
566 | icon = purple_buddy_icon_create(account, username); |
|
16438
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
567 | icon->ref_count = 0; |
|
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
568 | icon->img = 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
|
569 | 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
|
570 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
571 | 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
|
572 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
573 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
574 | 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
|
575 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
576 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
577 | 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
|
578 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
579 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
580 | gboolean |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
581 | 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
|
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 | 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
|
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 | 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
|
586 | } |
|
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 | PurpleStoredImage * |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
589 | 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
|
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 | 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
|
592 | 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
|
593 | 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
|
594 | 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
|
595 | 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
|
596 | 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
|
597 | |
|
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_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
|
599 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
600 | 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
|
601 | { |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
602 | 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
|
603 | } |
|
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 | 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
|
606 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
607 | 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
|
608 | 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
|
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 | 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
|
611 | 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
|
612 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
613 | 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
|
614 | { |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
615 | 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
|
616 | 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
|
617 | 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
|
618 | 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
|
619 | } |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
620 | 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
|
621 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
622 | 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
|
623 | } |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
624 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
625 | void |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
626 | 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
|
627 | 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
|
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 | 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
|
630 | 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
|
631 | 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
|
632 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
633 | 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
|
634 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
635 | 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
|
636 | 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
|
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 | 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
|
639 | "custom_buddy_icon")); |
|
16440
d4e3c52ce58b
If we're not caching icons, then don't save the filename.
Richard Laager <rlaager@pidgin.im>
parents:
16439
diff
changeset
|
640 | if (img && purple_buddy_icons_is_caching()) |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
641 | { |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
642 | 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
|
643 | 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
|
644 | "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
|
645 | filename); |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
646 | 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
|
647 | } |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
648 | else |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
649 | { |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
650 | 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
|
651 | "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
|
652 | } |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
653 | 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
|
654 | 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
|
655 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
656 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
657 | 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
|
658 | 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
|
659 | } |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
660 | |
|
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
|
661 | 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
|
662 | 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
|
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 | 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
|
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 | |
|
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 | 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
|
668 | 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
|
669 | 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
|
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 | 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
|
672 | |
|
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 | 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
|
674 | { |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
675 | 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
|
676 | 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
|
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 | 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
|
682 | |
|
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 | 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
|
684 | } |
|
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 | 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
|
686 | 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
|
687 | |
|
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 | 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
|
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 | 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
|
691 | 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
|
692 | 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
|
693 | char *new_filename; |
|
9747
5c89f93ad4dc
[gaim-migrate @ 10613]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9396
diff
changeset
|
694 | |
|
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
|
695 | 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
|
696 | { |
|
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 | 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
|
698 | 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
|
699 | } |
|
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 | 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
|
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 | 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
|
704 | 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
|
705 | { |
|
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 | 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
|
707 | } |
|
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 | |
|
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 | 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
|
710 | 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
|
711 | { |
|
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 | 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
|
713 | { |
|
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 | 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
|
715 | 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
|
716 | } |
|
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 | 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
|
718 | 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
|
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 | 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
|
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 | 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
|
723 | { |
|
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 | 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
|
725 | 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
|
726 | 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
|
727 | 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
|
728 | 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
|
729 | } |
|
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 | 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
|
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 | 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
|
733 | 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
|
734 | 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
|
735 | 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
|
736 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
737 | 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
|
738 | } |
|
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 | 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
|
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 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
|
742 | 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
|
743 | 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
|
744 | 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
|
745 | } |
|
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 | |
|
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 | 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
|
749 | 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
|
750 | { |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
751 | 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
|
752 | 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
|
753 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
754 | // TODO: TEMP |
|
16439
c50ef85a3b27
Since I'm about to push this, I'm going to comment out the temp code that references my home directory.
Richard Laager <rlaager@pidgin.im>
parents:
16438
diff
changeset
|
755 | //old_icons_dir = g_strdup("/home/rlaager/.gaim/icons"); |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
756 | |
|
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
|
757 | /* 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
|
758 | 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
|
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 | 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
|
761 | { |
|
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 | 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
|
763 | |
|
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 | 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
|
765 | { |
|
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 | 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
|
767 | "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
|
768 | dirname, strerror(errno)); |
| 9396 | 769 | } |
| 770 | } | |
| 771 | } | |
| 772 | ||
|
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
|
773 | 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
|
774 | { |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
775 | 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
|
776 | { |
|
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 | 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
|
778 | |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
779 | 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
|
780 | 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
|
781 | { |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
782 | 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
|
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 | 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
|
785 | "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
|
786 | 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
|
787 | } |
|
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 | 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
|
789 | { |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
790 | 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
|
791 | { |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
792 | purple_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
|
793 | "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
|
794 | } |
|
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
|
795 | 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
|
796 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
797 | } |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
798 | } |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
799 | 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
|
800 | { |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
801 | 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
|
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 | 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
|
804 | 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
|
805 | { |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
806 | 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
|
807 | { |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
808 | 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
|
809 | "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
|
810 | 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
|
811 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
812 | 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
|
813 | { |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
814 | 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
|
815 | { |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
816 | 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
|
817 | "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
|
818 | } |
|
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
|
819 | 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
|
820 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
821 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
822 | } |
|
f9218e1c4703
The buddy icon code as it stands, with lots of bugs and design flaws.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
823 | 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
|
824 | } |
| 6846 | 825 | } |
| 826 | ||
|
6886
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
827 | void |
| 15884 | 828 | purple_buddy_icons_set_caching(gboolean caching) |
|
6886
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
829 | { |
|
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
830 | icon_caching = caching; |
|
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 | |
|
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
833 | gboolean |
| 15884 | 834 | purple_buddy_icons_is_caching(void) |
|
6886
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
835 | { |
|
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
836 | return icon_caching; |
|
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
837 | } |
|
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
838 | |
|
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
839 | void |
| 15884 | 840 | purple_buddy_icons_set_cache_dir(const char *dir) |
|
6886
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
841 | { |
|
10811
6b7ac5a9dd35
[gaim-migrate @ 12464]
Richard Laager <rlaager@pidgin.im>
parents:
10589
diff
changeset
|
842 | g_return_if_fail(dir != NULL); |
|
6886
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
843 | |
|
13934
c554909e9ff6
[gaim-migrate @ 16342]
Mark Doliner <markdoliner@pidgin.im>
parents:
13555
diff
changeset
|
844 | g_free(cache_dir); |
|
6886
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
845 | cache_dir = g_strdup(dir); |
|
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
846 | } |
|
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
847 | |
|
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
848 | const char * |
| 15884 | 849 | purple_buddy_icons_get_cache_dir(void) |
|
6886
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
850 | { |
|
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
851 | return cache_dir; |
|
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
852 | } |
|
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
853 | |
|
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
|
854 | // TODO: Deal with this |
| 15884 | 855 | char *purple_buddy_icons_get_full_path(const char *icon) { |
|
11303
448b8bae1ca7
[gaim-migrate @ 13503]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
856 | if (icon == NULL) |
|
448b8bae1ca7
[gaim-migrate @ 13503]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
857 | return NULL; |
|
448b8bae1ca7
[gaim-migrate @ 13503]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
858 | |
|
15117
01f77aba34e8
[gaim-migrate @ 17839]
Mark Doliner <markdoliner@pidgin.im>
parents:
14744
diff
changeset
|
859 | if (g_file_test(icon, G_FILE_TEST_IS_REGULAR)) |
|
11303
448b8bae1ca7
[gaim-migrate @ 13503]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
860 | return g_strdup(icon); |
|
448b8bae1ca7
[gaim-migrate @ 13503]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
861 | else |
| 15884 | 862 | 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
|
863 | } |
|
448b8bae1ca7
[gaim-migrate @ 13503]
Richard Laager <rlaager@pidgin.im>
parents:
11256
diff
changeset
|
864 | |
| 6846 | 865 | void * |
| 15884 | 866 | purple_buddy_icons_get_handle() |
| 6846 | 867 | { |
| 868 | static int handle; | |
| 869 | ||
| 870 | return &handle; | |
| 871 | } | |
| 872 | ||
| 873 | void | |
| 15884 | 874 | purple_buddy_icons_init() |
| 6846 | 875 | { |
| 876 | account_cache = g_hash_table_new_full( | |
| 877 | g_direct_hash, g_direct_equal, | |
| 878 | NULL, (GFreeFunc)g_hash_table_destroy); | |
|
6886
97734a57c0f5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
879 | |
|
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
|
880 | 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
|
881 | 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
|
882 | 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
|
883 | 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
|
884 | |
| 15884 | 885 | 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
|
886 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
887 | 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
|
888 | 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
|
889 | G_CALLBACK(image_deleting_cb), NULL); |
| 6846 | 890 | } |
| 891 | ||
| 892 | void | |
| 15884 | 893 | purple_buddy_icons_uninit() |
| 6846 | 894 | { |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
16421
diff
changeset
|
895 | 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
|
896 | |
| 6846 | 897 | 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
|
898 | 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
|
899 | 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
|
900 | 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
|
901 | g_free(old_icons_dir); |
| 6846 | 902 | } |
| 10483 | 903 | |
| 15884 | 904 | void purple_buddy_icon_get_scale_size(PurpleBuddyIconSpec *spec, int *width, int *height) |
| 10483 | 905 | { |
|
15284
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
906 | int new_width, new_height; |
|
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
907 | |
|
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
908 | new_width = *width; |
|
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
909 | new_height = *height; |
|
10523
ef52a88a8512
[gaim-migrate @ 11840]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10483
diff
changeset
|
910 | |
|
15284
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
911 | if (*width < spec->min_width) |
|
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
912 | new_width = spec->min_width; |
|
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
913 | else if (*width > spec->max_width) |
|
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
914 | new_width = spec->max_width; |
| 10483 | 915 | |
|
15284
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
916 | if (*height < spec->min_height) |
|
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
917 | new_height = spec->min_height; |
|
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
918 | else if (*height > spec->max_height) |
|
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
919 | new_height = spec->max_height; |
|
10523
ef52a88a8512
[gaim-migrate @ 11840]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10483
diff
changeset
|
920 | |
|
15284
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
921 | /* preserve aspect ratio */ |
|
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
922 | if ((double)*height * (double)new_width > |
|
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
923 | (double)*width * (double)new_height) { |
|
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
924 | new_width = 0.5 + (double)*width * (double)new_height / (double)*height; |
|
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
925 | } else { |
|
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
926 | new_height = 0.5 + (double)*height * (double)new_width / (double)*width; |
|
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
927 | } |
|
10523
ef52a88a8512
[gaim-migrate @ 11840]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10483
diff
changeset
|
928 | |
|
15284
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
929 | *width = new_width; |
|
98e8f9912107
[gaim-migrate @ 18012]
Mark Doliner <markdoliner@pidgin.im>
parents:
15135
diff
changeset
|
930 | *height = new_height; |
| 10483 | 931 | } |