summaryrefslogtreecommitdiff
path: root/libpurple/presence.h
blob: 32f8184ba9c3c9860027202ed5c5ce39f7f27287 (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
/**
 * @file presence.h Presence, account presence and buddy presence 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_PRESENCE_H_
#define _PURPLE_PRESENCE_H_

#define PURPLE_TYPE_PRESENCE             (purple_presence_get_type())
#define PURPLE_PRESENCE(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_PRESENCE, PurplePresence))
#define PURPLE_PRESENCE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_PRESENCE, PurplePresenceClass))
#define PURPLE_IS_PRESENCE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_PRESENCE))
#define PURPLE_IS_PRESENCE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_PRESENCE))
#define PURPLE_PRESENCE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_PRESENCE, PurplePresenceClass))

typedef struct _PurplePresence  PurplePresence;
typedef struct _PurplePresenceClass  PurplePresenceClass;

#define PURPLE_TYPE_ACCOUNT_PRESENCE             (purple_account_presence_get_type())
#define PURPLE_ACCOUNT_PRESENCE(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_ACCOUNT_PRESENCE, PurpleAccountPresence))
#define PURPLE_ACCOUNT_PRESENCE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_ACCOUNT_PRESENCE, PurpleAccountPresenceClass))
#define PURPLE_IS_ACCOUNT_PRESENCE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_ACCOUNT_PRESENCE))
#define PURPLE_IS_ACCOUNT_PRESENCE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_ACCOUNT_PRESENCE))
#define PURPLE_ACCOUNT_PRESENCE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_ACCOUNT_PRESENCE, PurpleAccountPresenceClass))

typedef struct _PurpleAccountPresence  PurpleAccountPresence;
typedef struct _PurpleAccountPresenceClass  PurpleAccountPresenceClass;

#define PURPLE_TYPE_BUDDY_PRESENCE             (purple_buddy_presence_get_type())
#define PURPLE_BUDDY_PRESENCE(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_BUDDY_PRESENCE, PurpleBuddyPresence))
#define PURPLE_BUDDY_PRESENCE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_BUDDY_PRESENCE, PurpleBuddyPresenceClass))
#define PURPLE_IS_BUDDY_PRESENCE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_BUDDY_PRESENCE))
#define PURPLE_IS_BUDDY_PRESENCE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_BUDDY_PRESENCE))
#define PURPLE_BUDDY_PRESENCE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_BUDDY_PRESENCE, PurpleBuddyPresenceClass))

typedef struct _PurpleBuddyPresence  PurpleBuddyPresence;
typedef struct _PurpleBuddyPresenceClass  PurpleBuddyPresenceClass;

#include "account.h"
#include "buddylist.h"
#include "status.h"

/**
 * PurplePresence:
 *
 * A PurplePresence is like a collection of PurpleStatuses (plus some
 * other random info).  For any buddy, or for any one of your accounts,
 * or for any person with which you're chatting, you may know various
 * amounts of information.  This information is all contained in
 * one PurplePresence.  If one of your buddies is away and idle,
 * then the presence contains the PurpleStatus for their awayness,
 * and it contains their current idle time.  PurplePresences are
 * never saved to disk.  The information they contain is only relevant
 * for the current PurpleSession.
 *
 * Note: When a presence is destroyed with the last g_object_unref(), all
 *       statuses added to this list will be destroyed along with the presence.
 */
struct _PurplePresence
{
	GObject gparent;
};

/**
 * PurplePresenceClass:
 *
 * Base class for all #PurplePresence's
 */
struct _PurplePresenceClass {
	GObjectClass parent_class;

	/**
	 * Updates the logs and the UI when the idle state or time of the presence
	 * changes.
	 */
	void (*update_idle)(PurplePresence *presence, gboolean old_idle);

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

/**
 * PurpleAccountPresence:
 *
 * A presence for an account
 */
struct _PurpleAccountPresence
{
	PurplePresence parent;
};

/**
 * PurpleAccountPresenceClass:
 *
 * Base class for all #PurpleAccountPresence's
 */
struct _PurpleAccountPresenceClass {
	PurplePresenceClass parent_class;

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

/**
 * PurpleBuddyPresence:
 *
 * A presence for a buddy
 */
struct _PurpleBuddyPresence
{
	PurplePresence parent;
};

/**
 * PurpleBuddyPresenceClass:
 *
 * Base class for all #PurpleBuddyPresence's
 */
struct _PurpleBuddyPresenceClass {
	PurplePresenceClass parent_class;

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

G_BEGIN_DECLS

/**************************************************************************/
/** @name PurpleAccountPresence API                                       */
/**************************************************************************/
/*@{*/

/**
 * purple_account_presence_get_type:
 *
 * Returns the GType for the PurpleAccountPresence object.
 */
GType purple_account_presence_get_type(void);

/**
 * purple_account_presence_new:
 * @account: The account to associate with the presence.
 *
 * Creates a presence for an account.
 *
 * Returns: The new presence.
 */
PurpleAccountPresence *purple_account_presence_new(PurpleAccount *account);

/**
 * purple_account_presence_get_account:
 * @presence: The presence.
 *
 * Returns an account presence's account.
 *
 * Returns: The presence's account.
 */
PurpleAccount *purple_account_presence_get_account(const PurpleAccountPresence *presence);

/*@}*/

/**************************************************************************/
/** @name PurpleBuddyPresence API                                         */
/**************************************************************************/
/*@{*/

/**
 * purple_buddy_presence_get_type:
 *
 * Returns the GType for the PurpleBuddyPresence object.
 */
GType purple_buddy_presence_get_type(void);

/**
 * purple_buddy_presence_new:
 * @buddy: The buddy to associate with the presence.
 *
 * Creates a presence for a buddy.
 *
 * Returns: The new presence.
 */
PurpleBuddyPresence *purple_buddy_presence_new(PurpleBuddy *buddy);

/**
 * purple_buddy_presence_get_buddy:
 * @presence: The presence.
 *
 * Returns the buddy presence's buddy.
 *
 * Returns: The presence's buddy.
 */
PurpleBuddy *purple_buddy_presence_get_buddy(const PurpleBuddyPresence *presence);

/**
 * purple_buddy_presence_compare:
 * @buddy_presence1: The first presence.
 * @buddy_presence2: The second presence.
 *
 * Compares two buddy presences for availability.
 *
 * Returns: -1 if @buddy_presence1 is more available than @buddy_presence2.
 *           0 if @buddy_presence1 is equal to @buddy_presence2.
 *           1 if @buddy_presence1 is less available than @buddy_presence2.
 */
gint purple_buddy_presence_compare(const PurpleBuddyPresence *buddy_presence1,
						   const PurpleBuddyPresence *buddy_presence2);

/*@}*/

/**************************************************************************/
/** @name PurplePresence API                                              */
/**************************************************************************/
/*@{*/

/**
 * purple_presence_get_type:
 *
 * Returns the GType for the PurplePresence object.
 */
GType purple_presence_get_type(void);

/**
 * purple_presence_set_status_active:
 * @presence:  The presence.
 * @status_id: The ID of the status.
 * @active:    The active state.
 *
 * Sets the active state of a status in a presence.
 *
 * Only independent statuses can be set unactive. Normal statuses can only
 * be set active, so if you wish to disable a status, set another
 * non-independent status to active, or use purple_presence_switch_status().
 */
void purple_presence_set_status_active(PurplePresence *presence,
									 const char *status_id, gboolean active);

/**
 * purple_presence_switch_status:
 * @presence: The presence.
 * @status_id: The status ID to switch to.
 *
 * Switches the active status in a presence.
 *
 * This is similar to purple_presence_set_status_active(), except it won't
 * activate independent statuses.
 */
void purple_presence_switch_status(PurplePresence *presence,
								 const char *status_id);

/**
 * purple_presence_set_idle:
 * @presence:  The presence.
 * @idle:      The idle state.
 * @idle_time: The idle time, if @idle is TRUE.  This
 *                  is the time at which the user became idle,
 *                  in seconds since the epoch.  If this value is
 *                  unknown then 0 should be used.
 *
 * Sets the idle state and time on a presence.
 */
void purple_presence_set_idle(PurplePresence *presence, gboolean idle,
							time_t idle_time);

/**
 * purple_presence_set_login_time:
 * @presence:   The presence.
 * @login_time: The login time.
 *
 * Sets the login time on a presence.
 */
void purple_presence_set_login_time(PurplePresence *presence, time_t login_time);

/**
 * purple_presence_get_statuses:
 * @presence: The presence.
 *
 * Returns all the statuses in a presence.
 *
 * Returns: (transfer none): The statuses.
 */
GList *purple_presence_get_statuses(const PurplePresence *presence);

/**
 * purple_presence_get_status:
 * @presence:  The presence.
 * @status_id: The ID of the status.
 *
 * Returns the status with the specified ID from a presence.
 *
 * Returns: The status if found, or NULL.
 */
PurpleStatus *purple_presence_get_status(const PurplePresence *presence,
									 const char *status_id);

/**
 * purple_presence_get_active_status:
 * @presence: The presence.
 *
 * Returns the active exclusive status from a presence.
 *
 * Returns: The active exclusive status.
 */
PurpleStatus *purple_presence_get_active_status(const PurplePresence *presence);

/**
 * purple_presence_is_available:
 * @presence: The presence.
 *
 * Returns whether or not a presence is available.
 *
 * Available presences are online and possibly invisible, but not away or idle.
 *
 * Returns: TRUE if the presence is available, or FALSE otherwise.
 */
gboolean purple_presence_is_available(const PurplePresence *presence);

/**
 * purple_presence_is_online:
 * @presence: The presence.
 *
 * Returns whether or not a presence is online.
 *
 * Returns: TRUE if the presence is online, or FALSE otherwise.
 */
gboolean purple_presence_is_online(const PurplePresence *presence);

/**
 * purple_presence_is_status_active:
 * @presence:  The presence.
 * @status_id: The ID of the status.
 *
 * Returns whether or not a status in a presence is active.
 *
 * A status is active if itself or any of its sub-statuses are active.
 *
 * Returns: TRUE if the status is active, or FALSE.
 */
gboolean purple_presence_is_status_active(const PurplePresence *presence,
										const char *status_id);

/**
 * purple_presence_is_status_primitive_active:
 * @presence:  The presence.
 * @primitive: The status primitive.
 *
 * Returns whether or not a status with the specified primitive type
 * in a presence is active.
 *
 * A status is active if itself or any of its sub-statuses are active.
 *
 * Returns: TRUE if the status is active, or FALSE.
 */
gboolean purple_presence_is_status_primitive_active(
	const PurplePresence *presence, PurpleStatusPrimitive primitive);

/**
 * purple_presence_is_idle:
 * @presence: The presence.
 *
 * Returns whether or not a presence is idle.
 *
 * Returns: TRUE if the presence is idle, or FALSE otherwise.
 *         If the presence is offline (purple_presence_is_online()
 *         returns FALSE) then FALSE is returned.
 */
gboolean purple_presence_is_idle(const PurplePresence *presence);

/**
 * purple_presence_get_idle_time:
 * @presence: The presence.
 *
 * Returns the presence's idle time.
 *
 * Returns: The presence's idle time.
 */
time_t purple_presence_get_idle_time(const PurplePresence *presence);

/**
 * purple_presence_get_login_time:
 * @presence: The presence.
 *
 * Returns the presence's login time.
 *
 * Returns: The presence's login time.
 */
time_t purple_presence_get_login_time(const PurplePresence *presence);

/*@}*/

G_END_DECLS

#endif /* _PURPLE_PRESENCE_H_ */