mandriva: Srpm support for extfs
[midnight-commander.git] / src / boxes.c
blobf5eae405f4a23ddbbc5e5460299eca941a6bda0f
1 /* Some misc dialog boxes for the program.
3 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 2005, 2006 Free Software Foundation, Inc.
6 Authors: 1994, 1995 Miguel de Icaza
7 1995 Jakub Jelinek
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
23 #include <config.h>
25 #include <ctype.h>
26 #include <signal.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
33 #include "global.h"
34 #include "tty.h"
35 #include "win.h" /* Our window tools */
36 #include "color.h" /* Color definitions */
37 #include "dialog.h" /* The nice dialog manager */
38 #include "widget.h" /* The widgets for the nice dialog manager */
39 #include "wtools.h"
40 #include "setup.h" /* For profile_name */
41 #include "profile.h" /* Load/save user formats */
42 #include "key.h" /* XCTRL and ALT macros */
43 #include "command.h" /* For cmdline */
44 #include "dir.h"
45 #include "panel.h"
46 #include "boxes.h"
47 #include "main.h" /* For the confirm_* variables */
48 #include "tree.h"
49 #include "layout.h" /* for get_nth_panel_name proto */
50 #include "background.h" /* task_list */
52 #ifdef HAVE_CHARSET
53 #include "charsets.h"
54 #include "selcodepage.h"
55 #endif
57 #ifdef USE_NETCODE
58 # include "../vfs/ftpfs.h"
59 #endif
61 #ifdef USE_VFS
62 #include "../vfs/gc.h"
63 #endif
65 static int DISPLAY_X = 45, DISPLAY_Y = 14;
67 static Dlg_head *dd;
68 static WRadio *my_radio;
69 static WInput *user;
70 static WInput *status;
71 static WCheck *check_status;
72 static int current_mode;
74 static char **displays_status;
76 /* Controls whether the array strings have been translated */
77 static const char *displays [LIST_TYPES] = {
78 N_("&Full file list"),
79 N_("&Brief file list"),
80 N_("&Long file list"),
81 N_("&User defined:")
84 /* Index in displays[] for "user defined" */
85 #define USER_TYPE 3
87 static int user_hotkey = 'u';
89 static cb_ret_t
90 display_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
92 switch (msg) {
93 case DLG_UNFOCUS:
94 if (dlg_widget_active (my_radio)) {
95 assign_text (status, displays_status[my_radio->sel]);
96 input_set_point (status, 0);
98 return MSG_HANDLED;
100 case DLG_KEY:
101 if (parm == '\n') {
102 if (dlg_widget_active (my_radio)) {
103 assign_text (status, displays_status[my_radio->sel]);
104 dlg_stop (h);
105 return MSG_HANDLED;
108 if (dlg_widget_active (user)) {
109 h->ret_value = B_USER + 6;
110 dlg_stop (h);
111 return MSG_HANDLED;
114 if (dlg_widget_active (status)) {
115 h->ret_value = B_USER + 7;
116 dlg_stop (h);
117 return MSG_HANDLED;
121 if (tolower (parm) == user_hotkey && dlg_widget_active (user)
122 && dlg_widget_active (status)) {
123 my_radio->sel = 3;
124 dlg_select_widget (my_radio); /* force redraw */
125 dlg_select_widget (user);
126 return MSG_HANDLED;
128 return MSG_NOT_HANDLED;
130 default:
131 return default_dlg_callback (h, msg, parm);
135 static void
136 display_init (int radio_sel, char *init_text, int _check_status,
137 char **_status)
139 static const char *display_title = N_("Listing mode");
140 static int i18n_displays_flag;
141 const char *user_mini_status = _("user &Mini status");
142 const char *ok_button = _("&OK");
143 const char *cancel_button = _("&Cancel");
145 static int button_start = 30;
147 displays_status = _status;
149 if (!i18n_displays_flag) {
150 int i, l, maxlen = 0;
151 const char *cp;
153 display_title = _(display_title);
154 for (i = 0; i < LIST_TYPES; i++) {
155 displays[i] = _(displays[i]);
156 if ((l = strlen (displays[i])) > maxlen)
157 maxlen = l;
160 i = strlen (ok_button) + 5;
161 l = strlen (cancel_button) + 3;
162 l = max (i, l);
164 i = maxlen + l + 16;
165 if (i > DISPLAY_X)
166 DISPLAY_X = i;
168 i = strlen (user_mini_status) + 13;
169 if (i > DISPLAY_X)
170 DISPLAY_X = i;
172 i = strlen (display_title) + 10;
173 if (i > DISPLAY_X)
174 DISPLAY_X = i;
176 button_start = DISPLAY_X - l - 5;
178 /* get hotkey of user-defined format string */
179 cp = strchr (displays[USER_TYPE], '&');
180 if (cp != NULL && *++cp != '\0')
181 user_hotkey = tolower ((unsigned char) *cp);
183 i18n_displays_flag = 1;
185 dd = create_dlg (0, 0, DISPLAY_Y, DISPLAY_X, dialog_colors,
186 display_callback, "[Listing Mode...]", display_title,
187 DLG_CENTER | DLG_REVERSE);
189 add_widget (dd,
190 button_new (4, button_start, B_CANCEL, NORMAL_BUTTON,
191 cancel_button, 0));
193 add_widget (dd,
194 button_new (3, button_start, B_ENTER, DEFPUSH_BUTTON,
195 ok_button, 0));
197 status =
198 input_new (10, 9, INPUT_COLOR, DISPLAY_X - 14, _status[radio_sel],
199 "mini-input", INPUT_COMPLETE_DEFAULT);
200 add_widget (dd, status);
201 input_set_point (status, 0);
203 check_status =
204 check_new (9, 5, _check_status, user_mini_status);
205 add_widget (dd, check_status);
207 user =
208 input_new (7, 9, INPUT_COLOR, DISPLAY_X - 14, init_text,
209 "user-fmt-input", INPUT_COMPLETE_DEFAULT);
210 add_widget (dd, user);
211 input_set_point (user, 0);
213 my_radio = radio_new (3, 5, LIST_TYPES, displays);
214 my_radio->sel = my_radio->pos = current_mode;
215 add_widget (dd, my_radio);
219 display_box (WPanel *panel, char **userp, char **minip, int *use_msformat, int num)
221 int result, i;
222 char *section = NULL;
223 const char *p;
225 if (!panel) {
226 p = get_nth_panel_name (num);
227 panel = g_new (WPanel, 1);
228 panel->list_type = list_full;
229 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
230 panel->user_mini_status = 0;
231 for (i = 0; i < LIST_TYPES; i++)
232 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
233 section = g_strconcat ("Temporal:", p, (char *) NULL);
234 if (!profile_has_section (section, profile_name)) {
235 g_free (section);
236 section = g_strdup (p);
238 panel_load_setup (panel, section);
239 g_free (section);
242 current_mode = panel->list_type;
243 display_init (current_mode, panel->user_format,
244 panel->user_mini_status, panel->user_status_format);
246 run_dlg (dd);
248 result = -1;
250 if (section) {
251 g_free (panel->user_format);
252 for (i = 0; i < LIST_TYPES; i++)
253 g_free (panel->user_status_format [i]);
254 g_free (panel);
257 if (dd->ret_value != B_CANCEL){
258 result = my_radio->sel;
259 *userp = g_strdup (user->buffer);
260 *minip = g_strdup (status->buffer);
261 *use_msformat = check_status->state & C_BOOL;
263 destroy_dlg (dd);
265 return result;
268 static int SORT_X = 60, SORT_Y = 14;
270 static const char *sort_orders_names [SORT_TYPES];
272 sortfn *
273 sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive, int *exec_first)
275 int i, r, l;
276 sortfn *result;
277 WCheck *c, *case_sense, *exec_ff;
279 const char *ok_button = _("&OK");
280 const char *cancel_button = _("&Cancel");
281 const char *reverse_label = _("&Reverse");
282 const char *case_label = _("case sensi&tive");
283 const char *sort_title = _("Sort order");
284 const char *exec_label = _("Executable first");
286 static int i18n_sort_flag = 0, check_pos = 0, button_pos = 0;
288 if (!i18n_sort_flag) {
289 int maxlen = 0;
290 for (i = SORT_TYPES - 1; i >= 0; i--) {
291 sort_orders_names[i] = _(sort_orders[i].sort_name);
292 r = strlen (sort_orders_names[i]);
293 if (r > maxlen)
294 maxlen = r;
297 check_pos = maxlen + 9;
299 r = strlen (reverse_label) + 4;
300 i = strlen (case_label) + 4;
301 if (i > r)
302 r = i;
304 l = strlen (ok_button) + 6;
305 i = strlen (cancel_button) + 4;
306 if (i > l)
307 l = i;
309 i = check_pos + max (r, l) + 2;
311 if (i > SORT_X)
312 SORT_X = i;
314 i = strlen (sort_title) + 6;
315 if (i > SORT_X)
316 SORT_X = i;
318 button_pos = SORT_X - l - 2;
320 i18n_sort_flag = 1;
323 result = 0;
325 for (i = 0; i < SORT_TYPES; i++)
326 if ((sortfn *) (sort_orders[i].sort_fn) == sort_fn) {
327 current_mode = i;
328 break;
331 dd = create_dlg (0, 0, SORT_Y, SORT_X, dialog_colors, NULL,
332 "[Sort Order...]", sort_title, DLG_CENTER | DLG_REVERSE);
334 add_widget (dd,
335 button_new (10, button_pos, B_CANCEL, NORMAL_BUTTON,
336 cancel_button, 0));
338 add_widget (dd,
339 button_new (9, button_pos, B_ENTER, DEFPUSH_BUTTON,
340 ok_button, 0));
342 exec_ff = check_new (5, check_pos, *exec_first, exec_label);
343 add_widget (dd, exec_ff);
344 case_sense = check_new (4, check_pos, *case_sensitive, case_label);
345 add_widget (dd, case_sense);
346 c = check_new (3, check_pos, *reverse, reverse_label);
347 add_widget (dd, c);
349 my_radio = radio_new (3, 3, SORT_TYPES, sort_orders_names);
350 my_radio->sel = my_radio->pos = current_mode;
352 add_widget (dd, my_radio);
353 run_dlg (dd);
355 r = dd->ret_value;
356 if (r != B_CANCEL) {
357 result = (sortfn *) sort_orders[my_radio->sel].sort_fn;
358 *reverse = c->state & C_BOOL;
359 *case_sensitive = case_sense->state & C_BOOL;
360 *exec_first = exec_ff->state & C_BOOL;
361 } else
362 result = sort_fn;
363 destroy_dlg (dd);
365 return result;
368 #define CONFY 11
369 #define CONFX 46
371 static int my_delete;
372 static int my_directory_hotlist_delete;
373 static int my_overwrite;
374 static int my_execute;
375 static int my_exit;
377 static QuickWidget conf_widgets [] = {
378 { quick_button, 4, 6, 4, CONFY, N_("&Cancel"),
379 0, B_CANCEL, 0, 0, NULL },
380 { quick_button, 4, 6, 3, CONFY, N_("&OK"),
381 0, B_ENTER, 0, 0, NULL },
383 { quick_checkbox, 1, 13, 7, CONFY, N_(" confirm di&Rectory hotlist delete "),
384 11, 0, &my_directory_hotlist_delete, NULL, NULL },
385 { quick_checkbox, 1, 13, 6, CONFY, N_(" confirm &Exit "),
386 9, 0, &my_exit, 0, NULL },
387 { quick_checkbox, 1, 13, 5, CONFY, N_(" confirm e&Xecute "),
388 10, 0, &my_execute, 0, NULL },
389 { quick_checkbox, 1, 13, 4, CONFY, N_(" confirm o&Verwrite "),
390 10, 0, &my_overwrite, 0, NULL },
391 { quick_checkbox, 1, 13, 3, CONFY, N_(" confirm &Delete "),
392 9, 0, &my_delete, 0, NULL },
393 NULL_QuickWidget
396 static QuickDialog confirmation =
397 { CONFX, CONFY, -1, -1, N_(" Confirmation "), "[Confirmation]",
398 conf_widgets, 0
401 void
402 confirm_box (void)
405 #ifdef ENABLE_NLS
406 static int i18n_flag = 0;
408 if (!i18n_flag)
410 register int i = sizeof(conf_widgets)/sizeof(QuickWidget) - 1;
411 int l1, maxlen = 0;
412 while (i--)
414 conf_widgets [i].text = _(conf_widgets [i].text);
415 l1 = strlen (conf_widgets [i].text) + 3;
416 if (l1 > maxlen)
417 maxlen = l1;
421 * If buttons start on 4/6, checkboxes (with some add'l space)
422 * must take not more than it.
424 confirmation.xlen = (maxlen + 5) * 6 / 4;
427 * And this for the case when buttons with some space to the right
428 * do not fit within 2/6
430 l1 = strlen (conf_widgets [0].text) + 3;
431 i = strlen (conf_widgets [1].text) + 5;
432 if (i > l1)
433 l1 = i;
435 i = (l1 + 3) * 6 / 2;
436 if (i > confirmation.xlen)
437 confirmation.xlen = i;
439 confirmation.title = _(confirmation.title);
441 i18n_flag = confirmation.i18n = 1;
444 #endif /* ENABLE_NLS */
446 my_delete = confirm_delete;
447 my_overwrite = confirm_overwrite;
448 my_execute = confirm_execute;
449 my_exit = confirm_exit;
450 my_directory_hotlist_delete = confirm_directory_hotlist_delete;
452 if (quick_dialog (&confirmation) != B_CANCEL){
453 confirm_delete = my_delete;
454 confirm_overwrite = my_overwrite;
455 confirm_execute = my_execute;
456 confirm_exit = my_exit;
457 confirm_directory_hotlist_delete = my_directory_hotlist_delete;
461 #define DISPY 11
462 #define DISPX 46
465 #ifndef HAVE_CHARSET
467 static int new_mode;
468 static int new_meta;
470 static const char *display_bits_str [] =
471 { N_("Full 8 bits output"), N_("ISO 8859-1"), N_("7 bits") };
473 static QuickWidget display_widgets [] = {
474 { quick_button, 4, 6, 4, DISPY, N_("&Cancel"),
475 0, B_CANCEL, 0, 0, NULL },
476 { quick_button, 4, 6, 3, DISPY, N_("&OK"),
477 0, B_ENTER, 0, 0, NULL },
478 { quick_checkbox, 4, DISPX, 7, DISPY, N_("F&ull 8 bits input"),
479 0, 0, &new_meta, 0, NULL },
480 { quick_radio, 4, DISPX, 3, DISPY, "", 3, 0,
481 &new_mode, const_cast(char **, display_bits_str), NULL },
482 NULL_QuickWidget
485 static QuickDialog display_bits =
486 { DISPX, DISPY, -1, -1, N_(" Display bits "), "[Display bits]",
487 display_widgets, 0 };
489 void
490 display_bits_box (void)
492 int current_mode;
494 #ifdef ENABLE_NLS
495 static int i18n_flag = 0;
496 if (!i18n_flag)
498 register int i;
499 int l1, maxlen = 0;
500 for (i = 0; i < 3; i++)
502 display_widgets [i].text = _(display_widgets[i].text);
503 display_bits_str [i] = _(display_bits_str [i]);
504 l1 = strlen (display_bits_str [i]);
505 if (l1 > maxlen)
506 maxlen = l1;
508 l1 = strlen (display_widgets [2].text);
509 if (l1 > maxlen)
510 maxlen = l1;
513 display_bits.xlen = (maxlen + 5) * 6 / 4;
515 /* See above confirm_box */
516 l1 = strlen (display_widgets [0].text) + 3;
517 i = strlen (display_widgets [1].text) + 5;
518 if (i > l1)
519 l1 = i;
521 i = (l1 + 3) * 6 / 2;
522 if (i > display_bits.xlen)
523 display_bits.xlen = i;
525 display_bits.title = _(display_bits.title);
526 i18n_flag = display_bits.i18n = 1;
529 #endif /* ENABLE_NLS */
531 if (full_eight_bits)
532 current_mode = 0;
533 else if (eight_bit_clean)
534 current_mode = 1;
535 else
536 current_mode = 2;
538 display_widgets [3].value = current_mode;
539 new_meta = !use_8th_bit_as_meta;
540 if (quick_dialog (&display_bits) != B_ENTER)
541 return;
543 eight_bit_clean = new_mode < 2;
544 full_eight_bits = new_mode == 0;
545 #ifndef HAVE_SLANG
546 meta (stdscr, eight_bit_clean);
547 #else
548 SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
549 #endif
550 use_8th_bit_as_meta = !new_meta;
554 #else /* HAVE_CHARSET */
557 static int new_display_codepage;
559 static WLabel *cplabel;
560 static WCheck *inpcheck;
562 static int
563 sel_charset_button (int action)
565 const char *cpname;
566 char buf[64];
567 new_display_codepage = select_charset (new_display_codepage, 1);
568 cpname = (new_display_codepage < 0)
569 ? _("Other 8 bit")
570 : codepages[new_display_codepage].name;
572 /* avoid strange bug with label repainting */
573 g_snprintf (buf, sizeof (buf), "%-27s", cpname);
574 label_set_text (cplabel, buf);
575 return 0;
578 static Dlg_head *
579 init_disp_bits_box (void)
581 const char *cpname;
582 Dlg_head *dbits_dlg;
584 do_refresh ();
586 dbits_dlg =
587 create_dlg (0, 0, DISPY, DISPX, dialog_colors, NULL,
588 "[Display bits]", _(" Display bits "), DLG_CENTER | DLG_REVERSE);
590 add_widget (dbits_dlg,
591 label_new (3, 4, _("Input / display codepage:")));
593 cpname = (new_display_codepage < 0)
594 ? _("Other 8 bit")
595 : codepages[new_display_codepage].name;
596 cplabel = label_new (4, 4, cpname);
597 add_widget (dbits_dlg, cplabel);
599 add_widget (dbits_dlg,
600 button_new (DISPY - 3, DISPX / 2 + 3, B_CANCEL,
601 NORMAL_BUTTON, _("&Cancel"), 0));
602 add_widget (dbits_dlg,
603 button_new (DISPY - 3, 7, B_ENTER, NORMAL_BUTTON, _("&OK"),
604 0));
606 inpcheck =
607 check_new (6, 4, !use_8th_bit_as_meta, _("F&ull 8 bits input"));
608 add_widget (dbits_dlg, inpcheck);
610 cpname = _("&Select");
611 add_widget (dbits_dlg,
612 button_new (4, DISPX - 8 - strlen (cpname), B_USER,
613 NORMAL_BUTTON, cpname, sel_charset_button));
615 return dbits_dlg;
618 void
619 display_bits_box (void)
621 Dlg_head *dbits_dlg;
622 new_display_codepage = display_codepage;
624 application_keypad_mode ();
625 dbits_dlg = init_disp_bits_box ();
627 run_dlg (dbits_dlg);
629 if (dbits_dlg->ret_value == B_ENTER) {
630 const char *errmsg;
631 display_codepage = new_display_codepage;
632 errmsg =
633 init_translation_table (source_codepage, display_codepage);
634 if (errmsg)
635 message (D_ERROR, MSG_ERROR, "%s", errmsg);
636 #ifndef HAVE_SLANG
637 meta (stdscr, display_codepage != 0);
638 #else
639 SLsmg_Display_Eight_Bit = (display_codepage != 0
640 && display_codepage != 1) ? 128 : 160;
641 #endif
642 use_8th_bit_as_meta = !(inpcheck->state & C_BOOL);
644 destroy_dlg (dbits_dlg);
645 repaint_screen ();
648 #endif /* HAVE_CHARSET */
651 #define TREE_Y 20
652 #define TREE_X 60
654 static cb_ret_t
655 tree_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
657 switch (msg) {
659 case DLG_POST_KEY:
660 /* The enter key will be processed by the tree widget */
661 if (parm == '\n') {
662 h->ret_value = B_ENTER;
663 dlg_stop (h);
665 return MSG_HANDLED;
667 default:
668 return default_dlg_callback (h, msg, parm);
672 /* Show tree in a box, not on a panel */
673 char *
674 tree_box (const char *current_dir)
676 WTree *mytree;
677 Dlg_head *dlg;
678 char *val;
679 WButtonBar *bar;
681 /* Create the components */
682 dlg = create_dlg (0, 0, TREE_Y, TREE_X, dialog_colors,
683 tree_callback, "[Directory Tree]", NULL, DLG_CENTER | DLG_REVERSE);
684 mytree = tree_new (0, 2, 2, TREE_Y - 6, TREE_X - 5);
685 add_widget (dlg, mytree);
686 bar = buttonbar_new(1);
687 add_widget (dlg, bar);
688 ((Widget *) bar)->x = 0;
689 ((Widget *) bar)->y = LINES - 1;
691 run_dlg (dlg);
692 if (dlg->ret_value == B_ENTER)
693 val = g_strdup (tree_selected_name (mytree));
694 else
695 val = 0;
697 destroy_dlg (dlg);
698 return val;
701 #ifdef USE_VFS
703 #if defined(USE_NETCODE)
704 #define VFSY 17
705 #define VFS_WIDGETBASE 10
706 #else
707 #define VFSY 8
708 #define VFS_WIDGETBASE 0
709 #endif
711 #define VFSX 56
713 static char *ret_timeout;
715 #if defined(USE_NETCODE)
716 static char *ret_passwd;
717 static char *ret_directory_timeout;
718 static char *ret_ftp_proxy;
719 static int ret_use_netrc;
720 static int ret_ftpfs_use_passive_connections;
721 static int ret_ftpfs_use_passive_connections_over_proxy;
722 #endif
724 static QuickWidget confvfs_widgets [] = {
725 { quick_button, 30, VFSX, VFSY - 3, VFSY, N_("&Cancel"),
726 0, B_CANCEL, 0, 0, NULL },
727 { quick_button, 12, VFSX, VFSY - 3, VFSY, N_("&OK"),
728 0, B_ENTER, 0, 0, NULL },
729 #if defined(USE_NETCODE)
730 { quick_checkbox, 4, VFSX, 12, VFSY, N_("Use passive mode over pro&xy"), 0, 0,
731 &ret_ftpfs_use_passive_connections_over_proxy, 0, NULL },
732 { quick_checkbox, 4, VFSX, 11, VFSY, N_("Use &passive mode"), 0, 0,
733 &ret_ftpfs_use_passive_connections, 0, NULL },
734 { quick_checkbox, 4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), 0, 0,
735 &ret_use_netrc, 0, NULL },
736 { quick_input, 4, VFSX, 9, VFSY, "", 48, 0, 0, &ret_ftp_proxy,
737 "input-ftp-proxy" },
738 { quick_checkbox, 4, VFSX, 8, VFSY, N_("&Always use ftp proxy"), 0, 0,
739 &ftpfs_always_use_proxy, 0, NULL },
740 { quick_label, 49, VFSX, 7, VFSY, N_("sec"),
741 0, 0, 0, 0, NULL },
742 { quick_input, 38, VFSX, 7, VFSY, "", 10, 0, 0, &ret_directory_timeout,
743 "input-timeout" },
744 { quick_label, 4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:"),
745 0, 0, 0, 0, NULL },
746 { quick_input, 4, VFSX, 6, VFSY, "", 48, 0, 0, &ret_passwd,
747 "input-passwd" },
748 { quick_label, 4, VFSX, 5, VFSY, N_("ftp anonymous password:"),
749 0, 0, 0, 0, NULL },
750 #endif
751 { quick_label, 49, VFSX, 3, VFSY, "sec",
752 0, 0, 0, 0, NULL },
753 { quick_input, 38, VFSX, 3, VFSY, "", 10, 0, 0, &ret_timeout,
754 "input-timo-vfs" },
755 { quick_label, 4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:"),
756 0, 0, 0, 0, NULL },
757 NULL_QuickWidget
760 static QuickDialog confvfs_dlg =
761 { VFSX, VFSY, -1, -1, N_(" Virtual File System Setting "),
762 "[Virtual FS]", confvfs_widgets, 0 };
764 void
765 configure_vfs (void)
767 char buffer2[BUF_TINY];
768 #if defined(USE_NETCODE)
769 char buffer3[BUF_TINY];
771 ret_use_netrc = use_netrc;
772 ret_ftpfs_use_passive_connections = ftpfs_use_passive_connections;
773 ret_ftpfs_use_passive_connections_over_proxy = ftpfs_use_passive_connections_over_proxy;
774 g_snprintf(buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
775 confvfs_widgets[8].text = buffer3;
776 confvfs_widgets[10].text = ftpfs_anonymous_passwd;
777 confvfs_widgets[5].text = ftpfs_proxy_host;
778 #endif
779 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
780 confvfs_widgets [3 + VFS_WIDGETBASE].text = buffer2;
782 if (quick_dialog (&confvfs_dlg) != B_CANCEL) {
783 vfs_timeout = atoi (ret_timeout);
784 g_free (ret_timeout);
785 if (vfs_timeout < 0 || vfs_timeout > 10000)
786 vfs_timeout = 10;
787 #if defined(USE_NETCODE)
788 g_free (ftpfs_anonymous_passwd);
789 ftpfs_anonymous_passwd = ret_passwd;
790 g_free (ftpfs_proxy_host);
791 ftpfs_proxy_host = ret_ftp_proxy;
792 ftpfs_directory_timeout = atoi(ret_directory_timeout);
793 use_netrc = ret_use_netrc;
794 ftpfs_use_passive_connections = ret_ftpfs_use_passive_connections;
795 ftpfs_use_passive_connections_over_proxy = ret_ftpfs_use_passive_connections_over_proxy;
796 g_free (ret_directory_timeout);
797 #endif
801 #endif /* USE_VFS */
803 char *
804 cd_dialog (void)
806 QuickDialog Quick_input;
807 QuickWidget quick_widgets [] = {
808 { quick_input, 6, 57, 2, 0, "", 50, 0, 0, 0, "input" },
809 { quick_label, 3, 57, 2, 0, "", 0, 0, 0, 0, NULL },
810 NULL_QuickWidget
812 char *my_str;
813 int len;
815 Quick_input.xlen = 57;
816 Quick_input.title = _("Quick cd");
817 Quick_input.help = "[Quick cd]";
818 quick_widgets [0].value = 2; /* want cd like completion */
819 quick_widgets [1].text = _("cd");
820 quick_widgets [1].y_divisions =
821 quick_widgets [0].y_divisions = Quick_input.ylen = 5;
823 len = strlen (quick_widgets [1].text);
825 quick_widgets [0].relative_x =
826 quick_widgets [1].relative_x + len + 1;
828 Quick_input.xlen = len + quick_widgets [0].hotkey_pos + 7;
829 quick_widgets [0].x_divisions =
830 quick_widgets [1].x_divisions = Quick_input.xlen;
832 Quick_input.i18n = 1;
833 Quick_input.xpos = 2;
834 Quick_input.ypos = LINES - 2 - Quick_input.ylen;
835 quick_widgets [0].str_result = &my_str;
837 Quick_input.widgets = quick_widgets;
838 if (quick_dialog (&Quick_input) != B_CANCEL){
839 return my_str;
840 } else
841 return 0;
844 void
845 symlink_dialog (const char *existing, const char *new, char **ret_existing,
846 char **ret_new)
848 QuickDialog Quick_input;
849 QuickWidget quick_widgets[] = {
850 {quick_button, 50, 80, 6, 8, N_("&Cancel"), 0, B_CANCEL, 0, 0,
851 NULL},
852 {quick_button, 16, 80, 6, 8, N_("&OK"), 0, B_ENTER, 0, 0, NULL},
853 {quick_input, 4, 80, 5, 8, "", 58, 0, 0, 0, "input-1"},
854 {quick_label, 4, 80, 4, 8, N_("Symbolic link filename:"), 0, 0, 0,
855 0, NULL},
856 {quick_input, 4, 80, 3, 8, "", 58, 0, 0, 0, "input-2"},
857 {quick_label, 4, 80, 2, 8,
858 N_("Existing filename (filename symlink will point to):"), 0, 0,
859 0, 0, NULL},
860 NULL_QuickWidget
863 Quick_input.xlen = 64;
864 Quick_input.ylen = 12;
865 Quick_input.title = N_("Symbolic link");
866 Quick_input.help = "[File Menu]";
867 Quick_input.i18n = 0;
868 quick_widgets[2].text = new;
869 quick_widgets[4].text = existing;
870 Quick_input.xpos = -1;
871 quick_widgets[2].str_result = ret_new;
872 quick_widgets[4].str_result = ret_existing;
874 Quick_input.widgets = quick_widgets;
875 if (quick_dialog (&Quick_input) == B_CANCEL) {
876 *ret_new = NULL;
877 *ret_existing = NULL;
881 #ifdef WITH_BACKGROUND
882 #define B_STOP (B_USER+1)
883 #define B_RESUME (B_USER+2)
884 #define B_KILL (B_USER+3)
886 static int JOBS_X = 60;
887 #define JOBS_Y 15
888 static WListbox *bg_list;
889 static Dlg_head *jobs_dlg;
891 static void
892 jobs_fill_listbox (void)
894 static const char *state_str [2];
895 TaskList *tl = task_list;
897 if (!state_str [0]){
898 state_str [0] = _("Running ");
899 state_str [1] = _("Stopped");
902 while (tl){
903 char *s;
905 s = g_strconcat (state_str [tl->state], " ", tl->info, (char *) NULL);
906 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
907 g_free (s);
908 tl = tl->next;
912 static int
913 task_cb (int action)
915 TaskList *tl;
916 int sig = 0;
918 if (!bg_list->list)
919 return 0;
921 /* Get this instance information */
922 tl = (TaskList *) bg_list->current->data;
924 # ifdef SIGTSTP
925 if (action == B_STOP){
926 sig = SIGSTOP;
927 tl->state = Task_Stopped;
928 } else if (action == B_RESUME){
929 sig = SIGCONT;
930 tl->state = Task_Running;
931 } else
932 # endif
933 if (action == B_KILL){
934 sig = SIGKILL;
937 if (sig == SIGINT)
938 unregister_task_running (tl->pid, tl->fd);
940 kill (tl->pid, sig);
941 listbox_remove_list (bg_list);
942 jobs_fill_listbox ();
944 /* This can be optimized to just redraw this widget :-) */
945 dlg_redraw (jobs_dlg);
947 return 0;
950 static struct
952 const char* name;
953 int xpos;
954 int value;
955 int (*callback)(int);
957 job_buttons [] =
959 {N_("&Stop"), 3, B_STOP, task_cb},
960 {N_("&Resume"), 12, B_RESUME, task_cb},
961 {N_("&Kill"), 23, B_KILL, task_cb},
962 {N_("&OK"), 35, B_CANCEL, NULL }
965 void
966 jobs_cmd (void)
968 register int i;
969 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
971 #ifdef ENABLE_NLS
972 static int i18n_flag = 0;
973 if (!i18n_flag)
975 int startx = job_buttons [0].xpos;
976 int len;
978 for (i = 0; i < n_buttons; i++)
980 job_buttons [i].name = _(job_buttons [i].name);
982 len = strlen (job_buttons [i].name) + 4;
983 JOBS_X = max (JOBS_X, startx + len + 3);
985 job_buttons [i].xpos = startx;
986 startx += len;
989 /* Last button - Ok a.k.a. Cancel :) */
990 job_buttons [n_buttons - 1].xpos =
991 JOBS_X - strlen (job_buttons [n_buttons - 1].name) - 7;
993 i18n_flag = 1;
995 #endif /* ENABLE_NLS */
997 jobs_dlg = create_dlg (0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL,
998 "[Background jobs]", _("Background Jobs"),
999 DLG_CENTER | DLG_REVERSE);
1001 bg_list = listbox_new (2, 3, JOBS_X-7, JOBS_Y-9, 0);
1002 add_widget (jobs_dlg, bg_list);
1004 i = n_buttons;
1005 while (i--)
1007 add_widget (jobs_dlg, button_new (JOBS_Y-4,
1008 job_buttons [i].xpos, job_buttons [i].value,
1009 NORMAL_BUTTON, job_buttons [i].name,
1010 job_buttons [i].callback));
1013 /* Insert all of task information in the list */
1014 jobs_fill_listbox ();
1015 run_dlg (jobs_dlg);
1017 destroy_dlg (jobs_dlg);
1019 #endif /* WITH_BACKGROUND */
1021 #ifdef WITH_SMBFS
1022 struct smb_authinfo *
1023 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
1024 const char *user)
1026 static int dialog_x = 44;
1027 enum { b0 = 3, dialog_y = 12};
1028 struct smb_authinfo *return_value;
1029 static const char* labs[] = {N_("Domain:"), N_("Username:"), N_("Password:")};
1030 static const char* buts[] = {N_("&OK"), N_("&Cancel")};
1031 static int ilen = 30, istart = 14;
1032 static int b2 = 30;
1033 char *title;
1034 WInput *in_password;
1035 WInput *in_user;
1036 WInput *in_domain;
1037 Dlg_head *auth_dlg;
1039 #ifdef ENABLE_NLS
1040 static int i18n_flag = 0;
1042 if (!i18n_flag)
1044 register int i = sizeof(labs)/sizeof(labs[0]);
1045 int l1, maxlen = 0;
1047 while (i--)
1049 l1 = strlen (labs [i] = _(labs [i]));
1050 if (l1 > maxlen)
1051 maxlen = l1;
1053 i = maxlen + ilen + 7;
1054 if (i > dialog_x)
1055 dialog_x = i;
1057 for (i = sizeof(buts)/sizeof(buts[0]), l1 = 0; i--; )
1059 l1 += strlen (buts [i] = _(buts [i]));
1061 l1 += 15;
1062 if (l1 > dialog_x)
1063 dialog_x = l1;
1065 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1066 istart = dialog_x - 3 - ilen;
1068 b2 = dialog_x - (strlen(buts[1]) + 6);
1070 i18n_flag = 1;
1073 #endif /* ENABLE_NLS */
1075 if (!domain)
1076 domain = "";
1077 if (!user)
1078 user = "";
1080 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1082 auth_dlg = create_dlg (0, 0, dialog_y, dialog_x, dialog_colors, NULL,
1083 "[Smb Authinfo]", title, DLG_CENTER | DLG_REVERSE);
1085 g_free (title);
1087 in_user = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name", INPUT_COMPLETE_DEFAULT);
1088 add_widget (auth_dlg, in_user);
1090 in_domain = input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain", INPUT_COMPLETE_DEFAULT);
1091 add_widget (auth_dlg, in_domain);
1092 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON,
1093 buts[1], 0));
1094 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON,
1095 buts[0], 0));
1097 in_password = input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password", INPUT_COMPLETE_DEFAULT);
1098 in_password->completion_flags = 0;
1099 in_password->is_password = 1;
1100 add_widget (auth_dlg, in_password);
1102 add_widget (auth_dlg, label_new (7, 3, labs[2]));
1103 add_widget (auth_dlg, label_new (5, 3, labs[1]));
1104 add_widget (auth_dlg, label_new (3, 3, labs[0]));
1106 run_dlg (auth_dlg);
1108 switch (auth_dlg->ret_value) {
1109 case B_CANCEL:
1110 return_value = 0;
1111 break;
1112 default:
1113 return_value = g_new (struct smb_authinfo, 1);
1114 if (return_value) {
1115 return_value->host = g_strdup (host);
1116 return_value->share = g_strdup (share);
1117 return_value->domain = g_strdup (in_domain->buffer);
1118 return_value->user = g_strdup (in_user->buffer);
1119 return_value->password = g_strdup (in_password->buffer);
1123 destroy_dlg (auth_dlg);
1125 return return_value;
1127 #endif /* WITH_SMBFS */