Just a little correction at the it.po file.
[midnight-commander.git] / src / boxes.c
blob65fde9a30a6aaa424c62cf249e2ecd04dd323f06
1 /* Some misc dialog boxes for the program.
3 Copyright (C) 1994, 1995 the Free Software Foundation
5 Authors: 1994, 1995 Miguel de Icaza
6 1995 Jakub Jelinek
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include <config.h>
23 #include <string.h>
24 #include <stdio.h>
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <signal.h>
28 #include <ctype.h>
30 #include "global.h"
31 #include "tty.h"
32 #include "win.h" /* Our window tools */
33 #include "color.h" /* Color definitions */
34 #include "dlg.h" /* The nice dialog manager */
35 #include "widget.h" /* The widgets for the nice dialog manager */
36 #include "dialog.h" /* For do_refresh() */
37 #include "wtools.h"
38 #include "setup.h" /* For profile_name */
39 #include "profile.h" /* Load/save user formats */
40 #include "key.h" /* XCTRL and ALT macros */
41 #include "command.h" /* For cmdline */
42 #include "dir.h"
43 #include "panel.h"
44 #include "boxes.h"
45 #include "main.h" /* For the confirm_* variables */
46 #include "tree.h"
47 #include "layout.h" /* for get_nth_panel_name proto */
48 #include "background.h"
50 #ifdef HAVE_CHARSET
51 #include "charsets.h"
52 #include "selcodepage.h"
53 #endif
55 #include "../vfs/vfs.h" /* vfs_timeout */
56 #ifdef USE_NETCODE
57 # include "../vfs/ftpfs.h"
58 #endif
60 static int DISPLAY_X = 45, DISPLAY_Y = 14;
62 static Dlg_head *dd;
63 static WRadio *my_radio;
64 static WInput *user;
65 static WInput *status;
66 static WCheck *check_status;
67 static int current_mode;
69 static char **displays_status;
71 /* Controls whether the array strings have been translated */
72 static char *displays [LIST_TYPES] = {
73 N_("&Full file list"),
74 N_("&Brief file list"),
75 N_("&Long file list"),
76 N_("&User defined:")
79 /* Index in displays[] for "user defined" */
80 #define USER_TYPE 3
82 static int user_hotkey = 'u';
84 static int
85 display_callback (struct Dlg_head *h, int id, int Msg)
87 switch (Msg){
88 case DLG_DRAW:
89 common_dialog_repaint (h);
90 break;
92 case DLG_UNFOCUS:
93 if((WRadio *) h->current->widget == my_radio){
94 assign_text (status, displays_status [my_radio->sel]);
95 input_set_point (status, 0);
97 break;
99 case DLG_KEY:
100 if (id == '\n'){
101 if((WRadio *) h->current->widget == my_radio){
102 assign_text (status, displays_status [my_radio->sel]);
103 dlg_stop (h);
104 break;
107 if ((WInput *) h->current->widget == user){
108 h->ret_value = B_USER + 6;
109 dlg_stop (h);
110 break;
113 if ((WInput *) h->current->widget == status){
114 h->ret_value = B_USER + 7;
115 dlg_stop (h);
116 break;
120 if (tolower(id) == user_hotkey && h->current->widget != (Widget *) user
121 && h->current->widget != (Widget *) status){
122 my_radio->sel = 3;
123 dlg_select_widget (h, my_radio); /* force redraw */
124 dlg_select_widget (h, user);
125 return MSG_HANDLED;
128 return MSG_NOT_HANDLED;
131 static void
132 display_init (int radio_sel, char *init_text, int _check_status,
133 char **_status)
135 static char *display_title = N_("Listing mode");
136 static int i18n_displays_flag;
137 char *user_mini_status = _("user &Mini status");
138 char *ok_button = _("&OK");
139 char *cancel_button = _("&Cancel");
141 static int button_start = 30;
143 displays_status = _status;
145 if (!i18n_displays_flag) {
146 int i, l, maxlen = 0;
147 char *cp;
149 display_title = _(display_title);
150 for (i = 0; i < LIST_TYPES; i++) {
151 displays[i] = _(displays[i]);
152 if ((l = strlen (displays[i])) > maxlen)
153 maxlen = l;
156 i = strlen (ok_button) + 5;
157 l = strlen (cancel_button) + 3;
158 l = max (i, l);
160 i = maxlen + l + 16;
161 if (i > DISPLAY_X)
162 DISPLAY_X = i;
164 i = strlen (user_mini_status) + 13;
165 if (i > DISPLAY_X)
166 DISPLAY_X = i;
168 i = strlen (display_title) + 10;
169 if (i > DISPLAY_X)
170 DISPLAY_X = i;
172 button_start = DISPLAY_X - l - 5;
174 /* get hotkey of user-defined format string */
175 cp = strchr (displays[USER_TYPE], '&');
176 if (cp != NULL && *++cp != '\0')
177 user_hotkey = tolower (*cp);
179 i18n_displays_flag = 1;
181 dd = create_dlg (0, 0, DISPLAY_Y, DISPLAY_X, dialog_colors,
182 display_callback, "[Listing Mode...]", display_title,
183 DLG_CENTER);
185 add_widget (dd,
186 button_new (4, button_start, B_CANCEL, NORMAL_BUTTON,
187 cancel_button, 0, 0, "cancel-button"));
189 add_widget (dd,
190 button_new (3, button_start, B_ENTER, DEFPUSH_BUTTON,
191 ok_button, 0, 0, "ok-button"));
193 status =
194 input_new (10, 9, INPUT_COLOR, DISPLAY_X - 14, _status[radio_sel],
195 "mini-input");
196 add_widget (dd, status);
197 input_set_point (status, 0);
199 check_status =
200 check_new (9, 5, _check_status, user_mini_status, "mini-status");
201 add_widget (dd, check_status);
203 user =
204 input_new (7, 9, INPUT_COLOR, DISPLAY_X - 14, init_text,
205 "user-fmt-input");
206 add_widget (dd, user);
207 input_set_point (user, 0);
209 my_radio = radio_new (3, 5, LIST_TYPES, displays, 1, "radio");
210 my_radio->sel = my_radio->pos = current_mode;
211 add_widget (dd, my_radio);
215 display_box (WPanel *panel, char **userp, char **minip, int *use_msformat, int num)
217 int result, i;
218 char *section = NULL;
219 char *p;
221 if (!panel) {
222 p = get_nth_panel_name (num);
223 panel = g_new (WPanel, 1);
224 panel->list_type = list_full;
225 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
226 panel->user_mini_status = 0;
227 for (i = 0; i < LIST_TYPES; i++)
228 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
229 section = g_strconcat ("Temporal:", p, NULL);
230 if (!profile_has_section (section, profile_name)) {
231 g_free (section);
232 section = g_strdup (p);
234 panel_load_setup (panel, section);
235 g_free (section);
238 current_mode = panel->list_type;
239 display_init (current_mode, panel->user_format,
240 panel->user_mini_status, panel->user_status_format);
242 run_dlg (dd);
244 result = -1;
246 if (section) {
247 g_free (panel->user_format);
248 for (i = 0; i < LIST_TYPES; i++)
249 g_free (panel->user_status_format [i]);
250 g_free (panel);
253 if (dd->ret_value != B_CANCEL){
254 result = my_radio->sel;
255 *userp = g_strdup (user->buffer);
256 *minip = g_strdup (status->buffer);
257 *use_msformat = check_status->state & C_BOOL;
259 destroy_dlg (dd);
261 return result;
264 static int SORT_X = 40, SORT_Y = 14;
266 static char *sort_orders_names [SORT_TYPES];
268 sortfn *
269 sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive)
271 int i, r, l;
272 sortfn *result;
273 WCheck *c, *case_sense;
275 char* ok_button = _("&OK");
276 char* cancel_button = _("&Cancel");
277 char* reverse_label = _("&Reverse");
278 char* case_label = _("case sensi&tive");
279 char* sort_title = _("Sort order");
281 static int i18n_sort_flag = 0, check_pos = 0, button_pos = 0;
283 if (!i18n_sort_flag)
285 int maxlen = 0;
286 for (i = SORT_TYPES-1; i >= 0; i--)
288 sort_orders_names [i] = _(sort_orders [i].sort_name);
289 r = strlen (sort_orders_names [i]);
290 if (r > maxlen)
291 maxlen = r;
294 check_pos = maxlen + 9;
296 r = strlen (reverse_label) + 4;
297 i = strlen (case_label) + 4;
298 if (i > r)
299 r = i;
301 l = strlen (ok_button) + 6;
302 i = strlen (cancel_button) + 4;
303 if (i > l)
304 l = i;
306 i = check_pos + max(r,l) + 2;
308 if (i > SORT_X)
309 SORT_X = i;
311 i = strlen (sort_title) + 6;
312 if (i > SORT_X)
313 SORT_X = i;
315 button_pos = SORT_X - l - 2;
317 i18n_sort_flag = 1;
320 result = 0;
322 for (i = 0; i < SORT_TYPES; i++)
323 if ((sortfn *) (sort_orders [i].sort_fn) == sort_fn){
324 current_mode = i;
325 break;
328 dd = create_dlg (0, 0, SORT_Y, SORT_X, dialog_colors, NULL,
329 "[Sort Order...]", sort_title, DLG_CENTER);
331 add_widget (dd,
332 button_new (10, button_pos, B_CANCEL, NORMAL_BUTTON, cancel_button,
333 0, 0, "cancel-button"));
335 add_widget (dd,
336 button_new (9, button_pos, B_ENTER, DEFPUSH_BUTTON, ok_button,
337 0, 0, "ok-button"));
339 case_sense = check_new (4, check_pos, *case_sensitive, case_label, "case-check");
340 add_widget (dd, case_sense);
341 c = check_new (3, check_pos, *reverse, reverse_label, "reverse-check");
342 add_widget (dd, c);
344 my_radio = radio_new (3, 3, SORT_TYPES, sort_orders_names, 1, "radio-1");
345 my_radio->sel = my_radio->pos = current_mode;
347 add_widget (dd, my_radio);
348 run_dlg (dd);
350 r = dd->ret_value;
351 if (r != B_CANCEL){
352 result = (sortfn *) sort_orders [my_radio->sel].sort_fn;
353 *reverse = c->state & C_BOOL;
354 *case_sensitive = case_sense->state & C_BOOL;
355 } else
356 result = sort_fn;
357 destroy_dlg (dd);
359 return result;
362 #define CONFY 10
363 #define CONFX 46
365 static int my_delete;
366 static int my_overwrite;
367 static int my_execute;
368 static int my_exit;
370 static QuickWidget conf_widgets [] = {
371 { quick_button, 4, 6, 4, CONFY, N_("&Cancel"),
372 0, B_CANCEL, 0, 0, "c" },
373 { quick_button, 4, 6, 3, CONFY, N_("&OK"),
374 0, B_ENTER, 0, 0, "o" },
376 { quick_checkbox, 1, 13, 6, CONFY, N_(" confirm &Exit "),
377 9, 0, &my_exit, 0, "e" },
378 { quick_checkbox, 1, 13, 5, CONFY, N_(" confirm e&Xecute "),
379 10, 0, &my_execute, 0, "x" },
380 { quick_checkbox, 1, 13, 4, CONFY, N_(" confirm o&Verwrite "),
381 10, 0, &my_overwrite, 0, "ov" },
382 { quick_checkbox, 1, 13, 3, CONFY, N_(" confirm &Delete "),
383 9, 0, &my_delete, 0, "de" },
384 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
387 static QuickDialog confirmation =
388 { CONFX, CONFY, -1, -1, N_(" Confirmation "), "[Confirmation]",
389 conf_widgets, 0
392 void
393 confirm_box (void)
396 #ifdef ENABLE_NLS
397 static int i18n_flag = 0;
399 if (!i18n_flag)
401 register int i = sizeof(conf_widgets)/sizeof(QuickWidget) - 1;
402 int l1, maxlen = 0;
403 while (i--)
405 conf_widgets [i].text = _(conf_widgets [i].text);
406 l1 = strlen (conf_widgets [i].text) + 3;
407 if (l1 > maxlen)
408 maxlen = l1;
412 * If buttons start on 4/6, checkboxes (with some add'l space)
413 * must take not more than it.
415 confirmation.xlen = (maxlen + 5) * 6 / 4;
418 * And this for the case when buttons with some space to the right
419 * do not fit within 2/6
421 l1 = strlen (conf_widgets [0].text) + 3;
422 i = strlen (conf_widgets [1].text) + 5;
423 if (i > l1)
424 l1 = i;
426 i = (l1 + 3) * 6 / 2;
427 if (i > confirmation.xlen)
428 confirmation.xlen = i;
430 confirmation.title = _(confirmation.title);
432 i18n_flag = confirmation.i18n = 1;
435 #endif /* ENABLE_NLS */
437 my_delete = confirm_delete;
438 my_overwrite = confirm_overwrite;
439 my_execute = confirm_execute;
440 my_exit = confirm_exit;
442 if (quick_dialog (&confirmation) != B_CANCEL){
443 confirm_delete = my_delete;
444 confirm_overwrite = my_overwrite;
445 confirm_execute = my_execute;
446 confirm_exit = my_exit;
450 #define DISPY 11
451 #define DISPX 46
454 #ifndef HAVE_CHARSET
456 static int new_mode;
457 static int new_meta;
459 static char *display_bits_str [] =
460 { N_("Full 8 bits output"), N_("ISO 8859-1"), N_("7 bits") };
462 static QuickWidget display_widgets [] = {
463 { quick_button, 4, 6, 4, DISPY, N_("&Cancel"),
464 0, B_CANCEL, 0, 0, "c" },
465 { quick_button, 4, 6, 3, DISPY, N_("&OK"),
466 0, B_ENTER, 0, 0, "o" },
467 { quick_checkbox, 4, DISPX, 7, DISPY, N_("F&ull 8 bits input"),
468 0, 0, &new_meta, 0, "u" },
469 { quick_radio, 4, DISPX, 3, DISPY, "", 3, 0,
470 &new_mode, display_bits_str, "r" },
471 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
474 static QuickDialog display_bits =
475 { DISPX, DISPY, -1, -1, N_(" Display bits "), "[Display bits]",
476 display_widgets, 0 };
478 void
479 display_bits_box (void)
481 int current_mode;
483 #ifdef ENABLE_NLS
484 static int i18n_flag = 0;
485 if (!i18n_flag)
487 register int i;
488 int l1, maxlen = 0;
489 for (i = 0; i < 3; i++)
491 display_widgets [i].text = _(display_widgets[i].text);
492 display_bits_str [i] = _(display_bits_str [i]);
493 l1 = strlen (display_bits_str [i]);
494 if (l1 > maxlen)
495 maxlen = l1;
497 l1 = strlen (display_widgets [2].text);
498 if (l1 > maxlen)
499 maxlen = l1;
502 display_bits.xlen = (maxlen + 5) * 6 / 4;
504 /* See above confirm_box */
505 l1 = strlen (display_widgets [0].text) + 3;
506 i = strlen (display_widgets [1].text) + 5;
507 if (i > l1)
508 l1 = i;
510 i = (l1 + 3) * 6 / 2;
511 if (i > display_bits.xlen)
512 display_bits.xlen = i;
514 display_bits.title = _(display_bits.title);
515 i18n_flag = display_bits.i18n = 1;
518 #endif /* ENABLE_NLS */
520 if (full_eight_bits)
521 current_mode = 0;
522 else if (eight_bit_clean)
523 current_mode = 1;
524 else
525 current_mode = 2;
527 display_widgets [3].value = current_mode;
528 new_meta = !use_8th_bit_as_meta;
529 if (quick_dialog (&display_bits) != B_ENTER)
530 return;
532 eight_bit_clean = new_mode < 2;
533 full_eight_bits = new_mode == 0;
534 #ifndef HAVE_SLANG
535 meta (stdscr, eight_bit_clean);
536 #else
537 SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
538 #endif
539 use_8th_bit_as_meta = !new_meta;
543 #else /* HAVE_CHARSET */
546 static int new_display_codepage;
548 static WLabel *cplabel;
549 static WCheck *inpcheck;
551 static int sel_charset_button( int action, void *param )
553 char *cpname, buf[64];
554 new_display_codepage = select_charset( new_display_codepage, 1 );
555 cpname = (new_display_codepage < 0)
556 ? _("Other 8 bit")
557 : codepages[ new_display_codepage ].name;
558 g_snprintf( buf, sizeof (buf), "%-27s", cpname ); /* avoid strange bug with label repainting */
559 label_set_text( cplabel, buf );
560 return 0;
563 static Dlg_head *
564 init_disp_bits_box (void)
566 char *cpname;
567 Dlg_head *dbits_dlg;
569 do_refresh();
571 dbits_dlg = create_dlg( 0, 0, DISPY, DISPX, dialog_colors,
572 NULL, "[Display bits]", _(" Display bits "), DLG_CENTER);
574 add_widget( dbits_dlg,
575 label_new( 3, 4, _("Input / display codepage:"), NULL));
577 cpname = (new_display_codepage < 0)
578 ? _("Other 8 bit")
579 : codepages[ new_display_codepage ].name;
580 cplabel = label_new( 4, 4, cpname, NULL);
581 add_widget( dbits_dlg, cplabel );
583 add_widget( dbits_dlg,
584 button_new( DISPY - 3, DISPX / 2 + 3, B_CANCEL,
585 NORMAL_BUTTON, _("&Cancel"), 0, 0, NULL ) );
586 add_widget( dbits_dlg,
587 button_new( DISPY - 3, 7, B_ENTER,
588 NORMAL_BUTTON, _("&OK"), 0, 0, NULL ) );
590 inpcheck = check_new( 6, 4, !use_8th_bit_as_meta,
591 _("F&ull 8 bits input"), NULL );
592 add_widget( dbits_dlg, inpcheck );
594 cpname = _("&Select");
595 add_widget( dbits_dlg,
596 button_new( 4, DISPX - 8 - strlen(cpname) , B_USER,
597 NORMAL_BUTTON, cpname,
598 sel_charset_button, 0, NULL ) );
600 return dbits_dlg;
603 void
604 display_bits_box (void)
606 Dlg_head *dbits_dlg;
607 new_display_codepage = display_codepage;
609 application_keypad_mode ();
610 dbits_dlg = init_disp_bits_box ();
612 run_dlg (dbits_dlg);
614 if (dbits_dlg->ret_value == B_ENTER) {
615 char *errmsg;
616 display_codepage = new_display_codepage;
617 errmsg = init_translation_table( source_codepage, display_codepage );
618 if (errmsg)
619 message( 1, MSG_ERROR, "%s", errmsg );
620 #ifndef HAVE_SLANG
621 meta( stdscr, display_codepage != 0 );
622 #else
623 SLsmg_Display_Eight_Bit
624 = (display_codepage != 0 && display_codepage != 1) ? 128 : 160;
625 #endif
626 use_8th_bit_as_meta = ! (inpcheck->state & C_BOOL);
628 destroy_dlg( dbits_dlg );
629 repaint_screen();
632 #endif /* HAVE_CHARSET */
635 #define TREE_Y 20
636 #define TREE_X 60
638 static int
639 tree_callback (struct Dlg_head *h, int id, int msg)
641 switch (msg){
643 case DLG_POST_KEY:
644 /* The enter key will be processed by the tree widget */
645 if (id == '\n') {
646 h->ret_value = B_ENTER;
647 dlg_stop (h);
649 return MSG_HANDLED;
651 case DLG_DRAW:
652 common_dialog_repaint (h);
653 break;
655 return MSG_NOT_HANDLED;
658 /* Show tree in a box, not on a panel */
659 char *
660 tree_box (char *current_dir)
662 WTree *mytree;
663 Dlg_head *dlg;
664 char *val;
665 WButtonBar *bar;
667 /* Create the components */
668 dlg = create_dlg (0, 0, TREE_Y, TREE_X, dialog_colors,
669 tree_callback, "[Directory Tree]", NULL, DLG_CENTER);
670 mytree = tree_new (0, 2, 2, TREE_Y - 6, TREE_X - 5);
671 add_widget (dlg, mytree);
672 bar = buttonbar_new(1);
673 add_widget (dlg, bar);
674 bar->widget.x = 0;
675 bar->widget.y = LINES - 1;
677 run_dlg (dlg);
678 if (dlg->ret_value == B_ENTER)
679 val = g_strdup (tree_selected_name (mytree));
680 else
681 val = 0;
683 destroy_dlg (dlg);
684 return val;
687 #ifdef USE_VFS
689 #if defined(USE_NETCODE)
690 #define VFSY 16
691 #define VFS_WIDGETBASE 9
692 #else
693 #define VFSY 8
694 #define VFS_WIDGETBASE 0
695 #endif
697 #define VFSX 56
699 static char *ret_timeout;
701 #if defined(USE_NETCODE)
702 static char *ret_passwd;
703 static char *ret_directory_timeout;
704 static char *ret_ftp_proxy;
705 static int ret_use_netrc;
706 static int ret_ftpfs_use_passive_connections;
707 #endif
709 static QuickWidget confvfs_widgets [] = {
710 { quick_button, 30, VFSX, VFSY - 3, VFSY, N_("&Cancel"),
711 0, B_CANCEL, 0, 0, "button-cancel" },
712 { quick_button, 12, VFSX, VFSY - 3, VFSY, N_("&OK"),
713 0, B_ENTER, 0, 0, "button-ok" },
714 #if defined(USE_NETCODE)
715 { quick_checkbox, 4, VFSX, 11, VFSY, N_("Use &passive mode"), 0, 0,
716 &ret_ftpfs_use_passive_connections, 0, "check-use-passive-mode" },
717 { quick_checkbox, 4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), 0, 0,
718 &ret_use_netrc, 0, "check-use-netrc" },
719 { quick_input, 4, VFSX, 9, VFSY, "", 48, 0, 0, &ret_ftp_proxy,
720 "input-ftp-proxy" },
721 { quick_checkbox, 4, VFSX, 8, VFSY, N_("&Always use ftp proxy"), 0, 0,
722 &ftpfs_always_use_proxy, 0, "check-ftp-proxy" },
723 { quick_label, 49, VFSX, 7, VFSY, N_("sec"),
724 0, 0, 0, 0, "label-sec" },
725 { quick_input, 38, VFSX, 7, VFSY, "", 10, 0, 0, &ret_directory_timeout,
726 "input-timeout" },
727 { quick_label, 4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:"),
728 0, 0, 0, 0, "label-cache"},
729 { quick_input, 4, VFSX, 6, VFSY, "", 48, 0, 0, &ret_passwd,
730 "input-passwd" },
731 { quick_label, 4, VFSX, 5, VFSY, N_("ftp anonymous password:"),
732 0, 0, 0, 0, "label-pass"},
733 #endif
734 { quick_label, 49, VFSX, 3, VFSY, "sec",
735 0, 0, 0, 0, "label-sec2" },
736 { quick_input, 38, VFSX, 3, VFSY, "", 10, 0, 0, &ret_timeout,
737 "input-timo-vfs" },
738 { quick_label, 4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:"),
739 0, 0, 0, 0, "label-vfs" },
740 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
743 static QuickDialog confvfs_dlg =
744 { VFSX, VFSY, -1, -1, N_(" Virtual File System Setting "),
745 "[Virtual FS]", confvfs_widgets, 0 };
747 void
748 configure_vfs (void)
750 char buffer2[BUF_TINY];
751 #if defined(USE_NETCODE)
752 char buffer3[BUF_TINY];
754 ret_use_netrc = use_netrc;
755 ret_ftpfs_use_passive_connections = ftpfs_use_passive_connections;
756 g_snprintf(buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
757 confvfs_widgets[7].text = buffer3;
758 confvfs_widgets[9].text = ftpfs_anonymous_passwd;
759 confvfs_widgets[4].text = ftpfs_proxy_host;
760 #endif
761 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
762 confvfs_widgets [3 + VFS_WIDGETBASE].text = buffer2;
764 if (quick_dialog (&confvfs_dlg) != B_CANCEL) {
765 vfs_timeout = atoi (ret_timeout);
766 g_free (ret_timeout);
767 if (vfs_timeout < 0 || vfs_timeout > 10000)
768 vfs_timeout = 10;
769 #if defined(USE_NETCODE)
770 g_free (ftpfs_anonymous_passwd);
771 ftpfs_anonymous_passwd = ret_passwd;
772 if (ftpfs_proxy_host)
773 g_free (ftpfs_proxy_host);
774 ftpfs_proxy_host = ret_ftp_proxy;
775 ftpfs_directory_timeout = atoi(ret_directory_timeout);
776 use_netrc = ret_use_netrc;
777 ftpfs_use_passive_connections = ret_ftpfs_use_passive_connections;
778 g_free (ret_directory_timeout);
779 #endif
783 #endif /* USE_VFS */
785 char *
786 cd_dialog (void)
788 QuickDialog Quick_input;
789 QuickWidget quick_widgets [] = {
790 { quick_input, 6, 57, 2, 0, "", 50, 0, 0, 0, "input" },
791 { quick_label, 3, 57, 2, 0, "", 0, 0, 0, 0, "label" },
792 { 0 }
794 char *my_str;
795 int len;
797 Quick_input.xlen = 57;
798 Quick_input.title = _("Quick cd");
799 Quick_input.help = "[Quick cd]";
800 quick_widgets [0].value = 2; /* want cd like completion */
801 quick_widgets [1].text = _("cd");
802 quick_widgets [1].y_divisions =
803 quick_widgets [0].y_divisions = Quick_input.ylen = 5;
805 len = strlen (quick_widgets [1].text);
807 quick_widgets [0].relative_x =
808 quick_widgets [1].relative_x + len + 1;
810 Quick_input.xlen = len + quick_widgets [0].hotkey_pos + 7;
811 quick_widgets [0].x_divisions =
812 quick_widgets [1].x_divisions = Quick_input.xlen;
814 Quick_input.i18n = 1;
815 Quick_input.xpos = 2;
816 Quick_input.ypos = LINES - 2 - Quick_input.ylen;
817 quick_widgets [0].str_result = &my_str;
819 Quick_input.widgets = quick_widgets;
820 if (quick_dialog (&Quick_input) != B_CANCEL){
821 return my_str;
822 } else
823 return 0;
826 void
827 symlink_dialog (char *existing, char *new, char **ret_existing, char **ret_new)
829 QuickDialog Quick_input;
830 QuickWidget quick_widgets [] = {
831 { quick_input, 4, 80, 5, 8, "", 58, 0, 0, 0, "input-1" },
832 { quick_label, 4, 80, 4, 8, "", 0, 0, 0, 0, "label-1" },
833 { quick_input, 4, 80, 3, 8, "", 58, 0, 0, 0, "input-2" },
834 { quick_label, 4, 80, 2, 8, "", 0, 0, 0, 0, "label-2" },
835 { 0 } };
837 Quick_input.xlen = 64;
838 Quick_input.ylen = 8;
839 Quick_input.title = _("Symbolic link");
840 Quick_input.help = "[File Menu]";
841 Quick_input.i18n = 0;
842 quick_widgets [0].text = new;
843 quick_widgets [1].text = _("Symbolic link filename:");
844 quick_widgets [2].text = existing;
845 quick_widgets [3].text = _("Existing filename (filename symlink will point to):");
846 Quick_input.xpos = -1;
847 quick_widgets [0].str_result = ret_new;
848 quick_widgets [2].str_result = ret_existing;
850 Quick_input.widgets = quick_widgets;
851 if (quick_dialog (&Quick_input) == B_CANCEL){
852 *ret_new = NULL;
853 *ret_existing = NULL;
857 #ifdef WITH_BACKGROUND
858 #define B_STOP B_USER+1
859 #define B_RESUME B_USER+2
860 #define B_KILL B_USER+3
862 static int JOBS_X = 60;
863 #define JOBS_Y 15
864 static WListbox *bg_list;
865 static Dlg_head *jobs_dlg;
867 static void
868 jobs_fill_listbox (void)
870 static char *state_str [2];
871 TaskList *tl = task_list;
873 if (!state_str [0]){
874 state_str [0] = _("Running ");
875 state_str [1] = _("Stopped");
878 while (tl){
879 char *s;
881 s = g_strconcat (state_str [tl->state], " ", tl->info, NULL);
882 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
883 g_free (s);
884 tl = tl->next;
888 static int
889 task_cb (int action, void *ignored)
891 TaskList *tl;
892 int sig = 0;
894 if (!bg_list->list)
895 return 0;
897 /* Get this instance information */
898 tl = (TaskList *) bg_list->current->data;
900 # ifdef SIGTSTP
901 if (action == B_STOP){
902 sig = SIGSTOP;
903 tl->state = Task_Stopped;
904 } else if (action == B_RESUME){
905 sig = SIGCONT;
906 tl->state = Task_Running;
907 } else
908 # endif
909 if (action == B_KILL){
910 sig = SIGKILL;
913 if (sig == SIGINT)
914 unregister_task_running (tl->pid, tl->fd);
916 kill (tl->pid, sig);
917 listbox_remove_list (bg_list);
918 jobs_fill_listbox ();
920 /* This can be optimized to just redraw this widget :-) */
921 dlg_redraw (jobs_dlg);
923 return 0;
926 static struct
928 char* name;
929 int xpos;
930 int value;
931 int (*callback)(int, void *);
932 char* tkname;
934 job_buttons [] =
936 {N_("&Stop"), 3, B_STOP, task_cb, "button-stop"},
937 {N_("&Resume"), 12, B_RESUME, task_cb, "button-cont"},
938 {N_("&Kill"), 23, B_KILL, task_cb, "button-kill"},
939 {N_("&OK"), 35, B_CANCEL, NULL, "button-ok"},
942 void
943 jobs_cmd (void)
945 register int i;
946 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
948 #ifdef ENABLE_NLS
949 static int i18n_flag = 0;
950 if (!i18n_flag)
952 int startx = job_buttons [0].xpos;
953 int len;
955 for (i = 0; i < n_buttons; i++)
957 job_buttons [i].name = _(job_buttons [i].name);
959 len = strlen (job_buttons [i].name) + 4;
960 JOBS_X = max (JOBS_X, startx + len + 3);
962 job_buttons [i].xpos = startx;
963 startx += len;
966 /* Last button - Ok a.k.a. Cancel :) */
967 job_buttons [n_buttons - 1].xpos =
968 JOBS_X - strlen (job_buttons [n_buttons - 1].name) - 7;
970 i18n_flag = 1;
972 #endif /* ENABLE_NLS */
974 jobs_dlg = create_dlg (0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL,
975 "[Background jobs]", _("Background Jobs"),
976 DLG_CENTER);
978 bg_list = listbox_new (2, 3, JOBS_X-7, JOBS_Y-9, listbox_nothing, 0, "listbox");
979 add_widget (jobs_dlg, bg_list);
981 i = n_buttons;
982 while (i--)
984 add_widget (jobs_dlg, button_new (JOBS_Y-4,
985 job_buttons [i].xpos, job_buttons [i].value,
986 NORMAL_BUTTON, job_buttons [i].name,
987 job_buttons [i].callback, 0,
988 job_buttons [i].tkname));
991 /* Insert all of task information in the list */
992 jobs_fill_listbox ();
993 run_dlg (jobs_dlg);
995 destroy_dlg (jobs_dlg);
997 #endif /* WITH_BACKGROUND */
999 #ifdef WITH_SMBFS
1000 struct smb_authinfo *
1001 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
1002 const char *user)
1004 static int dialog_x = 44;
1005 enum { b0 = 3, dialog_y = 12};
1006 struct smb_authinfo *return_value;
1007 static char* labs[] = {N_("Domain:"), N_("Username:"), N_("Password:")};
1008 static char* buts[] = {N_("&OK"), N_("&Cancel")};
1009 static int ilen = 30, istart = 14;
1010 static int b2 = 30;
1011 char *title;
1012 WInput *in_password;
1013 WInput *in_user;
1014 WInput *in_domain;
1015 Dlg_head *auth_dlg;
1017 #ifdef ENABLE_NLS
1018 static int i18n_flag = 0;
1020 if (!i18n_flag)
1022 register int i = sizeof(labs)/sizeof(labs[0]);
1023 int l1, maxlen = 0;
1025 while (i--)
1027 l1 = strlen (labs [i] = _(labs [i]));
1028 if (l1 > maxlen)
1029 maxlen = l1;
1031 i = maxlen + ilen + 7;
1032 if (i > dialog_x)
1033 dialog_x = i;
1035 for (i = sizeof(buts)/sizeof(buts[0]), l1 = 0; i--; )
1037 l1 += strlen (buts [i] = _(buts [i]));
1039 l1 += 15;
1040 if (l1 > dialog_x)
1041 dialog_x = l1;
1043 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1044 istart = dialog_x - 3 - ilen;
1046 b2 = dialog_x - (strlen(buts[1]) + 6);
1048 i18n_flag = 1;
1051 #endif /* ENABLE_NLS */
1053 if (!domain)
1054 domain = "";
1055 if (!user)
1056 user = "";
1058 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1060 auth_dlg = create_dlg (0, 0, dialog_y, dialog_x, dialog_colors, NULL,
1061 "[Smb Authinfo]", title, DLG_CENTER);
1063 g_free (title);
1065 in_user = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name");
1066 add_widget (auth_dlg, in_user);
1068 in_domain = input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain");
1069 add_widget (auth_dlg, in_domain);
1070 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON,
1071 buts[1], 0 ,0, "cancel"));
1072 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON,
1073 buts[0], 0, 0, "ok"));
1075 in_password = input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password");
1076 in_password->completion_flags = 0;
1077 in_password->is_password = 1;
1078 add_widget (auth_dlg, in_password);
1080 add_widget (auth_dlg, label_new (7, 3, labs[2], "label-passwd"));
1081 add_widget (auth_dlg, label_new (5, 3, labs[1], "label-user"));
1082 add_widget (auth_dlg, label_new (3, 3, labs[0], "label-domain"));
1084 run_dlg (auth_dlg);
1086 switch (auth_dlg->ret_value) {
1087 case B_CANCEL:
1088 return_value = 0;
1089 break;
1090 default:
1091 return_value = g_new (struct smb_authinfo, 1);
1092 if (return_value) {
1093 return_value->host = g_strdup (host);
1094 return_value->share = g_strdup (share);
1095 return_value->domain = g_strdup (in_domain->buffer);
1096 return_value->user = g_strdup (in_user->buffer);
1097 return_value->password = g_strdup (in_password->buffer);
1101 destroy_dlg (auth_dlg);
1103 return return_value;
1105 #endif /* WITH_SMBFS */