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
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
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
38 /* Counting node property enums */
48 static GParamSpec
*properties
[PROP_LAST
];
50 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(PurpleCountingNode
, purple_counting_node
,
51 PURPLE_TYPE_BLIST_NODE
);
53 /******************************************************************************
55 *****************************************************************************/
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
;
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
;
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
;
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
);
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
);
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
);
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
]);
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
]);
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 /**************************************************************************
163 **************************************************************************/
164 /* Set method for GObject properties */
166 purple_counting_node_set_property(GObject
*obj
, guint param_id
, const GValue
*value
,
169 PurpleCountingNode
*node
= PURPLE_COUNTING_NODE(obj
);
172 case PROP_TOTAL_SIZE
:
173 purple_counting_node_set_total_size(node
, g_value_get_int(value
));
175 case PROP_CURRENT_SIZE
:
176 purple_counting_node_set_current_size(node
, g_value_get_int(value
));
178 case PROP_ONLINE_COUNT
:
179 purple_counting_node_set_online_count(node
, g_value_get_int(value
));
182 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, pspec
);
187 /* Get method for GObject properties */
189 purple_counting_node_get_property(GObject
*obj
, guint param_id
, GValue
*value
,
192 PurpleCountingNode
*node
= PURPLE_COUNTING_NODE(obj
);
195 case PROP_TOTAL_SIZE
:
196 g_value_set_int(value
, purple_counting_node_get_total_size(node
));
198 case PROP_CURRENT_SIZE
:
199 g_value_set_int(value
, purple_counting_node_get_current_size(node
));
201 case PROP_ONLINE_COUNT
:
202 g_value_set_int(value
, purple_counting_node_get_online_count(node
));
205 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, pspec
);
211 purple_counting_node_init(PurpleCountingNode
*counter
)
215 /* Class initializer function */
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(
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(
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(
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
);