comparison src/request.h @ 8286:89d9d004e3f3

[gaim-migrate @ 9010] Improved the field request API, adding required fields and account fields, as well as some new utility API functions and bug fixes. These changes allowed me to migrate the New IM dialog over to the field request API, removing a lot of code and improving consistency. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Wed, 18 Feb 2004 07:22:53 +0000
parents d335cc7bca54
children e39ea2b4f6cd
comparison
equal deleted inserted replaced
8285:d335cc7bca54 8286:89d9d004e3f3
26 #define _GAIM_REQUEST_H_ 26 #define _GAIM_REQUEST_H_
27 27
28 #include <stdlib.h> 28 #include <stdlib.h>
29 #include <glib-object.h> 29 #include <glib-object.h>
30 #include <glib.h> 30 #include <glib.h>
31
32 #include "account.h"
31 33
32 /** 34 /**
33 * Request types. 35 * Request types.
34 */ 36 */
35 typedef enum 37 typedef enum
50 GAIM_REQUEST_FIELD_STRING, 52 GAIM_REQUEST_FIELD_STRING,
51 GAIM_REQUEST_FIELD_INTEGER, 53 GAIM_REQUEST_FIELD_INTEGER,
52 GAIM_REQUEST_FIELD_BOOLEAN, 54 GAIM_REQUEST_FIELD_BOOLEAN,
53 GAIM_REQUEST_FIELD_CHOICE, 55 GAIM_REQUEST_FIELD_CHOICE,
54 GAIM_REQUEST_FIELD_LIST, 56 GAIM_REQUEST_FIELD_LIST,
55 GAIM_REQUEST_FIELD_LABEL 57 GAIM_REQUEST_FIELD_LABEL,
58 GAIM_REQUEST_FIELD_ACCOUNT
56 59
57 } GaimRequestFieldType; 60 } GaimRequestFieldType;
61
62 /**
63 * Multiple fields request data.
64 */
65 typedef struct
66 {
67 GList *groups;
68
69 GHashTable *fields;
70
71 GList *required_fields;
72
73 void *ui_data;
74
75 } GaimRequestFields;
76
77 /**
78 * A group of fields with a title.
79 */
80 typedef struct
81 {
82 GaimRequestFields *fields_list;
83
84 char *title;
85
86 GList *fields;
87
88 } GaimRequestFieldGroup;
58 89
59 /** 90 /**
60 * A request field. 91 * A request field.
61 */ 92 */
62 typedef struct 93 typedef struct
63 { 94 {
64 GaimRequestFieldType type; 95 GaimRequestFieldType type;
96 GaimRequestFieldGroup *group;
65 97
66 char *id; 98 char *id;
67 char *label; 99 char *label;
68 char *type_hint; 100 char *type_hint;
69 101
70 gboolean visible; 102 gboolean visible;
103 gboolean required;
71 104
72 union 105 union
73 { 106 {
74 struct 107 struct
75 { 108 {
113 146
114 gboolean multiple_selection; 147 gboolean multiple_selection;
115 148
116 } list; 149 } list;
117 150
151 struct
152 {
153 GaimAccount *default_account;
154 GaimAccount *account;
155 gboolean show_all;
156
157 } account;
158
118 } u; 159 } u;
119 160
120 void *ui_data; 161 void *ui_data;
121 162
122 } GaimRequestField; 163 } GaimRequestField;
123
124 /**
125 * Multiple fields request data.
126 */
127 typedef struct
128 {
129 GList *groups;
130
131 GHashTable *fields;
132
133 } GaimRequestFields;
134
135 /**
136 * A group of fields with a title.
137 */
138 typedef struct
139 {
140 GaimRequestFields *fields_list;
141
142 char *title;
143
144 GList *fields;
145
146 } GaimRequestFieldGroup;
147 164
148 /** 165 /**
149 * Request UI operations. 166 * Request UI operations.
150 */ 167 */
151 typedef struct 168 typedef struct
220 * @return A list of groups. 237 * @return A list of groups.
221 */ 238 */
222 GList *gaim_request_fields_get_groups(const GaimRequestFields *fields); 239 GList *gaim_request_fields_get_groups(const GaimRequestFields *fields);
223 240
224 /** 241 /**
225 * Return the field with the specified ID. 242 * Returns whether or not the field with the specified ID exists.
226 * 243 *
227 * @param fields The fields list. 244 * @param fields The fields list.
228 * @param id The ID of the field. 245 * @param id The ID of the field.
229 * 246 *
247 * @return TRUE if the field exists, or FALSE.
248 */
249 gboolean gaim_request_fields_exists(const GaimRequestFields *fields,
250 const char *id);
251
252 /**
253 * Returns a list of all required fields.
254 *
255 * @param fields The fields list.
256 *
257 * @return The list of required fields.
258 */
259 const GList *gaim_request_fields_get_required(const GaimRequestFields *fields);
260
261 /**
262 * Returns whether or not a field with the specified ID is required.
263 *
264 * @param fields The fields list.
265 * @param id The field ID.
266 *
267 * @return TRUE if the specified field is required, or FALSE.
268 */
269 gboolean gaim_request_fields_is_field_required(const GaimRequestFields *fields,
270 const char *id);
271
272 /**
273 * Returns whether or not all required fields have values.
274 *
275 * @param fields The fields list.
276 *
277 * @return TRUE if all required fields have values, or FALSE.
278 */
279 gboolean gaim_request_fields_all_required_filled(
280 const GaimRequestFields *fields);
281
282 /**
283 * Return the field with the specified ID.
284 *
285 * @param fields The fields list.
286 * @param id The ID of the field.
287 *
230 * @return The field, if found. 288 * @return The field, if found.
231 */ 289 */
232 GaimRequestField *gaim_request_fields_get_field( 290 GaimRequestField *gaim_request_fields_get_field(
233 const GaimRequestFields *fields, const char *id); 291 const GaimRequestFields *fields, const char *id);
234 292
273 * 331 *
274 * @return The choice index, if found, or -1 otherwise. 332 * @return The choice index, if found, or -1 otherwise.
275 */ 333 */
276 int gaim_request_fields_get_choice(const GaimRequestFields *fields, 334 int gaim_request_fields_get_choice(const GaimRequestFields *fields,
277 const char *id); 335 const char *id);
336
337 /**
338 * Returns the account of a field with the specified ID.
339 *
340 * @param fields The fields list.
341 * @param id The ID of the field.
342 *
343 * @return The account value, if found, or NULL otherwise.
344 */
345 GaimAccount *gaim_request_fields_get_account(const GaimRequestFields *fields,
346 const char *id);
278 347
279 /*@}*/ 348 /*@}*/
280 349
281 /**************************************************************************/ 350 /**************************************************************************/
282 /** @name Fields Group API */ 351 /** @name Fields Group API */
381 */ 450 */
382 void gaim_request_field_set_type_hint(GaimRequestField *field, 451 void gaim_request_field_set_type_hint(GaimRequestField *field,
383 const char *type_hint); 452 const char *type_hint);
384 453
385 /** 454 /**
455 * Sets whether or not a field is required.
456 *
457 * @param field The field.
458 * @param required TRUE if required, or FALSE.
459 */
460 void gaim_request_field_set_required(GaimRequestField *field,
461 gboolean required);
462
463 /**
386 * Returns the type of a field. 464 * Returns the type of a field.
387 * 465 *
388 * @param field The field. 466 * @param field The field.
389 * 467 *
390 * @return The field's type. 468 * @return The field's type.
424 * @param field The field. 502 * @param field The field.
425 * 503 *
426 * @return The field's type hint. 504 * @return The field's type hint.
427 */ 505 */
428 const char *gaim_request_field_get_type_hint(const GaimRequestField *field); 506 const char *gaim_request_field_get_type_hint(const GaimRequestField *field);
507
508 /**
509 * Returns whether or not a field is required.
510 *
511 * @param field The field.
512 *
513 * @return TRUE if the fiels is required, or FALSE.
514 */
515 gboolean gaim_request_field_is_required(const GaimRequestField *field);
429 516
430 /*@}*/ 517 /*@}*/
431 518
432 /**************************************************************************/ 519 /**************************************************************************/
433 /** @name String Field API */ 520 /** @name String Field API */
846 933
847 /** 934 /**
848 * Creates a label field. 935 * Creates a label field.
849 * 936 *
850 * @param id The field ID. 937 * @param id The field ID.
851 * @param text The optional label of the field. 938 * @param text The label of the field.
852 * 939 *
853 * @return The new field. 940 * @return The new field.
854 */ 941 */
855 GaimRequestField *gaim_request_field_label_new(const char *id, 942 GaimRequestField *gaim_request_field_label_new(const char *id,
856 const char *text); 943 const char *text);
944
945 /*@}*/
946
947 /**************************************************************************/
948 /** @name Account Field API */
949 /**************************************************************************/
950 /*@{*/
951
952 /**
953 * Creates an account field.
954 *
955 * By default, this field will not show offline accounts.
956 *
957 * @param id The field ID.
958 * @param text The text label of the field.
959 * @param account The optional default account.
960 *
961 * @return The new field.
962 */
963 GaimRequestField *gaim_request_field_account_new(const char *id,
964 const char *text,
965 GaimAccount *account);
966
967 /**
968 * Sets the default account on an account field.
969 *
970 * @param field The account field.
971 * @param default_value The default account.
972 */
973 void gaim_request_field_account_set_default_value(GaimRequestField *field,
974 GaimAccount *default_value);
975
976 /**
977 * Sets the account in an account field.
978 *
979 * @param field The account field.
980 * @param value The account.
981 */
982 void gaim_request_field_account_set_value(GaimRequestField *field,
983 GaimAccount *value);
984
985 /**
986 * Sets whether or not to show all accounts in an account field.
987 *
988 * If TRUE, all accounts, online or offline, will be shown. If FALSE,
989 * only online accounts will be shown.
990 *
991 * @param field The account field.
992 * @param show_all Whether or not to show all accounts.
993 */
994 void gaim_request_field_account_set_show_all(GaimRequestField *field,
995 gboolean show_all);
996
997 /**
998 * Returns the default account in an account field.
999 *
1000 * @param field The field.
1001 *
1002 * @return The default account.
1003 */
1004 GaimAccount *gaim_request_field_account_get_default_value(
1005 const GaimRequestField *field);
1006
1007 /**
1008 * Returns the user-entered account in an account field.
1009 *
1010 * @param field The field.
1011 *
1012 * @return The user-entered account.
1013 */
1014 GaimAccount *gaim_request_field_account_get_value(
1015 const GaimRequestField *field);
1016
1017 /**
1018 * Returns whether or not to show all accounts in an account field.
1019 *
1020 * If TRUE, all accounts, online or offline, will be shown. If FALSE,
1021 * only online accounts will be shown.
1022 *
1023 * @param field The account field.
1024 * @param show_all Whether or not to show all accounts.
1025 */
1026 gboolean gaim_request_field_account_get_show_all(
1027 const GaimRequestField *field);
857 1028
858 /*@}*/ 1029 /*@}*/
859 1030
860 /**************************************************************************/ 1031 /**************************************************************************/
861 /** @name Request API */ 1032 /** @name Request API */