Mercurial > pidgin
comparison src/request.h @ 5807:11001789cb22
[gaim-migrate @ 6237]
Added a multi-field request API. Haven't tested it yet, or written a UI
implementation, so parts may change.
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Sun, 08 Jun 2003 04:06:21 +0000 |
| parents | cce2d7868c78 |
| children | 133e86584f4b |
comparison
equal
deleted
inserted
replaced
| 5806:a997762fbaeb | 5807:11001789cb22 |
|---|---|
| 32 */ | 32 */ |
| 33 typedef enum | 33 typedef enum |
| 34 { | 34 { |
| 35 GAIM_REQUEST_INPUT = 0, /**< Text input request. */ | 35 GAIM_REQUEST_INPUT = 0, /**< Text input request. */ |
| 36 GAIM_REQUEST_CHOICE, /**< Multiple-choice request. */ | 36 GAIM_REQUEST_CHOICE, /**< Multiple-choice request. */ |
| 37 GAIM_REQUEST_ACTION /**< Action request. */ | 37 GAIM_REQUEST_ACTION, /**< Action request. */ |
| 38 GAIM_REQUEST_FIELDS /**< Multiple fields request. */ | |
| 38 | 39 |
| 39 } GaimRequestType; | 40 } GaimRequestType; |
| 41 | |
| 42 /** | |
| 43 * A type of field. | |
| 44 */ | |
| 45 typedef enum | |
| 46 { | |
| 47 GAIM_REQUEST_FIELD_NONE, | |
| 48 GAIM_REQUEST_FIELD_STRING, | |
| 49 GAIM_REQUEST_FIELD_INTEGER, | |
| 50 GAIM_REQUEST_FIELD_BOOLEAN, | |
| 51 GAIM_REQUEST_FIELD_CHOICE | |
| 52 | |
| 53 } GaimRequestFieldType; | |
| 54 | |
| 55 /** | |
| 56 * A request field. | |
| 57 */ | |
| 58 typedef struct | |
| 59 { | |
| 60 GaimRequestFieldType type; | |
| 61 | |
| 62 char *id; | |
| 63 char *label; | |
| 64 | |
| 65 union | |
| 66 { | |
| 67 struct | |
| 68 { | |
| 69 gboolean multiline; | |
| 70 char *default_value; | |
| 71 char *value; | |
| 72 | |
| 73 } string; | |
| 74 | |
| 75 struct | |
| 76 { | |
| 77 int default_value; | |
| 78 int value; | |
| 79 | |
| 80 } integer; | |
| 81 | |
| 82 struct | |
| 83 { | |
| 84 gboolean default_value; | |
| 85 gboolean value; | |
| 86 | |
| 87 } boolean; | |
| 88 | |
| 89 struct | |
| 90 { | |
| 91 int default_value; | |
| 92 int value; | |
| 93 | |
| 94 GList *labels; | |
| 95 | |
| 96 } choice; | |
| 97 | |
| 98 } u; | |
| 99 | |
| 100 } GaimRequestField; | |
| 101 | |
| 102 /** | |
| 103 * Multiple fields request data. | |
| 104 */ | |
| 105 typedef struct | |
| 106 { | |
| 107 GList *groups; | |
| 108 | |
| 109 GHashTable *fields; | |
| 110 | |
| 111 } GaimRequestFields; | |
| 112 | |
| 113 /** | |
| 114 * A group of fields with a title. | |
| 115 */ | |
| 116 typedef struct | |
| 117 { | |
| 118 GaimRequestFields *fields_list; | |
| 119 | |
| 120 char *title; | |
| 121 | |
| 122 GList *fields; | |
| 123 | |
| 124 } GaimRequestFieldGroup; | |
| 40 | 125 |
| 41 /** | 126 /** |
| 42 * Request UI operations. | 127 * Request UI operations. |
| 43 */ | 128 */ |
| 44 typedef struct | 129 typedef struct |
| 57 va_list choices); | 142 va_list choices); |
| 58 void *(*request_action)(const char *title, const char *primary, | 143 void *(*request_action)(const char *title, const char *primary, |
| 59 const char *secondary, unsigned int default_action, | 144 const char *secondary, unsigned int default_action, |
| 60 void *user_data, size_t action_count, | 145 void *user_data, size_t action_count, |
| 61 va_list actions); | 146 va_list actions); |
| 147 void *(*request_fields)(const char *title, const char *primary, | |
| 148 const char *secondary, GaimRequestFields *fields, | |
| 149 const char *ok_text, GCallback ok_cb, | |
| 150 const char *cancel_text, GCallback cancel_cb, | |
| 151 void *user_data); | |
| 62 | 152 |
| 63 void (*close_request)(GaimRequestType type, void *ui_handle); | 153 void (*close_request)(GaimRequestType type, void *ui_handle); |
| 64 | 154 |
| 65 } GaimRequestUiOps; | 155 } GaimRequestUiOps; |
| 66 | 156 |
| 67 typedef void (*GaimRequestInputCb)(void *, const char *); | 157 typedef void (*GaimRequestInputCb)(void *, const char *); |
| 68 typedef void (*GaimRequestActionCb)(void *, int); | 158 typedef void (*GaimRequestActionCb)(void *, int); |
| 159 typedef void (*GaimRequestFieldsCb)(void *, GaimRequestFields *fields); | |
| 160 | |
| 161 /**************************************************************************/ | |
| 162 /** @name Field List API */ | |
| 163 /**************************************************************************/ | |
| 164 /*@{*/ | |
| 165 | |
| 166 /** | |
| 167 * Creates a list of fields to pass to gaim_request_fields(). | |
| 168 * | |
| 169 * @return A GaimRequestFields structure. | |
| 170 */ | |
| 171 GaimRequestFields *gaim_request_fields_new(void); | |
| 172 | |
| 173 /** | |
| 174 * Destroys a list of fields. | |
| 175 * | |
| 176 * @param fields The list of fields to destroy. | |
| 177 */ | |
| 178 void gaim_request_fields_destroy(GaimRequestFields *fields); | |
| 179 | |
| 180 /** | |
| 181 * Adds a group of fields to the list. | |
| 182 * | |
| 183 * @param fields The fields list. | |
| 184 * @param group The group to add. | |
| 185 */ | |
| 186 void gaim_request_fields_add_group(GaimRequestFields *fields, | |
| 187 GaimRequestFieldGroup *group); | |
| 188 | |
| 189 /** | |
| 190 * Returns a list of all groups in a field list. | |
| 191 * | |
| 192 * @param fields The fields list. | |
| 193 * | |
| 194 * @return A list of groups. | |
| 195 */ | |
| 196 GList *gaim_request_fields_get_groups(const GaimRequestFields *fields); | |
| 197 | |
| 198 /** | |
| 199 * Return the field with the specified ID. | |
| 200 * | |
| 201 * @param fields The fields list. | |
| 202 * @param id The ID of the field. | |
| 203 * | |
| 204 * @return The field, if found. | |
| 205 */ | |
| 206 GaimRequestField *gaim_request_fields_get_field( | |
| 207 const GaimRequestFields *fields, const char *id); | |
| 208 | |
| 209 /** | |
| 210 * Returns the string value of a field with the specified ID. | |
| 211 * | |
| 212 * @param fields The fields list. | |
| 213 * @param id The ID of the field. | |
| 214 * | |
| 215 * @return The string value, if found, or @c NULL otherwise. | |
| 216 */ | |
| 217 const char *gaim_request_fields_get_string(const GaimRequestFields *fields, | |
| 218 const char *id); | |
| 219 | |
| 220 /** | |
| 221 * Returns the integer value of a field with the specified ID. | |
| 222 * | |
| 223 * @param fields The fields list. | |
| 224 * @param id The ID of the field. | |
| 225 * | |
| 226 * @return The integer value, if found, or 0 otherwise. | |
| 227 */ | |
| 228 int gaim_request_fields_get_integer(const GaimRequestFields *fields, | |
| 229 const char *id); | |
| 230 | |
| 231 /** | |
| 232 * Returns the boolean value of a field with the specified ID. | |
| 233 * | |
| 234 * @param fields The fields list. | |
| 235 * @param id The ID of the field. | |
| 236 * | |
| 237 * @return The boolean value, if found, or @c FALSE otherwise. | |
| 238 */ | |
| 239 gboolean gaim_request_fields_get_bool(const GaimRequestFields *fields, | |
| 240 const char *id); | |
| 241 | |
| 242 /** | |
| 243 * Returns the choice index of a field with the specified ID. | |
| 244 * | |
| 245 * @param fields The fields list. | |
| 246 * @param id The ID of the field. | |
| 247 * | |
| 248 * @return The choice index, if found, or -1 otherwise. | |
| 249 */ | |
| 250 int gaim_request_fields_get_choice(const GaimRequestFields *fields, | |
| 251 const char *id); | |
| 252 | |
| 253 /*@}*/ | |
| 254 | |
| 255 /**************************************************************************/ | |
| 256 /** @name Fields Group API */ | |
| 257 /**************************************************************************/ | |
| 258 /*@{*/ | |
| 259 | |
| 260 /** | |
| 261 * Creates a fields group with an optional title. | |
| 262 * | |
| 263 * @param title The optional title to give the group. | |
| 264 * | |
| 265 * @return A new fields group | |
| 266 */ | |
| 267 GaimRequestFieldGroup *gaim_request_field_group_new(const char *title); | |
| 268 | |
| 269 /** | |
| 270 * Destroys a fields group. | |
| 271 * | |
| 272 * @param group The group to destroy. | |
| 273 */ | |
| 274 void gaim_request_field_group_destroy(GaimRequestFieldGroup *group); | |
| 275 | |
| 276 /** | |
| 277 * Adds a field to the group. | |
| 278 * | |
| 279 * @param group The group to add the field to. | |
| 280 * @param field The field to add to the group. | |
| 281 */ | |
| 282 void gaim_request_field_group_add_field(GaimRequestFieldGroup *group, | |
| 283 GaimRequestField *field); | |
| 284 | |
| 285 /** | |
| 286 * Returns the title of a fields group. | |
| 287 * | |
| 288 * @param group The group. | |
| 289 * | |
| 290 * @return The title, if set. | |
| 291 */ | |
| 292 const char *gaim_request_field_group_get_title( | |
| 293 const GaimRequestFieldGroup *group); | |
| 294 | |
| 295 /** | |
| 296 * Returns a list of all fields in a group. | |
| 297 * | |
| 298 * @param group The group. | |
| 299 * | |
| 300 * @return The list of fields in the group. | |
| 301 */ | |
| 302 GList *gaim_request_field_group_get_fields( | |
| 303 const GaimRequestFieldGroup *group); | |
| 304 | |
| 305 /*@}*/ | |
| 306 | |
| 307 /**************************************************************************/ | |
| 308 /** @name Field API */ | |
| 309 /**************************************************************************/ | |
| 310 /*@{*/ | |
| 311 | |
| 312 /** | |
| 313 * Creates a field of the specified type. | |
| 314 * | |
| 315 * @param id The field ID. | |
| 316 * @param text The text label of the field. | |
| 317 * @param type The type of field. | |
| 318 * | |
| 319 * @return The new field. | |
| 320 */ | |
| 321 GaimRequestField *gaim_request_field_new(const char *id, const char *text, | |
| 322 GaimRequestFieldType type); | |
| 323 | |
| 324 /** | |
| 325 * Destroys a field. | |
| 326 * | |
| 327 * @param field The field to destroy. | |
| 328 */ | |
| 329 void gaim_request_field_destroy(GaimRequestField *field); | |
| 330 | |
| 331 /** | |
| 332 * Sets the label text of a field. | |
| 333 * | |
| 334 * @param field The field. | |
| 335 * @param label The text label. | |
| 336 */ | |
| 337 void gaim_request_field_set_label(GaimRequestField *field, const char *label); | |
| 338 | |
| 339 /** | |
| 340 * Returns the type of a field. | |
| 341 * | |
| 342 * @param field The field. | |
| 343 * | |
| 344 * @return The field's type. | |
| 345 */ | |
| 346 GaimRequestFieldType gaim_request_field_get_type(const GaimRequestField *field); | |
| 347 | |
| 348 /** | |
| 349 * Returns the ID of a field. | |
| 350 * | |
| 351 * @param field The field. | |
| 352 * | |
| 353 * @return The ID | |
| 354 */ | |
| 355 const char *gaim_request_field_get_id(const GaimRequestField *field); | |
| 356 | |
| 357 /** | |
| 358 * Returns the label text of a field. | |
| 359 * | |
| 360 * @param field The field. | |
| 361 * | |
| 362 * @return The label text. | |
| 363 */ | |
| 364 const char *gaim_request_field_get_label(const GaimRequestField *field); | |
| 365 | |
| 366 /*@}*/ | |
| 367 | |
| 368 /**************************************************************************/ | |
| 369 /** @name String Field API */ | |
| 370 /**************************************************************************/ | |
| 371 /*@{*/ | |
| 372 | |
| 373 /** | |
| 374 * Creates a string request field. | |
| 375 * | |
| 376 * @param id The field ID. | |
| 377 * @param text The text label of the field. | |
| 378 * @param default_value The optional default value. | |
| 379 * @param multiline Whether or not this should be a multiline string. | |
| 380 * | |
| 381 * @return The new field. | |
| 382 */ | |
| 383 GaimRequestField *gaim_request_field_string_new(const char *id, | |
| 384 const char *text, | |
| 385 const char *default_value, | |
| 386 gboolean multiline); | |
| 387 | |
| 388 /** | |
| 389 * Sets the default value in a string field. | |
| 390 * | |
| 391 * @param field The field. | |
| 392 * @param value The default value. | |
| 393 */ | |
| 394 void gaim_request_field_string_set_default_value(GaimRequestField *field, | |
| 395 const char *default_value); | |
| 396 | |
| 397 /** | |
| 398 * Returns the default value in a string field. | |
| 399 * | |
| 400 * @param field The field. | |
| 401 * | |
| 402 * @return The default value. | |
| 403 */ | |
| 404 const char *gaim_request_field_string_get_default_value( | |
| 405 const GaimRequestField *field); | |
| 406 | |
| 407 /** | |
| 408 * Returns the user-entered value in a string field. | |
| 409 * | |
| 410 * @param field The field. | |
| 411 * | |
| 412 * @return The value. | |
| 413 */ | |
| 414 const char *gaim_request_field_string_get_value(const GaimRequestField *field); | |
| 415 | |
| 416 /** | |
| 417 * Returns whether or not a string field is multi-line. | |
| 418 * | |
| 419 * @param field The field. | |
| 420 * | |
| 421 * @return @c TRUE if the field is mulit-line, or @c FALSE otherwise. | |
| 422 */ | |
| 423 gboolean gaim_request_field_string_is_multiline(const GaimRequestField *field); | |
| 424 | |
| 425 /*@}*/ | |
| 426 | |
| 427 /**************************************************************************/ | |
| 428 /** @name Integer Field API */ | |
| 429 /**************************************************************************/ | |
| 430 /*@{*/ | |
| 431 | |
| 432 /** | |
| 433 * Creates an integer field. | |
| 434 * | |
| 435 * @param id The field ID. | |
| 436 * @param text The text label of the field. | |
| 437 * @param default_value The default value. | |
| 438 * | |
| 439 * @return The new field. | |
| 440 */ | |
| 441 GaimRequestField *gaim_request_field_int_new(const char *id, | |
| 442 const char *text, | |
| 443 int default_value); | |
| 444 | |
| 445 /** | |
| 446 * Sets the default value in an integer field. | |
| 447 * | |
| 448 * @param field The field. | |
| 449 * @param value The default value. | |
| 450 */ | |
| 451 void gaim_request_field_int_set_default_value(GaimRequestField *field, | |
| 452 int default_value); | |
| 453 | |
| 454 /** | |
| 455 * Returns the default value in an integer field. | |
| 456 * | |
| 457 * @param field The field. | |
| 458 * | |
| 459 * @return The default value. | |
| 460 */ | |
| 461 int gaim_request_field_int_get_default_value(const GaimRequestField *field); | |
| 462 | |
| 463 /** | |
| 464 * Returns the user-entered value in an integer field. | |
| 465 * | |
| 466 * @param field The field. | |
| 467 * | |
| 468 * @return The value. | |
| 469 */ | |
| 470 int gaim_request_field_int_get_value(const GaimRequestField *field); | |
| 471 | |
| 472 /*@}*/ | |
| 473 | |
| 474 /**************************************************************************/ | |
| 475 /** @name Boolean Field API */ | |
| 476 /**************************************************************************/ | |
| 477 /*@{*/ | |
| 478 | |
| 479 /** | |
| 480 * Creates a boolean field. | |
| 481 * | |
| 482 * This is often represented as a checkbox. | |
| 483 * | |
| 484 * @param id The field ID. | |
| 485 * @param text The text label of the field. | |
| 486 * @param default_value The default value. | |
| 487 * | |
| 488 * @return The new field. | |
| 489 */ | |
| 490 GaimRequestField *gaim_request_field_bool_new(const char *id, | |
| 491 const char *text, | |
| 492 gboolean default_value); | |
| 493 | |
| 494 /** | |
| 495 * Sets the default value in an boolean field. | |
| 496 * | |
| 497 * @param field The field. | |
| 498 * @param value The default value. | |
| 499 */ | |
| 500 void gaim_request_field_bool_set_default_value(GaimRequestField *field, | |
| 501 gboolean default_value); | |
| 502 | |
| 503 /** | |
| 504 * Returns the default value in an boolean field. | |
| 505 * | |
| 506 * @param field The field. | |
| 507 * | |
| 508 * @return The default value. | |
| 509 */ | |
| 510 gboolean gaim_request_field_bool_get_default_value( | |
| 511 const GaimRequestField *field); | |
| 512 | |
| 513 /** | |
| 514 * Returns the user-entered value in an boolean field. | |
| 515 * | |
| 516 * @param field The field. | |
| 517 * | |
| 518 * @return The value. | |
| 519 */ | |
| 520 gboolean gaim_request_field_bool_get_value(const GaimRequestField *field); | |
| 521 | |
| 522 /*@}*/ | |
| 523 | |
| 524 /**************************************************************************/ | |
| 525 /** @name Choice Field API */ | |
| 526 /**************************************************************************/ | |
| 527 /*@{*/ | |
| 528 | |
| 529 /** | |
| 530 * Creates a multiple choice field. | |
| 531 * | |
| 532 * This is often represented as a group of radio buttons. | |
| 533 * | |
| 534 * @param id The field ID. | |
| 535 * @param text The optional label of the field. | |
| 536 * @param default_value The default choice. | |
| 537 * | |
| 538 * @return The new field. | |
| 539 */ | |
| 540 GaimRequestField *gaim_request_field_choice_new(const char *id, | |
| 541 const char *text, | |
| 542 int default_value); | |
| 543 | |
| 544 /** | |
| 545 * Adds a choice to a multiple choice field. | |
| 546 * | |
| 547 * @param field The choice field. | |
| 548 * @param label The choice label. | |
| 549 */ | |
| 550 void gaim_request_field_choice_add(GaimRequestField *field, | |
| 551 const char *label); | |
| 552 | |
| 553 /** | |
| 554 * Sets the default value in an choice field. | |
| 555 * | |
| 556 * @param field The field. | |
| 557 * @param value The default value. | |
| 558 */ | |
| 559 void gaim_request_field_choice_set_default_value(GaimRequestField *field, | |
| 560 int default_value); | |
| 561 | |
| 562 /** | |
| 563 * Returns the default value in an choice field. | |
| 564 * | |
| 565 * @param field The field. | |
| 566 * | |
| 567 * @return The default value. | |
| 568 */ | |
| 569 int gaim_request_field_choice_get_default_value(const GaimRequestField *field); | |
| 570 | |
| 571 /** | |
| 572 * Returns the user-entered value in an choice field. | |
| 573 * | |
| 574 * @param field The field. | |
| 575 * | |
| 576 * @return The value. | |
| 577 */ | |
| 578 int gaim_request_field_choice_get_value(const GaimRequestField *field); | |
| 579 | |
| 580 /*@}*/ | |
| 69 | 581 |
| 70 /**************************************************************************/ | 582 /**************************************************************************/ |
| 71 /** @name Request API */ | 583 /** @name Request API */ |
| 72 /**************************************************************************/ | 584 /**************************************************************************/ |
| 73 /*@{*/ | 585 /*@{*/ |
| 189 unsigned int default_action, | 701 unsigned int default_action, |
| 190 void *user_data, size_t action_count, | 702 void *user_data, size_t action_count, |
| 191 va_list actions); | 703 va_list actions); |
| 192 | 704 |
| 193 /** | 705 /** |
| 706 * Displays groups of fields for the user to fill in. | |
| 707 * | |
| 708 * @param handle The plugin or connection handle. | |
| 709 * @param title The title of the message. | |
| 710 * @param primary The main point of the message. | |
| 711 * @param secondary The secondary information. | |
| 712 * @param fields The list of fields. | |
| 713 * @param ok_text The text for the OK button. | |
| 714 * @param ok_cb The callback for the OK button. | |
| 715 * @param cancel_text The text for the cancel button. | |
| 716 * @param cancel_cb The callback for the cancel button. | |
| 717 * @param user_data The data to pass to the callback. | |
| 718 * | |
| 719 * @return A UI-specific handle. | |
| 720 */ | |
| 721 void *gaim_request_fields(void *handle, const char *title, | |
| 722 const char *primary, const char *secondary, | |
| 723 GaimRequestFields *fields, | |
| 724 const char *ok_text, GCallback ok_cb, | |
| 725 const char *cancel_text, GCallback cancel_cb, | |
| 726 void *user_data); | |
| 727 | |
| 728 /** | |
| 194 * Closes a request. | 729 * Closes a request. |
| 195 * | 730 * |
| 196 * This should be used only by the UI operation functions and part of the | 731 * This should be used only by the UI operation functions and part of the |
| 197 * core. | 732 * core. |
| 198 * | 733 * |
