summaryrefslogtreecommitdiff
path: root/libpurple/protocols/facebook/data.h
blob: 1e3fbae59666e6b773e5e6d73d6c48652883a95a (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
/* 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_FACEBOOK_DATA_H
#define PURPLE_FACEBOOK_DATA_H

#include <glib.h>

#include <purple.h>

#include "api.h"
#include "http.h"
#include "id.h"

#define FB_TYPE_DATA  fb_data_get_type()
#define FB_TYPE_DATA_IMAGE  fb_data_image_get_type()

/**
 * FB_DATA_ICON_MAX:
 *
 * The maximum of number of concurrent icon fetches.
 */
#define FB_DATA_ICON_MAX  4

/**
 * FB_DATA_ICON_SIZE_MAX:
 *
 * The maximum size of a fetched icon.
 */
#define FB_DATA_ICON_SIZE_MAX  0xa00000 /* 10MiB */

G_DECLARE_FINAL_TYPE(FbData, fb_data, FB, DATA, GObject)

G_DECLARE_FINAL_TYPE(FbDataImage, fb_data_image, FB, DATA_IMAGE, GObject)

/**
 * FbDataImageFunc:
 * @img: The #FbDataImage.
 * @error: The #GError or #NULL.
 *
 * The callback for a fetched #FbDataImage.
 */
typedef void (*FbDataImageFunc) (FbDataImage *img, GError *error);

/**
 * fb_data_new:
 * @gc: The #PurpleConnection.
 * @resolver: The proxy resolver to use from the account.
 *
 * Creates a new #FbData. The returned #FbData should be freed with
 * #g_object_unref() when no longer needed.
 *
 * Returns: The new #FbData.
 */
FbData *fb_data_new(PurpleConnection *gc, GProxyResolver *resolver);

/**
 * fb_data_load:
 * @fata: The #FbData.
 *
 * Loads the internal data from the underlying #PurpleAccount.
 *
 * Return: #TRUE if all of the data was loaded, otherwise #FALSE.
 */
gboolean
fb_data_load(FbData *fata);

/**
 * fb_data_save:
 * @fata: The #FbData.
 *
 * Saves the internal data to the underlying #PurpleAccount.
 */
void
fb_data_save(FbData *fata);

/**
 * fb_data_save_timeout:
 * @fata: The #FbData.
 * @name: The name of the timeout.
 * @id: The source id of the timeout.
 *
 * Saves a new callback timer. The callback should be added to the main loop
 * with `g_timeout_add` or similar, and the returned source identifier passed
 * to this function. The timeout should be cleared with
 * #fb_data_clear_timeout() when no longer needed.
 */
void
fb_data_save_timeout(FbData *fata, const gchar *name, guint id);

/**
 * fb_data_clear_timeout:
 * @fata: The #FbData.
 * @name: The name of the timeout.
 * @remove: #TRUE to remove from the event loop, otherwise #FALSE.
 *
 * Clears and removes a callback timer. The only time @remove should be
 * #FALSE, is when being called from a #GSourceFunc, which is returning
 * #FALSE.
 */
void
fb_data_clear_timeout(FbData *fata, const gchar *name, gboolean remove);

/**
 * fb_data_get_api:
 * @fata: The #FbData.
 *
 * Gets the #FbApi from the #FbData.
 *
 * Return: (transfer none): The #FbApi.
 */
FbApi *
fb_data_get_api(FbData *fata);

/**
 * fb_data_get_connection:
 * @fata: The #FbData.
 *
 * Gets the #PurpleConnection from the #FbData.
 *
 * Return: (transfer none): The #PurpleConnection.
 */
PurpleConnection *
fb_data_get_connection(FbData *fata);

/**
 * fb_data_get_roomlist:
 * @fata: The #FbData.
 *
 * Gets the #PurpleRoomlist from the #FbData.
 *
 * Return: (transfer none): The #PurpleRoomlist.
 */
PurpleRoomlist *
fb_data_get_roomlist(FbData *fata);

/**
 * fb_data_get_unread:
 * @fata: The #FbData.
 * @id: The #FbId.
 *
 * Gets the unread state of an #FbId.
 *
 * Return: #TRUE if the #FbId is unread, otherwise #FALSE.
 */
gboolean
fb_data_get_unread(FbData *fata, FbId id);

/**
 * fb_data_set_roomlist:
 * @fata: The #FbData.
 * @list: The #PurpleRoomlist.
 *
 * Sets the #PurpleRoomlist to the #FbData.
 */
void
fb_data_set_roomlist(FbData *fata, PurpleRoomlist *list);

/**
 * fb_data_set_unread:
 * @fata: The #FbData.
 * @id: The #FbId.
 * @unread: #TRUE if the #FbId is unread, otherwise #FALSE.
 *
 * Sets the unread state of an #FbId to the #FbData.
 */
void
fb_data_set_unread(FbData *fata, FbId id, gboolean unread);

/**
 * fb_data_add_message:
 * @fata: The #FbData.
 * @msg: The #FbApiMessage.
 *
 * Adds an #FbApiMessage to the #FbData.
 */
void
fb_data_add_message(FbData *fata, FbApiMessage *msg);

/**
 * fb_data_remove_message:
 * @fata: The #FbData.
 * @msg: The #FbApiMessage.
 *
 * Removes an #FbApiMessage from the #FbData.
 */
void
fb_data_remove_message(FbData *fata, FbApiMessage *msg);

/**
 * fb_data_take_messages:
 * @fata: The #FbData.
 * @uid: The user #FbId.
 *
 * Gets a #GSList of messages by the user #FbId from the #FbData. The
 * #FbApiMessage's are removed from the #FbData.
 *
 * Returns: (element-type FbApiMessage) (transfer full): The messages from the
 *          user.
 */
GSList *
fb_data_take_messages(FbData *fata, FbId uid);

/**
 * fb_data_image_add:
 * @fata: The #FbData.
 * @url: The image URL.
 * @func: The #FbDataImageFunc.
 * @data: The user-defined data.
 * @dunc: The #GDestroyNotify for @data or #NULL.
 *
 * Adds a new #FbDataImage to the #FbData. This is used to fetch images
 * from HTTP sources. After calling this, #fb_data_image_queue() should
 * be called to queue the fetching process.
 *
 * Return: (transfer none): The #FbDataImage.
 */
FbDataImage *
fb_data_image_add(FbData *fata, const gchar *url, FbDataImageFunc func,
                  gpointer data, GDestroyNotify dunc);

/**
 * fb_data_image_get_active:
 * @img: The #FbDataImage.
 *
 * Gets the active fetching state from the #FbDataImage.
 *
 * Returns: #TRUE if the image is being fetched, otherwise #FALSE.
 */
gboolean
fb_data_image_get_active(FbDataImage *img);

/**
 * fb_data_image_get_data:
 * @img: The #FbDataImage.
 *
 * Gets the user-defined data from the #FbDataImage.
 *
 * Returns: The user-defined data.
 */
gpointer
fb_data_image_get_data(FbDataImage *img);

/**
 * fb_data_image_get_fata:
 * @img: The #FbDataImage.
 *
 * Gets the #FbData from the #FbDataImage.
 *
 * Returns: (transfer none): The #FbData.
 */
FbData *
fb_data_image_get_fata(FbDataImage *img);

/**
 * fb_data_image_get_image:
 * @img: The #FbDataImage.
 * @size: The return location for the image size or #NULL.
 *
 * Gets the image data from the #FbDataImage.
 *
 * Returns: The image data.
 */
const guint8 *
fb_data_image_get_image(FbDataImage *img, gsize *size);

/**
 * fb_data_image_dup_image:
 * @img: The #FbDataImage.
 * @size: The return location for the image size or #NULL.
 *
 * Gets the duplicated image data from the #FbDataImage. The returned
 * data should be freed with #g_free() when no longer needed.
 *
 * Returns: The duplicated image data.
 */
guint8 *
fb_data_image_dup_image(FbDataImage *img, gsize *size);

/**
 * fb_data_image_get_url:
 * @img: The #FbDataImage.
 *
 * Gets the image URL from the #FbDataImage.
 *
 * Returns: The image URL.
 */
const gchar *
fb_data_image_get_url(FbDataImage *img);

/**
 * fb_data_image_queue:
 * @fata: The #FbData.
 *
 * Queues the next #FbDataImage fetches.
 */
void
fb_data_image_queue(FbData *fata);

#endif /* PURPLE_FACEBOOK_DATA_H */