summaryrefslogtreecommitdiff
path: root/libpurple/buddylist.h
blob: 88c91f75a3b15c72187fe79870384907788ae4ec (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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
/* 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
 */

#if !defined(PURPLE_GLOBAL_HEADER_INSIDE) && !defined(PURPLE_COMPILATION)
# error "only <purple.h> may be included directly"
#endif

#ifndef PURPLE_BUDDY_LIST_H
#define PURPLE_BUDDY_LIST_H

/* I can't believe I let ChipX86 inspire me to write good code. -Sean */

#include "buddy.h"

#define PURPLE_TYPE_BUDDY_LIST (purple_buddy_list_get_type())
typedef struct _PurpleBuddyList PurpleBuddyList;

/**
 * PURPLE_BLIST_DEFAULT_GROUP_NAME:
 *
 * A helper to get the default group name for the buddy list.
 */
#define PURPLE_BLIST_DEFAULT_GROUP_NAME (purple_blist_get_default_group_name())

#include "chat.h"
#include "contact.h"

/**
 * _purple_blist_get_localized_default_group_name:
 *
 * Returns the name of default group for previously used non-English
 * localization. It's used for merging default group, in cases when roster
 * contains localized name.
 *
 * Please note, prpls shouldn't save default group name depending on current
 * locale. So, this function is mostly for libpurple2 compatibility. And for
 * improperly written prpls.
 */
const gchar *
_purple_blist_get_localized_default_group_name(void);

/**
 * PurpleBlistWalkFunc:
 * @node: The node that's being iterated
 * @data: User supplied data.
 *
 * A callback function for purple_blist_walk.
 *
 * Since: 3.0.0
 */
typedef void (*PurpleBlistWalkFunc)(PurpleBlistNode *node, gpointer data);

/**************************************************************************/
/* Data Structures                                                        */
/**************************************************************************/
/**
 * PurpleBuddyList:
 *
 * The Buddy List
 */
/**
 * PurpleBuddyListClass:
 * @new_node:     Sets UI-specific data on a node.
 * @show:         The core will call this when it's finished doing its core
 *                stuff.
 * @update:       This will update a node in the buddy list.
 * @remove:       This removes a node from the list
 * @set_visible:  Hides or unhides the buddy list.
 * @request_add_buddy: Called when information is needed to add a buddy to the
 *                     buddy list. See purple_blist_request_add_buddy().
 * @request_add_chat: Called when information is needed to add a chat to the
 *                    buddy list. See purple_blist_request_add_chat().
 * @request_add_group: Called when information is needed to add a group to the
 *                     buddy list. See purple_blist_request_add_group().
 * @save_node:    This is called when a node has been modified and should be
 *                saved.
 *                <sbr/>Implementation of this method is
 *                <emphasis>OPTIONAL</emphasis>. If not implemented, it will be
 *                set to a fallback function that saves data to
 *                <filename>blist.xml</filename> like in previous libpurple
 *                versions.
 *                <sbr/>@node: The node which has been modified.
 * @remove_node:  Called when a node is about to be removed from the buddy list.
 *                The method should update the relevant data structures to
 *                remove this node (for example, removing a buddy from the
 *                group this node is in).
 *                <sbr/>Implementation of this method is
 *                <emphasis>OPTIONAL</emphasis>. If not implemented, it will be
 *                set to a fallback function that saves data to
 *                <filename>blist.xml</filename> like in previous libpurple
 *                versions.
 *                <sbr/>@node: The node which has been modified.
 * @save_account: Called to save all the data for an account. If the UI sets
 *                this, the callback must save the privacy and buddy list data
 *                for an account. If the account is %NULL, save the data for all
 *                accounts.
 *                <sbr/>Implementation of this method is
 *                <emphasis>OPTIONAL</emphasis>. If not implemented, it will be
 *                set to a fallback function that saves data to
 *                <filename>blist.xml</filename> like in previous
 *                libpurple versions.
 *                <sbr/>@account: The account whose data to save. If %NULL,
 *                                save all data for all accounts.
 *
 * Buddy list operations.
 *
 * Any UI representing a buddy list must derive a filled-out
 * @PurpleBuddyListClass and set the GType using purple_blist_set_ui() before a
 * buddy list is created.
 */
struct _PurpleBuddyListClass {
	/*< private >*/
	GObjectClass gparent_class;

	/*< public >*/
	void (*new_node)(PurpleBuddyList *list, PurpleBlistNode *node);
	void (*show)(PurpleBuddyList *list);
	void (*update)(PurpleBuddyList *list, PurpleBlistNode *node);
	void (*remove)(PurpleBuddyList *list, PurpleBlistNode *node);
	void (*set_visible)(PurpleBuddyList *list, gboolean show);

	void (*request_add_buddy)(PurpleBuddyList *list, PurpleAccount *account,
	                          const char *username, const char *group,
	                          const char *alias);

	void (*request_add_chat)(PurpleBuddyList *list, PurpleAccount *account,
	                         PurpleGroup *group, const char *alias,
	                         const char *name);

	void (*request_add_group)(PurpleBuddyList *list);

	void (*save_node)(PurpleBuddyList *list, PurpleBlistNode *node);
	void (*remove_node)(PurpleBuddyList *list, PurpleBlistNode *node);

	void (*save_account)(PurpleBuddyList *list, PurpleAccount *account);

	/*< private >*/
	gpointer reserved[4];
};

G_BEGIN_DECLS

/**************************************************************************/
/* Buddy List API                                                         */
/**************************************************************************/

/**
 * purple_buddy_list_get_type:
 *
 * Returns: The #GType for the #PurpleBuddyList object.
 */
G_DECLARE_DERIVABLE_TYPE(PurpleBuddyList, purple_buddy_list, PURPLE, BUDDY_LIST,
                         GObject)

/**
 * purple_blist_get_default:
 *
 * Returns the default buddy list.
 *
 * Returns: (transfer none): The default buddy list.
 *
 * Since: 3.0.0
 */
PurpleBuddyList *purple_blist_get_default(void);

/**
 * purple_blist_get_default_root:
 *
 * Returns the root node of the default buddy list.
 *
 * Returns: (transfer none): The root node.
 *
 * Since: 3.0.0
 */
PurpleBlistNode *purple_blist_get_default_root(void);

/**
 * purple_blist_get_root:
 * @list: The buddy list to query.
 *
 * Returns the root node of the specified buddy list.
 *
 * Returns: (transfer none): The root node.
 */
PurpleBlistNode *purple_blist_get_root(PurpleBuddyList *list);

/**
 * purple_blist_get_buddies:
 *
 * Returns a list of every buddy in the list.  Use of this function is
 * discouraged if you do not actually need every buddy in the list.  Use
 * purple_blist_find_buddies instead.
 *
 * See purple_blist_find_buddies().
 *
 * Returns: (element-type PurpleBlistNode) (transfer container): A list of every
 *          buddy in the list.
 */
GSList *purple_blist_get_buddies(void);

/**
 * purple_blist_show:
 *
 * Shows the buddy list, creating a new one if necessary.
 */
void purple_blist_show(void);

/**
 * purple_blist_set_visible:
 * @show:   Whether or not to show the buddy list
 *
 * Hides or unhides the buddy list.
 */
void purple_blist_set_visible(gboolean show);

/**
 * purple_blist_update_buddies_cache:
 * @buddy:    The buddy whose name will be changed.
 * @new_name: The new name of the buddy.
 *
 * Updates the buddies hash table when a buddy has been renamed. This only
 * updates the cache, the caller is responsible for the actual renaming of
 * the buddy after updating the cache.
 */
void purple_blist_update_buddies_cache(PurpleBuddy *buddy, const char *new_name);

/**
 * purple_blist_update_groups_cache:
 * @group:    The group whose name will be changed.
 * @new_name: The new name of the group.
 *
 * Updates the groups hash table when a group has been renamed. This only
 * updates the cache, the caller is responsible for the actual renaming of
 * the group after updating the cache.
 */
void purple_blist_update_groups_cache(PurpleGroup *group, const char *new_name);

/**
 * purple_blist_add_chat:
 * @chat:  The new chat who gets added
 * @group:  The group to add the new chat to.
 * @node:   The insertion point
 *
 * Adds a new chat to the buddy list.
 *
 * The chat will be inserted right after node or appended to the end
 * of group if node is NULL.  If both are NULL, the buddy will be added to
 * the "Chats" group.
 */
void purple_blist_add_chat(PurpleChat *chat, PurpleGroup *group, PurpleBlistNode *node);

/**
 * purple_blist_add_buddy:
 * @buddy:   The new buddy who gets added
 * @contact: The optional contact to place the buddy in.
 * @group:   The group to add the new buddy to.
 * @node:    The insertion point.  Pass in NULL to add the node as
 *                the first child in the given group.
 *
 * Adds a new buddy to the buddy list.
 *
 * The buddy will be inserted right after node or prepended to the
 * group if node is NULL.  If both are NULL, the buddy will be added to
 * the default group.
 */
void purple_blist_add_buddy(PurpleBuddy *buddy, PurpleMetaContact *contact, PurpleGroup *group, PurpleBlistNode *node);

/**
 * purple_blist_add_group:
 * @group:  The group
 * @node:   The insertion point
 *
 * Adds a new group to the buddy list.
 *
 * The new group will be inserted after insert or prepended to the list if
 * node is NULL.
 */
void purple_blist_add_group(PurpleGroup *group, PurpleBlistNode *node);

/**
 * purple_blist_add_contact:
 * @contact: The contact
 * @group:   The group to add the contact to
 * @node:    The insertion point
 *
 * Adds a new contact to the buddy list.
 *
 * The new contact will be inserted after insert or prepended to the list if
 * node is NULL.
 */
void purple_blist_add_contact(PurpleMetaContact *contact, PurpleGroup *group, PurpleBlistNode *node);

/**
 * purple_blist_remove_buddy:
 * @buddy:   The buddy to be removed
 *
 * Removes a buddy from the buddy list and frees the memory allocated to it.
 * This doesn't actually try to remove the buddy from the server list.
 *
 * See purple_account_remove_buddy().
 */
void purple_blist_remove_buddy(PurpleBuddy *buddy);

/**
 * purple_blist_remove_contact:
 * @contact: The contact to be removed
 *
 * Removes a contact, and any buddies it contains, and frees the memory
 * allocated to it. This calls purple_blist_remove_buddy and therefore
 * doesn't remove the buddies from the server list.
 *
 * See purple_blist_remove_buddy().
 */
void purple_blist_remove_contact(PurpleMetaContact *contact);

/**
 * purple_blist_remove_chat:
 * @chat:   The chat to be removed
 *
 * Removes a chat from the buddy list and frees the memory allocated to it.
 */
void purple_blist_remove_chat(PurpleChat *chat);

/**
 * purple_blist_remove_group:
 * @group:   The group to be removed
 *
 * Removes a group from the buddy list and frees the memory allocated to it and to
 * its children
 */
void purple_blist_remove_group(PurpleGroup *group);

/**
 * purple_blist_find_buddy:
 * @account: The account this buddy belongs to
 * @name:    The buddy's name
 *
 * Finds the buddy struct given a name and an account
 *
 * Returns: (transfer none): The buddy or %NULL if the buddy does not exist.
 */
PurpleBuddy *purple_blist_find_buddy(PurpleAccount *account, const char *name);

/**
 * purple_blist_find_buddy_in_group:
 * @account: The account this buddy belongs to
 * @name:    The buddy's name
 * @group:   The group to look in
 *
 * Finds the buddy struct given a name, an account, and a group
 *
 * Returns: (transfer none): The buddy or %NULL if the buddy does not exist in
 *          the group.
 */
PurpleBuddy *purple_blist_find_buddy_in_group(PurpleAccount *account, const char *name,
		PurpleGroup *group);

/**
 * purple_blist_find_buddies:
 * @account: The account this buddy belongs to
 * @name:    The buddy's name (or NULL to return all buddies for the account)
 *
 * Finds all PurpleBuddy structs given a name and an account
 *
 * Returns: (element-type PurpleBuddy) (transfer container): %NULL if the buddy
 *          doesn't exist, or a GSList of PurpleBuddy structs.
 */
GSList *purple_blist_find_buddies(PurpleAccount *account, const char *name);

/**
 * purple_blist_find_group:
 * @name:    The group's name
 *
 * Finds a group by name
 *
 * Returns: (transfer none): The group or %NULL if the group does not exist.
 */
PurpleGroup *purple_blist_find_group(const char *name);

/**
 * purple_blist_get_default_group:
 *
 * Finds or creates default group.
 *
 * Returns: (transfer none): The default group.
 */
PurpleGroup *purple_blist_get_default_group(void);

/**
 * purple_blist_find_chat:
 * @account: The chat's account.
 * @name:    The chat's name.
 *
 * Finds a chat by name.
 *
 * Returns: (transfer none): The chat, or %NULL if the chat does not exist.
 */
PurpleChat *purple_blist_find_chat(PurpleAccount *account, const char *name);

/**
 * purple_blist_add_account:
 * @account:   The account
 *
 * Called when an account connects.  Tells the UI to update all the
 * buddies.
 */
void purple_blist_add_account(PurpleAccount *account);

/**
 * purple_blist_remove_account:
 * @account:   The account
 *
 * Called when an account disconnects.  Sets the presence of all the buddies to 0
 * and tells the UI to update them.
 */
void purple_blist_remove_account(PurpleAccount *account);

/**
 * purple_blist_walk:
 * @group_func: (scope call): The callback for groups
 * @chat_func: (scope call): The callback for chats
 * @meta_contact_func: (scope call): The callback for meta-contacts
 * @contact_func: (scope call): The callback for contacts
 * @data: User supplied data.
 *
 * Walks the buddy list and calls the appropriate function for each node.  If
 * a callback function is omitted iteration will continue without it.
 *
 * Since: 3.0.0
 */
void purple_blist_walk(PurpleBlistWalkFunc group_func, PurpleBlistWalkFunc chat_func, PurpleBlistWalkFunc meta_contact_func, PurpleBlistWalkFunc contact_func, gpointer data);

/**
 * purple_blist_get_default_group_name:
 *
 * Gets the default group name for the buddy list.
 *
 * Returns: The name of the default group.
 *
 * Since: 3.0.0
 */
const gchar *purple_blist_get_default_group_name(void);

/****************************************************************************************/
/* Buddy list file management API                                                       */
/****************************************************************************************/

/**
 * purple_blist_schedule_save:
 *
 * Schedule a save of the <filename>blist.xml</filename> file.  This is used by
 * the account API whenever the privacy settings are changed.  If you make a
 * change to <filename>blist.xml</filename> using one of the functions in the
 * buddy list API, then the buddy list is saved automatically, so you should not
 * need to call this.
 */
void purple_blist_schedule_save(void);

/**
 * purple_blist_request_add_buddy:
 * @account:  The account the buddy is added to.
 * @username: The username of the buddy.
 * @group:    The name of the group to place the buddy in.
 * @alias:    The optional alias for the buddy.
 *
 * Requests from the user information needed to add a buddy to the
 * buddy list.
 */
void purple_blist_request_add_buddy(PurpleAccount *account, const char *username,
								  const char *group, const char *alias);

/**
 * purple_blist_request_add_chat:
 * @account: The account the buddy is added to.
 * @group:   The optional group to add the chat to.
 * @alias:   The optional alias for the chat.
 * @name:    The required chat name.
 *
 * Requests from the user information needed to add a chat to the
 * buddy list.
 */
void purple_blist_request_add_chat(PurpleAccount *account, PurpleGroup *group,
								 const char *alias, const char *name);

/**
 * purple_blist_request_add_group:
 *
 * Requests from the user information needed to add a group to the
 * buddy list.
 */
void purple_blist_request_add_group(void);

/**
 * purple_blist_new_node:
 * @list: The list that contains the node.
 * @node: The node to initialize.
 *
 * Sets UI-specific data on a node.
 *
 * This should usually only be run when initializing a @PurpleBlistNode
 * instance.
 *
 * Since: 3.0.0
 */
void purple_blist_new_node(PurpleBuddyList *list, PurpleBlistNode *node);

/**
 * purple_blist_update_node:
 * @list: The buddy list to modify.
 * @node: The node to update.
 *
 * Update a node in the buddy list in the UI.
 *
 * Since: 3.0.0
 */
void purple_blist_update_node(PurpleBuddyList *list, PurpleBlistNode *node);

/**
 * purple_blist_save_node:
 * @list: The list that contains the node.
 * @node: The node which has been modified.
 *
 * This is called when a node has been modified and should be saved by the UI.
 *
 * If the UI does not implement a more specific method, it will be set to save
 * data to <filename>blist.xml</filename> like in previous libpurple versions.
 *
 * Since: 3.0.0
 */
void purple_blist_save_node(PurpleBuddyList *list, PurpleBlistNode *node);

/**
 * purple_blist_save_account:
 * @list: The list that contains the account.
 * @account: The account whose data to save. If %NULL, save all data for all
 *           accounts.
 *
 * Save all the data for an account.
 *
 * If the UI does not set a more specific method, it will be set to save data
 * to <filename>blist.xml</filename> like in previous libpurple versions.
 *
 * Since: 3.0.0
 */
void purple_blist_save_account(PurpleBuddyList *list, PurpleAccount *account);

/**************************************************************************/
/* Buddy List Subsystem                                                   */
/**************************************************************************/

/**
 * purple_blist_set_ui:
 * @type: The @GType of a derived UI implementation of @PurpleBuddyList.
 *
 * Set the UI implementation of the buddy list.
 *
 * This must be called before the buddy list is created or you will get the
 * default libpurple implementation.
 *
 * Since: 3.0.0
 */
void purple_blist_set_ui(GType type);

/**
 * purple_blist_get_handle:
 *
 * Returns the handle for the buddy list subsystem.
 *
 * Returns: The buddy list subsystem handle.
 */
void *purple_blist_get_handle(void);

/**
 * purple_blist_init:
 *
 * Initializes the buddy list subsystem.
 */
void purple_blist_init(void);

/**
 * purple_blist_boot:
 *
 * Loads the buddy list.
 *
 * You shouldn't call this. purple_core_init() will do it for you.
 */
void purple_blist_boot(void);

/**
 * purple_blist_uninit:
 *
 * Uninitializes the buddy list subsystem.
 */
void purple_blist_uninit(void);

G_END_DECLS

#endif /* PURPLE_BUDDY_LIST_H */