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