Thu, 22 May 2003 10:22:18 +0000
[gaim-migrate @ 5878]
Added multiline support.
| 5477 | 1 | /** |
| 2 | * @file request.c Request API | |
| 3 | * @ingroup core | |
| 4 | * | |
| 5 | * gaim | |
| 6 | * | |
| 7 | * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
| 8 | * | |
| 9 | * This program is free software; you can redistribute it and/or modify | |
| 10 | * it under the terms of the GNU General Public License as published by | |
| 11 | * the Free Software Foundation; either version 2 of the License, or | |
| 12 | * (at your option) any later version. | |
| 13 | * | |
| 14 | * This program is distributed in the hope that it will be useful, | |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 | * GNU General Public License for more details. | |
| 18 | * | |
| 19 | * You should have received a copy of the GNU General Public License | |
| 20 | * along with this program; if not, write to the Free Software | |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 22 | */ | |
| 23 | #include "request.h" | |
| 24 | ||
| 25 | static GaimRequestUiOps *request_ui_ops = NULL; | |
| 26 | static GList *handles = NULL; | |
| 27 | ||
| 28 | typedef struct | |
| 29 | { | |
| 30 | GaimRequestType type; | |
| 31 | void *handle; | |
| 32 | void *ui_handle; | |
| 33 | ||
| 34 | } GaimRequestInfo; | |
| 35 | ||
| 36 | ||
| 37 | void * | |
| 38 | gaim_request_input(void *handle, const char *title, const char *primary, | |
| 39 | const char *secondary, const char *default_value, | |
|
5482
6831f83bfae5
[gaim-migrate @ 5878]
Christian Hammond <chipx86@chipx86.com>
parents:
5477
diff
changeset
|
40 | gboolean multiline, |
| 5477 | 41 | const char *ok_text, GCallback ok_cb, |
| 42 | const char *cancel_text, GCallback cancel_cb, | |
| 43 | void *user_data) | |
| 44 | { | |
| 45 | GaimRequestUiOps *ops; | |
| 46 | ||
| 47 | g_return_val_if_fail(primary != NULL, NULL); | |
| 48 | g_return_val_if_fail(ok_text != NULL, NULL); | |
| 49 | g_return_val_if_fail(ok_cb != NULL, NULL); | |
| 50 | ||
| 51 | ops = gaim_get_request_ui_ops(); | |
| 52 | ||
| 53 | if (ops != NULL && ops->request_input != NULL) { | |
| 54 | GaimRequestInfo *info; | |
| 55 | ||
| 56 | info = g_new0(GaimRequestInfo, 1); | |
| 57 | info->type = GAIM_REQUEST_INPUT; | |
| 58 | info->handle = handle; | |
| 59 | info->ui_handle = ops->request_input(title, primary, secondary, | |
|
5482
6831f83bfae5
[gaim-migrate @ 5878]
Christian Hammond <chipx86@chipx86.com>
parents:
5477
diff
changeset
|
60 | default_value, multiline, |
|
6831f83bfae5
[gaim-migrate @ 5878]
Christian Hammond <chipx86@chipx86.com>
parents:
5477
diff
changeset
|
61 | ok_text, ok_cb, |
| 5477 | 62 | cancel_text, cancel_cb, |
| 63 | user_data); | |
| 64 | ||
| 65 | handles = g_list_append(handles, info); | |
| 66 | ||
| 67 | return info->ui_handle; | |
| 68 | } | |
| 69 | ||
| 70 | return NULL; | |
| 71 | } | |
| 72 | ||
| 73 | void * | |
| 74 | gaim_request_choice(void *handle, const char *title, const char *primary, | |
| 75 | const char *secondary, unsigned int default_value, | |
| 76 | const char *ok_text, GCallback ok_cb, | |
| 77 | const char *cancel_text, GCallback cancel_cb, | |
| 78 | void *user_data, const char *choice, ...) | |
| 79 | { | |
| 80 | void *ui_handle; | |
| 81 | va_list args; | |
| 82 | ||
| 83 | g_return_val_if_fail(primary != NULL, NULL); | |
| 84 | g_return_val_if_fail(ok_text != NULL, NULL); | |
| 85 | g_return_val_if_fail(ok_cb != NULL, NULL); | |
| 86 | g_return_val_if_fail(choice != NULL, NULL); | |
| 87 | ||
| 88 | va_start(args, choice); | |
| 89 | ui_handle = gaim_request_choice_varg(handle, title, primary, secondary, | |
| 90 | default_value, ok_text, ok_cb, | |
| 91 | cancel_text, cancel_cb, user_data, | |
| 92 | args); | |
| 93 | va_end(args); | |
| 94 | ||
| 95 | return ui_handle; | |
| 96 | } | |
| 97 | ||
| 98 | void * | |
| 99 | gaim_request_choice_varg(void *handle, const char *title, | |
| 100 | const char *primary, const char *secondary, | |
| 101 | unsigned int default_value, | |
| 102 | const char *ok_text, GCallback ok_cb, | |
| 103 | const char *cancel_text, GCallback cancel_cb, | |
| 104 | void *user_data, va_list choices) | |
| 105 | { | |
| 106 | GaimRequestUiOps *ops; | |
| 107 | ||
| 108 | g_return_val_if_fail(primary != NULL, NULL); | |
| 109 | g_return_val_if_fail(ok_text != NULL, NULL); | |
| 110 | g_return_val_if_fail(ok_cb != NULL, NULL); | |
| 111 | ||
| 112 | ops = gaim_get_request_ui_ops(); | |
| 113 | ||
| 114 | if (ops != NULL && ops->request_input != NULL) { | |
| 115 | GaimRequestInfo *info; | |
| 116 | ||
| 117 | info = g_new0(GaimRequestInfo, 1); | |
| 118 | info->type = GAIM_REQUEST_CHOICE; | |
| 119 | info->handle = handle; | |
| 120 | info->ui_handle = ops->request_choice(title, primary, secondary, | |
|
5482
6831f83bfae5
[gaim-migrate @ 5878]
Christian Hammond <chipx86@chipx86.com>
parents:
5477
diff
changeset
|
121 | default_value, |
|
6831f83bfae5
[gaim-migrate @ 5878]
Christian Hammond <chipx86@chipx86.com>
parents:
5477
diff
changeset
|
122 | ok_text, ok_cb, |
| 5477 | 123 | cancel_text, cancel_cb, |
| 124 | user_data, choices); | |
| 125 | ||
| 126 | handles = g_list_append(handles, info); | |
| 127 | ||
| 128 | return info->ui_handle; | |
| 129 | } | |
| 130 | ||
| 131 | return NULL; | |
| 132 | } | |
| 133 | ||
| 134 | void * | |
| 135 | gaim_request_action(void *handle, const char *title, const char *primary, | |
| 136 | const char *secondary, unsigned int default_action, | |
| 137 | void *user_data, const char *action, ...) | |
| 138 | { | |
| 139 | void *ui_handle; | |
| 140 | va_list args; | |
| 141 | ||
| 142 | g_return_val_if_fail(primary != NULL, NULL); | |
| 143 | g_return_val_if_fail(action != NULL, NULL); | |
| 144 | ||
| 145 | va_start(args, action); | |
| 146 | ui_handle = gaim_request_action_varg(handle, title, primary, secondary, | |
| 147 | default_action, user_data, args); | |
| 148 | va_end(args); | |
| 149 | ||
| 150 | return ui_handle; | |
| 151 | } | |
| 152 | ||
| 153 | void * | |
| 154 | gaim_request_action_varg(void *handle, const char *title, | |
| 155 | const char *primary, const char *secondary, | |
| 156 | unsigned int default_action, void *user_data, | |
| 157 | va_list actions) | |
| 158 | { | |
| 159 | GaimRequestUiOps *ops; | |
| 160 | ||
| 161 | g_return_val_if_fail(primary != NULL, NULL); | |
| 162 | ||
| 163 | ops = gaim_get_request_ui_ops(); | |
| 164 | ||
| 165 | if (ops != NULL && ops->request_input != NULL) { | |
| 166 | GaimRequestInfo *info; | |
| 167 | ||
| 168 | info = g_new0(GaimRequestInfo, 1); | |
| 169 | info->type = GAIM_REQUEST_ACTION; | |
| 170 | info->handle = handle; | |
| 171 | info->ui_handle = ops->request_action(title, primary, secondary, | |
| 172 | default_action, user_data, | |
| 173 | actions); | |
| 174 | ||
| 175 | handles = g_list_append(handles, info); | |
| 176 | ||
| 177 | return info->ui_handle; | |
| 178 | } | |
| 179 | ||
| 180 | return NULL; | |
| 181 | } | |
| 182 | ||
| 183 | void | |
| 184 | gaim_request_close(GaimRequestType type, void *ui_handle) | |
| 185 | { | |
| 186 | GList *l; | |
| 187 | GaimRequestUiOps *ops; | |
| 188 | ||
| 189 | g_return_if_fail(ui_handle != NULL); | |
| 190 | ||
| 191 | ops = gaim_get_request_ui_ops(); | |
| 192 | ||
| 193 | for (l = handles; l != NULL; l = l->next) { | |
| 194 | GaimRequestInfo *info = l->data; | |
| 195 | ||
| 196 | if (info->ui_handle == ui_handle) { | |
| 197 | handles = g_list_remove(handles, info); | |
| 198 | ||
| 199 | if (ops != NULL && ops->close_request != NULL) | |
| 200 | ops->close_request(info->type, ui_handle); | |
| 201 | ||
| 202 | g_free(info); | |
| 203 | ||
| 204 | break; | |
| 205 | } | |
| 206 | } | |
| 207 | } | |
| 208 | ||
| 209 | void | |
| 210 | gaim_request_close_with_handle(void *handle) | |
| 211 | { | |
| 212 | GList *l, *l_next; | |
| 213 | GaimRequestUiOps *ops; | |
| 214 | ||
| 215 | g_return_if_fail(handle != NULL); | |
| 216 | ||
| 217 | ops = gaim_get_request_ui_ops(); | |
| 218 | ||
| 219 | for (l = handles; l != NULL; l = l_next) { | |
| 220 | GaimRequestInfo *info = l->data; | |
| 221 | ||
| 222 | l_next = l->next; | |
| 223 | ||
| 224 | if (info->handle == handle) { | |
| 225 | handles = g_list_remove(handles, info); | |
| 226 | ||
| 227 | if (ops != NULL && ops->close_request != NULL) | |
| 228 | ops->close_request(info->type, info->ui_handle); | |
| 229 | ||
| 230 | g_free(info); | |
| 231 | } | |
| 232 | } | |
| 233 | } | |
| 234 | ||
| 235 | void | |
| 236 | gaim_set_request_ui_ops(GaimRequestUiOps *ops) | |
| 237 | { | |
| 238 | request_ui_ops = ops; | |
| 239 | } | |
| 240 | ||
| 241 | GaimRequestUiOps * | |
| 242 | gaim_get_request_ui_ops(void) | |
| 243 | { | |
| 244 | return request_ui_ops; | |
| 245 | } | |
| 246 | ||
| 247 |