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 #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
41 /* Counting node property enums */
51 static GParamSpec
*properties
[PROP_LAST
];
53 /******************************************************************************
55 *****************************************************************************/
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
;
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
;
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
;
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
);
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
);
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
);
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
]);
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
]);
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 /**************************************************************************
154 **************************************************************************/
155 /* Set method for GObject properties */
157 purple_counting_node_set_property(GObject
*obj
, guint param_id
, const GValue
*value
,
160 PurpleCountingNode
*node
= PURPLE_COUNTING_NODE(obj
);
163 case PROP_TOTAL_SIZE
:
164 purple_counting_node_set_total_size(node
, g_value_get_int(value
));
166 case PROP_CURRENT_SIZE
:
167 purple_counting_node_set_current_size(node
, g_value_get_int(value
));
169 case PROP_ONLINE_COUNT
:
170 purple_counting_node_set_online_count(node
, g_value_get_int(value
));
173 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, pspec
);
178 /* Get method for GObject properties */
180 purple_counting_node_get_property(GObject
*obj
, guint param_id
, GValue
*value
,
183 PurpleCountingNode
*node
= PURPLE_COUNTING_NODE(obj
);
186 case PROP_TOTAL_SIZE
:
187 g_value_set_int(value
, purple_counting_node_get_total_size(node
));
189 case PROP_CURRENT_SIZE
:
190 g_value_set_int(value
, purple_counting_node_get_current_size(node
));
192 case PROP_ONLINE_COUNT
:
193 g_value_set_int(value
, purple_counting_node_get_online_count(node
));
196 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, pspec
);
201 /* Class initializer function */
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(
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(
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(
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
);
241 purple_counting_node_get_type(void)
243 static GType type
= 0;
246 static const GTypeInfo info
= {
247 sizeof(PurpleCountingNodeClass
),
250 (GClassInitFunc
)purple_counting_node_class_init
,
253 sizeof(PurpleCountingNode
),
259 type
= g_type_register_static(PURPLE_TYPE_BLIST_NODE
,
260 "PurpleCountingNode",
261 &info
, G_TYPE_FLAG_ABSTRACT
);