Updated italian translation.
[midnight-commander.git] / src / boxes.c
blob89cb17022dc294ecbfa2db66156994571a20d6a3
1 /* Some misc dialog boxes for the program.
3 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 2005, 2006, 2009 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 /** \file boxes.c
24 * \brief Source: Some misc dialog boxes for the program
27 #include <config.h>
29 #include <ctype.h>
30 #include <signal.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
37 #include "lib/global.h"
39 #include "lib/tty/tty.h"
40 #include "lib/skin.h" /* INPUT_COLOR */
41 #include "lib/tty/key.h" /* XCTRL and ALT macros */
42 #include "lib/mcconfig.h" /* Load/save user formats */
43 #include "lib/strutil.h"
45 #ifdef USE_NETCODE
46 # include "lib/vfs/mc-vfs/ftpfs.h"
47 #endif
49 #ifdef ENABLE_VFS
50 #include "lib/vfs/mc-vfs/gc.h"
51 #endif
53 #include "dialog.h" /* The nice dialog manager */
54 #include "widget.h" /* The widgets for the nice dialog manager */
55 #include "wtools.h"
56 #include "setup.h" /* For profile_name */
57 #include "command.h" /* For cmdline */
58 #include "dir.h"
59 #include "panel.h" /* LIST_TYPES */
60 #include "boxes.h"
61 #include "main.h" /* For the confirm_* variables */
62 #include "tree.h"
63 #include "layout.h" /* for get_nth_panel_name proto */
64 #include "background.h" /* task_list */
66 #ifdef HAVE_CHARSET
67 #include "charsets.h"
68 #include "selcodepage.h"
69 #endif
72 static WRadio *display_radio;
73 static WInput *display_user_format;
74 static WInput *display_mini_status;
75 static WCheck *display_check_status;
76 static char **displays_status;
77 static int display_user_hotkey = 'u';
79 static cb_ret_t
80 display_callback (Dlg_head *h, Widget *sender,
81 dlg_msg_t msg, int parm, void *data)
83 switch (msg) {
84 case DLG_UNFOCUS:
85 if (dlg_widget_active (display_radio)) {
86 assign_text (display_mini_status, displays_status[display_radio->sel]);
87 input_set_point (display_mini_status, 0);
89 return MSG_HANDLED;
91 case DLG_KEY:
92 if (parm == '\n') {
93 if (dlg_widget_active (display_radio)) {
94 assign_text (display_mini_status, displays_status[display_radio->sel]);
95 dlg_stop (h);
96 return MSG_HANDLED;
99 if (dlg_widget_active (display_user_format)) {
100 h->ret_value = B_USER + 6;
101 dlg_stop (h);
102 return MSG_HANDLED;
105 if (dlg_widget_active (display_mini_status)) {
106 h->ret_value = B_USER + 7;
107 dlg_stop (h);
108 return MSG_HANDLED;
112 if (g_ascii_tolower (parm) == display_user_hotkey && dlg_widget_active (display_user_format)
113 && dlg_widget_active (display_mini_status)) {
114 display_radio->sel = 3;
115 dlg_select_widget (display_radio); /* force redraw */
116 dlg_select_widget (display_user_format);
117 return MSG_HANDLED;
119 return MSG_NOT_HANDLED;
121 default:
122 return default_dlg_callback (h, sender, msg, parm, data);
126 static Dlg_head *
127 display_init (int radio_sel, char *init_text, int _check_status,
128 char **_status)
130 int dlg_width = 48, dlg_height = 15;
131 Dlg_head *dd;
133 /* Controls whether the array strings have been translated */
134 const char *displays [LIST_TYPES] =
136 N_("&Full file list"),
137 N_("&Brief file list"),
138 N_("&Long file list"),
139 N_("&User defined:")
142 /* Index in displays[] for "user defined" */
143 const int user_type_idx = 3;
145 const char *display_title = N_("Listing mode");
146 const char *user_mini_status = N_("user &Mini status");
147 const char *ok_name = N_("&OK");
148 const char *cancel_name = N_("&Cancel");
150 WButton *ok_button, *cancel_button;
153 int i, maxlen = 0;
154 const char *cp;
155 int ok_len, cancel_len;
157 #ifdef ENABLE_NLS
158 display_title = _(display_title);
159 user_mini_status = _(user_mini_status);
160 ok_name = _(ok_name);
161 cancel_name = _(cancel_name);
163 for (i = 0; i < LIST_TYPES; i++)
164 displays[i] = _(displays[i]);
165 #endif
167 /* get hotkey of user-defined format string */
168 cp = strchr (displays[user_type_idx], '&');
169 if (cp != NULL && *++cp != '\0')
170 display_user_hotkey = g_ascii_tolower (*cp);
172 /* xpos will be fixed later */
173 ok_button = button_new (dlg_height - 3, 0, B_ENTER, DEFPUSH_BUTTON, ok_name, 0);
174 ok_len = button_get_len (ok_button);
175 cancel_button = button_new (dlg_height - 3, 0, B_CANCEL, NORMAL_BUTTON, cancel_name, 0);
176 cancel_len = button_get_len (cancel_button);
178 dlg_width = max (dlg_width, str_term_width1 (display_title) + 10);
179 /* calculate max width of radiobutons */
180 for (i = 0; i < LIST_TYPES; i++)
181 maxlen = max (maxlen, str_term_width1 (displays[i]));
182 dlg_width = max (dlg_width, maxlen);
183 dlg_width = max (dlg_width, str_term_width1 (user_mini_status) + 13);
185 /* buttons */
186 dlg_width = max (dlg_width, ok_len + cancel_len + 8);
187 ok_button->widget.x = dlg_width/3 - ok_len/2;
188 cancel_button->widget.x = dlg_width * 2/3 - cancel_len/2;
191 displays_status = _status;
193 dd = create_dlg (0, 0, dlg_height, dlg_width, dialog_colors,
194 display_callback, "[Listing Mode...]", display_title,
195 DLG_CENTER | DLG_REVERSE);
197 add_widget (dd, cancel_button);
198 add_widget (dd, ok_button);
200 display_mini_status = input_new (10, 8, INPUT_COLOR, dlg_width - 12, _status[radio_sel],
201 "mini-input", INPUT_COMPLETE_DEFAULT);
202 add_widget (dd, display_mini_status);
203 input_set_point (display_mini_status, 0);
205 display_check_status = check_new (9, 4, _check_status, user_mini_status);
206 add_widget (dd, display_check_status);
208 display_user_format = input_new (7, 8, INPUT_COLOR, dlg_width - 12, init_text,
209 "user-fmt-input", INPUT_COMPLETE_DEFAULT);
210 add_widget (dd, display_user_format);
211 input_set_point (display_user_format, 0);
213 display_radio = radio_new (3, 4, LIST_TYPES, displays);
214 display_radio->sel = display_radio->pos = radio_sel;
215 add_widget (dd, display_radio);
217 return dd;
220 /* return list type */
222 display_box (WPanel *panel, char **userp, char **minip, int *use_msformat, int num)
224 int result = -1;
225 Dlg_head *dd;
226 char *section = NULL;
227 size_t i;
229 if (panel == NULL) {
230 const char *p = get_nth_panel_name (num);
231 panel = g_new (WPanel, 1);
232 panel->list_type = list_full;
233 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
234 panel->user_mini_status = 0;
235 for (i = 0; i < LIST_TYPES; i++)
236 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
237 section = g_strconcat ("Temporal:", p, (char *) NULL);
238 if (! mc_config_has_group (mc_main_config, section)) {
239 g_free (section);
240 section = g_strdup (p);
242 panel_load_setup (panel, section);
243 g_free (section);
246 dd = display_init (panel->list_type, panel->user_format,
247 panel->user_mini_status, panel->user_status_format);
249 if (run_dlg (dd) != B_CANCEL) {
250 result = display_radio->sel;
251 *userp = g_strdup (display_user_format->buffer);
252 *minip = g_strdup (display_mini_status->buffer);
253 *use_msformat = display_check_status->state & C_BOOL;
256 if (section != NULL) {
257 g_free (panel->user_format);
258 for (i = 0; i < LIST_TYPES; i++)
259 g_free (panel->user_status_format [i]);
260 g_free (panel);
263 destroy_dlg (dd);
265 return result;
268 const panel_field_t *
269 sort_box (const panel_field_t *sort_format, int *reverse, int *case_sensitive, int *exec_first)
271 int dlg_width = 40, dlg_height = 15;
273 const char **sort_orders_names;
274 gsize sort_names_num;
276 int sort_idx = 0;
278 const panel_field_t *result = sort_format;
281 int max_radio = 0, max_check = 0;
282 int ok_len, cancel_len;
283 gsize i;
285 QuickWidget quick_widgets[] =
287 /* 0 */
288 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
289 /* 1 */
290 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
291 /* 2 */
292 QUICK_CHECKBOX (0, dlg_width, 5, dlg_height, N_("&Reverse"), reverse),
293 /* 3 */
294 QUICK_CHECKBOX (0, dlg_width, 4, dlg_height, N_("Case sensi&tive"), case_sensitive),
295 /* 4 */
296 QUICK_CHECKBOX (0, dlg_width, 3, dlg_height, N_("Executable &first"), exec_first),
297 /* 5 */
298 QUICK_RADIO (4, dlg_width, 3, dlg_height, 0,
299 NULL, &sort_idx),
300 QUICK_END
303 QuickDialog quick_dlg =
305 dlg_width, dlg_height, -1, -1,
306 N_("Sort order"), "[Sort Order...]",
307 quick_widgets, TRUE
310 sort_orders_names = panel_get_sortable_fields(&sort_names_num);
311 quick_widgets[5].u.radio.items = sort_orders_names;
312 quick_widgets[5].u.radio.count = sort_names_num;
314 for (i = 0; i < sort_names_num; i++)
315 if (strcmp (sort_orders_names[i], _(sort_format->title_hotkey)) == 0 ) {
316 sort_idx = i;
317 break;
320 #ifdef ENABLE_NLS
321 quick_dlg.title = _(quick_dlg.title);
322 /* buttons */
323 for (i = 0; i < 2; i++)
324 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
325 /* checkboxes */
326 for (i = 2; i < 5; i++)
327 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
328 #endif /* ENABLE_NlS */
330 /* buttons */
331 cancel_len = str_term_width1 (quick_widgets[0].u.button.text) + 4;
332 ok_len = str_term_width1 (quick_widgets[1].u.button.text) + 6;
333 /* checkboxes */
334 for (i = 2; i < 5; i++)
335 max_check = max (max_check, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
336 /* radiobuttons */
337 for (i = 0; i < sort_names_num; i++)
338 max_radio = max (max_radio, str_term_width1 (sort_orders_names[i]) + 4);
340 /* dialog width */
341 dlg_width = max (dlg_width, str_term_width1 (quick_dlg.title) + 8);
342 dlg_width = max (dlg_width, ok_len + cancel_len + 8);
343 dlg_width = max (dlg_width, 2 * max (max_radio, max_check) + 8);
345 /* fix widget and dialog parameters */
346 /* dialog */
347 quick_dlg.xlen = dlg_width;
348 /* widgets */
349 for (i = 0; (size_t) i < sizeof (quick_widgets)/sizeof (quick_widgets[0]) - 1; i++)
350 quick_widgets[i].x_divisions = dlg_width;
351 /* buttons */
352 quick_widgets[0].relative_x = dlg_width * 2/3 - cancel_len/2;
353 quick_widgets[1].relative_x = dlg_width/3 - ok_len/2;
354 /* checkboxes */
355 for (i = 2; i < 5; i++)
356 quick_widgets[i].relative_x = dlg_width/2 + 2;
358 if (quick_dialog (&quick_dlg) != B_CANCEL)
359 result = panel_get_field_by_title_hotkey(sort_orders_names[sort_idx]);
361 if (result == NULL)
362 result = sort_format;
364 g_strfreev((gchar **)sort_orders_names);
365 return result;
369 void
370 confirm_box (void)
372 const char *title = _("Confirmation");
374 QuickWidget conf_widgets [] =
376 /* 0 */ QUICK_BUTTON (29, 46, 10, 13, N_("&Cancel"), B_CANCEL, NULL),
377 /* 1 */ QUICK_BUTTON (12, 46, 10, 13, N_("&OK"), B_ENTER, NULL),
378 /* TRANSLATORS: no need to translate 'Confirmation', it's just a context prefix */
379 /* 2 */ QUICK_CHECKBOX (3, 46, 8, 13, N_("Confirmation|&History cleanup"), &confirm_history_cleanup),
380 /* 3 */ QUICK_CHECKBOX (3, 46, 7, 13, N_("Confirmation|&Directory hotlist delete"), &confirm_directory_hotlist_delete),
381 /* 4 */ QUICK_CHECKBOX (3, 46, 6, 13, N_("Confirmation|E&xit"), &confirm_exit),
382 /* 5 */ QUICK_CHECKBOX (3, 46, 5, 13, N_("Confirmation|&Execute"), &confirm_execute),
383 /* 6 */ QUICK_CHECKBOX (3, 46, 4, 13, N_("Confirmation|O&verwrite"), &confirm_overwrite),
384 /* 7 */ QUICK_CHECKBOX (3, 46, 3, 13, N_("Confirmation|&Delete"), &confirm_delete),
385 QUICK_END
388 const size_t w_num = sizeof (conf_widgets) / sizeof (conf_widgets[0]) - 1;
390 /* dialog sizes */
391 int dlg_width = 46;
392 int dlg_height = w_num + 5;
394 size_t i;
395 int maxlen = 0;
396 int cancel_len, ok_len, blen;
398 #ifdef ENABLE_NLS
399 title = _(title);
401 for (i = 0; i < 2; i++)
402 conf_widgets [i].u.button.text = _(conf_widgets [i].u.button.text);
404 for (i = 2; i < w_num; i++)
405 conf_widgets [i].u.checkbox.text = Q_(conf_widgets [i].u.checkbox.text);
406 #endif /* ENABLE_NLS */
408 /* maximumr length of checkboxes */
409 for (i = 2; i < w_num; i++)
410 maxlen = max (maxlen, str_term_width1 (conf_widgets [i].u.checkbox.text) + 4);
412 /* length of buttons */
413 cancel_len = str_term_width1 (conf_widgets [0].u.button.text) + 3;
414 ok_len = str_term_width1 (conf_widgets [1].u.button.text) + 5; /* default button */
416 blen = cancel_len + ok_len + 2;
418 dlg_width = max (maxlen, blen) + 6;
419 dlg_width = max (dlg_width, str_term_width1 (title) + 4);
421 /* correct widget parameters */
422 for (i = 0; i < w_num; i++) {
423 conf_widgets[i].x_divisions = dlg_width;
424 conf_widgets[i].y_divisions = dlg_height;
427 conf_widgets[1].relative_x = dlg_width/2 - blen/2;
428 conf_widgets[0].relative_x = conf_widgets[1].relative_x + ok_len + 2;
431 QuickDialog confirmation =
433 dlg_width, dlg_height, -1, -1, title,
434 "[Confirmation]", conf_widgets, 1
437 (void) quick_dialog (&confirmation);
442 #ifndef HAVE_CHARSET
443 void
444 display_bits_box (void) /* AB:FIXME: test dialog */
446 /* dialog sizes */
447 const int DISPY = 13;
448 const int DISPX = 46;
450 int new_meta = 0;
451 int current_mode;
453 const char *display_bits_str [] =
455 N_("UTF-8 output"),
456 N_("Full 8 bits output"),
457 N_("ISO 8859-1"),
458 N_("7 bits")
461 QuickWidget display_widgets[] =
463 /* 0 */ QUICK_BUTTON (15, DISPX, DISPY - 3, DISPY, N_("&Cancel"), B_CANCEL, NULL),
464 /* 1 */ QUICK_BUTTON (29, DISPX, DISPY - 3, DISPY, N_("&OK"), B_ENTER, NULL),
465 /* 2 */ QUICK_CHECKBOX (3, DISPX, 8, DISPY, N_("F&ull 8 bits input"), &new_meta),
466 /* 3 */ QUICK_RADIO (3, DISPX, 3, DISPY, 4, display_bits_str, &current_mode),
467 QUICK_END
470 QuickDialog display_bits =
472 DISPX, DISPY, -1, -1, _(" Display bits "),
473 "[Display bits]", display_widgets, TRUE
476 int i;
477 int l1, maxlen = 0;
478 int ok_len, cancel_len;
480 #ifdef ENABLE_NLS
481 static gboolean i18n_flag = FALSE;
483 if (!i18n_flag) {
484 for (i = 0; i < 3; i++) {
485 display_bits_str[i] = _(display_bits_str [i]);
488 display_widgets[0].u.button.text = _(display_widgets[0].u.button.text);
489 display_widgets[1].u.button.text = _(display_widgets[1].u.button.text);
490 display_widgets[2].u.checkbox.text = _(display_widgets[2].u.checkbox.text);
492 i18n_flag = TRUE;
494 #endif /* ENABLE_NLS */
496 /* radiobuttons */
497 for (i = 0; i < 3; i++)
498 maxlen = max (maxlen, str_term_width1 (display_bits_str [i]));
500 /* buttons */
501 cancel_len = str_term_width1 (display_widgets [0].u.button.text) + 2;
502 ok_len = str_term_width1 (display_widgets [1].u.button.text) + 4; /* default button */
504 l1 = max (cancel_len, ok_len);
506 display_bits.xlen = max (maxlen, l1) + 20;
508 for (i = 0; i < 4; i++)
509 display_widgets[i].x_divisions = display_bits.xlen;
511 display_widgets[0].relative_x = display_bits.xlen * 2/3 - cancel_len/2;
512 display_widgets[1].relative_x = display_bits.xlen/3 - ok_len/2;
514 if (full_eight_bits)
515 current_mode = 0;
516 else if (eight_bit_clean)
517 current_mode = 1;
518 else
519 current_mode = 2;
521 new_meta = !use_8th_bit_as_meta;
523 if (quick_dialog (&display_bits) != B_CANCEL) {
524 eight_bit_clean = current_mode < 3;
525 full_eight_bits = current_mode < 2;
526 #ifndef HAVE_SLANG
527 meta (stdscr, eight_bit_clean);
528 #else
529 SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
530 #endif
531 use_8th_bit_as_meta = !new_meta;
535 #else /* HAVE_CHARSET */
537 static int new_display_codepage;
539 static WLabel *cplabel;
540 static WCheck *inpcheck;
542 static int
543 sel_charset_button (int action)
545 int new_dcp;
547 (void) action;
549 new_dcp = select_charset (-1, -1, new_display_codepage, TRUE);
551 if (new_dcp != SELECT_CHARSET_CANCEL) {
552 const char *cpname;
553 char buf[BUF_TINY];
555 new_display_codepage = new_dcp;
556 cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
557 _("Other 8 bit") : codepages[new_display_codepage].name;
558 if (cpname != NULL)
559 utf8_display = str_isutf8 (cpname);
560 /* avoid strange bug with label repainting */
561 g_snprintf (buf, sizeof (buf), "%-27s", cpname);
562 label_set_text (cplabel, buf);
565 return 0;
568 static Dlg_head *
569 init_disp_bits_box (void)
571 /* dialog sizes */
572 const int DISPY = 11;
573 const int DISPX = 46;
575 const char *cpname;
576 Dlg_head *dbits_dlg;
578 do_refresh ();
580 dbits_dlg =
581 create_dlg (0, 0, DISPY, DISPX, dialog_colors, NULL,
582 "[Display bits]", _(" Display bits "), DLG_CENTER | DLG_REVERSE);
584 add_widget (dbits_dlg,
585 label_new (3, 4, _("Input / display codepage:")));
587 cpname = (new_display_codepage < 0)
588 ? _("Other 8 bit")
589 : codepages[new_display_codepage].name;
590 cplabel = label_new (4, 4, cpname);
591 add_widget (dbits_dlg, cplabel);
593 add_widget (dbits_dlg,
594 button_new (DISPY - 3, DISPX / 2 + 3, B_CANCEL,
595 NORMAL_BUTTON, _("&Cancel"), 0));
596 add_widget (dbits_dlg,
597 button_new (DISPY - 3, 7, B_ENTER, NORMAL_BUTTON, _("&OK"),
598 0));
600 inpcheck =
601 check_new (6, 4, !use_8th_bit_as_meta, _("F&ull 8 bits input"));
602 add_widget (dbits_dlg, inpcheck);
604 cpname = _("&Select");
605 add_widget (dbits_dlg,
606 button_new (4, DISPX - 7 - str_term_width1 (cpname), B_USER,
607 NORMAL_BUTTON, cpname, sel_charset_button));
609 return dbits_dlg;
612 void
613 display_bits_box (void)
615 Dlg_head *dbits_dlg;
616 new_display_codepage = display_codepage;
618 application_keypad_mode ();
619 dbits_dlg = init_disp_bits_box ();
621 run_dlg (dbits_dlg);
623 if (dbits_dlg->ret_value == B_ENTER) {
624 const char *errmsg;
625 display_codepage = new_display_codepage;
626 errmsg =
627 init_translation_table (source_codepage, display_codepage);
628 if (errmsg)
629 message (D_ERROR, MSG_ERROR, "%s", errmsg);
630 #ifdef HAVE_SLANG
631 tty_display_8bit (display_codepage != 0 && display_codepage != 1);
632 #else
633 tty_display_8bit (display_codepage != 0);
634 #endif
635 use_8th_bit_as_meta = !(inpcheck->state & C_BOOL);
637 destroy_dlg (dbits_dlg);
638 repaint_screen ();
641 #endif /* HAVE_CHARSET */
643 static cb_ret_t
644 tree_callback (Dlg_head *h, Widget *sender,
645 dlg_msg_t msg, int parm, void *data)
647 switch (msg) {
648 case DLG_POST_KEY:
649 /* The enter key will be processed by the tree widget */
650 if (parm == '\n') {
651 h->ret_value = B_ENTER;
652 dlg_stop (h);
654 return MSG_HANDLED;
656 case DLG_ACTION:
657 /* command from buttonbar */
658 return send_message ((Widget *) find_tree (h), WIDGET_COMMAND, parm);
660 default:
661 return default_dlg_callback (h, sender, msg, parm, data);
665 /* Show tree in a box, not on a panel */
666 char *
667 tree_box (const char *current_dir)
669 WTree *mytree;
670 Dlg_head *dlg;
671 char *val = NULL;
672 WButtonBar *bar;
674 (void) current_dir;
676 /* Create the components */
677 dlg = create_dlg (0, 0, LINES - 9, COLS - 20, dialog_colors,
678 tree_callback, "[Directory Tree]",
679 NULL, DLG_CENTER | DLG_REVERSE);
681 mytree = tree_new (0, 2, 2, dlg->lines - 6, dlg->cols - 5);
682 add_widget (dlg, mytree);
683 bar = buttonbar_new (TRUE);
684 add_widget (dlg, bar);
685 /* restore ButtonBar coordinates after add_widget() */
686 ((Widget *) bar)->x = 0;
687 ((Widget *) bar)->y = LINES - 1;
689 if (run_dlg (dlg) == B_ENTER)
690 val = g_strdup (tree_selected_name (mytree));
692 destroy_dlg (dlg);
693 return val;
696 #ifdef ENABLE_VFS
698 static char *ret_timeout;
700 #ifdef USE_NETCODE
701 static char *ret_passwd;
702 static char *ret_directory_timeout;
703 static char *ret_ftp_proxy;
704 #endif
706 void
707 configure_vfs (void)
709 #define VFSX 56
711 #ifdef USE_NETCODE
712 #define VFSY 17
713 #else
714 #define VFSY 8
715 #endif
717 char buffer2 [BUF_TINY];
718 #ifdef USE_NETCODE
719 char buffer3 [BUF_TINY];
720 #endif
722 QuickWidget confvfs_widgets [] =
724 /* 0 */ QUICK_BUTTON (30, VFSX, VFSY - 3, VFSY, N_("&Cancel"), B_CANCEL, NULL),
725 /* 1 */ QUICK_BUTTON (12, VFSX, VFSY - 3, VFSY, N_("&OK"), B_ENTER, NULL),
726 #ifdef USE_NETCODE
727 /* 2 */ QUICK_CHECKBOX (4, VFSX, 12, VFSY, N_("Use passive mode over pro&xy"), &ftpfs_use_passive_connections_over_proxy),
728 /* 3 */ QUICK_CHECKBOX (4, VFSX, 11, VFSY, N_("Use &passive mode"), &ftpfs_use_passive_connections),
729 /* 4 */ QUICK_CHECKBOX (4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), &use_netrc),
730 /* 5 */ QUICK_INPUT (4, VFSX, 9, VFSY, ftpfs_proxy_host, 48, 0, "input-ftp-proxy", &ret_ftp_proxy),
731 /* 6 */ QUICK_CHECKBOX (4, VFSX, 8, VFSY, N_("&Always use ftp proxy"), &ftpfs_always_use_proxy),
732 /* 7 */ QUICK_LABEL (49, VFSX, 7, VFSY, N_("sec")),
733 /* 8 */ QUICK_INPUT (38, VFSX, 7, VFSY, buffer3, 10, 0, "input-timeout", &ret_directory_timeout),
734 /* 9 */ QUICK_LABEL (4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:")),
735 /* 10 */ QUICK_INPUT (4, VFSX, 6, VFSY, ftpfs_anonymous_passwd, 48, 0, "input-passwd", &ret_passwd),
736 /* 11 */ QUICK_LABEL (4, VFSX, 5, VFSY, N_("ftp anonymous password:")),
737 #endif
738 /* 12 */ QUICK_LABEL (49, VFSX, 3, VFSY, N_("sec")),
739 /* 13 */ QUICK_INPUT (38, VFSX, 3, VFSY, buffer2, 10, 0, "input-timo-vfs", &ret_timeout),
740 /* 14 */ QUICK_LABEL (4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:")),
741 QUICK_END
744 QuickDialog confvfs_dlg =
746 VFSX, VFSY, -1, -1, N_(" Virtual File System Setting "),
747 "[Virtual FS]", confvfs_widgets, FALSE
750 #ifdef USE_NETCODE
751 g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
752 #endif
753 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
755 if (quick_dialog (&confvfs_dlg) != B_CANCEL) {
756 vfs_timeout = atoi (ret_timeout);
757 g_free (ret_timeout);
759 if (vfs_timeout < 0 || vfs_timeout > 10000)
760 vfs_timeout = 10;
761 #ifdef USE_NETCODE
762 g_free (ftpfs_anonymous_passwd);
763 ftpfs_anonymous_passwd = ret_passwd;
764 g_free (ftpfs_proxy_host);
765 ftpfs_proxy_host = ret_ftp_proxy;
766 ftpfs_directory_timeout = atoi(ret_directory_timeout);
767 g_free (ret_directory_timeout);
768 #endif
771 #undef VFSX
772 #undef VFSY
775 #endif /* ENABLE_VFS */
777 char *
778 cd_dialog (void)
780 const char *label = N_("cd");
781 const int ylen = 5;
782 const int xlen = 57;
784 int len;
786 #ifdef ENABLE_NLS
787 label = _(label);
788 #endif
790 len = str_term_width1 (label);
793 char *my_str;
795 QuickWidget quick_widgets [] =
797 /* 0 */ QUICK_INPUT (4 + len, xlen, 2, ylen, "", xlen - 7 - len, 2, "input" , &my_str),
798 /* 1 */ QUICK_LABEL (3, xlen, 2, ylen, label),
799 QUICK_END
802 QuickDialog Quick_input =
804 xlen, ylen, 2, LINES - 2 - ylen, _("Quick cd"),
805 "[Quick cd]", quick_widgets, TRUE
808 return (quick_dialog (&Quick_input) != B_CANCEL) ? my_str : NULL;
812 void
813 symlink_dialog (const char *existing, const char *new, char **ret_existing,
814 char **ret_new)
816 QuickWidget quick_widgets[] =
818 /* 0 */ QUICK_BUTTON (50, 80, 6, 8, N_("&Cancel"), B_CANCEL, NULL),
819 /* 1 */ QUICK_BUTTON (16, 80, 6, 8, N_("&OK"), B_ENTER, NULL),
820 /* 2 */ QUICK_INPUT (4, 80, 5, 8, new, 58, 0, "input-1", ret_new),
821 /* 3 */ QUICK_LABEL (4, 80, 4, 8, N_("Symbolic link filename:")),
822 /* 4 */ QUICK_INPUT (4, 80, 3, 8, existing, 58, 0, "input-2", ret_existing),
823 /* 5 */ QUICK_LABEL (4, 80, 2, 8, N_("Existing filename (filename symlink will point to):")),
824 QUICK_END
827 QuickDialog Quick_input =
829 64, 12, -1, -1, N_("Symbolic link"),
830 "[File Menu]", quick_widgets, FALSE
833 if (quick_dialog (&Quick_input) == B_CANCEL) {
834 *ret_new = NULL;
835 *ret_existing = NULL;
839 #ifdef WITH_BACKGROUND
840 #define B_STOP (B_USER+1)
841 #define B_RESUME (B_USER+2)
842 #define B_KILL (B_USER+3)
844 static int JOBS_X = 60;
845 #define JOBS_Y 15
846 static WListbox *bg_list;
847 static Dlg_head *jobs_dlg;
849 static void
850 jobs_fill_listbox (void)
852 static const char *state_str [2];
853 TaskList *tl = task_list;
855 if (!state_str [0]){
856 state_str [0] = _("Running ");
857 state_str [1] = _("Stopped");
860 while (tl){
861 char *s;
863 s = g_strconcat (state_str [tl->state], " ", tl->info, (char *) NULL);
864 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
865 g_free (s);
866 tl = tl->next;
870 static int
871 task_cb (int action)
873 TaskList *tl;
874 int sig = 0;
876 if (!bg_list->list)
877 return 0;
879 /* Get this instance information */
880 listbox_get_current (bg_list, NULL, (void **) &tl);
882 # ifdef SIGTSTP
883 if (action == B_STOP){
884 sig = SIGSTOP;
885 tl->state = Task_Stopped;
886 } else if (action == B_RESUME){
887 sig = SIGCONT;
888 tl->state = Task_Running;
889 } else
890 # endif
891 if (action == B_KILL){
892 sig = SIGKILL;
895 if (sig == SIGKILL)
896 unregister_task_running (tl->pid, tl->fd);
898 kill (tl->pid, sig);
899 listbox_remove_list (bg_list);
900 jobs_fill_listbox ();
902 /* This can be optimized to just redraw this widget :-) */
903 dlg_redraw (jobs_dlg);
905 return 0;
908 static struct
910 const char* name;
911 int xpos;
912 int value;
913 int (*callback)(int);
915 job_buttons [] =
917 {N_("&Stop"), 3, B_STOP, task_cb},
918 {N_("&Resume"), 12, B_RESUME, task_cb},
919 {N_("&Kill"), 23, B_KILL, task_cb},
920 {N_("&OK"), 35, B_CANCEL, NULL }
923 void
924 jobs_cmd (void)
926 register int i;
927 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
929 #ifdef ENABLE_NLS
930 static int i18n_flag = 0;
931 if (!i18n_flag)
933 int startx = job_buttons [0].xpos;
934 int len;
936 for (i = 0; i < n_buttons; i++)
938 job_buttons [i].name = _(job_buttons [i].name);
940 len = str_term_width1 (job_buttons [i].name) + 4;
941 JOBS_X = max (JOBS_X, startx + len + 3);
943 job_buttons [i].xpos = startx;
944 startx += len;
947 /* Last button - Ok a.k.a. Cancel :) */
948 job_buttons [n_buttons - 1].xpos =
949 JOBS_X - str_term_width1 (job_buttons [n_buttons - 1].name) - 7;
951 i18n_flag = 1;
953 #endif /* ENABLE_NLS */
955 jobs_dlg = create_dlg (0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL,
956 "[Background jobs]", _("Background Jobs"),
957 DLG_CENTER | DLG_REVERSE);
959 bg_list = listbox_new (2, 3, JOBS_Y - 9, JOBS_X - 7, FALSE, NULL);
960 add_widget (jobs_dlg, bg_list);
962 i = n_buttons;
963 while (i--)
965 add_widget (jobs_dlg, button_new (JOBS_Y-4,
966 job_buttons [i].xpos, job_buttons [i].value,
967 NORMAL_BUTTON, job_buttons [i].name,
968 job_buttons [i].callback));
971 /* Insert all of task information in the list */
972 jobs_fill_listbox ();
973 run_dlg (jobs_dlg);
975 destroy_dlg (jobs_dlg);
977 #endif /* WITH_BACKGROUND */
979 #ifdef ENABLE_VFS_SMB
980 struct smb_authinfo *
981 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
982 const char *user)
984 static int dialog_x = 44;
985 enum { b0 = 3, dialog_y = 12};
986 struct smb_authinfo *return_value;
987 static const char* lc_labs[] = {N_("Domain:"), N_("Username:"), N_("Password:")};
988 static const char* buts[] = {N_("&OK"), N_("&Cancel")};
989 static int ilen = 30, istart = 14;
990 static int b2 = 30;
991 char *title;
992 WInput *in_password;
993 WInput *in_user;
994 WInput *in_domain;
995 Dlg_head *auth_dlg;
997 #ifdef ENABLE_NLS
998 static int i18n_flag = 0;
1000 if (!i18n_flag)
1002 register int i = sizeof(lc_labs)/sizeof(lc_labs[0]);
1003 int l1, maxlen = 0;
1005 while (i--)
1007 l1 = str_term_width1 (lc_labs [i] = _(lc_labs [i]));
1008 if (l1 > maxlen)
1009 maxlen = l1;
1011 i = maxlen + ilen + 7;
1012 if (i > dialog_x)
1013 dialog_x = i;
1015 for (i = sizeof(buts)/sizeof(buts[0]), l1 = 0; i--; )
1017 l1 += str_term_width1 (buts [i] = _(buts [i]));
1019 l1 += 15;
1020 if (l1 > dialog_x)
1021 dialog_x = l1;
1023 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1024 istart = dialog_x - 3 - ilen;
1026 b2 = dialog_x - (str_term_width1 (buts[1]) + 6);
1028 i18n_flag = 1;
1031 #endif /* ENABLE_NLS */
1033 if (!domain)
1034 domain = "";
1035 if (!user)
1036 user = "";
1038 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1040 auth_dlg = create_dlg (0, 0, dialog_y, dialog_x, dialog_colors, NULL,
1041 "[Smb Authinfo]", title, DLG_CENTER | DLG_REVERSE);
1043 g_free (title);
1045 in_user = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name", INPUT_COMPLETE_DEFAULT);
1046 add_widget (auth_dlg, in_user);
1048 in_domain = input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain", INPUT_COMPLETE_DEFAULT);
1049 add_widget (auth_dlg, in_domain);
1050 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON,
1051 buts[1], 0));
1052 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON,
1053 buts[0], 0));
1055 in_password = input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password", INPUT_COMPLETE_DEFAULT);
1056 in_password->completion_flags = 0;
1057 in_password->is_password = 1;
1058 add_widget (auth_dlg, in_password);
1060 add_widget (auth_dlg, label_new (7, 3, lc_labs[2]));
1061 add_widget (auth_dlg, label_new (5, 3, lc_labs[1]));
1062 add_widget (auth_dlg, label_new (3, 3, lc_labs[0]));
1064 run_dlg (auth_dlg);
1066 switch (auth_dlg->ret_value) {
1067 case B_CANCEL:
1068 return_value = 0;
1069 break;
1070 default:
1071 return_value = g_try_new (struct smb_authinfo, 1);
1072 if (return_value) {
1073 return_value->host = g_strdup (host);
1074 return_value->share = g_strdup (share);
1075 return_value->domain = g_strdup (in_domain->buffer);
1076 return_value->user = g_strdup (in_user->buffer);
1077 return_value->password = g_strdup (in_password->buffer);
1081 destroy_dlg (auth_dlg);
1083 return return_value;
1085 #endif /* ENABLE_VFS_SMB */