libpurple/imgstore.c

Fri, 28 Sep 2007 20:29:06 +0000

author
Richard Laager <rlaager@pidgin.im>
date
Fri, 28 Sep 2007 20:29:06 +0000
changeset 20756
2828e7b71a7c
parent 20147
66f05a854eee
child 22613
1077236bf4fb
child 22652
ba50c2bc1adc
permissions
-rw-r--r--

propagate from branch 'im.pidgin.rlaager.merging.2_2_1_conflicts' (head 2c886553edaf187292439e8fea5eb6cace270126)
to branch 'im.pidgin.pidgin' (head 4d669acf2042a39fd9aa77ed011c492aab5e3c1b)

6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
1 /**
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
2 * @file imgstore.h IM Image Store API
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
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
28 #include <glib.h>
18265
9f26190d7f46 Move the define in internal.h instead.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17372
diff changeset
29 #include "internal.h"
9f26190d7f46 Move the define in internal.h instead.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17372
diff changeset
30
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
31 #include "dbus-maybe.h"
14639
706c89fe995f [gaim-migrate @ 17301]
Patrick Cheung
parents: 14254
diff changeset
32 #include "debug.h"
706c89fe995f [gaim-migrate @ 17301]
Patrick Cheung
parents: 14254
diff changeset
33 #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
34 #include "util.h"
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
35
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
36 static GHashTable *imgstore;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
37 static int nextid = 0;
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
38
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
39 /**
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
40 * Stored image
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
41 *
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
42 * 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
43 * NOTE: make sure to update that function when adding members.
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
44 */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
45 struct _PurpleStoredImage
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
46 {
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
47 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
48 guint8 refcount;
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
49 size_t size; /**< The image data's size. */
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
50 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
51 gpointer data; /**< The image data. */
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
52 };
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
53
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
54 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
55 purple_imgstore_add(gpointer data, size_t size, const char *filename)
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
56 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
57 PurpleStoredImage *img;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
58
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
59 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
60 g_return_val_if_fail(size > 0, NULL);
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
61
16446
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16438
diff changeset
62 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
63 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
64 img->data = data;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
65 img->size = size;
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
66 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
67 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
68 img->id = 0;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
69
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
70 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
71 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
72
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
73 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
74 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
75 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
76 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
77 if (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
78 img->id = ++nextid;
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
79
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
80 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
81 }
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
82
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
83 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
84 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
85
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
86 PurpleStoredImage *purple_imgstore_find_by_id(int id) {
16587
50de12a4b81b disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents: 16586
diff changeset
87 PurpleStoredImage *img = g_hash_table_lookup(imgstore, &id);
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
88
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
89 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
90 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
91
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
92 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
93 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
94
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
95 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
96 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
97
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
98 return img->data;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
99 }
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
100
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 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
102 {
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
103 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
104
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
105 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
106 }
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
107
16775
8627d2560d40 Get rid of two harmless warnings:
Mark Doliner <markdoliner@pidgin.im>
parents: 16656
diff changeset
108 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
109 {
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
110 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
111
16437
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->filename;
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
113 }
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
114
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
115 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
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 purple_util_get_image_extension(img->data, img->size);
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 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
123 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
124 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
125
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
126 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
127
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
128 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
129 }
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
130
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
131 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
132 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
133 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
134
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
135 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
136
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
137 purple_imgstore_unref(img);
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
138 }
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
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 PurpleStoredImage *
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
141 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
142 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
143 g_return_val_if_fail(img != NULL, NULL);
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
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 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
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 return img;
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
148 }
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
149
16437
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 *
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
151 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
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 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
154 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
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_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
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 img->refcount--;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
159
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
160 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
161 {
16438
64e892ac6180 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@pidgin.im>
parents: 16437
diff changeset
162 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
163 "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
164 if (img->id)
16587
50de12a4b81b disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents: 16586
diff changeset
165 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
166
3a6ed6c3400e Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@pidgin.im>
parents: 16438
diff changeset
167 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
168 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
169 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
170 g_free(img);
16656
c11fcc08882a Part of the patch in ticket #383:
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16595
diff changeset
171 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
172 }
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
173
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
174 return img;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
175 }
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
176
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
177 void *
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
178 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
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 static int handle;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
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 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
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
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
185 void
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
186 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
187 {
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
188 void *handle = purple_imgstore_get_handle();
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
189
16437
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
190 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
191 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
192 1,
7ff7c3405ea2 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
193 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
194 PURPLE_SUBTYPE_STORED_IMAGE));
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
diff changeset
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 imgstore = g_hash_table_new(g_int_hash, g_int_equal);
6982
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
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_uninit()
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 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
203
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
204 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
205 }

mercurial