Ticket #3493: user menu selector: make "User", not "Local", the focused button.
[midnight-commander.git] / src / filemanager / boxes.c
blobe153e5f8a648fd5b54235727450d76c0831bee91
1 /*
2 Some misc dialog boxes for the program.
4 Copyright (C) 1994-2015
5 Free Software Foundation, Inc.
7 Written by:
8 Miguel de Icaza, 1994, 1995
9 Jakub Jelinek, 1995
10 Andrew Borodin <aborodin@vmail.ru>, 2009-2015
12 This file is part of the Midnight Commander.
14 The Midnight Commander is free software: you can redistribute it
15 and/or modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation, either version 3 of the License,
17 or (at your option) any later version.
19 The Midnight Commander is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 /** \file boxes.c
29 * \brief Source: Some misc dialog boxes for the program
32 #include <config.h>
34 #include <ctype.h>
35 #include <signal.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <sys/types.h>
40 #include <sys/stat.h>
42 #include "lib/global.h"
44 #include "lib/tty/tty.h"
45 #include "lib/tty/key.h" /* XCTRL and ALT macros */
46 #include "lib/skin.h" /* INPUT_COLOR */
47 #include "lib/mcconfig.h" /* Load/save user formats */
48 #include "lib/strutil.h"
50 #include "lib/vfs/vfs.h"
51 #ifdef ENABLE_VFS_FTP
52 #include "src/vfs/ftpfs/ftpfs.h"
53 #endif /* ENABLE_VFS_FTP */
54 #ifdef ENABLE_VFS_SMB
55 #include "src/vfs/smbfs/smbfs.h"
56 #endif /* ENABLE_VFS_SMB */
58 #include "lib/util.h" /* Q_() */
59 #include "lib/widget.h"
61 #include "src/setup.h"
62 #include "src/history.h" /* MC_HISTORY_ESC_TIMEOUT */
63 #include "src/execute.h" /* pause_after_run */
64 #ifdef ENABLE_BACKGROUND
65 #include "src/background.h" /* task_list */
66 #endif
68 #ifdef HAVE_CHARSET
69 #include "lib/charsets.h"
70 #include "src/selcodepage.h"
71 #endif
73 #include "command.h" /* For cmdline */
74 #include "dir.h"
75 #include "panel.h" /* LIST_TYPES */
76 #include "tree.h"
77 #include "layout.h" /* for get_nth_panel_name proto */
78 #include "midnight.h" /* current_panel */
80 #include "boxes.h"
82 /*** global variables ****************************************************************************/
84 /*** file scope macro definitions ****************************************************************/
86 #ifdef ENABLE_BACKGROUND
87 #define B_STOP (B_USER+1)
88 #define B_RESUME (B_USER+2)
89 #define B_KILL (B_USER+3)
90 #endif /* ENABLE_BACKGROUND */
92 /*** file scope type declarations ****************************************************************/
94 /*** file scope variables ************************************************************************/
96 static unsigned long configure_old_esc_mode_id, configure_time_out_id;
98 /* Index in list_types[] for "brief" */
99 static const int panel_listing_brief_idx = 1;
100 /* Index in list_types[] for "user defined" */
101 static const int panel_listing_user_idx = 3;
103 static char **status_format;
104 static int listing_user_hotkey = 'u';
105 static unsigned long panel_listing_types_id, panel_user_format_id, panel_brief_cols_id;
106 static unsigned long mini_user_status_id, mini_user_format_id;
108 #ifdef HAVE_CHARSET
109 static int new_display_codepage;
110 #endif /* HAVE_CHARSET */
112 #if defined(ENABLE_VFS) && defined(ENABLE_VFS_FTP)
113 static unsigned long ftpfs_always_use_proxy_id, ftpfs_proxy_host_id;
114 #endif /* ENABLE_VFS && ENABLE_VFS_FTP */
116 static GPtrArray *skin_names;
117 static gchar *current_skin_name;
119 #ifdef ENABLE_BACKGROUND
120 static WListbox *bg_list = NULL;
121 #endif /* ENABLE_BACKGROUND */
123 /* --------------------------------------------------------------------------------------------- */
124 /*** file scope functions ************************************************************************/
125 /* --------------------------------------------------------------------------------------------- */
127 static cb_ret_t
128 configure_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
130 switch (msg)
132 case MSG_ACTION:
133 /* message from "Single press" checkbutton */
134 if (sender != NULL && sender->id == configure_old_esc_mode_id)
136 const gboolean not_single = !(CHECK (sender)->state & C_BOOL);
137 Widget *ww;
139 /* input line */
140 ww = dlg_find_by_id (DIALOG (w), configure_time_out_id);
141 widget_disable (ww, not_single);
143 return MSG_HANDLED;
145 return MSG_NOT_HANDLED;
147 default:
148 return dlg_default_callback (w, sender, msg, parm, data);
152 /* --------------------------------------------------------------------------------------------- */
154 static void
155 skin_apply (const gchar * skin_override)
157 GError *mcerror = NULL;
159 mc_skin_deinit ();
160 mc_skin_init (skin_override, &mcerror);
161 mc_fhl_free (&mc_filehighlight);
162 mc_filehighlight = mc_fhl_new (TRUE);
163 dlg_set_default_colors ();
164 input_set_default_colors ();
165 if (mc_global.mc_run_mode == MC_RUN_FULL)
166 command_set_default_colors ();
167 panel_deinit ();
168 panel_init ();
169 repaint_screen ();
171 mc_error_message (&mcerror, NULL);
174 /* --------------------------------------------------------------------------------------------- */
176 static const gchar *
177 skin_name_to_label (const gchar * name)
179 if (strcmp (name, "default") == 0)
180 return _("< Default >");
181 return name;
184 /* --------------------------------------------------------------------------------------------- */
186 static int
187 sel_skin_button (WButton * button, int action)
189 int result;
190 WListbox *skin_list;
191 WDialog *skin_dlg;
192 const gchar *skin_name;
193 int lxx, lyy;
194 unsigned int i;
195 unsigned int pos = 1;
197 (void) action;
199 lxx = COLS / 2;
200 lyy = (LINES - 13) / 2;
201 skin_dlg =
202 dlg_create (TRUE, lyy, lxx, 13, 24, dialog_colors, NULL, NULL, "[Appearance]", _("Skins"),
203 DLG_COMPACT);
205 skin_list = listbox_new (1, 1, 11, 22, FALSE, NULL);
206 skin_name = "default";
207 listbox_add_item (skin_list, LISTBOX_APPEND_AT_END, 0, skin_name_to_label (skin_name),
208 (void *) skin_name);
210 if (strcmp (skin_name, current_skin_name) == 0)
211 listbox_select_entry (skin_list, 0);
213 for (i = 0; i < skin_names->len; i++)
215 skin_name = g_ptr_array_index (skin_names, i);
216 if (strcmp (skin_name, "default") != 0)
218 listbox_add_item (skin_list, LISTBOX_APPEND_AT_END, 0, skin_name_to_label (skin_name),
219 (void *) skin_name);
220 if (strcmp (skin_name, current_skin_name) == 0)
221 listbox_select_entry (skin_list, pos);
222 pos++;
226 add_widget (skin_dlg, skin_list);
228 result = dlg_run (skin_dlg);
229 if (result == B_ENTER)
231 gchar *skin_label;
233 listbox_get_current (skin_list, &skin_label, (void **) &skin_name);
234 g_free (current_skin_name);
235 current_skin_name = g_strdup (skin_name);
236 skin_apply (skin_name);
238 button_set_text (button, str_fit_to_term (skin_label, 20, J_LEFT_FIT));
240 dlg_destroy (skin_dlg);
242 return 0;
245 /* --------------------------------------------------------------------------------------------- */
247 static cb_ret_t
248 panel_listing_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
250 WDialog *h = DIALOG (w);
252 switch (msg)
254 case MSG_KEY:
255 if (parm == '\n')
257 Widget *wi;
259 wi = dlg_find_by_id (h, panel_listing_types_id);
260 if (widget_is_active (wi))
262 WInput *in;
264 in = INPUT (dlg_find_by_id (h, mini_user_format_id));
265 input_assign_text (in, status_format[RADIO (wi)->sel]);
266 dlg_stop (h);
267 return MSG_HANDLED;
270 wi = dlg_find_by_id (h, panel_user_format_id);
271 if (widget_is_active (wi))
273 h->ret_value = B_USER + 6;
274 dlg_stop (h);
275 return MSG_HANDLED;
278 wi = dlg_find_by_id (h, mini_user_format_id);
279 if (widget_is_active (wi))
281 h->ret_value = B_USER + 7;
282 dlg_stop (h);
283 return MSG_HANDLED;
287 if (g_ascii_tolower (parm) == listing_user_hotkey)
289 Widget *wi;
291 wi = dlg_find_by_id (h, panel_user_format_id);
292 if (widget_is_active (wi))
294 wi = dlg_find_by_id (h, mini_user_format_id);
295 if (widget_is_active (wi))
297 WRadio *r;
299 r = RADIO (dlg_find_by_id (h, panel_listing_types_id));
300 r->pos = r->sel = panel_listing_user_idx;
301 dlg_select_widget (WIDGET (r)); /* force redraw */
302 send_message (h, r, MSG_ACTION, 0, NULL);
303 return MSG_HANDLED;
307 return MSG_NOT_HANDLED;
309 case MSG_ACTION:
310 if (sender != NULL && sender->id == panel_listing_types_id)
312 WCheck *ch;
313 WInput *in1, *in2, *in3;
315 in1 = INPUT (dlg_find_by_id (h, panel_user_format_id));
316 in2 = INPUT (dlg_find_by_id (h, panel_brief_cols_id));
317 ch = CHECK (dlg_find_by_id (h, mini_user_status_id));
318 in3 = INPUT (dlg_find_by_id (h, mini_user_format_id));
320 if (!(ch->state & C_BOOL))
321 input_assign_text (in3, status_format[RADIO (sender)->sel]);
322 input_update (in1, FALSE);
323 input_update (in2, FALSE);
324 input_update (in3, FALSE);
325 widget_disable (WIDGET (in1), RADIO (sender)->sel != panel_listing_user_idx);
326 widget_disable (WIDGET (in2), RADIO (sender)->sel != panel_listing_brief_idx);
327 return MSG_HANDLED;
330 if (sender != NULL && sender->id == mini_user_status_id)
332 WInput *in;
334 in = INPUT (dlg_find_by_id (h, mini_user_format_id));
336 if (CHECK (sender)->state & C_BOOL)
338 widget_disable (WIDGET (in), FALSE);
339 input_assign_text (in, status_format[3]);
341 else
343 WRadio *r;
345 r = RADIO (dlg_find_by_id (h, panel_listing_types_id));
346 widget_disable (WIDGET (in), TRUE);
347 input_assign_text (in, status_format[r->sel]);
349 /* input_update (in, FALSE); */
350 return MSG_HANDLED;
353 return MSG_NOT_HANDLED;
355 default:
356 return dlg_default_callback (w, sender, msg, parm, data);
360 /* --------------------------------------------------------------------------------------------- */
362 #ifdef HAVE_CHARSET
363 static int
364 sel_charset_button (WButton * button, int action)
366 int new_dcp;
368 (void) action;
370 new_dcp = select_charset (-1, -1, new_display_codepage, TRUE);
372 if (new_dcp != SELECT_CHARSET_CANCEL)
374 const char *cpname;
376 new_display_codepage = new_dcp;
377 cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
378 _("Other 8 bit") :
379 ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
380 if (cpname != NULL)
381 mc_global.utf8_display = str_isutf8 (cpname);
382 else
383 cpname = _("7-bit ASCII"); /* FIXME */
385 button_set_text (button, cpname);
386 dlg_redraw (WIDGET (button)->owner);
389 return 0;
391 #endif /* HAVE_CHARSET */
393 /* --------------------------------------------------------------------------------------------- */
395 static cb_ret_t
396 tree_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
398 WDialog *h = DIALOG (w);
400 switch (msg)
402 case MSG_RESIZE:
404 Widget *bar;
406 /* simply call dlg_set_size() with new size */
407 dlg_set_size (h, LINES - 9, COLS - 20);
408 bar = WIDGET (find_buttonbar (h));
409 bar->x = 0;
410 bar->y = LINES - 1;
411 return MSG_HANDLED;
414 case MSG_ACTION:
415 return send_message (find_tree (h), NULL, MSG_ACTION, parm, NULL);
417 default:
418 return dlg_default_callback (w, sender, msg, parm, data);
422 /* --------------------------------------------------------------------------------------------- */
424 #if defined(ENABLE_VFS) && defined (ENABLE_VFS_FTP)
425 static cb_ret_t
426 confvfs_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
428 switch (msg)
430 case MSG_ACTION:
431 /* message from "Always use ftp proxy" checkbutton */
432 if (sender != NULL && sender->id == ftpfs_always_use_proxy_id)
434 const gboolean not_use = !(CHECK (sender)->state & C_BOOL);
435 Widget *wi;
437 /* input */
438 wi = dlg_find_by_id (DIALOG (w), ftpfs_proxy_host_id);
439 widget_disable (wi, not_use);
440 return MSG_HANDLED;
442 return MSG_NOT_HANDLED;
444 default:
445 return dlg_default_callback (w, sender, msg, parm, data);
448 #endif /* ENABLE_VFS && ENABLE_VFS_FTP */
450 /* --------------------------------------------------------------------------------------------- */
452 #ifdef ENABLE_BACKGROUND
453 static void
454 jobs_fill_listbox (WListbox * list)
456 static const char *state_str[2] = { "", "" };
457 TaskList *tl;
459 if (state_str[0] == '\0')
461 state_str[0] = _("Running");
462 state_str[1] = _("Stopped");
465 for (tl = task_list; tl != NULL; tl = tl->next)
467 char *s;
469 s = g_strconcat (state_str[tl->state], " ", tl->info, (char *) NULL);
470 listbox_add_item (list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
471 g_free (s);
475 /* --------------------------------------------------------------------------------------------- */
477 static int
478 task_cb (WButton * button, int action)
480 TaskList *tl;
481 int sig = 0;
483 (void) button;
485 if (bg_list->list == NULL)
486 return 0;
488 /* Get this instance information */
489 listbox_get_current (bg_list, NULL, (void **) &tl);
491 #ifdef SIGTSTP
492 if (action == B_STOP)
494 sig = SIGSTOP;
495 tl->state = Task_Stopped;
497 else if (action == B_RESUME)
499 sig = SIGCONT;
500 tl->state = Task_Running;
502 else
503 #endif
504 if (action == B_KILL)
505 sig = SIGKILL;
507 if (sig == SIGKILL)
508 unregister_task_running (tl->pid, tl->fd);
510 kill (tl->pid, sig);
511 listbox_remove_list (bg_list);
512 jobs_fill_listbox (bg_list);
514 /* This can be optimized to just redraw this widget :-) */
515 dlg_redraw (WIDGET (button)->owner);
517 return 0;
519 #endif /* ENABLE_BACKGROUND */
521 /* --------------------------------------------------------------------------------------------- */
522 /*** public functions ****************************************************************************/
523 /* --------------------------------------------------------------------------------------------- */
525 void
526 configure_box (void)
528 const char *pause_options[] = {
529 N_("&Never"),
530 N_("On dum&b terminals"),
531 N_("Alwa&ys")
534 int pause_options_num;
536 pause_options_num = G_N_ELEMENTS (pause_options);
539 char time_out[BUF_TINY] = "";
540 char *time_out_new;
542 quick_widget_t quick_widgets[] = {
543 /* *INDENT-OFF* */
544 QUICK_START_COLUMNS,
545 QUICK_START_GROUPBOX (N_("File operations")),
546 QUICK_CHECKBOX (N_("&Verbose operation"), &verbose, NULL),
547 QUICK_CHECKBOX (N_("Compute tota&ls"), &file_op_compute_totals, NULL),
548 QUICK_CHECKBOX (N_("Classic pro&gressbar"), &classic_progressbar, NULL),
549 QUICK_CHECKBOX (N_("Mkdi&r autoname"), &auto_fill_mkdir_name, NULL),
550 QUICK_CHECKBOX (N_("&Preallocate space"), &mc_global.vfs.preallocate_space,
551 NULL),
552 QUICK_STOP_GROUPBOX,
553 QUICK_START_GROUPBOX (N_("Esc key mode")),
554 QUICK_CHECKBOX (N_("S&ingle press"), &old_esc_mode, &configure_old_esc_mode_id),
555 QUICK_LABELED_INPUT (N_("Timeout:"), input_label_left,
556 (const char *) time_out, MC_HISTORY_ESC_TIMEOUT,
557 &time_out_new, &configure_time_out_id, FALSE, FALSE,
558 INPUT_COMPLETE_NONE),
559 QUICK_STOP_GROUPBOX,
560 QUICK_START_GROUPBOX (N_("Pause after run")),
561 QUICK_RADIO (pause_options_num, pause_options, &pause_after_run, NULL),
562 QUICK_STOP_GROUPBOX,
563 QUICK_NEXT_COLUMN,
564 QUICK_START_GROUPBOX (N_("Other options")),
565 QUICK_CHECKBOX (N_("Use internal edi&t"), &use_internal_edit, NULL),
566 QUICK_CHECKBOX (N_("Use internal vie&w"), &use_internal_view, NULL),
567 QUICK_CHECKBOX (N_("A&sk new file name"),
568 &editor_ask_filename_before_edit, NULL),
569 QUICK_CHECKBOX (N_("Auto m&enus"), &auto_menu, NULL),
570 QUICK_CHECKBOX (N_("&Drop down menus"), &drop_menus, NULL),
571 QUICK_CHECKBOX (N_("S&hell patterns"), &easy_patterns, NULL),
572 QUICK_CHECKBOX (N_("Co&mplete: show all"),
573 &mc_global.widget.show_all_if_ambiguous, NULL),
574 QUICK_CHECKBOX (N_("Rotating d&ash"), &nice_rotating_dash, NULL),
575 QUICK_CHECKBOX (N_("Cd follows lin&ks"), &mc_global.vfs.cd_symlinks, NULL),
576 QUICK_CHECKBOX (N_("Sa&fe delete"), &safe_delete, NULL),
577 QUICK_CHECKBOX (N_("A&uto save setup"), &auto_save_setup, NULL),
578 QUICK_SEPARATOR (FALSE),
579 QUICK_SEPARATOR (FALSE),
580 QUICK_SEPARATOR (FALSE),
581 QUICK_STOP_GROUPBOX,
582 QUICK_STOP_COLUMNS,
583 QUICK_BUTTONS_OK_CANCEL,
584 QUICK_END
585 /* *INDENT-ON* */
588 quick_dialog_t qdlg = {
589 -1, -1, 60,
590 N_("Configure options"), "[Configuration]",
591 quick_widgets, configure_callback, NULL
594 g_snprintf (time_out, sizeof (time_out), "%d", old_esc_mode_timeout);
596 #ifndef USE_INTERNAL_EDIT
597 quick_widgets[17].options = W_DISABLED;
598 #endif
600 if (!old_esc_mode)
601 quick_widgets[10].options = quick_widgets[11].options = W_DISABLED;
603 #ifndef HAVE_POSIX_FALLOCATE
604 mc_global.vfs.preallocate_space = FALSE;
605 quick_widgets[7].options = W_DISABLED;
606 #endif
608 if (quick_dialog (&qdlg) == B_ENTER)
609 old_esc_mode_timeout = atoi (time_out_new);
611 g_free (time_out_new);
615 /* --------------------------------------------------------------------------------------------- */
617 void
618 appearance_box (void)
620 current_skin_name = g_strdup (mc_skin__default.name);
621 skin_names = mc_skin_list ();
624 quick_widget_t quick_widgets[] = {
625 /* *INDENT-OFF* */
626 QUICK_START_COLUMNS,
627 QUICK_LABEL (N_("Skin:"), NULL),
628 QUICK_NEXT_COLUMN,
629 QUICK_BUTTON (str_fit_to_term (skin_name_to_label (current_skin_name), 20, J_LEFT_FIT),
630 B_USER, sel_skin_button, NULL),
631 QUICK_STOP_COLUMNS,
632 QUICK_BUTTONS_OK_CANCEL,
633 QUICK_END
634 /* *INDENT-ON* */
637 quick_dialog_t qdlg = {
638 -1, -1, 54,
639 N_("Appearance"), "[Appearance]",
640 quick_widgets, dlg_default_callback, NULL
643 if (quick_dialog (&qdlg) == B_ENTER)
644 mc_config_set_string (mc_main_config, CONFIG_APP_SECTION, "skin", current_skin_name);
645 else
646 skin_apply (NULL);
649 g_free (current_skin_name);
650 g_ptr_array_foreach (skin_names, (GFunc) g_free, NULL);
651 g_ptr_array_free (skin_names, TRUE);
654 /* --------------------------------------------------------------------------------------------- */
656 void
657 panel_options_box (void)
659 int simple_swap;
661 simple_swap = mc_config_get_bool (mc_main_config, CONFIG_PANELS_SECTION,
662 "simple_swap", FALSE) ? 1 : 0;
664 const char *qsearch_options[] = {
665 N_("Case &insensitive"),
666 N_("Cas&e sensitive"),
667 N_("Use panel sort mo&de")
670 quick_widget_t quick_widgets[] = {
671 /* *INDENT-OFF* */
672 QUICK_START_COLUMNS,
673 QUICK_START_GROUPBOX (N_("Main options")),
674 QUICK_CHECKBOX (N_("Show mi&ni-status"), &panels_options.show_mini_info, NULL),
675 QUICK_CHECKBOX (N_("Use SI si&ze units"), &panels_options.kilobyte_si, NULL),
676 QUICK_CHECKBOX (N_("Mi&x all files"), &panels_options.mix_all_files, NULL),
677 QUICK_CHECKBOX (N_("Show &backup files"), &panels_options.show_backups, NULL),
678 QUICK_CHECKBOX (N_("Show &hidden files"), &panels_options.show_dot_files, NULL),
679 QUICK_CHECKBOX (N_("&Fast dir reload"), &panels_options.fast_reload, NULL),
680 QUICK_CHECKBOX (N_("Ma&rk moves down"), &panels_options.mark_moves_down, NULL),
681 QUICK_CHECKBOX (N_("Re&verse files only"), &panels_options.reverse_files_only,
682 NULL),
683 QUICK_CHECKBOX (N_("Simple s&wap"), &simple_swap, NULL),
684 QUICK_CHECKBOX (N_("A&uto save panels setup"), &panels_options.auto_save_setup,
685 NULL),
686 QUICK_SEPARATOR (FALSE),
687 QUICK_SEPARATOR (FALSE),
688 QUICK_STOP_GROUPBOX,
689 QUICK_NEXT_COLUMN,
690 QUICK_START_GROUPBOX (N_("Navigation")),
691 QUICK_CHECKBOX (N_("L&ynx-like motion"), &panels_options.navigate_with_arrows,
692 NULL),
693 QUICK_CHECKBOX (N_("Pa&ge scrolling"), &panels_options.scroll_pages, NULL),
694 QUICK_CHECKBOX (N_("&Mouse page scrolling"), &panels_options.mouse_move_pages,
695 NULL),
696 QUICK_STOP_GROUPBOX,
697 QUICK_START_GROUPBOX (N_("File highlight")),
698 QUICK_CHECKBOX (N_("File &types"), &panels_options.filetype_mode, NULL),
699 QUICK_CHECKBOX (N_("&Permissions"), &panels_options.permission_mode, NULL),
700 QUICK_STOP_GROUPBOX,
701 QUICK_START_GROUPBOX (N_("Quick search")),
702 QUICK_RADIO (QSEARCH_NUM, qsearch_options, (int *) &panels_options.qsearch_mode,
703 NULL),
704 QUICK_STOP_GROUPBOX,
705 QUICK_STOP_COLUMNS,
706 QUICK_BUTTONS_OK_CANCEL,
707 QUICK_END
708 /* *INDENT-ON* */
711 quick_dialog_t qdlg = {
712 -1, -1, 60,
713 N_("Panel options"), "[Panel options]",
714 quick_widgets, NULL, NULL
717 if (quick_dialog (&qdlg) != B_ENTER)
718 return;
721 mc_config_set_bool (mc_main_config, CONFIG_PANELS_SECTION,
722 "simple_swap", (gboolean) (simple_swap & C_BOOL));
724 if (!panels_options.fast_reload_msg_shown && panels_options.fast_reload)
726 message (D_NORMAL, _("Information"),
727 _("Using the fast reload option may not reflect the exact\n"
728 "directory contents. In this case you'll need to do a\n"
729 "manual reload of the directory. See the man page for\n" "the details."));
730 panels_options.fast_reload_msg_shown = TRUE;
733 update_panels (UP_RELOAD, UP_KEEPSEL);
736 /* --------------------------------------------------------------------------------------------- */
738 /* return list type */
740 panel_listing_box (WPanel * panel, int num, char **userp, char **minip, int *use_msformat,
741 int *brief_cols)
743 int result = -1;
744 char *section = NULL;
746 if (panel == NULL)
748 const char *p;
749 size_t i;
751 p = get_nth_panel_name (num);
752 panel = g_new (WPanel, 1);
753 panel->list_type = list_full;
754 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
755 panel->user_mini_status = 0;
756 for (i = 0; i < LIST_TYPES; i++)
757 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
758 section = g_strconcat ("Temporal:", p, (char *) NULL);
759 if (!mc_config_has_group (mc_main_config, section))
761 g_free (section);
762 section = g_strdup (p);
764 panel_load_setup (panel, section);
765 g_free (section);
769 int mini_user_status;
770 char panel_brief_cols_in[BUF_TINY];
771 char *panel_brief_cols_out = NULL;
772 char *panel_user_format = NULL;
773 char *mini_user_format = NULL;
774 const char *cp;
776 /* Controls whether the array strings have been translated */
777 const char *list_types[LIST_TYPES] = {
778 N_("&Full file list"),
779 N_("&Brief file list:"),
780 N_("&Long file list"),
781 N_("&User defined:")
784 quick_widget_t quick_widgets[] = {
785 /* *INDENT-OFF* */
786 QUICK_START_COLUMNS,
787 QUICK_RADIO (LIST_TYPES, list_types, &result, &panel_listing_types_id),
788 QUICK_NEXT_COLUMN,
789 QUICK_SEPARATOR (FALSE),
790 QUICK_LABELED_INPUT (_ ("columns"), input_label_right, panel_brief_cols_in,
791 "panel-brief-cols-input", &panel_brief_cols_out,
792 &panel_brief_cols_id, FALSE, FALSE, INPUT_COMPLETE_NONE),
793 QUICK_STOP_COLUMNS,
794 QUICK_INPUT (panel->user_format, "user-fmt-input", &panel_user_format,
795 &panel_user_format_id, FALSE, FALSE, INPUT_COMPLETE_NONE),
796 QUICK_SEPARATOR (TRUE),
797 QUICK_CHECKBOX (N_("User &mini status"), &mini_user_status, &mini_user_status_id),
798 QUICK_INPUT (panel->user_status_format[panel->list_type], "mini_input",
799 &mini_user_format, &mini_user_format_id, FALSE, FALSE, INPUT_COMPLETE_NONE),
800 QUICK_BUTTONS_OK_CANCEL,
801 QUICK_END
802 /* *INDENT-ON* */
805 quick_dialog_t qdlg = {
806 -1, -1, 48,
807 N_("Listing mode"), "[Listing Mode...]",
808 quick_widgets, panel_listing_callback, NULL
811 /* get hotkey of user-defined format string */
812 cp = strchr (_(list_types[panel_listing_user_idx]), '&');
813 if (cp != NULL && *++cp != '\0')
814 listing_user_hotkey = g_ascii_tolower (*cp);
816 mini_user_status = panel->user_mini_status;
817 result = panel->list_type;
818 status_format = panel->user_status_format;
820 g_snprintf (panel_brief_cols_in, sizeof (panel_brief_cols_in), "%d", panel->brief_cols);
822 if ((int) panel->list_type != panel_listing_brief_idx)
823 quick_widgets[4].options = W_DISABLED;
825 if ((int) panel->list_type != panel_listing_user_idx)
826 quick_widgets[6].options = W_DISABLED;
828 if (!mini_user_status)
829 quick_widgets[9].options = W_DISABLED;
831 if (quick_dialog (&qdlg) == B_CANCEL)
832 result = -1;
833 else
835 int cols;
836 char *error = NULL;
838 *userp = panel_user_format;
839 *minip = mini_user_format;
840 *use_msformat = mini_user_status;
842 cols = strtol (panel_brief_cols_out, &error, 10);
843 if (*error == '\0')
844 *brief_cols = cols;
845 else
846 *brief_cols = panel->brief_cols;
848 g_free (panel_brief_cols_out);
852 if (section != NULL)
854 int i;
856 g_free (panel->user_format);
857 for (i = 0; i < LIST_TYPES; i++)
858 g_free (panel->user_status_format[i]);
859 g_free (panel);
862 return result;
865 /* --------------------------------------------------------------------------------------------- */
867 const panel_field_t *
868 sort_box (dir_sort_options_t * op, const panel_field_t * sort_field)
870 const char **sort_orders_names;
871 gsize sort_names_num, i;
872 int sort_idx = 0;
873 const panel_field_t *result = NULL;
875 sort_orders_names = panel_get_sortable_fields (&sort_names_num);
877 for (i = 0; i < sort_names_num; i++)
878 if (strcmp (sort_orders_names[i], _(sort_field->title_hotkey)) == 0)
880 sort_idx = i;
881 break;
885 quick_widget_t quick_widgets[] = {
886 /* *INDENT-OFF* */
887 QUICK_START_COLUMNS,
888 QUICK_RADIO (sort_names_num, sort_orders_names, &sort_idx, NULL),
889 QUICK_NEXT_COLUMN,
890 QUICK_CHECKBOX (N_("Executable &first"), &op->exec_first, NULL),
891 QUICK_CHECKBOX (N_("Cas&e sensitive"), &op->case_sensitive, NULL),
892 QUICK_CHECKBOX (N_("&Reverse"), &op->reverse, NULL),
893 QUICK_STOP_COLUMNS,
894 QUICK_BUTTONS_OK_CANCEL,
895 QUICK_END
896 /* *INDENT-ON* */
899 quick_dialog_t qdlg = {
900 -1, -1, 40,
901 N_("Sort order"), "[Sort Order...]",
902 quick_widgets, NULL, NULL
905 if (quick_dialog (&qdlg) != B_CANCEL)
906 result = panel_get_field_by_title_hotkey (sort_orders_names[sort_idx]);
908 if (result == NULL)
909 result = sort_field;
912 g_strfreev ((gchar **) sort_orders_names);
914 return result;
917 /* --------------------------------------------------------------------------------------------- */
919 void
920 confirm_box (void)
922 quick_widget_t quick_widgets[] = {
923 /* *INDENT-OFF* */
924 /* TRANSLATORS: no need to translate 'Confirmation', it's just a context prefix */
925 QUICK_CHECKBOX (Q_("Confirmation|&Delete"), &confirm_delete, NULL),
926 QUICK_CHECKBOX (Q_("Confirmation|O&verwrite"), &confirm_overwrite, NULL),
927 QUICK_CHECKBOX (Q_("Confirmation|&Execute"), &confirm_execute, NULL),
928 QUICK_CHECKBOX (Q_("Confirmation|E&xit"), &confirm_exit, NULL),
929 QUICK_CHECKBOX (Q_("Confirmation|Di&rectory hotlist delete"),
930 &confirm_directory_hotlist_delete, NULL),
931 QUICK_CHECKBOX (Q_("Confirmation|&History cleanup"),
932 &mc_global.widget.confirm_history_cleanup, NULL),
933 QUICK_BUTTONS_OK_CANCEL,
934 QUICK_END
935 /* *INDENT-ON* */
938 quick_dialog_t qdlg = {
939 -1, -1, 46,
940 N_("Confirmation"), "[Confirmation]",
941 quick_widgets, NULL, NULL
944 (void) quick_dialog (&qdlg);
947 /* --------------------------------------------------------------------------------------------- */
949 #ifndef HAVE_CHARSET
950 void
951 display_bits_box (void)
953 int new_meta;
954 int current_mode;
956 const char *display_bits_str[] = {
957 N_("&UTF-8 output"),
958 N_("&Full 8 bits output"),
959 N_("&ISO 8859-1"),
960 N_("7 &bits")
963 quick_widget_t quick_widgets[] = {
964 /* *INDENT-OFF* */
965 QUICK_RADIO (4, display_bits_str, &current_mode, NULL),
966 QUICK_SEPARATOR (TRUE),
967 QUICK_CHECKBOX (N_("F&ull 8 bits input"), &new_meta, NULL),
968 QUICK_BUTTONS_OK_CANCEL,
969 QUICK_END
970 /* *INDENT-ON* */
973 quick_dialog_t qdlg = {
974 -1, -1, 46,
975 _("Display bits"), "[Display bits]",
976 quick_widgets, NULL, NULL
979 if (mc_global.full_eight_bits)
980 current_mode = 0;
981 else if (mc_global.eight_bit_clean)
982 current_mode = 1;
983 else
984 current_mode = 2;
986 new_meta = !use_8th_bit_as_meta;
988 if (quick_dialog (&qdlg) != B_CANCEL)
990 mc_global.eight_bit_clean = current_mode < 3;
991 mc_global.full_eight_bits = current_mode < 2;
992 #ifndef HAVE_SLANG
993 meta (stdscr, mc_global.eight_bit_clean);
994 #else
995 SLsmg_Display_Eight_Bit = mc_global.full_eight_bits ? 128 : 160;
996 #endif
997 use_8th_bit_as_meta = !new_meta;
1001 /* --------------------------------------------------------------------------------------------- */
1002 #else /* HAVE_CHARSET */
1004 void
1005 display_bits_box (void)
1007 const char *cpname;
1009 new_display_codepage = mc_global.display_codepage;
1011 cpname = (new_display_codepage < 0) ? _("Other 8 bit")
1012 : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
1015 int new_meta;
1017 quick_widget_t quick_widgets[] = {
1018 /* *INDENT-OFF* */
1019 QUICK_START_COLUMNS,
1020 QUICK_LABEL (N_("Input / display codepage:"), NULL),
1021 QUICK_NEXT_COLUMN,
1022 QUICK_BUTTON (cpname, B_USER, sel_charset_button, NULL),
1023 QUICK_STOP_COLUMNS,
1024 QUICK_SEPARATOR (TRUE),
1025 QUICK_CHECKBOX (N_("F&ull 8 bits input"), &new_meta, NULL),
1026 QUICK_BUTTONS_OK_CANCEL,
1027 QUICK_END
1028 /* *INDENT-ON* */
1031 quick_dialog_t qdlg = {
1032 -1, -1, 46,
1033 N_("Display bits"), "[Display bits]",
1034 quick_widgets, NULL, NULL
1037 new_meta = !use_8th_bit_as_meta;
1038 application_keypad_mode ();
1040 if (quick_dialog (&qdlg) == B_ENTER)
1042 char *errmsg;
1044 mc_global.display_codepage = new_display_codepage;
1046 errmsg = init_translation_table (mc_global.source_codepage, mc_global.display_codepage);
1047 if (errmsg != NULL)
1049 message (D_ERROR, MSG_ERROR, "%s", errmsg);
1050 g_free (errmsg);
1053 #ifdef HAVE_SLANG
1054 tty_display_8bit (mc_global.display_codepage != 0 && mc_global.display_codepage != 1);
1055 #else
1056 tty_display_8bit (mc_global.display_codepage != 0);
1057 #endif
1058 use_8th_bit_as_meta = !new_meta;
1060 repaint_screen ();
1064 #endif /* HAVE_CHARSET */
1066 /* --------------------------------------------------------------------------------------------- */
1067 /** Show tree in a box, not on a panel */
1069 char *
1070 tree_box (const char *current_dir)
1072 WTree *mytree;
1073 WDialog *dlg;
1074 Widget *wd;
1075 char *val = NULL;
1076 WButtonBar *bar;
1078 (void) current_dir;
1080 /* Create the components */
1081 dlg = dlg_create (TRUE, 0, 0, LINES - 9, COLS - 20, dialog_colors, tree_callback, NULL,
1082 "[Directory Tree]", _("Directory tree"), DLG_CENTER);
1083 wd = WIDGET (dlg);
1085 mytree = tree_new (2, 2, wd->lines - 6, wd->cols - 5, FALSE);
1086 add_widget_autopos (dlg, mytree, WPOS_KEEP_ALL, NULL);
1087 add_widget_autopos (dlg, hline_new (wd->lines - 4, 1, -1), WPOS_KEEP_BOTTOM, NULL);
1088 bar = buttonbar_new (TRUE);
1089 add_widget (dlg, bar);
1090 /* restore ButtonBar coordinates after add_widget() */
1091 WIDGET (bar)->x = 0;
1092 WIDGET (bar)->y = LINES - 1;
1094 if (dlg_run (dlg) == B_ENTER)
1096 const vfs_path_t *selected_name;
1097 selected_name = tree_selected_name (mytree);
1098 val = g_strdup (vfs_path_as_str (selected_name));
1101 dlg_destroy (dlg);
1102 return val;
1105 /* --------------------------------------------------------------------------------------------- */
1107 #ifdef ENABLE_VFS
1108 void
1109 configure_vfs (void)
1111 char buffer2[BUF_TINY];
1112 #ifdef ENABLE_VFS_FTP
1113 char buffer3[BUF_TINY];
1115 g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
1116 #endif
1118 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
1121 char *ret_timeout;
1122 #ifdef ENABLE_VFS_FTP
1123 char *ret_passwd;
1124 char *ret_ftp_proxy;
1125 char *ret_directory_timeout;
1126 #endif /* ENABLE_VFS_FTP */
1128 quick_widget_t quick_widgets[] = {
1129 /* *INDENT-OFF* */
1130 QUICK_LABELED_INPUT (N_("Timeout for freeing VFSs (sec):"), input_label_left,
1131 buffer2, "input-timo-vfs", &ret_timeout, NULL, FALSE, FALSE,
1132 INPUT_COMPLETE_NONE),
1133 #ifdef ENABLE_VFS_FTP
1134 QUICK_SEPARATOR (TRUE),
1135 QUICK_LABELED_INPUT (N_("FTP anonymous password:"), input_label_left,
1136 ftpfs_anonymous_passwd, "input-passwd", &ret_passwd, NULL,
1137 FALSE, FALSE, INPUT_COMPLETE_NONE),
1138 QUICK_LABELED_INPUT (N_("FTP directory cache timeout (sec):"), input_label_left,
1139 buffer3, "input-timeout", &ret_directory_timeout, NULL,
1140 FALSE, FALSE, INPUT_COMPLETE_NONE),
1141 QUICK_CHECKBOX (N_("&Always use ftp proxy:"), &ftpfs_always_use_proxy,
1142 &ftpfs_always_use_proxy_id),
1143 QUICK_INPUT (ftpfs_proxy_host, "input-ftp-proxy", &ret_ftp_proxy,
1144 &ftpfs_proxy_host_id, FALSE, FALSE, INPUT_COMPLETE_HOSTNAMES),
1145 QUICK_CHECKBOX (N_("&Use ~/.netrc"), &ftpfs_use_netrc, NULL),
1146 QUICK_CHECKBOX (N_("Use &passive mode"), &ftpfs_use_passive_connections, NULL),
1147 QUICK_CHECKBOX (N_("Use passive mode over pro&xy"),
1148 &ftpfs_use_passive_connections_over_proxy, NULL),
1149 #endif /* ENABLE_VFS_FTP */
1150 QUICK_BUTTONS_OK_CANCEL,
1151 QUICK_END
1152 /* *INDENT-ON* */
1155 quick_dialog_t qdlg = {
1156 -1, -1, 56,
1157 N_("Virtual File System Setting"), "[Virtual FS]",
1158 quick_widgets,
1159 #ifdef ENABLE_VFS_FTP
1160 confvfs_callback,
1161 #else
1162 NULL,
1163 #endif
1164 NULL,
1167 #ifdef ENABLE_VFS_FTP
1168 if (!ftpfs_always_use_proxy)
1169 quick_widgets[5].options = W_DISABLED;
1170 #endif
1172 if (quick_dialog (&qdlg) != B_CANCEL)
1174 /* cppcheck-suppress uninitvar */
1175 vfs_timeout = atoi (ret_timeout);
1176 g_free (ret_timeout);
1178 if (vfs_timeout < 0 || vfs_timeout > 10000)
1179 vfs_timeout = 10;
1180 #ifdef ENABLE_VFS_FTP
1181 g_free (ftpfs_anonymous_passwd);
1182 /* cppcheck-suppress uninitvar */
1183 ftpfs_anonymous_passwd = ret_passwd;
1184 g_free (ftpfs_proxy_host);
1185 /* cppcheck-suppress uninitvar */
1186 ftpfs_proxy_host = ret_ftp_proxy;
1187 /* cppcheck-suppress uninitvar */
1188 ftpfs_directory_timeout = atoi (ret_directory_timeout);
1189 g_free (ret_directory_timeout);
1190 #endif
1195 #endif /* ENABLE_VFS */
1197 /* --------------------------------------------------------------------------------------------- */
1199 char *
1200 cd_dialog (void)
1202 const Widget *w = WIDGET (current_panel);
1203 char *my_str;
1205 quick_widget_t quick_widgets[] = {
1206 QUICK_LABELED_INPUT (N_("cd"), input_label_left, "", "input", &my_str, NULL, FALSE, TRUE,
1207 INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_CD),
1208 QUICK_END
1211 quick_dialog_t qdlg = {
1212 w->y + w->lines - 6, w->x, w->cols,
1213 N_("Quick cd"), "[Quick cd]",
1214 quick_widgets, NULL, NULL
1217 return (quick_dialog (&qdlg) != B_CANCEL) ? my_str : NULL;
1220 /* --------------------------------------------------------------------------------------------- */
1222 void
1223 symlink_dialog (const vfs_path_t * existing_vpath, const vfs_path_t * new_vpath,
1224 char **ret_existing, char **ret_new)
1226 quick_widget_t quick_widgets[] = {
1227 /* *INDENT-OFF* */
1228 QUICK_LABELED_INPUT (N_("Existing filename (filename symlink will point to):"),
1229 input_label_above, vfs_path_as_str (existing_vpath), "input-2",
1230 ret_existing, NULL, FALSE, FALSE, INPUT_COMPLETE_FILENAMES),
1231 QUICK_SEPARATOR (FALSE),
1232 QUICK_LABELED_INPUT (N_("Symbolic link filename:"), input_label_above,
1233 vfs_path_as_str (new_vpath), "input-1",
1234 ret_new, NULL, FALSE, FALSE, INPUT_COMPLETE_FILENAMES),
1235 QUICK_BUTTONS_OK_CANCEL,
1236 QUICK_END
1237 /* *INDENT-ON* */
1240 quick_dialog_t qdlg = {
1241 -1, -1, 64,
1242 N_("Symbolic link"), "[File Menu]",
1243 quick_widgets, NULL, NULL
1246 if (quick_dialog (&qdlg) == B_CANCEL)
1248 *ret_new = NULL;
1249 *ret_existing = NULL;
1253 /* --------------------------------------------------------------------------------------------- */
1255 #ifdef ENABLE_BACKGROUND
1256 void
1257 jobs_cmd (void)
1259 struct
1261 const char *name;
1262 int flags;
1263 int value;
1264 int len;
1265 bcback_fn callback;
1267 job_but[] =
1269 /* *INDENT-OFF* */
1270 { N_("&Stop"), NORMAL_BUTTON, B_STOP, 0, task_cb },
1271 { N_("&Resume"), NORMAL_BUTTON, B_RESUME, 0, task_cb },
1272 { N_("&Kill"), NORMAL_BUTTON, B_KILL, 0, task_cb },
1273 { N_("&OK"), DEFPUSH_BUTTON, B_CANCEL, 0, NULL }
1274 /* *INDENT-ON* */
1277 size_t i;
1278 const size_t n_but = G_N_ELEMENTS (job_but);
1280 WDialog *jobs_dlg;
1281 int cols = 60;
1282 int lines = 15;
1283 int x = 0;
1285 for (i = 0; i < n_but; i++)
1287 #ifdef ENABLE_NLS
1288 job_but[i].name = _(job_but[i].name);
1289 #endif /* ENABLE_NLS */
1291 job_but[i].len = str_term_width1 (job_but[i].name) + 3;
1292 if (job_but[i].flags == DEFPUSH_BUTTON)
1293 job_but[i].len += 2;
1294 x += job_but[i].len;
1297 x += (int) n_but - 1;
1298 cols = max (cols, x + 6);
1300 jobs_dlg = dlg_create (TRUE, 0, 0, lines, cols, dialog_colors, NULL, NULL,
1301 "[Background jobs]", _("Background jobs"), DLG_CENTER);
1303 bg_list = listbox_new (2, 2, lines - 6, cols - 6, FALSE, NULL);
1304 jobs_fill_listbox (bg_list);
1305 add_widget (jobs_dlg, bg_list);
1307 add_widget (jobs_dlg, hline_new (lines - 4, -1, -1));
1309 x = (cols - x) / 2;
1310 for (i = 0; i < n_but; i++)
1312 add_widget (jobs_dlg,
1313 button_new (lines - 3, x, job_but[i].value, job_but[i].flags, job_but[i].name,
1314 job_but[i].callback));
1315 x += job_but[i].len + 1;
1318 (void) dlg_run (jobs_dlg);
1319 dlg_destroy (jobs_dlg);
1321 #endif /* ENABLE_BACKGROUND */
1323 /* --------------------------------------------------------------------------------------------- */
1325 #ifdef ENABLE_VFS_SMB
1326 struct smb_authinfo *
1327 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, const char *user)
1329 char *label;
1330 struct smb_authinfo *return_value = NULL;
1332 if (domain == NULL)
1333 domain = "";
1334 if (user == NULL)
1335 user = "";
1337 label = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1340 char *ret_domain, *ret_user, *ret_password;
1342 quick_widget_t quick_widgets[] = {
1343 /* *INDENT-OFF* */
1344 QUICK_LABEL (label, NULL),
1345 QUICK_SEPARATOR (TRUE),
1346 QUICK_START_COLUMNS,
1347 QUICK_LABEL (N_("Domain:"), NULL),
1348 QUICK_SEPARATOR (FALSE),
1349 QUICK_LABEL (N_("Username:"), NULL),
1350 QUICK_SEPARATOR (FALSE),
1351 QUICK_LABEL (N_("Password:"), NULL),
1352 QUICK_NEXT_COLUMN,
1353 QUICK_INPUT (domain, "auth_domain", &ret_domain, NULL, FALSE, FALSE, INPUT_COMPLETE_HOSTNAMES),
1354 QUICK_SEPARATOR (FALSE),
1355 QUICK_INPUT (user, "auth_name", &ret_user, NULL, FALSE, FALSE, INPUT_COMPLETE_USERNAMES),
1356 QUICK_SEPARATOR (FALSE),
1357 QUICK_INPUT ("", "auth_password", &ret_password, NULL, TRUE, FALSE, INPUT_COMPLETE_NONE),
1358 QUICK_STOP_COLUMNS,
1359 QUICK_BUTTONS_OK_CANCEL,
1360 QUICK_END
1361 /* *INDENT-ON* */
1364 quick_dialog_t qdlg = {
1365 -1, -1, 40,
1366 N_("SMB authentication"), "[Smb Authinfo]",
1367 quick_widgets, NULL, NULL
1370 if (quick_dialog (&qdlg) != B_CANCEL)
1372 return_value = vfs_smb_authinfo_new (host, share, ret_domain, ret_user, ret_password);
1374 g_free (ret_domain);
1375 g_free (ret_user);
1376 g_free (ret_password);
1380 g_free (label);
1382 return return_value;
1384 #endif /* ENABLE_VFS_SMB */
1386 /* --------------------------------------------------------------------------------------------- */