Mercurial > pidgin
annotate finch/gntrequest.c @ 20655:e4d6bdb2a0c0
fixes #3140
committer: Luke Schierer <lschiere@pidgin.im>
author | Miloš Popović <gpopac@gmail.com> |
---|---|
date | Tue, 25 Sep 2007 18:06:20 +0000 |
parents | 6bf32c9e15a7 |
children | 591267f6f1d5 2354c9748a66 |
rev | line source |
---|---|
15817 | 1 /** |
2 * @file gntrequest.c GNT Request API | |
16194
0f0832c13fcb
Rename the Doxygen group from gntui to finch and define the finch group
Richard Laager <rlaager@wiktel.com>
parents:
16164
diff
changeset
|
3 * @ingroup finch |
20074
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19761
diff
changeset
|
4 */ |
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19761
diff
changeset
|
5 |
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19761
diff
changeset
|
6 /* finch |
15817 | 7 * |
15870
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15843
diff
changeset
|
8 * Finch is the legal property of its developers, whose names are too numerous |
15817 | 9 * to list here. Please refer to the COPYRIGHT file distributed with this |
10 * source distribution. | |
11 * | |
12 * This program is free software; you can redistribute it and/or modify | |
13 * it under the terms of the GNU General Public License as published by | |
14 * the Free Software Foundation; either version 2 of the License, or | |
15 * (at your option) any later version. | |
16 * | |
17 * This program is distributed in the hope that it will be useful, | |
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 * GNU General Public License for more details. | |
21 * | |
22 * You should have received a copy of the GNU General Public License | |
23 * along with this program; if not, write to the Free Software | |
19681
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19528
diff
changeset
|
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
15817 | 25 */ |
26 #include <gnt.h> | |
27 #include <gntbox.h> | |
28 #include <gntbutton.h> | |
29 #include <gntcheckbox.h> | |
30 #include <gntcombobox.h> | |
31 #include <gntentry.h> | |
15927
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15924
diff
changeset
|
32 #include <gntfilesel.h> |
15817 | 33 #include <gntlabel.h> |
34 #include <gntline.h> | |
35 #include <gnttree.h> | |
36 | |
15822 | 37 #include "finch.h" |
15817 | 38 #include "gntrequest.h" |
16164
87019c619be0
Include header files, not source files. Bah.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15936
diff
changeset
|
39 #include "util.h" |
15817 | 40 |
41 typedef struct | |
42 { | |
43 void *user_data; | |
15927
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15924
diff
changeset
|
44 GntWidget *dialog; |
15817 | 45 GCallback *cbs; |
18410
719f73b9a593
Remember the open/save file locations.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18347
diff
changeset
|
46 gboolean save; |
15822 | 47 } PurpleGntFileRequest; |
15817 | 48 |
49 static GntWidget * | |
50 setup_request_window(const char *title, const char *primary, | |
15822 | 51 const char *secondary, PurpleRequestType type) |
15817 | 52 { |
53 GntWidget *window; | |
54 | |
55 window = gnt_vbox_new(FALSE); | |
56 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
57 gnt_box_set_title(GNT_BOX(window), title); | |
58 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); | |
59 | |
60 if (primary) | |
61 gnt_box_add_widget(GNT_BOX(window), | |
62 gnt_label_new_with_format(primary, GNT_TEXT_FLAG_BOLD)); | |
63 if (secondary) | |
64 gnt_box_add_widget(GNT_BOX(window), gnt_label_new(secondary)); | |
65 | |
15822 | 66 g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(purple_request_close), |
15817 | 67 GINT_TO_POINTER(type)); |
68 | |
69 return window; | |
70 } | |
71 | |
18333
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
72 /** |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
73 * If the window is closed by the wm (ie, without triggering any of |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
74 * the buttons, then do some default callback. |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
75 */ |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
76 static void |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
77 setup_default_callback(GntWidget *window, gpointer default_cb, gpointer data) |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
78 { |
18347
a90f9a0b90c8
Update search-api to not crash. Searching for users in xmpp/oscar works now.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18333
diff
changeset
|
79 g_object_set_data(G_OBJECT(window), "default-callback", default_cb); |
18333
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
80 g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(default_cb), data); |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
81 } |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
82 |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
83 static void |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
84 action_performed(GntWidget *button, gpointer data) |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
85 { |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
86 g_signal_handlers_disconnect_matched(data, G_SIGNAL_MATCH_FUNC, |
18347
a90f9a0b90c8
Update search-api to not crash. Searching for users in xmpp/oscar works now.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18333
diff
changeset
|
87 0, 0, NULL, |
a90f9a0b90c8
Update search-api to not crash. Searching for users in xmpp/oscar works now.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18333
diff
changeset
|
88 g_object_get_data(data, "default-callback"), |
a90f9a0b90c8
Update search-api to not crash. Searching for users in xmpp/oscar works now.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18333
diff
changeset
|
89 NULL); |
18333
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
90 } |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
91 |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
92 /** |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
93 * window: this is the window |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
94 * userdata: the userdata to pass to the primary callbacks |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
95 * cb: the callback |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
96 * data: data for the callback |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
97 * (text, primary-callback) pairs, ended by a NULL |
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
98 */ |
15817 | 99 static GntWidget * |
18333
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
100 setup_button_box(GntWidget *win, gpointer userdata, gpointer cb, gpointer data, ...) |
15817 | 101 { |
102 GntWidget *box, *button; | |
103 va_list list; | |
104 const char *text; | |
105 gpointer callback; | |
106 | |
107 box = gnt_hbox_new(FALSE); | |
108 | |
109 va_start(list, data); | |
110 | |
111 while ((text = va_arg(list, const char *))) | |
112 { | |
113 callback = va_arg(list, gpointer); | |
114 button = gnt_button_new(text); | |
115 gnt_box_add_widget(GNT_BOX(box), button); | |
116 g_object_set_data(G_OBJECT(button), "activate-callback", callback); | |
117 g_object_set_data(G_OBJECT(button), "activate-userdata", userdata); | |
18347
a90f9a0b90c8
Update search-api to not crash. Searching for users in xmpp/oscar works now.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18333
diff
changeset
|
118 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(action_performed), win); |
15817 | 119 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(cb), data); |
120 } | |
121 | |
122 va_end(list); | |
123 return box; | |
124 } | |
125 | |
126 static void | |
127 notify_input_cb(GntWidget *button, GntWidget *entry) | |
128 { | |
15822 | 129 PurpleRequestInputCb callback = g_object_get_data(G_OBJECT(button), "activate-callback"); |
15817 | 130 gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata"); |
131 const char *text = gnt_entry_get_text(GNT_ENTRY(entry)); | |
132 | |
133 if (callback) | |
134 callback(data, text); | |
135 | |
136 while (button->parent) | |
137 button = button->parent; | |
138 | |
15822 | 139 purple_request_close(PURPLE_REQUEST_INPUT, button); |
15817 | 140 } |
141 | |
142 static void * | |
143 finch_request_input(const char *title, const char *primary, | |
144 const char *secondary, const char *default_value, | |
145 gboolean multiline, gboolean masked, gchar *hint, | |
146 const char *ok_text, GCallback ok_cb, | |
147 const char *cancel_text, GCallback cancel_cb, | |
16439
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16310
diff
changeset
|
148 PurpleAccount *account, const char *who, PurpleConversation *conv, |
15817 | 149 void *user_data) |
150 { | |
151 GntWidget *window, *box, *entry; | |
152 | |
15822 | 153 window = setup_request_window(title, primary, secondary, PURPLE_REQUEST_INPUT); |
15817 | 154 |
155 entry = gnt_entry_new(default_value); | |
156 if (masked) | |
157 gnt_entry_set_masked(GNT_ENTRY(entry), TRUE); | |
158 gnt_box_add_widget(GNT_BOX(window), entry); | |
159 | |
18333
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
160 box = setup_button_box(window, user_data, notify_input_cb, entry, |
15817 | 161 ok_text, ok_cb, cancel_text, cancel_cb, NULL); |
162 gnt_box_add_widget(GNT_BOX(window), box); | |
163 | |
18333
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
164 setup_default_callback(window, cancel_cb, user_data); |
15817 | 165 gnt_widget_show(window); |
166 | |
167 return window; | |
168 } | |
169 | |
170 static void | |
15822 | 171 finch_close_request(PurpleRequestType type, gpointer ui_handle) |
15817 | 172 { |
173 GntWidget *widget = GNT_WIDGET(ui_handle); | |
16310
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
174 if (type == PURPLE_REQUEST_FIELDS) { |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
175 PurpleRequestFields *fields = g_object_get_data(G_OBJECT(widget), "fields"); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
176 purple_request_fields_destroy(fields); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
177 } |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
178 |
15817 | 179 while (widget->parent) |
180 widget = widget->parent; | |
181 gnt_widget_destroy(widget); | |
182 } | |
183 | |
184 static void | |
185 request_choice_cb(GntWidget *button, GntComboBox *combo) | |
186 { | |
15822 | 187 PurpleRequestChoiceCb callback = g_object_get_data(G_OBJECT(button), "activate-callback"); |
15817 | 188 gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata"); |
189 int choice = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo))) - 1; | |
190 | |
191 if (callback) | |
192 callback(data, choice); | |
193 | |
194 while (button->parent) | |
195 button = button->parent; | |
196 | |
15822 | 197 purple_request_close(PURPLE_REQUEST_INPUT, button); |
15817 | 198 } |
199 | |
200 static void * | |
201 finch_request_choice(const char *title, const char *primary, | |
19528
b7fa8fa4de5b
Fix building on older glib versions.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18411
diff
changeset
|
202 const char *secondary, int default_value, |
15817 | 203 const char *ok_text, GCallback ok_cb, |
204 const char *cancel_text, GCallback cancel_cb, | |
16439
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16310
diff
changeset
|
205 PurpleAccount *account, const char *who, PurpleConversation *conv, |
15817 | 206 void *user_data, va_list choices) |
207 { | |
208 GntWidget *window, *combo, *box; | |
209 const char *text; | |
210 int val; | |
211 | |
15822 | 212 window = setup_request_window(title, primary, secondary, PURPLE_REQUEST_CHOICE); |
15817 | 213 |
214 combo = gnt_combo_box_new(); | |
215 gnt_box_add_widget(GNT_BOX(window), combo); | |
216 while ((text = va_arg(choices, const char *))) | |
217 { | |
218 val = va_arg(choices, int); | |
219 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), GINT_TO_POINTER(val + 1), text); | |
220 } | |
221 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), GINT_TO_POINTER(default_value + 1)); | |
222 | |
18333
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
223 box = setup_button_box(window, user_data, request_choice_cb, combo, |
15817 | 224 ok_text, ok_cb, cancel_text, cancel_cb, NULL); |
225 gnt_box_add_widget(GNT_BOX(window), box); | |
226 | |
18333
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
227 setup_default_callback(window, cancel_cb, user_data); |
15817 | 228 gnt_widget_show(window); |
229 | |
230 return window; | |
231 } | |
232 | |
233 static void | |
234 request_action_cb(GntWidget *button, GntWidget *window) | |
235 { | |
15822 | 236 PurpleRequestActionCb callback = g_object_get_data(G_OBJECT(button), "activate-callback"); |
15817 | 237 gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata"); |
238 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button), "activate-id")); | |
239 | |
240 if (callback) | |
241 callback(data, id); | |
242 | |
15822 | 243 purple_request_close(PURPLE_REQUEST_ACTION, window); |
15817 | 244 } |
245 | |
246 static void* | |
247 finch_request_action(const char *title, const char *primary, | |
19528
b7fa8fa4de5b
Fix building on older glib versions.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18411
diff
changeset
|
248 const char *secondary, int default_value, |
16439
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16310
diff
changeset
|
249 PurpleAccount *account, const char *who, PurpleConversation *conv, |
15817 | 250 void *user_data, size_t actioncount, |
251 va_list actions) | |
252 { | |
253 GntWidget *window, *box, *button; | |
254 int i; | |
255 | |
15822 | 256 window = setup_request_window(title, primary, secondary, PURPLE_REQUEST_ACTION); |
15817 | 257 |
258 box = gnt_hbox_new(FALSE); | |
259 gnt_box_add_widget(GNT_BOX(window), box); | |
260 for (i = 0; i < actioncount; i++) | |
261 { | |
262 const char *text = va_arg(actions, const char *); | |
15822 | 263 PurpleRequestActionCb callback = va_arg(actions, PurpleRequestActionCb); |
15817 | 264 |
265 button = gnt_button_new(text); | |
266 gnt_box_add_widget(GNT_BOX(box), button); | |
267 | |
268 g_object_set_data(G_OBJECT(button), "activate-callback", callback); | |
269 g_object_set_data(G_OBJECT(button), "activate-userdata", user_data); | |
270 g_object_set_data(G_OBJECT(button), "activate-id", GINT_TO_POINTER(i)); | |
271 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(request_action_cb), window); | |
272 } | |
273 | |
274 gnt_widget_show(window); | |
275 | |
276 return window; | |
277 } | |
278 | |
279 static void | |
15822 | 280 request_fields_cb(GntWidget *button, PurpleRequestFields *fields) |
15817 | 281 { |
15822 | 282 PurpleRequestFieldsCb callback = g_object_get_data(G_OBJECT(button), "activate-callback"); |
15817 | 283 gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata"); |
284 GList *list; | |
285 | |
16310
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
286 /* Update the data of the fields. Pidgin does this differently. Instead of |
15817 | 287 * updating the fields at the end like here, it updates the appropriate field |
288 * instantly whenever a change is made. That allows it to make sure the | |
289 * 'required' fields are entered before the user can hit OK. It's not the case | |
290 * here, althought it can be done. I am not honouring the 'required' fields | |
291 * for the moment. */ | |
15822 | 292 for (list = purple_request_fields_get_groups(fields); list; list = list->next) |
15817 | 293 { |
15822 | 294 PurpleRequestFieldGroup *group = list->data; |
295 GList *fields = purple_request_field_group_get_fields(group); | |
15817 | 296 |
297 for (; fields ; fields = fields->next) | |
298 { | |
15822 | 299 PurpleRequestField *field = fields->data; |
300 PurpleRequestFieldType type = purple_request_field_get_type(field); | |
301 if (type == PURPLE_REQUEST_FIELD_BOOLEAN) | |
15817 | 302 { |
303 GntWidget *check = field->ui_data; | |
304 gboolean value = gnt_check_box_get_checked(GNT_CHECK_BOX(check)); | |
15822 | 305 purple_request_field_bool_set_value(field, value); |
15817 | 306 } |
15822 | 307 else if (type == PURPLE_REQUEST_FIELD_STRING) |
15817 | 308 { |
309 GntWidget *entry = field->ui_data; | |
310 const char *text = gnt_entry_get_text(GNT_ENTRY(entry)); | |
15822 | 311 purple_request_field_string_set_value(field, (text && *text) ? text : NULL); |
15817 | 312 } |
15822 | 313 else if (type == PURPLE_REQUEST_FIELD_INTEGER) |
15817 | 314 { |
315 GntWidget *entry = field->ui_data; | |
316 const char *text = gnt_entry_get_text(GNT_ENTRY(entry)); | |
317 int value = (text && *text) ? atoi(text) : 0; | |
15822 | 318 purple_request_field_int_set_value(field, value); |
15817 | 319 } |
15822 | 320 else if (type == PURPLE_REQUEST_FIELD_CHOICE) |
15817 | 321 { |
322 GntWidget *combo = field->ui_data; | |
323 int id; | |
324 id = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo))); | |
15822 | 325 purple_request_field_choice_set_value(field, id); |
15817 | 326 } |
15822 | 327 else if (type == PURPLE_REQUEST_FIELD_LIST) |
15817 | 328 { |
329 GList *list = NULL; | |
15822 | 330 if (purple_request_field_list_get_multi_select(field)) |
15817 | 331 { |
18118
ab6d2763b8d8
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@wiktel.com>
parents:
18063
diff
changeset
|
332 GList *iter; |
15817 | 333 GntWidget *tree = field->ui_data; |
334 | |
15822 | 335 iter = purple_request_field_list_get_items(field); |
15817 | 336 for (; iter; iter = iter->next) |
337 { | |
338 const char *text = iter->data; | |
15822 | 339 gpointer key = purple_request_field_list_get_data(field, text); |
15817 | 340 if (gnt_tree_get_choice(GNT_TREE(tree), key)) |
341 list = g_list_prepend(list, key); | |
342 } | |
343 } | |
344 else | |
345 { | |
346 GntWidget *combo = field->ui_data; | |
347 gpointer data = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo)); | |
348 list = g_list_append(list, data); | |
349 } | |
350 | |
15822 | 351 purple_request_field_list_set_selected(field, list); |
15817 | 352 g_list_free(list); |
353 } | |
15822 | 354 else if (type == PURPLE_REQUEST_FIELD_ACCOUNT) |
15817 | 355 { |
356 GntWidget *combo = field->ui_data; | |
15822 | 357 PurpleAccount *acc = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo)); |
358 purple_request_field_account_set_value(field, acc); | |
15817 | 359 } |
360 } | |
361 } | |
362 | |
363 if (callback) | |
364 callback(data, fields); | |
365 | |
366 while (button->parent) | |
367 button = button->parent; | |
368 | |
15822 | 369 purple_request_close(PURPLE_REQUEST_FIELDS, button); |
15817 | 370 } |
371 | |
19761
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
372 static void |
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
373 update_selected_account(GntEntry *screenname, const char *start, const char *end, |
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
374 GntComboBox *accountlist) |
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
375 { |
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
376 GList *accounts = gnt_tree_get_rows(GNT_TREE(accountlist->dropdown)); |
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
377 const char *name = gnt_entry_get_text(screenname); |
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
378 while (accounts) { |
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
379 if (purple_find_buddy(accounts->data, name)) { |
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
380 gnt_combo_box_set_selected(accountlist, accounts->data); |
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
381 gnt_widget_draw(GNT_WIDGET(accountlist)); |
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
382 break; |
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
383 } |
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
384 accounts = accounts->next; |
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
385 } |
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
386 } |
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
387 |
15817 | 388 static void * |
389 finch_request_fields(const char *title, const char *primary, | |
15822 | 390 const char *secondary, PurpleRequestFields *allfields, |
15817 | 391 const char *ok, GCallback ok_cb, |
392 const char *cancel, GCallback cancel_cb, | |
16439
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16310
diff
changeset
|
393 PurpleAccount *account, const char *who, PurpleConversation *conv, |
15817 | 394 void *userdata) |
395 { | |
396 GntWidget *window, *box; | |
397 GList *grlist; | |
19761
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
398 GntWidget *screenname = NULL, *accountlist = NULL; |
15817 | 399 |
15822 | 400 window = setup_request_window(title, primary, secondary, PURPLE_REQUEST_FIELDS); |
15817 | 401 |
402 /* This is how it's going to work: the request-groups are going to be | |
403 * stacked vertically one after the other. A GntLine will be separating | |
404 * the groups. */ | |
405 box = gnt_vbox_new(FALSE); | |
406 gnt_box_set_pad(GNT_BOX(box), 0); | |
407 gnt_box_set_fill(GNT_BOX(box), TRUE); | |
15822 | 408 for (grlist = purple_request_fields_get_groups(allfields); grlist; grlist = grlist->next) |
15817 | 409 { |
15822 | 410 PurpleRequestFieldGroup *group = grlist->data; |
411 GList *fields = purple_request_field_group_get_fields(group); | |
15817 | 412 GntWidget *hbox; |
15822 | 413 const char *title = purple_request_field_group_get_title(group); |
15817 | 414 |
415 if (title) | |
416 gnt_box_add_widget(GNT_BOX(box), | |
417 gnt_label_new_with_format(title, GNT_TEXT_FLAG_BOLD)); | |
418 | |
419 for (; fields ; fields = fields->next) | |
420 { | |
421 /* XXX: Break each of the fields into a separate function? */ | |
15822 | 422 PurpleRequestField *field = fields->data; |
423 PurpleRequestFieldType type = purple_request_field_get_type(field); | |
424 const char *label = purple_request_field_get_label(field); | |
15817 | 425 |
426 hbox = gnt_hbox_new(TRUE); /* hrm */ | |
427 gnt_box_add_widget(GNT_BOX(box), hbox); | |
428 | |
15822 | 429 if (type != PURPLE_REQUEST_FIELD_BOOLEAN && label) |
15817 | 430 { |
431 GntWidget *l = gnt_label_new(label); | |
432 gnt_widget_set_size(l, 0, 1); | |
433 gnt_box_add_widget(GNT_BOX(hbox), l); | |
434 } | |
435 | |
15822 | 436 if (type == PURPLE_REQUEST_FIELD_BOOLEAN) |
15817 | 437 { |
438 GntWidget *check = gnt_check_box_new(label); | |
439 gnt_check_box_set_checked(GNT_CHECK_BOX(check), | |
15822 | 440 purple_request_field_bool_get_default_value(field)); |
15817 | 441 gnt_box_add_widget(GNT_BOX(hbox), check); |
442 field->ui_data = check; | |
443 } | |
15822 | 444 else if (type == PURPLE_REQUEST_FIELD_STRING) |
15817 | 445 { |
15829 | 446 const char *hint = purple_request_field_get_type_hint(field); |
15817 | 447 GntWidget *entry = gnt_entry_new( |
15822 | 448 purple_request_field_string_get_default_value(field)); |
15817 | 449 gnt_entry_set_masked(GNT_ENTRY(entry), |
15822 | 450 purple_request_field_string_is_masked(field)); |
18222
ef65d43190e5
Fix a few runtime warnings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18118
diff
changeset
|
451 if (hint && purple_str_has_prefix(hint, "screenname")) { |
15829 | 452 PurpleBlistNode *node = purple_blist_get_root(); |
453 gboolean offline = purple_str_has_suffix(hint, "all"); | |
454 for (; node; node = purple_blist_node_next(node, offline)) { | |
455 if (!PURPLE_BLIST_NODE_IS_BUDDY(node)) | |
15826
f59cfcce68a8
Add auto-complete support in request-entries that have 'screenname' hint set. This can be useful in, for example, 'send im' dialog etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
456 continue; |
15829 | 457 gnt_entry_add_suggest(GNT_ENTRY(entry), purple_buddy_get_name((PurpleBuddy*)node)); |
15826
f59cfcce68a8
Add auto-complete support in request-entries that have 'screenname' hint set. This can be useful in, for example, 'send im' dialog etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
458 } |
f59cfcce68a8
Add auto-complete support in request-entries that have 'screenname' hint set. This can be useful in, for example, 'send im' dialog etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
459 gnt_entry_set_always_suggest(GNT_ENTRY(entry), TRUE); |
19761
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
460 screenname = entry; |
15843
e74c2488448b
Group autocomplete for buddy adding
Richard Nelson <wabz@pidgin.im>
parents:
15829
diff
changeset
|
461 } else if (hint && !strcmp(hint, "group")) { |
e74c2488448b
Group autocomplete for buddy adding
Richard Nelson <wabz@pidgin.im>
parents:
15829
diff
changeset
|
462 PurpleBlistNode *node; |
e74c2488448b
Group autocomplete for buddy adding
Richard Nelson <wabz@pidgin.im>
parents:
15829
diff
changeset
|
463 for (node = purple_blist_get_root(); node; node = node->next) { |
e74c2488448b
Group autocomplete for buddy adding
Richard Nelson <wabz@pidgin.im>
parents:
15829
diff
changeset
|
464 if (PURPLE_BLIST_NODE_IS_GROUP(node)) |
e74c2488448b
Group autocomplete for buddy adding
Richard Nelson <wabz@pidgin.im>
parents:
15829
diff
changeset
|
465 gnt_entry_add_suggest(GNT_ENTRY(entry), ((PurpleGroup *)node)->name); |
e74c2488448b
Group autocomplete for buddy adding
Richard Nelson <wabz@pidgin.im>
parents:
15829
diff
changeset
|
466 } |
15826
f59cfcce68a8
Add auto-complete support in request-entries that have 'screenname' hint set. This can be useful in, for example, 'send im' dialog etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
467 } |
15817 | 468 gnt_box_add_widget(GNT_BOX(hbox), entry); |
469 field->ui_data = entry; | |
470 } | |
15822 | 471 else if (type == PURPLE_REQUEST_FIELD_INTEGER) |
15817 | 472 { |
473 char str[256]; | |
15822 | 474 int val = purple_request_field_int_get_default_value(field); |
15817 | 475 GntWidget *entry; |
476 | |
477 snprintf(str, sizeof(str), "%d", val); | |
478 entry = gnt_entry_new(str); | |
479 gnt_entry_set_flag(GNT_ENTRY(entry), GNT_ENTRY_FLAG_INT); | |
480 gnt_box_add_widget(GNT_BOX(hbox), entry); | |
481 field->ui_data = entry; | |
482 } | |
15822 | 483 else if (type == PURPLE_REQUEST_FIELD_CHOICE) |
15817 | 484 { |
485 int id; | |
18118
ab6d2763b8d8
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@wiktel.com>
parents:
18063
diff
changeset
|
486 GList *list; |
15817 | 487 GntWidget *combo = gnt_combo_box_new(); |
488 gnt_box_add_widget(GNT_BOX(hbox), combo); | |
489 field->ui_data = combo; | |
490 | |
15822 | 491 list = purple_request_field_choice_get_labels(field); |
15817 | 492 for (id = 1; list; list = list->next, id++) |
493 { | |
494 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), | |
495 GINT_TO_POINTER(id), list->data); | |
496 } | |
497 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), | |
15822 | 498 GINT_TO_POINTER(purple_request_field_choice_get_default_value(field))); |
15817 | 499 } |
15822 | 500 else if (type == PURPLE_REQUEST_FIELD_LIST) |
15817 | 501 { |
18118
ab6d2763b8d8
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@wiktel.com>
parents:
18063
diff
changeset
|
502 GList *list; |
15822 | 503 gboolean multi = purple_request_field_list_get_multi_select(field); |
15817 | 504 if (multi) |
505 { | |
506 GntWidget *tree = gnt_tree_new(); | |
507 gnt_box_add_widget(GNT_BOX(hbox), tree); | |
508 field->ui_data = tree; | |
509 | |
15822 | 510 list = purple_request_field_list_get_items(field); |
15817 | 511 for (; list; list = list->next) |
512 { | |
513 const char *text = list->data; | |
15822 | 514 gpointer key = purple_request_field_list_get_data(field, text); |
15817 | 515 gnt_tree_add_choice(GNT_TREE(tree), key, |
516 gnt_tree_create_row(GNT_TREE(tree), text), NULL, NULL); | |
15822 | 517 if (purple_request_field_list_is_selected(field, text)) |
15817 | 518 gnt_tree_set_choice(GNT_TREE(tree), key, TRUE); |
519 } | |
520 } | |
521 else | |
522 { | |
523 GntWidget *combo = gnt_combo_box_new(); | |
524 gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); | |
525 gnt_box_add_widget(GNT_BOX(hbox), combo); | |
526 field->ui_data = combo; | |
527 | |
15822 | 528 list = purple_request_field_list_get_items(field); |
15817 | 529 for (; list; list = list->next) |
530 { | |
531 const char *text = list->data; | |
15822 | 532 gpointer key = purple_request_field_list_get_data(field, text); |
15817 | 533 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), key, text); |
15822 | 534 if (purple_request_field_list_is_selected(field, text)) |
15817 | 535 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), key); |
536 } | |
537 } | |
538 } | |
15822 | 539 else if (type == PURPLE_REQUEST_FIELD_ACCOUNT) |
15817 | 540 { |
541 gboolean all; | |
15822 | 542 PurpleAccount *def; |
18063
926ccb104da0
disapproval of revision '1411afd7660760db59966c3a9f18e2adab8eb27e'
Richard Laager <rlaager@wiktel.com>
parents:
18058
diff
changeset
|
543 GList *list; |
15817 | 544 GntWidget *combo = gnt_combo_box_new(); |
545 gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); | |
546 gnt_box_add_widget(GNT_BOX(hbox), combo); | |
547 field->ui_data = combo; | |
548 | |
15822 | 549 all = purple_request_field_account_get_show_all(field); |
16927
43abb4942a6d
Select the right account when adding a buddy after authorizing her.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
550 def = purple_request_field_account_get_value(field); |
43abb4942a6d
Select the right account when adding a buddy after authorizing her.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
551 if (!def) |
43abb4942a6d
Select the right account when adding a buddy after authorizing her.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
552 def = purple_request_field_account_get_default_value(field); |
15817 | 553 |
554 if (all) | |
15822 | 555 list = purple_accounts_get_all(); |
15817 | 556 else |
15822 | 557 list = purple_connections_get_all(); |
15817 | 558 |
559 for (; list; list = list->next) | |
560 { | |
15822 | 561 PurpleAccount *account; |
15817 | 562 char *text; |
563 | |
564 if (all) | |
565 account = list->data; | |
566 else | |
15822 | 567 account = purple_connection_get_account(list->data); |
15817 | 568 |
569 text = g_strdup_printf("%s (%s)", | |
15822 | 570 purple_account_get_username(account), |
571 purple_account_get_protocol_name(account)); | |
15817 | 572 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), account, text); |
573 g_free(text); | |
574 if (account == def) | |
575 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), account); | |
576 } | |
577 gnt_widget_set_size(combo, 20, 3); /* ew */ | |
19761
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
578 accountlist = combo; |
15817 | 579 } |
580 else | |
581 { | |
582 gnt_box_add_widget(GNT_BOX(hbox), | |
583 gnt_label_new_with_format(_("Not implemented yet."), | |
584 GNT_TEXT_FLAG_BOLD)); | |
585 } | |
586 } | |
587 if (grlist->next) | |
588 gnt_box_add_widget(GNT_BOX(box), gnt_hline_new()); | |
589 } | |
590 gnt_box_add_widget(GNT_BOX(window), box); | |
591 | |
18333
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
592 box = setup_button_box(window, userdata, request_fields_cb, allfields, |
15817 | 593 ok, ok_cb, cancel, cancel_cb, NULL); |
594 gnt_box_add_widget(GNT_BOX(window), box); | |
595 | |
18333
f23a7736586f
Consider closing a request dialog equivalent to cancelling it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18222
diff
changeset
|
596 setup_default_callback(window, cancel_cb, userdata); |
15817 | 597 gnt_widget_show(window); |
16310
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
598 |
19761
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
599 if (screenname && accountlist) { |
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
600 g_signal_connect(screenname, "completion", G_CALLBACK(update_selected_account), accountlist); |
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
601 } |
8c356223e182
Select the right account when a buddyname is selected from the suggest-list.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
602 |
16310
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
603 g_object_set_data(G_OBJECT(window), "fields", allfields); |
15817 | 604 |
605 return window; | |
606 } | |
607 | |
608 static void | |
18411
3849776d0f71
Fix some crashes resulting from rejecting file-transfer requests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18410
diff
changeset
|
609 file_cancel_cb(gpointer fq, GntWidget *wid) |
15817 | 610 { |
15822 | 611 PurpleGntFileRequest *data = fq; |
15817 | 612 if (data->cbs[1] != NULL) |
15822 | 613 ((PurpleRequestFileCb)data->cbs[1])(data->user_data, NULL); |
15817 | 614 |
15822 | 615 purple_request_close(PURPLE_REQUEST_FILE, data->dialog); |
15817 | 616 } |
617 | |
618 static void | |
18411
3849776d0f71
Fix some crashes resulting from rejecting file-transfer requests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18410
diff
changeset
|
619 file_ok_cb(gpointer fq, GntWidget *widget) |
15817 | 620 { |
15822 | 621 PurpleGntFileRequest *data = fq; |
15927
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15924
diff
changeset
|
622 char *file = gnt_file_sel_get_selected_file(GNT_FILE_SEL(data->dialog)); |
18410
719f73b9a593
Remember the open/save file locations.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18347
diff
changeset
|
623 char *dir = g_path_get_dirname(file); |
15817 | 624 if (data->cbs[0] != NULL) |
15927
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15924
diff
changeset
|
625 ((PurpleRequestFileCb)data->cbs[0])(data->user_data, file); |
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15924
diff
changeset
|
626 g_free(file); |
18410
719f73b9a593
Remember the open/save file locations.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18347
diff
changeset
|
627 purple_prefs_set_path(data->save ? "/finch/filelocations/last_save_folder" : |
719f73b9a593
Remember the open/save file locations.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18347
diff
changeset
|
628 "/finch/filelocations/last_open_folder", dir); |
719f73b9a593
Remember the open/save file locations.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18347
diff
changeset
|
629 g_free(dir); |
15817 | 630 |
15822 | 631 purple_request_close(PURPLE_REQUEST_FILE, data->dialog); |
15817 | 632 } |
633 | |
634 static void | |
15822 | 635 file_request_destroy(PurpleGntFileRequest *data) |
15817 | 636 { |
637 g_free(data->cbs); | |
638 g_free(data); | |
639 } | |
640 | |
641 static void * | |
642 finch_request_file(const char *title, const char *filename, | |
643 gboolean savedialog, | |
644 GCallback ok_cb, GCallback cancel_cb, | |
16439
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16310
diff
changeset
|
645 PurpleAccount *account, const char *who, PurpleConversation *conv, |
15817 | 646 void *user_data) |
647 { | |
15927
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15924
diff
changeset
|
648 GntWidget *window = gnt_file_sel_new(); |
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15924
diff
changeset
|
649 GntFileSel *sel = GNT_FILE_SEL(window); |
15822 | 650 PurpleGntFileRequest *data = g_new0(PurpleGntFileRequest, 1); |
18410
719f73b9a593
Remember the open/save file locations.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18347
diff
changeset
|
651 const char *path; |
15817 | 652 |
653 data->user_data = user_data; | |
654 data->cbs = g_new0(GCallback, 2); | |
655 data->cbs[0] = ok_cb; | |
656 data->cbs[1] = cancel_cb; | |
657 data->dialog = window; | |
18410
719f73b9a593
Remember the open/save file locations.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18347
diff
changeset
|
658 data->save = savedialog; |
15817 | 659 gnt_box_set_title(GNT_BOX(window), title ? title : (savedialog ? _("Save File...") : _("Open File..."))); |
18410
719f73b9a593
Remember the open/save file locations.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18347
diff
changeset
|
660 |
719f73b9a593
Remember the open/save file locations.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18347
diff
changeset
|
661 path = purple_prefs_get_path(savedialog ? "/finch/filelocations/last_save_folder" : "/finch/filelocations/last_open_folder"); |
719f73b9a593
Remember the open/save file locations.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18347
diff
changeset
|
662 gnt_file_sel_set_current_location(sel, (path && *path) ? path : purple_home_dir()); |
719f73b9a593
Remember the open/save file locations.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18347
diff
changeset
|
663 |
15936 | 664 if (savedialog) |
665 gnt_file_sel_set_suggested_filename(sel, filename); | |
18411
3849776d0f71
Fix some crashes resulting from rejecting file-transfer requests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18410
diff
changeset
|
666 |
15927
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15924
diff
changeset
|
667 g_signal_connect(G_OBJECT(sel->cancel), "activate", |
18411
3849776d0f71
Fix some crashes resulting from rejecting file-transfer requests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18410
diff
changeset
|
668 G_CALLBACK(action_performed), window); |
3849776d0f71
Fix some crashes resulting from rejecting file-transfer requests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18410
diff
changeset
|
669 g_signal_connect(G_OBJECT(sel->select), "activate", |
3849776d0f71
Fix some crashes resulting from rejecting file-transfer requests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18410
diff
changeset
|
670 G_CALLBACK(action_performed), window); |
3849776d0f71
Fix some crashes resulting from rejecting file-transfer requests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18410
diff
changeset
|
671 g_signal_connect_swapped(G_OBJECT(sel->cancel), "activate", |
15927
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15924
diff
changeset
|
672 G_CALLBACK(file_cancel_cb), data); |
18411
3849776d0f71
Fix some crashes resulting from rejecting file-transfer requests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18410
diff
changeset
|
673 g_signal_connect_swapped(G_OBJECT(sel->select), "activate", |
15927
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15924
diff
changeset
|
674 G_CALLBACK(file_ok_cb), data); |
15817 | 675 |
18411
3849776d0f71
Fix some crashes resulting from rejecting file-transfer requests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18410
diff
changeset
|
676 setup_default_callback(window, file_cancel_cb, data); |
3849776d0f71
Fix some crashes resulting from rejecting file-transfer requests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18410
diff
changeset
|
677 g_object_set_data_full(G_OBJECT(window), "filerequestdata", data, |
3849776d0f71
Fix some crashes resulting from rejecting file-transfer requests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18410
diff
changeset
|
678 (GDestroyNotify)file_request_destroy); |
15817 | 679 gnt_widget_show(window); |
680 | |
681 return window; | |
682 } | |
683 | |
15822 | 684 static PurpleRequestUiOps uiops = |
15817 | 685 { |
17091
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16927
diff
changeset
|
686 finch_request_input, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16927
diff
changeset
|
687 finch_request_choice, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16927
diff
changeset
|
688 finch_request_action, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16927
diff
changeset
|
689 finch_request_fields, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16927
diff
changeset
|
690 finch_request_file, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16927
diff
changeset
|
691 finch_close_request, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16927
diff
changeset
|
692 NULL, /* No plans for request_folder */ |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16927
diff
changeset
|
693 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16927
diff
changeset
|
694 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16927
diff
changeset
|
695 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16927
diff
changeset
|
696 NULL |
15817 | 697 }; |
698 | |
15822 | 699 PurpleRequestUiOps *finch_request_get_ui_ops() |
15817 | 700 { |
701 return &uiops; | |
702 } | |
703 | |
704 void finch_request_init() | |
705 { | |
706 } | |
707 | |
708 void finch_request_uninit() | |
709 { | |
710 } | |
711 | |
16310
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
712 void finch_request_save_in_prefs(gpointer null, PurpleRequestFields *allfields) |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
713 { |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
714 GList *list; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
715 for (list = purple_request_fields_get_groups(allfields); list; list = list->next) { |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
716 PurpleRequestFieldGroup *group = list->data; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
717 GList *fields = purple_request_field_group_get_fields(group); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
718 |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
719 for (; fields ; fields = fields->next) { |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
720 PurpleRequestField *field = fields->data; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
721 PurpleRequestFieldType type = purple_request_field_get_type(field); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
722 PurplePrefType pt; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
723 gpointer val = NULL; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
724 const char *id = purple_request_field_get_id(field); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
725 |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
726 switch (type) { |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
727 case PURPLE_REQUEST_FIELD_LIST: |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
728 val = purple_request_field_list_get_selected(field)->data; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
729 break; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
730 case PURPLE_REQUEST_FIELD_BOOLEAN: |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
731 val = GINT_TO_POINTER(purple_request_field_bool_get_value(field)); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
732 break; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
733 case PURPLE_REQUEST_FIELD_INTEGER: |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
734 val = GINT_TO_POINTER(purple_request_field_int_get_value(field)); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
735 break; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
736 case PURPLE_REQUEST_FIELD_STRING: |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
737 val = (gpointer)purple_request_field_string_get_value(field); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
738 break; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
739 default: |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
740 break; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
741 } |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
742 |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
743 pt = purple_prefs_get_type(id); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
744 switch (pt) { |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
745 case PURPLE_PREF_INT: |
17392
a236c67e39b6
A change from o_sukhodolsky:
Richard Laager <rlaager@wiktel.com>
parents:
17091
diff
changeset
|
746 { |
18222
ef65d43190e5
Fix a few runtime warnings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18118
diff
changeset
|
747 long int tmp = GPOINTER_TO_INT(val); |
16310
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
748 if (type == PURPLE_REQUEST_FIELD_LIST) /* Lists always return string */ |
17392
a236c67e39b6
A change from o_sukhodolsky:
Richard Laager <rlaager@wiktel.com>
parents:
17091
diff
changeset
|
749 sscanf(val, "%ld", &tmp); |
a236c67e39b6
A change from o_sukhodolsky:
Richard Laager <rlaager@wiktel.com>
parents:
17091
diff
changeset
|
750 purple_prefs_set_int(id, (gint)tmp); |
16310
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
751 break; |
17392
a236c67e39b6
A change from o_sukhodolsky:
Richard Laager <rlaager@wiktel.com>
parents:
17091
diff
changeset
|
752 } |
16310
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
753 case PURPLE_PREF_BOOLEAN: |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
754 purple_prefs_set_bool(id, GPOINTER_TO_INT(val)); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
755 break; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
756 case PURPLE_PREF_STRING: |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
757 purple_prefs_set_string(id, val); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
758 break; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
759 default: |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
760 break; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
761 } |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
762 } |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
763 } |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
764 } |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
765 |