Changes in directory listing format:
[midnight-commander.git] / src / boxes.c
blob0fd2a0b70aaeb5b0123c2dc4e9721b65485a7c46
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>
31 #include <sys/types.h>
32 #include <sys/stat.h>
34 #include "global.h"
35 #include "tty.h"
36 #include "win.h" /* Our window tools */
37 #include "color.h" /* Color definitions */
38 #include "dialog.h" /* The nice dialog manager */
39 #include "widget.h" /* The widgets for the nice dialog manager */
40 #include "wtools.h"
41 #include "setup.h" /* For profile_name */
42 #include "profile.h" /* Load/save user formats */
43 #include "key.h" /* XCTRL and ALT macros */
44 #include "command.h" /* For cmdline */
45 #include "dir.h"
46 #include "panel.h"
47 #include "boxes.h"
48 #include "main.h" /* For the confirm_* variables */
49 #include "tree.h"
50 #include "layout.h" /* for get_nth_panel_name proto */
51 #include "background.h" /* task_list */
53 #ifdef HAVE_CHARSET
54 #include "charsets.h"
55 #include "selcodepage.h"
56 #endif
58 #ifdef USE_NETCODE
59 # include "../vfs/ftpfs.h"
60 #endif
62 #ifdef USE_VFS
63 #include "../vfs/gc.h"
64 #endif
66 static int DISPLAY_X = 45, DISPLAY_Y = 14;
68 static Dlg_head *dd;
69 static WRadio *my_radio;
70 static WInput *user;
71 static WInput *status;
72 static WCheck *check_status;
73 static int current_mode;
75 static char **displays_status;
77 /* Controls whether the array strings have been translated */
78 static const char *displays [LIST_TYPES] = {
79 N_("&Full file list"),
80 N_("&Brief file list"),
81 N_("&Long file list"),
82 N_("&User defined:")
85 /* Index in displays[] for "user defined" */
86 #define USER_TYPE 3
88 static int user_hotkey = 'u';
90 static cb_ret_t
91 display_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
93 switch (msg) {
94 case DLG_UNFOCUS:
95 if (dlg_widget_active (my_radio)) {
96 assign_text (status, displays_status[my_radio->sel]);
97 input_set_point (status, 0);
99 return MSG_HANDLED;
101 case DLG_KEY:
102 if (parm == '\n') {
103 if (dlg_widget_active (my_radio)) {
104 assign_text (status, displays_status[my_radio->sel]);
105 dlg_stop (h);
106 return MSG_HANDLED;
109 if (dlg_widget_active (user)) {
110 h->ret_value = B_USER + 6;
111 dlg_stop (h);
112 return MSG_HANDLED;
115 if (dlg_widget_active (status)) {
116 h->ret_value = B_USER + 7;
117 dlg_stop (h);
118 return MSG_HANDLED;
122 if (tolower (parm) == user_hotkey && dlg_widget_active (user)
123 && dlg_widget_active (status)) {
124 my_radio->sel = 3;
125 dlg_select_widget (my_radio); /* force redraw */
126 dlg_select_widget (user);
127 return MSG_HANDLED;
129 return MSG_NOT_HANDLED;
131 default:
132 return default_dlg_callback (h, msg, parm);
136 static void
137 display_init (int radio_sel, char *init_text, int _check_status,
138 char **_status)
140 static const char *display_title = N_("Listing mode");
141 static int i18n_displays_flag;
142 const char *user_mini_status = _("user &Mini status");
143 const char *ok_button = _("&OK");
144 const char *cancel_button = _("&Cancel");
146 static int button_start = 30;
148 displays_status = _status;
150 if (!i18n_displays_flag) {
151 int i, l, maxlen = 0;
152 const char *cp;
154 display_title = _(display_title);
155 for (i = 0; i < LIST_TYPES; i++) {
156 displays[i] = _(displays[i]);
157 if ((l = strlen (displays[i])) > maxlen)
158 maxlen = l;
161 i = strlen (ok_button) + 5;
162 l = strlen (cancel_button) + 3;
163 l = max (i, l);
165 i = maxlen + l + 16;
166 if (i > DISPLAY_X)
167 DISPLAY_X = i;
169 i = strlen (user_mini_status) + 13;
170 if (i > DISPLAY_X)
171 DISPLAY_X = i;
173 i = strlen (display_title) + 10;
174 if (i > DISPLAY_X)
175 DISPLAY_X = i;
177 button_start = DISPLAY_X - l - 5;
179 /* get hotkey of user-defined format string */
180 cp = strchr (displays[USER_TYPE], '&');
181 if (cp != NULL && *++cp != '\0')
182 user_hotkey = tolower ((unsigned char) *cp);
184 i18n_displays_flag = 1;
186 dd = create_dlg (0, 0, DISPLAY_Y, DISPLAY_X, dialog_colors,
187 display_callback, "[Listing Mode...]", display_title,
188 DLG_CENTER | DLG_REVERSE);
190 add_widget (dd,
191 button_new (4, button_start, B_CANCEL, NORMAL_BUTTON,
192 cancel_button, 0));
194 add_widget (dd,
195 button_new (3, button_start, B_ENTER, DEFPUSH_BUTTON,
196 ok_button, 0));
198 status =
199 input_new (10, 9, INPUT_COLOR, DISPLAY_X - 14, _status[radio_sel],
200 "mini-input");
201 add_widget (dd, status);
202 input_set_point (status, 0);
204 check_status =
205 check_new (9, 5, _check_status, user_mini_status);
206 add_widget (dd, check_status);
208 user =
209 input_new (7, 9, INPUT_COLOR, DISPLAY_X - 14, init_text,
210 "user-fmt-input");
211 add_widget (dd, user);
212 input_set_point (user, 0);
214 my_radio = radio_new (3, 5, LIST_TYPES, displays);
215 my_radio->sel = my_radio->pos = current_mode;
216 add_widget (dd, my_radio);
220 display_box (WPanel *panel, char **userp, char **minip, int *use_msformat, int num)
222 int result, i;
223 char *section = NULL;
224 const char *p;
226 if (!panel) {
227 p = get_nth_panel_name (num);
228 panel = g_new (WPanel, 1);
229 panel->list_type = list_full;
230 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
231 panel->user_mini_status = 0;
232 for (i = 0; i < LIST_TYPES; i++)
233 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
234 section = g_strconcat ("Temporal:", p, (char *) NULL);
235 if (!profile_has_section (section, profile_name)) {
236 g_free (section);
237 section = g_strdup (p);
239 panel_load_setup (panel, section);
240 g_free (section);
243 current_mode = panel->list_type;
244 display_init (current_mode, panel->user_format,
245 panel->user_mini_status, panel->user_status_format);
247 run_dlg (dd);
249 result = -1;
251 if (section) {
252 g_free (panel->user_format);
253 for (i = 0; i < LIST_TYPES; i++)
254 g_free (panel->user_status_format [i]);
255 g_free (panel);
258 if (dd->ret_value != B_CANCEL){
259 result = my_radio->sel;
260 *userp = g_strdup (user->buffer);
261 *minip = g_strdup (status->buffer);
262 *use_msformat = check_status->state & C_BOOL;
264 destroy_dlg (dd);
266 return result;
269 static int SORT_X = 40, SORT_Y = 14;
271 static const char *sort_orders_names [SORT_TYPES];
273 sortfn *
274 sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive)
276 int i, r, l;
277 sortfn *result;
278 WCheck *c, *case_sense;
280 const char *ok_button = _("&OK");
281 const char *cancel_button = _("&Cancel");
282 const char *reverse_label = _("&Reverse");
283 const char *case_label = _("case sensi&tive");
284 const char *sort_title = _("Sort order");
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 case_sense = check_new (4, check_pos, *case_sensitive, case_label);
343 add_widget (dd, case_sense);
344 c = check_new (3, check_pos, *reverse, reverse_label);
345 add_widget (dd, c);
347 my_radio = radio_new (3, 3, SORT_TYPES, sort_orders_names);
348 my_radio->sel = my_radio->pos = current_mode;
350 add_widget (dd, my_radio);
351 run_dlg (dd);
353 r = dd->ret_value;
354 if (r != B_CANCEL) {
355 result = (sortfn *) sort_orders[my_radio->sel].sort_fn;
356 *reverse = c->state & C_BOOL;
357 *case_sensitive = case_sense->state & C_BOOL;
358 } else
359 result = sort_fn;
360 destroy_dlg (dd);
362 return result;
365 #define CONFY 11
366 #define CONFX 46
368 static int my_delete;
369 static int my_directory_hotlist_delete;
370 static int my_overwrite;
371 static int my_execute;
372 static int my_exit;
374 static QuickWidget conf_widgets [] = {
375 { quick_button, 4, 6, 4, CONFY, N_("&Cancel"),
376 0, B_CANCEL, 0, 0, NULL },
377 { quick_button, 4, 6, 3, CONFY, N_("&OK"),
378 0, B_ENTER, 0, 0, NULL },
380 { quick_checkbox, 1, 13, 7, CONFY, N_(" confirm di&Rectory hotlist delete "),
381 11, 0, &my_directory_hotlist_delete, NULL, NULL },
382 { quick_checkbox, 1, 13, 6, CONFY, N_(" confirm &Exit "),
383 9, 0, &my_exit, 0, NULL },
384 { quick_checkbox, 1, 13, 5, CONFY, N_(" confirm e&Xecute "),
385 10, 0, &my_execute, 0, NULL },
386 { quick_checkbox, 1, 13, 4, CONFY, N_(" confirm o&Verwrite "),
387 10, 0, &my_overwrite, 0, NULL },
388 { quick_checkbox, 1, 13, 3, CONFY, N_(" confirm &Delete "),
389 9, 0, &my_delete, 0, NULL },
390 NULL_QuickWidget
393 static QuickDialog confirmation =
394 { CONFX, CONFY, -1, -1, N_(" Confirmation "), "[Confirmation]",
395 conf_widgets, 0
398 void
399 confirm_box (void)
402 #ifdef ENABLE_NLS
403 static int i18n_flag = 0;
405 if (!i18n_flag)
407 register int i = sizeof(conf_widgets)/sizeof(QuickWidget) - 1;
408 int l1, maxlen = 0;
409 while (i--)
411 conf_widgets [i].text = _(conf_widgets [i].text);
412 l1 = strlen (conf_widgets [i].text) + 3;
413 if (l1 > maxlen)
414 maxlen = l1;
418 * If buttons start on 4/6, checkboxes (with some add'l space)
419 * must take not more than it.
421 confirmation.xlen = (maxlen + 5) * 6 / 4;
424 * And this for the case when buttons with some space to the right
425 * do not fit within 2/6
427 l1 = strlen (conf_widgets [0].text) + 3;
428 i = strlen (conf_widgets [1].text) + 5;
429 if (i > l1)
430 l1 = i;
432 i = (l1 + 3) * 6 / 2;
433 if (i > confirmation.xlen)
434 confirmation.xlen = i;
436 confirmation.title = _(confirmation.title);
438 i18n_flag = confirmation.i18n = 1;
441 #endif /* ENABLE_NLS */
443 my_delete = confirm_delete;
444 my_overwrite = confirm_overwrite;
445 my_execute = confirm_execute;
446 my_exit = confirm_exit;
447 my_directory_hotlist_delete = confirm_directory_hotlist_delete;
449 if (quick_dialog (&confirmation) != B_CANCEL){
450 confirm_delete = my_delete;
451 confirm_overwrite = my_overwrite;
452 confirm_execute = my_execute;
453 confirm_exit = my_exit;
454 confirm_directory_hotlist_delete = my_directory_hotlist_delete;
458 #define DISPY 11
459 #define DISPX 46
462 #ifndef HAVE_CHARSET
464 static int new_mode;
465 static int new_meta;
467 static const char *display_bits_str [] =
468 { N_("Full 8 bits output"), N_("ISO 8859-1"), N_("7 bits") };
470 static QuickWidget display_widgets [] = {
471 { quick_button, 4, 6, 4, DISPY, N_("&Cancel"),
472 0, B_CANCEL, 0, 0, NULL },
473 { quick_button, 4, 6, 3, DISPY, N_("&OK"),
474 0, B_ENTER, 0, 0, NULL },
475 { quick_checkbox, 4, DISPX, 7, DISPY, N_("F&ull 8 bits input"),
476 0, 0, &new_meta, 0, NULL },
477 { quick_radio, 4, DISPX, 3, DISPY, "", 3, 0,
478 &new_mode, const_cast(char **, display_bits_str), NULL },
479 NULL_QuickWidget
482 static QuickDialog display_bits =
483 { DISPX, DISPY, -1, -1, N_(" Display bits "), "[Display bits]",
484 display_widgets, 0 };
486 void
487 display_bits_box (void)
489 int current_mode;
491 #ifdef ENABLE_NLS
492 static int i18n_flag = 0;
493 if (!i18n_flag)
495 register int i;
496 int l1, maxlen = 0;
497 for (i = 0; i < 3; i++)
499 display_widgets [i].text = _(display_widgets[i].text);
500 display_bits_str [i] = _(display_bits_str [i]);
501 l1 = strlen (display_bits_str [i]);
502 if (l1 > maxlen)
503 maxlen = l1;
505 l1 = strlen (display_widgets [2].text);
506 if (l1 > maxlen)
507 maxlen = l1;
510 display_bits.xlen = (maxlen + 5) * 6 / 4;
512 /* See above confirm_box */
513 l1 = strlen (display_widgets [0].text) + 3;
514 i = strlen (display_widgets [1].text) + 5;
515 if (i > l1)
516 l1 = i;
518 i = (l1 + 3) * 6 / 2;
519 if (i > display_bits.xlen)
520 display_bits.xlen = i;
522 display_bits.title = _(display_bits.title);
523 i18n_flag = display_bits.i18n = 1;
526 #endif /* ENABLE_NLS */
528 if (full_eight_bits)
529 current_mode = 0;
530 else if (eight_bit_clean)
531 current_mode = 1;
532 else
533 current_mode = 2;
535 display_widgets [3].value = current_mode;
536 new_meta = !use_8th_bit_as_meta;
537 if (quick_dialog (&display_bits) != B_ENTER)
538 return;
540 eight_bit_clean = new_mode < 2;
541 full_eight_bits = new_mode == 0;
542 #ifndef HAVE_SLANG
543 meta (stdscr, eight_bit_clean);
544 #else
545 SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
546 #endif
547 use_8th_bit_as_meta = !new_meta;
551 #else /* HAVE_CHARSET */
554 static int new_display_codepage;
556 static WLabel *cplabel;
557 static WCheck *inpcheck;
559 static int
560 sel_charset_button (int action)
562 const char *cpname;
563 char buf[64];
564 new_display_codepage = select_charset (new_display_codepage, 1);
565 cpname = (new_display_codepage < 0)
566 ? _("Other 8 bit")
567 : codepages[new_display_codepage].name;
569 /* avoid strange bug with label repainting */
570 g_snprintf (buf, sizeof (buf), "%-27s", cpname);
571 label_set_text (cplabel, buf);
572 return 0;
575 static Dlg_head *
576 init_disp_bits_box (void)
578 const char *cpname;
579 Dlg_head *dbits_dlg;
581 do_refresh ();
583 dbits_dlg =
584 create_dlg (0, 0, DISPY, DISPX, dialog_colors, NULL,
585 "[Display bits]", _(" Display bits "), DLG_CENTER | DLG_REVERSE);
587 add_widget (dbits_dlg,
588 label_new (3, 4, _("Input / display codepage:")));
590 cpname = (new_display_codepage < 0)
591 ? _("Other 8 bit")
592 : codepages[new_display_codepage].name;
593 cplabel = label_new (4, 4, cpname);
594 add_widget (dbits_dlg, cplabel);
596 add_widget (dbits_dlg,
597 button_new (DISPY - 3, DISPX / 2 + 3, B_CANCEL,
598 NORMAL_BUTTON, _("&Cancel"), 0));
599 add_widget (dbits_dlg,
600 button_new (DISPY - 3, 7, B_ENTER, NORMAL_BUTTON, _("&OK"),
601 0));
603 inpcheck =
604 check_new (6, 4, !use_8th_bit_as_meta, _("F&ull 8 bits input"));
605 add_widget (dbits_dlg, inpcheck);
607 cpname = _("&Select");
608 add_widget (dbits_dlg,
609 button_new (4, DISPX - 8 - strlen (cpname), B_USER,
610 NORMAL_BUTTON, cpname, sel_charset_button));
612 return dbits_dlg;
615 void
616 display_bits_box (void)
618 Dlg_head *dbits_dlg;
619 new_display_codepage = display_codepage;
621 application_keypad_mode ();
622 dbits_dlg = init_disp_bits_box ();
624 run_dlg (dbits_dlg);
626 if (dbits_dlg->ret_value == B_ENTER) {
627 const char *errmsg;
628 display_codepage = new_display_codepage;
629 errmsg =
630 init_translation_table (source_codepage, display_codepage);
631 if (errmsg)
632 message (1, MSG_ERROR, "%s", errmsg);
633 #ifndef HAVE_SLANG
634 meta (stdscr, display_codepage != 0);
635 #else
636 SLsmg_Display_Eight_Bit = (display_codepage != 0
637 && display_codepage != 1) ? 128 : 160;
638 #endif
639 use_8th_bit_as_meta = !(inpcheck->state & C_BOOL);
641 destroy_dlg (dbits_dlg);
642 repaint_screen ();
645 #endif /* HAVE_CHARSET */
648 #define TREE_Y 20
649 #define TREE_X 60
651 static cb_ret_t
652 tree_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
654 switch (msg) {
656 case DLG_POST_KEY:
657 /* The enter key will be processed by the tree widget */
658 if (parm == '\n') {
659 h->ret_value = B_ENTER;
660 dlg_stop (h);
662 return MSG_HANDLED;
664 default:
665 return default_dlg_callback (h, msg, parm);
669 /* Show tree in a box, not on a panel */
670 char *
671 tree_box (const char *current_dir)
673 WTree *mytree;
674 Dlg_head *dlg;
675 char *val;
676 WButtonBar *bar;
678 /* Create the components */
679 dlg = create_dlg (0, 0, TREE_Y, TREE_X, dialog_colors,
680 tree_callback, "[Directory Tree]", NULL, DLG_CENTER | DLG_REVERSE);
681 mytree = tree_new (0, 2, 2, TREE_Y - 6, TREE_X - 5);
682 add_widget (dlg, mytree);
683 bar = buttonbar_new(1);
684 add_widget (dlg, bar);
685 ((Widget *) bar)->x = 0;
686 ((Widget *) bar)->y = LINES - 1;
688 run_dlg (dlg);
689 if (dlg->ret_value == B_ENTER)
690 val = g_strdup (tree_selected_name (mytree));
691 else
692 val = 0;
694 destroy_dlg (dlg);
695 return val;
698 #ifdef USE_VFS
700 #if defined(USE_NETCODE)
701 #define VFSY 17
702 #define VFS_WIDGETBASE 10
703 #else
704 #define VFSY 8
705 #define VFS_WIDGETBASE 0
706 #endif
708 #define VFSX 56
710 static char *ret_timeout;
712 #if defined(USE_NETCODE)
713 static char *ret_passwd;
714 static char *ret_directory_timeout;
715 static char *ret_ftp_proxy;
716 static int ret_use_netrc;
717 static int ret_ftpfs_use_passive_connections;
718 static int ret_ftpfs_use_passive_connections_over_proxy;
719 #endif
721 static QuickWidget confvfs_widgets [] = {
722 { quick_button, 30, VFSX, VFSY - 3, VFSY, N_("&Cancel"),
723 0, B_CANCEL, 0, 0, NULL },
724 { quick_button, 12, VFSX, VFSY - 3, VFSY, N_("&OK"),
725 0, B_ENTER, 0, 0, NULL },
726 #if defined(USE_NETCODE)
727 { quick_checkbox, 4, VFSX, 12, VFSY, N_("Use passive mode over pro&xy"), 0, 0,
728 &ret_ftpfs_use_passive_connections_over_proxy, 0, NULL },
729 { quick_checkbox, 4, VFSX, 11, VFSY, N_("Use &passive mode"), 0, 0,
730 &ret_ftpfs_use_passive_connections, 0, NULL },
731 { quick_checkbox, 4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), 0, 0,
732 &ret_use_netrc, 0, NULL },
733 { quick_input, 4, VFSX, 9, VFSY, "", 48, 0, 0, &ret_ftp_proxy,
734 "input-ftp-proxy" },
735 { quick_checkbox, 4, VFSX, 8, VFSY, N_("&Always use ftp proxy"), 0, 0,
736 &ftpfs_always_use_proxy, 0, NULL },
737 { quick_label, 49, VFSX, 7, VFSY, N_("sec"),
738 0, 0, 0, 0, NULL },
739 { quick_input, 38, VFSX, 7, VFSY, "", 10, 0, 0, &ret_directory_timeout,
740 "input-timeout" },
741 { quick_label, 4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:"),
742 0, 0, 0, 0, NULL },
743 { quick_input, 4, VFSX, 6, VFSY, "", 48, 0, 0, &ret_passwd,
744 "input-passwd" },
745 { quick_label, 4, VFSX, 5, VFSY, N_("ftp anonymous password:"),
746 0, 0, 0, 0, NULL },
747 #endif
748 { quick_label, 49, VFSX, 3, VFSY, "sec",
749 0, 0, 0, 0, NULL },
750 { quick_input, 38, VFSX, 3, VFSY, "", 10, 0, 0, &ret_timeout,
751 "input-timo-vfs" },
752 { quick_label, 4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:"),
753 0, 0, 0, 0, NULL },
754 NULL_QuickWidget
757 static QuickDialog confvfs_dlg =
758 { VFSX, VFSY, -1, -1, N_(" Virtual File System Setting "),
759 "[Virtual FS]", confvfs_widgets, 0 };
761 void
762 configure_vfs (void)
764 char buffer2[BUF_TINY];
765 #if defined(USE_NETCODE)
766 char buffer3[BUF_TINY];
768 ret_use_netrc = use_netrc;
769 ret_ftpfs_use_passive_connections = ftpfs_use_passive_connections;
770 ret_ftpfs_use_passive_connections_over_proxy = ftpfs_use_passive_connections_over_proxy;
771 g_snprintf(buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
772 confvfs_widgets[8].text = buffer3;
773 confvfs_widgets[10].text = ftpfs_anonymous_passwd;
774 confvfs_widgets[5].text = ftpfs_proxy_host;
775 #endif
776 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
777 confvfs_widgets [3 + VFS_WIDGETBASE].text = buffer2;
779 if (quick_dialog (&confvfs_dlg) != B_CANCEL) {
780 vfs_timeout = atoi (ret_timeout);
781 g_free (ret_timeout);
782 if (vfs_timeout < 0 || vfs_timeout > 10000)
783 vfs_timeout = 10;
784 #if defined(USE_NETCODE)
785 g_free (ftpfs_anonymous_passwd);
786 ftpfs_anonymous_passwd = ret_passwd;
787 g_free (ftpfs_proxy_host);
788 ftpfs_proxy_host = ret_ftp_proxy;
789 ftpfs_directory_timeout = atoi(ret_directory_timeout);
790 use_netrc = ret_use_netrc;
791 ftpfs_use_passive_connections = ret_ftpfs_use_passive_connections;
792 ftpfs_use_passive_connections_over_proxy = ret_ftpfs_use_passive_connections_over_proxy;
793 g_free (ret_directory_timeout);
794 #endif
798 #endif /* USE_VFS */
800 char *
801 cd_dialog (void)
803 QuickDialog Quick_input;
804 QuickWidget quick_widgets [] = {
805 { quick_input, 6, 57, 2, 0, "", 50, 0, 0, 0, "input" },
806 { quick_label, 3, 57, 2, 0, "", 0, 0, 0, 0, NULL },
807 NULL_QuickWidget
809 char *my_str;
810 int len;
812 Quick_input.xlen = 57;
813 Quick_input.title = _("Quick cd");
814 Quick_input.help = "[Quick cd]";
815 quick_widgets [0].value = 2; /* want cd like completion */
816 quick_widgets [1].text = _("cd");
817 quick_widgets [1].y_divisions =
818 quick_widgets [0].y_divisions = Quick_input.ylen = 5;
820 len = strlen (quick_widgets [1].text);
822 quick_widgets [0].relative_x =
823 quick_widgets [1].relative_x + len + 1;
825 Quick_input.xlen = len + quick_widgets [0].hotkey_pos + 7;
826 quick_widgets [0].x_divisions =
827 quick_widgets [1].x_divisions = Quick_input.xlen;
829 Quick_input.i18n = 1;
830 Quick_input.xpos = 2;
831 Quick_input.ypos = LINES - 2 - Quick_input.ylen;
832 quick_widgets [0].str_result = &my_str;
834 Quick_input.widgets = quick_widgets;
835 if (quick_dialog (&Quick_input) != B_CANCEL){
836 return my_str;
837 } else
838 return 0;
841 void
842 symlink_dialog (const char *existing, const char *new, char **ret_existing,
843 char **ret_new)
845 QuickDialog Quick_input;
846 QuickWidget quick_widgets[] = {
847 {quick_button, 50, 80, 6, 8, N_("&Cancel"), 0, B_CANCEL, 0, 0,
848 NULL},
849 {quick_button, 16, 80, 6, 8, N_("&OK"), 0, B_ENTER, 0, 0, NULL},
850 {quick_input, 4, 80, 5, 8, "", 58, 0, 0, 0, "input-1"},
851 {quick_label, 4, 80, 4, 8, N_("Symbolic link filename:"), 0, 0, 0,
852 0, NULL},
853 {quick_input, 4, 80, 3, 8, "", 58, 0, 0, 0, "input-2"},
854 {quick_label, 4, 80, 2, 8,
855 N_("Existing filename (filename symlink will point to):"), 0, 0,
856 0, 0, NULL},
857 NULL_QuickWidget
860 Quick_input.xlen = 64;
861 Quick_input.ylen = 12;
862 Quick_input.title = N_("Symbolic link");
863 Quick_input.help = "[File Menu]";
864 Quick_input.i18n = 0;
865 quick_widgets[2].text = new;
866 quick_widgets[4].text = existing;
867 Quick_input.xpos = -1;
868 quick_widgets[2].str_result = ret_new;
869 quick_widgets[4].str_result = ret_existing;
871 Quick_input.widgets = quick_widgets;
872 if (quick_dialog (&Quick_input) == B_CANCEL) {
873 *ret_new = NULL;
874 *ret_existing = NULL;
878 #ifdef WITH_BACKGROUND
879 #define B_STOP (B_USER+1)
880 #define B_RESUME (B_USER+2)
881 #define B_KILL (B_USER+3)
883 static int JOBS_X = 60;
884 #define JOBS_Y 15
885 static WListbox *bg_list;
886 static Dlg_head *jobs_dlg;
888 static void
889 jobs_fill_listbox (void)
891 static const char *state_str [2];
892 TaskList *tl = task_list;
894 if (!state_str [0]){
895 state_str [0] = _("Running ");
896 state_str [1] = _("Stopped");
899 while (tl){
900 char *s;
902 s = g_strconcat (state_str [tl->state], " ", tl->info, (char *) NULL);
903 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
904 g_free (s);
905 tl = tl->next;
909 static int
910 task_cb (int action)
912 TaskList *tl;
913 int sig = 0;
915 if (!bg_list->list)
916 return 0;
918 /* Get this instance information */
919 tl = (TaskList *) bg_list->current->data;
921 # ifdef SIGTSTP
922 if (action == B_STOP){
923 sig = SIGSTOP;
924 tl->state = Task_Stopped;
925 } else if (action == B_RESUME){
926 sig = SIGCONT;
927 tl->state = Task_Running;
928 } else
929 # endif
930 if (action == B_KILL){
931 sig = SIGKILL;
934 if (sig == SIGINT)
935 unregister_task_running (tl->pid, tl->fd);
937 kill (tl->pid, sig);
938 listbox_remove_list (bg_list);
939 jobs_fill_listbox ();
941 /* This can be optimized to just redraw this widget :-) */
942 dlg_redraw (jobs_dlg);
944 return 0;
947 static struct
949 const char* name;
950 int xpos;
951 int value;
952 int (*callback)(int);
954 job_buttons [] =
956 {N_("&Stop"), 3, B_STOP, task_cb},
957 {N_("&Resume"), 12, B_RESUME, task_cb},
958 {N_("&Kill"), 23, B_KILL, task_cb},
959 {N_("&OK"), 35, B_CANCEL, NULL }
962 void
963 jobs_cmd (void)
965 register int i;
966 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
968 #ifdef ENABLE_NLS
969 static int i18n_flag = 0;
970 if (!i18n_flag)
972 int startx = job_buttons [0].xpos;
973 int len;
975 for (i = 0; i < n_buttons; i++)
977 job_buttons [i].name = _(job_buttons [i].name);
979 len = strlen (job_buttons [i].name) + 4;
980 JOBS_X = max (JOBS_X, startx + len + 3);
982 job_buttons [i].xpos = startx;
983 startx += len;
986 /* Last button - Ok a.k.a. Cancel :) */
987 job_buttons [n_buttons - 1].xpos =
988 JOBS_X - strlen (job_buttons [n_buttons - 1].name) - 7;
990 i18n_flag = 1;
992 #endif /* ENABLE_NLS */
994 jobs_dlg = create_dlg (0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL,
995 "[Background jobs]", _("Background Jobs"),
996 DLG_CENTER | DLG_REVERSE);
998 bg_list = listbox_new (2, 3, JOBS_X-7, JOBS_Y-9, 0);
999 add_widget (jobs_dlg, bg_list);
1001 i = n_buttons;
1002 while (i--)
1004 add_widget (jobs_dlg, button_new (JOBS_Y-4,
1005 job_buttons [i].xpos, job_buttons [i].value,
1006 NORMAL_BUTTON, job_buttons [i].name,
1007 job_buttons [i].callback));
1010 /* Insert all of task information in the list */
1011 jobs_fill_listbox ();
1012 run_dlg (jobs_dlg);
1014 destroy_dlg (jobs_dlg);
1016 #endif /* WITH_BACKGROUND */
1018 #ifdef WITH_SMBFS
1019 struct smb_authinfo *
1020 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
1021 const char *user)
1023 static int dialog_x = 44;
1024 enum { b0 = 3, dialog_y = 12};
1025 struct smb_authinfo *return_value;
1026 static const char* labs[] = {N_("Domain:"), N_("Username:"), N_("Password:")};
1027 static const char* buts[] = {N_("&OK"), N_("&Cancel")};
1028 static int ilen = 30, istart = 14;
1029 static int b2 = 30;
1030 char *title;
1031 WInput *in_password;
1032 WInput *in_user;
1033 WInput *in_domain;
1034 Dlg_head *auth_dlg;
1036 #ifdef ENABLE_NLS
1037 static int i18n_flag = 0;
1039 if (!i18n_flag)
1041 register int i = sizeof(labs)/sizeof(labs[0]);
1042 int l1, maxlen = 0;
1044 while (i--)
1046 l1 = strlen (labs [i] = _(labs [i]));
1047 if (l1 > maxlen)
1048 maxlen = l1;
1050 i = maxlen + ilen + 7;
1051 if (i > dialog_x)
1052 dialog_x = i;
1054 for (i = sizeof(buts)/sizeof(buts[0]), l1 = 0; i--; )
1056 l1 += strlen (buts [i] = _(buts [i]));
1058 l1 += 15;
1059 if (l1 > dialog_x)
1060 dialog_x = l1;
1062 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1063 istart = dialog_x - 3 - ilen;
1065 b2 = dialog_x - (strlen(buts[1]) + 6);
1067 i18n_flag = 1;
1070 #endif /* ENABLE_NLS */
1072 if (!domain)
1073 domain = "";
1074 if (!user)
1075 user = "";
1077 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1079 auth_dlg = create_dlg (0, 0, dialog_y, dialog_x, dialog_colors, NULL,
1080 "[Smb Authinfo]", title, DLG_CENTER | DLG_REVERSE);
1082 g_free (title);
1084 in_user = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name");
1085 add_widget (auth_dlg, in_user);
1087 in_domain = input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain");
1088 add_widget (auth_dlg, in_domain);
1089 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON,
1090 buts[1], 0));
1091 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON,
1092 buts[0], 0));
1094 in_password = input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password");
1095 in_password->completion_flags = 0;
1096 in_password->is_password = 1;
1097 add_widget (auth_dlg, in_password);
1099 add_widget (auth_dlg, label_new (7, 3, labs[2]));
1100 add_widget (auth_dlg, label_new (5, 3, labs[1]));
1101 add_widget (auth_dlg, label_new (3, 3, labs[0]));
1103 run_dlg (auth_dlg);
1105 switch (auth_dlg->ret_value) {
1106 case B_CANCEL:
1107 return_value = 0;
1108 break;
1109 default:
1110 return_value = g_new (struct smb_authinfo, 1);
1111 if (return_value) {
1112 return_value->host = g_strdup (host);
1113 return_value->share = g_strdup (share);
1114 return_value->domain = g_strdup (in_domain->buffer);
1115 return_value->user = g_strdup (in_user->buffer);
1116 return_value->password = g_strdup (in_password->buffer);
1120 destroy_dlg (auth_dlg);
1122 return return_value;
1124 #endif /* WITH_SMBFS */