Ticket #1648: implemented single-line boxes.
[kaloumi3.git] / src / boxes.c
blob61fca6824e9e754078059bc078af03cc63e29f73
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 = 7;
273 const char **sort_orders_names;
274 gsize sort_names_num;
276 int sort_idx = 0;
278 const panel_field_t *result = sort_format;
280 sort_orders_names = panel_get_sortable_fields(&sort_names_num);
281 dlg_height += sort_names_num;
284 int max_radio = 0, max_check = 0;
285 int ok_len, cancel_len;
286 gsize i;
288 QuickWidget quick_widgets[] =
290 /* 0 */
291 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
292 /* 1 */
293 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
294 /* 2 */
295 QUICK_CHECKBOX (0, dlg_width, 5, dlg_height, N_("&Reverse"), reverse),
296 /* 3 */
297 QUICK_CHECKBOX (0, dlg_width, 4, dlg_height, N_("Case sensi&tive"), case_sensitive),
298 /* 4 */
299 QUICK_CHECKBOX (0, dlg_width, 3, dlg_height, N_("Executable &first"), exec_first),
300 /* 5 */
301 QUICK_RADIO (4, dlg_width, 3, dlg_height, 0,
302 NULL, &sort_idx),
303 QUICK_END
306 QuickDialog quick_dlg =
308 dlg_width, dlg_height, -1, -1,
309 N_("Sort order"), "[Sort Order...]",
310 quick_widgets, TRUE
313 quick_widgets[5].u.radio.items = sort_orders_names;
314 quick_widgets[5].u.radio.count = sort_names_num;
316 for (i = 0; i < sort_names_num; i++)
317 if (strcmp (sort_orders_names[i], _(sort_format->title_hotkey)) == 0 ) {
318 sort_idx = i;
319 break;
322 #ifdef ENABLE_NLS
323 quick_dlg.title = _(quick_dlg.title);
324 /* buttons */
325 for (i = 0; i < 2; i++)
326 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
327 /* checkboxes */
328 for (i = 2; i < 5; i++)
329 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
330 #endif /* ENABLE_NlS */
332 /* buttons */
333 cancel_len = str_term_width1 (quick_widgets[0].u.button.text) + 4;
334 ok_len = str_term_width1 (quick_widgets[1].u.button.text) + 6;
335 /* checkboxes */
336 for (i = 2; i < 5; i++)
337 max_check = max (max_check, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
338 /* radiobuttons */
339 for (i = 0; i < sort_names_num; i++)
340 max_radio = max (max_radio, str_term_width1 (sort_orders_names[i]) + 4);
342 /* dialog width */
343 dlg_width = max (dlg_width, str_term_width1 (quick_dlg.title) + 8);
344 dlg_width = max (dlg_width, ok_len + cancel_len + 8);
345 dlg_width = max (dlg_width, 2 * max (max_radio, max_check) + 8);
347 /* fix widget and dialog parameters */
348 /* dialog */
349 quick_dlg.xlen = dlg_width;
350 /* widgets */
351 for (i = 0; (size_t) i < sizeof (quick_widgets)/sizeof (quick_widgets[0]) - 1; i++)
352 quick_widgets[i].x_divisions = dlg_width;
353 /* buttons */
354 quick_widgets[0].relative_x = dlg_width * 2/3 - cancel_len/2;
355 quick_widgets[1].relative_x = dlg_width/3 - ok_len/2;
356 /* checkboxes */
357 for (i = 2; i < 5; i++)
358 quick_widgets[i].relative_x = dlg_width/2 + 2;
360 if (quick_dialog (&quick_dlg) != B_CANCEL)
361 result = panel_get_field_by_title_hotkey(sort_orders_names[sort_idx]);
363 if (result == NULL)
364 result = sort_format;
366 g_strfreev((gchar **)sort_orders_names);
367 return result;
371 void
372 confirm_box (void)
374 const char *title = _("Confirmation");
376 QuickWidget conf_widgets [] =
378 /* 0 */ QUICK_BUTTON (29, 46, 10, 13, N_("&Cancel"), B_CANCEL, NULL),
379 /* 1 */ QUICK_BUTTON (12, 46, 10, 13, N_("&OK"), B_ENTER, NULL),
380 /* TRANSLATORS: no need to translate 'Confirmation', it's just a context prefix */
381 /* 2 */ QUICK_CHECKBOX (3, 46, 8, 13, N_("Confirmation|&History cleanup"), &confirm_history_cleanup),
382 /* 3 */ QUICK_CHECKBOX (3, 46, 7, 13, N_("Confirmation|&Directory hotlist delete"), &confirm_directory_hotlist_delete),
383 /* 4 */ QUICK_CHECKBOX (3, 46, 6, 13, N_("Confirmation|E&xit"), &confirm_exit),
384 /* 5 */ QUICK_CHECKBOX (3, 46, 5, 13, N_("Confirmation|&Execute"), &confirm_execute),
385 /* 6 */ QUICK_CHECKBOX (3, 46, 4, 13, N_("Confirmation|O&verwrite"), &confirm_overwrite),
386 /* 7 */ QUICK_CHECKBOX (3, 46, 3, 13, N_("Confirmation|&Delete"), &confirm_delete),
387 QUICK_END
390 const size_t w_num = sizeof (conf_widgets) / sizeof (conf_widgets[0]) - 1;
392 /* dialog sizes */
393 int dlg_width = 46;
394 int dlg_height = w_num + 5;
396 size_t i;
397 int maxlen = 0;
398 int cancel_len, ok_len, blen;
400 #ifdef ENABLE_NLS
401 title = _(title);
403 for (i = 0; i < 2; i++)
404 conf_widgets [i].u.button.text = _(conf_widgets [i].u.button.text);
406 for (i = 2; i < w_num; i++)
407 conf_widgets [i].u.checkbox.text = Q_(conf_widgets [i].u.checkbox.text);
408 #endif /* ENABLE_NLS */
410 /* maximumr length of checkboxes */
411 for (i = 2; i < w_num; i++)
412 maxlen = max (maxlen, str_term_width1 (conf_widgets [i].u.checkbox.text) + 4);
414 /* length of buttons */
415 cancel_len = str_term_width1 (conf_widgets [0].u.button.text) + 3;
416 ok_len = str_term_width1 (conf_widgets [1].u.button.text) + 5; /* default button */
418 blen = cancel_len + ok_len + 2;
420 dlg_width = max (maxlen, blen) + 6;
421 dlg_width = max (dlg_width, str_term_width1 (title) + 4);
423 /* correct widget parameters */
424 for (i = 0; i < w_num; i++) {
425 conf_widgets[i].x_divisions = dlg_width;
426 conf_widgets[i].y_divisions = dlg_height;
429 conf_widgets[1].relative_x = dlg_width/2 - blen/2;
430 conf_widgets[0].relative_x = conf_widgets[1].relative_x + ok_len + 2;
433 QuickDialog confirmation =
435 dlg_width, dlg_height, -1, -1, title,
436 "[Confirmation]", conf_widgets, 1
439 (void) quick_dialog (&confirmation);
444 #ifndef HAVE_CHARSET
445 void
446 display_bits_box (void) /* AB:FIXME: test dialog */
448 /* dialog sizes */
449 const int DISPY = 13;
450 const int DISPX = 46;
452 int new_meta = 0;
453 int current_mode;
455 const char *display_bits_str [] =
457 N_("UTF-8 output"),
458 N_("Full 8 bits output"),
459 N_("ISO 8859-1"),
460 N_("7 bits")
463 QuickWidget display_widgets[] =
465 /* 0 */ QUICK_BUTTON (15, DISPX, DISPY - 3, DISPY, N_("&Cancel"), B_CANCEL, NULL),
466 /* 1 */ QUICK_BUTTON (29, DISPX, DISPY - 3, DISPY, N_("&OK"), B_ENTER, NULL),
467 /* 2 */ QUICK_CHECKBOX (3, DISPX, 8, DISPY, N_("F&ull 8 bits input"), &new_meta),
468 /* 3 */ QUICK_RADIO (3, DISPX, 3, DISPY, 4, display_bits_str, &current_mode),
469 QUICK_END
472 QuickDialog display_bits =
474 DISPX, DISPY, -1, -1, _(" Display bits "),
475 "[Display bits]", display_widgets, TRUE
478 int i;
479 int l1, maxlen = 0;
480 int ok_len, cancel_len;
482 #ifdef ENABLE_NLS
483 static gboolean i18n_flag = FALSE;
485 if (!i18n_flag) {
486 for (i = 0; i < 3; i++) {
487 display_bits_str[i] = _(display_bits_str [i]);
490 display_widgets[0].u.button.text = _(display_widgets[0].u.button.text);
491 display_widgets[1].u.button.text = _(display_widgets[1].u.button.text);
492 display_widgets[2].u.checkbox.text = _(display_widgets[2].u.checkbox.text);
494 i18n_flag = TRUE;
496 #endif /* ENABLE_NLS */
498 /* radiobuttons */
499 for (i = 0; i < 3; i++)
500 maxlen = max (maxlen, str_term_width1 (display_bits_str [i]));
502 /* buttons */
503 cancel_len = str_term_width1 (display_widgets [0].u.button.text) + 2;
504 ok_len = str_term_width1 (display_widgets [1].u.button.text) + 4; /* default button */
506 l1 = max (cancel_len, ok_len);
508 display_bits.xlen = max (maxlen, l1) + 20;
510 for (i = 0; i < 4; i++)
511 display_widgets[i].x_divisions = display_bits.xlen;
513 display_widgets[0].relative_x = display_bits.xlen * 2/3 - cancel_len/2;
514 display_widgets[1].relative_x = display_bits.xlen/3 - ok_len/2;
516 if (full_eight_bits)
517 current_mode = 0;
518 else if (eight_bit_clean)
519 current_mode = 1;
520 else
521 current_mode = 2;
523 new_meta = !use_8th_bit_as_meta;
525 if (quick_dialog (&display_bits) != B_CANCEL) {
526 eight_bit_clean = current_mode < 3;
527 full_eight_bits = current_mode < 2;
528 #ifndef HAVE_SLANG
529 meta (stdscr, eight_bit_clean);
530 #else
531 SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
532 #endif
533 use_8th_bit_as_meta = !new_meta;
537 #else /* HAVE_CHARSET */
539 static int new_display_codepage;
541 static WLabel *cplabel;
542 static WCheck *inpcheck;
544 static int
545 sel_charset_button (int action)
547 int new_dcp;
549 (void) action;
551 new_dcp = select_charset (-1, -1, new_display_codepage, TRUE);
553 if (new_dcp != SELECT_CHARSET_CANCEL) {
554 const char *cpname;
555 char buf[BUF_TINY];
557 new_display_codepage = new_dcp;
558 cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
559 _("Other 8 bit") : codepages[new_display_codepage].name;
560 if (cpname != NULL)
561 utf8_display = str_isutf8 (cpname);
562 /* avoid strange bug with label repainting */
563 g_snprintf (buf, sizeof (buf), "%-27s", cpname);
564 label_set_text (cplabel, buf);
567 return 0;
570 static Dlg_head *
571 init_disp_bits_box (void)
573 /* dialog sizes */
574 const int DISPY = 11;
575 const int DISPX = 46;
577 const char *cpname;
578 Dlg_head *dbits_dlg;
580 do_refresh ();
582 dbits_dlg =
583 create_dlg (0, 0, DISPY, DISPX, dialog_colors, NULL,
584 "[Display bits]", _(" Display bits "), DLG_CENTER | DLG_REVERSE);
586 add_widget (dbits_dlg,
587 label_new (3, 4, _("Input / display codepage:")));
589 cpname = (new_display_codepage < 0)
590 ? _("Other 8 bit")
591 : codepages[new_display_codepage].name;
592 cplabel = label_new (4, 4, cpname);
593 add_widget (dbits_dlg, cplabel);
595 add_widget (dbits_dlg,
596 button_new (DISPY - 3, DISPX / 2 + 3, B_CANCEL,
597 NORMAL_BUTTON, _("&Cancel"), 0));
598 add_widget (dbits_dlg,
599 button_new (DISPY - 3, 7, B_ENTER, NORMAL_BUTTON, _("&OK"),
600 0));
602 inpcheck =
603 check_new (6, 4, !use_8th_bit_as_meta, _("F&ull 8 bits input"));
604 add_widget (dbits_dlg, inpcheck);
606 cpname = _("&Select");
607 add_widget (dbits_dlg,
608 button_new (4, DISPX - 7 - str_term_width1 (cpname), B_USER,
609 NORMAL_BUTTON, cpname, sel_charset_button));
611 return dbits_dlg;
614 void
615 display_bits_box (void)
617 Dlg_head *dbits_dlg;
618 new_display_codepage = display_codepage;
620 application_keypad_mode ();
621 dbits_dlg = init_disp_bits_box ();
623 run_dlg (dbits_dlg);
625 if (dbits_dlg->ret_value == B_ENTER) {
626 const char *errmsg;
627 display_codepage = new_display_codepage;
628 errmsg =
629 init_translation_table (source_codepage, display_codepage);
630 if (errmsg)
631 message (D_ERROR, MSG_ERROR, "%s", errmsg);
632 #ifdef HAVE_SLANG
633 tty_display_8bit (display_codepage != 0 && display_codepage != 1);
634 #else
635 tty_display_8bit (display_codepage != 0);
636 #endif
637 use_8th_bit_as_meta = !(inpcheck->state & C_BOOL);
639 destroy_dlg (dbits_dlg);
640 repaint_screen ();
643 #endif /* HAVE_CHARSET */
645 static cb_ret_t
646 tree_callback (Dlg_head *h, Widget *sender,
647 dlg_msg_t msg, int parm, void *data)
649 switch (msg) {
650 case DLG_POST_KEY:
651 /* The enter key will be processed by the tree widget */
652 if (parm == '\n') {
653 h->ret_value = B_ENTER;
654 dlg_stop (h);
656 return MSG_HANDLED;
658 case DLG_ACTION:
659 /* command from buttonbar */
660 return send_message ((Widget *) find_tree (h), WIDGET_COMMAND, parm);
662 default:
663 return default_dlg_callback (h, sender, msg, parm, data);
667 /* Show tree in a box, not on a panel */
668 char *
669 tree_box (const char *current_dir)
671 WTree *mytree;
672 Dlg_head *dlg;
673 char *val = NULL;
674 WButtonBar *bar;
676 (void) current_dir;
678 /* Create the components */
679 dlg = create_dlg (0, 0, LINES - 9, COLS - 20, dialog_colors,
680 tree_callback, "[Directory Tree]",
681 NULL, DLG_CENTER | DLG_REVERSE);
683 mytree = tree_new (0, 2, 2, dlg->lines - 6, dlg->cols - 5);
684 add_widget (dlg, mytree);
685 bar = buttonbar_new (TRUE);
686 add_widget (dlg, bar);
687 /* restore ButtonBar coordinates after add_widget() */
688 ((Widget *) bar)->x = 0;
689 ((Widget *) bar)->y = LINES - 1;
691 if (run_dlg (dlg) == B_ENTER)
692 val = g_strdup (tree_selected_name (mytree));
694 destroy_dlg (dlg);
695 return val;
698 #ifdef ENABLE_VFS
700 static char *ret_timeout;
702 #ifdef USE_NETCODE
703 static char *ret_passwd;
704 static char *ret_directory_timeout;
705 static char *ret_ftp_proxy;
706 #endif
708 void
709 configure_vfs (void)
711 #define VFSX 56
713 #ifdef USE_NETCODE
714 #define VFSY 17
715 #else
716 #define VFSY 8
717 #endif
719 char buffer2 [BUF_TINY];
720 #ifdef USE_NETCODE
721 char buffer3 [BUF_TINY];
722 #endif
724 QuickWidget confvfs_widgets [] =
726 /* 0 */ QUICK_BUTTON (30, VFSX, VFSY - 3, VFSY, N_("&Cancel"), B_CANCEL, NULL),
727 /* 1 */ QUICK_BUTTON (12, VFSX, VFSY - 3, VFSY, N_("&OK"), B_ENTER, NULL),
728 #ifdef USE_NETCODE
729 /* 2 */ QUICK_CHECKBOX (4, VFSX, 12, VFSY, N_("Use passive mode over pro&xy"), &ftpfs_use_passive_connections_over_proxy),
730 /* 3 */ QUICK_CHECKBOX (4, VFSX, 11, VFSY, N_("Use &passive mode"), &ftpfs_use_passive_connections),
731 /* 4 */ QUICK_CHECKBOX (4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), &use_netrc),
732 /* 5 */ QUICK_INPUT (4, VFSX, 9, VFSY, ftpfs_proxy_host, 48, 0, "input-ftp-proxy", &ret_ftp_proxy),
733 /* 6 */ QUICK_CHECKBOX (4, VFSX, 8, VFSY, N_("&Always use ftp proxy"), &ftpfs_always_use_proxy),
734 /* 7 */ QUICK_LABEL (49, VFSX, 7, VFSY, N_("sec")),
735 /* 8 */ QUICK_INPUT (38, VFSX, 7, VFSY, buffer3, 10, 0, "input-timeout", &ret_directory_timeout),
736 /* 9 */ QUICK_LABEL (4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:")),
737 /* 10 */ QUICK_INPUT (4, VFSX, 6, VFSY, ftpfs_anonymous_passwd, 48, 0, "input-passwd", &ret_passwd),
738 /* 11 */ QUICK_LABEL (4, VFSX, 5, VFSY, N_("ftp anonymous password:")),
739 #endif
740 /* 12 */ QUICK_LABEL (49, VFSX, 3, VFSY, N_("sec")),
741 /* 13 */ QUICK_INPUT (38, VFSX, 3, VFSY, buffer2, 10, 0, "input-timo-vfs", &ret_timeout),
742 /* 14 */ QUICK_LABEL (4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:")),
743 QUICK_END
746 QuickDialog confvfs_dlg =
748 VFSX, VFSY, -1, -1, N_(" Virtual File System Setting "),
749 "[Virtual FS]", confvfs_widgets, FALSE
752 #ifdef USE_NETCODE
753 g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
754 #endif
755 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
757 if (quick_dialog (&confvfs_dlg) != B_CANCEL) {
758 vfs_timeout = atoi (ret_timeout);
759 g_free (ret_timeout);
761 if (vfs_timeout < 0 || vfs_timeout > 10000)
762 vfs_timeout = 10;
763 #ifdef USE_NETCODE
764 g_free (ftpfs_anonymous_passwd);
765 ftpfs_anonymous_passwd = ret_passwd;
766 g_free (ftpfs_proxy_host);
767 ftpfs_proxy_host = ret_ftp_proxy;
768 ftpfs_directory_timeout = atoi(ret_directory_timeout);
769 g_free (ret_directory_timeout);
770 #endif
773 #undef VFSX
774 #undef VFSY
777 #endif /* ENABLE_VFS */
779 char *
780 cd_dialog (void)
782 const char *label = N_("cd");
783 const int ylen = 5;
784 const int xlen = 57;
786 int len;
788 #ifdef ENABLE_NLS
789 label = _(label);
790 #endif
792 len = str_term_width1 (label);
795 char *my_str;
797 QuickWidget quick_widgets [] =
799 /* 0 */ QUICK_INPUT (4 + len, xlen, 2, ylen, "", xlen - 7 - len, 2, "input" , &my_str),
800 /* 1 */ QUICK_LABEL (3, xlen, 2, ylen, label),
801 QUICK_END
804 QuickDialog Quick_input =
806 xlen, ylen, 2, LINES - 2 - ylen, _("Quick cd"),
807 "[Quick cd]", quick_widgets, TRUE
810 return (quick_dialog (&Quick_input) != B_CANCEL) ? my_str : NULL;
814 void
815 symlink_dialog (const char *existing, const char *new, char **ret_existing,
816 char **ret_new)
818 QuickWidget quick_widgets[] =
820 /* 0 */ QUICK_BUTTON (50, 80, 6, 8, N_("&Cancel"), B_CANCEL, NULL),
821 /* 1 */ QUICK_BUTTON (16, 80, 6, 8, N_("&OK"), B_ENTER, NULL),
822 /* 2 */ QUICK_INPUT (4, 80, 5, 8, new, 58, 0, "input-1", ret_new),
823 /* 3 */ QUICK_LABEL (4, 80, 4, 8, N_("Symbolic link filename:")),
824 /* 4 */ QUICK_INPUT (4, 80, 3, 8, existing, 58, 0, "input-2", ret_existing),
825 /* 5 */ QUICK_LABEL (4, 80, 2, 8, N_("Existing filename (filename symlink will point to):")),
826 QUICK_END
829 QuickDialog Quick_input =
831 64, 12, -1, -1, N_("Symbolic link"),
832 "[File Menu]", quick_widgets, FALSE
835 if (quick_dialog (&Quick_input) == B_CANCEL) {
836 *ret_new = NULL;
837 *ret_existing = NULL;
841 #ifdef WITH_BACKGROUND
842 #define B_STOP (B_USER+1)
843 #define B_RESUME (B_USER+2)
844 #define B_KILL (B_USER+3)
846 static int JOBS_X = 60;
847 #define JOBS_Y 15
848 static WListbox *bg_list;
849 static Dlg_head *jobs_dlg;
851 static void
852 jobs_fill_listbox (void)
854 static const char *state_str [2];
855 TaskList *tl = task_list;
857 if (!state_str [0]){
858 state_str [0] = _("Running ");
859 state_str [1] = _("Stopped");
862 while (tl){
863 char *s;
865 s = g_strconcat (state_str [tl->state], " ", tl->info, (char *) NULL);
866 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
867 g_free (s);
868 tl = tl->next;
872 static int
873 task_cb (int action)
875 TaskList *tl;
876 int sig = 0;
878 if (!bg_list->list)
879 return 0;
881 /* Get this instance information */
882 listbox_get_current (bg_list, NULL, (void **) &tl);
884 # ifdef SIGTSTP
885 if (action == B_STOP){
886 sig = SIGSTOP;
887 tl->state = Task_Stopped;
888 } else if (action == B_RESUME){
889 sig = SIGCONT;
890 tl->state = Task_Running;
891 } else
892 # endif
893 if (action == B_KILL){
894 sig = SIGKILL;
897 if (sig == SIGKILL)
898 unregister_task_running (tl->pid, tl->fd);
900 kill (tl->pid, sig);
901 listbox_remove_list (bg_list);
902 jobs_fill_listbox ();
904 /* This can be optimized to just redraw this widget :-) */
905 dlg_redraw (jobs_dlg);
907 return 0;
910 static struct
912 const char* name;
913 int xpos;
914 int value;
915 int (*callback)(int);
917 job_buttons [] =
919 {N_("&Stop"), 3, B_STOP, task_cb},
920 {N_("&Resume"), 12, B_RESUME, task_cb},
921 {N_("&Kill"), 23, B_KILL, task_cb},
922 {N_("&OK"), 35, B_CANCEL, NULL }
925 void
926 jobs_cmd (void)
928 register int i;
929 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
931 #ifdef ENABLE_NLS
932 static int i18n_flag = 0;
933 if (!i18n_flag)
935 int startx = job_buttons [0].xpos;
936 int len;
938 for (i = 0; i < n_buttons; i++)
940 job_buttons [i].name = _(job_buttons [i].name);
942 len = str_term_width1 (job_buttons [i].name) + 4;
943 JOBS_X = max (JOBS_X, startx + len + 3);
945 job_buttons [i].xpos = startx;
946 startx += len;
949 /* Last button - Ok a.k.a. Cancel :) */
950 job_buttons [n_buttons - 1].xpos =
951 JOBS_X - str_term_width1 (job_buttons [n_buttons - 1].name) - 7;
953 i18n_flag = 1;
955 #endif /* ENABLE_NLS */
957 jobs_dlg = create_dlg (0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL,
958 "[Background jobs]", _("Background Jobs"),
959 DLG_CENTER | DLG_REVERSE);
961 bg_list = listbox_new (2, 3, JOBS_Y - 9, JOBS_X - 7, FALSE, NULL);
962 add_widget (jobs_dlg, bg_list);
964 i = n_buttons;
965 while (i--)
967 add_widget (jobs_dlg, button_new (JOBS_Y-4,
968 job_buttons [i].xpos, job_buttons [i].value,
969 NORMAL_BUTTON, job_buttons [i].name,
970 job_buttons [i].callback));
973 /* Insert all of task information in the list */
974 jobs_fill_listbox ();
975 run_dlg (jobs_dlg);
977 destroy_dlg (jobs_dlg);
979 #endif /* WITH_BACKGROUND */
981 #ifdef ENABLE_VFS_SMB
982 struct smb_authinfo *
983 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
984 const char *user)
986 static int dialog_x = 44;
987 enum { b0 = 3, dialog_y = 12};
988 struct smb_authinfo *return_value;
989 static const char* lc_labs[] = {N_("Domain:"), N_("Username:"), N_("Password:")};
990 static const char* buts[] = {N_("&OK"), N_("&Cancel")};
991 static int ilen = 30, istart = 14;
992 static int b2 = 30;
993 char *title;
994 WInput *in_password;
995 WInput *in_user;
996 WInput *in_domain;
997 Dlg_head *auth_dlg;
999 #ifdef ENABLE_NLS
1000 static int i18n_flag = 0;
1002 if (!i18n_flag)
1004 register int i = sizeof(lc_labs)/sizeof(lc_labs[0]);
1005 int l1, maxlen = 0;
1007 while (i--)
1009 l1 = str_term_width1 (lc_labs [i] = _(lc_labs [i]));
1010 if (l1 > maxlen)
1011 maxlen = l1;
1013 i = maxlen + ilen + 7;
1014 if (i > dialog_x)
1015 dialog_x = i;
1017 for (i = sizeof(buts)/sizeof(buts[0]), l1 = 0; i--; )
1019 l1 += str_term_width1 (buts [i] = _(buts [i]));
1021 l1 += 15;
1022 if (l1 > dialog_x)
1023 dialog_x = l1;
1025 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1026 istart = dialog_x - 3 - ilen;
1028 b2 = dialog_x - (str_term_width1 (buts[1]) + 6);
1030 i18n_flag = 1;
1033 #endif /* ENABLE_NLS */
1035 if (!domain)
1036 domain = "";
1037 if (!user)
1038 user = "";
1040 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1042 auth_dlg = create_dlg (0, 0, dialog_y, dialog_x, dialog_colors, NULL,
1043 "[Smb Authinfo]", title, DLG_CENTER | DLG_REVERSE);
1045 g_free (title);
1047 in_user = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name", INPUT_COMPLETE_DEFAULT);
1048 add_widget (auth_dlg, in_user);
1050 in_domain = input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain", INPUT_COMPLETE_DEFAULT);
1051 add_widget (auth_dlg, in_domain);
1052 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON,
1053 buts[1], 0));
1054 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON,
1055 buts[0], 0));
1057 in_password = input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password", INPUT_COMPLETE_DEFAULT);
1058 in_password->completion_flags = 0;
1059 in_password->is_password = 1;
1060 add_widget (auth_dlg, in_password);
1062 add_widget (auth_dlg, label_new (7, 3, lc_labs[2]));
1063 add_widget (auth_dlg, label_new (5, 3, lc_labs[1]));
1064 add_widget (auth_dlg, label_new (3, 3, lc_labs[0]));
1066 run_dlg (auth_dlg);
1068 switch (auth_dlg->ret_value) {
1069 case B_CANCEL:
1070 return_value = 0;
1071 break;
1072 default:
1073 return_value = g_try_new (struct smb_authinfo, 1);
1074 if (return_value) {
1075 return_value->host = g_strdup (host);
1076 return_value->share = g_strdup (share);
1077 return_value->domain = g_strdup (in_domain->buffer);
1078 return_value->user = g_strdup (in_user->buffer);
1079 return_value->password = g_strdup (in_password->buffer);
1083 destroy_dlg (auth_dlg);
1085 return return_value;
1087 #endif /* ENABLE_VFS_SMB */