summaryrefslogtreecommitdiff
path: root/libpurple/buddy.h
blob: c8a0af7daed289df7d76dba7734339e5f2a7c161 (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
/* 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_H
#define PURPLE_BUDDY_H

#define PURPLE_TYPE_BUDDY             (purple_buddy_get_type())
#define PURPLE_BUDDY(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_BUDDY, PurpleBuddy))
#define PURPLE_BUDDY_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_BUDDY, PurpleBuddyClass))
#define PURPLE_IS_BUDDY(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_BUDDY))
#define PURPLE_IS_BUDDY_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_BUDDY))
#define PURPLE_BUDDY_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_BUDDY, PurpleBuddyClass))

typedef struct _PurpleBuddy PurpleBuddy;
typedef struct _PurpleBuddyClass PurpleBuddyClass;

#include "account.h"
#include "blistnode.h"
#include "buddyicon.h"
#include "chat.h"
#include "contact.h"
#include "group.h"
#include "media.h"
#include "purplepresence.h"
#include "status.h"

/**
 * PURPLE_BUDDY_IS_ONLINE:
 * @b: The #PurpleBuddy instance.
 *
 * Checks whether @b is online or not.
 */
#define PURPLE_BUDDY_IS_ONLINE(b) \
	(PURPLE_IS_BUDDY(b) \
	&& purple_account_is_connected(purple_buddy_get_account(PURPLE_BUDDY(b))) \
	&& purple_presence_is_online(purple_buddy_get_presence(PURPLE_BUDDY(b))))

/**
 * PURPLE_BLIST_NODE_NAME:
 * @n: The #PurpleBlistNode instance.
 *
 * Gets the name of @n.
 */
#define PURPLE_BLIST_NODE_NAME(n) \
	(PURPLE_IS_CHAT(n) ? purple_chat_get_name(PURPLE_CHAT(n)) : \
	PURPLE_IS_BUDDY(n) ? purple_buddy_get_name(PURPLE_BUDDY(n)) : NULL)

/**************************************************************************/
/* Data Structures                                                        */
/**************************************************************************/
/**
 * PurpleBuddy:
 *
 * A buddy on the buddy list.
 */
struct _PurpleBuddy {
	PurpleBlistNode node;
};

struct _PurpleBuddyClass {
	PurpleBlistNodeClass node_class;

	/*< private >*/
	void (*_purple_reserved1)(void);
	void (*_purple_reserved2)(void);
	void (*_purple_reserved3)(void);
	void (*_purple_reserved4)(void);
};

G_BEGIN_DECLS

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

/**
 * purple_buddy_get_type:
 *
 * Returns: The #GType for the #PurpleBuddy object.
 */
GType purple_buddy_get_type(void);

/**
 * purple_buddy_new:
 * @account:    The account this buddy will get added to
 * @name:       The name of the new buddy
 * @alias:      The alias of the new buddy (or NULL if unaliased)
 *
 * Creates a new buddy.
 *
 * This function only creates the #PurpleBuddy. Use purple_blist_add_buddy()
 * to add the buddy to the list and purple_account_add_buddy() to sync up
 * with the server.
 *
 * See purple_account_add_buddy(), purple_blist_add_buddy().
 *
 * Returns: A newly allocated buddy
 */
PurpleBuddy *purple_buddy_new(PurpleAccount *account, const char *name, const char *alias);

/**
 * purple_buddy_get_id:
 * @buddy: The buddy.
 *
 * Gets the globally unique identifier of the buddy.
 *
 * Returns: The id of @buddy.
 *
 * Since: 3.0.0
 */
const gchar *purple_buddy_get_id(PurpleBuddy *buddy);

/**
 * purple_buddy_set_icon:
 * @buddy: The buddy.
 * @icon:  The buddy icon.
 *
 * Sets a buddy's icon.
 *
 * This should only be called from within Purple. You probably want to
 * call purple_buddy_icon_set_data().
 *
 * See purple_buddy_icon_set_data().
 */
void purple_buddy_set_icon(PurpleBuddy *buddy, PurpleBuddyIcon *icon);

/**
 * purple_buddy_get_icon:
 * @buddy: The buddy.
 *
 * Returns a buddy's icon.
 *
 * Returns: The buddy icon.
 */
PurpleBuddyIcon *purple_buddy_get_icon(PurpleBuddy *buddy);

/**
 * purple_buddy_get_account:
 * @buddy: The buddy.
 *
 * Returns a buddy's account.
 *
 * Returns: (transfer none): The account.
 */
PurpleAccount *purple_buddy_get_account(PurpleBuddy *buddy);

/**
 * purple_buddy_set_name:
 * @buddy: The buddy.
 * @name:  The name.
 *
 * Sets a buddy's name
 */
void purple_buddy_set_name(PurpleBuddy *buddy, const char *name);

/**
 * purple_buddy_get_name:
 * @buddy: The buddy.
 *
 * Returns a buddy's name
 *
 * Returns: The name.
 */
const char *purple_buddy_get_name(PurpleBuddy *buddy);

/**
 * purple_buddy_get_protocol_data:
 * @buddy: The buddy.
 *
 * Returns a buddy's protocol-specific data.
 *
 * This should only be called from the associated protocol.
 *
 * See purple_buddy_set_protocol_data().
 *
 * Returns:      The protocol data.
 */
gpointer purple_buddy_get_protocol_data(PurpleBuddy *buddy);

/**
 * purple_buddy_set_protocol_data:
 * @buddy: The buddy.
 * @data:  The data.
 *
 * Sets a buddy's protocol-specific data.
 *
 * This should only be called from the associated protocol.
 *
 * See purple_buddy_get_protocol_data().
 */
void purple_buddy_set_protocol_data(PurpleBuddy *buddy, gpointer data);

/**
 * purple_buddy_get_contact:
 * @buddy: The buddy.
 *
 * Returns a buddy's contact.
 *
 * Returns: (transfer none): The buddy's contact.
 */
PurpleMetaContact *purple_buddy_get_contact(PurpleBuddy *buddy);

/**
 * purple_buddy_get_presence:
 * @buddy: The buddy.
 *
 * Returns a buddy's presence.
 *
 * Returns: (transfer none): The buddy's presence.
 */
PurplePresence *purple_buddy_get_presence(PurpleBuddy *buddy);

/**
 * purple_buddy_update_status:
 * @buddy:      The buddy whose status has changed.
 * @old_status: The status from which we are changing.
 *
 * Updates a buddy's status.
 *
 * This should only be called from within Purple.
 */
void purple_buddy_update_status(PurpleBuddy *buddy, PurpleStatus *old_status);

/**
 * purple_buddy_get_media_caps:
 * @buddy: The buddy.
 *
 * Gets the media caps from a buddy.
 *
 * Returns:      The media caps.
 */
PurpleMediaCaps purple_buddy_get_media_caps(PurpleBuddy *buddy);

/**
 * purple_buddy_set_media_caps:
 * @buddy:      The PurpleBuddy.
 * @media_caps: The PurpleMediaCaps.
 *
 * Sets the media caps for a buddy.
 */
void purple_buddy_set_media_caps(PurpleBuddy *buddy, PurpleMediaCaps media_caps);

/**
 * purple_buddy_get_alias_only:
 * @buddy:   The buddy whose alias will be returned.
 *
 * Returns the alias of a buddy.
 *
 * Returns:        The alias (if set), server alias (if set),
 *                or NULL.
 */
const char *purple_buddy_get_alias_only(PurpleBuddy *buddy);

/**
 * purple_buddy_set_server_alias:
 * @buddy:  The buddy.
 * @alias:  The server alias to be set.
 *
 * Sets the server alias for a buddy.
 */
void purple_buddy_set_server_alias(PurpleBuddy *buddy, const char *alias);

/**
 * purple_buddy_get_server_alias:
 * @buddy:  The buddy whose server alias will be returned
 *
 * Gets the server alias for a buddy.
 *
 * Returns:  The server alias, or NULL if it is not set.
 */
const char *purple_buddy_get_server_alias(PurpleBuddy *buddy);

/**
 * purple_buddy_get_contact_alias:
 * @buddy:  The buddy whose alias will be returned
 *
 * Returns the correct name to display for a buddy, taking the contact alias
 * into account. In order of precedence: the buddy's alias; the buddy's
 * contact alias; the buddy's server alias; the buddy's user name.
 *
 * Returns:       The appropriate name or alias, or NULL.
 *
 */
const char *purple_buddy_get_contact_alias(PurpleBuddy *buddy);

/**
 * purple_buddy_get_alias:
 * @buddy:   The buddy whose alias will be returned.
 *
 * Returns the correct name to display for a buddy. In order of precedence:
 * the buddy's local alias; the buddy's server alias; the buddy's contact alias;
 * the buddy's user name.
 *
 * Returns:        The appropriate name or alias, or NULL
 */
const char *purple_buddy_get_alias(PurpleBuddy *buddy);

/**
 * purple_buddy_set_local_alias:
 * @buddy:  The buddy
 * @alias:  The local alias for the buddy
 *
 * Sets the local alias for the buddy.
 */
void purple_buddy_set_local_alias(PurpleBuddy *buddy, const char *alias);

/**
 * purple_buddy_get_local_alias:
 * @buddy:  The buddy
 *
 * Returns the local alias for the buddy, or %NULL if none exists.
 *
 * Returns:       The local alias for the buddy
 */
const char *purple_buddy_get_local_alias(PurpleBuddy *buddy);

/**
 * purple_buddy_get_group:
 * @buddy:   The buddy
 *
 * Returns the group of which the buddy is a member.
 *
 * Returns: (transfer none): The group or %NULL if the buddy is not in a group.
 */
PurpleGroup *purple_buddy_get_group(PurpleBuddy *buddy);

G_END_DECLS

#endif /* PURPLE_BUDDY_H */