Mercurial > pidgin
comparison src/request.c @ 5477:e8e498255369
[gaim-migrate @ 5873]
The beginnings of the request API.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Thu, 22 May 2003 05:36:47 +0000 |
parents | |
children | a41149ee8a29 |
comparison
equal
deleted
inserted
replaced
5476:9bcd8cd625ae | 5477:e8e498255369 |
---|---|
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, | |
40 const char *ok_text, GCallback ok_cb, | |
41 const char *cancel_text, GCallback cancel_cb, | |
42 void *user_data) | |
43 { | |
44 GaimRequestUiOps *ops; | |
45 | |
46 g_return_val_if_fail(primary != NULL, NULL); | |
47 g_return_val_if_fail(ok_text != NULL, NULL); | |
48 g_return_val_if_fail(ok_cb != NULL, NULL); | |
49 | |
50 ops = gaim_get_request_ui_ops(); | |
51 | |
52 if (ops != NULL && ops->request_input != NULL) { | |
53 GaimRequestInfo *info; | |
54 | |
55 info = g_new0(GaimRequestInfo, 1); | |
56 info->type = GAIM_REQUEST_INPUT; | |
57 info->handle = handle; | |
58 info->ui_handle = ops->request_input(title, primary, secondary, | |
59 default_value, ok_text, ok_cb, | |
60 cancel_text, cancel_cb, | |
61 user_data); | |
62 | |
63 handles = g_list_append(handles, info); | |
64 | |
65 return info->ui_handle; | |
66 } | |
67 | |
68 return NULL; | |
69 } | |
70 | |
71 void * | |
72 gaim_request_choice(void *handle, const char *title, const char *primary, | |
73 const char *secondary, unsigned int default_value, | |
74 const char *ok_text, GCallback ok_cb, | |
75 const char *cancel_text, GCallback cancel_cb, | |
76 void *user_data, const char *choice, ...) | |
77 { | |
78 void *ui_handle; | |
79 va_list args; | |
80 | |
81 g_return_val_if_fail(primary != NULL, NULL); | |
82 g_return_val_if_fail(ok_text != NULL, NULL); | |
83 g_return_val_if_fail(ok_cb != NULL, NULL); | |
84 g_return_val_if_fail(choice != NULL, NULL); | |
85 | |
86 va_start(args, choice); | |
87 ui_handle = gaim_request_choice_varg(handle, title, primary, secondary, | |
88 default_value, ok_text, ok_cb, | |
89 cancel_text, cancel_cb, user_data, | |
90 args); | |
91 va_end(args); | |
92 | |
93 return ui_handle; | |
94 } | |
95 | |
96 void * | |
97 gaim_request_choice_varg(void *handle, const char *title, | |
98 const char *primary, const char *secondary, | |
99 unsigned int default_value, | |
100 const char *ok_text, GCallback ok_cb, | |
101 const char *cancel_text, GCallback cancel_cb, | |
102 void *user_data, va_list choices) | |
103 { | |
104 GaimRequestUiOps *ops; | |
105 | |
106 g_return_val_if_fail(primary != NULL, NULL); | |
107 g_return_val_if_fail(ok_text != NULL, NULL); | |
108 g_return_val_if_fail(ok_cb != NULL, NULL); | |
109 | |
110 ops = gaim_get_request_ui_ops(); | |
111 | |
112 if (ops != NULL && ops->request_input != NULL) { | |
113 GaimRequestInfo *info; | |
114 | |
115 info = g_new0(GaimRequestInfo, 1); | |
116 info->type = GAIM_REQUEST_CHOICE; | |
117 info->handle = handle; | |
118 info->ui_handle = ops->request_choice(title, primary, secondary, | |
119 default_value, ok_text, ok_cb, | |
120 cancel_text, cancel_cb, | |
121 user_data, choices); | |
122 | |
123 handles = g_list_append(handles, info); | |
124 | |
125 return info->ui_handle; | |
126 } | |
127 | |
128 return NULL; | |
129 } | |
130 | |
131 void * | |
132 gaim_request_action(void *handle, const char *title, const char *primary, | |
133 const char *secondary, unsigned int default_action, | |
134 void *user_data, const char *action, ...) | |
135 { | |
136 void *ui_handle; | |
137 va_list args; | |
138 | |
139 g_return_val_if_fail(primary != NULL, NULL); | |
140 g_return_val_if_fail(action != NULL, NULL); | |
141 | |
142 va_start(args, action); | |
143 ui_handle = gaim_request_action_varg(handle, title, primary, secondary, | |
144 default_action, user_data, args); | |
145 va_end(args); | |
146 | |
147 return ui_handle; | |
148 } | |
149 | |
150 void * | |
151 gaim_request_action_varg(void *handle, const char *title, | |
152 const char *primary, const char *secondary, | |
153 unsigned int default_action, void *user_data, | |
154 va_list actions) | |
155 { | |
156 GaimRequestUiOps *ops; | |
157 | |
158 g_return_val_if_fail(primary != NULL, NULL); | |
159 | |
160 ops = gaim_get_request_ui_ops(); | |
161 | |
162 if (ops != NULL && ops->request_input != NULL) { | |
163 GaimRequestInfo *info; | |
164 | |
165 info = g_new0(GaimRequestInfo, 1); | |
166 info->type = GAIM_REQUEST_ACTION; | |
167 info->handle = handle; | |
168 info->ui_handle = ops->request_action(title, primary, secondary, | |
169 default_action, user_data, | |
170 actions); | |
171 | |
172 handles = g_list_append(handles, info); | |
173 | |
174 return info->ui_handle; | |
175 } | |
176 | |
177 return NULL; | |
178 } | |
179 | |
180 void | |
181 gaim_request_close(GaimRequestType type, void *ui_handle) | |
182 { | |
183 GList *l; | |
184 GaimRequestUiOps *ops; | |
185 | |
186 g_return_if_fail(ui_handle != NULL); | |
187 | |
188 ops = gaim_get_request_ui_ops(); | |
189 | |
190 for (l = handles; l != NULL; l = l->next) { | |
191 GaimRequestInfo *info = l->data; | |
192 | |
193 if (info->ui_handle == ui_handle) { | |
194 handles = g_list_remove(handles, info); | |
195 | |
196 if (ops != NULL && ops->close_request != NULL) | |
197 ops->close_request(info->type, ui_handle); | |
198 | |
199 g_free(info); | |
200 | |
201 break; | |
202 } | |
203 } | |
204 } | |
205 | |
206 void | |
207 gaim_request_close_with_handle(void *handle) | |
208 { | |
209 GList *l, *l_next; | |
210 GaimRequestUiOps *ops; | |
211 | |
212 g_return_if_fail(handle != NULL); | |
213 | |
214 ops = gaim_get_request_ui_ops(); | |
215 | |
216 for (l = handles; l != NULL; l = l_next) { | |
217 GaimRequestInfo *info = l->data; | |
218 | |
219 l_next = l->next; | |
220 | |
221 if (info->handle == handle) { | |
222 handles = g_list_remove(handles, info); | |
223 | |
224 if (ops != NULL && ops->close_request != NULL) | |
225 ops->close_request(info->type, info->ui_handle); | |
226 | |
227 g_free(info); | |
228 } | |
229 } | |
230 } | |
231 | |
232 void | |
233 gaim_set_request_ui_ops(GaimRequestUiOps *ops) | |
234 { | |
235 request_ui_ops = ops; | |
236 } | |
237 | |
238 GaimRequestUiOps * | |
239 gaim_get_request_ui_ops(void) | |
240 { | |
241 return request_ui_ops; | |
242 } | |
243 | |
244 |