libpurple/imgstore.c

Thu, 03 Apr 2014 16:02:37 +0200

author
Tomasz Wasilczyk <twasilczyk@pidgin.im>
date
Thu, 03 Apr 2014 16:02:37 +0200
changeset 35686
cae91a875b23
parent 35470
8ee08a41f2f3
child 35750
db721872a325
permissions
-rw-r--r--

Merge release-2.x.y

20147
66f05a854eee applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
1 /* purple
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
2 *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
3 * 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
4 * 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
5 * source distribution.
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
6 *
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
8 * 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
9 * the Free Software Foundation; either version 2 of the License, or
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
10 * (at your option) any later version.
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 distributed in the hope that it will be useful,
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
15 * GNU General Public License for more details.
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 * You should have received a copy of the GNU General Public License
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
18 * 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
19 * 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
20 *
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
18265
9f26190d7f46 Move the define in internal.h instead.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17372
diff changeset
23 #include "internal.h"
9f26190d7f46 Move the define in internal.h instead.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17372
diff changeset
24
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
25 #include "dbus-maybe.h"
14639
706c89fe995f [gaim-migrate @ 17301]
Patrick Cheung
parents: 14254
diff changeset
26 #include "debug.h"
706c89fe995f [gaim-migrate @ 17301]
Patrick Cheung
parents: 14254
diff changeset
27 #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
28 #include "util.h"
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
29
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
30 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
31 static unsigned int nextid = 0;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
32
22763
6e4bbebdf127 Better documentation.
Mark Doliner <markdoliner@pidgin.im>
parents: 22613
diff changeset
33 /*
33661
2ebcb105e606 Rename two functions.
Mark Doliner <mark@kingant.net>
parents: 33656
diff changeset
34 * 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
35 * NOTE: make sure to update that function when adding members.
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
36 */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
37 struct _PurpleStoredImage
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
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 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
40 guint8 refcount;
35470
8ee08a41f2f3 Convert some other doxygen-type comments
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
41 size_t size; /* The image data's size. */
8ee08a41f2f3 Convert some other doxygen-type comments
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
42 char *filename; /* The filename (for the UI) */
8ee08a41f2f3 Convert some other doxygen-type comments
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
43 gpointer data; /* The image data. */
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
44 };
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
45
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
46 PurpleStoredImage *
33661
2ebcb105e606 Rename two functions.
Mark Doliner <mark@kingant.net>
parents: 33656
diff changeset
47 purple_imgstore_new(gpointer data, size_t size, const char *filename)
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
48 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
49 PurpleStoredImage *img;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
50
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
51 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
52 g_return_val_if_fail(size > 0, NULL);
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
53
16446
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16438
diff changeset
54 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
55 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
56 img->data = data;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
57 img->size = size;
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
58 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
59 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
60 img->id = 0;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
61
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
62 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
63 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
64
22652
ba50c2bc1adc Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20147
diff changeset
65 PurpleStoredImage *
ba50c2bc1adc Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20147
diff changeset
66 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
67 {
ba50c2bc1adc Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20147
diff changeset
68 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
69 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
70 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
71
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
72 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
73
22652
ba50c2bc1adc Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20147
diff changeset
74 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
75 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
76 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
77 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
78 return NULL;
ba50c2bc1adc Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20147
diff changeset
79 }
33661
2ebcb105e606 Rename two functions.
Mark Doliner <mark@kingant.net>
parents: 33656
diff changeset
80 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
81 }
ba50c2bc1adc Make it simple to create a stored-image from a filename.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 20147
diff changeset
82
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
83 int
33661
2ebcb105e606 Rename two functions.
Mark Doliner <mark@kingant.net>
parents: 33656
diff changeset
84 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
85 {
33661
2ebcb105e606 Rename two functions.
Mark Doliner <mark@kingant.net>
parents: 33656
diff changeset
86 PurpleStoredImage *img = purple_imgstore_new(data, size, filename);
33653
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
87 if (!img) {
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
88 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
89 }
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
90
33653
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
91 /*
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
92 * 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
93 * 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
94 * table still contains entries from the first time around.
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
95 */
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
96 do {
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
97 img->id = ++nextid;
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
98 } 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
99
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
100 g_hash_table_insert(imgstore, &(img->id), img);
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
101
33c8355ead2a Simpler control flow.
Mark Doliner <mark@kingant.net>
parents: 28981
diff changeset
102 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
103 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
104
33656
d09413e12a04 Better documentation.
Mark Doliner <mark@kingant.net>
parents: 33653
diff changeset
105 PurpleStoredImage *purple_imgstore_find_by_id(int id)
d09413e12a04 Better documentation.
Mark Doliner <mark@kingant.net>
parents: 33653
diff changeset
106 {
16587
50de12a4b81b disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents: 16586
diff changeset
107 PurpleStoredImage *img = g_hash_table_lookup(imgstore, &id);
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
108
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
109 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
110 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
111
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
112 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
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
33656
d09413e12a04 Better documentation.
Mark Doliner <mark@kingant.net>
parents: 33653
diff changeset
115 gconstpointer purple_imgstore_get_data(PurpleStoredImage *img)
d09413e12a04 Better documentation.
Mark Doliner <mark@kingant.net>
parents: 33653
diff changeset
116 {
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
117 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
118
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
119 return img->data;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
120 }
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
121
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
122 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
123 {
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
124 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
125
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
126 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
127 }
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
128
16775
8627d2560d40 Get rid of two harmless warnings:
Mark Doliner <markdoliner@pidgin.im>
parents: 16656
diff changeset
129 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
130 {
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
131 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
132
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
133 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
134 }
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
135
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
136 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
137 {
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
138 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
139
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
140 return purple_util_get_image_extension(img->data, img->size);
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
141 }
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
142
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
143 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
144 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
145 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
146
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
147 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
148
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
149 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
150 }
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 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
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 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
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 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
157
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
158 purple_imgstore_unref(img);
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
159 }
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
160
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
161 PurpleStoredImage *
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
162 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
163 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
164 g_return_val_if_fail(img != NULL, NULL);
8962
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 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
167
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
168 return img;
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
169 }
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 PurpleStoredImage *
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
172 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
173 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
174 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
175 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
176
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
177 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
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 img->refcount--;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
180
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
181 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
182 {
16438
64e892ac6180 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents: 16437
diff changeset
183 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
184 "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
185 if (img->id)
16587
50de12a4b81b disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents: 16586
diff changeset
186 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
187
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16438
diff changeset
188 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
189 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
190 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
191 g_free(img);
16656
c11fcc08882a Part of the patch in ticket #383:
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16595
diff changeset
192 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
193 }
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
194
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
195 return img;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
196 }
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
197
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 void *
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
199 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
200 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
201 static int handle;
6982
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 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
204 }
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 void
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
207 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
208 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
209 void *handle = purple_imgstore_get_handle();
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
210
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
211 purple_signal_register(handle, "image-deleting",
34818
a65e961e1e29 Refactored core, ft, imgstore to use GType instead of PurpleValue
Ankit Vani <a@nevitus.org>
parents: 34797
diff changeset
212 purple_marshal_VOID__POINTER, G_TYPE_NONE,
a65e961e1e29 Refactored core, ft, imgstore to use GType instead of PurpleValue
Ankit Vani <a@nevitus.org>
parents: 34797
diff changeset
213 1, PURPLE_TYPE_STORED_IMAGE);
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
214
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
215 imgstore = g_hash_table_new(g_int_hash, g_int_equal);
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
216 }
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
217
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
218 void
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_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
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 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
222
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
223 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
224 }
34797
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
225
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
226 static PurpleStoredImage *
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
227 purple_imgstore_copy(PurpleStoredImage *img)
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
228 {
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
229 PurpleStoredImage *img_copy;
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
230
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
231 g_return_val_if_fail(img != NULL, NULL);
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
232
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
233 img_copy = g_new(PurpleStoredImage, 1);
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
234 *img_copy = *img;
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
235
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
236 return img_copy;
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
237 }
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
238
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
239 GType
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
240 purple_imgstore_get_type(void)
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
241 {
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
242 static GType type = 0;
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
243
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
244 if (type == 0) {
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
245 type = g_boxed_type_register_static("PurpleStoredImage",
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
246 (GBoxedCopyFunc)purple_imgstore_copy,
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
247 (GBoxedFreeFunc)g_free);
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
248 }
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
249
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
250 return type;
57724af9660d Added temporary GBoxed to PurpleStoredImage
Ankit Vani <a@nevitus.org>
parents: 33662
diff changeset
251 }

mercurial