Mercurial > pidgin.yaz
annotate src/gtkrequest.c @ 5742:e0a1a2110432
[gaim-migrate @ 6166]
removed an unnecessary schedule for account saving.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Wed, 04 Jun 2003 08:41:43 +0000 |
parents | da18a02c3705 |
children | 5e93fc46d1af |
rev | line source |
---|---|
5480 | 1 /** |
2 * @file gtkrequest.c GTK+ Request API | |
3 * @ingroup gtkui | |
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 "gtkrequest.h" | |
24 #include "stock.h" | |
25 #include <gtk/gtk.h> | |
26 #include <string.h> | |
27 | |
28 /* XXX For _(..) */ | |
29 #include "gaim.h" | |
30 | |
31 typedef struct | |
32 { | |
33 GaimRequestType type; | |
34 | |
35 void *user_data; | |
36 GtkWidget *dialog; | |
37 | |
38 size_t cb_count; | |
39 GCallback *cbs; | |
40 | |
5490
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
41 union |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
42 { |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
43 struct |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
44 { |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
45 GtkWidget *entry; |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
46 |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
47 gboolean multiline; |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
48 |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
49 } input; |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
50 |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
51 } u; |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
52 |
5480 | 53 } GaimRequestData; |
54 | |
55 static void | |
56 __input_response_cb(GtkDialog *dialog, gint id, GaimRequestData *data) | |
57 { | |
5490
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
58 const char *value; |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
59 |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
60 if (data->u.input.multiline) { |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
61 GtkTextIter start_iter, end_iter; |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
62 GtkTextBuffer *buffer = |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
63 gtk_text_view_get_buffer(GTK_TEXT_VIEW(data->u.input.entry)); |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
64 |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
65 gtk_text_buffer_get_start_iter(buffer, &start_iter); |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
66 gtk_text_buffer_get_end_iter(buffer, &end_iter); |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
67 |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
68 value = gtk_text_buffer_get_text(buffer, &start_iter, &end_iter, |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
69 FALSE); |
5480 | 70 } |
5490
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
71 else |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
72 value = gtk_entry_get_text(GTK_ENTRY(data->u.input.entry)); |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
73 |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
74 if (id < data->cb_count && data->cbs[id] != NULL) |
5498
cce2d7868c78
[gaim-migrate @ 5894]
Christian Hammond <chipx86@chipx86.com>
parents:
5496
diff
changeset
|
75 ((GaimRequestInputCb)data->cbs[id])(data->user_data, value); |
5480 | 76 |
77 gaim_request_close(GAIM_REQUEST_INPUT, data); | |
78 } | |
79 | |
5496
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
80 static void |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
81 __action_response_cb(GtkDialog *dialog, gint id, GaimRequestData *data) |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
82 { |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
83 if (id < data->cb_count && data->cbs[id] != NULL) |
5498
cce2d7868c78
[gaim-migrate @ 5894]
Christian Hammond <chipx86@chipx86.com>
parents:
5496
diff
changeset
|
84 ((GaimRequestActionCb)data->cbs[id])(data->user_data, id); |
5496
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
85 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
86 gaim_request_close(GAIM_REQUEST_INPUT, data); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
87 } |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
88 |
5480 | 89 #define STOCK_ITEMIZE(r, l) \ |
90 if (!strcmp((r), text)) \ | |
91 return (l); | |
92 | |
93 static const char * | |
94 __text_to_stock(const char *text) | |
95 { | |
96 STOCK_ITEMIZE(_("Yes"), GTK_STOCK_YES); | |
97 STOCK_ITEMIZE(_("No"), GTK_STOCK_NO); | |
98 STOCK_ITEMIZE(_("OK"), GTK_STOCK_OK); | |
99 STOCK_ITEMIZE(_("Cancel"), GTK_STOCK_CANCEL); | |
100 STOCK_ITEMIZE(_("Apply"), GTK_STOCK_APPLY); | |
101 STOCK_ITEMIZE(_("Close"), GTK_STOCK_CLOSE); | |
102 STOCK_ITEMIZE(_("Delete"), GTK_STOCK_DELETE); | |
103 STOCK_ITEMIZE(_("Add"), GTK_STOCK_ADD); | |
104 STOCK_ITEMIZE(_("Remove"), GTK_STOCK_REMOVE); | |
105 | |
5490
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
106 return text; |
5480 | 107 } |
108 | |
109 void * | |
110 gaim_gtk_request_input(const char *title, const char *primary, | |
111 const char *secondary, const char *default_value, | |
112 gboolean multiline, | |
113 const char *ok_text, GCallback ok_cb, | |
114 const char *cancel_text, GCallback cancel_cb, | |
115 void *user_data) | |
116 { | |
117 GaimRequestData *data; | |
118 GtkWidget *dialog; | |
119 GtkWidget *vbox; | |
120 GtkWidget *hbox; | |
121 GtkWidget *label; | |
122 GtkWidget *entry; | |
123 GtkWidget *img; | |
124 char *label_text; | |
125 | |
126 data = g_new0(GaimRequestData, 1); | |
127 data->type = GAIM_REQUEST_INPUT; | |
128 data->user_data = user_data; | |
129 | |
130 data->cb_count = 2; | |
131 data->cbs = g_new0(GCallback, 2); | |
132 | |
133 data->cbs[0] = ok_cb; | |
134 data->cbs[1] = cancel_cb; | |
135 | |
136 /* Create the dialog. */ | |
137 dialog = gtk_dialog_new_with_buttons("", NULL, 0, | |
5485 | 138 __text_to_stock(cancel_text), 1, |
139 __text_to_stock(ok_text), 0, | |
140 NULL); | |
5480 | 141 data->dialog = dialog; |
142 | |
143 g_signal_connect(G_OBJECT(dialog), "response", | |
144 G_CALLBACK(__input_response_cb), data); | |
145 | |
146 /* Setup the dialog */ | |
147 gtk_container_set_border_width(GTK_CONTAINER(dialog), 6); | |
5510
da18a02c3705
[gaim-migrate @ 5909]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
148 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 6); |
5480 | 149 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); |
150 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); | |
5510
da18a02c3705
[gaim-migrate @ 5909]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
151 gtk_dialog_set_default_response(GTK_DIALOG(dialog), 0); |
5480 | 152 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 12); |
153 | |
154 /* Setup the main horizontal box */ | |
155 hbox = gtk_hbox_new(FALSE, 12); | |
156 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox); | |
157 | |
158 /* Dialog icon. */ | |
159 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, | |
160 GTK_ICON_SIZE_DIALOG); | |
161 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
162 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
163 | |
164 /* Vertical box */ | |
165 vbox = gtk_vbox_new(FALSE, 12); | |
166 | |
167 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); | |
168 | |
169 /* Descriptive label */ | |
170 label_text = g_strdup_printf("<span weight=\"bold\" size=\"larger\">" | |
171 "%s</span>\n\n%s", | |
172 primary, (secondary ? secondary : "")); | |
173 | |
174 label = gtk_label_new(NULL); | |
175 | |
176 gtk_label_set_markup(GTK_LABEL(label), label_text); | |
177 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
178 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
179 gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); | |
180 | |
181 g_free(label_text); | |
182 | |
183 /* Entry field. */ | |
5490
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
184 data->u.input.multiline = multiline; |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
185 |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
186 if (multiline) { |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
187 GtkWidget *sw; |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
188 |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
189 sw = gtk_scrolled_window_new(NULL, NULL); |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
190 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
191 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
192 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
193 GTK_SHADOW_IN); |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
194 |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
195 gtk_widget_set_size_request(sw, 300, 75); |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
196 |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
197 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
198 |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
199 entry = gtk_text_view_new(); |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
200 gtk_text_view_set_editable(GTK_TEXT_VIEW(entry), TRUE); |
5480 | 201 |
5490
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
202 gtk_container_add(GTK_CONTAINER(sw), entry); |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
203 |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
204 if (default_value != NULL) { |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
205 GtkTextBuffer *buffer; |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
206 |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
207 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)); |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
208 gtk_text_buffer_set_text(buffer, default_value, -1); |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
209 } |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
210 } |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
211 else { |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
212 entry = gtk_entry_new(); |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
213 |
5510
da18a02c3705
[gaim-migrate @ 5909]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
214 gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE); |
da18a02c3705
[gaim-migrate @ 5909]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
215 |
5490
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
216 gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0); |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
217 |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
218 if (default_value != NULL) |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
219 gtk_entry_set_text(GTK_ENTRY(entry), default_value); |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
220 } |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
221 |
421020171808
[gaim-migrate @ 5886]
Christian Hammond <chipx86@chipx86.com>
parents:
5485
diff
changeset
|
222 data->u.input.entry = entry; |
5480 | 223 |
224 /* Show everything. */ | |
225 gtk_widget_show_all(dialog); | |
226 | |
227 return data; | |
228 } | |
229 | |
230 void * | |
231 gaim_gtk_request_choice(const char *title, const char *primary, | |
232 const char *secondary, unsigned int default_value, | |
233 const char *ok_text, GCallback ok_cb, | |
234 const char *cancel_text, GCallback cancel_cb, | |
5496
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
235 void *user_data, size_t choice_count, va_list args) |
5480 | 236 { |
237 return NULL; | |
238 } | |
239 | |
240 void * | |
241 gaim_gtk_request_action(const char *title, const char *primary, | |
242 const char *secondary, unsigned int default_action, | |
5496
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
243 void *user_data, size_t action_count, va_list actions) |
5480 | 244 { |
5496
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
245 GaimRequestData *data; |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
246 GtkWidget *dialog; |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
247 GtkWidget *vbox; |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
248 GtkWidget *hbox; |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
249 GtkWidget *label; |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
250 GtkWidget *img; |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
251 void **buttons; |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
252 char *label_text; |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
253 int i; |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
254 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
255 data = g_new0(GaimRequestData, 1); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
256 data->type = GAIM_REQUEST_ACTION; |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
257 data->user_data = user_data; |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
258 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
259 data->cb_count = action_count; |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
260 data->cbs = g_new0(GCallback, action_count); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
261 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
262 /* Reverse the buttons */ |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
263 buttons = g_new0(void *, action_count * 2); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
264 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
265 for (i = 0; i < action_count * 2; i += 2) { |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
266 buttons[(action_count * 2) - i - 2] = va_arg(actions, char *); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
267 buttons[(action_count * 2) - i - 1] = va_arg(actions, GCallback); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
268 } |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
269 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
270 /* Create the dialog. */ |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
271 data->dialog = dialog = gtk_dialog_new(); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
272 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
273 for (i = 0; i < action_count; i++) { |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
274 gtk_dialog_add_button(GTK_DIALOG(dialog), |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
275 __text_to_stock(buttons[2 * i]), i); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
276 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
277 data->cbs[i] = buttons[2 * i + 1]; |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
278 } |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
279 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
280 g_free(buttons); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
281 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
282 g_signal_connect(G_OBJECT(dialog), "response", |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
283 G_CALLBACK(__action_response_cb), data); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
284 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
285 /* Setup the dialog */ |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
286 gtk_container_set_border_width(GTK_CONTAINER(dialog), 6); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
287 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
288 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
289 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 12); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
290 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 6); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
291 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
292 /* Setup the main horizontal box */ |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
293 hbox = gtk_hbox_new(FALSE, 12); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
294 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
295 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
296 /* Dialog icon. */ |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
297 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
298 GTK_ICON_SIZE_DIALOG); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
299 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
300 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
301 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
302 /* Vertical box */ |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
303 vbox = gtk_vbox_new(FALSE, 12); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
304 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
305 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
306 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
307 /* Descriptive label */ |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
308 label_text = g_strdup_printf("<span weight=\"bold\" size=\"larger\">" |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
309 "%s</span>\n\n%s", |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
310 primary, (secondary ? secondary : "")); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
311 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
312 label = gtk_label_new(NULL); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
313 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
314 gtk_label_set_markup(GTK_LABEL(label), label_text); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
315 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
316 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
317 gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
318 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
319 g_free(label_text); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
320 |
5510
da18a02c3705
[gaim-migrate @ 5909]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
321 if (default_action != -1) |
da18a02c3705
[gaim-migrate @ 5909]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
322 gtk_dialog_set_default_response(GTK_DIALOG(dialog), default_action); |
da18a02c3705
[gaim-migrate @ 5909]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
323 |
5496
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
324 /* Show everything. */ |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
325 gtk_widget_show_all(dialog); |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
326 |
b7c0be69c749
[gaim-migrate @ 5892]
Christian Hammond <chipx86@chipx86.com>
parents:
5490
diff
changeset
|
327 return data; |
5480 | 328 } |
329 | |
330 void | |
331 gaim_gtk_close_request(GaimRequestType type, void *ui_handle) | |
332 { | |
333 GaimRequestData *data = (GaimRequestData *)ui_handle; | |
334 | |
335 if (data->cbs != NULL) | |
336 g_free(data->cbs); | |
337 | |
338 gtk_widget_destroy(data->dialog); | |
339 | |
340 g_free(data); | |
341 } | |
342 | |
343 static GaimRequestUiOps ops = | |
344 { | |
345 gaim_gtk_request_input, | |
346 gaim_gtk_request_choice, | |
347 gaim_gtk_request_action, | |
348 gaim_gtk_close_request | |
349 }; | |
350 | |
351 GaimRequestUiOps * | |
352 gaim_get_gtk_request_ui_ops(void) | |
353 { | |
354 return &ops; | |
355 } |