summaryrefslogtreecommitdiff
path: root/libpurple/blistnode.h
blob: 80362c9ecb9b17bc32b2f51f608d837e1c909191 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
/**
 * @file blistnode.h Buddy list node and Counting node API
 * @ingroup core
 */
/* purple
 *
 * Purple is the legal property of its developers, whose names are too numerous
 * to list here.  Please refer to the COPYRIGHT file distributed with this
 * source distribution.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 */
#ifndef _PURPLE_BLIST_NODE_H_
#define _PURPLE_BLIST_NODE_H_

#include <glib.h>
#include <glib-object.h>

#define PURPLE_TYPE_BLIST_NODE             (purple_blist_node_get_type())
#define PURPLE_BLIST_NODE(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_BLIST_NODE, PurpleBlistNode))
#define PURPLE_BLIST_NODE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_BLIST_NODE, PurpleBlistNodeClass))
#define PURPLE_IS_BLIST_NODE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_BLIST_NODE))
#define PURPLE_IS_BLIST_NODE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_BLIST_NODE))
#define PURPLE_BLIST_NODE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_BLIST_NODE, PurpleBlistNodeClass))

/** @copydoc _PurpleBlistNode */
typedef struct _PurpleBlistNode PurpleBlistNode;
/** @copydoc _PurpleBlistNodeClass */
typedef struct _PurpleBlistNodeClass PurpleBlistNodeClass;

#define PURPLE_TYPE_COUNTING_NODE             (purple_counting_node_get_type())
#define PURPLE_COUNTING_NODE(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_COUNTING_NODE, PurpleCountingNode))
#define PURPLE_COUNTING_NODE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_COUNTING_NODE, PurpleCountingNodeClass))
#define PURPLE_IS_COUNTING_NODE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_COUNTING_NODE))
#define PURPLE_IS_COUNTING_NODE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_COUNTING_NODE))
#define PURPLE_COUNTING_NODE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_COUNTING_NODE, PurpleCountingNodeClass))

/** @copydoc _PurpleCountingNode */
typedef struct _PurpleCountingNode PurpleCountingNode;
/** @copydoc _PurpleCountingNodeClass */
typedef struct _PurpleCountingNodeClass PurpleCountingNodeClass;

/**************************************************************************/
/* Data Structures                                                        */
/**************************************************************************/

/**
 * A Buddy list node.  This can represent a group, a buddy, or anything else.
 * This is a base class for PurpleBuddy, PurpleContact, PurpleGroup, and for
 * anything else that wants to put itself in the buddy list. */
struct _PurpleBlistNode {
	/*< private >*/
	GObject gparent;

	/** The UI data associated with this node. This is a convenience
	 *  field provided to the UIs -- it is not used by the libpurple core.
	 */
	gpointer ui_data;

	PurpleBlistNode *prev;    /**< The sibling before this buddy. */
	PurpleBlistNode *next;    /**< The sibling after this buddy.  */
	PurpleBlistNode *parent;  /**< The parent of this node        */
	PurpleBlistNode *child;   /**< The child of this node         */
};

/** The base class for all #PurpleBlistNode's. */
struct _PurpleBlistNodeClass {
	/*< private >*/
	GObjectClass gparent_class;

	void (*_purple_reserved1)(void);
	void (*_purple_reserved2)(void);
	void (*_purple_reserved3)(void);
	void (*_purple_reserved4)(void);
};

/**
 * A node that keeps count of the number of children that it has. It tracks the
 * total number of children, the number of children corresponding to online
 * accounts, and the number of online children.
 *
 * The two types of counting nodes are:
 * 1. Contact: Keeps track of the number of buddies under it.
 * 2. Group:   Keeps track of the number of chats and contacts under it.
 *
 * @see PurpleContact
 * @see PurpleGroup
 */
struct _PurpleCountingNode {
	/** The blist node that this counting node inherits from */
	PurpleBlistNode node;
};

/** The base class for all #PurpleCountingNode's. */
struct _PurpleCountingNodeClass {
	/*< private >*/
	PurpleBlistNodeClass node_class;

	void (*_purple_reserved1)(void);
	void (*_purple_reserved2)(void);
	void (*_purple_reserved3)(void);
	void (*_purple_reserved4)(void);
};

G_BEGIN_DECLS

