14192
|
1 /**
|
|
2 * @file request.c Request API
|
|
3 * @ingroup core
|
|
4 *
|
|
5 * gaim
|
|
6 *
|
|
7 * Gaim is the legal property of its developers, whose names are too numerous
|
|
8 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
9 * source distribution.
|
|
10 *
|
|
11 * This program is free software; you can redistribute it and/or modify
|
|
12 * it under the terms of the GNU General Public License as published by
|
|
13 * the Free Software Foundation; either version 2 of the License, or
|
|
14 * (at your option) any later version.
|
|
15 *
|
|
16 * This program is distributed in the hope that it will be useful,
|
|
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19 * GNU General Public License for more details.
|
|
20 *
|
|
21 * You should have received a copy of the GNU General Public License
|
|
22 * along with this program; if not, write to the Free Software
|
|
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
24 */
|
|
25 #include "notify.h"
|
|
26 #include "request.h"
|
|
27 #include "debug.h"
|
|
28
|
|
29 static GaimRequestUiOps *request_ui_ops = NULL;
|
|
30 static GList *handles = NULL;
|
|
31
|
|
32 typedef struct
|
|
33 {
|
|
34 GaimRequestType type;
|
|
35 void *handle;
|
|
36 void *ui_handle;
|
|
37
|
|
38 } GaimRequestInfo;
|
|
39
|
|
40
|
|
41 GaimRequestFields *
|
|
42 gaim_request_fields_new(void)
|
|
43 {
|
|
44 GaimRequestFields *fields;
|
|
45
|
|
46 fields = g_new0(GaimRequestFields, 1);
|
|
47
|
|
48 fields->fields = g_hash_table_new_full(g_str_hash, g_str_equal,
|
|
49 g_free, NULL);
|
|
50
|
|
51 return fields;
|
|
52 }
|
|
53
|
|
54 void
|
|
55 gaim_request_fields_destroy(GaimRequestFields *fields)
|
|
56 {
|
|
57 g_return_if_fail(fields != NULL);
|
|
58
|
|
59 g_list_foreach(fields->groups, (GFunc)gaim_request_field_group_destroy, NULL);
|
|
60 g_list_free(fields->groups);
|
|
61 g_list_free(fields->required_fields);
|
|
62 g_hash_table_destroy(fields->fields);
|
|
63 g_free(fields);
|
|
64 }
|
|
65
|
|
66 void
|
|
67 gaim_request_fields_add_group(GaimRequestFields *fields,
|
|
68 GaimRequestFieldGroup *group)
|
|
69 {
|
|
70 GList *l;
|
|
71 GaimRequestField *field;
|
|
72
|
|
73 g_return_if_fail(fields != NULL);
|
|
74 g_return_if_fail(group != NULL);
|
|
75
|
|
76 fields->groups = g_list_append(fields->groups, group);
|
|
77
|
|
78 group->fields_list = fields;
|
|
79
|
|
80 for (l = gaim_request_field_group_get_fields(group);
|
|
81 l != NULL;
|
|
82 l = l->next) {
|
|
83
|
|
84 field = l->data;
|
|
85
|
|
86 g_hash_table_insert(fields->fields,
|
|
87 g_strdup(gaim_request_field_get_id(field)), field);
|
|
88
|
|
89 if (gaim_request_field_is_required(field)) {
|
|
90 fields->required_fields =
|
|
91 g_list_append(fields->required_fields, field);
|
|
92 }
|
|
93
|
|
94 }
|
|
95 }
|
|
96
|
|
97 GList *
|
|
98 gaim_request_fields_get_groups(const GaimRequestFields *fields)
|
|
99 {
|
|
100 g_return_val_if_fail(fields != NULL, NULL);
|
|
101
|
|
102 return fields->groups;
|
|
103 }
|
|
104
|
|
105 gboolean
|
|
106 gaim_request_fields_exists(const GaimRequestFields *fields, const char *id)
|
|
107 {
|
|
108 g_return_val_if_fail(fields != NULL, FALSE);
|
|
109 g_return_val_if_fail(id != NULL, FALSE);
|
|
110
|
|
111 return (g_hash_table_lookup(fields->fields, id) != NULL);
|
|
112 }
|
|
113
|
|
114 const GList *
|
|
115 gaim_request_fields_get_required(const GaimRequestFields *fields)
|
|
116 {
|
|
117 g_return_val_if_fail(fields != NULL, NULL);
|
|
118
|
|
119 return fields->required_fields;
|
|
120 }
|
|
121
|
|
122 gboolean
|
|
123 gaim_request_fields_is_field_required(const GaimRequestFields *fields,
|
|
124 const char *id)
|
|
125 {
|
|
126 GaimRequestField *field;
|
|
127
|
|
128 g_return_val_if_fail(fields != NULL, FALSE);
|
|
129 g_return_val_if_fail(id != NULL, FALSE);
|
|
130
|
|
131 if ((field = gaim_request_fields_get_field(fields, id)) == NULL)
|
|
132 return FALSE;
|
|
133
|
|
134 return gaim_request_field_is_required(field);
|
|
135 }
|
|
136
|
|
137 gboolean
|
|
138 gaim_request_fields_all_required_filled(const GaimRequestFields *fields)
|
|
139 {
|
|
140 GList *l;
|
|
141
|
|
142 g_return_val_if_fail(fields != NULL, FALSE);
|
|
143
|
|
144 for (l = fields->required_fields; l != NULL; l = l->next)
|
|
145 {
|
|
146 GaimRequestField *field = (GaimRequestField *)l->data;
|
|
147
|
|
148 switch (gaim_request_field_get_type(field))
|
|
149 {
|
|
150 case GAIM_REQUEST_FIELD_STRING:
|
|
151 if (gaim_request_field_string_get_value(field) == NULL)
|
|
152 return FALSE;
|
|
153
|
|
154 break;
|
|
155
|
|
156 default:
|
|
157 break;
|
|
158 }
|
|
159 }
|
|
160
|
|
161 return TRUE;
|
|
162 }
|
|
163
|
|
164 GaimRequestField *
|
|
165 gaim_request_fields_get_field(const GaimRequestFields *fields, const char *id)
|
|
166 {
|
|
167 GaimRequestField *field;
|
|
168
|
|
169 g_return_val_if_fail(fields != NULL, NULL);
|
|
170 g_return_val_if_fail(id != NULL, NULL);
|
|
171
|
|
172 field = g_hash_table_lookup(fields->fields, id);
|
|
173
|
|
174 g_return_val_if_fail(field != NULL, NULL);
|
|
175
|
|
176 return field;
|
|
177 }
|
|
178
|
|
179 const char *
|
|
180 gaim_request_fields_get_string(const GaimRequestFields *fields, const char *id)
|
|
181 {
|
|
182 GaimRequestField *field;
|
|
183
|
|
184 g_return_val_if_fail(fields != NULL, NULL);
|
|
185 g_return_val_if_fail(id != NULL, NULL);
|
|
186
|
|
187 if ((field = gaim_request_fields_get_field(fields, id)) == NULL)
|
|
188 return NULL;
|
|
189
|
|
190 return gaim_request_field_string_get_value(field);
|
|
191 }
|
|
192
|
|
193 int
|
|
194 gaim_request_fields_get_integer(const GaimRequestFields *fields,
|
|
195 const char *id)
|
|
196 {
|
|
197 GaimRequestField *field;
|
|
198
|
|
199 g_return_val_if_fail(fields != NULL, 0);
|
|
200 g_return_val_if_fail(id != NULL, 0);
|
|
201
|
|
202 if ((field = gaim_request_fields_get_field(fields, id)) == NULL)
|
|
203 return 0;
|
|
204
|
|
205 return gaim_request_field_int_get_value(field);
|
|
206 }
|
|
207
|
|
208 gboolean
|
|
209 gaim_request_fields_get_bool(const GaimRequestFields *fields, const char *id)
|
|
210 {
|
|
211 GaimRequestField *field;
|
|
212
|
|
213 g_return_val_if_fail(fields != NULL, FALSE);
|
|
214 g_return_val_if_fail(id != NULL, FALSE);
|
|
215
|
|
216 if ((field = gaim_request_fields_get_field(fields, id)) == NULL)
|
|
217 return FALSE;
|
|
218
|
|
219 return gaim_request_field_bool_get_value(field);
|
|
220 }
|
|
221
|
|
222 int
|
|
223 gaim_request_fields_get_choice(const GaimRequestFields *fields, const char *id)
|
|
224 {
|
|
225 GaimRequestField *field;
|
|
226
|
|
227 g_return_val_if_fail(fields != NULL, -1);
|
|
228 g_return_val_if_fail(id != NULL, -1);
|
|
229
|
|
230 if ((field = gaim_request_fields_get_field(fields, id)) == NULL)
|
|
231 return -1;
|
|
232
|
|
233 return gaim_request_field_choice_get_value(field);
|
|
234 }
|
|
235
|
|
236 GaimAccount *
|
|
237 gaim_request_fields_get_account(const GaimRequestFields *fields,
|
|
238 const char *id)
|
|
239 {
|
|
240 GaimRequestField *field;
|
|
241
|
|
242 g_return_val_if_fail(fields != NULL, NULL);
|
|
243 g_return_val_if_fail(id != NULL, NULL);
|
|
244
|
|
245 if ((field = gaim_request_fields_get_field(fields, id)) == NULL)
|
|
246 return NULL;
|
|
247
|
|
248 return gaim_request_field_account_get_value(field);
|
|
249 }
|
|
250
|
|
251 GaimRequestFieldGroup *
|
|
252 gaim_request_field_group_new(const char *title)
|
|
253 {
|
|
254 GaimRequestFieldGroup *group;
|
|
255
|
|
256 group = g_new0(GaimRequestFieldGroup, 1);
|
|
257
|
|
258 group->title = g_strdup(title);
|
|
259
|
|
260 return group;
|
|
261 }
|
|
262
|
|
263 void
|
|
264 gaim_request_field_group_destroy(GaimRequestFieldGroup *group)
|
|
265 {
|
|
266 g_return_if_fail(group != NULL);
|
|
267
|
|
268 g_free(group->title);
|
|
269
|
|
270 g_list_foreach(group->fields, (GFunc)gaim_request_field_destroy, NULL);
|
|
271 g_list_free(group->fields);
|
|
272
|
|
273 g_free(group);
|
|
274 }
|
|
275
|
|
276 void
|
|
277 gaim_request_field_group_add_field(GaimRequestFieldGroup *group,
|
|
278 GaimRequestField *field)
|
|
279 {
|
|
280 g_return_if_fail(group != NULL);
|
|
281 g_return_if_fail(field != NULL);
|
|
282
|
|
283 group->fields = g_list_append(group->fields, field);
|
|
284
|
|
285 if (group->fields_list != NULL)
|
|
286 {
|
|
287 g_hash_table_insert(group->fields_list->fields,
|
|
288 g_strdup(gaim_request_field_get_id(field)), field);
|
|
289
|
|
290 if (gaim_request_field_is_required(field))
|
|
291 {
|
|
292 group->fields_list->required_fields =
|
|
293 g_list_append(group->fields_list->required_fields, field);
|
|
294 }
|
|
295 }
|
|
296
|
|
297 field->group = group;
|
|
298
|
|
299 }
|
|
300
|
|
301 const char *
|
|
302 gaim_request_field_group_get_title(const GaimRequestFieldGroup *group)
|
|
303 {
|
|
304 g_return_val_if_fail(group != NULL, NULL);
|
|
305
|
|
306 return group->title;
|
|
307 }
|
|
308
|
|
309 GList *
|
|
310 gaim_request_field_group_get_fields(const GaimRequestFieldGroup *group)
|
|
311 {
|
|
312 g_return_val_if_fail(group != NULL, NULL);
|
|
313
|
|
314 return group->fields;
|
|
315 }
|
|
316
|
|
317 GaimRequestField *
|
|
318 gaim_request_field_new(const char *id, const char *text,
|
|
319 GaimRequestFieldType type)
|
|
320 {
|
|
321 GaimRequestField *field;
|
|
322
|
|
323 g_return_val_if_fail(id != NULL, NULL);
|
|
324 g_return_val_if_fail(type != GAIM_REQUEST_FIELD_NONE, NULL);
|
|
325
|
|
326 field = g_new0(GaimRequestField, 1);
|
|
327
|
|
328 field->id = g_strdup(id);
|
|
329 field->type = type;
|
|
330
|
|
331 gaim_request_field_set_label(field, text);
|
|
332 gaim_request_field_set_visible(field, TRUE);
|
|
333
|
|
334 return field;
|
|
335 }
|
|
336
|
|
337 void
|
|
338 gaim_request_field_destroy(GaimRequestField *field)
|
|
339 {
|
|
340 g_return_if_fail(field != NULL);
|
|
341
|
|
342 g_free(field->id);
|
|
343 g_free(field->label);
|
|
344 g_free(field->type_hint);
|
|
345
|
|
346 if (field->type == GAIM_REQUEST_FIELD_STRING)
|
|
347 {
|
|
348 g_free(field->u.string.default_value);
|
|
349 g_free(field->u.string.value);
|
|
350 }
|
|
351 else if (field->type == GAIM_REQUEST_FIELD_CHOICE)
|
|
352 {
|
|
353 if (field->u.choice.labels != NULL)
|
|
354 {
|
|
355 g_list_foreach(field->u.choice.labels, (GFunc)g_free, NULL);
|
|
356 g_list_free(field->u.choice.labels);
|
|
357 }
|
|
358 }
|
|
359 else if (field->type == GAIM_REQUEST_FIELD_LIST)
|
|
360 {
|
|
361 if (field->u.list.items != NULL)
|
|
362 {
|
|
363 g_list_foreach(field->u.list.items, (GFunc)g_free, NULL);
|
|
364 g_list_free(field->u.list.items);
|
|
365 }
|
|
366
|
|
367 if (field->u.list.selected != NULL)
|
|
368 {
|
|
369 g_list_foreach(field->u.list.selected, (GFunc)g_free, NULL);
|
|
370 g_list_free(field->u.list.selected);
|
|
371 }
|
|
372
|
|
373 g_hash_table_destroy(field->u.list.item_data);
|
|
374 g_hash_table_destroy(field->u.list.selected_table);
|
|
375 }
|
|
376
|
|
377 g_free(field);
|
|
378 }
|
|
379
|
|
380 void
|
|
381 gaim_request_field_set_label(GaimRequestField *field, const char *label)
|
|
382 {
|
|
383 g_return_if_fail(field != NULL);
|
|
384
|
|
385 g_free(field->label);
|
|
386 field->label = g_strdup(label);
|
|
387 }
|
|
388
|
|
389 void
|
|
390 gaim_request_field_set_visible(GaimRequestField *field, gboolean visible)
|
|
391 {
|
|
392 g_return_if_fail(field != NULL);
|
|
393
|
|
394 field->visible = visible;
|
|
395 }
|
|
396
|
|
397 void
|
|
398 gaim_request_field_set_type_hint(GaimRequestField *field,
|
|
399 const char *type_hint)
|
|
400 {
|
|
401 g_return_if_fail(field != NULL);
|
|
402
|
|
403 g_free(field->type_hint);
|
|
404 field->type_hint = g_strdup(type_hint);
|
|
405 }
|
|
406
|
|
407 void
|
|
408 gaim_request_field_set_required(GaimRequestField *field, gboolean required)
|
|
409 {
|
|
410 g_return_if_fail(field != NULL);
|
|
411
|
|
412 if (field->required == required)
|
|
413 return;
|
|
414
|
|
415 field->required = required;
|
|
416
|
|
417 if (field->group != NULL)
|
|
418 {
|
|
419 if (required)
|
|
420 {
|
|
421 field->group->fields_list->required_fields =
|
|
422 g_list_append(field->group->fields_list->required_fields,
|
|
423 field);
|
|
424 }
|
|
425 else
|
|
426 {
|
|
427 field->group->fields_list->required_fields =
|
|
428 g_list_remove(field->group->fields_list->required_fields,
|
|
429 field);
|
|
430 }
|
|
431 }
|
|
432 }
|
|
433
|
|
434 GaimRequestFieldType
|
|
435 gaim_request_field_get_type(const GaimRequestField *field)
|
|
436 {
|
|
437 g_return_val_if_fail(field != NULL, GAIM_REQUEST_FIELD_NONE);
|
|
438
|
|
439 return field->type;
|
|
440 }
|
|
441
|
|
442 const char *
|
|
443 gaim_request_field_get_id(const GaimRequestField *field)
|
|
444 {
|
|
445 g_return_val_if_fail(field != NULL, NULL);
|
|
446
|
|
447 return field->id;
|
|
448 }
|
|
449
|
|
450 const char *
|
|
451 gaim_request_field_get_label(const GaimRequestField *field)
|
|
452 {
|
|
453 g_return_val_if_fail(field != NULL, NULL);
|
|
454
|
|
455 return field->label;
|
|
456 }
|
|
457
|
|
458 gboolean
|
|
459 gaim_request_field_is_visible(const GaimRequestField *field)
|
|
460 {
|
|
461 g_return_val_if_fail(field != NULL, FALSE);
|
|
462
|
|
463 return field->visible;
|
|
464 }
|
|
465
|
|
466 const char *
|
|
467 gaim_request_field_get_type_hint(const GaimRequestField *field)
|
|
468 {
|
|
469 g_return_val_if_fail(field != NULL, NULL);
|
|
470
|
|
471 return field->type_hint;
|
|
472 }
|
|
473
|
|
474 gboolean
|
|
475 gaim_request_field_is_required(const GaimRequestField *field)
|
|
476 {
|
|
477 g_return_val_if_fail(field != NULL, FALSE);
|
|
478
|
|
479 return field->required;
|
|
480 }
|
|
481
|
|
482 GaimRequestField *
|
|
483 gaim_request_field_string_new(const char *id, const char *text,
|
|
484 const char *default_value, gboolean multiline)
|
|
485 {
|
|
486 GaimRequestField *field;
|
|
487
|
|
488 g_return_val_if_fail(id != NULL, NULL);
|
|
489 g_return_val_if_fail(text != NULL, NULL);
|
|
490
|
|
491 field = gaim_request_field_new(id, text, GAIM_REQUEST_FIELD_STRING);
|
|
492
|
|
493 field->u.string.multiline = multiline;
|
|
494 field->u.string.editable = TRUE;
|
|
495
|
|
496 gaim_request_field_string_set_default_value(field, default_value);
|
|
497 gaim_request_field_string_set_value(field, default_value);
|
|
498
|
|
499 return field;
|
|
500 }
|
|
501
|
|
502 void
|
|
503 gaim_request_field_string_set_default_value(GaimRequestField *field,
|
|
504 const char *default_value)
|
|
505 {
|
|
506 g_return_if_fail(field != NULL);
|
|
507 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_STRING);
|
|
508
|
|
509 g_free(field->u.string.default_value);
|
|
510 field->u.string.default_value = g_strdup(default_value);
|
|
511 }
|
|
512
|
|
513 void
|
|
514 gaim_request_field_string_set_value(GaimRequestField *field, const char *value)
|
|
515 {
|
|
516 g_return_if_fail(field != NULL);
|
|
517 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_STRING);
|
|
518
|
|
519 g_free(field->u.string.value);
|
|
520 field->u.string.value = g_strdup(value);
|
|
521 }
|
|
522
|
|
523 void
|
|
524 gaim_request_field_string_set_masked(GaimRequestField *field, gboolean masked)
|
|
525 {
|
|
526 g_return_if_fail(field != NULL);
|
|
527 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_STRING);
|
|
528
|
|
529 field->u.string.masked = masked;
|
|
530 }
|
|
531
|
|
532 void
|
|
533 gaim_request_field_string_set_editable(GaimRequestField *field,
|
|
534 gboolean editable)
|
|
535 {
|
|
536 g_return_if_fail(field != NULL);
|
|
537 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_STRING);
|
|
538
|
|
539 field->u.string.editable = editable;
|
|
540 }
|
|
541
|
|
542 const char *
|
|
543 gaim_request_field_string_get_default_value(const GaimRequestField *field)
|
|
544 {
|
|
545 g_return_val_if_fail(field != NULL, NULL);
|
|
546 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_STRING, NULL);
|
|
547
|
|
548 return field->u.string.default_value;
|
|
549 }
|
|
550
|
|
551 const char *
|
|
552 gaim_request_field_string_get_value(const GaimRequestField *field)
|
|
553 {
|
|
554 g_return_val_if_fail(field != NULL, NULL);
|
|
555 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_STRING, NULL);
|
|
556
|
|
557 return field->u.string.value;
|
|
558 }
|
|
559
|
|
560 gboolean
|
|
561 gaim_request_field_string_is_multiline(const GaimRequestField *field)
|
|
562 {
|
|
563 g_return_val_if_fail(field != NULL, FALSE);
|
|
564 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_STRING, FALSE);
|
|
565
|
|
566 return field->u.string.multiline;
|
|
567 }
|
|
568
|
|
569 gboolean
|
|
570 gaim_request_field_string_is_masked(const GaimRequestField *field)
|
|
571 {
|
|
572 g_return_val_if_fail(field != NULL, FALSE);
|
|
573 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_STRING, FALSE);
|
|
574
|
|
575 return field->u.string.masked;
|
|
576 }
|
|
577
|
|
578 gboolean
|
|
579 gaim_request_field_string_is_editable(const GaimRequestField *field)
|
|
580 {
|
|
581 g_return_val_if_fail(field != NULL, FALSE);
|
|
582 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_STRING, FALSE);
|
|
583
|
|
584 return field->u.string.editable;
|
|
585 }
|
|
586
|
|
587 GaimRequestField *
|
|
588 gaim_request_field_int_new(const char *id, const char *text,
|
|
589 int default_value)
|
|
590 {
|
|
591 GaimRequestField *field;
|
|
592
|
|
593 g_return_val_if_fail(id != NULL, NULL);
|
|
594 g_return_val_if_fail(text != NULL, NULL);
|
|
595
|
|
596 field = gaim_request_field_new(id, text, GAIM_REQUEST_FIELD_INTEGER);
|
|
597
|
|
598 gaim_request_field_int_set_default_value(field, default_value);
|
|
599 gaim_request_field_int_set_value(field, default_value);
|
|
600
|
|
601 return field;
|
|
602 }
|
|
603
|
|
604 void
|
|
605 gaim_request_field_int_set_default_value(GaimRequestField *field,
|
|
606 int default_value)
|
|
607 {
|
|
608 g_return_if_fail(field != NULL);
|
|
609 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_INTEGER);
|
|
610
|
|
611 field->u.integer.default_value = default_value;
|
|
612 }
|
|
613
|
|
614 void
|
|
615 gaim_request_field_int_set_value(GaimRequestField *field, int value)
|
|
616 {
|
|
617 g_return_if_fail(field != NULL);
|
|
618 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_INTEGER);
|
|
619
|
|
620 field->u.integer.value = value;
|
|
621 }
|
|
622
|
|
623 int
|
|
624 gaim_request_field_int_get_default_value(const GaimRequestField *field)
|
|
625 {
|
|
626 g_return_val_if_fail(field != NULL, 0);
|
|
627 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_INTEGER, 0);
|
|
628
|
|
629 return field->u.integer.default_value;
|
|
630 }
|
|
631
|
|
632 int
|
|
633 gaim_request_field_int_get_value(const GaimRequestField *field)
|
|
634 {
|
|
635 g_return_val_if_fail(field != NULL, 0);
|
|
636 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_INTEGER, 0);
|
|
637
|
|
638 return field->u.integer.value;
|
|
639 }
|
|
640
|
|
641 GaimRequestField *
|
|
642 gaim_request_field_bool_new(const char *id, const char *text,
|
|
643 gboolean default_value)
|
|
644 {
|
|
645 GaimRequestField *field;
|
|
646
|
|
647 g_return_val_if_fail(id != NULL, NULL);
|
|
648 g_return_val_if_fail(text != NULL, NULL);
|
|
649
|
|
650 field = gaim_request_field_new(id, text, GAIM_REQUEST_FIELD_BOOLEAN);
|
|
651
|
|
652 gaim_request_field_bool_set_default_value(field, default_value);
|
|
653 gaim_request_field_bool_set_value(field, default_value);
|
|
654
|
|
655 return field;
|
|
656 }
|
|
657
|
|
658 void
|
|
659 gaim_request_field_bool_set_default_value(GaimRequestField *field,
|
|
660 gboolean default_value)
|
|
661 {
|
|
662 g_return_if_fail(field != NULL);
|
|
663 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_BOOLEAN);
|
|
664
|
|
665 field->u.boolean.default_value = default_value;
|
|
666 }
|
|
667
|
|
668 void
|
|
669 gaim_request_field_bool_set_value(GaimRequestField *field, gboolean value)
|
|
670 {
|
|
671 g_return_if_fail(field != NULL);
|
|
672 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_BOOLEAN);
|
|
673
|
|
674 field->u.boolean.value = value;
|
|
675 }
|
|
676
|
|
677 gboolean
|
|
678 gaim_request_field_bool_get_default_value(const GaimRequestField *field)
|
|
679 {
|
|
680 g_return_val_if_fail(field != NULL, FALSE);
|
|
681 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_BOOLEAN, FALSE);
|
|
682
|
|
683 return field->u.boolean.default_value;
|
|
684 }
|
|
685
|
|
686 gboolean
|
|
687 gaim_request_field_bool_get_value(const GaimRequestField *field)
|
|
688 {
|
|
689 g_return_val_if_fail(field != NULL, FALSE);
|
|
690 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_BOOLEAN, FALSE);
|
|
691
|
|
692 return field->u.boolean.value;
|
|
693 }
|
|
694
|
|
695 GaimRequestField *
|
|
696 gaim_request_field_choice_new(const char *id, const char *text,
|
|
697 int default_value)
|
|
698 {
|
|
699 GaimRequestField *field;
|
|
700
|
|
701 g_return_val_if_fail(id != NULL, NULL);
|
|
702 g_return_val_if_fail(text != NULL, NULL);
|
|
703
|
|
704 field = gaim_request_field_new(id, text, GAIM_REQUEST_FIELD_CHOICE);
|
|
705
|
|
706 gaim_request_field_choice_set_default_value(field, default_value);
|
|
707 gaim_request_field_choice_set_value(field, default_value);
|
|
708
|
|
709 return field;
|
|
710 }
|
|
711
|
|
712 void
|
|
713 gaim_request_field_choice_add(GaimRequestField *field, const char *label)
|
|
714 {
|
|
715 g_return_if_fail(field != NULL);
|
|
716 g_return_if_fail(label != NULL);
|
|
717 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_CHOICE);
|
|
718
|
|
719 field->u.choice.labels = g_list_append(field->u.choice.labels,
|
|
720 g_strdup(label));
|
|
721 }
|
|
722
|
|
723 void
|
|
724 gaim_request_field_choice_set_default_value(GaimRequestField *field,
|
|
725 int default_value)
|
|
726 {
|
|
727 g_return_if_fail(field != NULL);
|
|
728 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_CHOICE);
|
|
729
|
|
730 field->u.choice.default_value = default_value;
|
|
731 }
|
|
732
|
|
733 void
|
|
734 gaim_request_field_choice_set_value(GaimRequestField *field,
|
|
735 int value)
|
|
736 {
|
|
737 g_return_if_fail(field != NULL);
|
|
738 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_CHOICE);
|
|
739
|
|
740 field->u.choice.value = value;
|
|
741 }
|
|
742
|
|
743 int
|
|
744 gaim_request_field_choice_get_default_value(const GaimRequestField *field)
|
|
745 {
|
|
746 g_return_val_if_fail(field != NULL, -1);
|
|
747 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_CHOICE, -1);
|
|
748
|
|
749 return field->u.choice.default_value;
|
|
750 }
|
|
751
|
|
752 int
|
|
753 gaim_request_field_choice_get_value(const GaimRequestField *field)
|
|
754 {
|
|
755 g_return_val_if_fail(field != NULL, -1);
|
|
756 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_CHOICE, -1);
|
|
757
|
|
758 return field->u.choice.value;
|
|
759 }
|
|
760
|
|
761 GList *
|
|
762 gaim_request_field_choice_get_labels(const GaimRequestField *field)
|
|
763 {
|
|
764 g_return_val_if_fail(field != NULL, NULL);
|
|
765 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_CHOICE, NULL);
|
|
766
|
|
767 return field->u.choice.labels;
|
|
768 }
|
|
769
|
|
770 GaimRequestField *
|
|
771 gaim_request_field_list_new(const char *id, const char *text)
|
|
772 {
|
|
773 GaimRequestField *field;
|
|
774
|
|
775 g_return_val_if_fail(id != NULL, NULL);
|
|
776
|
|
777 field = gaim_request_field_new(id, text, GAIM_REQUEST_FIELD_LIST);
|
|
778
|
|
779 field->u.list.item_data = g_hash_table_new_full(g_str_hash, g_str_equal,
|
|
780 g_free, NULL);
|
|
781
|
|
782 field->u.list.selected_table =
|
|
783 g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
|
|
784
|
|
785 return field;
|
|
786 }
|
|
787
|
|
788 void
|
|
789 gaim_request_field_list_set_multi_select(GaimRequestField *field,
|
|
790 gboolean multi_select)
|
|
791 {
|
|
792 g_return_if_fail(field != NULL);
|
|
793 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_LIST);
|
|
794
|
|
795 field->u.list.multiple_selection = multi_select;
|
|
796 }
|
|
797
|
|
798 gboolean
|
|
799 gaim_request_field_list_get_multi_select(const GaimRequestField *field)
|
|
800 {
|
|
801 g_return_val_if_fail(field != NULL, FALSE);
|
|
802 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_LIST, FALSE);
|
|
803
|
|
804 return field->u.list.multiple_selection;
|
|
805 }
|
|
806
|
|
807 void *
|
|
808 gaim_request_field_list_get_data(const GaimRequestField *field,
|
|
809 const char *text)
|
|
810 {
|
|
811 g_return_val_if_fail(field != NULL, NULL);
|
|
812 g_return_val_if_fail(text != NULL, NULL);
|
|
813 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_LIST, NULL);
|
|
814
|
|
815 return g_hash_table_lookup(field->u.list.item_data, text);
|
|
816 }
|
|
817
|
|
818 void
|
|
819 gaim_request_field_list_add(GaimRequestField *field, const char *item,
|
|
820 void *data)
|
|
821 {
|
|
822 g_return_if_fail(field != NULL);
|
|
823 g_return_if_fail(item != NULL);
|
|
824 g_return_if_fail(data != NULL);
|
|
825 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_LIST);
|
|
826
|
|
827 field->u.list.items = g_list_append(field->u.list.items, g_strdup(item));
|
|
828
|
|
829 g_hash_table_insert(field->u.list.item_data, g_strdup(item), data);
|
|
830 }
|
|
831
|
|
832 void
|
|
833 gaim_request_field_list_add_selected(GaimRequestField *field, const char *item)
|
|
834 {
|
|
835 g_return_if_fail(field != NULL);
|
|
836 g_return_if_fail(item != NULL);
|
|
837 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_LIST);
|
|
838
|
|
839 if (!gaim_request_field_list_get_multi_select(field) &&
|
|
840 field->u.list.selected != NULL)
|
|
841 {
|
|
842 gaim_debug_warning("request",
|
|
843 "More than one item added to non-multi-select "
|
|
844 "field %s\n",
|
|
845 gaim_request_field_get_id(field));
|
|
846 return;
|
|
847 }
|
|
848
|
|
849 field->u.list.selected = g_list_append(field->u.list.selected,
|
|
850 g_strdup(item));
|
|
851
|
|
852 g_hash_table_insert(field->u.list.selected_table, g_strdup(item), NULL);
|
|
853 }
|
|
854
|
|
855 void
|
|
856 gaim_request_field_list_clear_selected(GaimRequestField *field)
|
|
857 {
|
|
858 g_return_if_fail(field != NULL);
|
|
859 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_LIST);
|
|
860
|
|
861 if (field->u.list.selected != NULL)
|
|
862 {
|
|
863 g_list_foreach(field->u.list.selected, (GFunc)g_free, NULL);
|
|
864 g_list_free(field->u.list.selected);
|
|
865 field->u.list.selected = NULL;
|
|
866 }
|
|
867
|
|
868 g_hash_table_destroy(field->u.list.selected_table);
|
|
869
|
|
870 field->u.list.selected_table =
|
|
871 g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
|
|
872 }
|
|
873
|
|
874 void
|
|
875 gaim_request_field_list_set_selected(GaimRequestField *field, const GList *items)
|
|
876 {
|
|
877 const GList *l;
|
|
878
|
|
879 g_return_if_fail(field != NULL);
|
|
880 g_return_if_fail(items != NULL);
|
|
881 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_LIST);
|
|
882
|
|
883 gaim_request_field_list_clear_selected(field);
|
|
884
|
|
885 if (!gaim_request_field_list_get_multi_select(field) &&
|
|
886 g_list_length((GList*)items) > 1)
|
|
887 {
|
|
888 gaim_debug_warning("request",
|
|
889 "More than one item added to non-multi-select "
|
|
890 "field %s\n",
|
|
891 gaim_request_field_get_id(field));
|
|
892 return;
|
|
893 }
|
|
894
|
|
895 for (l = items; l != NULL; l = l->next)
|
|
896 {
|
|
897 field->u.list.selected = g_list_append(field->u.list.selected,
|
|
898 g_strdup(l->data));
|
|
899 g_hash_table_insert(field->u.list.selected_table,
|
|
900 g_strdup((char *)l->data), NULL);
|
|
901 }
|
|
902 }
|
|
903
|
|
904 gboolean
|
|
905 gaim_request_field_list_is_selected(const GaimRequestField *field,
|
|
906 const char *item)
|
|
907 {
|
|
908 g_return_val_if_fail(field != NULL, FALSE);
|
|
909 g_return_val_if_fail(item != NULL, FALSE);
|
|
910 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_LIST, FALSE);
|
|
911
|
|
912 return g_hash_table_lookup_extended(field->u.list.selected_table,
|
|
913 item, NULL, NULL);
|
|
914 }
|
|
915
|
|
916 const GList *
|
|
917 gaim_request_field_list_get_selected(const GaimRequestField *field)
|
|
918 {
|
|
919 g_return_val_if_fail(field != NULL, NULL);
|
|
920 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_LIST, NULL);
|
|
921
|
|
922 return field->u.list.selected;
|
|
923 }
|
|
924
|
|
925 const GList *
|
|
926 gaim_request_field_list_get_items(const GaimRequestField *field)
|
|
927 {
|
|
928 g_return_val_if_fail(field != NULL, NULL);
|
|
929 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_LIST, NULL);
|
|
930
|
|
931 return field->u.list.items;
|
|
932 }
|
|
933
|
|
934 GaimRequestField *
|
|
935 gaim_request_field_label_new(const char *id, const char *text)
|
|
936 {
|
|
937 GaimRequestField *field;
|
|
938
|
|
939 g_return_val_if_fail(id != NULL, NULL);
|
|
940 g_return_val_if_fail(text != NULL, NULL);
|
|
941
|
|
942 field = gaim_request_field_new(id, text, GAIM_REQUEST_FIELD_LABEL);
|
|
943
|
|
944 return field;
|
|
945 }
|
|
946
|
|
947 GaimRequestField *
|
|
948 gaim_request_field_image_new(const char *id, const char *text, const char *buf, gsize size)
|
|
949 {
|
|
950 GaimRequestField *field;
|
|
951
|
|
952 g_return_val_if_fail(id != NULL, NULL);
|
|
953 g_return_val_if_fail(text != NULL, NULL);
|
|
954 g_return_val_if_fail(buf != NULL, NULL);
|
|
955 g_return_val_if_fail(size > 0, NULL);
|
|
956
|
|
957 field = gaim_request_field_new(id, text, GAIM_REQUEST_FIELD_IMAGE);
|
|
958
|
|
959 field->u.image.buffer = g_memdup(buf, size);
|
|
960 field->u.image.size = size;
|
|
961 field->u.image.scale_x = 1;
|
|
962 field->u.image.scale_y = 1;
|
|
963
|
|
964 return field;
|
|
965 }
|
|
966
|
|
967 void
|
|
968 gaim_request_field_image_set_scale(GaimRequestField *field, unsigned int x, unsigned int y)
|
|
969 {
|
|
970 g_return_if_fail(field != NULL);
|
|
971 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_IMAGE);
|
|
972
|
|
973 field->u.image.scale_x = x;
|
|
974 field->u.image.scale_y = y;
|
|
975 }
|
|
976
|
|
977 const char *
|
|
978 gaim_request_field_image_get_buffer(GaimRequestField *field)
|
|
979 {
|
|
980 g_return_val_if_fail(field != NULL, NULL);
|
|
981 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_IMAGE, NULL);
|
|
982
|
|
983 return field->u.image.buffer;
|
|
984 }
|
|
985
|
|
986 gsize
|
|
987 gaim_request_field_image_get_size(GaimRequestField *field)
|
|
988 {
|
|
989 g_return_val_if_fail(field != NULL, 0);
|
|
990 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_IMAGE, 0);
|
|
991
|
|
992 return field->u.image.size;
|
|
993 }
|
|
994
|
|
995 unsigned int
|
|
996 gaim_request_field_image_get_scale_x(GaimRequestField *field)
|
|
997 {
|
|
998 g_return_val_if_fail(field != NULL, 0);
|
|
999 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_IMAGE, 0);
|
|
1000
|
|
1001 return field->u.image.scale_x;
|
|
1002 }
|
|
1003
|
|
1004 unsigned int
|
|
1005 gaim_request_field_image_get_scale_y(GaimRequestField *field)
|
|
1006 {
|
|
1007 g_return_val_if_fail(field != NULL, 0);
|
|
1008 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_IMAGE, 0);
|
|
1009
|
|
1010 return field->u.image.scale_y;
|
|
1011 }
|
|
1012
|
|
1013 GaimRequestField *
|
|
1014 gaim_request_field_account_new(const char *id, const char *text,
|
|
1015 GaimAccount *account)
|
|
1016 {
|
|
1017 GaimRequestField *field;
|
|
1018
|
|
1019 g_return_val_if_fail(id != NULL, NULL);
|
|
1020 g_return_val_if_fail(text != NULL, NULL);
|
|
1021
|
|
1022 field = gaim_request_field_new(id, text, GAIM_REQUEST_FIELD_ACCOUNT);
|
|
1023
|
|
1024 if (account == NULL && gaim_connections_get_all() != NULL)
|
|
1025 {
|
|
1026 account = gaim_connection_get_account(
|
|
1027 (GaimConnection *)gaim_connections_get_all()->data);
|
|
1028 }
|
|
1029
|
|
1030 gaim_request_field_account_set_default_value(field, account);
|
|
1031 gaim_request_field_account_set_value(field, account);
|
|
1032
|
|
1033 return field;
|
|
1034 }
|
|
1035
|
|
1036 void
|
|
1037 gaim_request_field_account_set_default_value(GaimRequestField *field,
|
|
1038 GaimAccount *default_value)
|
|
1039 {
|
|
1040 g_return_if_fail(field != NULL);
|
|
1041 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_ACCOUNT);
|
|
1042
|
|
1043 field->u.account.default_account = default_value;
|
|
1044 }
|
|
1045
|
|
1046 void
|
|
1047 gaim_request_field_account_set_value(GaimRequestField *field,
|
|
1048 GaimAccount *value)
|
|
1049 {
|
|
1050 g_return_if_fail(field != NULL);
|
|
1051 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_ACCOUNT);
|
|
1052
|
|
1053 field->u.account.account = value;
|
|
1054 }
|
|
1055
|
|
1056 void
|
|
1057 gaim_request_field_account_set_show_all(GaimRequestField *field,
|
|
1058 gboolean show_all)
|
|
1059 {
|
|
1060 g_return_if_fail(field != NULL);
|
|
1061 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_ACCOUNT);
|
|
1062
|
|
1063 if (field->u.account.show_all == show_all)
|
|
1064 return;
|
|
1065
|
|
1066 field->u.account.show_all = show_all;
|
|
1067
|
|
1068 if (!show_all)
|
|
1069 {
|
|
1070 if (gaim_account_is_connected(field->u.account.default_account))
|
|
1071 {
|
|
1072 gaim_request_field_account_set_default_value(field,
|
|
1073 (GaimAccount *)gaim_connections_get_all()->data);
|
|
1074 }
|
|
1075
|
|
1076 if (gaim_account_is_connected(field->u.account.account))
|
|
1077 {
|
|
1078 gaim_request_field_account_set_value(field,
|
|
1079 (GaimAccount *)gaim_connections_get_all()->data);
|
|
1080 }
|
|
1081 }
|
|
1082 }
|
|
1083
|
|
1084 void
|
|
1085 gaim_request_field_account_set_filter(GaimRequestField *field,
|
|
1086 GaimFilterAccountFunc filter_func)
|
|
1087 {
|
|
1088 g_return_if_fail(field != NULL);
|
|
1089 g_return_if_fail(field->type == GAIM_REQUEST_FIELD_ACCOUNT);
|
|
1090
|
|
1091 field->u.account.filter_func = filter_func;
|
|
1092 }
|
|
1093
|
|
1094 GaimAccount *
|
|
1095 gaim_request_field_account_get_default_value(const GaimRequestField *field)
|
|
1096 {
|
|
1097 g_return_val_if_fail(field != NULL, NULL);
|
|
1098 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_ACCOUNT, NULL);
|
|
1099
|
|
1100 return field->u.account.default_account;
|
|
1101 }
|
|
1102
|
|
1103 GaimAccount *
|
|
1104 gaim_request_field_account_get_value(const GaimRequestField *field)
|
|
1105 {
|
|
1106 g_return_val_if_fail(field != NULL, NULL);
|
|
1107 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_ACCOUNT, NULL);
|
|
1108
|
|
1109 return field->u.account.account;
|
|
1110 }
|
|
1111
|
|
1112 gboolean
|
|
1113 gaim_request_field_account_get_show_all(const GaimRequestField *field)
|
|
1114 {
|
|
1115 g_return_val_if_fail(field != NULL, FALSE);
|
|
1116 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_ACCOUNT, FALSE);
|
|
1117
|
|
1118 return field->u.account.show_all;
|
|
1119 }
|
|
1120
|
|
1121 GaimFilterAccountFunc
|
|
1122 gaim_request_field_account_get_filter(const GaimRequestField *field)
|
|
1123 {
|
|
1124 g_return_val_if_fail(field != NULL, FALSE);
|
|
1125 g_return_val_if_fail(field->type == GAIM_REQUEST_FIELD_ACCOUNT, FALSE);
|
|
1126
|
|
1127 return field->u.account.filter_func;
|
|
1128 }
|
|
1129
|
|
1130 /* -- */
|
|
1131
|
|
1132 void *
|
|
1133 gaim_request_input(void *handle, const char *title, const char *primary,
|
|
1134 const char *secondary, const char *default_value,
|
|
1135 gboolean multiline, gboolean masked, gchar *hint,
|
|
1136 const char *ok_text, GCallback ok_cb,
|
|
1137 const char *cancel_text, GCallback cancel_cb,
|
|
1138 void *user_data)
|
|
1139 {
|
|
1140 GaimRequestUiOps *ops;
|
|
1141
|
|
1142 g_return_val_if_fail(ok_text != NULL, NULL);
|
|
1143 g_return_val_if_fail(ok_cb != NULL, NULL);
|
|
1144
|
|
1145 ops = gaim_request_get_ui_ops();
|
|
1146
|
|
1147 if (ops != NULL && ops->request_input != NULL) {
|
|
1148 GaimRequestInfo *info;
|
|
1149
|
|
1150 info = g_new0(GaimRequestInfo, 1);
|
|
1151 info->type = GAIM_REQUEST_INPUT;
|
|
1152 info->handle = handle;
|
|
1153 info->ui_handle = ops->request_input(title, primary, secondary,
|
|
1154 default_value,
|
|
1155 multiline, masked, hint,
|
|
1156 ok_text, ok_cb,
|
|
1157 cancel_text, cancel_cb,
|
|
1158 user_data);
|
|
1159
|
|
1160 handles = g_list_append(handles, info);
|
|
1161
|
|
1162 return info->ui_handle;
|
|
1163 }
|
|
1164
|
|
1165 return NULL;
|
|
1166 }
|
|
1167
|
|
1168 void *
|
|
1169 gaim_request_choice(void *handle, const char *title, const char *primary,
|
|
1170 const char *secondary, unsigned int default_value,
|
|
1171 const char *ok_text, GCallback ok_cb,
|
|
1172 const char *cancel_text, GCallback cancel_cb,
|
|
1173 void *user_data, ...)
|
|
1174 {
|
|
1175 void *ui_handle;
|
|
1176 va_list args;
|
|
1177
|
|
1178 g_return_val_if_fail(ok_text != NULL, NULL);
|
|
1179 g_return_val_if_fail(ok_cb != NULL, NULL);
|
|
1180
|
|
1181 va_start(args, user_data);
|
|
1182 ui_handle = gaim_request_choice_varg(handle, title, primary, secondary,
|
|
1183 default_value, ok_text, ok_cb,
|
|
1184 cancel_text, cancel_cb, user_data, args);
|
|
1185 va_end(args);
|
|
1186
|
|
1187 return ui_handle;
|
|
1188 }
|
|
1189
|
|
1190 void *
|
|
1191 gaim_request_choice_varg(void *handle, const char *title,
|
|
1192 const char *primary, const char *secondary,
|
|
1193 unsigned int default_value,
|
|
1194 const char *ok_text, GCallback ok_cb,
|
|
1195 const char *cancel_text, GCallback cancel_cb,
|
|
1196 void *user_data, va_list choices)
|
|
1197 {
|
|
1198 GaimRequestUiOps *ops;
|
|
1199
|
|
1200 g_return_val_if_fail(ok_text != NULL, NULL);
|
|
1201 g_return_val_if_fail(ok_cb != NULL, NULL);
|
|
1202
|
|
1203 ops = gaim_request_get_ui_ops();
|
|
1204
|
|
1205 if (ops != NULL && ops->request_choice != NULL) {
|
|
1206 GaimRequestInfo *info;
|
|
1207
|
|
1208 info = g_new0(GaimRequestInfo, 1);
|
|
1209 info->type = GAIM_REQUEST_CHOICE;
|
|
1210 info->handle = handle;
|
|
1211 info->ui_handle = ops->request_choice(title, primary, secondary,
|
|
1212 default_value,
|
|
1213 ok_text, ok_cb,
|
|
1214 cancel_text, cancel_cb,
|
|
1215 user_data, choices);
|
|
1216
|
|
1217 handles = g_list_append(handles, info);
|
|
1218
|
|
1219 return info->ui_handle;
|
|
1220 }
|
|
1221
|
|
1222 return NULL;
|
|
1223 }
|
|
1224
|
|
1225 void *
|
|
1226 gaim_request_action(void *handle, const char *title, const char *primary,
|
|
1227 const char *secondary, unsigned int default_action,
|
|
1228 void *user_data, size_t action_count, ...)
|
|
1229 {
|
|
1230 void *ui_handle;
|
|
1231 va_list args;
|
|
1232
|
|
1233 g_return_val_if_fail(action_count > 0, NULL);
|
|
1234
|
|
1235 va_start(args, action_count);
|
|
1236 ui_handle = gaim_request_action_varg(handle, title, primary, secondary,
|
|
1237 default_action, user_data,
|
|
1238 action_count, args);
|
|
1239 va_end(args);
|
|
1240
|
|
1241 return ui_handle;
|
|
1242 }
|
|
1243
|
|
1244 void *
|
|
1245 gaim_request_action_varg(void *handle, const char *title,
|
|
1246 const char *primary, const char *secondary,
|
|
1247 unsigned int default_action, void *user_data,
|
|
1248 size_t action_count, va_list actions)
|
|
1249 {
|
|
1250 GaimRequestUiOps *ops;
|
|
1251
|
|
1252 g_return_val_if_fail(action_count > 0, NULL);
|
|
1253
|
|
1254 ops = gaim_request_get_ui_ops();
|
|
1255
|
|
1256 if (ops != NULL && ops->request_action != NULL) {
|
|
1257 GaimRequestInfo *info;
|
|
1258
|
|
1259 info = g_new0(GaimRequestInfo, 1);
|
|
1260 info->type = GAIM_REQUEST_ACTION;
|
|
1261 info->handle = handle;
|
|
1262 info->ui_handle = ops->request_action(title, primary, secondary,
|
|
1263 default_action, user_data,
|
|
1264 action_count, actions);
|
|
1265
|
|
1266 handles = g_list_append(handles, info);
|
|
1267
|
|
1268 return info->ui_handle;
|
|
1269 }
|
|
1270
|
|
1271 return NULL;
|
|
1272 }
|
|
1273
|
|
1274 void *
|
|
1275 gaim_request_fields(void *handle, const char *title, const char *primary,
|
|
1276 const char *secondary, GaimRequestFields *fields,
|
|
1277 const char *ok_text, GCallback ok_cb,
|
|
1278 const char *cancel_text, GCallback cancel_cb,
|
|
1279 void *user_data)
|
|
1280 {
|
|
1281 GaimRequestUiOps *ops;
|
|
1282
|
|
1283 g_return_val_if_fail(fields != NULL, NULL);
|
|
1284 g_return_val_if_fail(ok_text != NULL, NULL);
|
|
1285 g_return_val_if_fail(ok_cb != NULL, NULL);
|
|
1286
|
|
1287 ops = gaim_request_get_ui_ops();
|
|
1288
|
|
1289 if (ops != NULL && ops->request_fields != NULL) {
|
|
1290 GaimRequestInfo *info;
|
|
1291
|
|
1292 info = g_new0(GaimRequestInfo, 1);
|
|
1293 info->type = GAIM_REQUEST_FIELDS;
|
|
1294 info->handle = handle;
|
|
1295 info->ui_handle = ops->request_fields(title, primary, secondary,
|
|
1296 fields, ok_text, ok_cb,
|
|
1297 cancel_text, cancel_cb,
|
|
1298 user_data);
|
|
1299
|
|
1300 handles = g_list_append(handles, info);
|
|
1301
|
|
1302 return info->ui_handle;
|
|
1303 }
|
|
1304
|
|
1305 return NULL;
|
|
1306 }
|
|
1307
|
|
1308 void *
|
|
1309 gaim_request_file(void *handle, const char *title, const char *filename,
|
|
1310 gboolean savedialog,
|
|
1311 GCallback ok_cb, GCallback cancel_cb, void *user_data)
|
|
1312 {
|
|
1313 GaimRequestUiOps *ops;
|
|
1314
|
|
1315 ops = gaim_request_get_ui_ops();
|
|
1316
|
|
1317 if (ops != NULL && ops->request_file != NULL) {
|
|
1318 GaimRequestInfo *info;
|
|
1319
|
|
1320 info = g_new0(GaimRequestInfo, 1);
|
|
1321 info->type = GAIM_REQUEST_FILE;
|
|
1322 info->handle = handle;
|
|
1323 info->ui_handle = ops->request_file(title, filename, savedialog,
|
|
1324 ok_cb, cancel_cb, user_data);
|
|
1325 handles = g_list_append(handles, info);
|
|
1326 return info->ui_handle;
|
|
1327 }
|
|
1328
|
|
1329 return NULL;
|
|
1330 }
|
|
1331
|
|
1332 void *
|
|
1333 gaim_request_folder(void *handle, const char *title, const char *dirname,
|
|
1334 GCallback ok_cb, GCallback cancel_cb, void *user_data)
|
|
1335 {
|
|
1336 GaimRequestUiOps *ops;
|
|
1337
|
|
1338 ops = gaim_request_get_ui_ops();
|
|
1339
|
|
1340 if (ops != NULL && ops->request_file != NULL) {
|
|
1341 GaimRequestInfo *info;
|
|
1342
|
|
1343 info = g_new0(GaimRequestInfo, 1);
|
|
1344 info->type = GAIM_REQUEST_FOLDER;
|
|
1345 info->handle = handle;
|
|
1346 info->ui_handle = ops->request_folder(title, dirname,
|
|
1347 ok_cb, cancel_cb, user_data);
|
|
1348 handles = g_list_append(handles, info);
|
|
1349 return info->ui_handle;
|
|
1350 }
|
|
1351
|
|
1352 return NULL;
|
|
1353 }
|
|
1354
|
|
1355 static void
|
|
1356 gaim_request_close_info(GaimRequestInfo *info)
|
|
1357 {
|
|
1358 GaimRequestUiOps *ops;
|
|
1359
|
|
1360 ops = gaim_request_get_ui_ops();
|
|
1361
|
|
1362 gaim_notify_close_with_handle(info->ui_handle);
|
|
1363 gaim_request_close_with_handle(info->ui_handle);
|
|
1364
|
|
1365 if (ops != NULL && ops->close_request != NULL)
|
|
1366 ops->close_request(info->type, info->ui_handle);
|
|
1367
|
|
1368 g_free(info);
|
|
1369 }
|
|
1370
|
|
1371 void
|
|
1372 gaim_request_close(GaimRequestType type, void *ui_handle)
|
|
1373 {
|
|
1374 GList *l;
|
|
1375
|
|
1376 g_return_if_fail(ui_handle != NULL);
|
|
1377
|
|
1378 for (l = handles; l != NULL; l = l->next) {
|
|
1379 GaimRequestInfo *info = l->data;
|
|
1380
|
|
1381 if (info->ui_handle == ui_handle) {
|
|
1382 handles = g_list_remove(handles, info);
|
|
1383 gaim_request_close_info(info);
|
|
1384 break;
|
|
1385 }
|
|
1386 }
|
|
1387 }
|
|
1388
|
|
1389 void
|
|
1390 gaim_request_close_with_handle(void *handle)
|
|
1391 {
|
|
1392 GList *l, *l_next;
|
|
1393
|
|
1394 g_return_if_fail(handle != NULL);
|
|
1395
|
|
1396 for (l = handles; l != NULL; l = l_next) {
|
|
1397 GaimRequestInfo *info = l->data;
|
|
1398
|
|
1399 l_next = l->next;
|
|
1400
|
|
1401 if (info->handle == handle) {
|
|
1402 handles = g_list_remove(handles, info);
|
|
1403 gaim_request_close_info(info);
|
|
1404 }
|
|
1405 }
|
|
1406 }
|
|
1407
|
|
1408 void
|
|
1409 gaim_request_set_ui_ops(GaimRequestUiOps *ops)
|
|
1410 {
|
|
1411 request_ui_ops = ops;
|
|
1412 }
|
|
1413
|
|
1414 GaimRequestUiOps *
|
|
1415 gaim_request_get_ui_ops(void)
|
|
1416 {
|
|
1417 return request_ui_ops;
|
|
1418 }
|