Split file src/keybind.[ch] to lib/keybind.[ch] and src/keybind-defaults.[ch].
[midnight-commander.git] / src / boxes.c
blob8a8239fe13e1e61538c6967c506b84726b4a9ec5
1 /* Some misc dialog boxes for the program.
3 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 2005, 2006, 2009, 2010 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/tty/key.h" /* XCTRL and ALT macros */
41 #include "lib/skin.h" /* INPUT_COLOR */
42 #include "lib/mcconfig.h" /* Load/save user formats */
43 #include "lib/strutil.h"
45 #include "lib/vfs/mc-vfs/vfs.h"
46 #ifdef ENABLE_VFS_FTP
47 #include "lib/vfs/mc-vfs/ftpfs.h"
48 #endif /* ENABLE_VFS_FTP */
49 #ifdef ENABLE_VFS_SMB
50 #include "lib/vfs/mc-vfs/smbfs.h"
51 #endif /* ENABLE_VFS_SMB */
53 #include "lib/util.h" /* Q_() */
54 #include "lib/widget.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 "main.h" /* For the confirm_* variables */
61 #include "tree.h"
62 #include "layout.h" /* for get_nth_panel_name proto */
63 #include "background.h" /* task_list */
65 #ifdef HAVE_CHARSET
66 #include "lib/charsets.h"
67 #include "selcodepage.h"
68 #endif
70 #include "boxes.h"
72 /*** global variables ****************************************************************************/
74 /*** file scope macro definitions ****************************************************************/
76 #ifdef ENABLE_VFS
77 #define VFSX 56
79 #ifdef ENABLE_VFS_FTP
80 #define VFSY 17
81 #else
82 #define VFSY 8
83 #endif /* ENABLE_VFS_FTP */
84 #endif /* ENABLE_VFS */
86 #ifdef WITH_BACKGROUND
87 #define B_STOP (B_USER+1)
88 #define B_RESUME (B_USER+2)
89 #define B_KILL (B_USER+3)
90 #define JOBS_Y 15
91 #endif /* WITH_BACKGROUND */
93 /*** file scope type declarations ****************************************************************/
95 /*** file scope variables ************************************************************************/
97 static WRadio *display_radio;
98 static WInput *display_user_format;
99 static WInput *display_mini_status;
100 static WCheck *display_check_status;
101 static char **displays_status;
102 static int display_user_hotkey = 'u';
104 #ifdef HAVE_CHARSET
105 static int new_display_codepage;
106 static WLabel *cplabel;
107 static WCheck *inpcheck;
108 #endif /* HAVE_CHARSET */
110 #ifdef ENABLE_VFS
111 static char *ret_timeout;
112 #ifdef ENABLE_VFS_FTP
113 static char *ret_ftp_proxy;
114 static char *ret_passwd;
115 static char *ret_directory_timeout;
116 #endif /* ENABLE_VFS_FTP */
117 #endif /* ENABLE_VFS */
119 #ifdef WITH_BACKGROUND
120 static int JOBS_X = 60;
121 static WListbox *bg_list;
122 static Dlg_head *jobs_dlg;
124 static int task_cb (WButton * button, int action);
126 static struct
128 const char *name;
129 int xpos;
130 int value;
131 bcback_fn callback;
133 job_buttons[] =
135 /* *INDENT-OFF* */
136 { N_("&Stop"), 3, B_STOP, task_cb },
137 { N_("&Resume"), 12, B_RESUME, task_cb },
138 { N_("&Kill"), 23, B_KILL, task_cb },
139 { N_("&OK"), 35, B_CANCEL, NULL }
140 /* *INDENT-ON* */
143 #endif /* WITH_BACKGROUND */
145 /*** file scope functions ************************************************************************/
146 /* --------------------------------------------------------------------------------------------- */
148 static cb_ret_t
149 display_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
151 switch (msg)
153 case DLG_KEY:
154 if (parm == '\n')
156 if (dlg_widget_active (display_radio))
158 input_assign_text (display_mini_status, displays_status[display_radio->sel]);
159 dlg_stop (h);
160 return MSG_HANDLED;
163 if (dlg_widget_active (display_user_format))
165 h->ret_value = B_USER + 6;
166 dlg_stop (h);
167 return MSG_HANDLED;
170 if (dlg_widget_active (display_mini_status))
172 h->ret_value = B_USER + 7;
173 dlg_stop (h);
174 return MSG_HANDLED;
178 if ((g_ascii_tolower (parm) == display_user_hotkey)
179 && dlg_widget_active (display_user_format) && dlg_widget_active (display_mini_status))
181 display_radio->pos = display_radio->sel = 3;
182 dlg_select_widget (display_radio); /* force redraw */
183 h->callback (h, (Widget *) display_radio, DLG_ACTION, 0, NULL);
184 return MSG_HANDLED;
186 return MSG_NOT_HANDLED;
188 case DLG_ACTION:
189 if (sender == (Widget *) display_radio)
191 if (!(display_check_status->state & C_BOOL))
192 input_assign_text (display_mini_status, displays_status[display_radio->sel]);
193 input_update (display_mini_status, FALSE);
194 input_update (display_user_format, FALSE);
195 widget_disable (display_user_format->widget, display_radio->sel != 3);
196 return MSG_HANDLED;
199 if (sender == (Widget *) display_check_status)
201 if (display_check_status->state & C_BOOL)
203 widget_disable (display_mini_status->widget, FALSE);
204 input_assign_text (display_mini_status, displays_status[3]);
206 else
208 widget_disable (display_mini_status->widget, TRUE);
209 input_assign_text (display_mini_status, displays_status[display_radio->sel]);
211 input_update (display_mini_status, FALSE);
212 return MSG_HANDLED;
215 return MSG_NOT_HANDLED;
217 default:
218 return default_dlg_callback (h, sender, msg, parm, data);
222 /* --------------------------------------------------------------------------------------------- */
224 static Dlg_head *
225 display_init (int radio_sel, char *init_text, int _check_status, char **_status)
227 int dlg_width = 48, dlg_height = 15;
228 Dlg_head *dd;
230 /* Controls whether the array strings have been translated */
231 const char *displays[LIST_TYPES] = {
232 N_("&Full file list"),
233 N_("&Brief file list"),
234 N_("&Long file list"),
235 N_("&User defined:")
238 /* Index in displays[] for "user defined" */
239 const int user_type_idx = 3;
241 const char *display_title = N_("Listing mode");
242 const char *user_mini_status = N_("User &mini status");
243 const char *ok_name = N_("&OK");
244 const char *cancel_name = N_("&Cancel");
246 WButton *ok_button, *cancel_button;
249 int i, maxlen = 0;
250 const char *cp;
251 int ok_len, cancel_len, b_len, gap;
253 #ifdef ENABLE_NLS
254 display_title = _(display_title);
255 user_mini_status = _(user_mini_status);
256 ok_name = _(ok_name);
257 cancel_name = _(cancel_name);
259 for (i = 0; i < LIST_TYPES; i++)
260 displays[i] = _(displays[i]);
261 #endif
263 /* get hotkey of user-defined format string */
264 cp = strchr (displays[user_type_idx], '&');
265 if (cp != NULL && *++cp != '\0')
266 display_user_hotkey = g_ascii_tolower (*cp);
268 /* xpos will be fixed later */
269 ok_button = button_new (dlg_height - 3, 0, B_ENTER, DEFPUSH_BUTTON, ok_name, 0);
270 ok_len = button_get_len (ok_button);
271 cancel_button = button_new (dlg_height - 3, 0, B_CANCEL, NORMAL_BUTTON, cancel_name, 0);
272 cancel_len = button_get_len (cancel_button);
273 b_len = ok_len + cancel_len + 2;
275 dlg_width = max (dlg_width, str_term_width1 (display_title) + 10);
276 /* calculate max width of radiobutons */
277 for (i = 0; i < LIST_TYPES; i++)
278 maxlen = max (maxlen, str_term_width1 (displays[i]));
279 dlg_width = max (dlg_width, maxlen);
280 dlg_width = max (dlg_width, str_term_width1 (user_mini_status) + 13);
282 /* buttons */
283 dlg_width = max (dlg_width, b_len + 6);
284 gap = (dlg_width - 6 - b_len) / 3;
285 ok_button->widget.x = 3 + gap;
286 cancel_button->widget.x = ok_button->widget.x + ok_len + gap + 2;
289 displays_status = _status;
291 dd = create_dlg (TRUE, 0, 0, dlg_height, dlg_width, dialog_colors,
292 display_callback, "[Listing Mode...]", display_title,
293 DLG_CENTER | DLG_REVERSE);
295 add_widget (dd, cancel_button);
296 add_widget (dd, ok_button);
298 display_mini_status =
299 input_new (10, 8, input_get_default_colors (), dlg_width - 12, _status[radio_sel],
300 "mini-input", INPUT_COMPLETE_DEFAULT);
301 add_widget (dd, display_mini_status);
303 display_check_status = check_new (9, 4, _check_status, user_mini_status);
304 add_widget (dd, display_check_status);
306 display_user_format = input_new (7, 8, input_get_default_colors (), dlg_width - 12, init_text,
307 "user-fmt-input", INPUT_COMPLETE_DEFAULT);
308 add_widget (dd, display_user_format);
310 display_radio = radio_new (3, 4, LIST_TYPES, displays);
311 display_radio->sel = display_radio->pos = radio_sel;
312 add_widget (dd, display_radio);
314 return dd;
317 /* --------------------------------------------------------------------------------------------- */
318 #ifdef HAVE_CHARSET
320 static int
321 sel_charset_button (WButton * button, int action)
323 int new_dcp;
325 (void) button;
326 (void) action;
328 new_dcp = select_charset (-1, -1, new_display_codepage, TRUE);
330 if (new_dcp != SELECT_CHARSET_CANCEL)
332 const char *cpname;
333 char buf[BUF_TINY];
335 new_display_codepage = new_dcp;
336 cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
337 _("Other 8 bit") :
338 ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
339 if (cpname != NULL)
340 utf8_display = str_isutf8 (cpname);
341 /* avoid strange bug with label repainting */
342 g_snprintf (buf, sizeof (buf), "%-27s", cpname);
343 label_set_text (cplabel, buf);
346 return 0;
349 /* --------------------------------------------------------------------------------------------- */
351 static Dlg_head *
352 init_disp_bits_box (void)
354 /* dialog sizes */
355 const int DISPY = 11;
356 const int DISPX = 46;
358 const char *cpname;
359 Dlg_head *dbits_dlg;
361 do_refresh ();
363 dbits_dlg =
364 create_dlg (TRUE, 0, 0, DISPY, DISPX, dialog_colors, NULL,
365 "[Display bits]", _("Display bits"), DLG_CENTER | DLG_REVERSE);
367 add_widget (dbits_dlg, label_new (3, 4, _("Input / display codepage:")));
369 cpname = (new_display_codepage < 0) ? _("Other 8 bit")
370 : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
371 cplabel = label_new (4, 4, cpname);
372 add_widget (dbits_dlg, cplabel);
374 add_widget (dbits_dlg,
375 button_new (DISPY - 3, DISPX / 2 + 3, B_CANCEL, NORMAL_BUTTON, _("&Cancel"), 0));
376 add_widget (dbits_dlg, button_new (DISPY - 3, 7, B_ENTER, NORMAL_BUTTON, _("&OK"), 0));
378 inpcheck = check_new (6, 4, !use_8th_bit_as_meta, _("F&ull 8 bits input"));
379 add_widget (dbits_dlg, inpcheck);
381 cpname = _("&Select");
382 add_widget (dbits_dlg,
383 button_new (4, DISPX - 7 - str_term_width1 (cpname), B_USER,
384 NORMAL_BUTTON, cpname, sel_charset_button));
386 return dbits_dlg;
388 #endif /* HAVE_CHARSET */
390 /* --------------------------------------------------------------------------------------------- */
392 static cb_ret_t
393 tree_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
395 switch (msg)
397 case DLG_POST_KEY:
398 /* The enter key will be processed by the tree widget */
399 if (parm == '\n')
401 h->ret_value = B_ENTER;
402 dlg_stop (h);
404 return MSG_HANDLED;
406 case DLG_ACTION:
407 /* command from buttonbar */
408 return send_message ((Widget *) find_tree (h), WIDGET_COMMAND, parm);
410 default:
411 return default_dlg_callback (h, sender, msg, parm, data);
415 /* --------------------------------------------------------------------------------------------- */
417 #ifdef ENABLE_VFS
418 #ifdef ENABLE_VFS_FTP
420 static cb_ret_t
421 confvfs_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
423 switch (msg)
425 case DLG_ACTION:
426 if (sender->id == 6)
428 /* message from "Always use ftp proxy" checkbutton */
429 const gboolean not_use = !(((WCheck *) sender)->state & C_BOOL);
430 Widget *w;
432 /* input */
433 w = dlg_find_by_id (h, sender->id - 1);
434 widget_disable (*w, not_use);
435 send_message (w, WIDGET_DRAW, 0);
437 return MSG_HANDLED;
439 return MSG_NOT_HANDLED;
441 default:
442 return default_dlg_callback (h, sender, msg, parm, data);
445 #endif /* ENABLE_VFS_FTP */
446 #endif /* ENABLE_VFS */
448 #ifdef WITH_BACKGROUND
449 static void
450 jobs_fill_listbox (void)
452 static const char *state_str[2];
453 TaskList *tl = task_list;
455 if (!state_str[0])
457 state_str[0] = _("Running");
458 state_str[1] = _("Stopped");
461 while (tl)
463 char *s;
465 s = g_strconcat (state_str[tl->state], " ", tl->info, (char *) NULL);
466 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
467 g_free (s);
468 tl = tl->next;
472 /* --------------------------------------------------------------------------------------------- */
474 static int
475 task_cb (WButton * button, int action)
477 TaskList *tl;
478 int sig = 0;
480 (void) button;
482 if (bg_list->list == NULL)
483 return 0;
485 /* Get this instance information */
486 listbox_get_current (bg_list, NULL, (void **) &tl);
488 #ifdef SIGTSTP
489 if (action == B_STOP)
491 sig = SIGSTOP;
492 tl->state = Task_Stopped;
494 else if (action == B_RESUME)
496 sig = SIGCONT;
497 tl->state = Task_Running;
499 else
500 #endif
501 if (action == B_KILL)
503 sig = SIGKILL;
506 if (sig == SIGKILL)
507 unregister_task_running (tl->pid, tl->fd);
509 kill (tl->pid, sig);
510 listbox_remove_list (bg_list);
511 jobs_fill_listbox ();
513 /* This can be optimized to just redraw this widget :-) */
514 dlg_redraw (jobs_dlg);
516 return 0;
518 #endif /* WITH_BACKGROUND */
520 /* --------------------------------------------------------------------------------------------- */
521 /*** public functions ****************************************************************************/
522 /* --------------------------------------------------------------------------------------------- */
524 /* return list type */
526 display_box (WPanel * panel, char **userp, char **minip, int *use_msformat, int num)
528 int result = -1;
529 Dlg_head *dd;
530 char *section = NULL;
531 size_t i;
533 if (panel == NULL)
535 const char *p = get_nth_panel_name (num);
536 panel = g_new (WPanel, 1);
537 panel->list_type = list_full;
538 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
539 panel->user_mini_status = 0;
540 for (i = 0; i < LIST_TYPES; i++)
541 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
542 section = g_strconcat ("Temporal:", p, (char *) NULL);
543 if (!mc_config_has_group (mc_main_config, section))
545 g_free (section);
546 section = g_strdup (p);
548 panel_load_setup (panel, section);
549 g_free (section);
552 dd = display_init (panel->list_type, panel->user_format,
553 panel->user_mini_status, panel->user_status_format);
555 if (run_dlg (dd) != B_CANCEL)
557 result = display_radio->sel;
558 *userp = g_strdup (display_user_format->buffer);
559 *minip = g_strdup (display_mini_status->buffer);
560 *use_msformat = display_check_status->state & C_BOOL;
563 if (section != NULL)
565 g_free (panel->user_format);
566 for (i = 0; i < LIST_TYPES; i++)
567 g_free (panel->user_status_format[i]);
568 g_free (panel);
571 destroy_dlg (dd);
573 return result;
576 /* --------------------------------------------------------------------------------------------- */
578 const panel_field_t *
579 sort_box (const panel_field_t * sort_format, int *reverse, int *case_sensitive, int *exec_first)
581 int dlg_width = 40, dlg_height = 7;
583 const char **sort_orders_names;
584 gsize sort_names_num;
586 int sort_idx = 0;
588 const panel_field_t *result = sort_format;
590 sort_orders_names = panel_get_sortable_fields (&sort_names_num);
591 dlg_height += sort_names_num;
594 int max_radio = 0, max_check = 0;
595 int ok_len, cancel_len;
596 gsize i;
598 QuickWidget quick_widgets[] = {
599 /* 0 */
600 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
601 /* 1 */
602 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
603 /* 2 */
604 QUICK_CHECKBOX (0, dlg_width, 5, dlg_height, N_("&Reverse"), reverse),
605 /* 3 */
606 QUICK_CHECKBOX (0, dlg_width, 4, dlg_height, N_("Case sensi&tive"), case_sensitive),
607 /* 4 */
608 QUICK_CHECKBOX (0, dlg_width, 3, dlg_height, N_("Executable &first"), exec_first),
609 /* 5 */
610 QUICK_RADIO (4, dlg_width, 3, dlg_height, 0,
611 NULL, &sort_idx),
612 QUICK_END
615 QuickDialog quick_dlg = {
616 dlg_width, dlg_height, -1, -1,
617 N_("Sort order"), "[Sort Order...]",
618 quick_widgets, NULL, TRUE
621 quick_widgets[5].u.radio.items = sort_orders_names;
622 quick_widgets[5].u.radio.count = sort_names_num;
624 for (i = 0; i < sort_names_num; i++)
625 if (strcmp (sort_orders_names[i], _(sort_format->title_hotkey)) == 0)
627 sort_idx = i;
628 break;
631 #ifdef ENABLE_NLS
632 quick_dlg.title = _(quick_dlg.title);
633 /* buttons */
634 for (i = 0; i < 2; i++)
635 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
636 /* checkboxes */
637 for (i = 2; i < 5; i++)
638 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
639 #endif /* ENABLE_NlS */
641 /* buttons */
642 cancel_len = str_term_width1 (quick_widgets[0].u.button.text) + 4;
643 ok_len = str_term_width1 (quick_widgets[1].u.button.text) + 6;
644 /* checkboxes */
645 for (i = 2; i < 5; i++)
646 max_check = max (max_check, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
647 /* radiobuttons */
648 for (i = 0; i < sort_names_num; i++)
649 max_radio = max (max_radio, str_term_width1 (sort_orders_names[i]) + 4);
651 /* dialog width */
652 dlg_width = max (dlg_width, str_term_width1 (quick_dlg.title) + 8);
653 dlg_width = max (dlg_width, ok_len + cancel_len + 8);
654 dlg_width = max (dlg_width, 2 * max (max_radio, max_check) + 8);
656 /* fix widget and dialog parameters */
657 /* dialog */
658 quick_dlg.xlen = dlg_width;
659 /* widgets */
660 for (i = 0; (size_t) i < sizeof (quick_widgets) / sizeof (quick_widgets[0]) - 1; i++)
661 quick_widgets[i].x_divisions = dlg_width;
662 /* buttons */
663 quick_widgets[0].relative_x = dlg_width * 2 / 3 - cancel_len / 2;
664 quick_widgets[1].relative_x = dlg_width / 3 - ok_len / 2;
665 /* checkboxes */
666 for (i = 2; i < 5; i++)
667 quick_widgets[i].relative_x = dlg_width / 2 + 2;
669 if (quick_dialog (&quick_dlg) != B_CANCEL)
670 result = panel_get_field_by_title_hotkey (sort_orders_names[sort_idx]);
672 if (result == NULL)
673 result = sort_format;
675 g_strfreev ((gchar **) sort_orders_names);
676 return result;
679 /* --------------------------------------------------------------------------------------------- */
681 void
682 confirm_box (void)
684 const char *title = _("Confirmation");
686 QuickWidget conf_widgets[] = {
687 /* 0 */ QUICK_BUTTON (29, 46, 10, 13, N_("&Cancel"), B_CANCEL, NULL),
688 /* 1 */ QUICK_BUTTON (12, 46, 10, 13, N_("&OK"), B_ENTER, NULL),
689 /* TRANSLATORS: no need to translate 'Confirmation', it's just a context prefix */
690 /* 2 */ QUICK_CHECKBOX (3, 46, 8, 13, N_("Confirmation|&History cleanup"),
691 &confirm_history_cleanup),
692 /* 3 */ QUICK_CHECKBOX (3, 46, 7, 13, N_("Confirmation|Di&rectory hotlist delete"),
693 &confirm_directory_hotlist_delete),
694 /* 4 */ QUICK_CHECKBOX (3, 46, 6, 13, N_("Confirmation|E&xit"), &confirm_exit),
695 /* 5 */ QUICK_CHECKBOX (3, 46, 5, 13, N_("Confirmation|&Execute"), &confirm_execute),
696 /* 6 */ QUICK_CHECKBOX (3, 46, 4, 13, N_("Confirmation|O&verwrite"), &confirm_overwrite),
697 /* 7 */ QUICK_CHECKBOX (3, 46, 3, 13, N_("Confirmation|&Delete"), &confirm_delete),
698 QUICK_END
701 const size_t w_num = sizeof (conf_widgets) / sizeof (conf_widgets[0]) - 1;
703 /* dialog sizes */
704 int dlg_width = 46;
705 int dlg_height = w_num + 5;
707 size_t i;
708 int maxlen = 0;
709 int cancel_len, ok_len, blen;
711 #ifdef ENABLE_NLS
712 title = _(title);
714 for (i = 0; i < 2; i++)
715 conf_widgets[i].u.button.text = _(conf_widgets[i].u.button.text);
716 #endif /* ENABLE_NLS */
718 for (i = 2; i < w_num; i++)
719 conf_widgets[i].u.checkbox.text = Q_ (conf_widgets[i].u.checkbox.text);
721 /* maximum length of checkboxes */
722 for (i = 2; i < w_num; i++)
723 maxlen = max (maxlen, str_term_width1 (conf_widgets[i].u.checkbox.text) + 4);
725 /* length of buttons */
726 cancel_len = str_term_width1 (conf_widgets[0].u.button.text) + 3;
727 ok_len = str_term_width1 (conf_widgets[1].u.button.text) + 5; /* default button */
729 blen = cancel_len + ok_len + 2;
731 dlg_width = max (maxlen, blen) + 6;
732 dlg_width = max (dlg_width, str_term_width1 (title) + 4);
734 /* correct widget parameters */
735 for (i = 0; i < w_num; i++)
737 conf_widgets[i].x_divisions = dlg_width;
738 conf_widgets[i].y_divisions = dlg_height;
741 conf_widgets[1].relative_x = dlg_width / 2 - blen / 2;
742 conf_widgets[0].relative_x = conf_widgets[1].relative_x + ok_len + 2;
745 QuickDialog confirmation = {
746 dlg_width, dlg_height, -1, -1, title,
747 "[Confirmation]", conf_widgets, NULL, TRUE
750 (void) quick_dialog (&confirmation);
754 /* --------------------------------------------------------------------------------------------- */
756 #ifndef HAVE_CHARSET
757 void
758 display_bits_box (void) /* AB:FIXME: test dialog */
760 /* dialog sizes */
761 const int DISPY = 13;
762 const int DISPX = 46;
764 int new_meta = 0;
765 int current_mode;
767 const char *display_bits_str[] = {
768 N_("UTF-8 output"),
769 N_("Full 8 bits output"),
770 N_("ISO 8859-1"),
771 N_("7 bits")
774 QuickWidget display_widgets[] = {
775 /* 0 */ QUICK_BUTTON (15, DISPX, DISPY - 3, DISPY, N_("&Cancel"), B_CANCEL, NULL),
776 /* 1 */ QUICK_BUTTON (29, DISPX, DISPY - 3, DISPY, N_("&OK"), B_ENTER, NULL),
777 /* 2 */ QUICK_CHECKBOX (3, DISPX, 8, DISPY, N_("F&ull 8 bits input"), &new_meta),
778 /* 3 */ QUICK_RADIO (3, DISPX, 3, DISPY, 4, display_bits_str, &current_mode),
779 QUICK_END
782 QuickDialog display_bits = {
783 DISPX, DISPY, -1, -1, _("Display bits"),
784 "[Display bits]", display_widgets, NULL, TRUE
787 int i;
788 int l1, maxlen = 0;
789 int ok_len, cancel_len;
791 #ifdef ENABLE_NLS
792 static gboolean i18n_flag = FALSE;
794 if (!i18n_flag)
796 for (i = 0; i < 3; i++)
798 display_bits_str[i] = _(display_bits_str[i]);
801 display_widgets[0].u.button.text = _(display_widgets[0].u.button.text);
802 display_widgets[1].u.button.text = _(display_widgets[1].u.button.text);
803 display_widgets[2].u.checkbox.text = _(display_widgets[2].u.checkbox.text);
805 i18n_flag = TRUE;
807 #endif /* ENABLE_NLS */
809 /* radiobuttons */
810 for (i = 0; i < 3; i++)
811 maxlen = max (maxlen, str_term_width1 (display_bits_str[i]));
813 /* buttons */
814 cancel_len = str_term_width1 (display_widgets[0].u.button.text) + 2;
815 ok_len = str_term_width1 (display_widgets[1].u.button.text) + 4; /* default button */
817 l1 = max (cancel_len, ok_len);
819 display_bits.xlen = max (maxlen, l1) + 20;
821 for (i = 0; i < 4; i++)
822 display_widgets[i].x_divisions = display_bits.xlen;
824 display_widgets[0].relative_x = display_bits.xlen * 2 / 3 - cancel_len / 2;
825 display_widgets[1].relative_x = display_bits.xlen / 3 - ok_len / 2;
827 if (full_eight_bits)
828 current_mode = 0;
829 else if (eight_bit_clean)
830 current_mode = 1;
831 else
832 current_mode = 2;
834 new_meta = !use_8th_bit_as_meta;
836 if (quick_dialog (&display_bits) != B_CANCEL)
838 eight_bit_clean = current_mode < 3;
839 full_eight_bits = current_mode < 2;
840 #ifndef HAVE_SLANG
841 meta (stdscr, eight_bit_clean);
842 #else
843 SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
844 #endif
845 use_8th_bit_as_meta = !new_meta;
849 /* --------------------------------------------------------------------------------------------- */
850 #else /* HAVE_CHARSET */
852 void
853 display_bits_box (void)
855 Dlg_head *dbits_dlg;
856 new_display_codepage = display_codepage;
858 application_keypad_mode ();
859 dbits_dlg = init_disp_bits_box ();
861 run_dlg (dbits_dlg);
863 if (dbits_dlg->ret_value == B_ENTER)
865 char *errmsg;
867 display_codepage = new_display_codepage;
868 errmsg = init_translation_table (source_codepage, display_codepage);
869 if (errmsg != NULL)
871 message (D_ERROR, MSG_ERROR, "%s", errmsg);
872 g_free (errmsg);
874 #ifdef HAVE_SLANG
875 tty_display_8bit (display_codepage != 0 && display_codepage != 1);
876 #else
877 tty_display_8bit (display_codepage != 0);
878 #endif
879 use_8th_bit_as_meta = !(inpcheck->state & C_BOOL);
881 destroy_dlg (dbits_dlg);
882 repaint_screen ();
884 #endif /* HAVE_CHARSET */
886 /* --------------------------------------------------------------------------------------------- */
887 /** Show tree in a box, not on a panel */
889 char *
890 tree_box (const char *current_dir)
892 WTree *mytree;
893 Dlg_head *dlg;
894 char *val = NULL;
895 WButtonBar *bar;
897 (void) current_dir;
899 /* Create the components */
900 dlg = create_dlg (TRUE, 0, 0, LINES - 9, COLS - 20, dialog_colors,
901 tree_callback, "[Directory Tree]",
902 _("Directory tree"), DLG_CENTER | DLG_REVERSE);
904 mytree = tree_new (2, 2, dlg->lines - 6, dlg->cols - 5, FALSE);
905 add_widget (dlg, mytree);
906 add_widget (dlg, hline_new (dlg->lines - 4, 1, -1));
907 bar = buttonbar_new (TRUE);
908 add_widget (dlg, bar);
909 /* restore ButtonBar coordinates after add_widget() */
910 ((Widget *) bar)->x = 0;
911 ((Widget *) bar)->y = LINES - 1;
913 if (run_dlg (dlg) == B_ENTER)
914 val = g_strdup (tree_selected_name (mytree));
916 destroy_dlg (dlg);
917 return val;
920 /* --------------------------------------------------------------------------------------------- */
922 #ifdef ENABLE_VFS
923 void
924 configure_vfs (void)
926 char buffer2[BUF_TINY];
927 #ifdef ENABLE_VFS_FTP
928 char buffer3[BUF_TINY];
929 #endif
931 QuickWidget confvfs_widgets[] = {
932 /* 0 */ QUICK_BUTTON (30, VFSX, VFSY - 3, VFSY, N_("&Cancel"), B_CANCEL, NULL),
933 /* 1 */ QUICK_BUTTON (12, VFSX, VFSY - 3, VFSY, N_("&OK"), B_ENTER, NULL),
934 #ifdef ENABLE_VFS_FTP
935 /* 2 */ QUICK_CHECKBOX (4, VFSX, 12, VFSY, N_("Use passive mode over pro&xy"),
936 &ftpfs_use_passive_connections_over_proxy),
937 /* 3 */ QUICK_CHECKBOX (4, VFSX, 11, VFSY, N_("Use &passive mode"),
938 &ftpfs_use_passive_connections),
939 /* 4 */ QUICK_CHECKBOX (4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), &ftpfs_use_netrc),
940 /* 5 */ QUICK_INPUT (4, VFSX, 9, VFSY, ftpfs_proxy_host, 48, 0, "input-ftp-proxy",
941 &ret_ftp_proxy),
942 /* 6 */ QUICK_CHECKBOX (4, VFSX, 8, VFSY, N_("&Always use ftp proxy"),
943 &ftpfs_always_use_proxy),
944 /* 7 */ QUICK_LABEL (49, VFSX, 7, VFSY, N_("sec")),
945 /* 8 */ QUICK_INPUT (38, VFSX, 7, VFSY, buffer3, 10, 0, "input-timeout",
946 &ret_directory_timeout),
947 /* 9 */ QUICK_LABEL (4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:")),
948 /* 10 */ QUICK_INPUT (4, VFSX, 6, VFSY, ftpfs_anonymous_passwd, 48, 0, "input-passwd",
949 &ret_passwd),
950 /* 11 */ QUICK_LABEL (4, VFSX, 5, VFSY, N_("ftp anonymous password:")),
951 #endif /* ENABLE_VFS_FTP */
952 /* 12 */ QUICK_LABEL (49, VFSX, 3, VFSY, N_("sec")),
953 /* 13 */ QUICK_INPUT (38, VFSX, 3, VFSY, buffer2, 10, 0, "input-timo-vfs", &ret_timeout),
954 /* 14 */ QUICK_LABEL (4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:")),
955 QUICK_END
958 QuickDialog confvfs_dlg = {
959 VFSX, VFSY, -1, -1, N_("Virtual File System Setting"),
960 "[Virtual FS]", confvfs_widgets,
961 #ifdef ENABLE_VFS_FTP
962 confvfs_callback,
963 #else
964 NULL,
965 #endif
966 FALSE
969 #ifdef ENABLE_VFS_FTP
970 g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
972 if (!ftpfs_always_use_proxy)
973 confvfs_widgets[5].options = W_DISABLED;
974 #endif
976 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
978 if (quick_dialog (&confvfs_dlg) != B_CANCEL)
980 vfs_timeout = atoi (ret_timeout);
981 g_free (ret_timeout);
983 if (vfs_timeout < 0 || vfs_timeout > 10000)
984 vfs_timeout = 10;
985 #ifdef ENABLE_VFS_FTP
986 g_free (ftpfs_anonymous_passwd);
987 ftpfs_anonymous_passwd = ret_passwd;
988 g_free (ftpfs_proxy_host);
989 ftpfs_proxy_host = ret_ftp_proxy;
990 ftpfs_directory_timeout = atoi (ret_directory_timeout);
991 g_free (ret_directory_timeout);
992 #endif
995 #undef VFSX
996 #undef VFSY
999 #endif /* ENABLE_VFS */
1001 /* --------------------------------------------------------------------------------------------- */
1003 char *
1004 cd_dialog (void)
1006 const char *label = N_("cd");
1007 const int ylen = 5;
1008 const int xlen = 57;
1010 int len;
1012 #ifdef ENABLE_NLS
1013 label = _(label);
1014 #endif
1016 len = str_term_width1 (label);
1019 char *my_str;
1021 QuickWidget quick_widgets[] = {
1022 /* 0 */ QUICK_INPUT (4 + len, xlen, 2, ylen, "", xlen - 7 - len, 2, "input", &my_str),
1023 /* 1 */ QUICK_LABEL (3, xlen, 2, ylen, label),
1024 QUICK_END
1027 QuickDialog Quick_input = {
1028 xlen, ylen, 2, LINES - 2 - ylen, _("Quick cd"),
1029 "[Quick cd]", quick_widgets, NULL, TRUE
1032 return (quick_dialog (&Quick_input) != B_CANCEL) ? my_str : NULL;
1036 /* --------------------------------------------------------------------------------------------- */
1038 void
1039 symlink_dialog (const char *existing, const char *new, char **ret_existing, char **ret_new)
1041 QuickWidget quick_widgets[] = {
1042 /* 0 */ QUICK_BUTTON (50, 80, 6, 8, N_("&Cancel"), B_CANCEL, NULL),
1043 /* 1 */ QUICK_BUTTON (16, 80, 6, 8, N_("&OK"), B_ENTER, NULL),
1044 /* 2 */ QUICK_INPUT (4, 80, 5, 8, new, 58, 0, "input-1", ret_new),
1045 /* 3 */ QUICK_LABEL (4, 80, 4, 8, N_("Symbolic link filename:")),
1046 /* 4 */ QUICK_INPUT (4, 80, 3, 8, existing, 58, 0, "input-2", ret_existing),
1047 /* 5 */ QUICK_LABEL (4, 80, 2, 8,
1048 N_("Existing filename (filename symlink will point to):")),
1049 QUICK_END
1052 QuickDialog Quick_input = {
1053 64, 12, -1, -1, N_("Symbolic link"),
1054 "[File Menu]", quick_widgets, NULL, FALSE
1057 if (quick_dialog (&Quick_input) == B_CANCEL)
1059 *ret_new = NULL;
1060 *ret_existing = NULL;
1064 /* --------------------------------------------------------------------------------------------- */
1066 #ifdef WITH_BACKGROUND
1067 void
1068 jobs_cmd (void)
1070 register int i;
1071 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
1073 #ifdef ENABLE_NLS
1074 static int i18n_flag = 0;
1075 if (!i18n_flag)
1077 int startx = job_buttons[0].xpos;
1078 int len;
1080 for (i = 0; i < n_buttons; i++)
1082 job_buttons[i].name = _(job_buttons[i].name);
1084 len = str_term_width1 (job_buttons[i].name) + 4;
1085 JOBS_X = max (JOBS_X, startx + len + 3);
1087 job_buttons[i].xpos = startx;
1088 startx += len;
1091 /* Last button - Ok a.k.a. Cancel :) */
1092 job_buttons[n_buttons - 1].xpos =
1093 JOBS_X - str_term_width1 (job_buttons[n_buttons - 1].name) - 7;
1095 i18n_flag = 1;
1097 #endif /* ENABLE_NLS */
1099 jobs_dlg = create_dlg (TRUE, 0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL,
1100 "[Background jobs]", _("Background Jobs"), DLG_CENTER | DLG_REVERSE);
1102 bg_list = listbox_new (2, 3, JOBS_Y - 9, JOBS_X - 7, FALSE, NULL);
1103 add_widget (jobs_dlg, bg_list);
1105 i = n_buttons;
1106 while (i--)
1108 add_widget (jobs_dlg, button_new (JOBS_Y - 4,
1109 job_buttons[i].xpos, job_buttons[i].value,
1110 NORMAL_BUTTON, job_buttons[i].name,
1111 job_buttons[i].callback));
1114 /* Insert all of task information in the list */
1115 jobs_fill_listbox ();
1116 run_dlg (jobs_dlg);
1118 destroy_dlg (jobs_dlg);
1120 #endif /* WITH_BACKGROUND */
1122 /* --------------------------------------------------------------------------------------------- */
1124 #ifdef ENABLE_VFS_SMB
1125 struct smb_authinfo *
1126 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, const char *user)
1128 static int dialog_x = 44;
1129 int b0 = 3, dialog_y = 12;
1130 static const char *lc_labs[] = { N_("Domain:"), N_("Username:"), N_("Password:") };
1131 static const char *buts[] = { N_("&OK"), N_("&Cancel") };
1132 static int ilen = 30, istart = 14;
1133 static int b2 = 30;
1134 char *title;
1135 WInput *in_password;
1136 WInput *in_user;
1137 WInput *in_domain;
1138 Dlg_head *auth_dlg;
1139 struct smb_authinfo *return_value = NULL;
1141 const int input_colors[3] = {
1142 INPUT_COLOR,
1143 INPUT_UNCHANGED_COLOR,
1144 INPUT_MARK_COLOR
1147 #ifdef ENABLE_NLS
1148 static int i18n_flag = 0;
1150 if (!i18n_flag)
1152 register int i = sizeof (lc_labs) / sizeof (lc_labs[0]);
1153 int l1, maxlen = 0;
1155 while (i--)
1157 l1 = str_term_width1 (lc_labs[i] = _(lc_labs[i]));
1158 if (l1 > maxlen)
1159 maxlen = l1;
1161 i = maxlen + ilen + 7;
1162 if (i > dialog_x)
1163 dialog_x = i;
1165 for (i = sizeof (buts) / sizeof (buts[0]), l1 = 0; i--;)
1167 l1 += str_term_width1 (buts[i] = _(buts[i]));
1169 l1 += 15;
1170 if (l1 > dialog_x)
1171 dialog_x = l1;
1173 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1174 istart = dialog_x - 3 - ilen;
1176 b2 = dialog_x - (str_term_width1 (buts[1]) + 6);
1178 i18n_flag = 1;
1181 #endif /* ENABLE_NLS */
1183 if (!domain)
1184 domain = "";
1185 if (!user)
1186 user = "";
1188 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1190 auth_dlg = create_dlg (TRUE, 0, 0, dialog_y, dialog_x, dialog_colors, NULL,
1191 "[Smb Authinfo]", title, DLG_CENTER | DLG_REVERSE);
1193 g_free (title);
1195 in_user =
1196 input_new (5, istart, input_get_default_colors (), ilen, user, "auth_name",
1197 INPUT_COMPLETE_DEFAULT);
1198 add_widget (auth_dlg, in_user);
1200 in_domain =
1201 input_new (3, istart, input_get_default_colors (), ilen, domain, "auth_domain",
1202 INPUT_COMPLETE_DEFAULT);
1204 add_widget (auth_dlg, in_domain);
1205 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON, buts[1], 0));
1206 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON, buts[0], 0));
1208 in_password =
1209 input_new (7, istart, input_get_default_colors (), ilen, "", "auth_password",
1210 INPUT_COMPLETE_DEFAULT);
1212 in_password->completion_flags = 0;
1213 in_password->is_password = 1;
1214 add_widget (auth_dlg, in_password);
1216 add_widget (auth_dlg, label_new (7, 3, lc_labs[2]));
1217 add_widget (auth_dlg, label_new (5, 3, lc_labs[1]));
1218 add_widget (auth_dlg, label_new (3, 3, lc_labs[0]));
1220 if (run_dlg (auth_dlg) != B_CANCEL)
1221 return_value = vfs_smb_authinfo_new (host, share, in_domain->buffer, in_user->buffer,
1222 in_password->buffer);
1224 destroy_dlg (auth_dlg);
1226 return return_value;
1228 #endif /* ENABLE_VFS_SMB */
1230 /* --------------------------------------------------------------------------------------------- */