/**************************************************************************/
/** @name Buddy list node API                                             */
/**************************************************************************/
/*@{*/

/**
 * Returns the GType for the PurpleBlistNode object.
 */
GType purple_blist_node_get_type(void);

/**
 * Returns the next node of a given node. This function is to be used to iterate
 * over the tree returned by purple_blist_get_buddy_list.
 *
 * @param node		A node.
 * @param offline	Whether to include nodes for offline accounts
 * @return	The next node
 * @see purple_blist_node_get_parent
 * @see purple_blist_node_get_first_child
 * @see purple_blist_node_get_sibling_next
 * @see purple_blist_node_get_sibling_prev
 */
PurpleBlistNode *purple_blist_node_next(PurpleBlistNode *node, gboolean offline);

/**
 * Returns the parent node of a given node.
 *
 * @param node A node.
 * @return  The parent node.
 *
 * @see purple_blist_node_get_first_child
 * @see purple_blist_node_get_sibling_next
 * @see purple_blist_node_get_sibling_prev
 * @see purple_blist_node_next
 */
PurpleBlistNode *purple_blist_node_get_parent(PurpleBlistNode *node);

/**
 * Returns the the first child node of a given node.
 *
 * @param node A node.
 * @return  The child node.
 *
 * @see purple_blist_node_get_parent
 * @see purple_blist_node_get_sibling_next
 * @see purple_blist_node_get_sibling_prev
 * @see purple_blist_node_next
 */
PurpleBlistNode *purple_blist_node_get_first_child(PurpleBlistNode *node);

/**
 * Returns the sibling node of a given node.
 *
 * @param node A node.
 * @return  The sibling node.
 *
 * @see purple_blist_node_get_parent
 * @see purple_blist_node_get_first_child
 * @see purple_blist_node_get_sibling_prev
 * @see purple_blist_node_next
 */
PurpleBlistNode *purple_blist_node_get_sibling_next(PurpleBlistNode *node);

/**
 * Returns the previous sibling node of a given node.
 *
 * @param node A node.
 * @return  The sibling node.
 *
 * @see purple_blist_node_get_parent
 * @see purple_blist_node_get_first_child
 * @see purple_blist_node_get_sibling_next
 * @see purple_blist_node_next
 */
PurpleBlistNode *purple_blist_node_get_sibling_prev(PurpleBlistNode *node);

/**
 * Returns the UI data of a given node.
 *
 * @param node The node.
 * @return The UI data.
 */
gpointer purple_blist_node_get_ui_data(const PurpleBlistNode *node);

/**
 * Sets the UI data of a given node.
 *
 * @param node The node.
 * @param ui_data The UI data.
 */
void purple_blist_node_set_ui_data(PurpleBlistNode *node, gpointer ui_data);

/**
 * Returns a node's settings
 *
 * @param node  The node to from which to get settings
 *
 * @return The hash table with the node's settings
 */
GHashTable *purple_blist_node_get_settings(PurpleBlistNode *node);

/**
 * Checks whether a named setting exists for a node in the buddy list
 *
 * @param node  The node to check from which to check settings
 * @param key   The identifier of the data
 *
 * @return TRUE if a value exists, or FALSE if there is no setting
 */
gboolean purple_blist_node_has_setting(PurpleBlistNode *node, const char *key);

/**
 * Associates a boolean with a node in the buddy list
 *
 * @param node  The node to associate the data with
 * @param key   The identifier for the data
 * @param value The value to set
 */
void purple_blist_node_set_bool(PurpleBlistNode *node, const char *key, gboolean value);

/**
 * Retrieves a named boolean setting from a node in the buddy list
 *
 * @param node  The node to retrieve the data from
 * @param key   The identifier of the data
 *
 * @return The value, or FALSE if there is no setting
 */
gboolean purple_blist_node_get_bool(PurpleBlistNode *node, const char *key);

/**
 * Associates an integer with a node in the buddy list
 *
 * @param node  The node to associate the data with
 * @param key   The identifier for the data
 * @param value The value to set
 */
void purple_blist_node_set_int(PurpleBlistNode *node, const char *key, int value);

/**
 * Retrieves a named integer setting from a node in the buddy list
 *
 * @param node  The node to retrieve the data from
 * @param key   The identifier of the data
 *
 * @return The value, or 0 if there is no setting
 */
