libpurple/imgstore.c

Sat, 29 Jun 2013 22:10:18 +0530

author
Ankit Vani <a@nevitus.org>
date
Sat, 29 Jun 2013 22:10:18 +0530
branch
soc.2013.gobjectification
changeset 34678
40a30f74a7b8
parent 33662
7777db43477a
child 34797
57724af9660d
permissions
-rw-r--r--

Removed purple_conversation_[gs]et_data(). Used g_object_[gs]et_data() instead.
Removed data from PurpleConversationPrivate.

6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
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
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
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
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
7 *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
8 * Purple is the legal property of its developers, whose names are too numerous
8046
c581b20a47d6 [gaim-migrate @ 8730]
Sean Egan <seanegan@pidgin.im>
parents: 6982
diff changeset
9 * to list here. Please refer to the COPYRIGHT file distributed with this
c581b20a47d6 [gaim-migrate @ 8730]
Sean Egan <seanegan@pidgin.im>
parents: 6982
diff changeset
10 * source distribution.
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
11 *
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
12 * This program is free software; you can redistribute it and/or modify
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
13 * it under the terms of the GNU General Public License as published by
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
14 * the Free Software Foundation; either version 2 of the License, or
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
15 * (at your option) any later version.
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
16 *
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
17 * This program is distributed in the hope that it will be useful,
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
20 * GNU General Public License for more details.
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
21 *
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
22 * You should have received a copy of the GNU General Public License
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
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
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
25 *
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
26 */
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
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
706c89fe995f [gaim-migrate @ 17301]
Patrick Cheung
parents: 14254
diff changeset
31 #include "debug.h"
706c89fe995f [gaim-migrate @ 17301]
Patrick Cheung
parents: 14254
diff changeset
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
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
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
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
37
22763
6e4bbebdf127 Better documentation.
Mark Doliner <markdoliner@pidgin.im>
parents: 22613
diff changeset
38 /*
33661
2ebcb105e606 Rename two functions.
Mark Doliner <mark@kingant.net>
parents: 33656
diff changeset
39 * NOTE: purple_imgstore_new() creates these without zeroing the memory, so
16437
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
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
41 */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
42 struct _PurpleStoredImage
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
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;
33656
d09413e12a04 Better documentation.
Mark Doliner <mark@kingant.net>
parents: 33653
diff changeset
46 size_t size; /**< The image data's size. */
d09413e12a04 Better documentation.
Mark Doliner <mark@kingant.net>
parents: 33653
diff changeset
47 char *filename; /**< The filename (for the UI) */
d09413e12a04 Better documentation.
Mark Doliner <mark@kingant.net>
parents: 33653
diff changeset
48 gpointer data; /**< The image data. */
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
49 };
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
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 *
33661
2ebcb105e606 Rename two functions.
Mark Doliner <mark@kingant.net>
parents: 33656
diff changeset
52 purple_imgstore_new(gpointer data, size_t size, const char *filename)
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
53 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
54 PurpleStoredImage *img;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
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
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
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
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
62 img->size = size;
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
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
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
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 }
33661
2ebcb105e606 Rename two functions.
Mark Doliner <mark@kingant.net>
parents: 33656
diff changeset
85 return purple_imgstore_new(data, len, path);
22652
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
33661
2ebcb105e606 Rename two functions.
Mark Doliner <mark@kingant.net>
parents: 33656
diff changeset
89 purple_imgstore_new_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 {
33661
2ebcb105e606 Rename two functions.
Mark Doliner <mark@kingant.net>
parents: 33656
diff changeset
91 PurpleStoredImage *img = purple_imgstore_new(data, size, filename);
33653
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
92 if (!img) {
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
93 return 0;
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
94 }
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
95
33653
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
96 /*
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
97 * Use the next unused id number. We do it in a loop on the
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
98 * off chance that nextid wraps back around to 0 and the hash
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
99 * table still contains entries from the first time around.
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
100 */
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
101 do {
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
102 img->id = ++nextid;
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
103 } while (img->id == 0 || g_hash_table_lookup(imgstore, &(img->id)) != NULL);
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
104
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
105 g_hash_table_insert(imgstore, &(img->id), img);
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
106
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
107 return img->id;
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
108 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
109
33656
d09413e12a04 Better documentation.
Mark Doliner <mark@kingant.net>
parents: 33653
diff changeset
110 PurpleStoredImage *purple_imgstore_find_by_id(int id)
d09413e12a04 Better documentation.
Mark Doliner <mark@kingant.net>
parents: 33653
diff changeset
111 {
16587
50de12a4b81b disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents: 16586
diff changeset
112 PurpleStoredImage *img = g_hash_table_lookup(imgstore, &id);
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
113
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
114 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
115 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
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 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
118 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
119
33656
d09413e12a04 Better documentation.
Mark Doliner <mark@kingant.net>
parents: 33653
diff changeset
120 gconstpointer purple_imgstore_get_data(PurpleStoredImage *img)
d09413e12a04 Better documentation.
Mark Doliner <mark@kingant.net>
parents: 33653
diff changeset
121 {
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
122 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
123
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
124 return img->data;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
125 }
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
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 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
128 {
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
129 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
130
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 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
132 }
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
133
16775
8627d2560d40 Get rid of two harmless warnings:
Mark Doliner <markdoliner@pidgin.im>
parents: 16656
diff changeset
134 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
135 {
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
136 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
137
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
138 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
139 }
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
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 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
142 {
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
143 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
144
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
145 return purple_util_get_image_extension(img->data, img->size);
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
146 }
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
147
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
148 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
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 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
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 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
153
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
154 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
155 }
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 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
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 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
160
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
161 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
162
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_unref(img);
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
164 }
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
165
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
166 PurpleStoredImage *
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
167 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
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 g_return_val_if_fail(img != NULL, NULL);
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
170
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
171 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
172
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
173 return img;
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
174 }
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
175
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
176 PurpleStoredImage *
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
177 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
178 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
179 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
180 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
181
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
182 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
183
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
184 img->refcount--;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
185
16437
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->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
187 {
16438
64e892ac6180 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents: 16437
diff changeset
188 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
189 "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
190 if (img->id)
16587
50de12a4b81b disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents: 16586
diff changeset
191 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
192
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16438
diff changeset
193 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
194 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
195 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
196 g_free(img);
16656
c11fcc08882a Part of the patch in ticket #383:
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16595
diff changeset
197 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
198 }
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
199
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
200 return img;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
201 }
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
202
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
203 void *
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
204 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
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 static int handle;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
207
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
208 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
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
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
211 void
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_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
213 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
214 void *handle = purple_imgstore_get_handle();
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
215
16437
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_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
217 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
218 1,
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
219 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
220 PURPLE_SUBTYPE_STORED_IMAGE));
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
221
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
222 imgstore = g_hash_table_new(g_int_hash, g_int_equal);
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
223 }
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
224
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
225 void
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
226 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
227 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
228 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
229
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
230 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
231 }

mercurial