annotate src/imgstore.c @ 10206:cf991e2b63cb

[gaim-migrate @ 11327] Don't crash when signing on with Gadu-Gadu, and don't have 2 states called "Invisible" (one should be "Invisible for Friends")--I think that was inadvertant. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 19 Nov 2004 03:46:15 +0000
parents 4ff4c34b7500
children 8bda65b88e49
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1 /**
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
2 * @file imgstore.h IM Image Store API
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
3 * @ingroup core
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
4 *
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
5 * gaim
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
6 *
8046
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 6982
diff changeset
7 * Gaim is the legal property of its developers, whose names are too numerous
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 6982
diff changeset
8 * to list here. Please refer to the COPYRIGHT file distributed with this
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 6982
diff changeset
9 * source distribution.
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
10 *
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
14 * (at your option) any later version.
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
15 *
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
19 * GNU General Public License for more details.
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
20 *
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
24 *
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
25 */
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
26
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
27 #include <glib.h>
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
28 #include <debug.h>
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
29 #include <imgstore.h>
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
30
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
31 static GSList *imgstore = NULL;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
32 static int nextid = 0;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
33
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
34 /**
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
35 * Stored image
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
36 *
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
37 * Represents a single IM image awaiting display and/or transmission.
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
38 * Now that this type is basicly private too, these two structs could
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
39 * probably be combined.
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
40 */
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
41 struct _GaimStoredImage
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
42 {
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
43 char *data; /**< The image data. */
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
44 size_t size; /**< The image data's size. */
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
45 char *filename; /**< The filename (for the UI) */
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
46 };
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
47
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
48 typedef struct
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
49 {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
50 int id;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
51 int refcount;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
52 GaimStoredImage *img;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
53 } GaimStoredImagePriv;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
54
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
55 /* private functions */
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
56
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
57 static GaimStoredImagePriv *gaim_imgstore_get_priv(int id) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
58 GSList *tmp = imgstore;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
59 GaimStoredImagePriv *priv = NULL;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
60
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
61 g_return_val_if_fail(id > 0, NULL);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
62
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
63 while (tmp && !priv) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
64 GaimStoredImagePriv *tmp_priv = tmp->data;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
65
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
66 if (tmp_priv->id == id)
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
67 priv = tmp_priv;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
68
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
69 tmp = tmp->next;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
70 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
71
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
72 if (!priv)
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
73 gaim_debug(GAIM_DEBUG_ERROR, "imgstore", "failed to find image id %d\n", id);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
74
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
75 return priv;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
76 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
77
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
78 static void gaim_imgstore_free_priv(GaimStoredImagePriv *priv) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
79 GaimStoredImage *img = NULL;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
80
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
81 g_return_if_fail(priv != NULL);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
82
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
83 img = priv->img;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
84 if (img) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
85 if (img->data)
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
86 g_free(img->data);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
87 if (img->filename)
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
88 g_free(img->filename);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
89 g_free(img);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
90 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
91
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
92 gaim_debug(GAIM_DEBUG_INFO, "imgstore", "freed image id %d\n", priv->id);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
93
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
94 g_free(priv);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
95
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
96 imgstore = g_slist_remove(imgstore, priv);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
97 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
98
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
99 /* public functions */
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
100
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
101 int gaim_imgstore_add(const void *data, size_t size, const char *filename) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
102 GaimStoredImagePriv *priv;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
103 GaimStoredImage *img;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
104
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
105 g_return_val_if_fail(data != NULL, 0);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
106 g_return_val_if_fail(size > 0, 0);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
107
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
108 img = g_new0(GaimStoredImage, 1);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
109 img->data = g_memdup(data, size);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
110 img->size = size;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
111 img->filename = g_strdup(filename);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
112
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
113 priv = g_new0(GaimStoredImagePriv, 1);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
114 priv->id = ++nextid;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
115 priv->refcount = 1;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
116 priv->img = img;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
117
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
118 imgstore = g_slist_append(imgstore, priv);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
119 gaim_debug(GAIM_DEBUG_INFO, "imgstore", "added image id %d\n", priv->id);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
120
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
121 return priv->id;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
122 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
123
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
124 GaimStoredImage *gaim_imgstore_get(int id) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
125 GaimStoredImagePriv *priv = gaim_imgstore_get_priv(id);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
126
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
127 g_return_val_if_fail(priv != NULL, NULL);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
128
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
129 gaim_debug(GAIM_DEBUG_INFO, "imgstore", "retrieved image id %d\n", priv->id);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
130
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
131 return priv->img;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
132 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
133
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
134 gpointer gaim_imgstore_get_data(GaimStoredImage *i) {
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
135 return i->data;
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
136 }
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
137
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
138 size_t gaim_imgstore_get_size(GaimStoredImage *i) {
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
139 return i->size;
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
140 }
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
141
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
142 const char *gaim_imgstore_get_filename(GaimStoredImage *i) {
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
143 return i->filename;
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
144 }
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8046
diff changeset
145
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
146 void gaim_imgstore_ref(int id) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
147 GaimStoredImagePriv *priv = gaim_imgstore_get_priv(id);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
148
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
149 g_return_if_fail(priv != NULL);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
150
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
151 (priv->refcount)++;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
152
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
153 gaim_debug(GAIM_DEBUG_INFO, "imgstore", "referenced image id %d (count now %d)\n", priv->id, priv->refcount);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
154 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
155
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
156 void gaim_imgstore_unref(int id) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
157 GaimStoredImagePriv *priv = gaim_imgstore_get_priv(id);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
158
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
159 g_return_if_fail(priv != NULL);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
160 g_return_if_fail(priv->refcount > 0);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
161
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
162 (priv->refcount)--;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
163
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
164 gaim_debug(GAIM_DEBUG_INFO, "imgstore", "unreferenced image id %d (count now %d)\n", priv->id, priv->refcount);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
165
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
166 if (priv->refcount == 0)
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
167 gaim_imgstore_free_priv(priv);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
168 }