Removed type SHELL_ESCAPED_STR in favour of plain char*
[midnight-commander.git] / src / boxes.c
bloba950f3d701ac33ebc65703cf853c46c0eb22622c
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 <mhl/memory.h>
34 #include <mhl/string.h>
36 #include "global.h"
37 #include "tty.h"
38 #include "win.h" /* Our window tools */
39 #include "color.h" /* Color definitions */
40 #include "dialog.h" /* The nice dialog manager */
41 #include "widget.h" /* The widgets for the nice dialog manager */
42 #include "wtools.h"
43 #include "setup.h" /* For profile_name */
44 #include "profile.h" /* Load/save user formats */
45 #include "key.h" /* XCTRL and ALT macros */
46 #include "command.h" /* For cmdline */
47 #include "dir.h"
48 #include "panel.h"
49 #include "boxes.h"
50 #include "main.h" /* For the confirm_* variables */
51 #include "tree.h"
52 #include "layout.h" /* for get_nth_panel_name proto */
53 #include "background.h" /* task_list */
55 #ifdef HAVE_CHARSET
56 #include "charsets.h"
57 #include "selcodepage.h"
58 #endif
60 #ifdef USE_NETCODE
61 # include "../vfs/ftpfs.h"
62 #endif
64 #ifdef USE_VFS
65 #include "../vfs/gc.h"
66 #endif
68 static int DISPLAY_X = 45, DISPLAY_Y = 14;
70 static Dlg_head *dd;
71 static WRadio *my_radio;
72 static WInput *user;
73 static WInput *status;
74 static WCheck *check_status;
75 static int current_mode;
77 static char **displays_status;
79 /* Controls whether the array strings have been translated */
80 static const char *displays [LIST_TYPES] = {
81 N_("&Full file list"),
82 N_("&Brief file list"),
83 N_("&Long file list"),
84 N_("&User defined:")
87 /* Index in displays[] for "user defined" */
88 #define USER_TYPE 3
90 static int user_hotkey = 'u';
92 static cb_ret_t
93 display_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
95 switch (msg) {
96 case DLG_UNFOCUS:
97 if (dlg_widget_active (my_radio)) {
98 assign_text (status, displays_status[my_radio->sel]);
99 input_set_point (status, 0);
101 return MSG_HANDLED;
103 case DLG_KEY:
104 if (parm == '\n') {
105 if (dlg_widget_active (my_radio)) {
106 assign_text (status, displays_status[my_radio->sel]);
107 dlg_stop (h);
108 return MSG_HANDLED;
111 if (dlg_widget_active (user)) {
112 h->ret_value = B_USER + 6;
113 dlg_stop (h);
114 return MSG_HANDLED;
117 if (dlg_widget_active (status)) {
118 h->ret_value = B_USER + 7;
119 dlg_stop (h);
120 return MSG_HANDLED;
124 if (tolower (parm) == user_hotkey && dlg_widget_active (user)
125 && dlg_widget_active (status)) {
126 my_radio->sel = 3;
127 dlg_select_widget (my_radio); /* force redraw */
128 dlg_select_widget (user);
129 return MSG_HANDLED;
131 return MSG_NOT_HANDLED;
133 default:
134 return default_dlg_callback (h, msg, parm);
138 static void
139 display_init (int radio_sel, char *init_text, int _check_status,
140 char **_status)
142 static const char *display_title = N_("Listing mode");
143 static int i18n_displays_flag;
144 const char *user_mini_status = _("user &Mini status");
145 const char *ok_button = _("&OK");
146 const char *cancel_button = _("&Cancel");
148 static int button_start = 30;
150 displays_status = _status;
152 if (!i18n_displays_flag) {
153 int i, l, maxlen = 0;
154 const char *cp;
156 display_title = _(display_title);
157 for (i = 0; i < LIST_TYPES; i++) {
158 displays[i] = _(displays[i]);
159 if ((l = strlen (displays[i])) > maxlen)
160 maxlen = l;
163 i = strlen (ok_button) + 5;
164 l = strlen (cancel_button) + 3;
165 l = max (i, l);
167 i = maxlen + l + 16;
168 if (i > DISPLAY_X)
169 DISPLAY_X = i;
171 i = strlen (user_mini_status) + 13;
172 if (i > DISPLAY_X)
173 DISPLAY_X = i;
175 i = strlen (display_title) + 10;
176 if (i > DISPLAY_X)
177 DISPLAY_X = i;
179 button_start = DISPLAY_X - l - 5;
181 /* get hotkey of user-defined format string */
182 cp = strchr (displays[USER_TYPE], '&');
183 if (cp != NULL && *++cp != '\0')
184 user_hotkey = tolower ((unsigned char) *cp);
186 i18n_displays_flag = 1;
188 dd = create_dlg (0, 0, DISPLAY_Y, DISPLAY_X, dialog_colors,
189 display_callback, "[Listing Mode...]", display_title,
190 DLG_CENTER | DLG_REVERSE);
192 add_widget (dd,
193 button_new (4, button_start, B_CANCEL, NORMAL_BUTTON,
194 cancel_button, 0));
196 add_widget (dd,
197 button_new (3, button_start, B_ENTER, DEFPUSH_BUTTON,
198 ok_button, 0));
200 status =
201 input_new (10, 9, INPUT_COLOR, DISPLAY_X - 14, _status[radio_sel],
202 "mini-input", INPUT_COMPLETE_DEFAULT);
203 add_widget (dd, status);
204 input_set_point (status, 0);
206 check_status =
207 check_new (9, 5, _check_status, user_mini_status);
208 add_widget (dd, check_status);
210 user =
211 input_new (7, 9, INPUT_COLOR, DISPLAY_X - 14, init_text,
212 "user-fmt-input", INPUT_COMPLETE_DEFAULT);
213 add_widget (dd, user);
214 input_set_point (user, 0);
216 my_radio = radio_new (3, 5, LIST_TYPES, displays);
217 my_radio->sel = my_radio->pos = current_mode;
218 add_widget (dd, my_radio);
222 display_box (WPanel *panel, char **userp, char **minip, int *use_msformat, int num)
224 int result, i;
225 char *section = NULL;
226 const char *p;
228 if (!panel) {
229 p = get_nth_panel_name (num);
230 panel = g_new (WPanel, 1);
231 panel->list_type = list_full;
232 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
233 panel->user_mini_status = 0;
234 for (i = 0; i < LIST_TYPES; i++)
235 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
236 section = g_strconcat ("Temporal:", p, (char *) NULL);
237 if (!profile_has_section (section, profile_name)) {
238 g_free (section);
239 section = g_strdup (p);
241 panel_load_setup (panel, section);
242 g_free (section);
245 current_mode = panel->list_type;
246 display_init (current_mode, panel->user_format,
247 panel->user_mini_status, panel->user_status_format);
249 run_dlg (dd);
251 result = -1;
253 if (section) {
254 g_free (panel->user_format);
255 for (i = 0; i < LIST_TYPES; i++)
256 g_free (panel->user_status_format [i]);
257 g_free (panel);
260 if (dd->ret_value != B_CANCEL){
261 result = my_radio->sel;
262 *userp = g_strdup (user->buffer);
263 *minip = g_strdup (status->buffer);
264 *use_msformat = check_status->state & C_BOOL;
266 destroy_dlg (dd);
268 return result;
271 static int SORT_X = 60, SORT_Y = 14;
273 static const char *sort_orders_names [SORT_TYPES];
275 sortfn *
276 sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive, int *exec_first)
278 int i, r, l;
279 sortfn *result;
280 WCheck *c, *case_sense, *exec_ff;
282 const char *ok_button = _("&OK");
283 const char *cancel_button = _("&Cancel");
284 const char *reverse_label = _("&Reverse");
285 const char *case_label = _("case sensi&tive");
286 const char *sort_title = _("Sort order");
287 const char *exec_label = _("Executable first");
289 static int i18n_sort_flag = 0, check_pos = 0, button_pos = 0;
291 if (!i18n_sort_flag) {
292 int maxlen = 0;
293 for (i = SORT_TYPES - 1; i >= 0; i--) {
294 sort_orders_names[i] = _(sort_orders[i].sort_name);
295 r = strlen (sort_orders_names[i]);
296 if (r > maxlen)
297 maxlen = r;
300 check_pos = maxlen + 9;
302 r = strlen (reverse_label) + 4;
303 i = strlen (case_label) + 4;
304 if (i > r)
305 r = i;
307 l = strlen (ok_button) + 6;
308 i = strlen (cancel_button) + 4;
309 if (i > l)
310 l = i;
312 i = check_pos + max (r, l) + 2;
314 if (i > SORT_X)
315 SORT_X = i;
317 i = strlen (sort_title) + 6;
318 if (i > SORT_X)
319 SORT_X = i;
321 button_pos = SORT_X - l - 2;
323 i18n_sort_flag = 1;
326 result = 0;
328 for (i = 0; i < SORT_TYPES; i++)
329 if ((sortfn *) (sort_orders[i].sort_fn) == sort_fn) {
330 current_mode = i;
331 break;
334 dd = create_dlg (0, 0, SORT_Y, SORT_X, dialog_colors, NULL,
335 "[Sort Order...]", sort_title, DLG_CENTER | DLG_REVERSE);
337 add_widget (dd,
338 button_new (10, button_pos, B_CANCEL, NORMAL_BUTTON,
339 cancel_button, 0));
341 add_widget (dd,
342 button_new (9, button_pos, B_ENTER, DEFPUSH_BUTTON,
343 ok_button, 0));
345 exec_ff = check_new (5, check_pos, *exec_first, exec_label);
346 add_widget (dd, exec_ff);
347 case_sense = check_new (4, check_pos, *case_sensitive, case_label);
348 add_widget (dd, case_sense);
349 c = check_new (3, check_pos, *reverse, reverse_label);
350 add_widget (dd, c);
352 my_radio = radio_new (3, 3, SORT_TYPES, sort_orders_names);
353 my_radio->sel = my_radio->pos = current_mode;
355 add_widget (dd, my_radio);
356 run_dlg (dd);
358 r = dd->ret_value;
359 if (r != B_CANCEL) {
360 result = (sortfn *) sort_orders[my_radio->sel].sort_fn;
361 *reverse = c->state & C_BOOL;
362 *case_sensitive = case_sense->state & C_BOOL;
363 *exec_first = exec_ff->state & C_BOOL;
364 } else
365 result = sort_fn;
366 destroy_dlg (dd);
368 return result;
371 #define CONFY 11
372 #define CONFX 46
374 static int my_delete;
375 static int my_directory_hotlist_delete;
376 static int my_overwrite;
377 static int my_execute;
378 static int my_exit;
380 static QuickWidget conf_widgets [] = {
381 { quick_button, 4, 6, 4, CONFY, N_("&Cancel"),
382 0, B_CANCEL, 0, 0, NULL },
383 { quick_button, 4, 6, 3, CONFY, N_("&OK"),
384 0, B_ENTER, 0, 0, NULL },
386 { quick_checkbox, 1, 13, 7, CONFY, N_(" confirm di&Rectory hotlist delete "),
387 11, 0, &my_directory_hotlist_delete, NULL, NULL },
388 { quick_checkbox, 1, 13, 6, CONFY, N_(" confirm &Exit "),
389 9, 0, &my_exit, 0, NULL },
390 { quick_checkbox, 1, 13, 5, CONFY, N_(" confirm e&Xecute "),
391 10, 0, &my_execute, 0, NULL },
392 { quick_checkbox, 1, 13, 4, CONFY, N_(" confirm o&Verwrite "),
393 10, 0, &my_overwrite, 0, NULL },
394 { quick_checkbox, 1, 13, 3, CONFY, N_(" confirm &Delete "),
395 9, 0, &my_delete, 0, NULL },
396 NULL_QuickWidget
399 static QuickDialog confirmation =
400 { CONFX, CONFY, -1, -1, N_(" Confirmation "), "[Confirmation]",
401 conf_widgets, 0
404 void
405 confirm_box (void)
408 #ifdef ENABLE_NLS
409 static int i18n_flag = 0;
411 if (!i18n_flag)
413 register int i = sizeof(conf_widgets)/sizeof(QuickWidget) - 1;
414 int l1, maxlen = 0;
415 while (i--)
417 conf_widgets [i].text = _(conf_widgets [i].text);
418 l1 = strlen (conf_widgets [i].text) + 3;
419 if (l1 > maxlen)
420 maxlen = l1;
424 * If buttons start on 4/6, checkboxes (with some add'l space)
425 * must take not more than it.
427 confirmation.xlen = (maxlen + 5) * 6 / 4;
430 * And this for the case when buttons with some space to the right
431 * do not fit within 2/6
433 l1 = strlen (conf_widgets [0].text) + 3;
434 i = strlen (conf_widgets [1].text) + 5;
435 if (i > l1)
436 l1 = i;
438 i = (l1 + 3) * 6 / 2;
439 if (i > confirmation.xlen)
440 confirmation.xlen = i;
442 confirmation.title = _(confirmation.title);
444 i18n_flag = confirmation.i18n = 1;
447 #endif /* ENABLE_NLS */
449 my_delete = confirm_delete;
450 my_overwrite = confirm_overwrite;
451 my_execute = confirm_execute;
452 my_exit = confirm_exit;
453 my_directory_hotlist_delete = confirm_directory_hotlist_delete;
455 if (quick_dialog (&confirmation) != B_CANCEL){
456 confirm_delete = my_delete;
457 confirm_overwrite = my_overwrite;
458 confirm_execute = my_execute;
459 confirm_exit = my_exit;
460 confirm_directory_hotlist_delete = my_directory_hotlist_delete;
464 #define DISPY 11
465 #define DISPX 46
468 #ifndef HAVE_CHARSET
470 static int new_mode;
471 static int new_meta;
473 static const char *display_bits_str [] =
474 { N_("Full 8 bits output"), N_("ISO 8859-1"), N_("7 bits") };
476 static QuickWidget display_widgets [] = {
477 { quick_button, 4, 6, 4, DISPY, N_("&Cancel"),
478 0, B_CANCEL, 0, 0, NULL },
479 { quick_button, 4, 6, 3, DISPY, N_("&OK"),
480 0, B_ENTER, 0, 0, NULL },
481 { quick_checkbox, 4, DISPX, 7, DISPY, N_("F&ull 8 bits input"),
482 0, 0, &new_meta, 0, NULL },
483 { quick_radio, 4, DISPX, 3, DISPY, "", 3, 0,
484 &new_mode, const_cast(char **, display_bits_str), NULL },
485 NULL_QuickWidget
488 static QuickDialog display_bits =
489 { DISPX, DISPY, -1, -1, N_(" Display bits "), "[Display bits]",
490 display_widgets, 0 };
492 void
493 display_bits_box (void)
495 int current_mode;
497 #ifdef ENABLE_NLS
498 static int i18n_flag = 0;
499 if (!i18n_flag)
501 register int i;
502 int l1, maxlen = 0;
503 for (i = 0; i < 3; i++)
505 display_widgets [i].text = _(display_widgets[i].text);
506 display_bits_str [i] = _(display_bits_str [i]);
507 l1 = strlen (display_bits_str [i]);
508 if (l1 > maxlen)
509 maxlen = l1;
511 l1 = strlen (display_widgets [2].text);
512 if (l1 > maxlen)
513 maxlen = l1;
516 display_bits.xlen = (maxlen + 5) * 6 / 4;
518 /* See above confirm_box */
519 l1 = strlen (display_widgets [0].text) + 3;
520 i = strlen (display_widgets [1].text) + 5;
521 if (i > l1)
522 l1 = i;
524 i = (l1 + 3) * 6 / 2;
525 if (i > display_bits.xlen)
526 display_bits.xlen = i;
528 display_bits.title = _(display_bits.title);
529 i18n_flag = display_bits.i18n = 1;
532 #endif /* ENABLE_NLS */
534 if (full_eight_bits)
535 current_mode = 0;
536 else if (eight_bit_clean)
537 current_mode = 1;
538 else
539 current_mode = 2;
541 display_widgets [3].value = current_mode;
542 new_meta = !use_8th_bit_as_meta;
543 if (quick_dialog (&display_bits) != B_ENTER)
544 return;
546 eight_bit_clean = new_mode < 2;
547 full_eight_bits = new_mode == 0;
548 #ifndef HAVE_SLANG
549 meta (stdscr, eight_bit_clean);
550 #else
551 SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
552 #endif
553 use_8th_bit_as_meta = !new_meta;
557 #else /* HAVE_CHARSET */
560 static int new_display_codepage;
562 static WLabel *cplabel;
563 static WCheck *inpcheck;
565 static int
566 sel_charset_button (int action)
568 const char *cpname;
569 char buf[64];
570 new_display_codepage = select_charset (new_display_codepage, 1);
571 cpname = (new_display_codepage < 0)
572 ? _("Other 8 bit")
573 : codepages[new_display_codepage].name;
575 /* avoid strange bug with label repainting */
576 g_snprintf (buf, sizeof (buf), "%-27s", cpname);
577 label_set_text (cplabel, buf);
578 return 0;
581 static Dlg_head *
582 init_disp_bits_box (void)
584 const char *cpname;
585 Dlg_head *dbits_dlg;
587 do_refresh ();
589 dbits_dlg =
590 create_dlg (0, 0, DISPY, DISPX, dialog_colors, NULL,
591 "[Display bits]", _(" Display bits "), DLG_CENTER | DLG_REVERSE);
593 add_widget (dbits_dlg,
594 label_new (3, 4, _("Input / display codepage:")));
596 cpname = (new_display_codepage < 0)
597 ? _("Other 8 bit")
598 : codepages[new_display_codepage].name;
599 cplabel = label_new (4, 4, cpname);
600 add_widget (dbits_dlg, cplabel);
602 add_widget (dbits_dlg,
603 button_new (DISPY - 3, DISPX / 2 + 3, B_CANCEL,
604 NORMAL_BUTTON, _("&Cancel"), 0));
605 add_widget (dbits_dlg,
606 button_new (DISPY - 3, 7, B_ENTER, NORMAL_BUTTON, _("&OK"),
607 0));
609 inpcheck =
610 check_new (6, 4, !use_8th_bit_as_meta, _("F&ull 8 bits input"));
611 add_widget (dbits_dlg, inpcheck);
613 cpname = _("&Select");
614 add_widget (dbits_dlg,
615 button_new (4, DISPX - 8 - strlen (cpname), B_USER,
616 NORMAL_BUTTON, cpname, sel_charset_button));
618 return dbits_dlg;
621 void
622 display_bits_box (void)
624 Dlg_head *dbits_dlg;
625 new_display_codepage = display_codepage;
627 application_keypad_mode ();
628 dbits_dlg = init_disp_bits_box ();
630 run_dlg (dbits_dlg);
632 if (dbits_dlg->ret_value == B_ENTER) {
633 const char *errmsg;
634 display_codepage = new_display_codepage;
635 errmsg =
636 init_translation_table (source_codepage, display_codepage);
637 if (errmsg)
638 message (D_ERROR, MSG_ERROR, "%s", errmsg);
639 #ifndef HAVE_SLANG
640 meta (stdscr, display_codepage != 0);
641 #else
642 SLsmg_Display_Eight_Bit = (display_codepage != 0
643 && display_codepage != 1) ? 128 : 160;
644 #endif
645 use_8th_bit_as_meta = !(inpcheck->state & C_BOOL);
647 destroy_dlg (dbits_dlg);
648 repaint_screen ();
651 #endif /* HAVE_CHARSET */
654 #define TREE_Y 20
655 #define TREE_X 60
657 static cb_ret_t
658 tree_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
660 switch (msg) {
662 case DLG_POST_KEY:
663 /* The enter key will be processed by the tree widget */
664 if (parm == '\n') {
665 h->ret_value = B_ENTER;
666 dlg_stop (h);
668 return MSG_HANDLED;
670 default:
671 return default_dlg_callback (h, msg, parm);
675 /* Show tree in a box, not on a panel */
676 char *
677 tree_box (const char *current_dir)
679 WTree *mytree;
680 Dlg_head *dlg;
681 char *val;
682 WButtonBar *bar;
684 /* Create the components */
685 dlg = create_dlg (0, 0, TREE_Y, TREE_X, dialog_colors,
686 tree_callback, "[Directory Tree]", NULL, DLG_CENTER | DLG_REVERSE);
687 mytree = tree_new (0, 2, 2, TREE_Y - 6, TREE_X - 5);
688 add_widget (dlg, mytree);
689 bar = buttonbar_new(1);
690 add_widget (dlg, bar);
691 ((Widget *) bar)->x = 0;
692 ((Widget *) bar)->y = LINES - 1;
694 run_dlg (dlg);
695 if (dlg->ret_value == B_ENTER)
696 val = g_strdup (tree_selected_name (mytree));
697 else
698 val = 0;
700 destroy_dlg (dlg);
701 return val;
704 #ifdef USE_VFS
706 #if defined(USE_NETCODE)
707 #define VFSY 17
708 #define VFS_WIDGETBASE 10
709 #else
710 #define VFSY 8
711 #define VFS_WIDGETBASE 0
712 #endif
714 #define VFSX 56
716 static char *ret_timeout;
718 #if defined(USE_NETCODE)
719 static char *ret_passwd;
720 static char *ret_directory_timeout;
721 static char *ret_ftp_proxy;
722 static int ret_use_netrc;
723 static int ret_ftpfs_use_passive_connections;
724 static int ret_ftpfs_use_passive_connections_over_proxy;
725 #endif
727 static QuickWidget confvfs_widgets [] = {
728 { quick_button, 30, VFSX, VFSY - 3, VFSY, N_("&Cancel"),
729 0, B_CANCEL, 0, 0, NULL },
730 { quick_button, 12, VFSX, VFSY - 3, VFSY, N_("&OK"),
731 0, B_ENTER, 0, 0, NULL },
732 #if defined(USE_NETCODE)
733 { quick_checkbox, 4, VFSX, 12, VFSY, N_("Use passive mode over pro&xy"), 0, 0,
734 &ret_ftpfs_use_passive_connections_over_proxy, 0, NULL },
735 { quick_checkbox, 4, VFSX, 11, VFSY, N_("Use &passive mode"), 0, 0,
736 &ret_ftpfs_use_passive_connections, 0, NULL },
737 { quick_checkbox, 4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), 0, 0,
738 &ret_use_netrc, 0, NULL },
739 { quick_input, 4, VFSX, 9, VFSY, "", 48, 0, 0, &ret_ftp_proxy,
740 "input-ftp-proxy" },
741 { quick_checkbox, 4, VFSX, 8, VFSY, N_("&Always use ftp proxy"), 0, 0,
742 &ftpfs_always_use_proxy, 0, NULL },
743 { quick_label, 49, VFSX, 7, VFSY, N_("sec"),
744 0, 0, 0, 0, NULL },
745 { quick_input, 38, VFSX, 7, VFSY, "", 10, 0, 0, &ret_directory_timeout,
746 "input-timeout" },
747 { quick_label, 4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:"),
748 0, 0, 0, 0, NULL },
749 { quick_input, 4, VFSX, 6, VFSY, "", 48, 0, 0, &ret_passwd,
750 "input-passwd" },
751 { quick_label, 4, VFSX, 5, VFSY, N_("ftp anonymous password:"),
752 0, 0, 0, 0, NULL },
753 #endif
754 { quick_label, 49, VFSX, 3, VFSY, "sec",
755 0, 0, 0, 0, NULL },
756 { quick_input, 38, VFSX, 3, VFSY, "", 10, 0, 0, &ret_timeout,
757 "input-timo-vfs" },
758 { quick_label, 4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:"),
759 0, 0, 0, 0, NULL },
760 NULL_QuickWidget
763 static QuickDialog confvfs_dlg =
764 { VFSX, VFSY, -1, -1, N_(" Virtual File System Setting "),
765 "[Virtual FS]", confvfs_widgets, 0 };
767 void
768 configure_vfs (void)
770 char buffer2[BUF_TINY];
771 #if defined(USE_NETCODE)
772 char buffer3[BUF_TINY];
774 ret_use_netrc = use_netrc;
775 ret_ftpfs_use_passive_connections = ftpfs_use_passive_connections;
776 ret_ftpfs_use_passive_connections_over_proxy = ftpfs_use_passive_connections_over_proxy;
777 g_snprintf(buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
778 confvfs_widgets[8].text = buffer3;
779 confvfs_widgets[10].text = ftpfs_anonymous_passwd;
780 confvfs_widgets[5].text = ftpfs_proxy_host;
781 #endif
782 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
783 confvfs_widgets [3 + VFS_WIDGETBASE].text = buffer2;
785 if (quick_dialog (&confvfs_dlg) != B_CANCEL) {
786 vfs_timeout = atoi (ret_timeout);
787 g_free (ret_timeout);
788 if (vfs_timeout < 0 || vfs_timeout > 10000)
789 vfs_timeout = 10;
790 #if defined(USE_NETCODE)
791 g_free (ftpfs_anonymous_passwd);
792 ftpfs_anonymous_passwd = ret_passwd;
793 g_free (ftpfs_proxy_host);
794 ftpfs_proxy_host = ret_ftp_proxy;
795 ftpfs_directory_timeout = atoi(ret_directory_timeout);
796 use_netrc = ret_use_netrc;
797 ftpfs_use_passive_connections = ret_ftpfs_use_passive_connections;
798 ftpfs_use_passive_connections_over_proxy = ret_ftpfs_use_passive_connections_over_proxy;
799 g_free (ret_directory_timeout);
800 #endif
804 #endif /* USE_VFS */
806 char *
807 cd_dialog (void)
809 QuickDialog Quick_input;
810 QuickWidget quick_widgets [] = {
811 { quick_input, 6, 57, 2, 0, "", 50, 0, 0, 0, "input" },
812 { quick_label, 3, 57, 2, 0, "", 0, 0, 0, 0, NULL },
813 NULL_QuickWidget
815 char *my_str;
816 int len;
818 Quick_input.xlen = 57;
819 Quick_input.title = _("Quick cd");
820 Quick_input.help = "[Quick cd]";
821 quick_widgets [0].value = 2; /* want cd like completion */
822 quick_widgets [1].text = _("cd");
823 quick_widgets [1].y_divisions =
824 quick_widgets [0].y_divisions = Quick_input.ylen = 5;
826 len = strlen (quick_widgets [1].text);
828 quick_widgets [0].relative_x =
829 quick_widgets [1].relative_x + len + 1;
831 Quick_input.xlen = len + quick_widgets [0].hotkey_pos + 7;
832 quick_widgets [0].x_divisions =
833 quick_widgets [1].x_divisions = Quick_input.xlen;
835 Quick_input.i18n = 1;
836 Quick_input.xpos = 2;
837 Quick_input.ypos = LINES - 2 - Quick_input.ylen;
838 quick_widgets [0].str_result = &my_str;
840 Quick_input.widgets = quick_widgets;
841 if (quick_dialog (&Quick_input) != B_CANCEL){
842 return my_str;
843 } else
844 return 0;
847 void
848 symlink_dialog (const char *existing, const char *new, char **ret_existing,
849 char **ret_new)
851 QuickDialog Quick_input;
852 QuickWidget quick_widgets[] = {
853 {quick_button, 50, 80, 6, 8, N_("&Cancel"), 0, B_CANCEL, 0, 0,
854 NULL},
855 {quick_button, 16, 80, 6, 8, N_("&OK"), 0, B_ENTER, 0, 0, NULL},
856 {quick_input, 4, 80, 5, 8, "", 58, 0, 0, 0, "input-1"},
857 {quick_label, 4, 80, 4, 8, N_("Symbolic link filename:"), 0, 0, 0,
858 0, NULL},
859 {quick_input, 4, 80, 3, 8, "", 58, 0, 0, 0, "input-2"},
860 {quick_label, 4, 80, 2, 8,
861 N_("Existing filename (filename symlink will point to):"), 0, 0,
862 0, 0, NULL},
863 NULL_QuickWidget
866 Quick_input.xlen = 64;
867 Quick_input.ylen = 12;
868 Quick_input.title = N_("Symbolic link");
869 Quick_input.help = "[File Menu]";
870 Quick_input.i18n = 0;
871 quick_widgets[2].text = new;
872 quick_widgets[4].text = existing;
873 Quick_input.xpos = -1;
874 quick_widgets[2].str_result = ret_new;
875 quick_widgets[4].str_result = ret_existing;
877 Quick_input.widgets = quick_widgets;
878 if (quick_dialog (&Quick_input) == B_CANCEL) {
879 *ret_new = NULL;
880 *ret_existing = NULL;
884 #ifdef WITH_BACKGROUND
885 #define B_STOP (B_USER+1)
886 #define B_RESUME (B_USER+2)
887 #define B_KILL (B_USER+3)
889 static int JOBS_X = 60;
890 #define JOBS_Y 15
891 static WListbox *bg_list;
892 static Dlg_head *jobs_dlg;
894 static void
895 jobs_fill_listbox (void)
897 static const char *state_str [2];
898 TaskList *tl = task_list;
900 if (!state_str [0]){
901 state_str [0] = _("Running ");
902 state_str [1] = _("Stopped");
905 while (tl){
906 char *s;
908 s = g_strconcat (state_str [tl->state], " ", tl->info, (char *) NULL);
909 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
910 g_free (s);
911 tl = tl->next;
915 static int
916 task_cb (int action)
918 TaskList *tl;
919 int sig = 0;
921 if (!bg_list->list)
922 return 0;
924 /* Get this instance information */
925 tl = (TaskList *) bg_list->current->data;
927 # ifdef SIGTSTP
928 if (action == B_STOP){
929 sig = SIGSTOP;
930 tl->state = Task_Stopped;
931 } else if (action == B_RESUME){
932 sig = SIGCONT;
933 tl->state = Task_Running;
934 } else
935 # endif
936 if (action == B_KILL){
937 sig = SIGKILL;
940 if (sig == SIGINT)
941 unregister_task_running (tl->pid, tl->fd);
943 kill (tl->pid, sig);
944 listbox_remove_list (bg_list);
945 jobs_fill_listbox ();
947 /* This can be optimized to just redraw this widget :-) */
948 dlg_redraw (jobs_dlg);
950 return 0;
953 static struct
955 const char* name;
956 int xpos;
957 int value;
958 int (*callback)(int);
960 job_buttons [] =
962 {N_("&Stop"), 3, B_STOP, task_cb},
963 {N_("&Resume"), 12, B_RESUME, task_cb},
964 {N_("&Kill"), 23, B_KILL, task_cb},
965 {N_("&OK"), 35, B_CANCEL, NULL }
968 void
969 jobs_cmd (void)
971 register int i;
972 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
974 #ifdef ENABLE_NLS
975 static int i18n_flag = 0;
976 if (!i18n_flag)
978 int startx = job_buttons [0].xpos;
979 int len;
981 for (i = 0; i < n_buttons; i++)
983 job_buttons [i].name = _(job_buttons [i].name);
985 len = strlen (job_buttons [i].name) + 4;
986 JOBS_X = max (JOBS_X, startx + len + 3);
988 job_buttons [i].xpos = startx;
989 startx += len;
992 /* Last button - Ok a.k.a. Cancel :) */
993 job_buttons [n_buttons - 1].xpos =
994 JOBS_X - strlen (job_buttons [n_buttons - 1].name) - 7;
996 i18n_flag = 1;
998 #endif /* ENABLE_NLS */
1000 jobs_dlg = create_dlg (0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL,
1001 "[Background jobs]", _("Background Jobs"),
1002 DLG_CENTER | DLG_REVERSE);
1004 bg_list = listbox_new (2, 3, JOBS_X-7, JOBS_Y-9, 0);
1005 add_widget (jobs_dlg, bg_list);
1007 i = n_buttons;
1008 while (i--)
1010 add_widget (jobs_dlg, button_new (JOBS_Y-4,
1011 job_buttons [i].xpos, job_buttons [i].value,
1012 NORMAL_BUTTON, job_buttons [i].name,
1013 job_buttons [i].callback));
1016 /* Insert all of task information in the list */
1017 jobs_fill_listbox ();
1018 run_dlg (jobs_dlg);
1020 destroy_dlg (jobs_dlg);
1022 #endif /* WITH_BACKGROUND */
1024 #ifdef WITH_SMBFS
1025 struct smb_authinfo *
1026 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
1027 const char *user)
1029 static int dialog_x = 44;
1030 enum { b0 = 3, dialog_y = 12};
1031 struct smb_authinfo *return_value;
1032 static const char* labs[] = {N_("Domain:"), N_("Username:"), N_("Password:")};
1033 static const char* buts[] = {N_("&OK"), N_("&Cancel")};
1034 static int ilen = 30, istart = 14;
1035 static int b2 = 30;
1036 char *title;
1037 WInput *in_password;
1038 WInput *in_user;
1039 WInput *in_domain;
1040 Dlg_head *auth_dlg;
1042 #ifdef ENABLE_NLS
1043 static int i18n_flag = 0;
1045 if (!i18n_flag)
1047 register int i = sizeof(labs)/sizeof(labs[0]);
1048 int l1, maxlen = 0;
1050 while (i--)
1052 l1 = strlen (labs [i] = _(labs [i]));
1053 if (l1 > maxlen)
1054 maxlen = l1;
1056 i = maxlen + ilen + 7;
1057 if (i > dialog_x)
1058 dialog_x = i;
1060 for (i = sizeof(buts)/sizeof(buts[0]), l1 = 0; i--; )
1062 l1 += strlen (buts [i] = _(buts [i]));
1064 l1 += 15;
1065 if (l1 > dialog_x)
1066 dialog_x = l1;
1068 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1069 istart = dialog_x - 3 - ilen;
1071 b2 = dialog_x - (strlen(buts[1]) + 6);
1073 i18n_flag = 1;
1076 #endif /* ENABLE_NLS */
1078 if (!domain)
1079 domain = "";
1080 if (!user)
1081 user = "";
1083 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1085 auth_dlg = create_dlg (0, 0, dialog_y, dialog_x, dialog_colors, NULL,
1086 "[Smb Authinfo]", title, DLG_CENTER | DLG_REVERSE);
1088 g_free (title);
1090 in_user = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name", INPUT_COMPLETE_DEFAULT);
1091 add_widget (auth_dlg, in_user);
1093 in_domain = input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain", INPUT_COMPLETE_DEFAULT);
1094 add_widget (auth_dlg, in_domain);
1095 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON,
1096 buts[1], 0));
1097 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON,
1098 buts[0], 0));
1100 in_password = input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password", INPUT_COMPLETE_DEFAULT);
1101 in_password->completion_flags = 0;
1102 in_password->is_password = 1;
1103 add_widget (auth_dlg, in_password);
1105 add_widget (auth_dlg, label_new (7, 3, labs[2]));
1106 add_widget (auth_dlg, label_new (5, 3, labs[1]));
1107 add_widget (auth_dlg, label_new (3, 3, labs[0]));
1109 run_dlg (auth_dlg);
1111 switch (auth_dlg->ret_value) {
1112 case B_CANCEL:
1113 return_value = 0;
1114 break;
1115 default:
1116 return_value = g_new (struct smb_authinfo, 1);
1117 if (return_value) {
1118 return_value->host = g_strdup (host);
1119 return_value->share = g_strdup (share);
1120 return_value->domain = g_strdup (in_domain->buffer);
1121 return_value->user = g_strdup (in_user->buffer);
1122 return_value->password = g_strdup (in_password->buffer);
1126 destroy_dlg (auth_dlg);
1128 return return_value;
1130 #endif /* WITH_SMBFS */