Updated Russian translation.
[midnight-commander.git] / src / boxes.c
blob7a9bfc2d5fdee0b28276f820924c34f5964ebbe3
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 ENABLE_VFS
46 #include "lib/vfs/mc-vfs/vfs.h" /* vfs_timeout */
47 #include "lib/vfs/mc-vfs/vfs-impl.h"
48 #endif
50 #ifdef USE_NETCODE
51 # include "lib/vfs/mc-vfs/ftpfs.h"
52 #endif
54 #include "dialog.h" /* The nice dialog manager */
55 #include "widget.h" /* The widgets for the nice dialog manager */
56 #include "wtools.h"
57 #include "setup.h" /* For profile_name */
58 #include "command.h" /* For cmdline */
59 #include "dir.h"
60 #include "panel.h" /* LIST_TYPES */
61 #include "boxes.h"
62 #include "main.h" /* For the confirm_* variables */
63 #include "tree.h"
64 #include "layout.h" /* for get_nth_panel_name proto */
65 #include "background.h" /* task_list */
67 #ifdef HAVE_CHARSET
68 #include "charsets.h"
69 #include "selcodepage.h"
70 #endif
73 static WRadio *display_radio;
74 static WInput *display_user_format;
75 static WInput *display_mini_status;
76 static WCheck *display_check_status;
77 static char **displays_status;
78 static int display_user_hotkey = 'u';
80 static cb_ret_t
81 display_callback (Dlg_head *h, Widget *sender,
82 dlg_msg_t msg, int parm, void *data)
84 switch (msg) {
85 case DLG_UNFOCUS:
86 if (dlg_widget_active (display_radio)) {
87 assign_text (display_mini_status, displays_status[display_radio->sel]);
88 input_set_point (display_mini_status, 0);
90 return MSG_HANDLED;
92 case DLG_KEY:
93 if (parm == '\n') {
94 if (dlg_widget_active (display_radio)) {
95 assign_text (display_mini_status, displays_status[display_radio->sel]);
96 dlg_stop (h);
97 return MSG_HANDLED;
100 if (dlg_widget_active (display_user_format)) {
101 h->ret_value = B_USER + 6;
102 dlg_stop (h);
103 return MSG_HANDLED;
106 if (dlg_widget_active (display_mini_status)) {
107 h->ret_value = B_USER + 7;
108 dlg_stop (h);
109 return MSG_HANDLED;
113 if (g_ascii_tolower (parm) == display_user_hotkey && dlg_widget_active (display_user_format)
114 && dlg_widget_active (display_mini_status)) {
115 display_radio->sel = 3;
116 dlg_select_widget (display_radio); /* force redraw */
117 dlg_select_widget (display_user_format);
118 return MSG_HANDLED;
120 return MSG_NOT_HANDLED;
122 default:
123 return default_dlg_callback (h, sender, msg, parm, data);
127 static Dlg_head *
128 display_init (int radio_sel, char *init_text, int _check_status,
129 char **_status)
131 int dlg_width = 48, dlg_height = 15;
132 Dlg_head *dd;
134 /* Controls whether the array strings have been translated */
135 const char *displays [LIST_TYPES] =
137 N_("&Full file list"),
138 N_("&Brief file list"),
139 N_("&Long file list"),
140 N_("&User defined:")
143 /* Index in displays[] for "user defined" */
144 const int user_type_idx = 3;
146 const char *display_title = N_("Listing mode");
147 const char *user_mini_status = N_("user &Mini status");
148 const char *ok_name = N_("&OK");
149 const char *cancel_name = N_("&Cancel");
151 WButton *ok_button, *cancel_button;
154 int i, maxlen = 0;
155 const char *cp;
156 int ok_len, cancel_len;
158 #ifdef ENABLE_NLS
159 display_title = _(display_title);
160 user_mini_status = _(user_mini_status);
161 ok_name = _(ok_name);
162 cancel_name = _(cancel_name);
164 for (i = 0; i < LIST_TYPES; i++)
165 displays[i] = _(displays[i]);
166 #endif
168 /* get hotkey of user-defined format string */
169 cp = strchr (displays[user_type_idx], '&');
170 if (cp != NULL && *++cp != '\0')
171 display_user_hotkey = g_ascii_tolower (*cp);
173 /* xpos will be fixed later */
174 ok_button = button_new (dlg_height - 3, 0, B_ENTER, DEFPUSH_BUTTON, ok_name, 0);
175 ok_len = button_get_len (ok_button);
176 cancel_button = button_new (dlg_height - 3, 0, B_CANCEL, NORMAL_BUTTON, cancel_name, 0);
177 cancel_len = button_get_len (cancel_button);
179 dlg_width = max (dlg_width, str_term_width1 (display_title) + 10);
180 /* calculate max width of radiobutons */
181 for (i = 0; i < LIST_TYPES; i++)
182 maxlen = max (maxlen, str_term_width1 (displays[i]));
183 dlg_width = max (dlg_width, maxlen);
184 dlg_width = max (dlg_width, str_term_width1 (user_mini_status) + 13);
186 /* buttons */
187 dlg_width = max (dlg_width, ok_len + cancel_len + 8);
188 ok_button->widget.x = dlg_width/3 - ok_len/2;
189 cancel_button->widget.x = dlg_width * 2/3 - cancel_len/2;
192 displays_status = _status;
194 dd = create_dlg (0, 0, dlg_height, dlg_width, dialog_colors,
195 display_callback, "[Listing Mode...]", display_title,
196 DLG_CENTER | DLG_REVERSE);
198 add_widget (dd, cancel_button);
199 add_widget (dd, ok_button);
201 display_mini_status = input_new (10, 8, INPUT_COLOR, dlg_width - 12, _status[radio_sel],
202 "mini-input", INPUT_COMPLETE_DEFAULT);
203 add_widget (dd, display_mini_status);
204 input_set_point (display_mini_status, 0);
206 display_check_status = check_new (9, 4, _check_status, user_mini_status);
207 add_widget (dd, display_check_status);
209 display_user_format = input_new (7, 8, INPUT_COLOR, dlg_width - 12, init_text,
210 "user-fmt-input", INPUT_COMPLETE_DEFAULT);
211 add_widget (dd, display_user_format);
212 input_set_point (display_user_format, 0);
214 display_radio = radio_new (3, 4, LIST_TYPES, displays);
215 display_radio->sel = display_radio->pos = radio_sel;
216 add_widget (dd, display_radio);
218 return dd;
221 /* return list type */
223 display_box (WPanel *panel, char **userp, char **minip, int *use_msformat, int num)
225 int result = -1;
226 Dlg_head *dd;
227 char *section = NULL;
228 size_t i;
230 if (panel == NULL) {
231 const char *p = get_nth_panel_name (num);
232 panel = g_new (WPanel, 1);
233 panel->list_type = list_full;
234 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
235 panel->user_mini_status = 0;
236 for (i = 0; i < LIST_TYPES; i++)
237 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
238 section = g_strconcat ("Temporal:", p, (char *) NULL);
239 if (! mc_config_has_group (mc_main_config, section)) {
240 g_free (section);
241 section = g_strdup (p);
243 panel_load_setup (panel, section);
244 g_free (section);
247 dd = display_init (panel->list_type, panel->user_format,
248 panel->user_mini_status, panel->user_status_format);
250 if (run_dlg (dd) != B_CANCEL) {
251 result = display_radio->sel;
252 *userp = g_strdup (display_user_format->buffer);
253 *minip = g_strdup (display_mini_status->buffer);
254 *use_msformat = display_check_status->state & C_BOOL;
257 if (section != NULL) {
258 g_free (panel->user_format);
259 for (i = 0; i < LIST_TYPES; i++)
260 g_free (panel->user_status_format [i]);
261 g_free (panel);
264 destroy_dlg (dd);
266 return result;
269 const panel_field_t *
270 sort_box (const panel_field_t *sort_format, int *reverse, int *case_sensitive, int *exec_first)
272 int dlg_width = 40, dlg_height = 7;
274 const char **sort_orders_names;
275 gsize sort_names_num;
277 int sort_idx = 0;
279 const panel_field_t *result = sort_format;
281 sort_orders_names = panel_get_sortable_fields(&sort_names_num);
282 dlg_height += sort_names_num;
285 int max_radio = 0, max_check = 0;
286 int ok_len, cancel_len;
287 gsize i;
289 QuickWidget quick_widgets[] =
291 /* 0 */
292 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
293 /* 1 */
294 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
295 /* 2 */
296 QUICK_CHECKBOX (0, dlg_width, 5, dlg_height, N_("&Reverse"), reverse),
297 /* 3 */
298 QUICK_CHECKBOX (0, dlg_width, 4, dlg_height, N_("Case sensi&tive"), case_sensitive),
299 /* 4 */
300 QUICK_CHECKBOX (0, dlg_width, 3, dlg_height, N_("Executable &first"), exec_first),
301 /* 5 */
302 QUICK_RADIO (4, dlg_width, 3, dlg_height, 0,
303 NULL, &sort_idx),
304 QUICK_END
307 QuickDialog quick_dlg =
309 dlg_width, dlg_height, -1, -1,
310 N_("Sort order"), "[Sort Order...]",
311 quick_widgets, TRUE
314 quick_widgets[5].u.radio.items = sort_orders_names;
315 quick_widgets[5].u.radio.count = sort_names_num;
317 for (i = 0; i < sort_names_num; i++)
318 if (strcmp (sort_orders_names[i], _(sort_format->title_hotkey)) == 0 ) {
319 sort_idx = i;
320 break;
323 #ifdef ENABLE_NLS
324 quick_dlg.title = _(quick_dlg.title);
325 /* buttons */
326 for (i = 0; i < 2; i++)
327 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
328 /* checkboxes */
329 for (i = 2; i < 5; i++)
330 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
331 #endif /* ENABLE_NlS */
333 /* buttons */
334 cancel_len = str_term_width1 (quick_widgets[0].u.button.text) + 4;
335 ok_len = str_term_width1 (quick_widgets[1].u.button.text) + 6;
336 /* checkboxes */
337 for (i = 2; i < 5; i++)
338 max_check = max (max_check, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
339 /* radiobuttons */
340 for (i = 0; i < sort_names_num; i++)
341 max_radio = max (max_radio, str_term_width1 (sort_orders_names[i]) + 4);
343 /* dialog width */
344 dlg_width = max (dlg_width, str_term_width1 (quick_dlg.title) + 8);
345 dlg_width = max (dlg_width, ok_len + cancel_len + 8);
346 dlg_width = max (dlg_width, 2 * max (max_radio, max_check) + 8);
348 /* fix widget and dialog parameters */
349 /* dialog */
350 quick_dlg.xlen = dlg_width;
351 /* widgets */
352 for (i = 0; (size_t) i < sizeof (quick_widgets)/sizeof (quick_widgets[0]) - 1; i++)
353 quick_widgets[i].x_divisions = dlg_width;
354 /* buttons */
355 quick_widgets[0].relative_x = dlg_width * 2/3 - cancel_len/2;
356 quick_widgets[1].relative_x = dlg_width/3 - ok_len/2;
357 /* checkboxes */
358 for (i = 2; i < 5; i++)
359 quick_widgets[i].relative_x = dlg_width/2 + 2;
361 if (quick_dialog (&quick_dlg) != B_CANCEL)
362 result = panel_get_field_by_title_hotkey(sort_orders_names[sort_idx]);
364 if (result == NULL)
365 result = sort_format;
367 g_strfreev((gchar **)sort_orders_names);
368 return result;
372 void
373 confirm_box (void)
375 const char *title = _("Confirmation");
377 QuickWidget conf_widgets [] =
379 /* 0 */ QUICK_BUTTON (29, 46, 10, 13, N_("&Cancel"), B_CANCEL, NULL),
380 /* 1 */ QUICK_BUTTON (12, 46, 10, 13, N_("&OK"), B_ENTER, NULL),
381 /* TRANSLATORS: no need to translate 'Confirmation', it's just a context prefix */
382 /* 2 */ QUICK_CHECKBOX (3, 46, 8, 13, N_("Confirmation|&History cleanup"), &confirm_history_cleanup),
383 /* 3 */ QUICK_CHECKBOX (3, 46, 7, 13, N_("Confirmation|&Directory hotlist delete"), &confirm_directory_hotlist_delete),
384 /* 4 */ QUICK_CHECKBOX (3, 46, 6, 13, N_("Confirmation|E&xit"), &confirm_exit),
385 /* 5 */ QUICK_CHECKBOX (3, 46, 5, 13, N_("Confirmation|&Execute"), &confirm_execute),
386 /* 6 */ QUICK_CHECKBOX (3, 46, 4, 13, N_("Confirmation|O&verwrite"), &confirm_overwrite),
387 /* 7 */ QUICK_CHECKBOX (3, 46, 3, 13, N_("Confirmation|&Delete"), &confirm_delete),
388 QUICK_END
391 const size_t w_num = sizeof (conf_widgets) / sizeof (conf_widgets[0]) - 1;
393 /* dialog sizes */
394 int dlg_width = 46;
395 int dlg_height = w_num + 5;
397 size_t i;
398 int maxlen = 0;
399 int cancel_len, ok_len, blen;
401 #ifdef ENABLE_NLS
402 title = _(title);
404 for (i = 0; i < 2; i++)
405 conf_widgets [i].u.button.text = _(conf_widgets [i].u.button.text);
407 for (i = 2; i < w_num; i++)
408 conf_widgets [i].u.checkbox.text = Q_(conf_widgets [i].u.checkbox.text);
409 #endif /* ENABLE_NLS */
411 /* maximumr length of checkboxes */
412 for (i = 2; i < w_num; i++)
413 maxlen = max (maxlen, str_term_width1 (conf_widgets [i].u.checkbox.text) + 4);
415 /* length of buttons */
416 cancel_len = str_term_width1 (conf_widgets [0].u.button.text) + 3;
417 ok_len = str_term_width1 (conf_widgets [1].u.button.text) + 5; /* default button */
419 blen = cancel_len + ok_len + 2;
421 dlg_width = max (maxlen, blen) + 6;
422 dlg_width = max (dlg_width, str_term_width1 (title) + 4);
424 /* correct widget parameters */
425 for (i = 0; i < w_num; i++) {
426 conf_widgets[i].x_divisions = dlg_width;
427 conf_widgets[i].y_divisions = dlg_height;
430 conf_widgets[1].relative_x = dlg_width/2 - blen/2;
431 conf_widgets[0].relative_x = conf_widgets[1].relative_x + ok_len + 2;
434 QuickDialog confirmation =
436 dlg_width, dlg_height, -1, -1, title,
437 "[Confirmation]", conf_widgets, 1
440 (void) quick_dialog (&confirmation);
445 #ifndef HAVE_CHARSET
446 void
447 display_bits_box (void) /* AB:FIXME: test dialog */
449 /* dialog sizes */
450 const int DISPY = 13;
451 const int DISPX = 46;
453 int new_meta = 0;
454 int current_mode;
456 const char *display_bits_str [] =
458 N_("UTF-8 output"),
459 N_("Full 8 bits output"),
460 N_("ISO 8859-1"),
461 N_("7 bits")
464 QuickWidget display_widgets[] =
466 /* 0 */ QUICK_BUTTON (15, DISPX, DISPY - 3, DISPY, N_("&Cancel"), B_CANCEL, NULL),
467 /* 1 */ QUICK_BUTTON (29, DISPX, DISPY - 3, DISPY, N_("&OK"), B_ENTER, NULL),
468 /* 2 */ QUICK_CHECKBOX (3, DISPX, 8, DISPY, N_("F&ull 8 bits input"), &new_meta),
469 /* 3 */ QUICK_RADIO (3, DISPX, 3, DISPY, 4, display_bits_str, &current_mode),
470 QUICK_END
473 QuickDialog display_bits =
475 DISPX, DISPY, -1, -1, _(" Display bits "),
476 "[Display bits]", display_widgets, TRUE
479 int i;
480 int l1, maxlen = 0;
481 int ok_len, cancel_len;
483 #ifdef ENABLE_NLS
484 static gboolean i18n_flag = FALSE;
486 if (!i18n_flag) {
487 for (i = 0; i < 3; i++) {
488 display_bits_str[i] = _(display_bits_str [i]);
491 display_widgets[0].u.button.text = _(display_widgets[0].u.button.text);
492 display_widgets[1].u.button.text = _(display_widgets[1].u.button.text);
493 display_widgets[2].u.checkbox.text = _(display_widgets[2].u.checkbox.text);
495 i18n_flag = TRUE;
497 #endif /* ENABLE_NLS */
499 /* radiobuttons */
500 for (i = 0; i < 3; i++)
501 maxlen = max (maxlen, str_term_width1 (display_bits_str [i]));
503 /* buttons */
504 cancel_len = str_term_width1 (display_widgets [0].u.button.text) + 2;
505 ok_len = str_term_width1 (display_widgets [1].u.button.text) + 4; /* default button */
507 l1 = max (cancel_len, ok_len);
509 display_bits.xlen = max (maxlen, l1) + 20;
511 for (i = 0; i < 4; i++)
512 display_widgets[i].x_divisions = display_bits.xlen;
514 display_widgets[0].relative_x = display_bits.xlen * 2/3 - cancel_len/2;
515 display_widgets[1].relative_x = display_bits.xlen/3 - ok_len/2;
517 if (full_eight_bits)
518 current_mode = 0;
519 else if (eight_bit_clean)
520 current_mode = 1;
521 else
522 current_mode = 2;
524 new_meta = !use_8th_bit_as_meta;
526 if (quick_dialog (&display_bits) != B_CANCEL) {
527 eight_bit_clean = current_mode < 3;
528 full_eight_bits = current_mode < 2;
529 #ifndef HAVE_SLANG
530 meta (stdscr, eight_bit_clean);
531 #else
532 SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
533 #endif
534 use_8th_bit_as_meta = !new_meta;
538 #else /* HAVE_CHARSET */
540 static int new_display_codepage;
542 static WLabel *cplabel;
543 static WCheck *inpcheck;
545 static int
546 sel_charset_button (int action)
548 int new_dcp;
550 (void) action;
552 new_dcp = select_charset (-1, -1, new_display_codepage, TRUE);
554 if (new_dcp != SELECT_CHARSET_CANCEL) {
555 const char *cpname;
556 char buf[BUF_TINY];
558 new_display_codepage = new_dcp;
559 cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
560 _("Other 8 bit") : codepages[new_display_codepage].name;
561 if (cpname != NULL)
562 utf8_display = str_isutf8 (cpname);
563 /* avoid strange bug with label repainting */
564 g_snprintf (buf, sizeof (buf), "%-27s", cpname);
565 label_set_text (cplabel, buf);
568 return 0;
571 static Dlg_head *
572 init_disp_bits_box (void)
574 /* dialog sizes */
575 const int DISPY = 11;
576 const int DISPX = 46;
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 - 7 - str_term_width1 (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 char *errmsg;
629 display_codepage = new_display_codepage;
630 errmsg = init_translation_table (source_codepage, display_codepage);
631 if (errmsg != NULL) {
632 message (D_ERROR, MSG_ERROR, "%s", errmsg);
633 g_free (errmsg);
635 #ifdef HAVE_SLANG
636 tty_display_8bit (display_codepage != 0 && display_codepage != 1);
637 #else
638 tty_display_8bit (display_codepage != 0);
639 #endif
640 use_8th_bit_as_meta = !(inpcheck->state & C_BOOL);
642 destroy_dlg (dbits_dlg);
643 repaint_screen ();
646 #endif /* HAVE_CHARSET */
648 static cb_ret_t
649 tree_callback (Dlg_head *h, Widget *sender,
650 dlg_msg_t msg, int parm, void *data)
652 switch (msg) {
653 case DLG_POST_KEY:
654 /* The enter key will be processed by the tree widget */
655 if (parm == '\n') {
656 h->ret_value = B_ENTER;
657 dlg_stop (h);
659 return MSG_HANDLED;
661 case DLG_ACTION:
662 /* command from buttonbar */
663 return send_message ((Widget *) find_tree (h), WIDGET_COMMAND, parm);
665 default:
666 return default_dlg_callback (h, sender, msg, parm, data);
670 /* Show tree in a box, not on a panel */
671 char *
672 tree_box (const char *current_dir)
674 WTree *mytree;
675 Dlg_head *dlg;
676 char *val = NULL;
677 WButtonBar *bar;
679 (void) current_dir;
681 /* Create the components */
682 dlg = create_dlg (0, 0, LINES - 9, COLS - 20, dialog_colors,
683 tree_callback, "[Directory Tree]",
684 NULL, DLG_CENTER | DLG_REVERSE);
686 mytree = tree_new (0, 2, 2, dlg->lines - 6, dlg->cols - 5);
687 add_widget (dlg, mytree);
688 bar = buttonbar_new (TRUE);
689 add_widget (dlg, bar);
690 /* restore ButtonBar coordinates after add_widget() */
691 ((Widget *) bar)->x = 0;
692 ((Widget *) bar)->y = LINES - 1;
694 if (run_dlg (dlg) == B_ENTER)
695 val = g_strdup (tree_selected_name (mytree));
697 destroy_dlg (dlg);
698 return val;
701 #ifdef ENABLE_VFS
703 static char *ret_timeout;
705 #ifdef USE_NETCODE
706 static char *ret_passwd;
707 static char *ret_directory_timeout;
708 static char *ret_ftp_proxy;
709 #endif
711 void
712 configure_vfs (void)
714 #define VFSX 56
716 #ifdef USE_NETCODE
717 #define VFSY 17
718 #else
719 #define VFSY 8
720 #endif
722 char buffer2 [BUF_TINY];
723 #ifdef USE_NETCODE
724 char buffer3 [BUF_TINY];
725 #endif
727 QuickWidget confvfs_widgets [] =
729 /* 0 */ QUICK_BUTTON (30, VFSX, VFSY - 3, VFSY, N_("&Cancel"), B_CANCEL, NULL),
730 /* 1 */ QUICK_BUTTON (12, VFSX, VFSY - 3, VFSY, N_("&OK"), B_ENTER, NULL),
731 #ifdef USE_NETCODE
732 /* 2 */ QUICK_CHECKBOX (4, VFSX, 12, VFSY, N_("Use passive mode over pro&xy"), &ftpfs_use_passive_connections_over_proxy),
733 /* 3 */ QUICK_CHECKBOX (4, VFSX, 11, VFSY, N_("Use &passive mode"), &ftpfs_use_passive_connections),
734 /* 4 */ QUICK_CHECKBOX (4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), &use_netrc),
735 /* 5 */ QUICK_INPUT (4, VFSX, 9, VFSY, ftpfs_proxy_host, 48, 0, "input-ftp-proxy", &ret_ftp_proxy),
736 /* 6 */ QUICK_CHECKBOX (4, VFSX, 8, VFSY, N_("&Always use ftp proxy"), &ftpfs_always_use_proxy),
737 /* 7 */ QUICK_LABEL (49, VFSX, 7, VFSY, N_("sec")),
738 /* 8 */ QUICK_INPUT (38, VFSX, 7, VFSY, buffer3, 10, 0, "input-timeout", &ret_directory_timeout),
739 /* 9 */ QUICK_LABEL (4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:")),
740 /* 10 */ QUICK_INPUT (4, VFSX, 6, VFSY, ftpfs_anonymous_passwd, 48, 0, "input-passwd", &ret_passwd),
741 /* 11 */ QUICK_LABEL (4, VFSX, 5, VFSY, N_("ftp anonymous password:")),
742 #endif
743 /* 12 */ QUICK_LABEL (49, VFSX, 3, VFSY, N_("sec")),
744 /* 13 */ QUICK_INPUT (38, VFSX, 3, VFSY, buffer2, 10, 0, "input-timo-vfs", &ret_timeout),
745 /* 14 */ QUICK_LABEL (4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:")),
746 QUICK_END
749 QuickDialog confvfs_dlg =
751 VFSX, VFSY, -1, -1, N_(" Virtual File System Setting "),
752 "[Virtual FS]", confvfs_widgets, FALSE
755 #ifdef USE_NETCODE
756 g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
757 #endif
758 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
760 if (quick_dialog (&confvfs_dlg) != B_CANCEL) {
761 vfs_timeout = atoi (ret_timeout);
762 g_free (ret_timeout);
764 if (vfs_timeout < 0 || vfs_timeout > 10000)
765 vfs_timeout = 10;
766 #ifdef USE_NETCODE
767 g_free (ftpfs_anonymous_passwd);
768 ftpfs_anonymous_passwd = ret_passwd;
769 g_free (ftpfs_proxy_host);
770 ftpfs_proxy_host = ret_ftp_proxy;
771 ftpfs_directory_timeout = atoi(ret_directory_timeout);
772 g_free (ret_directory_timeout);
773 #endif
776 #undef VFSX
777 #undef VFSY
780 #endif /* ENABLE_VFS */
782 char *
783 cd_dialog (void)
785 const char *label = N_("cd");
786 const int ylen = 5;
787 const int xlen = 57;
789 int len;
791 #ifdef ENABLE_NLS
792 label = _(label);
793 #endif
795 len = str_term_width1 (label);
798 char *my_str;
800 QuickWidget quick_widgets [] =
802 /* 0 */ QUICK_INPUT (4 + len, xlen, 2, ylen, "", xlen - 7 - len, 2, "input" , &my_str),
803 /* 1 */ QUICK_LABEL (3, xlen, 2, ylen, label),
804 QUICK_END
807 QuickDialog Quick_input =
809 xlen, ylen, 2, LINES - 2 - ylen, _("Quick cd"),
810 "[Quick cd]", quick_widgets, TRUE
813 return (quick_dialog (&Quick_input) != B_CANCEL) ? my_str : NULL;
817 void
818 symlink_dialog (const char *existing, const char *new, char **ret_existing,
819 char **ret_new)
821 QuickWidget quick_widgets[] =
823 /* 0 */ QUICK_BUTTON (50, 80, 6, 8, N_("&Cancel"), B_CANCEL, NULL),
824 /* 1 */ QUICK_BUTTON (16, 80, 6, 8, N_("&OK"), B_ENTER, NULL),
825 /* 2 */ QUICK_INPUT (4, 80, 5, 8, new, 58, 0, "input-1", ret_new),
826 /* 3 */ QUICK_LABEL (4, 80, 4, 8, N_("Symbolic link filename:")),
827 /* 4 */ QUICK_INPUT (4, 80, 3, 8, existing, 58, 0, "input-2", ret_existing),
828 /* 5 */ QUICK_LABEL (4, 80, 2, 8, N_("Existing filename (filename symlink will point to):")),
829 QUICK_END
832 QuickDialog Quick_input =
834 64, 12, -1, -1, N_("Symbolic link"),
835 "[File Menu]", quick_widgets, FALSE
838 if (quick_dialog (&Quick_input) == B_CANCEL) {
839 *ret_new = NULL;
840 *ret_existing = NULL;
844 #ifdef WITH_BACKGROUND
845 #define B_STOP (B_USER+1)
846 #define B_RESUME (B_USER+2)
847 #define B_KILL (B_USER+3)
849 static int JOBS_X = 60;
850 #define JOBS_Y 15
851 static WListbox *bg_list;
852 static Dlg_head *jobs_dlg;
854 static void
855 jobs_fill_listbox (void)
857 static const char *state_str [2];
858 TaskList *tl = task_list;
860 if (!state_str [0]){
861 state_str [0] = _("Running ");
862 state_str [1] = _("Stopped");
865 while (tl){
866 char *s;
868 s = g_strconcat (state_str [tl->state], " ", tl->info, (char *) NULL);
869 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
870 g_free (s);
871 tl = tl->next;
875 static int
876 task_cb (int action)
878 TaskList *tl;
879 int sig = 0;
881 if (!bg_list->list)
882 return 0;
884 /* Get this instance information */
885 listbox_get_current (bg_list, NULL, (void **) &tl);
887 # ifdef SIGTSTP
888 if (action == B_STOP){
889 sig = SIGSTOP;
890 tl->state = Task_Stopped;
891 } else if (action == B_RESUME){
892 sig = SIGCONT;
893 tl->state = Task_Running;
894 } else
895 # endif
896 if (action == B_KILL){
897 sig = SIGKILL;
900 if (sig == SIGKILL)
901 unregister_task_running (tl->pid, tl->fd);
903 kill (tl->pid, sig);
904 listbox_remove_list (bg_list);
905 jobs_fill_listbox ();
907 /* This can be optimized to just redraw this widget :-) */
908 dlg_redraw (jobs_dlg);
910 return 0;
913 static struct
915 const char* name;
916 int xpos;
917 int value;
918 int (*callback)(int);
920 job_buttons [] =
922 {N_("&Stop"), 3, B_STOP, task_cb},
923 {N_("&Resume"), 12, B_RESUME, task_cb},
924 {N_("&Kill"), 23, B_KILL, task_cb},
925 {N_("&OK"), 35, B_CANCEL, NULL }
928 void
929 jobs_cmd (void)
931 register int i;
932 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
934 #ifdef ENABLE_NLS
935 static int i18n_flag = 0;
936 if (!i18n_flag)
938 int startx = job_buttons [0].xpos;
939 int len;
941 for (i = 0; i < n_buttons; i++)
943 job_buttons [i].name = _(job_buttons [i].name);
945 len = str_term_width1 (job_buttons [i].name) + 4;
946 JOBS_X = max (JOBS_X, startx + len + 3);
948 job_buttons [i].xpos = startx;
949 startx += len;
952 /* Last button - Ok a.k.a. Cancel :) */
953 job_buttons [n_buttons - 1].xpos =
954 JOBS_X - str_term_width1 (job_buttons [n_buttons - 1].name) - 7;
956 i18n_flag = 1;
958 #endif /* ENABLE_NLS */
960 jobs_dlg = create_dlg (0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL,
961 "[Background jobs]", _("Background Jobs"),
962 DLG_CENTER | DLG_REVERSE);
964 bg_list = listbox_new (2, 3, JOBS_Y - 9, JOBS_X - 7, FALSE, NULL);
965 add_widget (jobs_dlg, bg_list);
967 i = n_buttons;
968 while (i--)
970 add_widget (jobs_dlg, button_new (JOBS_Y-4,
971 job_buttons [i].xpos, job_buttons [i].value,
972 NORMAL_BUTTON, job_buttons [i].name,
973 job_buttons [i].callback));
976 /* Insert all of task information in the list */
977 jobs_fill_listbox ();
978 run_dlg (jobs_dlg);
980 destroy_dlg (jobs_dlg);
982 #endif /* WITH_BACKGROUND */
984 #ifdef ENABLE_VFS_SMB
985 struct smb_authinfo *
986 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
987 const char *user)
989 static int dialog_x = 44;
990 enum { b0 = 3, dialog_y = 12};
991 struct smb_authinfo *return_value;
992 static const char* lc_labs[] = {N_("Domain:"), N_("Username:"), N_("Password:")};
993 static const char* buts[] = {N_("&OK"), N_("&Cancel")};
994 static int ilen = 30, istart = 14;
995 static int b2 = 30;
996 char *title;
997 WInput *in_password;
998 WInput *in_user;
999 WInput *in_domain;
1000 Dlg_head *auth_dlg;
1002 #ifdef ENABLE_NLS
1003 static int i18n_flag = 0;
1005 if (!i18n_flag)
1007 register int i = sizeof(lc_labs)/sizeof(lc_labs[0]);
1008 int l1, maxlen = 0;
1010 while (i--)
1012 l1 = str_term_width1 (lc_labs [i] = _(lc_labs [i]));
1013 if (l1 > maxlen)
1014 maxlen = l1;
1016 i = maxlen + ilen + 7;
1017 if (i > dialog_x)
1018 dialog_x = i;
1020 for (i = sizeof(buts)/sizeof(buts[0]), l1 = 0; i--; )
1022 l1 += str_term_width1 (buts [i] = _(buts [i]));
1024 l1 += 15;
1025 if (l1 > dialog_x)
1026 dialog_x = l1;
1028 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1029 istart = dialog_x - 3 - ilen;
1031 b2 = dialog_x - (str_term_width1 (buts[1]) + 6);
1033 i18n_flag = 1;
1036 #endif /* ENABLE_NLS */
1038 if (!domain)
1039 domain = "";
1040 if (!user)
1041 user = "";
1043 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1045 auth_dlg = create_dlg (0, 0, dialog_y, dialog_x, dialog_colors, NULL,
1046 "[Smb Authinfo]", title, DLG_CENTER | DLG_REVERSE);
1048 g_free (title);
1050 in_user = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name", INPUT_COMPLETE_DEFAULT);
1051 add_widget (auth_dlg, in_user);
1053 in_domain = input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain", INPUT_COMPLETE_DEFAULT);
1054 add_widget (auth_dlg, in_domain);
1055 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON,
1056 buts[1], 0));
1057 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON,
1058 buts[0], 0));
1060 in_password = input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password", INPUT_COMPLETE_DEFAULT);
1061 in_password->completion_flags = 0;
1062 in_password->is_password = 1;
1063 add_widget (auth_dlg, in_password);
1065 add_widget (auth_dlg, label_new (7, 3, lc_labs[2]));
1066 add_widget (auth_dlg, label_new (5, 3, lc_labs[1]));
1067 add_widget (auth_dlg, label_new (3, 3, lc_labs[0]));
1069 run_dlg (auth_dlg);
1071 switch (auth_dlg->ret_value) {
1072 case B_CANCEL:
1073 return_value = 0;
1074 break;
1075 default:
1076 return_value = g_try_new (struct smb_authinfo, 1);
1077 if (return_value) {
1078 return_value->host = g_strdup (host);
1079 return_value->share = g_strdup (share);
1080 return_value->domain = g_strdup (in_domain->buffer);
1081 return_value->user = g_strdup (in_user->buffer);
1082 return_value->password = g_strdup (in_password->buffer);
1086 destroy_dlg (auth_dlg);
1088 return return_value;
1090 #endif /* ENABLE_VFS_SMB */