replaced gboolean by bool (from mhl/types.h)
[midnight-commander.git] / src / boxes.c
blob48ac3a9b09325e924cfc7043fa5c65fdb5b3e5e9
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", INPUT_COMPLETE_DEFAULT);
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", INPUT_COMPLETE_DEFAULT);
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 = 60, 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, int *exec_first)
276 int i, r, l;
277 sortfn *result;
278 WCheck *c, *case_sense, *exec_ff;
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");
285 const char *exec_label = _("Executable first");
287 static int i18n_sort_flag = 0, check_pos = 0, button_pos = 0;
289 if (!i18n_sort_flag) {
290 int maxlen = 0;
291 for (i = SORT_TYPES - 1; i >= 0; i--) {
292 sort_orders_names[i] = _(sort_orders[i].sort_name);
293 r = strlen (sort_orders_names[i]);
294 if (r > maxlen)
295 maxlen = r;
298 check_pos = maxlen + 9;
300 r = strlen (reverse_label) + 4;
301 i = strlen (case_label) + 4;
302 if (i > r)
303 r = i;
305 l = strlen (ok_button) + 6;
306 i = strlen (cancel_button) + 4;
307 if (i > l)
308 l = i;
310 i = check_pos + max (r, l) + 2;
312 if (i > SORT_X)
313 SORT_X = i;
315 i = strlen (sort_title) + 6;
316 if (i > SORT_X)
317 SORT_X = i;
319 button_pos = SORT_X - l - 2;
321 i18n_sort_flag = 1;
324 result = 0;
326 for (i = 0; i < SORT_TYPES; i++)
327 if ((sortfn *) (sort_orders[i].sort_fn) == sort_fn) {
328 current_mode = i;
329 break;
332 dd = create_dlg (0, 0, SORT_Y, SORT_X, dialog_colors, NULL,
333 "[Sort Order...]", sort_title, DLG_CENTER | DLG_REVERSE);
335 add_widget (dd,
336 button_new (10, button_pos, B_CANCEL, NORMAL_BUTTON,
337 cancel_button, 0));
339 add_widget (dd,
340 button_new (9, button_pos, B_ENTER, DEFPUSH_BUTTON,
341 ok_button, 0));
343 exec_ff = check_new (5, check_pos, *exec_first, exec_label);
344 add_widget (dd, exec_ff);
345 case_sense = check_new (4, check_pos, *case_sensitive, case_label);
346 add_widget (dd, case_sense);
347 c = check_new (3, check_pos, *reverse, reverse_label);
348 add_widget (dd, c);
350 my_radio = radio_new (3, 3, SORT_TYPES, sort_orders_names);
351 my_radio->sel = my_radio->pos = current_mode;
353 add_widget (dd, my_radio);
354 run_dlg (dd);
356 r = dd->ret_value;
357 if (r != B_CANCEL) {
358 result = (sortfn *) sort_orders[my_radio->sel].sort_fn;
359 *reverse = c->state & C_BOOL;
360 *case_sensitive = case_sense->state & C_BOOL;
361 *exec_first = exec_ff->state & C_BOOL;
362 } else
363 result = sort_fn;
364 destroy_dlg (dd);
366 return result;
369 #define CONFY 11
370 #define CONFX 46
372 static int my_delete;
373 static int my_directory_hotlist_delete;
374 static int my_overwrite;
375 static int my_execute;
376 static int my_exit;
378 static QuickWidget conf_widgets [] = {
379 { quick_button, 4, 6, 4, CONFY, N_("&Cancel"),
380 0, B_CANCEL, 0, 0, NULL },
381 { quick_button, 4, 6, 3, CONFY, N_("&OK"),
382 0, B_ENTER, 0, 0, NULL },
384 { quick_checkbox, 1, 13, 7, CONFY, N_(" confirm di&Rectory hotlist delete "),
385 11, 0, &my_directory_hotlist_delete, NULL, NULL },
386 { quick_checkbox, 1, 13, 6, CONFY, N_(" confirm &Exit "),
387 9, 0, &my_exit, 0, NULL },
388 { quick_checkbox, 1, 13, 5, CONFY, N_(" confirm e&Xecute "),
389 10, 0, &my_execute, 0, NULL },
390 { quick_checkbox, 1, 13, 4, CONFY, N_(" confirm o&Verwrite "),
391 10, 0, &my_overwrite, 0, NULL },
392 { quick_checkbox, 1, 13, 3, CONFY, N_(" confirm &Delete "),
393 9, 0, &my_delete, 0, NULL },
394 NULL_QuickWidget
397 static QuickDialog confirmation =
398 { CONFX, CONFY, -1, -1, N_(" Confirmation "), "[Confirmation]",
399 conf_widgets, 0
402 void
403 confirm_box (void)
406 #ifdef ENABLE_NLS
407 static int i18n_flag = 0;
409 if (!i18n_flag)
411 register int i = sizeof(conf_widgets)/sizeof(QuickWidget) - 1;
412 int l1, maxlen = 0;
413 while (i--)
415 conf_widgets [i].text = _(conf_widgets [i].text);
416 l1 = strlen (conf_widgets [i].text) + 3;
417 if (l1 > maxlen)
418 maxlen = l1;
422 * If buttons start on 4/6, checkboxes (with some add'l space)
423 * must take not more than it.
425 confirmation.xlen = (maxlen + 5) * 6 / 4;
428 * And this for the case when buttons with some space to the right
429 * do not fit within 2/6
431 l1 = strlen (conf_widgets [0].text) + 3;
432 i = strlen (conf_widgets [1].text) + 5;
433 if (i > l1)
434 l1 = i;
436 i = (l1 + 3) * 6 / 2;
437 if (i > confirmation.xlen)
438 confirmation.xlen = i;
440 confirmation.title = _(confirmation.title);
442 i18n_flag = confirmation.i18n = 1;
445 #endif /* ENABLE_NLS */
447 my_delete = confirm_delete;
448 my_overwrite = confirm_overwrite;
449 my_execute = confirm_execute;
450 my_exit = confirm_exit;
451 my_directory_hotlist_delete = confirm_directory_hotlist_delete;
453 if (quick_dialog (&confirmation) != B_CANCEL){
454 confirm_delete = my_delete;
455 confirm_overwrite = my_overwrite;
456 confirm_execute = my_execute;
457 confirm_exit = my_exit;
458 confirm_directory_hotlist_delete = my_directory_hotlist_delete;
462 #define DISPY 11
463 #define DISPX 46
466 #ifndef HAVE_CHARSET
468 static int new_mode;
469 static int new_meta;
471 static const char *display_bits_str [] =
472 { N_("Full 8 bits output"), N_("ISO 8859-1"), N_("7 bits") };
474 static QuickWidget display_widgets [] = {
475 { quick_button, 4, 6, 4, DISPY, N_("&Cancel"),
476 0, B_CANCEL, 0, 0, NULL },
477 { quick_button, 4, 6, 3, DISPY, N_("&OK"),
478 0, B_ENTER, 0, 0, NULL },
479 { quick_checkbox, 4, DISPX, 7, DISPY, N_("F&ull 8 bits input"),
480 0, 0, &new_meta, 0, NULL },
481 { quick_radio, 4, DISPX, 3, DISPY, "", 3, 0,
482 &new_mode, const_cast(char **, display_bits_str), NULL },
483 NULL_QuickWidget
486 static QuickDialog display_bits =
487 { DISPX, DISPY, -1, -1, N_(" Display bits "), "[Display bits]",
488 display_widgets, 0 };
490 void
491 display_bits_box (void)
493 int current_mode;
495 #ifdef ENABLE_NLS
496 static int i18n_flag = 0;
497 if (!i18n_flag)
499 register int i;
500 int l1, maxlen = 0;
501 for (i = 0; i < 3; i++)
503 display_widgets [i].text = _(display_widgets[i].text);
504 display_bits_str [i] = _(display_bits_str [i]);
505 l1 = strlen (display_bits_str [i]);
506 if (l1 > maxlen)
507 maxlen = l1;
509 l1 = strlen (display_widgets [2].text);
510 if (l1 > maxlen)
511 maxlen = l1;
514 display_bits.xlen = (maxlen + 5) * 6 / 4;
516 /* See above confirm_box */
517 l1 = strlen (display_widgets [0].text) + 3;
518 i = strlen (display_widgets [1].text) + 5;
519 if (i > l1)
520 l1 = i;
522 i = (l1 + 3) * 6 / 2;
523 if (i > display_bits.xlen)
524 display_bits.xlen = i;
526 display_bits.title = _(display_bits.title);
527 i18n_flag = display_bits.i18n = 1;
530 #endif /* ENABLE_NLS */
532 if (full_eight_bits)
533 current_mode = 0;
534 else if (eight_bit_clean)
535 current_mode = 1;
536 else
537 current_mode = 2;
539 display_widgets [3].value = current_mode;
540 new_meta = !use_8th_bit_as_meta;
541 if (quick_dialog (&display_bits) != B_ENTER)
542 return;
544 eight_bit_clean = new_mode < 2;
545 full_eight_bits = new_mode == 0;
546 #ifndef HAVE_SLANG
547 meta (stdscr, eight_bit_clean);
548 #else
549 SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
550 #endif
551 use_8th_bit_as_meta = !new_meta;
555 #else /* HAVE_CHARSET */
558 static int new_display_codepage;
560 static WLabel *cplabel;
561 static WCheck *inpcheck;
563 static int
564 sel_charset_button (int action)
566 const char *cpname;
567 char buf[64];
568 new_display_codepage = select_charset (new_display_codepage, 1);
569 cpname = (new_display_codepage < 0)
570 ? _("Other 8 bit")
571 : codepages[new_display_codepage].name;
573 /* avoid strange bug with label repainting */
574 g_snprintf (buf, sizeof (buf), "%-27s", cpname);
575 label_set_text (cplabel, buf);
576 return 0;
579 static Dlg_head *
580 init_disp_bits_box (void)
582 const char *cpname;
583 Dlg_head *dbits_dlg;
585 do_refresh ();
587 dbits_dlg =
588 create_dlg (0, 0, DISPY, DISPX, dialog_colors, NULL,
589 "[Display bits]", _(" Display bits "), DLG_CENTER | DLG_REVERSE);
591 add_widget (dbits_dlg,
592 label_new (3, 4, _("Input / display codepage:")));
594 cpname = (new_display_codepage < 0)
595 ? _("Other 8 bit")
596 : codepages[new_display_codepage].name;
597 cplabel = label_new (4, 4, cpname);
598 add_widget (dbits_dlg, cplabel);
600 add_widget (dbits_dlg,
601 button_new (DISPY - 3, DISPX / 2 + 3, B_CANCEL,
602 NORMAL_BUTTON, _("&Cancel"), 0));
603 add_widget (dbits_dlg,
604 button_new (DISPY - 3, 7, B_ENTER, NORMAL_BUTTON, _("&OK"),
605 0));
607 inpcheck =
608 check_new (6, 4, !use_8th_bit_as_meta, _("F&ull 8 bits input"));
609 add_widget (dbits_dlg, inpcheck);
611 cpname = _("&Select");
612 add_widget (dbits_dlg,
613 button_new (4, DISPX - 8 - strlen (cpname), B_USER,
614 NORMAL_BUTTON, cpname, sel_charset_button));
616 return dbits_dlg;
619 void
620 display_bits_box (void)
622 Dlg_head *dbits_dlg;
623 new_display_codepage = display_codepage;
625 application_keypad_mode ();
626 dbits_dlg = init_disp_bits_box ();
628 run_dlg (dbits_dlg);
630 if (dbits_dlg->ret_value == B_ENTER) {
631 const char *errmsg;
632 display_codepage = new_display_codepage;
633 errmsg =
634 init_translation_table (source_codepage, display_codepage);
635 if (errmsg)
636 message (D_ERROR, MSG_ERROR, "%s", errmsg);
637 #ifndef HAVE_SLANG
638 meta (stdscr, display_codepage != 0);
639 #else
640 SLsmg_Display_Eight_Bit = (display_codepage != 0
641 && display_codepage != 1) ? 128 : 160;
642 #endif
643 use_8th_bit_as_meta = !(inpcheck->state & C_BOOL);
645 destroy_dlg (dbits_dlg);
646 repaint_screen ();
649 #endif /* HAVE_CHARSET */
652 #define TREE_Y 20
653 #define TREE_X 60
655 static cb_ret_t
656 tree_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
658 switch (msg) {
660 case DLG_POST_KEY:
661 /* The enter key will be processed by the tree widget */
662 if (parm == '\n') {
663 h->ret_value = B_ENTER;
664 dlg_stop (h);
666 return MSG_HANDLED;
668 default:
669 return default_dlg_callback (h, msg, parm);
673 /* Show tree in a box, not on a panel */
674 char *
675 tree_box (const char *current_dir)
677 WTree *mytree;
678 Dlg_head *dlg;
679 char *val;
680 WButtonBar *bar;
682 /* Create the components */
683 dlg = create_dlg (0, 0, TREE_Y, TREE_X, dialog_colors,
684 tree_callback, "[Directory Tree]", NULL, DLG_CENTER | DLG_REVERSE);
685 mytree = tree_new (0, 2, 2, TREE_Y - 6, TREE_X - 5);
686 add_widget (dlg, mytree);
687 bar = buttonbar_new(1);
688 add_widget (dlg, bar);
689 ((Widget *) bar)->x = 0;
690 ((Widget *) bar)->y = LINES - 1;
692 run_dlg (dlg);
693 if (dlg->ret_value == B_ENTER)
694 val = g_strdup (tree_selected_name (mytree));
695 else
696 val = 0;
698 destroy_dlg (dlg);
699 return val;
702 #ifdef USE_VFS
704 #if defined(USE_NETCODE)
705 #define VFSY 17
706 #define VFS_WIDGETBASE 10
707 #else
708 #define VFSY 8
709 #define VFS_WIDGETBASE 0
710 #endif
712 #define VFSX 56
714 static char *ret_timeout;
716 #if defined(USE_NETCODE)
717 static char *ret_passwd;
718 static char *ret_directory_timeout;
719 static char *ret_ftp_proxy;
720 static int ret_use_netrc;
721 static int ret_ftpfs_use_passive_connections;
722 static int ret_ftpfs_use_passive_connections_over_proxy;
723 #endif
725 static QuickWidget confvfs_widgets [] = {
726 { quick_button, 30, VFSX, VFSY - 3, VFSY, N_("&Cancel"),
727 0, B_CANCEL, 0, 0, NULL },
728 { quick_button, 12, VFSX, VFSY - 3, VFSY, N_("&OK"),
729 0, B_ENTER, 0, 0, NULL },
730 #if defined(USE_NETCODE)
731 { quick_checkbox, 4, VFSX, 12, VFSY, N_("Use passive mode over pro&xy"), 0, 0,
732 &ret_ftpfs_use_passive_connections_over_proxy, 0, NULL },
733 { quick_checkbox, 4, VFSX, 11, VFSY, N_("Use &passive mode"), 0, 0,
734 &ret_ftpfs_use_passive_connections, 0, NULL },
735 { quick_checkbox, 4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), 0, 0,
736 &ret_use_netrc, 0, NULL },
737 { quick_input, 4, VFSX, 9, VFSY, "", 48, 0, 0, &ret_ftp_proxy,
738 "input-ftp-proxy" },
739 { quick_checkbox, 4, VFSX, 8, VFSY, N_("&Always use ftp proxy"), 0, 0,
740 &ftpfs_always_use_proxy, 0, NULL },
741 { quick_label, 49, VFSX, 7, VFSY, N_("sec"),
742 0, 0, 0, 0, NULL },
743 { quick_input, 38, VFSX, 7, VFSY, "", 10, 0, 0, &ret_directory_timeout,
744 "input-timeout" },
745 { quick_label, 4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:"),
746 0, 0, 0, 0, NULL },
747 { quick_input, 4, VFSX, 6, VFSY, "", 48, 0, 0, &ret_passwd,
748 "input-passwd" },
749 { quick_label, 4, VFSX, 5, VFSY, N_("ftp anonymous password:"),
750 0, 0, 0, 0, NULL },
751 #endif
752 { quick_label, 49, VFSX, 3, VFSY, "sec",
753 0, 0, 0, 0, NULL },
754 { quick_input, 38, VFSX, 3, VFSY, "", 10, 0, 0, &ret_timeout,
755 "input-timo-vfs" },
756 { quick_label, 4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:"),
757 0, 0, 0, 0, NULL },
758 NULL_QuickWidget
761 static QuickDialog confvfs_dlg =
762 { VFSX, VFSY, -1, -1, N_(" Virtual File System Setting "),
763 "[Virtual FS]", confvfs_widgets, 0 };
765 void
766 configure_vfs (void)
768 char buffer2[BUF_TINY];
769 #if defined(USE_NETCODE)
770 char buffer3[BUF_TINY];
772 ret_use_netrc = use_netrc;
773 ret_ftpfs_use_passive_connections = ftpfs_use_passive_connections;
774 ret_ftpfs_use_passive_connections_over_proxy = ftpfs_use_passive_connections_over_proxy;
775 g_snprintf(buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
776 confvfs_widgets[8].text = buffer3;
777 confvfs_widgets[10].text = ftpfs_anonymous_passwd;
778 confvfs_widgets[5].text = ftpfs_proxy_host;
779 #endif
780 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
781 confvfs_widgets [3 + VFS_WIDGETBASE].text = buffer2;
783 if (quick_dialog (&confvfs_dlg) != B_CANCEL) {
784 vfs_timeout = atoi (ret_timeout);
785 g_free (ret_timeout);
786 if (vfs_timeout < 0 || vfs_timeout > 10000)
787 vfs_timeout = 10;
788 #if defined(USE_NETCODE)
789 g_free (ftpfs_anonymous_passwd);
790 ftpfs_anonymous_passwd = ret_passwd;
791 g_free (ftpfs_proxy_host);
792 ftpfs_proxy_host = ret_ftp_proxy;
793 ftpfs_directory_timeout = atoi(ret_directory_timeout);
794 use_netrc = ret_use_netrc;
795 ftpfs_use_passive_connections = ret_ftpfs_use_passive_connections;
796 ftpfs_use_passive_connections_over_proxy = ret_ftpfs_use_passive_connections_over_proxy;
797 g_free (ret_directory_timeout);
798 #endif
802 #endif /* USE_VFS */
804 char *
805 cd_dialog (void)
807 QuickDialog Quick_input;
808 QuickWidget quick_widgets [] = {
809 { quick_input, 6, 57, 2, 0, "", 50, 0, 0, 0, "input" },
810 { quick_label, 3, 57, 2, 0, "", 0, 0, 0, 0, NULL },
811 NULL_QuickWidget
813 char *my_str;
814 int len;
816 Quick_input.xlen = 57;
817 Quick_input.title = _("Quick cd");
818 Quick_input.help = "[Quick cd]";
819 quick_widgets [0].value = 2; /* want cd like completion */
820 quick_widgets [1].text = _("cd");
821 quick_widgets [1].y_divisions =
822 quick_widgets [0].y_divisions = Quick_input.ylen = 5;
824 len = strlen (quick_widgets [1].text);
826 quick_widgets [0].relative_x =
827 quick_widgets [1].relative_x + len + 1;
829 Quick_input.xlen = len + quick_widgets [0].hotkey_pos + 7;
830 quick_widgets [0].x_divisions =
831 quick_widgets [1].x_divisions = Quick_input.xlen;
833 Quick_input.i18n = 1;
834 Quick_input.xpos = 2;
835 Quick_input.ypos = LINES - 2 - Quick_input.ylen;
836 quick_widgets [0].str_result = &my_str;
838 Quick_input.widgets = quick_widgets;
839 if (quick_dialog (&Quick_input) != B_CANCEL){
840 return my_str;
841 } else
842 return 0;
845 void
846 symlink_dialog (const char *existing, const char *new, char **ret_existing,
847 char **ret_new)
849 QuickDialog Quick_input;
850 QuickWidget quick_widgets[] = {
851 {quick_button, 50, 80, 6, 8, N_("&Cancel"), 0, B_CANCEL, 0, 0,
852 NULL},
853 {quick_button, 16, 80, 6, 8, N_("&OK"), 0, B_ENTER, 0, 0, NULL},
854 {quick_input, 4, 80, 5, 8, "", 58, 0, 0, 0, "input-1"},
855 {quick_label, 4, 80, 4, 8, N_("Symbolic link filename:"), 0, 0, 0,
856 0, NULL},
857 {quick_input, 4, 80, 3, 8, "", 58, 0, 0, 0, "input-2"},
858 {quick_label, 4, 80, 2, 8,
859 N_("Existing filename (filename symlink will point to):"), 0, 0,
860 0, 0, NULL},
861 NULL_QuickWidget
864 Quick_input.xlen = 64;
865 Quick_input.ylen = 12;
866 Quick_input.title = N_("Symbolic link");
867 Quick_input.help = "[File Menu]";
868 Quick_input.i18n = 0;
869 quick_widgets[2].text = new;
870 quick_widgets[4].text = existing;
871 Quick_input.xpos = -1;
872 quick_widgets[2].str_result = ret_new;
873 quick_widgets[4].str_result = ret_existing;
875 Quick_input.widgets = quick_widgets;
876 if (quick_dialog (&Quick_input) == B_CANCEL) {
877 *ret_new = NULL;
878 *ret_existing = NULL;
882 #ifdef WITH_BACKGROUND
883 #define B_STOP (B_USER+1)
884 #define B_RESUME (B_USER+2)
885 #define B_KILL (B_USER+3)
887 static int JOBS_X = 60;
888 #define JOBS_Y 15
889 static WListbox *bg_list;
890 static Dlg_head *jobs_dlg;
892 static void
893 jobs_fill_listbox (void)
895 static const char *state_str [2];
896 TaskList *tl = task_list;
898 if (!state_str [0]){
899 state_str [0] = _("Running ");
900 state_str [1] = _("Stopped");
903 while (tl){
904 char *s;
906 s = g_strconcat (state_str [tl->state], " ", tl->info, (char *) NULL);
907 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
908 g_free (s);
909 tl = tl->next;
913 static int
914 task_cb (int action)
916 TaskList *tl;
917 int sig = 0;
919 if (!bg_list->list)
920 return 0;
922 /* Get this instance information */
923 tl = (TaskList *) bg_list->current->data;
925 # ifdef SIGTSTP
926 if (action == B_STOP){
927 sig = SIGSTOP;
928 tl->state = Task_Stopped;
929 } else if (action == B_RESUME){
930 sig = SIGCONT;
931 tl->state = Task_Running;
932 } else
933 # endif
934 if (action == B_KILL){
935 sig = SIGKILL;
938 if (sig == SIGINT)
939 unregister_task_running (tl->pid, tl->fd);
941 kill (tl->pid, sig);
942 listbox_remove_list (bg_list);
943 jobs_fill_listbox ();
945 /* This can be optimized to just redraw this widget :-) */
946 dlg_redraw (jobs_dlg);
948 return 0;
951 static struct
953 const char* name;
954 int xpos;
955 int value;
956 int (*callback)(int);
958 job_buttons [] =
960 {N_("&Stop"), 3, B_STOP, task_cb},
961 {N_("&Resume"), 12, B_RESUME, task_cb},
962 {N_("&Kill"), 23, B_KILL, task_cb},
963 {N_("&OK"), 35, B_CANCEL, NULL }
966 void
967 jobs_cmd (void)
969 register int i;
970 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
972 #ifdef ENABLE_NLS
973 static int i18n_flag = 0;
974 if (!i18n_flag)
976 int startx = job_buttons [0].xpos;
977 int len;
979 for (i = 0; i < n_buttons; i++)
981 job_buttons [i].name = _(job_buttons [i].name);
983 len = strlen (job_buttons [i].name) + 4;
984 JOBS_X = max (JOBS_X, startx + len + 3);
986 job_buttons [i].xpos = startx;
987 startx += len;
990 /* Last button - Ok a.k.a. Cancel :) */
991 job_buttons [n_buttons - 1].xpos =
992 JOBS_X - strlen (job_buttons [n_buttons - 1].name) - 7;
994 i18n_flag = 1;
996 #endif /* ENABLE_NLS */
998 jobs_dlg = create_dlg (0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL,
999 "[Background jobs]", _("Background Jobs"),
1000 DLG_CENTER | DLG_REVERSE);
1002 bg_list = listbox_new (2, 3, JOBS_X-7, JOBS_Y-9, 0);
1003 add_widget (jobs_dlg, bg_list);
1005 i = n_buttons;
1006 while (i--)
1008 add_widget (jobs_dlg, button_new (JOBS_Y-4,
1009 job_buttons [i].xpos, job_buttons [i].value,
1010 NORMAL_BUTTON, job_buttons [i].name,
1011 job_buttons [i].callback));
1014 /* Insert all of task information in the list */
1015 jobs_fill_listbox ();
1016 run_dlg (jobs_dlg);
1018 destroy_dlg (jobs_dlg);
1020 #endif /* WITH_BACKGROUND */
1022 #ifdef WITH_SMBFS
1023 struct smb_authinfo *
1024 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
1025 const char *user)
1027 static int dialog_x = 44;
1028 enum { b0 = 3, dialog_y = 12};
1029 struct smb_authinfo *return_value;
1030 static const char* labs[] = {N_("Domain:"), N_("Username:"), N_("Password:")};
1031 static const char* buts[] = {N_("&OK"), N_("&Cancel")};
1032 static int ilen = 30, istart = 14;
1033 static int b2 = 30;
1034 char *title;
1035 WInput *in_password;
1036 WInput *in_user;
1037 WInput *in_domain;
1038 Dlg_head *auth_dlg;
1040 #ifdef ENABLE_NLS
1041 static int i18n_flag = 0;
1043 if (!i18n_flag)
1045 register int i = sizeof(labs)/sizeof(labs[0]);
1046 int l1, maxlen = 0;
1048 while (i--)
1050 l1 = strlen (labs [i] = _(labs [i]));
1051 if (l1 > maxlen)
1052 maxlen = l1;
1054 i = maxlen + ilen + 7;
1055 if (i > dialog_x)
1056 dialog_x = i;
1058 for (i = sizeof(buts)/sizeof(buts[0]), l1 = 0; i--; )
1060 l1 += strlen (buts [i] = _(buts [i]));
1062 l1 += 15;
1063 if (l1 > dialog_x)
1064 dialog_x = l1;
1066 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1067 istart = dialog_x - 3 - ilen;
1069 b2 = dialog_x - (strlen(buts[1]) + 6);
1071 i18n_flag = 1;
1074 #endif /* ENABLE_NLS */
1076 if (!domain)
1077 domain = "";
1078 if (!user)
1079 user = "";
1081 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1083 auth_dlg = create_dlg (0, 0, dialog_y, dialog_x, dialog_colors, NULL,
1084 "[Smb Authinfo]", title, DLG_CENTER | DLG_REVERSE);
1086 g_free (title);
1088 in_user = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name", INPUT_COMPLETE_DEFAULT);
1089 add_widget (auth_dlg, in_user);
1091 in_domain = input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain", INPUT_COMPLETE_DEFAULT);
1092 add_widget (auth_dlg, in_domain);
1093 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON,
1094 buts[1], 0));
1095 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON,
1096 buts[0], 0));
1098 in_password = input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password", INPUT_COMPLETE_DEFAULT);
1099 in_password->completion_flags = 0;
1100 in_password->is_password = 1;
1101 add_widget (auth_dlg, in_password);
1103 add_widget (auth_dlg, label_new (7, 3, labs[2]));
1104 add_widget (auth_dlg, label_new (5, 3, labs[1]));
1105 add_widget (auth_dlg, label_new (3, 3, labs[0]));
1107 run_dlg (auth_dlg);
1109 switch (auth_dlg->ret_value) {
1110 case B_CANCEL:
1111 return_value = 0;
1112 break;
1113 default:
1114 return_value = g_new (struct smb_authinfo, 1);
1115 if (return_value) {
1116 return_value->host = g_strdup (host);
1117 return_value->share = g_strdup (share);
1118 return_value->domain = g_strdup (in_domain->buffer);
1119 return_value->user = g_strdup (in_user->buffer);
1120 return_value->password = g_strdup (in_password->buffer);
1124 destroy_dlg (auth_dlg);
1126 return return_value;
1128 #endif /* WITH_SMBFS */