int purple_blist_node_get_int(PurpleBlistNode *node, const char *key);

/**
 * Associates a string with a node in the buddy list
 *
 * @param node  The node to associate the data with
 * @param key   The identifier for the data
 * @param value The value to set
 */
void purple_blist_node_set_string(PurpleBlistNode *node, const char *key,
		const char *value);

/**
 * Retrieves a named string setting from a node in the buddy list
 *
 * @param node  The node to retrieve the data from
 * @param key   The identifier of the data
 *
 * @return The value, or NULL if there is no setting
 */
const char *purple_blist_node_get_string(PurpleBlistNode *node, const char *key);

/**
 * Removes a named setting from a blist node
 *
 * @param node  The node from which to remove the setting
 * @param key   The name of the setting
 */
void purple_blist_node_remove_setting(PurpleBlistNode *node, const char *key);

/**
 * Sets whether the node should be saved with the buddy list or not
 *
 * @param node  The node
 * @param transient TRUE if the node should NOT be saved, FALSE if node should
 *                  be saved
 */
void purple_blist_node_set_transient(PurpleBlistNode *node, gboolean transient);

/**
 * Gets whether the node should be saved with the buddy list or not
 *
 * @param node  The node
 *
 * @return TRUE if the node should NOT be saved, FALSE if node should be saved
 */
gboolean purple_blist_node_is_transient(PurpleBlistNode *node);

/*@}*/

/**
 * Retrieves the extended menu items for a buddy list node.
 * @param n The blist node for which to obtain the extended menu items.
 * @return  A list of PurpleMenuAction items, as harvested by the
 *          blist-node-extended-menu signal.
 */
GList *purple_blist_node_get_extended_menu(PurpleBlistNode *n);

/*@}*/

/**************************************************************************/
/** @name Counting node API                                               */
/**************************************************************************/
/*@{*/

/**
 * Returns the GType for the PurpleCountingNode object.
 */
GType purple_counting_node_get_type(void);

/**
 * Returns the total number of children of the counting node.
 *
 * @param counter  The node
 *
 * @return  The total number of children of the node
 */
int purple_counting_node_get_total_size(PurpleCountingNode *counter);

/**
 * Returns the number of children of the counting node corresponding to online
 * accounts.
 *
 * @param counter  The node
 *
 * @return  The number of children with online accounts
 */
int purple_counting_node_get_current_size(PurpleCountingNode *counter);

/**
 * Returns the number of children of the counting node that are online.
 *
 * @param counter  The node
 *
 * @return  The total number of online children
 */
int purple_counting_node_get_online_count(PurpleCountingNode *counter);

/**
 * Changes the total number of children of the counting node. The provided
 * delta value is added to the count, or if it's negative, the count is
 * decreased.
 *
 * @param counter  The node
 * @param delta    The value to change the total size by
 */
void purple_counting_node_change_total_size(PurpleCountingNode *counter, int delta);

/**
 * Changes the number of children of the counting node corresponding to online
 * accounts. The provided delta value is added to the count, or if it's
 * negative, the count is decreased.
 *
 * @param counter  The node
 * @param delta    The value to change the current size by
 */
void purple_counting_node_change_current_size(PurpleCountingNode *counter, int delta);

/**
 * Changes the number of children of the counting node that are online. The
 * provided delta value is added to the count, or if it's negative, the count is
 * decreased.
 *
 * @param counter  The node
 * @param delta    The value to change the online count by
 */
void purple_counting_node_change_online_count(PurpleCountingNode *counter, int delta);

/**
 * Sets the total number of children of the counting node.
 *
 * @param counter    The node
 * @param totalsize  The total number of children of the node
 */
void purple_counting_node_set_total_size(PurpleCountingNode *counter, int totalsize);

/**
 * Sets the number of children of the counting node corresponding to online
 * accounts.
 *
 * @param counter      The node
 * @param currentsize  The number of children with online accounts
 */
void purple_counting_node_set_current_size(PurpleCountingNode *counter, int currentsize);

/**
 * Sets the number of children of the counting node that are online.
 *
 * @param counter      The node
 * @param onlinecount  The total number of online children
 */
void purple_counting_node_set_online_count(PurpleCountingNode *counter, int onlinecount);

/*@}*/

G_END_DECLS

#endif /* _PURPLE_BLIST_NODE_H_ */