annotate libpurple/imgstore.c @ 18202:7df46d8bf114

Move the define in internal.h instead. This requires all .c files to include internal.h before including the other headers. Perhaps we should add the define in CFLAGS instead, when necessary.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Tue, 19 Jun 2007 22:47:12 +0000
parents 4bb617bd3d71
children e356256cb8a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 * @file imgstore.h IM Image Store API
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 * @ingroup core
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4 *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
5 * purple
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
6 *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
7 * Purple is the legal property of its developers, whose names are too numerous
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8 * to list here. Please refer to the COPYRIGHT file distributed with this
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 * source distribution.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 * (at your option) any later version.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 * GNU General Public License for more details.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 #include <glib.h>
18202
7df46d8bf114 Move the define in internal.h instead.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17762
diff changeset
28 #include "internal.h"
7df46d8bf114 Move the define in internal.h instead.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17762
diff changeset
29
17762
4bb617bd3d71 Get rid of a run-time dbus warning due to an unregistered storedimg.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 16701
diff changeset
30 #include "dbus-maybe.h"
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 #include "debug.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 #include "imgstore.h"
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
33 #include "util.h"
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
35 static GHashTable *imgstore;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 static int nextid = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 * Stored image
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 *
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
41 * NOTE: purple_imgstore_add() creates these without zeroing the memory, so
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
42 * NOTE: make sure to update that function when adding members.
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43 */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
44 struct _PurpleStoredImage
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 {
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
46 int id;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
47 guint8 refcount;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 size_t size; /**< The image data's size. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 char *filename; /**< The filename (for the UI) */
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
50 gpointer data; /**< The image data. */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
53 PurpleStoredImage *
16391
24bbd7e46bfe Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@wiktel.com>
parents: 16390
diff changeset
54 purple_imgstore_add(gpointer data, size_t size, const char *filename)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
56 PurpleStoredImage *img;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 g_return_val_if_fail(data != NULL, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 g_return_val_if_fail(size > 0, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16376
diff changeset
61 img = g_new(PurpleStoredImage, 1);
17762
4bb617bd3d71 Get rid of a run-time dbus warning due to an unregistered storedimg.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 16701
diff changeset
62 PURPLE_DBUS_REGISTER_POINTER(img, PurpleStoredImage);
16391
24bbd7e46bfe Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@wiktel.com>
parents: 16390
diff changeset
63 img->data = data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64 img->size = size;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 img->filename = g_strdup(filename);
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
66 img->refcount = 1;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
67 img->id = 0;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
69 return img;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
70 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
71
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
72 int
16391
24bbd7e46bfe Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@wiktel.com>
parents: 16390
diff changeset
73 purple_imgstore_add_with_id(gpointer data, size_t size, const char *filename)
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
74 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
75 PurpleStoredImage *img = purple_imgstore_add(data, size, filename);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
76 img->id = ++nextid;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
77
16507
e340dc515178 disapproval of revision 'a999246dfcbd33c9494afa445d9562aee5e5457c'
Richard Laager <rlaager@wiktel.com>
parents: 16506
diff changeset
78 g_hash_table_insert(imgstore, &(img->id), img);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
80 return img->id;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
81 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
82
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
83 PurpleStoredImage *purple_imgstore_find_by_id(int id) {
16507
e340dc515178 disapproval of revision 'a999246dfcbd33c9494afa445d9562aee5e5457c'
Richard Laager <rlaager@wiktel.com>
parents: 16506
diff changeset
84 PurpleStoredImage *img = g_hash_table_lookup(imgstore, &id);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
86 if (img != NULL)
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
87 purple_debug_misc("imgstore", "retrieved image id %d\n", img->id);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
88
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
89 return img;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
90 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
91
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
92 gconstpointer purple_imgstore_get_data(PurpleStoredImage *img) {
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
93 g_return_val_if_fail(img != NULL, NULL);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
94
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
95 return img->data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
96 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
97
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
98 size_t purple_imgstore_get_size(PurpleStoredImage *img)
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
99 {
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
100 g_return_val_if_fail(img != NULL, 0);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
101
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
102 return img->size;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
103 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104
16701
77cfd9bd6536 Get rid of two harmless warnings:
Mark Doliner <mark@kingant.net>
parents: 16587
diff changeset
105 const char *purple_imgstore_get_filename(const PurpleStoredImage *img)
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
106 {
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
107 g_return_val_if_fail(img != NULL, NULL);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
108
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
109 return img->filename;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
110 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
112 const char *purple_imgstore_get_extension(PurpleStoredImage *img)
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
113 {
16390
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
114 g_return_val_if_fail(img != NULL, NULL);
4fc51a87ce42 Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@wiktel.com>
parents: 16381
diff changeset
115
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
116 return purple_util_get_image_extension(img->data, img->size);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
119 void purple_imgstore_ref_by_id(int id)
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
120 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
121 PurpleStoredImage *img = purple_imgstore_find_by_id(id);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
122
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
123 g_return_if_fail(img != NULL);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
124
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
125 purple_imgstore_ref(img);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
126 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
127
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
128 void purple_imgstore_unref_by_id(int id)
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
129 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
130 PurpleStoredImage *img = purple_imgstore_find_by_id(id);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
131
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
132 g_return_if_fail(img != NULL);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
133
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
134 purple_imgstore_unref(img);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
137 PurpleStoredImage *
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
138 purple_imgstore_ref(PurpleStoredImage *img)
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
139 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
140 g_return_val_if_fail(img != NULL, NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
142 img->refcount++;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
143
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
144 return img;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
147 PurpleStoredImage *
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
148 purple_imgstore_unref(PurpleStoredImage *img)
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
149 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
150 if (img == NULL)
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
151 return NULL;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
152
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
153 g_return_val_if_fail(img->refcount > 0, NULL);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
154
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
155 img->refcount--;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
157 if (img->refcount == 0)
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
158 {
16376
dd47fa8ba3e4 Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
Richard Laager <rlaager@wiktel.com>
parents: 16375
diff changeset
159 purple_signal_emit(purple_imgstore_get_handle(),
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
160 "image-deleting", img);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
161 if (img->id)
16507
e340dc515178 disapproval of revision 'a999246dfcbd33c9494afa445d9562aee5e5457c'
Richard Laager <rlaager@wiktel.com>
parents: 16506
diff changeset
162 g_hash_table_remove(imgstore, &img->id);
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16376
diff changeset
163
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16376
diff changeset
164 g_free(img->data);
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16376
diff changeset
165 g_free(img->filename);
17762
4bb617bd3d71 Get rid of a run-time dbus warning due to an unregistered storedimg.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 16701
diff changeset
166 PURPLE_DBUS_UNREGISTER_POINTER(img);
16381
72dc611f3257 Fix the custom icon stuff, and various memory leaks. At this point, custom
Richard Laager <rlaager@wiktel.com>
parents: 16376
diff changeset
167 g_free(img);
16587
f2d2df46e68e Part of the patch in ticket #383:
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 16527
diff changeset
168 img = NULL;
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
169 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
170
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
171 return img;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
172 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
174 void *
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
175 purple_imgstore_get_handle()
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
176 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
177 static int handle;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
179 return &handle;
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
180 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
181
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
182 void
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
183 purple_imgstore_init()
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
184 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
185 void *handle = purple_imgstore_get_handle();
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
186
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
187 purple_signal_register(handle, "image-deleting",
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
188 purple_marshal_VOID__POINTER, NULL,
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
189 1,
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
190 purple_value_new(PURPLE_TYPE_SUBTYPE,
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
191 PURPLE_SUBTYPE_STORED_IMAGE));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
192
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
193 imgstore = g_hash_table_new(g_int_hash, g_int_equal);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
194 }
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
195
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
196 void
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
197 purple_imgstore_uninit()
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
198 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
199 g_hash_table_destroy(imgstore);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
200
16527
1d3d54e964ce Fix a bug in the imgstore code that I caught because of the fatal asserts in the test code.
Richard Laager <rlaager@wiktel.com>
parents: 16507
diff changeset
201 purple_signals_unregister_by_instance(purple_imgstore_get_handle());
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 15822
diff changeset
202 }