Fix an incorrect call to soup_message_set_request.
[pidgin-git.git] / libpurple / countingnode.c
blobb43168cf32c2bf3ab2eaedb7ca15f4c0c82cbfb3
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 typedef struct _PurpleCountingNodePrivate PurpleCountingNodePrivate;
29 /* Private data of a counting node */
30 struct _PurpleCountingNodePrivate {
31 int totalsize; /* The number of children under this node */
32 int currentsize; /* The number of children under this node
33 corresponding to online accounts */
34 int onlinecount; /* The number of children under this contact who are
35 currently online */
38 /* Counting node property enums */
39 enum
41 PROP_0,
42 PROP_TOTAL_SIZE,
43 PROP_CURRENT_SIZE,
44 PROP_ONLINE_COUNT,
45 PROP_LAST
48 static GParamSpec *properties[PROP_LAST];
50 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(PurpleCountingNode, purple_counting_node,
51 PURPLE_TYPE_BLIST_NODE);
53 /******************************************************************************
54 * API
55 *****************************************************************************/
56 int
57 purple_counting_node_get_total_size(PurpleCountingNode *counter)
59 PurpleCountingNodePrivate *priv = NULL;
61 g_return_val_if_fail(PURPLE_IS_COUNTING_NODE(counter), -1);
63 priv = purple_counting_node_get_instance_private(counter);
64 return priv->totalsize;
67 int
68 purple_counting_node_get_current_size(PurpleCountingNode *counter)
70 PurpleCountingNodePrivate *priv = NULL;
72 g_return_val_if_fail(PURPLE_IS_COUNTING_NODE(counter), -1);
74 priv = purple_counting_node_get_instance_private(counter);
75 return priv->currentsize;
78 int
79 purple_counting_node_get_online_count(PurpleCountingNode *counter)
81 PurpleCountingNodePrivate *priv = NULL;
83 g_return_val_if_fail(PURPLE_IS_COUNTING_NODE(counter), -1);
85 priv = purple_counting_node_get_instance_private(counter);
86 return priv->onlinecount;
89 void
90 purple_counting_node_change_total_size(PurpleCountingNode *counter, int delta)
92 PurpleCountingNodePrivate *priv = NULL;
94 g_return_if_fail(PURPLE_IS_COUNTING_NODE(counter));
96 priv = purple_counting_node_get_instance_private(counter);
97 purple_counting_node_set_total_size(counter, priv->totalsize + delta);
100 void
101 purple_counting_node_change_current_size(PurpleCountingNode *counter, int delta)
103 PurpleCountingNodePrivate *priv = NULL;
105 g_return_if_fail(PURPLE_IS_COUNTING_NODE(counter));
107 priv = purple_counting_node_get_instance_private(counter);
108 purple_counting_node_set_current_size(counter, priv->currentsize + delta);
111 void
112 purple_counting_node_change_online_count(PurpleCountingNode *counter, int delta)
114 PurpleCountingNodePrivate *priv = NULL;
116 g_return_if_fail(PURPLE_IS_COUNTING_NODE(counter));
118 priv = purple_counting_node_get_instance_private(counter);
119 purple_counting_node_set_online_count(counter, priv->onlinecount + delta);
122 void
123 purple_counting_node_set_total_size(PurpleCountingNode *counter, int totalsize)
125 PurpleCountingNodePrivate *priv = NULL;
127 g_return_if_fail(PURPLE_IS_COUNTING_NODE(counter));
129 priv = purple_counting_node_get_instance_private(counter);
130 priv->totalsize = totalsize;
132 g_object_notify_by_pspec(G_OBJECT(counter), properties[PROP_TOTAL_SIZE]);
135 void
136 purple_counting_node_set_current_size(PurpleCountingNode *counter, int currentsize)
138 PurpleCountingNodePrivate *priv = NULL;
140 g_return_if_fail(PURPLE_IS_COUNTING_NODE(counter));
142 priv = purple_counting_node_get_instance_private(counter);
143 priv->currentsize = currentsize;
145 g_object_notify_by_pspec(G_OBJECT(counter), properties[PROP_CURRENT_SIZE]);
148 void
149 purple_counting_node_set_online_count(PurpleCountingNode *counter, int onlinecount)
151 PurpleCountingNodePrivate *priv = NULL;
153 g_return_if_fail(PURPLE_IS_COUNTING_NODE(counter));
155 priv = purple_counting_node_get_instance_private(counter);
156 priv->onlinecount = onlinecount;
158 g_object_notify_by_pspec(G_OBJECT(counter), properties[PROP_ONLINE_COUNT]);
161 /**************************************************************************
162 * GObject Stuff
163 **************************************************************************/
164 /* Set method for GObject properties */
165 static void
166 purple_counting_node_set_property(GObject *obj, guint param_id, const GValue *value,
167 GParamSpec *pspec)
169 PurpleCountingNode *node = PURPLE_COUNTING_NODE(obj);
171 switch (param_id) {
172 case PROP_TOTAL_SIZE:
173 purple_counting_node_set_total_size(node, g_value_get_int(value));
174 break;
175 case PROP_CURRENT_SIZE:
176 purple_counting_node_set_current_size(node, g_value_get_int(value));
177 break;
178 case PROP_ONLINE_COUNT:
179 purple_counting_node_set_online_count(node, g_value_get_int(value));
180 break;
181 default:
182 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
183 break;
187 /* Get method for GObject properties */
188 static void
189 purple_counting_node_get_property(GObject *obj, guint param_id, GValue *value,
190 GParamSpec *pspec)
192 PurpleCountingNode *node = PURPLE_COUNTING_NODE(obj);
194 switch (param_id) {
195 case PROP_TOTAL_SIZE:
196 g_value_set_int(value, purple_counting_node_get_total_size(node));
197 break;
198 case PROP_CURRENT_SIZE:
199 g_value_set_int(value, purple_counting_node_get_current_size(node));
200 break;
201 case PROP_ONLINE_COUNT:
202 g_value_set_int(value, purple_counting_node_get_online_count(node));
203 break;
204 default:
205 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
206 break;
210 static void
211 purple_counting_node_init(PurpleCountingNode *counter)
215 /* Class initializer function */
216 static void
217 purple_counting_node_class_init(PurpleCountingNodeClass *klass)
219 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
221 /* Setup properties */
222 obj_class->get_property = purple_counting_node_get_property;
223 obj_class->set_property = purple_counting_node_set_property;
225 properties[PROP_TOTAL_SIZE] = g_param_spec_int(
226 "total-size",
227 "Total size",
228 "The number of children under this node.",
229 G_MININT, G_MAXINT, 0,
230 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
233 properties[PROP_CURRENT_SIZE] = g_param_spec_int(
234 "current-size",
235 "Current size",
236 "The number of children with online accounts.",
237 G_MININT, G_MAXINT, 0,
238 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
241 properties[PROP_ONLINE_COUNT] = g_param_spec_int(
242 "online-count",
243 "Online count",
244 "The number of children that are online.",
245 G_MININT, G_MAXINT, 0,
246 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
249 g_object_class_install_properties(obj_class, PROP_LAST, properties);