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