1
|
1 /*****************************************************************************/
|
|
2 /* menu-items.c - menu callbacks */
|
|
3 /* Copyright (C) 1998-2002 Brian Masney <masneyb@gftp.org> */
|
|
4 /* */
|
|
5 /* This program is free software; you can redistribute it and/or modify */
|
|
6 /* it under the terms of the GNU General Public License as published by */
|
|
7 /* the Free Software Foundation; either version 2 of the License, or */
|
|
8 /* (at your option) any later version. */
|
|
9 /* */
|
|
10 /* This program is distributed in the hope that it will be useful, */
|
|
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
|
13 /* GNU General Public License for more details. */
|
|
14 /* */
|
|
15 /* You should have received a copy of the GNU General Public License */
|
|
16 /* along with this program; if not, write to the Free Software */
|
|
17 /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
18 /*****************************************************************************/
|
|
19
|
|
20 #include <gftp-gtk.h>
|
|
21
|
|
22 static void make_proxy_hosts_tab ( GtkWidget * notebook );
|
|
23 static void add_host_to_listbox ( GList * templist );
|
|
24 static void add_proxy_host ( GtkWidget * widget,
|
|
25 gpointer data );
|
|
26 static void add_toggle ( GtkWidget * widget,
|
|
27 gpointer data );
|
|
28 static void add_ok ( GtkWidget * widget,
|
|
29 gpointer data );
|
|
30 static void delete_proxy_host ( GtkWidget * widget,
|
|
31 gpointer data );
|
|
32 static void proxy_toggle ( GtkList * list,
|
|
33 GtkWidget * child,
|
|
34 gpointer data );
|
|
35 static void apply_changes ( GtkWidget * widget,
|
|
36 gpointer data );
|
|
37 static void clean_old_changes ( GtkWidget * widget,
|
|
38 gpointer data );
|
|
39 static char *get_proxy_config ( void );
|
|
40
|
|
41 static GtkWidget * proxy_text, * proxy_list, * new_proxy_domain, * network1,
|
|
42 * network2, * network3, * network4, * netmask1, * netmask2,
|
|
43 * netmask3, * netmask4, * domain_active, * proxy_combo,
|
|
44 * def_proto_combo;
|
|
45 static GList * new_proxy_hosts;
|
|
46 static char *custom_proxy;
|
|
47
|
19
|
48 #if !(GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2)
|
|
49 static void
|
|
50 options_action (GtkWidget * widget, gint response, gpointer user_data)
|
|
51 {
|
|
52 switch (response)
|
|
53 {
|
|
54 case GTK_RESPONSE_APPLY:
|
|
55 apply_changes (widget, NULL);
|
|
56 break;
|
|
57 case GTK_RESPONSE_OK:
|
|
58 apply_changes (widget, NULL);
|
|
59 /* no break */
|
|
60 default:
|
|
61 gtk_widget_destroy (widget);
|
|
62 }
|
|
63 }
|
|
64 #endif
|
|
65
|
|
66
|
1
|
67 void
|
|
68 options_dialog (gpointer data)
|
|
69 {
|
|
70 GtkWidget * dialog, * tempwid, * notebook, * table, * box;
|
|
71 char tempstr[20], *pos, *endpos, *oldstr;
|
|
72 int i, tbl_col, tbl_num, combo_num;
|
|
73 GList * combo_list;
|
|
74
|
19
|
75 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2
|
1
|
76 dialog = gtk_dialog_new ();
|
|
77 gtk_window_set_title (GTK_WINDOW (dialog), _("Options"));
|
|
78 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area),
|
|
79 5);
|
|
80 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 15);
|
|
81 gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->action_area), TRUE);
|
19
|
82 #else
|
|
83 dialog = gtk_dialog_new_with_buttons (_("Options"), NULL, 0,
|
|
84 GTK_STOCK_SAVE,
|
|
85 GTK_RESPONSE_OK,
|
|
86 GTK_STOCK_CANCEL,
|
|
87 GTK_RESPONSE_CANCEL,
|
|
88 GTK_STOCK_APPLY,
|
|
89 GTK_RESPONSE_APPLY,
|
|
90 NULL);
|
|
91 #endif
|
|
92 gtk_window_set_wmclass (GTK_WINDOW(dialog), "options", "gFTP");
|
1
|
93 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
|
19
|
94 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 10);
|
|
95 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2);
|
|
96 gtk_widget_realize (dialog);
|
|
97
|
|
98 if (gftp_icon != NULL)
|
|
99 {
|
|
100 gdk_window_set_icon (dialog->window, NULL, gftp_icon->pixmap,
|
|
101 gftp_icon->bitmap);
|
|
102 gdk_window_set_icon_name (dialog->window, _("gFTP Icon"));
|
|
103 }
|
1
|
104
|
|
105 notebook = gtk_notebook_new ();
|
|
106 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), notebook, TRUE,
|
|
107 TRUE, 0);
|
|
108 gtk_widget_show (notebook);
|
|
109
|
|
110 tbl_num = tbl_col = 0;
|
|
111 table = box = NULL;
|
|
112 for (i=0; config_file_vars[i].key != NULL; i++)
|
|
113 {
|
|
114 if (!config_file_vars[i].shown)
|
|
115 continue;
|
|
116
|
|
117 switch (config_file_vars[i].type)
|
|
118 {
|
|
119 case CONFIG_NOTEBOOK:
|
|
120 box = gtk_vbox_new (FALSE, 0);
|
|
121 gtk_container_border_width (GTK_CONTAINER (box), 10);
|
|
122 gtk_widget_show (box);
|
|
123
|
|
124 tempwid = gtk_label_new (_(config_file_vars[i].description));
|
|
125 gtk_widget_show (tempwid);
|
|
126 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), box, tempwid);
|
|
127 break;
|
|
128 case CONFIG_TABLE:
|
|
129 table = gtk_table_new (1, 2, FALSE);
|
|
130 gtk_table_set_row_spacings (GTK_TABLE (table), 5);
|
|
131 gtk_table_set_col_spacings (GTK_TABLE (table), 5);
|
|
132 gtk_box_pack_start (GTK_BOX (box), table, FALSE, FALSE, 0);
|
|
133 gtk_widget_show (table);
|
|
134 tbl_num = 1;
|
|
135 tbl_col = 0;
|
|
136 break;
|
|
137 case CONFIG_COMBO:
|
|
138 gtk_table_resize (GTK_TABLE (table), tbl_num, 2);
|
|
139
|
|
140 tempwid = gtk_label_new (_(config_file_vars[i].description));
|
|
141 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
142 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1,
|
|
143 tbl_num - 1, tbl_num);
|
|
144 gtk_widget_show (tempwid);
|
|
145
|
|
146 tempwid = gtk_combo_new ();
|
|
147 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 1, 2,
|
|
148 tbl_num - 1, tbl_num);
|
|
149 gtk_widget_show (tempwid);
|
|
150 config_file_vars[i].widget = tempwid;
|
|
151
|
|
152 /* We only have Default Protocol and the Proxy type as the two
|
|
153 combo types. If I add more later on, I'll work on a better
|
|
154 interface for all this stuff */
|
|
155 if (strcmp (config_file_vars[i].comment, "DP") == 0)
|
|
156 def_proto_combo = tempwid;
|
|
157 else
|
|
158 proxy_combo = tempwid;
|
|
159
|
|
160 tbl_num++;
|
|
161 break;
|
|
162 case CONFIG_TEXT:
|
|
163 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2
|
|
164 proxy_text = gtk_text_new (NULL, NULL);
|
|
165 gtk_text_set_editable (GTK_TEXT (proxy_text), TRUE);
|
|
166 #else
|
|
167 proxy_text = gtk_text_view_new ();
|
|
168 gtk_text_view_set_editable (GTK_TEXT_VIEW (proxy_text), TRUE);
|
|
169 #endif
|
|
170 gtk_widget_set_size_request (proxy_text, -1, 75);
|
|
171 gtk_table_attach_defaults (GTK_TABLE (table), proxy_text, 0, 2,
|
|
172 tbl_num - 1, tbl_num);
|
|
173 gtk_widget_show (proxy_text);
|
|
174 config_file_vars[i].widget = proxy_text;
|
|
175
|
|
176 tbl_num++;
|
|
177 break;
|
|
178 case CONFIG_CHARTEXT:
|
|
179 case CONFIG_CHARPASS:
|
|
180 case CONFIG_INTTEXT:
|
|
181 case CONFIG_UINTTEXT:
|
|
182 case CONFIG_FLOATTEXT:
|
|
183 gtk_table_resize (GTK_TABLE (table), tbl_num, 2);
|
|
184
|
|
185 tempwid = gtk_label_new (_(config_file_vars[i].description));
|
|
186 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
187 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1,
|
|
188 tbl_num - 1, tbl_num);
|
|
189 gtk_widget_show (tempwid);
|
|
190
|
|
191 tempwid = gtk_entry_new ();
|
|
192 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 1, 2,
|
|
193 tbl_num - 1, tbl_num);
|
|
194
|
|
195 switch (config_file_vars[i].type)
|
|
196 {
|
|
197 case CONFIG_INTTEXT:
|
|
198 case CONFIG_UINTTEXT:
|
|
199 g_snprintf (tempstr, sizeof (tempstr), "%d",
|
|
200 *(int *) config_file_vars[i].var);
|
|
201 gtk_entry_set_text (GTK_ENTRY (tempwid), tempstr);
|
|
202 break;
|
|
203 case CONFIG_FLOATTEXT:
|
|
204 g_snprintf (tempstr, sizeof (tempstr), "%.2f",
|
|
205 *(double *) config_file_vars[i].var);
|
|
206 gtk_entry_set_text (GTK_ENTRY (tempwid), tempstr);
|
|
207 break;
|
|
208 case CONFIG_CHARTEXT:
|
|
209 gtk_entry_set_text (GTK_ENTRY (tempwid),
|
|
210 *(char **) config_file_vars[i].var);
|
|
211 break;
|
|
212 case CONFIG_CHARPASS:
|
|
213 gtk_entry_set_text (GTK_ENTRY (tempwid),
|
|
214 *(char **) config_file_vars[i].var);
|
|
215 gtk_entry_set_visibility (GTK_ENTRY (tempwid), 0);
|
|
216 break;
|
|
217 }
|
|
218 gtk_widget_show (tempwid);
|
|
219 config_file_vars[i].widget = tempwid;
|
|
220 tbl_num++;
|
|
221 break;
|
|
222 case CONFIG_CHECKBOX:
|
|
223 tempwid = gtk_check_button_new_with_label (
|
|
224 _(config_file_vars[i].description));
|
|
225 gtk_table_attach_defaults (GTK_TABLE (table), tempwid,
|
|
226 tbl_col, tbl_col + 1, tbl_num, tbl_num + 1);
|
|
227 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tempwid),
|
|
228 *(int *) config_file_vars[i].var);
|
|
229 gtk_widget_show (tempwid);
|
|
230 config_file_vars[i].widget = tempwid;
|
|
231 tbl_col++;
|
|
232 if (tbl_col == 2)
|
|
233 {
|
|
234 tbl_col = 0;
|
|
235 tbl_num++;
|
|
236 gtk_table_resize (GTK_TABLE (table), tbl_num + 1, 2);
|
|
237 }
|
|
238 break;
|
|
239 case CONFIG_LABEL:
|
|
240 tempwid = gtk_label_new (_(config_file_vars[i].description));
|
|
241 gtk_misc_set_alignment (GTK_MISC (tempwid), tbl_col, 0.5);
|
|
242 gtk_table_attach_defaults (GTK_TABLE (table), tempwid,
|
|
243 tbl_col, tbl_col + 1, tbl_num, tbl_num + 1);
|
|
244 gtk_widget_show (tempwid);
|
|
245 config_file_vars[i].widget = tempwid;
|
|
246 tbl_col++;
|
|
247 if (tbl_col == 2)
|
|
248 {
|
|
249 tbl_col = 0;
|
|
250 tbl_num++;
|
|
251 gtk_table_resize (GTK_TABLE (table), tbl_num + 1, 2);
|
|
252 }
|
|
253 break;
|
|
254 }
|
|
255 }
|
|
256
|
|
257 combo_num = 0;
|
|
258 combo_list = NULL;
|
|
259 for (i = 0; gftp_protocols[i].name != NULL; i++)
|
|
260 {
|
|
261 if (strcmp (default_protocol, gftp_protocols[i].name) == 0)
|
|
262 combo_num = i;
|
|
263 tempwid = gtk_list_item_new_with_label (gftp_protocols[i].name);
|
|
264 gtk_widget_show (tempwid);
|
|
265 combo_list = g_list_append (combo_list, tempwid);
|
|
266 }
|
|
267 gtk_list_prepend_items (GTK_LIST (GTK_COMBO (def_proto_combo)->list),
|
|
268 combo_list);
|
|
269 gtk_list_select_item (GTK_LIST (GTK_COMBO (def_proto_combo)->list),
|
|
270 combo_num);
|
|
271
|
|
272 combo_list = NULL;
|
|
273 for (i = 0; proxy_type[i].key != NULL; i++)
|
|
274 {
|
|
275 tempwid = gtk_list_item_new_with_label (_(proxy_type[i].key));
|
|
276 gtk_widget_show (tempwid);
|
|
277 combo_list = g_list_append (combo_list, tempwid);
|
|
278 }
|
|
279 gtk_list_prepend_items (GTK_LIST (GTK_COMBO (proxy_combo)->list), combo_list);
|
|
280 combo_list = NULL;
|
|
281
|
|
282 custom_proxy = g_malloc0 (1);
|
|
283 if (proxy_config == NULL || *proxy_config == '\0')
|
|
284 combo_num = 0;
|
|
285 else
|
|
286 {
|
|
287 pos = proxy_config;
|
|
288 while ((endpos = strstr (pos, "%n")))
|
|
289 {
|
|
290 *endpos = '\0';
|
|
291 oldstr = custom_proxy;
|
|
292 custom_proxy = g_strconcat (custom_proxy, pos, "\n", NULL);
|
|
293 g_free (oldstr);
|
|
294 *endpos = '%';
|
|
295 pos = endpos + 2;
|
|
296 }
|
|
297
|
|
298 for (combo_num = 1; combo_num < GFTP_CUSTOM_PROXY_NUM; combo_num++)
|
|
299 {
|
|
300 if (strcmp (proxy_type[combo_num].description, custom_proxy) == 0)
|
|
301 break;
|
|
302 }
|
|
303 }
|
|
304
|
|
305 gtk_signal_connect (GTK_OBJECT (GTK_COMBO (proxy_combo)->list),
|
|
306 "select_child", GTK_SIGNAL_FUNC (proxy_toggle), NULL);
|
|
307 gtk_list_select_item (GTK_LIST (GTK_COMBO (proxy_combo)->list), combo_num);
|
|
308
|
|
309 make_proxy_hosts_tab (notebook);
|
|
310
|
19
|
311 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2
|
1
|
312 tempwid = gtk_button_new_with_label (_("OK"));
|
|
313 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
314 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid,
|
|
315 TRUE, TRUE, 0);
|
|
316 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
|
317 GTK_SIGNAL_FUNC (apply_changes), NULL);
|
|
318 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked",
|
|
319 GTK_SIGNAL_FUNC (gtk_widget_destroy),
|
|
320 GTK_OBJECT (dialog));
|
|
321 gtk_widget_show (tempwid);
|
|
322
|
|
323 tempwid = gtk_button_new_with_label (_(" Cancel "));
|
|
324 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
325 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid,
|
|
326 TRUE, TRUE, 0);
|
|
327 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
|
328 GTK_SIGNAL_FUNC (clean_old_changes), NULL);
|
|
329 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked",
|
|
330 GTK_SIGNAL_FUNC (gtk_widget_destroy),
|
|
331 GTK_OBJECT (dialog));
|
|
332 gtk_widget_show (tempwid);
|
|
333
|
|
334 tempwid = gtk_button_new_with_label (_("Apply"));
|
|
335 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
336 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid,
|
|
337 TRUE, TRUE, 0);
|
|
338 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
|
339 GTK_SIGNAL_FUNC (apply_changes), NULL);
|
|
340 gtk_widget_grab_default (tempwid);
|
|
341 gtk_widget_show (tempwid);
|
19
|
342 #else
|
|
343 g_signal_connect (GTK_OBJECT (dialog), "response",
|
|
344 G_CALLBACK (options_action), NULL);
|
|
345 #endif
|
1
|
346
|
|
347 gtk_widget_show (dialog);
|
|
348 }
|
|
349
|
|
350
|
|
351 static void
|
|
352 make_proxy_hosts_tab (GtkWidget * notebook)
|
|
353 {
|
|
354 GtkWidget *tempwid, *box, *hbox, *scroll;
|
|
355 gftp_proxy_hosts *hosts, *newhosts;
|
|
356 char *add_data[2];
|
|
357 GList *templist;
|
|
358
|
|
359 add_data[0] = _("Network");
|
|
360 add_data[1] = _("Netmask");
|
|
361
|
|
362 box = gtk_vbox_new (FALSE, 5);
|
|
363 gtk_container_border_width (GTK_CONTAINER (box), 10);
|
|
364 gtk_widget_show (box);
|
|
365
|
|
366 tempwid = gtk_label_new (_("Local Hosts"));
|
|
367 gtk_widget_show (tempwid);
|
|
368 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), box, tempwid);
|
|
369
|
|
370 scroll = gtk_scrolled_window_new (NULL, NULL);
|
|
371 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
|
|
372 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
373 gtk_box_pack_start (GTK_BOX (box), scroll, TRUE, TRUE, 0);
|
|
374
|
|
375 proxy_list = gtk_clist_new_with_titles (2, add_data);
|
|
376 gtk_container_add (GTK_CONTAINER (scroll), proxy_list);
|
|
377 gtk_clist_set_column_auto_resize (GTK_CLIST (proxy_list), 0, TRUE);
|
|
378 gtk_clist_set_column_auto_resize (GTK_CLIST (proxy_list), 1, TRUE);
|
|
379 gtk_widget_show (proxy_list);
|
|
380 gtk_widget_show (scroll);
|
|
381
|
|
382 hbox = gtk_hbox_new (TRUE, 15);
|
|
383 gtk_box_pack_start (GTK_BOX (box), hbox, FALSE, FALSE, 0);
|
|
384 gtk_widget_show (hbox);
|
|
385
|
|
386 tempwid = gtk_button_new_with_label (_("Add"));
|
|
387 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
388 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0);
|
|
389 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
|
390 GTK_SIGNAL_FUNC (add_proxy_host), NULL);
|
|
391 gtk_widget_show (tempwid);
|
|
392
|
|
393 tempwid = gtk_button_new_with_label (_("Edit"));
|
|
394 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
395 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0);
|
|
396 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
|
397 GTK_SIGNAL_FUNC (add_proxy_host), (gpointer) 1);
|
|
398 gtk_widget_show (tempwid);
|
|
399
|
|
400 tempwid = gtk_button_new_with_label (_("Delete"));
|
|
401 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
402 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0);
|
|
403 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
|
404 GTK_SIGNAL_FUNC (delete_proxy_host), NULL);
|
|
405 gtk_widget_show (tempwid);
|
|
406
|
|
407 new_proxy_hosts = NULL;
|
|
408 for (templist = proxy_hosts; templist != NULL;
|
|
409 templist = templist->next)
|
|
410 {
|
|
411 hosts = templist->data;
|
|
412 newhosts = g_malloc (sizeof (*newhosts));
|
|
413 memcpy (newhosts, hosts, sizeof (*newhosts));
|
|
414 if (newhosts->domain)
|
|
415 {
|
|
416 newhosts->domain = g_malloc (strlen (hosts->domain) + 1);
|
|
417 strcpy (newhosts->domain, hosts->domain);
|
|
418 }
|
|
419 new_proxy_hosts = g_list_prepend (new_proxy_hosts, newhosts);
|
|
420 add_host_to_listbox (new_proxy_hosts);
|
|
421 }
|
|
422 }
|
|
423
|
|
424
|
|
425 static void
|
|
426 add_host_to_listbox (GList * templist)
|
|
427 {
|
|
428 gftp_proxy_hosts *hosts;
|
|
429 char *add_data[2];
|
|
430 int num;
|
|
431
|
|
432 hosts = templist->data;
|
|
433 if (hosts->domain)
|
|
434 {
|
|
435 add_data[0] = hosts->domain;
|
|
436 add_data[1] = NULL;
|
|
437 num = gtk_clist_append (GTK_CLIST (proxy_list), add_data);
|
|
438 }
|
|
439 else
|
|
440 {
|
|
441 add_data[0] = g_strdup_printf ("%d.%d.%d.%d",
|
|
442 hosts->ipv4_network_address >> 24 & 0xff,
|
|
443 hosts->ipv4_network_address >> 16 & 0xff,
|
|
444 hosts->ipv4_network_address >> 8 & 0xff,
|
|
445 hosts->ipv4_network_address & 0xff);
|
|
446 add_data[1] = g_strdup_printf ("%d.%d.%d.%d",
|
|
447 hosts->ipv4_netmask >> 24 & 0xff,
|
|
448 hosts->ipv4_netmask >> 16 & 0xff,
|
|
449 hosts->ipv4_netmask >> 8 & 0xff,
|
|
450 hosts->ipv4_netmask & 0xff);
|
|
451 num = gtk_clist_append (GTK_CLIST (proxy_list), add_data);
|
|
452 g_free (add_data[0]);
|
|
453 g_free (add_data[1]);
|
|
454 }
|
|
455 gtk_clist_set_row_data (GTK_CLIST (proxy_list), num, (gpointer) templist);
|
|
456 }
|
|
457
|
|
458
|
19
|
459 #if !(GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2)
|
|
460 static void
|
|
461 proxyhosts_action (GtkWidget * widget, gint response, gpointer user_data)
|
|
462 {
|
|
463 switch (response)
|
|
464 {
|
|
465 case GTK_RESPONSE_OK:
|
|
466 add_ok (widget, user_data);
|
|
467 /* no break */
|
|
468 default:
|
|
469 gtk_widget_destroy (widget);
|
|
470 }
|
|
471 }
|
|
472 #endif
|
|
473
|
|
474
|
1
|
475 static void
|
|
476 add_proxy_host (GtkWidget * widget, gpointer data)
|
|
477 {
|
|
478 GtkWidget *tempwid, *dialog, *frame, *box, *table;
|
|
479 gftp_proxy_hosts *hosts;
|
19
|
480 char *tempstr, *title;
|
1
|
481 GList *templist;
|
|
482
|
|
483 if (data)
|
|
484 {
|
|
485 if ((templist = GTK_CLIST (proxy_list)->selection) == NULL)
|
|
486 return;
|
|
487 templist = gtk_clist_get_row_data (GTK_CLIST (proxy_list),
|
|
488 (int) templist->data);
|
|
489 hosts = templist->data;
|
|
490 }
|
|
491 else
|
|
492 {
|
|
493 hosts = NULL;
|
|
494 templist = NULL;
|
|
495 }
|
|
496
|
19
|
497 title = hosts ? _("Edit Host") : _("Add Host");
|
|
498 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2
|
1
|
499 dialog = gtk_dialog_new ();
|
19
|
500 gtk_window_set_title (GTK_WINDOW (dialog), title);
|
1
|
501 gtk_container_border_width (GTK_CONTAINER
|
|
502 (GTK_DIALOG (dialog)->action_area), 5);
|
|
503 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 15);
|
|
504 gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->action_area), TRUE);
|
19
|
505 gtk_grab_add (dialog);
|
|
506 #else
|
|
507 dialog = gtk_dialog_new_with_buttons (title, NULL, 0,
|
|
508 GTK_STOCK_SAVE,
|
|
509 GTK_RESPONSE_OK,
|
|
510 GTK_STOCK_CANCEL,
|
|
511 GTK_RESPONSE_CANCEL,
|
|
512 NULL);
|
|
513 #endif
|
|
514 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 10);
|
|
515 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2);
|
|
516 gtk_window_set_wmclass (GTK_WINDOW(dialog), "hostinfo", "Gftp");
|
1
|
517 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
|
|
518
|
|
519 frame = gtk_frame_new (NULL);
|
|
520 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), frame, TRUE, TRUE,
|
|
521 0);
|
|
522 gtk_widget_show (frame);
|
|
523
|
|
524 box = gtk_hbox_new (FALSE, 5);
|
|
525 gtk_container_border_width (GTK_CONTAINER (box), 5);
|
|
526 gtk_container_add (GTK_CONTAINER (frame), box);
|
|
527 gtk_widget_show (box);
|
|
528
|
|
529 tempwid = gtk_label_new (_("Domain"));
|
|
530 gtk_box_pack_start (GTK_BOX (box), tempwid, TRUE, TRUE, 0);
|
|
531 gtk_widget_show (tempwid);
|
|
532
|
|
533 new_proxy_domain = gtk_entry_new ();
|
|
534 gtk_box_pack_start (GTK_BOX (box), new_proxy_domain, TRUE, TRUE, 0);
|
|
535 gtk_widget_show (new_proxy_domain);
|
|
536
|
|
537 frame = gtk_frame_new (NULL);
|
|
538 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), frame, TRUE, TRUE,
|
|
539 0);
|
|
540 gtk_widget_show (frame);
|
|
541
|
|
542 table = gtk_table_new (4, 2, FALSE);
|
|
543 gtk_container_border_width (GTK_CONTAINER (table), 5);
|
|
544 gtk_table_set_row_spacings (GTK_TABLE (table), 5);
|
|
545 gtk_table_set_col_spacings (GTK_TABLE (table), 5);
|
|
546 gtk_container_add (GTK_CONTAINER (frame), table);
|
|
547 gtk_widget_show (table);
|
|
548
|
|
549 tempwid = gtk_label_new (_("Network Address"));
|
|
550 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
551 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 0, 1);
|
|
552 gtk_widget_show (tempwid);
|
|
553
|
|
554 box = gtk_hbox_new (FALSE, 5);
|
|
555 gtk_table_attach_defaults (GTK_TABLE (table), box, 1, 2, 0, 1);
|
|
556 gtk_widget_show (box);
|
|
557
|
|
558 network1 = gtk_entry_new ();
|
|
559 gtk_widget_set_size_request (network1, 28, -1);
|
|
560
|
|
561 gtk_box_pack_start (GTK_BOX (box), network1, TRUE, TRUE, 0);
|
|
562 gtk_widget_show (network1);
|
|
563
|
|
564 network2 = gtk_entry_new ();
|
|
565 gtk_widget_set_size_request (network2, 28, -1);
|
|
566
|
|
567 gtk_box_pack_start (GTK_BOX (box), network2, TRUE, TRUE, 0);
|
|
568 gtk_widget_show (network2);
|
|
569
|
|
570 network3 = gtk_entry_new ();
|
|
571 gtk_widget_set_size_request (network3, 28, -1);
|
|
572
|
|
573 gtk_box_pack_start (GTK_BOX (box), network3, TRUE, TRUE, 0);
|
|
574 gtk_widget_show (network3);
|
|
575
|
|
576 network4 = gtk_entry_new ();
|
|
577 gtk_widget_set_size_request (network4, 28, -1);
|
|
578
|
|
579 gtk_box_pack_start (GTK_BOX (box), network4, TRUE, TRUE, 0);
|
|
580 gtk_widget_show (network4);
|
|
581
|
|
582 tempwid = gtk_label_new (_("Netmask"));
|
|
583 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
584 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 1, 2);
|
|
585 gtk_widget_show (tempwid);
|
|
586
|
|
587 box = gtk_hbox_new (FALSE, 5);
|
|
588 gtk_table_attach_defaults (GTK_TABLE (table), box, 1, 2, 1, 2);
|
|
589 gtk_widget_show (box);
|
|
590
|
|
591 netmask1 = gtk_entry_new ();
|
|
592 gtk_widget_set_size_request (netmask1, 28, -1);
|
|
593
|
|
594 gtk_box_pack_start (GTK_BOX (box), netmask1, TRUE, TRUE, 0);
|
|
595 gtk_widget_show (netmask1);
|
|
596
|
|
597 netmask2 = gtk_entry_new ();
|
|
598 gtk_widget_set_size_request (netmask2, 28, -1);
|
|
599
|
|
600 gtk_box_pack_start (GTK_BOX (box), netmask2, TRUE, TRUE, 0);
|
|
601 gtk_widget_show (netmask2);
|
|
602
|
|
603 netmask3 = gtk_entry_new ();
|
|
604 gtk_widget_set_size_request (netmask3, 28, -1);
|
|
605
|
|
606 gtk_box_pack_start (GTK_BOX (box), netmask3, TRUE, TRUE, 0);
|
|
607 gtk_widget_show (netmask3);
|
|
608
|
|
609 netmask4 = gtk_entry_new ();
|
|
610 gtk_widget_set_size_request (netmask4, 28, -1);
|
|
611
|
|
612 gtk_box_pack_start (GTK_BOX (box), netmask4, TRUE, TRUE, 0);
|
|
613 gtk_widget_show (netmask4);
|
|
614
|
|
615 box = gtk_hbox_new (FALSE, 5);
|
|
616 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), box, TRUE, TRUE,
|
|
617 0);
|
|
618 gtk_widget_show (box);
|
|
619
|
|
620 domain_active = gtk_radio_button_new_with_label (NULL, _("Domain"));
|
|
621 gtk_signal_connect (GTK_OBJECT (domain_active), "toggled",
|
|
622 GTK_SIGNAL_FUNC (add_toggle), (gpointer) 1);
|
|
623 gtk_box_pack_start (GTK_BOX (box), domain_active, TRUE, TRUE, 0);
|
|
624 gtk_widget_show (domain_active);
|
|
625
|
|
626 tempwid = gtk_radio_button_new_with_label (gtk_radio_button_group
|
|
627 (GTK_RADIO_BUTTON (domain_active)),
|
|
628 _("Network"));
|
|
629 gtk_signal_connect (GTK_OBJECT (tempwid), "toggled",
|
|
630 GTK_SIGNAL_FUNC (add_toggle), NULL);
|
|
631 gtk_box_pack_start (GTK_BOX (box), tempwid, TRUE, TRUE, 0);
|
|
632 gtk_widget_show (tempwid);
|
|
633
|
|
634 if (!hosts || !hosts->domain)
|
|
635 {
|
|
636 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tempwid), TRUE);
|
|
637 add_toggle (NULL, NULL);
|
|
638 }
|
|
639 else
|
|
640 {
|
|
641 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (domain_active), TRUE);
|
|
642 add_toggle (NULL, (gpointer) 1);
|
|
643 }
|
|
644
|
|
645 if (hosts)
|
|
646 {
|
|
647 if (hosts->domain)
|
|
648 gtk_entry_set_text (GTK_ENTRY (new_proxy_domain), hosts->domain);
|
|
649 else
|
|
650 {
|
|
651 tempstr = g_strdup_printf ("%d", hosts->ipv4_network_address >> 24 & 0xff);
|
|
652 gtk_entry_set_text (GTK_ENTRY (network1), tempstr);
|
|
653 g_free (tempstr);
|
|
654
|
|
655 tempstr = g_strdup_printf ("%d", hosts->ipv4_network_address >> 16 & 0xff);
|
|
656 gtk_entry_set_text (GTK_ENTRY (network2), tempstr);
|
|
657 g_free (tempstr);
|
|
658
|
|
659 tempstr = g_strdup_printf ("%d", hosts->ipv4_network_address >> 8 & 0xff);
|
|
660 gtk_entry_set_text (GTK_ENTRY (network3), tempstr);
|
|
661 g_free (tempstr);
|
|
662
|
|
663 tempstr = g_strdup_printf ("%d", hosts->ipv4_network_address & 0xff);
|
|
664 gtk_entry_set_text (GTK_ENTRY (network4), tempstr);
|
|
665 g_free (tempstr);
|
|
666
|
|
667 tempstr = g_strdup_printf ("%d", hosts->ipv4_netmask >> 24 & 0xff);
|
|
668 gtk_entry_set_text (GTK_ENTRY (netmask1), tempstr);
|
|
669 g_free (tempstr);
|
|
670
|
|
671 tempstr = g_strdup_printf ("%d", hosts->ipv4_netmask >> 16 & 0xff);
|
|
672 gtk_entry_set_text (GTK_ENTRY (netmask2), tempstr);
|
|
673 g_free (tempstr);
|
|
674
|
|
675 tempstr = g_strdup_printf ("%d", hosts->ipv4_netmask >> 8 & 0xff);
|
|
676 gtk_entry_set_text (GTK_ENTRY (netmask3), tempstr);
|
|
677 g_free (tempstr);
|
|
678
|
|
679 tempstr = g_strdup_printf ("%d", hosts->ipv4_netmask & 0xff);
|
|
680 gtk_entry_set_text (GTK_ENTRY (netmask4), tempstr);
|
|
681 g_free (tempstr);
|
|
682 }
|
|
683 }
|
|
684
|
19
|
685 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2
|
1
|
686 tempwid = gtk_button_new_with_label (_("OK"));
|
|
687 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
688 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid,
|
|
689 TRUE, TRUE, 0);
|
|
690 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
|
691 GTK_SIGNAL_FUNC (add_ok), (gpointer) templist);
|
|
692 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked",
|
|
693 GTK_SIGNAL_FUNC (gtk_widget_destroy),
|
|
694 GTK_OBJECT (dialog));
|
|
695 gtk_widget_show (tempwid);
|
|
696
|
|
697 tempwid = gtk_button_new_with_label (_(" Cancel "));
|
|
698 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
699 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid,
|
|
700 TRUE, TRUE, 0);
|
|
701 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked",
|
|
702 GTK_SIGNAL_FUNC (gtk_widget_destroy),
|
|
703 GTK_OBJECT (dialog));
|
|
704 gtk_widget_show (tempwid);
|
19
|
705 #else
|
|
706 g_signal_connect (GTK_OBJECT (dialog), "response",
|
|
707 G_CALLBACK (proxyhosts_action), NULL);
|
|
708 #endif
|
1
|
709
|
|
710 gtk_widget_show (dialog);
|
|
711 }
|
|
712
|
|
713
|
|
714 static void
|
|
715 add_toggle (GtkWidget * widget, gpointer data)
|
|
716 {
|
|
717 gtk_widget_set_sensitive (new_proxy_domain, data != NULL);
|
|
718 gtk_widget_set_sensitive (network1, data == NULL);
|
|
719 gtk_widget_set_sensitive (network2, data == NULL);
|
|
720 gtk_widget_set_sensitive (network3, data == NULL);
|
|
721 gtk_widget_set_sensitive (network4, data == NULL);
|
|
722 gtk_widget_set_sensitive (netmask1, data == NULL);
|
|
723 gtk_widget_set_sensitive (netmask2, data == NULL);
|
|
724 gtk_widget_set_sensitive (netmask3, data == NULL);
|
|
725 gtk_widget_set_sensitive (netmask4, data == NULL);
|
|
726 }
|
|
727
|
|
728
|
|
729 static void
|
|
730 add_ok (GtkWidget * widget, gpointer data)
|
|
731 {
|
|
732 gftp_proxy_hosts *hosts;
|
|
733 const char *edttxt;
|
|
734 GList *templist;
|
|
735 int num;
|
|
736
|
|
737 if ((templist = data) == NULL)
|
|
738 {
|
|
739 hosts = g_malloc0 (sizeof (*hosts));
|
|
740 new_proxy_hosts = g_list_append (new_proxy_hosts, hosts);
|
|
741 for (templist = new_proxy_hosts; templist->next != NULL;
|
|
742 templist = templist->next);
|
|
743 }
|
|
744 else
|
|
745 {
|
|
746 num = gtk_clist_find_row_from_data (GTK_CLIST (proxy_list), templist);
|
|
747 if (num != -1)
|
|
748 gtk_clist_remove (GTK_CLIST (proxy_list), num);
|
|
749 hosts = templist->data;
|
|
750 }
|
|
751
|
|
752 if (hosts->domain)
|
|
753 {
|
|
754 g_free (hosts->domain);
|
|
755 hosts->domain = NULL;
|
|
756 }
|
|
757
|
|
758 if (GTK_TOGGLE_BUTTON (domain_active)->active)
|
|
759 {
|
|
760 edttxt = gtk_entry_get_text (GTK_ENTRY (new_proxy_domain));
|
|
761 hosts->domain = g_malloc (strlen (edttxt) + 1);
|
|
762 strcpy (hosts->domain, edttxt);
|
|
763 hosts->ipv4_netmask = hosts->ipv4_network_address = 0;
|
|
764 }
|
|
765 else
|
|
766 {
|
|
767 edttxt = gtk_entry_get_text (GTK_ENTRY (network1));
|
|
768 hosts->ipv4_network_address = (strtol (edttxt, NULL, 10) & 0xff) << 24;
|
|
769
|
|
770 edttxt = gtk_entry_get_text (GTK_ENTRY (network2));
|
|
771 hosts->ipv4_network_address |= (strtol (edttxt, NULL, 10) & 0xff) << 16;
|
|
772
|
|
773 edttxt = gtk_entry_get_text (GTK_ENTRY (network3));
|
|
774 hosts->ipv4_network_address |= (strtol (edttxt, NULL, 10) & 0xff) << 8;
|
|
775
|
|
776 edttxt = gtk_entry_get_text (GTK_ENTRY (network4));
|
|
777 hosts->ipv4_network_address |= strtol (edttxt, NULL, 10) & 0xff;
|
|
778
|
|
779 edttxt = gtk_entry_get_text (GTK_ENTRY (netmask1));
|
|
780 hosts->ipv4_netmask = (strtol (edttxt, NULL, 10) & 0xff) << 24;
|
|
781
|
|
782 edttxt = gtk_entry_get_text (GTK_ENTRY (netmask2));
|
|
783 hosts->ipv4_netmask |= (strtol (edttxt, NULL, 10) & 0xff) << 16;
|
|
784
|
|
785 edttxt = gtk_entry_get_text (GTK_ENTRY (netmask3));
|
|
786 hosts->ipv4_netmask |= (strtol (edttxt, NULL, 10) & 0xff) << 8;
|
|
787
|
|
788 edttxt = gtk_entry_get_text (GTK_ENTRY (netmask4));
|
|
789 hosts->ipv4_netmask |= strtol (edttxt, NULL, 10) & 0xff;
|
|
790 }
|
|
791 add_host_to_listbox (templist);
|
|
792 }
|
|
793
|
|
794
|
|
795 static void
|
|
796 delete_proxy_host (GtkWidget * widget, gpointer data)
|
|
797 {
|
|
798 GList *templist;
|
|
799 int num;
|
|
800
|
|
801 if ((templist = GTK_CLIST (proxy_list)->selection) == NULL)
|
|
802 return;
|
|
803 num = (int) templist->data;
|
|
804 templist = gtk_clist_get_row_data (GTK_CLIST (proxy_list), num);
|
|
805 new_proxy_hosts = g_list_remove_link (new_proxy_hosts, templist);
|
|
806 gtk_clist_remove (GTK_CLIST (proxy_list), num);
|
|
807 }
|
|
808
|
|
809
|
|
810 static void
|
|
811 proxy_toggle (GtkList * list, GtkWidget * child, gpointer data)
|
|
812 {
|
|
813 int proxy_num;
|
|
814 char *str;
|
|
815
|
|
816 #if !(GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2)
|
|
817 GtkTextIter iter, iter2;
|
|
818 GtkTextBuffer * textbuf;
|
|
819 guint len;
|
|
820 #endif
|
|
821
|
|
822 proxy_num = gtk_list_child_position (list, child);
|
|
823 if (proxy_num == GFTP_CUSTOM_PROXY_NUM)
|
|
824 str = custom_proxy;
|
|
825 else
|
|
826 str = proxy_type[proxy_num].description;
|
|
827
|
|
828 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2
|
|
829 gtk_text_set_point (GTK_TEXT (proxy_text), 0);
|
|
830 gtk_text_forward_delete (GTK_TEXT (proxy_text),
|
|
831 gtk_text_get_length (GTK_TEXT (proxy_text)));
|
|
832
|
|
833 gtk_text_insert (GTK_TEXT (proxy_text), NULL, NULL, NULL, str, -1);
|
|
834 #else
|
|
835 textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (proxy_text));
|
|
836 len = gtk_text_buffer_get_char_count (textbuf);
|
|
837 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0);
|
|
838 gtk_text_buffer_get_iter_at_offset (textbuf, &iter2, len - 1);
|
|
839 gtk_text_buffer_delete (textbuf, &iter, &iter2);
|
|
840
|
|
841 len = gtk_text_buffer_get_char_count (textbuf);
|
|
842 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, len - 1);
|
|
843 gtk_text_buffer_insert (textbuf, &iter, str, -1);
|
|
844 #endif
|
|
845 }
|
|
846
|
|
847
|
|
848 static void
|
|
849 apply_changes (GtkWidget * widget, gpointer data)
|
|
850 {
|
|
851 const char *tempstr;
|
|
852 int num, found, i;
|
|
853 GList *templist;
|
|
854
|
|
855 for (num = 0; config_file_vars[num].var != NULL; num++)
|
|
856 {
|
|
857 if (config_file_vars[num].widget != NULL)
|
|
858 {
|
|
859 switch (config_file_vars[num].type)
|
|
860 {
|
|
861 case CONFIG_CHECKBOX:
|
|
862 *(int *) config_file_vars[num].var =
|
|
863 GTK_TOGGLE_BUTTON (config_file_vars[num].widget)->active;
|
|
864 break;
|
|
865 case CONFIG_INTTEXT:
|
|
866 case CONFIG_UINTTEXT:
|
|
867 tempstr = gtk_entry_get_text (
|
|
868 GTK_ENTRY (config_file_vars[num].widget));
|
|
869 *(int *) config_file_vars[num].var = strtol (tempstr, NULL, 10);
|
|
870 break;
|
|
871 case CONFIG_FLOATTEXT:
|
|
872 tempstr = gtk_entry_get_text (
|
|
873 GTK_ENTRY (config_file_vars[num].widget));
|
|
874 *(double *) config_file_vars[num].var = strtod (tempstr, NULL);
|
|
875 break;
|
|
876 case CONFIG_CHARTEXT:
|
|
877 case CONFIG_CHARPASS:
|
|
878 tempstr = gtk_entry_get_text (
|
|
879 GTK_ENTRY (config_file_vars[num].widget));
|
|
880 g_free (*(char **) config_file_vars[num].var);
|
|
881 *(char **) config_file_vars[num].var =
|
|
882 g_malloc (strlen (tempstr) + 1);
|
|
883 strcpy (*(char **) config_file_vars[num].var, tempstr);
|
|
884 break;
|
|
885 }
|
|
886 }
|
|
887 }
|
|
888
|
|
889 tempstr = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (def_proto_combo)->entry));
|
|
890 found = 0;
|
|
891 for (i = 0; gftp_protocols[i].name; i++)
|
|
892 {
|
|
893 if (strcmp (gftp_protocols[i].name, tempstr) == 0)
|
|
894 {
|
|
895 found = 1;
|
|
896 break;
|
|
897 }
|
|
898 }
|
|
899
|
|
900 if (found)
|
|
901 {
|
|
902 g_free (default_protocol);
|
|
903 default_protocol = g_strconcat (tempstr, NULL);
|
|
904 }
|
|
905
|
|
906 templist = proxy_hosts;
|
|
907 proxy_hosts = new_proxy_hosts;
|
|
908 new_proxy_hosts = templist;
|
|
909 clean_old_changes (NULL, NULL);
|
|
910
|
|
911 if (proxy_config != NULL)
|
|
912 g_free (proxy_config);
|
|
913 proxy_config = get_proxy_config ();
|
|
914
|
|
915 gftp_write_config_file ();
|
|
916 }
|
|
917
|
|
918
|
|
919 static void
|
|
920 clean_old_changes (GtkWidget * widget, gpointer data)
|
|
921 {
|
|
922 gftp_proxy_hosts *hosts;
|
|
923 GList *templist;
|
|
924
|
|
925 templist = new_proxy_hosts;
|
|
926 while (templist != NULL)
|
|
927 {
|
|
928 hosts = templist->data;
|
|
929 if (hosts->domain)
|
|
930 g_free (hosts->domain);
|
|
931 g_free (hosts);
|
|
932 templist = templist->next;
|
|
933 }
|
|
934 g_list_free (new_proxy_hosts);
|
|
935 new_proxy_hosts = NULL;
|
|
936
|
|
937 if (custom_proxy != NULL)
|
|
938 {
|
|
939 g_free (custom_proxy);
|
|
940 custom_proxy = NULL;
|
|
941 }
|
|
942 }
|
|
943
|
|
944
|
|
945 static char *
|
|
946 get_proxy_config (void)
|
|
947 {
|
|
948 char *newstr, *oldstr, *pos, *endpos, *textstr;
|
|
949 guint len;
|
|
950 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2
|
|
951 char tmp[128];
|
|
952 #else
|
|
953 GtkTextBuffer * textbuf;
|
|
954 GtkTextIter iter, iter2;
|
|
955 #endif
|
|
956
|
|
957 textstr = NULL;
|
|
958 newstr = g_malloc (1);
|
|
959 *newstr = '\0';
|
|
960
|
|
961 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2
|
|
962 /*
|
|
963 GTK_TEXT uses wchar_t instead of char in environment of multibyte encoding
|
|
964 locale (ex Japanese), so we must convert from wide character
|
|
965 to multibyte charator.... Yasuyuki Furukawa (yasu@on.cs.keio.ac.jp)
|
|
966 */
|
|
967 if (GTK_TEXT (proxy_text)->use_wchar)
|
|
968 {
|
|
969 wcstombs (tmp, (wchar_t *) GTK_TEXT (proxy_text)->text.wc,
|
|
970 sizeof (tmp));
|
|
971 pos = tmp;
|
|
972 }
|
|
973 else
|
|
974 {
|
|
975 oldstr = (char *) GTK_TEXT (proxy_text)->text.ch;
|
|
976 len = gtk_text_get_length (GTK_TEXT (proxy_text));
|
|
977 textstr = g_malloc (len + 1);
|
|
978 strncpy (textstr, oldstr, len);
|
|
979 textstr[len] = '\0';
|
|
980 pos = textstr;
|
|
981 }
|
|
982 #else
|
|
983 textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (proxy_text));
|
|
984 len = gtk_text_buffer_get_char_count (textbuf);
|
|
985 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0);
|
|
986 gtk_text_buffer_get_iter_at_offset (textbuf, &iter2, len - 1);
|
|
987 pos = textstr = gtk_text_buffer_get_text (textbuf, &iter, &iter2, 0);
|
|
988 #endif
|
|
989
|
|
990 do
|
|
991 {
|
|
992 if ((endpos = strchr (pos, '\n')) != NULL)
|
|
993 *endpos = '\0';
|
|
994 oldstr = newstr;
|
|
995 if (endpos != NULL)
|
|
996 newstr = g_strconcat (newstr, pos, "%n", NULL);
|
|
997 else
|
|
998 newstr = g_strconcat (newstr, pos, NULL);
|
|
999 g_free (oldstr);
|
|
1000 if (endpos != NULL)
|
|
1001 {
|
|
1002 *endpos = '\n';
|
|
1003 pos = endpos + 1;
|
|
1004 }
|
|
1005 }
|
|
1006 while (endpos != NULL);
|
|
1007
|
|
1008 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2
|
|
1009 if (!GTK_TEXT (proxy_text)->use_wchar)
|
|
1010 g_free (textstr);
|
|
1011 #else
|
|
1012 g_free (textstr);
|
|
1013 #endif
|
|
1014
|
|
1015 return (newstr);
|
|
1016 }
|
|
1017
|