summaryrefslogtreecommitdiff
path: root/libpurple/request-datasheet.h
blob: a25b53b56a35d4f01ab1500e7a1875a730df80d8 (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
/*
 * Purple - Internet Messaging Library
 * Copyright (C) Pidgin Developers <devel@pidgin.im>
 *
 * 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, see <https://www.gnu.org/licenses/>.
 */

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

#ifndef PURPLE_REQUEST_DATA_H
#define PURPLE_REQUEST_DATA_H

#include <glib.h>

/**
 * PurpleRequestDatasheet:
 *
 * Request Datasheet is a UI abstracted table.
 */

typedef struct _PurpleRequestDatasheet PurpleRequestDatasheet;
typedef struct _PurpleRequestDatasheetRecord PurpleRequestDatasheetRecord;
typedef struct _PurpleRequestDatasheetAction PurpleRequestDatasheetAction;

typedef void (*PurpleRequestDatasheetActionCb)(
	PurpleRequestDatasheetRecord *rec, gpointer user_data);
typedef gboolean (*PurpleRequestDatasheetActionCheckCb)(
	PurpleRequestDatasheetRecord *rec, gpointer user_data);

/**
 * PurpleRequestDatasheetColumnType:
 * @PURPLE_REQUEST_DATASHEET_COLUMN_STRING: The column displays strings.
 * @PURPLE_REQUEST_DATASHEET_COLUMN_IMAGE: The column displays images.
 *
 * The type of data to be shown in a column.
 */

typedef enum
{
	PURPLE_REQUEST_DATASHEET_COLUMN_STRING,
	PURPLE_REQUEST_DATASHEET_COLUMN_IMAGE
} PurpleRequestDatasheetColumnType;

G_BEGIN_DECLS

/**************************************************************************/
/* Datasheet API                                                          */
/**************************************************************************/

/**
 * purple_request_datasheet_new:
 *
 * Creates new Datasheet.
 *
 * Returns: (transfer full): The new datasheet.
 */
PurpleRequestDatasheet *
purple_request_datasheet_new(void);

/**
 * purple_request_datasheet_free:
 * @sheet: The datasheet.
 *
 * Destroys datasheet with all its contents.
 */
void
purple_request_datasheet_free(PurpleRequestDatasheet *sheet);

/**
 * purple_request_datasheet_add_column:
 * @sheet: The datasheet.
 * @type:  The column type.
 * @title: The column title (may be %NULL).
 *
 * Adds a column to the datasheet.
 *
 * You cannot add a column if datasheet contains any data.
 */
void
purple_request_datasheet_add_column(PurpleRequestDatasheet *sheet,
	PurpleRequestDatasheetColumnType type, const gchar *title);

/**
 * purple_request_datasheet_get_column_count:
 * @sheet: The datasheet.
 *
 * Returns the column count of datasheet.
 *
 * Returns: The column count.
 */
guint
purple_request_datasheet_get_column_count(PurpleRequestDatasheet *sheet);

/**
 * purple_request_datasheet_get_column_type:
 * @sheet:  The datasheet.
 * @col_no: The column number (0 is the first one).
 *
 * Returns the column type for a datasheet.
 *
 * Returns: The column type.
 */
PurpleRequestDatasheetColumnType
purple_request_datasheet_get_column_type(PurpleRequestDatasheet *sheet,
	guint col_no);

/**
 * purple_request_datasheet_get_column_title:
 * @sheet:  The datasheet.
 * @col_no: The column number (0 is the first one).
 *
 * Returns the column title for a datasheet.
 *
 * Returns: The column title.
 */
const gchar *
purple_request_datasheet_get_column_title(PurpleRequestDatasheet *sheet,
	guint col_no);

/**
 * purple_request_datasheet_get_records:
 * @sheet: The datasheet.
 *
 * Returns the list of records in a datasheet.
 *
 * You shouldn't modify datasheet's data while iterating through it.
 *
 * Returns: (element-type PurpleRequestDatasheetRecord) (transfer none): The list of records.
 */
const GList *
purple_request_datasheet_get_records(PurpleRequestDatasheet *sheet);

/**
 * purple_request_datasheet_add_action:
 * @sheet:  The datasheet.
 * @action: The action.
 *
 * Adds an action to the datasheet.
 *
 * Action object is owned by the datasheet since this call.
 */
void
purple_request_datasheet_add_action(PurpleRequestDatasheet *sheet,
	PurpleRequestDatasheetAction *action);

/**
 * purple_request_datasheet_get_actions:
 * @sheet: The datasheet.
 *
 * Returns the list of actions in a datasheet.
 *
 * Returns: (element-type PurpleRequestDatasheetAction) (transfer none): The list of actions.
 */
const GList *
purple_request_datasheet_get_actions(PurpleRequestDatasheet *sheet);


/**************************************************************************/
/* Datasheet actions API                                                  */
/**************************************************************************/

/**
 * purple_request_datasheet_action_new:
 *
 * Creates new datasheet action.
 *
 * Returns: (transfer full): The new action.
 */
PurpleRequestDatasheetAction *
purple_request_datasheet_action_new(void);

/**
 * purple_request_datasheet_action_free:
 * @act: The action.
 *
 * Destroys the datasheet action.
 */
void
purple_request_datasheet_action_free(PurpleRequestDatasheetAction *act);

/**
 * purple_request_datasheet_action_set_label:
 * @act:   The action.
 * @label: The label.
 *
 * Sets the localized label for the action.
 */
void
purple_request_datasheet_action_set_label(PurpleRequestDatasheetAction *act,
	const gchar *label);

/**
 * purple_request_datasheet_action_get_label:
 * @act: The action.
 *
 * Gets the label of action.
 *
 * Returns: The localized label text.
 */
const gchar*
purple_request_datasheet_action_get_label(PurpleRequestDatasheetAction *act);

/**
 * purple_request_datasheet_action_set_cb:
 * @act:       The action.
 * @cb: (scope notified):       The callback function.
 * @user_data: The data to be passed to the callback function.
 *
 * Sets the callback for the action.
 */
void
purple_request_datasheet_action_set_cb(PurpleRequestDatasheetAction *act,
	PurpleRequestDatasheetActionCb cb, gpointer user_data);

/**
 * purple_request_datasheet_action_call:
 * @act: The action.
 * @rec: The user selected record.
 *
 * Calls the callback of the action.
 */
void
purple_request_datasheet_action_call(PurpleRequestDatasheetAction *act,
	PurpleRequestDatasheetRecord *rec);

/**
 * purple_request_datasheet_action_set_sens_cb:
 * @act:       The action.
 * @cb: (scope notified):       The callback function, may be %NULL.
 * @user_data: The data to be passed to the callback function.
 *
 * Sets the sensitivity checker for the action.
 *
 * If there is no callback set, default is used: the action is enabled, if any
 * record is active.
 */
void
purple_request_datasheet_action_set_sens_cb(
	PurpleRequestDatasheetAction *act,
	PurpleRequestDatasheetActionCheckCb cb, gpointer user_data);

/**
 * purple_request_datasheet_action_is_sensitive:
 * @act: The action.
 * @rec: The record.
 *
 * Checks, if the action is enabled for the active record.
 *
 * Returns: %TRUE, if the action is enabled, %FALSE otherwise.
 */
gboolean
purple_request_datasheet_action_is_sensitive(PurpleRequestDatasheetAction *act,
	PurpleRequestDatasheetRecord *rec);


/**************************************************************************/
/* Datasheet record API                                                   */
/**************************************************************************/

/**
 * purple_request_datasheet_record_get_key:
 * @rec: The record.
 *
 * Returns the key of a record.
 *
 * Returns: The key.
 */
gpointer
purple_request_datasheet_record_get_key(
	const PurpleRequestDatasheetRecord *rec);

/**
 * purple_request_datasheet_record_get_datasheet:
 * @rec: The record.
 *
 * Returns the datasheet of a record.
 *
 * Returns: (transfer none): The datasheet.
 */
PurpleRequestDatasheet *
purple_request_datasheet_record_get_datasheet(
	PurpleRequestDatasheetRecord *rec);

/**
 * purple_request_datasheet_record_find:
 * @sheet: The datasheet.
 * @key:   The key.
 *
 * Looks up for a record in datasheet.
 *
 * Returns: (transfer none): The record if found, %NULL otherwise.
 */
PurpleRequestDatasheetRecord *
purple_request_datasheet_record_find(PurpleRequestDatasheet *sheet,
	gpointer key);

/**
 * purple_request_datasheet_record_add:
 * @sheet: The datasheet.
 * @key:   The key.
 *
 * Adds a record to the datasheet.
 *
 * If the specified key already exists in datasheet, old record is returned.
 *
 * Returns: (transfer full): The record.
 */
PurpleRequestDatasheetRecord *
purple_request_datasheet_record_add(PurpleRequestDatasheet *sheet,
	gpointer key);

/**
 * purple_request_datasheet_record_remove:
 * @sheet: The datasheet.
 * @key:   The key.
 *
 * Removes a record from a datasheet.
 */
void
purple_request_datasheet_record_remove(PurpleRequestDatasheet *sheet,
	gpointer key);

/**
 * purple_request_datasheet_record_remove_all:
 * @sheet: The datasheet.
 *
 * Removes all records from a datasheet.
 */
void
purple_request_datasheet_record_remove_all(PurpleRequestDatasheet *sheet);

/**
 * purple_request_datasheet_record_mark_all_for_rem:
 * @sheet: The datasheet.
 *
 * Marks all records for removal. Record will be unmarked, when touched with
 * purple_request_datasheet_record_add.
 *
 * See purple_request_datasheet_record_add().
 */
void
purple_request_datasheet_record_mark_all_for_rem(PurpleRequestDatasheet *sheet);

/**
 * purple_request_datasheet_record_remove_marked:
 * @sheet: The datasheet.
 *
 * Removes all marked records.
 *
 * See purple_request_datasheet_record_mark_all_for_rem().
 */
void
purple_request_datasheet_record_remove_marked(PurpleRequestDatasheet *sheet);

/**
 * purple_request_datasheet_record_set_string_data:
 * @rec:    The record.
 * @col_no: The column.
 * @data:   The data.
 *
 * Sets data for a string column of specified record.
 */
void
purple_request_datasheet_record_set_string_data(
	PurpleRequestDatasheetRecord *rec, guint col_no, const gchar *data);

/**
 * purple_request_datasheet_record_set_image_data:
 * @rec:      The record.
 * @col_no:   The column.
 * @stock_id: The stock identifier of a image.
 *
 * Sets data for a image column of specified record.
 */
void
purple_request_datasheet_record_set_image_data(
	PurpleRequestDatasheetRecord *rec, guint col_no, const gchar *stock_id);

/**
 * purple_request_datasheet_record_get_string_data:
 * @rec:    The record.
 * @col_no: The column.
 *
 * Returns data for a string column of specified record.
 *
 * Returns: The data.
 */
const gchar *
purple_request_datasheet_record_get_string_data(
	const PurpleRequestDatasheetRecord *rec, guint col_no);

/**
 * purple_request_datasheet_record_get_image_data:
 * @rec:    The record.
 * @col_no: The column.
 *
 * Returns data for an image column of specified record.
 *
 * Returns: The stock id of an image.
 */
const gchar *
purple_request_datasheet_record_get_image_data(
	const PurpleRequestDatasheetRecord *rec, guint col_no);

G_END_DECLS

#endif /* PURPLE_REQUEST_DATA_H */