Add purple_util_write_data_to_*_file declarations
[pidgin-git.git] / libpurple / countingnode.c
blob5aeaaada69200bfe77824ea5fb9ccdb6c3080cfb
1 /*
2 * purple
4 * Purple is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #include "internal.h"
24 #include "glibcompat.h"
25 #include "countingnode.h"
27 #define PURPLE_COUNTING_NODE_GET_PRIVATE(obj) \
28 (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_COUNTING_NODE, PurpleCountingNodePrivate))
30 typedef struct _PurpleCountingNodePrivate PurpleCountingNodePrivate;
32 /* Private data of a counting node */
33 struct _PurpleCountingNodePrivate {
34 int totalsize; /* The number of children under this node */
35 int currentsize; /* The number of children under this node
36 corresponding to online accounts */
37 int onlinecount; /* The number of children under this contact who are
38 currently online */
41 /* Counting node property enums */
42 enum
44 PROP_0,
45 PROP_TOTAL_SIZE,
46 PROP_CURRENT_SIZE,
47 PROP_ONLINE_COUNT,
48 PROP_LAST
51 static GParamSpec *properties[PROP_LAST];
53 /******************************************************************************
54 * API
55 *****************************************************************************/
56 int
57 purple_counting_node_get_total_size(PurpleCountingNode *counter)
59 PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter);
61 g_return_val_if_fail(priv != NULL, -1);
63 return priv->totalsize;
66 int
67 purple_counting_node_get_current_size(PurpleCountingNode *counter)
69 PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter);
71 g_return_val_if_fail(priv != NULL, -1);
73 return priv->currentsize;
76 int
77 purple_counting_node_get_online_count(PurpleCountingNode *counter)
79 PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter);
81 g_return_val_if_fail(priv != NULL, -1);
83 return priv->onlinecount;
86 void
87 purple_counting_node_change_total_size(PurpleCountingNode *counter, int delta)
89 PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter);
91 g_return_if_fail(priv != NULL);
93 purple_counting_node_set_total_size(counter, priv->totalsize + delta);
96 void
97 purple_counting_node_change_current_size(PurpleCountingNode *counter, int delta)
99 PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter);
101 g_return_if_fail(priv != NULL);
103 purple_counting_node_set_current_size(counter, priv->currentsize + delta);
106 void
107 purple_counting_node_change_online_count(PurpleCountingNode *counter, int delta)
109 PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter);
111 g_return_if_fail(priv != NULL);
113 purple_counting_node_set_online_count(counter, priv->onlinecount + delta);
116 void
117 purple_counting_node_set_total_size(PurpleCountingNode *counter, int totalsize)
119 PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter);
121 g_return_if_fail(priv != NULL);
123 priv->totalsize = totalsize;
125 g_object_notify_by_pspec(G_OBJECT(counter), properties[PROP_TOTAL_SIZE]);
128 void
129 purple_counting_node_set_current_size(PurpleCountingNode *counter, int currentsize)
131 PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter);
133 g_return_if_fail(priv != NULL);
135 priv->currentsize = currentsize;
137 g_object_notify_by_pspec(G_OBJECT(counter), properties[PROP_CURRENT_SIZE]);
140 void
141 purple_counting_node_set_online_count(PurpleCountingNode *counter, int onlinecount)
143 PurpleCountingNodePrivate *priv = PURPLE_COUNTING_NODE_GET_PRIVATE(counter);
145 g_return_if_fail(priv != NULL);
147 priv->onlinecount = onlinecount;
149 g_object_notify_by_pspec(G_OBJECT(counter), properties[PROP_ONLINE_COUNT]);
152 /**************************************************************************
153 * GObject Stuff
154 **************************************************************************/
155 /* Set method for GObject properties */
156 static void
157 purple_counting_node_set_property(GObject *obj, guint param_id, const GValue *value,
158 GParamSpec *pspec)
160 PurpleCountingNode *node = PURPLE_COUNTING_NODE(obj);
162 switch (param_id) {
163 case PROP_TOTAL_SIZE:
164 purple_counting_node_set_total_size(node, g_value_get_int(value));
165 break;
166 case PROP_CURRENT_SIZE:
167 purple_counting_node_set_current_size(node, g_value_get_int(value));
168 break;
169 case PROP_ONLINE_COUNT:
170 purple_counting_node_set_online_count(node, g_value_get_int(value));
171 break;
172 default:
173 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
174 break;
178 /* Get method for GObject properties */
179 static void
180 purple_counting_node_get_property(GObject *obj, guint param_id, GValue *value,
181 GParamSpec *pspec)
183 PurpleCountingNode *node = PURPLE_COUNTING_NODE(obj);
185 switch (param_id) {
186 case PROP_TOTAL_SIZE:
187 g_value_set_int(value, purple_counting_node_get_total_size(node));
188 break;
189 case PROP_CURRENT_SIZE:
190 g_value_set_int(value, purple_counting_node_get_current_size(node));
191 break;
192 case PROP_ONLINE_COUNT:
193 g_value_set_int(value, purple_counting_node_get_online_count(node));
194 break;
195 default:
196 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
197 break;
201 /* Class initializer function */
202 static void
203 purple_counting_node_class_init(PurpleCountingNodeClass *klass)
205 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
207 /* Setup properties */
208 obj_class->get_property = purple_counting_node_get_property;
209 obj_class->set_property = purple_counting_node_set_property;
211 g_type_class_add_private(klass, sizeof(PurpleCountingNodePrivate));
213 properties[PROP_TOTAL_SIZE] = g_param_spec_int(
214 "total-size",
215 "Total size",
216 "The number of children under this node.",
217 G_MININT, G_MAXINT, 0,
218 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
221 properties[PROP_CURRENT_SIZE] = g_param_spec_int(
222 "current-size",
223 "Current size",
224 "The number of children with online accounts.",
225 G_MININT, G_MAXINT, 0,
226 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
229 properties[PROP_ONLINE_COUNT] = g_param_spec_int(
230 "online-count",
231 "Online count",
232 "The number of children that are online.",
233 G_MININT, G_MAXINT, 0,
234 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
237 g_object_class_install_properties(obj_class, PROP_LAST, properties);
240 GType
241 purple_counting_node_get_type(void)
243 static GType type = 0;
245 if(type == 0) {
246 static const GTypeInfo info = {
247 sizeof(PurpleCountingNodeClass),
248 NULL,
249 NULL,
250 (GClassInitFunc)purple_counting_node_class_init,
251 NULL,
252 NULL,
253 sizeof(PurpleCountingNode),
255 NULL,
256 NULL,
259 type = g_type_register_static(PURPLE_TYPE_BLIST_NODE,
260 "PurpleCountingNode",
261 &info, G_TYPE_FLAG_ABSTRACT);
264 return type;