Thu, 31 May 2012 03:48:16 +0000
propagate from branch 'im.pidgin.pidgin.2.x.y' (head 0aa32fc00dc281d336971ef3966efe6652dc1bf6)
to branch 'im.pidgin.pidgin' (head 89f064bdd762e62b3e3d3a2153cece816879cee9)
| 6982 | 1 | /** |
|
22613
1077236bf4fb
Add docs to PurpleStoredImage so that doxygen links to it show up
Will Thompson <resiak@pidgin.im>
parents:
20147
diff
changeset
|
2 | * @file imgstore.c IM Image Store API |
| 6982 | 3 | * @ingroup core |
|
20147
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
4 | */ |
|
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
5 | |
|
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
6 | /* purple |
| 6982 | 7 | * |
| 15884 | 8 | * Purple is the legal property of its developers, whose names are too numerous |
| 8046 | 9 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 10 | * source distribution. | |
| 6982 | 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify | |
| 13 | * it under the terms of the GNU General Public License as published by | |
| 14 | * the Free Software Foundation; either version 2 of the License, or | |
| 15 | * (at your option) any later version. | |
| 16 | * | |
| 17 | * This program is distributed in the hope that it will be useful, | |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 20 | * GNU General Public License for more details. | |
| 21 | * | |
| 22 | * You should have received a copy of the GNU General Public License | |
| 23 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18397
diff
changeset
|
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 6982 | 25 | * |
| 26 | */ | |
| 27 | ||
|
18265
9f26190d7f46
Move the define in internal.h instead.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17372
diff
changeset
|
28 | #include "internal.h" |
|
9f26190d7f46
Move the define in internal.h instead.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17372
diff
changeset
|
29 | |
|
17372
92205276b430
Get rid of a run-time dbus warning due to an unregistered storedimg.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16775
diff
changeset
|
30 | #include "dbus-maybe.h" |
| 14639 | 31 | #include "debug.h" |
| 32 | #include "imgstore.h" | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
33 | #include "util.h" |
| 6982 | 34 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
35 | static GHashTable *imgstore; |
|
22764
19145fadd8b4
Add a little safety... just in case someone imgstores 13 million or
Mark Doliner <markdoliner@pidgin.im>
parents:
22763
diff
changeset
|
36 | static unsigned int nextid = 0; |
| 6982 | 37 | |
|
22763
6e4bbebdf127
Better documentation.
Mark Doliner <markdoliner@pidgin.im>
parents:
22613
diff
changeset
|
38 | /* |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
39 | * NOTE: purple_imgstore_add() creates these 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:
15884
diff
changeset
|
40 | * NOTE: make sure to update that function when adding members. |
| 8962 | 41 | */ |
| 15884 | 42 | struct _PurpleStoredImage |
| 8962 | 43 | { |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
44 | int id; |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
45 | guint8 refcount; |
| 8962 | 46 | size_t size; /**< The image data's size. */ |
| 47 | char *filename; /**< The filename (for the UI) */ | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
48 | gpointer data; /**< The image data. */ |
| 8962 | 49 | }; |
| 50 | ||
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
51 | PurpleStoredImage * |
|
16539
75a20ae3a527
Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@pidgin.im>
parents:
16538
diff
changeset
|
52 | purple_imgstore_add(gpointer data, size_t size, const char *filename) |
| 6982 | 53 | { |
| 15884 | 54 | PurpleStoredImage *img; |
| 6982 | 55 | |
|
18397
2148d74e1c6e
purple_imgstore_add() has checks which can lead it to return NULL (which should be NULL, not 0); purple_imgstore_add_with_id() should therefore allow for the possibility that the returned value is NULL and check it before using it. An id of 0 is returned if the function fails.
Evan Schoenberg <evands@pidgin.im>
parents:
18265
diff
changeset
|
56 | g_return_val_if_fail(data != NULL, NULL); |
|
2148d74e1c6e
purple_imgstore_add() has checks which can lead it to return NULL (which should be NULL, not 0); purple_imgstore_add_with_id() should therefore allow for the possibility that the returned value is NULL and check it before using it. An id of 0 is returned if the function fails.
Evan Schoenberg <evands@pidgin.im>
parents:
18265
diff
changeset
|
57 | g_return_val_if_fail(size > 0, NULL); |
| 6982 | 58 | |
|
16446
3a6ed6c3400e
Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents:
16438
diff
changeset
|
59 | img = g_new(PurpleStoredImage, 1); |
|
17372
92205276b430
Get rid of a run-time dbus warning due to an unregistered storedimg.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16775
diff
changeset
|
60 | PURPLE_DBUS_REGISTER_POINTER(img, PurpleStoredImage); |
|
16539
75a20ae3a527
Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@pidgin.im>
parents:
16538
diff
changeset
|
61 | img->data = data; |
| 6982 | 62 | img->size = size; |
| 63 | img->filename = g_strdup(filename); | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
64 | img->refcount = 1; |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
65 | img->id = 0; |
| 6982 | 66 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
67 | return img; |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
68 | } |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
69 | |
|
22652
ba50c2bc1adc
Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
70 | PurpleStoredImage * |
|
ba50c2bc1adc
Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
71 | purple_imgstore_new_from_file(const char *path) |
|
ba50c2bc1adc
Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
72 | { |
|
ba50c2bc1adc
Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
73 | gchar *data = NULL; |
|
ba50c2bc1adc
Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
74 | size_t len; |
|
ba50c2bc1adc
Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
75 | GError *err = NULL; |
|
ba50c2bc1adc
Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
76 | |
|
27491
47e2ad0ea258
Don't try to read in '' as our account icon. I don't know if I have a messed up prefs.xml or something else changed recently.
Paul Aurich <darkrain42@pidgin.im>
parents:
22895
diff
changeset
|
77 | g_return_val_if_fail(path != NULL && *path != '\0', NULL); |
|
47e2ad0ea258
Don't try to read in '' as our account icon. I don't know if I have a messed up prefs.xml or something else changed recently.
Paul Aurich <darkrain42@pidgin.im>
parents:
22895
diff
changeset
|
78 | |
|
22652
ba50c2bc1adc
Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
79 | if (!g_file_get_contents(path, &data, &len, &err)) { |
|
ba50c2bc1adc
Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
80 | purple_debug_error("imgstore", "Error reading %s: %s\n", |
|
ba50c2bc1adc
Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
81 | path, err->message); |
|
ba50c2bc1adc
Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
82 | g_error_free(err); |
|
ba50c2bc1adc
Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
83 | return NULL; |
|
ba50c2bc1adc
Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
84 | } |
|
ba50c2bc1adc
Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
85 | return purple_imgstore_add(data, len, path); |
|
ba50c2bc1adc
Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
86 | } |
|
ba50c2bc1adc
Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
87 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
88 | int |
|
16539
75a20ae3a527
Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@pidgin.im>
parents:
16538
diff
changeset
|
89 | purple_imgstore_add_with_id(gpointer data, size_t size, const char *filename) |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
90 | { |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
91 | PurpleStoredImage *img = purple_imgstore_add(data, size, filename); |
|
18397
2148d74e1c6e
purple_imgstore_add() has checks which can lead it to return NULL (which should be NULL, not 0); purple_imgstore_add_with_id() should therefore allow for the possibility that the returned value is NULL and check it before using it. An id of 0 is returned if the function fails.
Evan Schoenberg <evands@pidgin.im>
parents:
18265
diff
changeset
|
92 | if (img) { |
|
22764
19145fadd8b4
Add a little safety... just in case someone imgstores 13 million or
Mark Doliner <markdoliner@pidgin.im>
parents:
22763
diff
changeset
|
93 | /* |
|
19145fadd8b4
Add a little safety... just in case someone imgstores 13 million or
Mark Doliner <markdoliner@pidgin.im>
parents:
22763
diff
changeset
|
94 | * Use the next unused id number. We do it in a loop on the |
|
19145fadd8b4
Add a little safety... just in case someone imgstores 13 million or
Mark Doliner <markdoliner@pidgin.im>
parents:
22763
diff
changeset
|
95 | * off chance that nextid wraps back around to 0 and the hash |
|
19145fadd8b4
Add a little safety... just in case someone imgstores 13 million or
Mark Doliner <markdoliner@pidgin.im>
parents:
22763
diff
changeset
|
96 | * table still contains entries from the first time around. |
|
19145fadd8b4
Add a little safety... just in case someone imgstores 13 million or
Mark Doliner <markdoliner@pidgin.im>
parents:
22763
diff
changeset
|
97 | */ |
|
19145fadd8b4
Add a little safety... just in case someone imgstores 13 million or
Mark Doliner <markdoliner@pidgin.im>
parents:
22763
diff
changeset
|
98 | do { |
|
19145fadd8b4
Add a little safety... just in case someone imgstores 13 million or
Mark Doliner <markdoliner@pidgin.im>
parents:
22763
diff
changeset
|
99 | img->id = ++nextid; |
|
19145fadd8b4
Add a little safety... just in case someone imgstores 13 million or
Mark Doliner <markdoliner@pidgin.im>
parents:
22763
diff
changeset
|
100 | } while (img->id == 0 || g_hash_table_lookup(imgstore, &(img->id)) != NULL); |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
101 | |
|
18397
2148d74e1c6e
purple_imgstore_add() has checks which can lead it to return NULL (which should be NULL, not 0); purple_imgstore_add_with_id() should therefore allow for the possibility that the returned value is NULL and check it before using it. An id of 0 is returned if the function fails.
Evan Schoenberg <evands@pidgin.im>
parents:
18265
diff
changeset
|
102 | g_hash_table_insert(imgstore, &(img->id), img); |
|
2148d74e1c6e
purple_imgstore_add() has checks which can lead it to return NULL (which should be NULL, not 0); purple_imgstore_add_with_id() should therefore allow for the possibility that the returned value is NULL and check it before using it. An id of 0 is returned if the function fails.
Evan Schoenberg <evands@pidgin.im>
parents:
18265
diff
changeset
|
103 | } |
| 6982 | 104 | |
|
18397
2148d74e1c6e
purple_imgstore_add() has checks which can lead it to return NULL (which should be NULL, not 0); purple_imgstore_add_with_id() should therefore allow for the possibility that the returned value is NULL and check it before using it. An id of 0 is returned if the function fails.
Evan Schoenberg <evands@pidgin.im>
parents:
18265
diff
changeset
|
105 | return (img ? img->id : 0); |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
106 | } |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
107 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
108 | PurpleStoredImage *purple_imgstore_find_by_id(int id) { |
|
16587
50de12a4b81b
disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents:
16586
diff
changeset
|
109 | PurpleStoredImage *img = g_hash_table_lookup(imgstore, &id); |
| 6982 | 110 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
111 | if (img != NULL) |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
112 | purple_debug_misc("imgstore", "retrieved image id %d\n", img->id); |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
113 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
114 | return img; |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
115 | } |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
116 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
117 | gconstpointer purple_imgstore_get_data(PurpleStoredImage *img) { |
|
16538
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16446
diff
changeset
|
118 | g_return_val_if_fail(img != NULL, NULL); |
|
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16446
diff
changeset
|
119 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
120 | return img->data; |
| 6982 | 121 | } |
| 122 | ||
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
123 | size_t purple_imgstore_get_size(PurpleStoredImage *img) |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
124 | { |
|
16538
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16446
diff
changeset
|
125 | g_return_val_if_fail(img != NULL, 0); |
|
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16446
diff
changeset
|
126 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
127 | return img->size; |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
128 | } |
| 6982 | 129 | |
|
16775
8627d2560d40
Get rid of two harmless warnings:
Mark Doliner <markdoliner@pidgin.im>
parents:
16656
diff
changeset
|
130 | const char *purple_imgstore_get_filename(const PurpleStoredImage *img) |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
131 | { |
|
16538
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16446
diff
changeset
|
132 | g_return_val_if_fail(img != NULL, NULL); |
|
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16446
diff
changeset
|
133 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
134 | return img->filename; |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
135 | } |
| 6982 | 136 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
137 | const char *purple_imgstore_get_extension(PurpleStoredImage *img) |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
138 | { |
|
16538
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16446
diff
changeset
|
139 | g_return_val_if_fail(img != NULL, NULL); |
|
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16446
diff
changeset
|
140 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
141 | return purple_util_get_image_extension(img->data, img->size); |
| 6982 | 142 | } |
| 143 | ||
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
144 | void purple_imgstore_ref_by_id(int id) |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
145 | { |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
146 | PurpleStoredImage *img = purple_imgstore_find_by_id(id); |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
147 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
148 | 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:
15884
diff
changeset
|
149 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
150 | purple_imgstore_ref(img); |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
151 | } |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
152 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
153 | void purple_imgstore_unref_by_id(int id) |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
154 | { |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
155 | PurpleStoredImage *img = purple_imgstore_find_by_id(id); |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
156 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
157 | 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:
15884
diff
changeset
|
158 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
159 | purple_imgstore_unref(img); |
| 8962 | 160 | } |
| 161 | ||
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
162 | PurpleStoredImage * |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
163 | purple_imgstore_ref(PurpleStoredImage *img) |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
164 | { |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
165 | g_return_val_if_fail(img != NULL, NULL); |
| 8962 | 166 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
167 | img->refcount++; |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
168 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
169 | return img; |
| 8962 | 170 | } |
| 171 | ||
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
172 | PurpleStoredImage * |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
173 | purple_imgstore_unref(PurpleStoredImage *img) |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
174 | { |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
175 | if (img == NULL) |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
176 | return NULL; |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
177 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
178 | g_return_val_if_fail(img->refcount > 0, NULL); |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
179 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
180 | img->refcount--; |
| 6982 | 181 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
182 | if (img->refcount == 0) |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
183 | { |
|
16438
64e892ac6180
Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
184 | purple_signal_emit(purple_imgstore_get_handle(), |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
185 | "image-deleting", img); |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
186 | if (img->id) |
|
16587
50de12a4b81b
disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents:
16586
diff
changeset
|
187 | g_hash_table_remove(imgstore, &img->id); |
|
16446
3a6ed6c3400e
Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents:
16438
diff
changeset
|
188 | |
|
3a6ed6c3400e
Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents:
16438
diff
changeset
|
189 | g_free(img->data); |
|
3a6ed6c3400e
Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents:
16438
diff
changeset
|
190 | g_free(img->filename); |
|
17372
92205276b430
Get rid of a run-time dbus warning due to an unregistered storedimg.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16775
diff
changeset
|
191 | PURPLE_DBUS_UNREGISTER_POINTER(img); |
|
16446
3a6ed6c3400e
Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents:
16438
diff
changeset
|
192 | g_free(img); |
|
16656
c11fcc08882a
Part of the patch in ticket #383:
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16595
diff
changeset
|
193 | img = NULL; |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
194 | } |
| 6982 | 195 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
196 | return img; |
| 6982 | 197 | } |
| 198 | ||
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
199 | void * |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
200 | purple_imgstore_get_handle() |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
201 | { |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
202 | static int handle; |
| 6982 | 203 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
204 | return &handle; |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
205 | } |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
206 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
207 | void |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
208 | purple_imgstore_init() |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
209 | { |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
210 | void *handle = purple_imgstore_get_handle(); |
| 6982 | 211 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
212 | purple_signal_register(handle, "image-deleting", |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
213 | purple_marshal_VOID__POINTER, NULL, |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
214 | 1, |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
215 | purple_value_new(PURPLE_TYPE_SUBTYPE, |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
216 | PURPLE_SUBTYPE_STORED_IMAGE)); |
| 6982 | 217 | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
218 | imgstore = g_hash_table_new(g_int_hash, g_int_equal); |
| 6982 | 219 | } |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
220 | |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
221 | void |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
222 | purple_imgstore_uninit() |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
223 | { |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
224 | g_hash_table_destroy(imgstore); |
|
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
225 | |
|
16595
edbcbb0b97b3
Fix a bug in the imgstore code that I caught because of the fatal asserts in the test code.
Richard Laager <rlaager@pidgin.im>
parents:
16587
diff
changeset
|
226 | purple_signals_unregister_by_instance(purple_imgstore_get_handle()); |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
227 | } |