Ticket #3130: implement center scrolling of panel.
[midnight-commander.git] / src / filemanager / boxes.c
blob05d9ea2cff37756a86e8fd8701b4918ae151ffa2
1 /*
2 Some misc dialog boxes for the program.
4 Copyright (C) 1994-2016
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 unsigned long panel_listing_types_id, panel_user_format_id, panel_brief_cols_id;
105 static unsigned long mini_user_status_id, mini_user_format_id;
107 #ifdef HAVE_CHARSET
108 static int new_display_codepage;
109 #endif /* HAVE_CHARSET */
111 #if defined(ENABLE_VFS) && defined(ENABLE_VFS_FTP)
112 static unsigned long ftpfs_always_use_proxy_id, ftpfs_proxy_host_id;
113 #endif /* ENABLE_VFS && ENABLE_VFS_FTP */
115 static GPtrArray *skin_names;
116 static gchar *current_skin_name;
118 #ifdef ENABLE_BACKGROUND
119 static WListbox *bg_list = NULL;
120 #endif /* ENABLE_BACKGROUND */
122 /* --------------------------------------------------------------------------------------------- */
123 /*** file scope functions ************************************************************************/
124 /* --------------------------------------------------------------------------------------------- */
126 static cb_ret_t
127 configure_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
129 switch (msg)
131 case MSG_NOTIFY:
132 /* message from "Single press" checkbutton */
133 if (sender != NULL && sender->id == configure_old_esc_mode_id)
135 const gboolean not_single = !(CHECK (sender)->state & C_BOOL);
136 Widget *ww;
138 /* input line */
139 ww = dlg_find_by_id (DIALOG (w), configure_time_out_id);
140 widget_disable (ww, not_single);
142 return MSG_HANDLED;
144 return MSG_NOT_HANDLED;
146 default:
147 return dlg_default_callback (w, sender, msg, parm, data);
151 /* --------------------------------------------------------------------------------------------- */
153 static void
154 skin_apply (const gchar * skin_override)
156 GError *mcerror = NULL;
158 mc_skin_deinit ();
159 mc_skin_init (skin_override, &mcerror);
160 mc_fhl_free (&mc_filehighlight);
161 mc_filehighlight = mc_fhl_new (TRUE);
162 dlg_set_default_colors ();
163 input_set_default_colors ();
164 if (mc_global.mc_run_mode == MC_RUN_FULL)
165 command_set_default_colors ();
166 panel_deinit ();
167 panel_init ();
168 repaint_screen ();
170 mc_error_message (&mcerror, NULL);
173 /* --------------------------------------------------------------------------------------------- */
175 static const gchar *
176 skin_name_to_label (const gchar * name)
178 if (strcmp (name, "default") == 0)
179 return _("< Default >");
180 return name;
183 /* --------------------------------------------------------------------------------------------- */
185 static int
186 sel_skin_button (WButton * button, int action)
188 int result;
189 WListbox *skin_list;
190 WDialog *skin_dlg;
191 const gchar *skin_name;
192 int lxx, lyy;
193 unsigned int i;
194 unsigned int pos = 1;
196 (void) action;
198 lxx = COLS / 2;
199 lyy = (LINES - 13) / 2;
200 skin_dlg =
201 dlg_create (TRUE, lyy, lxx, 13, 24, dialog_colors, NULL, NULL, "[Appearance]", _("Skins"),
202 DLG_COMPACT);
204 skin_list = listbox_new (1, 1, 11, 22, FALSE, NULL);
205 skin_name = "default";
206 listbox_add_item (skin_list, LISTBOX_APPEND_AT_END, 0, skin_name_to_label (skin_name),
207 (void *) skin_name, FALSE);
209 if (strcmp (skin_name, current_skin_name) == 0)
210 listbox_select_entry (skin_list, 0);
212 for (i = 0; i < skin_names->len; i++)
214 skin_name = g_ptr_array_index (skin_names, i);
215 if (strcmp (skin_name, "default") != 0)
217 listbox_add_item (skin_list, LISTBOX_APPEND_AT_END, 0, skin_name_to_label (skin_name),
218 (void *) skin_name, FALSE);
219 if (strcmp (skin_name, current_skin_name) == 0)
220 listbox_select_entry (skin_list, pos);
221 pos++;
225 add_widget (skin_dlg, skin_list);
227 result = dlg_run (skin_dlg);
228 if (result == B_ENTER)
230 gchar *skin_label;
232 listbox_get_current (skin_list, &skin_label, (void **) &skin_name);
233 g_free (current_skin_name);
234 current_skin_name = g_strdup (skin_name);
235 skin_apply (skin_name);
237 button_set_text (button, str_fit_to_term (skin_label, 20, J_LEFT_FIT));
239 dlg_destroy (skin_dlg);
241 return 0;
244 /* --------------------------------------------------------------------------------------------- */
246 static cb_ret_t
247 panel_listing_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
249 WDialog *h = DIALOG (w);
251 switch (msg)
253 case MSG_NOTIFY:
254 if (sender != NULL && sender->id == panel_listing_types_id)
256 WCheck *ch;
257 WInput *in1, *in2, *in3;
259 in1 = INPUT (dlg_find_by_id (h, panel_user_format_id));
260 in2 = INPUT (dlg_find_by_id (h, panel_brief_cols_id));
261 ch = CHECK (dlg_find_by_id (h, mini_user_status_id));
262 in3 = INPUT (dlg_find_by_id (h, mini_user_format_id));
264 if (!(ch->state & C_BOOL))
265 input_assign_text (in3, status_format[RADIO (sender)->sel]);
266 input_update (in1, FALSE);
267 input_update (in2, FALSE);
268 input_update (in3, FALSE);
269 widget_disable (WIDGET (in1), RADIO (sender)->sel != panel_listing_user_idx);
270 widget_disable (WIDGET (in2), RADIO (sender)->sel != panel_listing_brief_idx);
271 return MSG_HANDLED;
274 if (sender != NULL && sender->id == mini_user_status_id)
276 WInput *in;
278 in = INPUT (dlg_find_by_id (h, mini_user_format_id));
280 if (CHECK (sender)->state & C_BOOL)
282 widget_disable (WIDGET (in), FALSE);
283 input_assign_text (in, status_format[3]);
285 else
287 WRadio *r;
289 r = RADIO (dlg_find_by_id (h, panel_listing_types_id));
290 widget_disable (WIDGET (in), TRUE);
291 input_assign_text (in, status_format[r->sel]);
293 /* input_update (in, FALSE); */
294 return MSG_HANDLED;
297 return MSG_NOT_HANDLED;
299 default:
300 return dlg_default_callback (w, sender, msg, parm, data);
304 /* --------------------------------------------------------------------------------------------- */
306 #ifdef HAVE_CHARSET
307 static int
308 sel_charset_button (WButton * button, int action)
310 int new_dcp;
312 (void) action;
314 new_dcp = select_charset (-1, -1, new_display_codepage, TRUE);
316 if (new_dcp != SELECT_CHARSET_CANCEL)
318 const char *cpname;
320 new_display_codepage = new_dcp;
321 cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
322 _("Other 8 bit") :
323 ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
324 if (cpname != NULL)
325 mc_global.utf8_display = str_isutf8 (cpname);
326 else
327 cpname = _("7-bit ASCII"); /* FIXME */
329 button_set_text (button, cpname);
330 dlg_redraw (WIDGET (button)->owner);
333 return 0;
335 #endif /* HAVE_CHARSET */
337 /* --------------------------------------------------------------------------------------------- */
339 static cb_ret_t
340 tree_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
342 WDialog *h = DIALOG (w);
344 switch (msg)
346 case MSG_RESIZE:
348 Widget *bar;
350 /* simply call dlg_set_size() with new size */
351 dlg_set_size (h, LINES - 9, COLS - 20);
352 bar = WIDGET (find_buttonbar (h));
353 bar->x = 0;
354 bar->y = LINES - 1;
355 return MSG_HANDLED;
358 case MSG_ACTION:
359 return send_message (find_tree (h), NULL, MSG_ACTION, parm, NULL);
361 default:
362 return dlg_default_callback (w, sender, msg, parm, data);
366 /* --------------------------------------------------------------------------------------------- */
368 #if defined(ENABLE_VFS) && defined (ENABLE_VFS_FTP)
369 static cb_ret_t
370 confvfs_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
372 switch (msg)
374 case MSG_NOTIFY:
375 /* message from "Always use ftp proxy" checkbutton */
376 if (sender != NULL && sender->id == ftpfs_always_use_proxy_id)
378 const gboolean not_use = !(CHECK (sender)->state & C_BOOL);
379 Widget *wi;
381 /* input */
382 wi = dlg_find_by_id (DIALOG (w), ftpfs_proxy_host_id);
383 widget_disable (wi, not_use);
384 return MSG_HANDLED;
386 return MSG_NOT_HANDLED;
388 default:
389 return dlg_default_callback (w, sender, msg, parm, data);
392 #endif /* ENABLE_VFS && ENABLE_VFS_FTP */
394 /* --------------------------------------------------------------------------------------------- */
396 #ifdef ENABLE_BACKGROUND
397 static void
398 jobs_fill_listbox (WListbox * list)
400 static const char *state_str[2] = { "", "" };
401 TaskList *tl;
403 if (state_str[0] == '\0')
405 state_str[0] = _("Running");
406 state_str[1] = _("Stopped");
409 for (tl = task_list; tl != NULL; tl = tl->next)
411 char *s;
413 s = g_strconcat (state_str[tl->state], " ", tl->info, (char *) NULL);
414 listbox_add_item (list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl, FALSE);
415 g_free (s);
419 /* --------------------------------------------------------------------------------------------- */
421 static int
422 task_cb (WButton * button, int action)
424 TaskList *tl;
425 int sig = 0;
427 (void) button;
429 if (bg_list->list == NULL)
430 return 0;
432 /* Get this instance information */
433 listbox_get_current (bg_list, NULL, (void **) &tl);
435 #ifdef SIGTSTP
436 if (action == B_STOP)
438 sig = SIGSTOP;
439 tl->state = Task_Stopped;
441 else if (action == B_RESUME)
443 sig = SIGCONT;
444 tl->state = Task_Running;
446 else
447 #endif
448 if (action == B_KILL)
449 sig = SIGKILL;
451 if (sig == SIGKILL)
452 unregister_task_running (tl->pid, tl->fd);
454 kill (tl->pid, sig);
455 listbox_remove_list (bg_list);
456 jobs_fill_listbox (bg_list);
458 /* This can be optimized to just redraw this widget :-) */
459 dlg_redraw (WIDGET (button)->owner);
461 return 0;
463 #endif /* ENABLE_BACKGROUND */
465 /* --------------------------------------------------------------------------------------------- */
466 /*** public functions ****************************************************************************/
467 /* --------------------------------------------------------------------------------------------- */
469 void
470 configure_box (void)
472 const char *pause_options[] = {
473 N_("&Never"),
474 N_("On dum&b terminals"),
475 N_("Alwa&ys")
478 int pause_options_num;
480 pause_options_num = G_N_ELEMENTS (pause_options);
483 char time_out[BUF_TINY] = "";
484 char *time_out_new;
486 quick_widget_t quick_widgets[] = {
487 /* *INDENT-OFF* */
488 QUICK_START_COLUMNS,
489 QUICK_START_GROUPBOX (N_("File operations")),
490 QUICK_CHECKBOX (N_("&Verbose operation"), &verbose, NULL),
491 QUICK_CHECKBOX (N_("Compute tota&ls"), &file_op_compute_totals, NULL),
492 QUICK_CHECKBOX (N_("Classic pro&gressbar"), &classic_progressbar, NULL),
493 QUICK_CHECKBOX (N_("Mkdi&r autoname"), &auto_fill_mkdir_name, NULL),
494 QUICK_CHECKBOX (N_("&Preallocate space"), &mc_global.vfs.preallocate_space,
495 NULL),
496 QUICK_STOP_GROUPBOX,
497 QUICK_START_GROUPBOX (N_("Esc key mode")),
498 QUICK_CHECKBOX (N_("S&ingle press"), &old_esc_mode, &configure_old_esc_mode_id),
499 QUICK_LABELED_INPUT (N_("Timeout:"), input_label_left,
500 (const char *) time_out, MC_HISTORY_ESC_TIMEOUT,
501 &time_out_new, &configure_time_out_id, FALSE, FALSE,
502 INPUT_COMPLETE_NONE),
503 QUICK_STOP_GROUPBOX,
504 QUICK_START_GROUPBOX (N_("Pause after run")),
505 QUICK_RADIO (pause_options_num, pause_options, &pause_after_run, NULL),
506 QUICK_STOP_GROUPBOX,
507 QUICK_NEXT_COLUMN,
508 QUICK_START_GROUPBOX (N_("Other options")),
509 QUICK_CHECKBOX (N_("Use internal edi&t"), &use_internal_edit, NULL),
510 QUICK_CHECKBOX (N_("Use internal vie&w"), &use_internal_view, NULL),
511 QUICK_CHECKBOX (N_("A&sk new file name"),
512 &editor_ask_filename_before_edit, NULL),
513 QUICK_CHECKBOX (N_("Auto m&enus"), &auto_menu, NULL),
514 QUICK_CHECKBOX (N_("&Drop down menus"), &drop_menus, NULL),
515 QUICK_CHECKBOX (N_("S&hell patterns"), &easy_patterns, NULL),
516 QUICK_CHECKBOX (N_("Co&mplete: show all"),
517 &mc_global.widget.show_all_if_ambiguous, NULL),
518 QUICK_CHECKBOX (N_("Rotating d&ash"), &nice_rotating_dash, NULL),
519 QUICK_CHECKBOX (N_("Cd follows lin&ks"), &mc_global.vfs.cd_symlinks, NULL),
520 QUICK_CHECKBOX (N_("Sa&fe delete"), &safe_delete, NULL),
521 QUICK_CHECKBOX (N_("A&uto save setup"), &auto_save_setup, NULL),
522 QUICK_SEPARATOR (FALSE),
523 QUICK_SEPARATOR (FALSE),
524 QUICK_SEPARATOR (FALSE),
525 QUICK_STOP_GROUPBOX,
526 QUICK_STOP_COLUMNS,
527 QUICK_BUTTONS_OK_CANCEL,
528 QUICK_END
529 /* *INDENT-ON* */
532 quick_dialog_t qdlg = {
533 -1, -1, 60,
534 N_("Configure options"), "[Configuration]",
535 quick_widgets, configure_callback, NULL
538 g_snprintf (time_out, sizeof (time_out), "%d", old_esc_mode_timeout);
540 #ifndef USE_INTERNAL_EDIT
541 quick_widgets[17].options = W_DISABLED;
542 #endif
544 if (!old_esc_mode)
545 quick_widgets[10].options = quick_widgets[11].options = W_DISABLED;
547 #ifndef HAVE_POSIX_FALLOCATE
548 mc_global.vfs.preallocate_space = FALSE;
549 quick_widgets[7].options = W_DISABLED;
550 #endif
552 if (quick_dialog (&qdlg) == B_ENTER)
553 old_esc_mode_timeout = atoi (time_out_new);
555 g_free (time_out_new);
559 /* --------------------------------------------------------------------------------------------- */
561 void
562 appearance_box (void)
564 current_skin_name = g_strdup (mc_skin__default.name);
565 skin_names = mc_skin_list ();
568 quick_widget_t quick_widgets[] = {
569 /* *INDENT-OFF* */
570 QUICK_START_COLUMNS,
571 QUICK_LABEL (N_("Skin:"), NULL),
572 QUICK_NEXT_COLUMN,
573 QUICK_BUTTON (str_fit_to_term (skin_name_to_label (current_skin_name), 20, J_LEFT_FIT),
574 B_USER, sel_skin_button, NULL),
575 QUICK_STOP_COLUMNS,
576 QUICK_BUTTONS_OK_CANCEL,
577 QUICK_END
578 /* *INDENT-ON* */
581 quick_dialog_t qdlg = {
582 -1, -1, 54,
583 N_("Appearance"), "[Appearance]",
584 quick_widgets, dlg_default_callback, NULL
587 if (quick_dialog (&qdlg) == B_ENTER)
588 mc_config_set_string (mc_global.main_config, CONFIG_APP_SECTION, "skin",
589 current_skin_name);
590 else
591 skin_apply (NULL);
594 g_free (current_skin_name);
595 g_ptr_array_foreach (skin_names, (GFunc) g_free, NULL);
596 g_ptr_array_free (skin_names, TRUE);
599 /* --------------------------------------------------------------------------------------------- */
601 void
602 panel_options_box (void)
604 int simple_swap;
606 simple_swap = mc_config_get_bool (mc_global.main_config, CONFIG_PANELS_SECTION,
607 "simple_swap", FALSE) ? 1 : 0;
609 const char *qsearch_options[] = {
610 N_("Case &insensitive"),
611 N_("Cas&e sensitive"),
612 N_("Use panel sort mo&de")
615 quick_widget_t quick_widgets[] = {
616 /* *INDENT-OFF* */
617 QUICK_START_COLUMNS,
618 QUICK_START_GROUPBOX (N_("Main options")),
619 QUICK_CHECKBOX (N_("Show mi&ni-status"), &panels_options.show_mini_info, NULL),
620 QUICK_CHECKBOX (N_("Use SI si&ze units"), &panels_options.kilobyte_si, NULL),
621 QUICK_CHECKBOX (N_("Mi&x all files"), &panels_options.mix_all_files, NULL),
622 QUICK_CHECKBOX (N_("Show &backup files"), &panels_options.show_backups, NULL),
623 QUICK_CHECKBOX (N_("Show &hidden files"), &panels_options.show_dot_files, NULL),
624 QUICK_CHECKBOX (N_("&Fast dir reload"), &panels_options.fast_reload, NULL),
625 QUICK_CHECKBOX (N_("Ma&rk moves down"), &panels_options.mark_moves_down, NULL),
626 QUICK_CHECKBOX (N_("Re&verse files only"), &panels_options.reverse_files_only,
627 NULL),
628 QUICK_CHECKBOX (N_("Simple s&wap"), &simple_swap, NULL),
629 QUICK_CHECKBOX (N_("A&uto save panels setup"), &panels_options.auto_save_setup,
630 NULL),
631 QUICK_SEPARATOR (FALSE),
632 QUICK_SEPARATOR (FALSE),
633 QUICK_SEPARATOR (FALSE),
634 QUICK_STOP_GROUPBOX,
635 QUICK_NEXT_COLUMN,
636 QUICK_START_GROUPBOX (N_("Navigation")),
637 QUICK_CHECKBOX (N_("L&ynx-like motion"), &panels_options.navigate_with_arrows,
638 NULL),
639 QUICK_CHECKBOX (N_("Pa&ge scrolling"), &panels_options.scroll_pages, NULL),
640 QUICK_CHECKBOX (N_("Center &scrolling"), &panels_options.scroll_center, NULL),
641 QUICK_CHECKBOX (N_("&Mouse page scrolling"), &panels_options.mouse_move_pages,
642 NULL),
643 QUICK_STOP_GROUPBOX,
644 QUICK_START_GROUPBOX (N_("File highlight")),
645 QUICK_CHECKBOX (N_("File &types"), &panels_options.filetype_mode, NULL),
646 QUICK_CHECKBOX (N_("&Permissions"), &panels_options.permission_mode, NULL),
647 QUICK_STOP_GROUPBOX,
648 QUICK_START_GROUPBOX (N_("Quick search")),
649 QUICK_RADIO (QSEARCH_NUM, qsearch_options, (int *) &panels_options.qsearch_mode,
650 NULL),
651 QUICK_STOP_GROUPBOX,
652 QUICK_STOP_COLUMNS,
653 QUICK_BUTTONS_OK_CANCEL,
654 QUICK_END
655 /* *INDENT-ON* */
658 quick_dialog_t qdlg = {
659 -1, -1, 60,
660 N_("Panel options"), "[Panel options]",
661 quick_widgets, NULL, NULL
664 if (quick_dialog (&qdlg) != B_ENTER)
665 return;
668 mc_config_set_bool (mc_global.main_config, CONFIG_PANELS_SECTION,
669 "simple_swap", (gboolean) (simple_swap & C_BOOL));
671 if (!panels_options.fast_reload_msg_shown && panels_options.fast_reload)
673 message (D_NORMAL, _("Information"),
674 _("Using the fast reload option may not reflect the exact\n"
675 "directory contents. In this case you'll need to do a\n"
676 "manual reload of the directory. See the man page for\n" "the details."));
677 panels_options.fast_reload_msg_shown = TRUE;
680 update_panels (UP_RELOAD, UP_KEEPSEL);
683 /* --------------------------------------------------------------------------------------------- */
685 /* return list type */
687 panel_listing_box (WPanel * panel, int num, char **userp, char **minip, int *use_msformat,
688 int *brief_cols)
690 int result = -1;
691 char *section = NULL;
693 if (panel == NULL)
695 const char *p;
696 size_t i;
698 p = get_nth_panel_name (num);
699 panel = g_new (WPanel, 1);
700 panel->list_type = list_full;
701 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
702 panel->user_mini_status = 0;
703 for (i = 0; i < LIST_TYPES; i++)
704 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
705 section = g_strconcat ("Temporal:", p, (char *) NULL);
706 if (!mc_config_has_group (mc_global.main_config, section))
708 g_free (section);
709 section = g_strdup (p);
711 panel_load_setup (panel, section);
712 g_free (section);
716 int mini_user_status;
717 char panel_brief_cols_in[BUF_TINY];
718 char *panel_brief_cols_out = NULL;
719 char *panel_user_format = NULL;
720 char *mini_user_format = NULL;
722 /* Controls whether the array strings have been translated */
723 const char *list_types[LIST_TYPES] = {
724 N_("&Full file list"),
725 N_("&Brief file list:"),
726 N_("&Long file list"),
727 N_("&User defined:")
730 quick_widget_t quick_widgets[] = {
731 /* *INDENT-OFF* */
732 QUICK_START_COLUMNS,
733 QUICK_RADIO (LIST_TYPES, list_types, &result, &panel_listing_types_id),
734 QUICK_NEXT_COLUMN,
735 QUICK_SEPARATOR (FALSE),
736 QUICK_LABELED_INPUT (_ ("columns"), input_label_right, panel_brief_cols_in,
737 "panel-brief-cols-input", &panel_brief_cols_out,
738 &panel_brief_cols_id, FALSE, FALSE, INPUT_COMPLETE_NONE),
739 QUICK_STOP_COLUMNS,
740 QUICK_INPUT (panel->user_format, "user-fmt-input", &panel_user_format,
741 &panel_user_format_id, FALSE, FALSE, INPUT_COMPLETE_NONE),
742 QUICK_SEPARATOR (TRUE),
743 QUICK_CHECKBOX (N_("User &mini status"), &mini_user_status, &mini_user_status_id),
744 QUICK_INPUT (panel->user_status_format[panel->list_type], "mini_input",
745 &mini_user_format, &mini_user_format_id, FALSE, FALSE, INPUT_COMPLETE_NONE),
746 QUICK_BUTTONS_OK_CANCEL,
747 QUICK_END
748 /* *INDENT-ON* */
751 quick_dialog_t qdlg = {
752 -1, -1, 48,
753 N_("Listing mode"), "[Listing Mode...]",
754 quick_widgets, panel_listing_callback, NULL
757 mini_user_status = panel->user_mini_status;
758 result = panel->list_type;
759 status_format = panel->user_status_format;
761 g_snprintf (panel_brief_cols_in, sizeof (panel_brief_cols_in), "%d", panel->brief_cols);
763 if ((int) panel->list_type != panel_listing_brief_idx)
764 quick_widgets[4].options = W_DISABLED;
766 if ((int) panel->list_type != panel_listing_user_idx)
767 quick_widgets[6].options = W_DISABLED;
769 if (!mini_user_status)
770 quick_widgets[9].options = W_DISABLED;
772 if (quick_dialog (&qdlg) == B_CANCEL)
773 result = -1;
774 else
776 int cols;
777 char *error = NULL;
779 *userp = panel_user_format;
780 *minip = mini_user_format;
781 *use_msformat = mini_user_status;
783 cols = strtol (panel_brief_cols_out, &error, 10);
784 if (*error == '\0')
785 *brief_cols = cols;
786 else
787 *brief_cols = panel->brief_cols;
789 g_free (panel_brief_cols_out);
793 if (section != NULL)
795 int i;
797 g_free (panel->user_format);
798 for (i = 0; i < LIST_TYPES; i++)
799 g_free (panel->user_status_format[i]);
800 g_free (panel);
803 return result;
806 /* --------------------------------------------------------------------------------------------- */
808 const panel_field_t *
809 sort_box (dir_sort_options_t * op, const panel_field_t * sort_field)
811 char **sort_orders_names;
812 gsize i;
813 gsize sort_names_num = 0;
814 int sort_idx = 0;
815 const panel_field_t *result = NULL;
817 sort_orders_names = panel_get_sortable_fields (&sort_names_num);
819 for (i = 0; i < sort_names_num; i++)
820 if (strcmp (sort_orders_names[i], _(sort_field->title_hotkey)) == 0)
822 sort_idx = i;
823 break;
827 quick_widget_t quick_widgets[] = {
828 /* *INDENT-OFF* */
829 QUICK_START_COLUMNS,
830 QUICK_RADIO (sort_names_num, (const char **) sort_orders_names, &sort_idx, NULL),
831 QUICK_NEXT_COLUMN,
832 QUICK_CHECKBOX (N_("Executable &first"), &op->exec_first, NULL),
833 QUICK_CHECKBOX (N_("Cas&e sensitive"), &op->case_sensitive, NULL),
834 QUICK_CHECKBOX (N_("&Reverse"), &op->reverse, NULL),
835 QUICK_STOP_COLUMNS,
836 QUICK_BUTTONS_OK_CANCEL,
837 QUICK_END
838 /* *INDENT-ON* */
841 quick_dialog_t qdlg = {
842 -1, -1, 40,
843 N_("Sort order"), "[Sort Order...]",
844 quick_widgets, NULL, NULL
847 if (quick_dialog (&qdlg) != B_CANCEL)
848 result = panel_get_field_by_title_hotkey (sort_orders_names[sort_idx]);
850 if (result == NULL)
851 result = sort_field;
854 g_strfreev (sort_orders_names);
856 return result;
859 /* --------------------------------------------------------------------------------------------- */
861 void
862 confirm_box (void)
864 quick_widget_t quick_widgets[] = {
865 /* *INDENT-OFF* */
866 /* TRANSLATORS: no need to translate 'Confirmation', it's just a context prefix */
867 QUICK_CHECKBOX (Q_("Confirmation|&Delete"), &confirm_delete, NULL),
868 QUICK_CHECKBOX (Q_("Confirmation|O&verwrite"), &confirm_overwrite, NULL),
869 QUICK_CHECKBOX (Q_("Confirmation|&Execute"), &confirm_execute, NULL),
870 QUICK_CHECKBOX (Q_("Confirmation|E&xit"), &confirm_exit, NULL),
871 QUICK_CHECKBOX (Q_("Confirmation|Di&rectory hotlist delete"),
872 &confirm_directory_hotlist_delete, NULL),
873 QUICK_CHECKBOX (Q_("Confirmation|&History cleanup"),
874 &mc_global.widget.confirm_history_cleanup, NULL),
875 QUICK_BUTTONS_OK_CANCEL,
876 QUICK_END
877 /* *INDENT-ON* */
880 quick_dialog_t qdlg = {
881 -1, -1, 46,
882 N_("Confirmation"), "[Confirmation]",
883 quick_widgets, NULL, NULL
886 (void) quick_dialog (&qdlg);
889 /* --------------------------------------------------------------------------------------------- */
891 #ifndef HAVE_CHARSET
892 void
893 display_bits_box (void)
895 int new_meta;
896 int current_mode;
898 const char *display_bits_str[] = {
899 N_("&UTF-8 output"),
900 N_("&Full 8 bits output"),
901 N_("&ISO 8859-1"),
902 N_("7 &bits")
905 quick_widget_t quick_widgets[] = {
906 /* *INDENT-OFF* */
907 QUICK_RADIO (4, display_bits_str, &current_mode, NULL),
908 QUICK_SEPARATOR (TRUE),
909 QUICK_CHECKBOX (N_("F&ull 8 bits input"), &new_meta, NULL),
910 QUICK_BUTTONS_OK_CANCEL,
911 QUICK_END
912 /* *INDENT-ON* */
915 quick_dialog_t qdlg = {
916 -1, -1, 46,
917 _("Display bits"), "[Display bits]",
918 quick_widgets, NULL, NULL
921 if (mc_global.full_eight_bits)
922 current_mode = 0;
923 else if (mc_global.eight_bit_clean)
924 current_mode = 1;
925 else
926 current_mode = 2;
928 new_meta = !use_8th_bit_as_meta;
930 if (quick_dialog (&qdlg) != B_CANCEL)
932 mc_global.eight_bit_clean = current_mode < 3;
933 mc_global.full_eight_bits = current_mode < 2;
934 #ifndef HAVE_SLANG
935 meta (stdscr, mc_global.eight_bit_clean);
936 #else
937 SLsmg_Display_Eight_Bit = mc_global.full_eight_bits ? 128 : 160;
938 #endif
939 use_8th_bit_as_meta = !new_meta;
943 /* --------------------------------------------------------------------------------------------- */
944 #else /* HAVE_CHARSET */
946 void
947 display_bits_box (void)
949 const char *cpname;
951 new_display_codepage = mc_global.display_codepage;
953 cpname = (new_display_codepage < 0) ? _("Other 8 bit")
954 : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
957 int new_meta;
959 quick_widget_t quick_widgets[] = {
960 /* *INDENT-OFF* */
961 QUICK_START_COLUMNS,
962 QUICK_LABEL (N_("Input / display codepage:"), NULL),
963 QUICK_NEXT_COLUMN,
964 QUICK_BUTTON (cpname, B_USER, sel_charset_button, NULL),
965 QUICK_STOP_COLUMNS,
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 N_("Display bits"), "[Display bits]",
976 quick_widgets, NULL, NULL
979 new_meta = !use_8th_bit_as_meta;
980 application_keypad_mode ();
982 if (quick_dialog (&qdlg) == B_ENTER)
984 char *errmsg;
986 mc_global.display_codepage = new_display_codepage;
988 errmsg = init_translation_table (mc_global.source_codepage, mc_global.display_codepage);
989 if (errmsg != NULL)
991 message (D_ERROR, MSG_ERROR, "%s", errmsg);
992 g_free (errmsg);
995 #ifdef HAVE_SLANG
996 tty_display_8bit (mc_global.display_codepage != 0 && mc_global.display_codepage != 1);
997 #else
998 tty_display_8bit (mc_global.display_codepage != 0);
999 #endif
1000 use_8th_bit_as_meta = !new_meta;
1002 repaint_screen ();
1006 #endif /* HAVE_CHARSET */
1008 /* --------------------------------------------------------------------------------------------- */
1009 /** Show tree in a box, not on a panel */
1011 char *
1012 tree_box (const char *current_dir)
1014 WTree *mytree;
1015 WDialog *dlg;
1016 Widget *wd;
1017 char *val = NULL;
1018 WButtonBar *bar;
1020 (void) current_dir;
1022 /* Create the components */
1023 dlg = dlg_create (TRUE, 0, 0, LINES - 9, COLS - 20, dialog_colors, tree_callback, NULL,
1024 "[Directory Tree]", _("Directory tree"), DLG_CENTER);
1025 wd = WIDGET (dlg);
1027 mytree = tree_new (2, 2, wd->lines - 6, wd->cols - 5, FALSE);
1028 add_widget_autopos (dlg, mytree, WPOS_KEEP_ALL, NULL);
1029 add_widget_autopos (dlg, hline_new (wd->lines - 4, 1, -1), WPOS_KEEP_BOTTOM, NULL);
1030 bar = buttonbar_new (TRUE);
1031 add_widget (dlg, bar);
1032 /* restore ButtonBar coordinates after add_widget() */
1033 WIDGET (bar)->x = 0;
1034 WIDGET (bar)->y = LINES - 1;
1036 if (dlg_run (dlg) == B_ENTER)
1038 const vfs_path_t *selected_name;
1040 selected_name = tree_selected_name (mytree);
1041 val = g_strdup (vfs_path_as_str (selected_name));
1044 dlg_destroy (dlg);
1045 return val;
1048 /* --------------------------------------------------------------------------------------------- */
1050 #ifdef ENABLE_VFS
1051 void
1052 configure_vfs (void)
1054 char buffer2[BUF_TINY];
1055 #ifdef ENABLE_VFS_FTP
1056 char buffer3[BUF_TINY];
1058 g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
1059 #endif
1061 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
1064 char *ret_timeout;
1065 #ifdef ENABLE_VFS_FTP
1066 char *ret_passwd;
1067 char *ret_ftp_proxy;
1068 char *ret_directory_timeout;
1069 #endif /* ENABLE_VFS_FTP */
1071 quick_widget_t quick_widgets[] = {
1072 /* *INDENT-OFF* */
1073 QUICK_LABELED_INPUT (N_("Timeout for freeing VFSs (sec):"), input_label_left,
1074 buffer2, "input-timo-vfs", &ret_timeout, NULL, FALSE, FALSE,
1075 INPUT_COMPLETE_NONE),
1076 #ifdef ENABLE_VFS_FTP
1077 QUICK_SEPARATOR (TRUE),
1078 QUICK_LABELED_INPUT (N_("FTP anonymous password:"), input_label_left,
1079 ftpfs_anonymous_passwd, "input-passwd", &ret_passwd, NULL,
1080 FALSE, FALSE, INPUT_COMPLETE_NONE),
1081 QUICK_LABELED_INPUT (N_("FTP directory cache timeout (sec):"), input_label_left,
1082 buffer3, "input-timeout", &ret_directory_timeout, NULL,
1083 FALSE, FALSE, INPUT_COMPLETE_NONE),
1084 QUICK_CHECKBOX (N_("&Always use ftp proxy:"), &ftpfs_always_use_proxy,
1085 &ftpfs_always_use_proxy_id),
1086 QUICK_INPUT (ftpfs_proxy_host, "input-ftp-proxy", &ret_ftp_proxy,
1087 &ftpfs_proxy_host_id, FALSE, FALSE, INPUT_COMPLETE_HOSTNAMES),
1088 QUICK_CHECKBOX (N_("&Use ~/.netrc"), &ftpfs_use_netrc, NULL),
1089 QUICK_CHECKBOX (N_("Use &passive mode"), &ftpfs_use_passive_connections, NULL),
1090 QUICK_CHECKBOX (N_("Use passive mode over pro&xy"),
1091 &ftpfs_use_passive_connections_over_proxy, NULL),
1092 #endif /* ENABLE_VFS_FTP */
1093 QUICK_BUTTONS_OK_CANCEL,
1094 QUICK_END
1095 /* *INDENT-ON* */
1098 quick_dialog_t qdlg = {
1099 -1, -1, 56,
1100 N_("Virtual File System Setting"), "[Virtual FS]",
1101 quick_widgets,
1102 #ifdef ENABLE_VFS_FTP
1103 confvfs_callback,
1104 #else
1105 NULL,
1106 #endif
1107 NULL,
1110 #ifdef ENABLE_VFS_FTP
1111 if (!ftpfs_always_use_proxy)
1112 quick_widgets[5].options = W_DISABLED;
1113 #endif
1115 if (quick_dialog (&qdlg) != B_CANCEL)
1117 /* cppcheck-suppress uninitvar */
1118 vfs_timeout = atoi (ret_timeout);
1119 g_free (ret_timeout);
1121 if (vfs_timeout < 0 || vfs_timeout > 10000)
1122 vfs_timeout = 10;
1123 #ifdef ENABLE_VFS_FTP
1124 g_free (ftpfs_anonymous_passwd);
1125 /* cppcheck-suppress uninitvar */
1126 ftpfs_anonymous_passwd = ret_passwd;
1127 g_free (ftpfs_proxy_host);
1128 /* cppcheck-suppress uninitvar */
1129 ftpfs_proxy_host = ret_ftp_proxy;
1130 /* cppcheck-suppress uninitvar */
1131 ftpfs_directory_timeout = atoi (ret_directory_timeout);
1132 g_free (ret_directory_timeout);
1133 #endif
1138 #endif /* ENABLE_VFS */
1140 /* --------------------------------------------------------------------------------------------- */
1142 char *
1143 cd_dialog (void)
1145 const Widget *w = CONST_WIDGET (current_panel);
1146 char *my_str;
1148 quick_widget_t quick_widgets[] = {
1149 QUICK_LABELED_INPUT (N_("cd"), input_label_left, "", "input", &my_str, NULL, FALSE, TRUE,
1150 INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_CD),
1151 QUICK_END
1154 quick_dialog_t qdlg = {
1155 w->y + w->lines - 6, w->x, w->cols,
1156 N_("Quick cd"), "[Quick cd]",
1157 quick_widgets, NULL, NULL
1160 return (quick_dialog (&qdlg) != B_CANCEL) ? my_str : NULL;
1163 /* --------------------------------------------------------------------------------------------- */
1165 void
1166 symlink_dialog (const vfs_path_t * existing_vpath, const vfs_path_t * new_vpath,
1167 char **ret_existing, char **ret_new)
1169 quick_widget_t quick_widgets[] = {
1170 /* *INDENT-OFF* */
1171 QUICK_LABELED_INPUT (N_("Existing filename (filename symlink will point to):"),
1172 input_label_above, vfs_path_as_str (existing_vpath), "input-2",
1173 ret_existing, NULL, FALSE, FALSE, INPUT_COMPLETE_FILENAMES),
1174 QUICK_SEPARATOR (FALSE),
1175 QUICK_LABELED_INPUT (N_("Symbolic link filename:"), input_label_above,
1176 vfs_path_as_str (new_vpath), "input-1",
1177 ret_new, NULL, FALSE, FALSE, INPUT_COMPLETE_FILENAMES),
1178 QUICK_BUTTONS_OK_CANCEL,
1179 QUICK_END
1180 /* *INDENT-ON* */
1183 quick_dialog_t qdlg = {
1184 -1, -1, 64,
1185 N_("Symbolic link"), "[File Menu]",
1186 quick_widgets, NULL, NULL
1189 if (quick_dialog (&qdlg) == B_CANCEL)
1191 *ret_new = NULL;
1192 *ret_existing = NULL;
1196 /* --------------------------------------------------------------------------------------------- */
1198 #ifdef ENABLE_BACKGROUND
1199 void
1200 jobs_cmd (void)
1202 struct
1204 const char *name;
1205 int flags;
1206 int value;
1207 int len;
1208 bcback_fn callback;
1210 job_but[] =
1212 /* *INDENT-OFF* */
1213 { N_("&Stop"), NORMAL_BUTTON, B_STOP, 0, task_cb },
1214 { N_("&Resume"), NORMAL_BUTTON, B_RESUME, 0, task_cb },
1215 { N_("&Kill"), NORMAL_BUTTON, B_KILL, 0, task_cb },
1216 { N_("&OK"), DEFPUSH_BUTTON, B_CANCEL, 0, NULL }
1217 /* *INDENT-ON* */
1220 size_t i;
1221 const size_t n_but = G_N_ELEMENTS (job_but);
1223 WDialog *jobs_dlg;
1224 int cols = 60;
1225 int lines = 15;
1226 int x = 0;
1228 for (i = 0; i < n_but; i++)
1230 #ifdef ENABLE_NLS
1231 job_but[i].name = _(job_but[i].name);
1232 #endif /* ENABLE_NLS */
1234 job_but[i].len = str_term_width1 (job_but[i].name) + 3;
1235 if (job_but[i].flags == DEFPUSH_BUTTON)
1236 job_but[i].len += 2;
1237 x += job_but[i].len;
1240 x += (int) n_but - 1;
1241 cols = MAX (cols, x + 6);
1243 jobs_dlg = dlg_create (TRUE, 0, 0, lines, cols, dialog_colors, NULL, NULL,
1244 "[Background jobs]", _("Background jobs"), DLG_CENTER);
1246 bg_list = listbox_new (2, 2, lines - 6, cols - 6, FALSE, NULL);
1247 jobs_fill_listbox (bg_list);
1248 add_widget (jobs_dlg, bg_list);
1250 add_widget (jobs_dlg, hline_new (lines - 4, -1, -1));
1252 x = (cols - x) / 2;
1253 for (i = 0; i < n_but; i++)
1255 add_widget (jobs_dlg,
1256 button_new (lines - 3, x, job_but[i].value, job_but[i].flags, job_but[i].name,
1257 job_but[i].callback));
1258 x += job_but[i].len + 1;
1261 (void) dlg_run (jobs_dlg);
1262 dlg_destroy (jobs_dlg);
1264 #endif /* ENABLE_BACKGROUND */
1266 /* --------------------------------------------------------------------------------------------- */
1268 #ifdef ENABLE_VFS_SMB
1269 struct smb_authinfo *
1270 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, const char *user)
1272 char *label;
1273 struct smb_authinfo *return_value = NULL;
1275 if (domain == NULL)
1276 domain = "";
1277 if (user == NULL)
1278 user = "";
1280 label = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1283 char *ret_domain, *ret_user, *ret_password;
1285 quick_widget_t quick_widgets[] = {
1286 /* *INDENT-OFF* */
1287 QUICK_LABEL (label, NULL),
1288 QUICK_SEPARATOR (TRUE),
1289 QUICK_START_COLUMNS,
1290 QUICK_LABEL (N_("Domain:"), NULL),
1291 QUICK_SEPARATOR (FALSE),
1292 QUICK_LABEL (N_("Username:"), NULL),
1293 QUICK_SEPARATOR (FALSE),
1294 QUICK_LABEL (N_("Password:"), NULL),
1295 QUICK_NEXT_COLUMN,
1296 QUICK_INPUT (domain, "auth_domain", &ret_domain, NULL, FALSE, FALSE, INPUT_COMPLETE_HOSTNAMES),
1297 QUICK_SEPARATOR (FALSE),
1298 QUICK_INPUT (user, "auth_name", &ret_user, NULL, FALSE, FALSE, INPUT_COMPLETE_USERNAMES),
1299 QUICK_SEPARATOR (FALSE),
1300 QUICK_INPUT ("", "auth_password", &ret_password, NULL, TRUE, FALSE, INPUT_COMPLETE_NONE),
1301 QUICK_STOP_COLUMNS,
1302 QUICK_BUTTONS_OK_CANCEL,
1303 QUICK_END
1304 /* *INDENT-ON* */
1307 quick_dialog_t qdlg = {
1308 -1, -1, 40,
1309 N_("SMB authentication"), "[Smb Authinfo]",
1310 quick_widgets, NULL, NULL
1313 if (quick_dialog (&qdlg) != B_CANCEL)
1315 return_value = vfs_smb_authinfo_new (host, share, ret_domain, ret_user, ret_password);
1317 g_free (ret_domain);
1318 g_free (ret_user);
1319 g_free (ret_password);
1323 g_free (label);
1325 return return_value;
1327 #endif /* ENABLE_VFS_SMB */
1329 /* --------------------------------------------------------------------------------------------- */