Remove min() and max() macros. Use MIN() and MAX() macros from GLib.
[midnight-commander.git] / src / filemanager / boxes.c
blob4188377771ad792857c2fa9f9f65a590d3a85978
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_main_config, CONFIG_APP_SECTION, "skin", current_skin_name);
589 else
590 skin_apply (NULL);
593 g_free (current_skin_name);
594 g_ptr_array_foreach (skin_names, (GFunc) g_free, NULL);
595 g_ptr_array_free (skin_names, TRUE);
598 /* --------------------------------------------------------------------------------------------- */
600 void
601 panel_options_box (void)
603 int simple_swap;
605 simple_swap = mc_config_get_bool (mc_main_config, CONFIG_PANELS_SECTION,
606 "simple_swap", FALSE) ? 1 : 0;
608 const char *qsearch_options[] = {
609 N_("Case &insensitive"),
610 N_("Cas&e sensitive"),
611 N_("Use panel sort mo&de")
614 quick_widget_t quick_widgets[] = {
615 /* *INDENT-OFF* */
616 QUICK_START_COLUMNS,
617 QUICK_START_GROUPBOX (N_("Main options")),
618 QUICK_CHECKBOX (N_("Show mi&ni-status"), &panels_options.show_mini_info, NULL),
619 QUICK_CHECKBOX (N_("Use SI si&ze units"), &panels_options.kilobyte_si, NULL),
620 QUICK_CHECKBOX (N_("Mi&x all files"), &panels_options.mix_all_files, NULL),
621 QUICK_CHECKBOX (N_("Show &backup files"), &panels_options.show_backups, NULL),
622 QUICK_CHECKBOX (N_("Show &hidden files"), &panels_options.show_dot_files, NULL),
623 QUICK_CHECKBOX (N_("&Fast dir reload"), &panels_options.fast_reload, NULL),
624 QUICK_CHECKBOX (N_("Ma&rk moves down"), &panels_options.mark_moves_down, NULL),
625 QUICK_CHECKBOX (N_("Re&verse files only"), &panels_options.reverse_files_only,
626 NULL),
627 QUICK_CHECKBOX (N_("Simple s&wap"), &simple_swap, NULL),
628 QUICK_CHECKBOX (N_("A&uto save panels setup"), &panels_options.auto_save_setup,
629 NULL),
630 QUICK_SEPARATOR (FALSE),
631 QUICK_SEPARATOR (FALSE),
632 QUICK_STOP_GROUPBOX,
633 QUICK_NEXT_COLUMN,
634 QUICK_START_GROUPBOX (N_("Navigation")),
635 QUICK_CHECKBOX (N_("L&ynx-like motion"), &panels_options.navigate_with_arrows,
636 NULL),
637 QUICK_CHECKBOX (N_("Pa&ge scrolling"), &panels_options.scroll_pages, NULL),
638 QUICK_CHECKBOX (N_("&Mouse page scrolling"), &panels_options.mouse_move_pages,
639 NULL),
640 QUICK_STOP_GROUPBOX,
641 QUICK_START_GROUPBOX (N_("File highlight")),
642 QUICK_CHECKBOX (N_("File &types"), &panels_options.filetype_mode, NULL),
643 QUICK_CHECKBOX (N_("&Permissions"), &panels_options.permission_mode, NULL),
644 QUICK_STOP_GROUPBOX,
645 QUICK_START_GROUPBOX (N_("Quick search")),
646 QUICK_RADIO (QSEARCH_NUM, qsearch_options, (int *) &panels_options.qsearch_mode,
647 NULL),
648 QUICK_STOP_GROUPBOX,
649 QUICK_STOP_COLUMNS,
650 QUICK_BUTTONS_OK_CANCEL,
651 QUICK_END
652 /* *INDENT-ON* */
655 quick_dialog_t qdlg = {
656 -1, -1, 60,
657 N_("Panel options"), "[Panel options]",
658 quick_widgets, NULL, NULL
661 if (quick_dialog (&qdlg) != B_ENTER)
662 return;
665 mc_config_set_bool (mc_main_config, CONFIG_PANELS_SECTION,
666 "simple_swap", (gboolean) (simple_swap & C_BOOL));
668 if (!panels_options.fast_reload_msg_shown && panels_options.fast_reload)
670 message (D_NORMAL, _("Information"),
671 _("Using the fast reload option may not reflect the exact\n"
672 "directory contents. In this case you'll need to do a\n"
673 "manual reload of the directory. See the man page for\n" "the details."));
674 panels_options.fast_reload_msg_shown = TRUE;
677 update_panels (UP_RELOAD, UP_KEEPSEL);
680 /* --------------------------------------------------------------------------------------------- */
682 /* return list type */
684 panel_listing_box (WPanel * panel, int num, char **userp, char **minip, int *use_msformat,
685 int *brief_cols)
687 int result = -1;
688 char *section = NULL;
690 if (panel == NULL)
692 const char *p;
693 size_t i;
695 p = get_nth_panel_name (num);
696 panel = g_new (WPanel, 1);
697 panel->list_type = list_full;
698 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
699 panel->user_mini_status = 0;
700 for (i = 0; i < LIST_TYPES; i++)
701 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
702 section = g_strconcat ("Temporal:", p, (char *) NULL);
703 if (!mc_config_has_group (mc_main_config, section))
705 g_free (section);
706 section = g_strdup (p);
708 panel_load_setup (panel, section);
709 g_free (section);
713 int mini_user_status;
714 char panel_brief_cols_in[BUF_TINY];
715 char *panel_brief_cols_out = NULL;
716 char *panel_user_format = NULL;
717 char *mini_user_format = NULL;
719 /* Controls whether the array strings have been translated */
720 const char *list_types[LIST_TYPES] = {
721 N_("&Full file list"),
722 N_("&Brief file list:"),
723 N_("&Long file list"),
724 N_("&User defined:")
727 quick_widget_t quick_widgets[] = {
728 /* *INDENT-OFF* */
729 QUICK_START_COLUMNS,
730 QUICK_RADIO (LIST_TYPES, list_types, &result, &panel_listing_types_id),
731 QUICK_NEXT_COLUMN,
732 QUICK_SEPARATOR (FALSE),
733 QUICK_LABELED_INPUT (_ ("columns"), input_label_right, panel_brief_cols_in,
734 "panel-brief-cols-input", &panel_brief_cols_out,
735 &panel_brief_cols_id, FALSE, FALSE, INPUT_COMPLETE_NONE),
736 QUICK_STOP_COLUMNS,
737 QUICK_INPUT (panel->user_format, "user-fmt-input", &panel_user_format,
738 &panel_user_format_id, FALSE, FALSE, INPUT_COMPLETE_NONE),
739 QUICK_SEPARATOR (TRUE),
740 QUICK_CHECKBOX (N_("User &mini status"), &mini_user_status, &mini_user_status_id),
741 QUICK_INPUT (panel->user_status_format[panel->list_type], "mini_input",
742 &mini_user_format, &mini_user_format_id, FALSE, FALSE, INPUT_COMPLETE_NONE),
743 QUICK_BUTTONS_OK_CANCEL,
744 QUICK_END
745 /* *INDENT-ON* */
748 quick_dialog_t qdlg = {
749 -1, -1, 48,
750 N_("Listing mode"), "[Listing Mode...]",
751 quick_widgets, panel_listing_callback, NULL
754 mini_user_status = panel->user_mini_status;
755 result = panel->list_type;
756 status_format = panel->user_status_format;
758 g_snprintf (panel_brief_cols_in, sizeof (panel_brief_cols_in), "%d", panel->brief_cols);
760 if ((int) panel->list_type != panel_listing_brief_idx)
761 quick_widgets[4].options = W_DISABLED;
763 if ((int) panel->list_type != panel_listing_user_idx)
764 quick_widgets[6].options = W_DISABLED;
766 if (!mini_user_status)
767 quick_widgets[9].options = W_DISABLED;
769 if (quick_dialog (&qdlg) == B_CANCEL)
770 result = -1;
771 else
773 int cols;
774 char *error = NULL;
776 *userp = panel_user_format;
777 *minip = mini_user_format;
778 *use_msformat = mini_user_status;
780 cols = strtol (panel_brief_cols_out, &error, 10);
781 if (*error == '\0')
782 *brief_cols = cols;
783 else
784 *brief_cols = panel->brief_cols;
786 g_free (panel_brief_cols_out);
790 if (section != NULL)
792 int i;
794 g_free (panel->user_format);
795 for (i = 0; i < LIST_TYPES; i++)
796 g_free (panel->user_status_format[i]);
797 g_free (panel);
800 return result;
803 /* --------------------------------------------------------------------------------------------- */
805 const panel_field_t *
806 sort_box (dir_sort_options_t * op, const panel_field_t * sort_field)
808 char **sort_orders_names;
809 gsize i;
810 gsize sort_names_num = 0;
811 int sort_idx = 0;
812 const panel_field_t *result = NULL;
814 sort_orders_names = panel_get_sortable_fields (&sort_names_num);
816 for (i = 0; i < sort_names_num; i++)
817 if (strcmp (sort_orders_names[i], _(sort_field->title_hotkey)) == 0)
819 sort_idx = i;
820 break;
824 quick_widget_t quick_widgets[] = {
825 /* *INDENT-OFF* */
826 QUICK_START_COLUMNS,
827 QUICK_RADIO (sort_names_num, (const char **) sort_orders_names, &sort_idx, NULL),
828 QUICK_NEXT_COLUMN,
829 QUICK_CHECKBOX (N_("Executable &first"), &op->exec_first, NULL),
830 QUICK_CHECKBOX (N_("Cas&e sensitive"), &op->case_sensitive, NULL),
831 QUICK_CHECKBOX (N_("&Reverse"), &op->reverse, NULL),
832 QUICK_STOP_COLUMNS,
833 QUICK_BUTTONS_OK_CANCEL,
834 QUICK_END
835 /* *INDENT-ON* */
838 quick_dialog_t qdlg = {
839 -1, -1, 40,
840 N_("Sort order"), "[Sort Order...]",
841 quick_widgets, NULL, NULL
844 if (quick_dialog (&qdlg) != B_CANCEL)
845 result = panel_get_field_by_title_hotkey (sort_orders_names[sort_idx]);
847 if (result == NULL)
848 result = sort_field;
851 g_strfreev (sort_orders_names);
853 return result;
856 /* --------------------------------------------------------------------------------------------- */
858 void
859 confirm_box (void)
861 quick_widget_t quick_widgets[] = {
862 /* *INDENT-OFF* */
863 /* TRANSLATORS: no need to translate 'Confirmation', it's just a context prefix */
864 QUICK_CHECKBOX (Q_("Confirmation|&Delete"), &confirm_delete, NULL),
865 QUICK_CHECKBOX (Q_("Confirmation|O&verwrite"), &confirm_overwrite, NULL),
866 QUICK_CHECKBOX (Q_("Confirmation|&Execute"), &confirm_execute, NULL),
867 QUICK_CHECKBOX (Q_("Confirmation|E&xit"), &confirm_exit, NULL),
868 QUICK_CHECKBOX (Q_("Confirmation|Di&rectory hotlist delete"),
869 &confirm_directory_hotlist_delete, NULL),
870 QUICK_CHECKBOX (Q_("Confirmation|&History cleanup"),
871 &mc_global.widget.confirm_history_cleanup, NULL),
872 QUICK_BUTTONS_OK_CANCEL,
873 QUICK_END
874 /* *INDENT-ON* */
877 quick_dialog_t qdlg = {
878 -1, -1, 46,
879 N_("Confirmation"), "[Confirmation]",
880 quick_widgets, NULL, NULL
883 (void) quick_dialog (&qdlg);
886 /* --------------------------------------------------------------------------------------------- */
888 #ifndef HAVE_CHARSET
889 void
890 display_bits_box (void)
892 int new_meta;
893 int current_mode;
895 const char *display_bits_str[] = {
896 N_("&UTF-8 output"),
897 N_("&Full 8 bits output"),
898 N_("&ISO 8859-1"),
899 N_("7 &bits")
902 quick_widget_t quick_widgets[] = {
903 /* *INDENT-OFF* */
904 QUICK_RADIO (4, display_bits_str, &current_mode, NULL),
905 QUICK_SEPARATOR (TRUE),
906 QUICK_CHECKBOX (N_("F&ull 8 bits input"), &new_meta, NULL),
907 QUICK_BUTTONS_OK_CANCEL,
908 QUICK_END
909 /* *INDENT-ON* */
912 quick_dialog_t qdlg = {
913 -1, -1, 46,
914 _("Display bits"), "[Display bits]",
915 quick_widgets, NULL, NULL
918 if (mc_global.full_eight_bits)
919 current_mode = 0;
920 else if (mc_global.eight_bit_clean)
921 current_mode = 1;
922 else
923 current_mode = 2;
925 new_meta = !use_8th_bit_as_meta;
927 if (quick_dialog (&qdlg) != B_CANCEL)
929 mc_global.eight_bit_clean = current_mode < 3;
930 mc_global.full_eight_bits = current_mode < 2;
931 #ifndef HAVE_SLANG
932 meta (stdscr, mc_global.eight_bit_clean);
933 #else
934 SLsmg_Display_Eight_Bit = mc_global.full_eight_bits ? 128 : 160;
935 #endif
936 use_8th_bit_as_meta = !new_meta;
940 /* --------------------------------------------------------------------------------------------- */
941 #else /* HAVE_CHARSET */
943 void
944 display_bits_box (void)
946 const char *cpname;
948 new_display_codepage = mc_global.display_codepage;
950 cpname = (new_display_codepage < 0) ? _("Other 8 bit")
951 : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
954 int new_meta;
956 quick_widget_t quick_widgets[] = {
957 /* *INDENT-OFF* */
958 QUICK_START_COLUMNS,
959 QUICK_LABEL (N_("Input / display codepage:"), NULL),
960 QUICK_NEXT_COLUMN,
961 QUICK_BUTTON (cpname, B_USER, sel_charset_button, NULL),
962 QUICK_STOP_COLUMNS,
963 QUICK_SEPARATOR (TRUE),
964 QUICK_CHECKBOX (N_("F&ull 8 bits input"), &new_meta, NULL),
965 QUICK_BUTTONS_OK_CANCEL,
966 QUICK_END
967 /* *INDENT-ON* */
970 quick_dialog_t qdlg = {
971 -1, -1, 46,
972 N_("Display bits"), "[Display bits]",
973 quick_widgets, NULL, NULL
976 new_meta = !use_8th_bit_as_meta;
977 application_keypad_mode ();
979 if (quick_dialog (&qdlg) == B_ENTER)
981 char *errmsg;
983 mc_global.display_codepage = new_display_codepage;
985 errmsg = init_translation_table (mc_global.source_codepage, mc_global.display_codepage);
986 if (errmsg != NULL)
988 message (D_ERROR, MSG_ERROR, "%s", errmsg);
989 g_free (errmsg);
992 #ifdef HAVE_SLANG
993 tty_display_8bit (mc_global.display_codepage != 0 && mc_global.display_codepage != 1);
994 #else
995 tty_display_8bit (mc_global.display_codepage != 0);
996 #endif
997 use_8th_bit_as_meta = !new_meta;
999 repaint_screen ();
1003 #endif /* HAVE_CHARSET */
1005 /* --------------------------------------------------------------------------------------------- */
1006 /** Show tree in a box, not on a panel */
1008 char *
1009 tree_box (const char *current_dir)
1011 WTree *mytree;
1012 WDialog *dlg;
1013 Widget *wd;
1014 char *val = NULL;
1015 WButtonBar *bar;
1017 (void) current_dir;
1019 /* Create the components */
1020 dlg = dlg_create (TRUE, 0, 0, LINES - 9, COLS - 20, dialog_colors, tree_callback, NULL,
1021 "[Directory Tree]", _("Directory tree"), DLG_CENTER);
1022 wd = WIDGET (dlg);
1024 mytree = tree_new (2, 2, wd->lines - 6, wd->cols - 5, FALSE);
1025 add_widget_autopos (dlg, mytree, WPOS_KEEP_ALL, NULL);
1026 add_widget_autopos (dlg, hline_new (wd->lines - 4, 1, -1), WPOS_KEEP_BOTTOM, NULL);
1027 bar = buttonbar_new (TRUE);
1028 add_widget (dlg, bar);
1029 /* restore ButtonBar coordinates after add_widget() */
1030 WIDGET (bar)->x = 0;
1031 WIDGET (bar)->y = LINES - 1;
1033 if (dlg_run (dlg) == B_ENTER)
1035 const vfs_path_t *selected_name;
1037 selected_name = tree_selected_name (mytree);
1038 val = g_strdup (vfs_path_as_str (selected_name));
1041 dlg_destroy (dlg);
1042 return val;
1045 /* --------------------------------------------------------------------------------------------- */
1047 #ifdef ENABLE_VFS
1048 void
1049 configure_vfs (void)
1051 char buffer2[BUF_TINY];
1052 #ifdef ENABLE_VFS_FTP
1053 char buffer3[BUF_TINY];
1055 g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
1056 #endif
1058 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
1061 char *ret_timeout;
1062 #ifdef ENABLE_VFS_FTP
1063 char *ret_passwd;
1064 char *ret_ftp_proxy;
1065 char *ret_directory_timeout;
1066 #endif /* ENABLE_VFS_FTP */
1068 quick_widget_t quick_widgets[] = {
1069 /* *INDENT-OFF* */
1070 QUICK_LABELED_INPUT (N_("Timeout for freeing VFSs (sec):"), input_label_left,
1071 buffer2, "input-timo-vfs", &ret_timeout, NULL, FALSE, FALSE,
1072 INPUT_COMPLETE_NONE),
1073 #ifdef ENABLE_VFS_FTP
1074 QUICK_SEPARATOR (TRUE),
1075 QUICK_LABELED_INPUT (N_("FTP anonymous password:"), input_label_left,
1076 ftpfs_anonymous_passwd, "input-passwd", &ret_passwd, NULL,
1077 FALSE, FALSE, INPUT_COMPLETE_NONE),
1078 QUICK_LABELED_INPUT (N_("FTP directory cache timeout (sec):"), input_label_left,
1079 buffer3, "input-timeout", &ret_directory_timeout, NULL,
1080 FALSE, FALSE, INPUT_COMPLETE_NONE),
1081 QUICK_CHECKBOX (N_("&Always use ftp proxy:"), &ftpfs_always_use_proxy,
1082 &ftpfs_always_use_proxy_id),
1083 QUICK_INPUT (ftpfs_proxy_host, "input-ftp-proxy", &ret_ftp_proxy,
1084 &ftpfs_proxy_host_id, FALSE, FALSE, INPUT_COMPLETE_HOSTNAMES),
1085 QUICK_CHECKBOX (N_("&Use ~/.netrc"), &ftpfs_use_netrc, NULL),
1086 QUICK_CHECKBOX (N_("Use &passive mode"), &ftpfs_use_passive_connections, NULL),
1087 QUICK_CHECKBOX (N_("Use passive mode over pro&xy"),
1088 &ftpfs_use_passive_connections_over_proxy, NULL),
1089 #endif /* ENABLE_VFS_FTP */
1090 QUICK_BUTTONS_OK_CANCEL,
1091 QUICK_END
1092 /* *INDENT-ON* */
1095 quick_dialog_t qdlg = {
1096 -1, -1, 56,
1097 N_("Virtual File System Setting"), "[Virtual FS]",
1098 quick_widgets,
1099 #ifdef ENABLE_VFS_FTP
1100 confvfs_callback,
1101 #else
1102 NULL,
1103 #endif
1104 NULL,
1107 #ifdef ENABLE_VFS_FTP
1108 if (!ftpfs_always_use_proxy)
1109 quick_widgets[5].options = W_DISABLED;
1110 #endif
1112 if (quick_dialog (&qdlg) != B_CANCEL)
1114 /* cppcheck-suppress uninitvar */
1115 vfs_timeout = atoi (ret_timeout);
1116 g_free (ret_timeout);
1118 if (vfs_timeout < 0 || vfs_timeout > 10000)
1119 vfs_timeout = 10;
1120 #ifdef ENABLE_VFS_FTP
1121 g_free (ftpfs_anonymous_passwd);
1122 /* cppcheck-suppress uninitvar */
1123 ftpfs_anonymous_passwd = ret_passwd;
1124 g_free (ftpfs_proxy_host);
1125 /* cppcheck-suppress uninitvar */
1126 ftpfs_proxy_host = ret_ftp_proxy;
1127 /* cppcheck-suppress uninitvar */
1128 ftpfs_directory_timeout = atoi (ret_directory_timeout);
1129 g_free (ret_directory_timeout);
1130 #endif
1135 #endif /* ENABLE_VFS */
1137 /* --------------------------------------------------------------------------------------------- */
1139 char *
1140 cd_dialog (void)
1142 const Widget *w = CONST_WIDGET (current_panel);
1143 char *my_str;
1145 quick_widget_t quick_widgets[] = {
1146 QUICK_LABELED_INPUT (N_("cd"), input_label_left, "", "input", &my_str, NULL, FALSE, TRUE,
1147 INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_CD),
1148 QUICK_END
1151 quick_dialog_t qdlg = {
1152 w->y + w->lines - 6, w->x, w->cols,
1153 N_("Quick cd"), "[Quick cd]",
1154 quick_widgets, NULL, NULL
1157 return (quick_dialog (&qdlg) != B_CANCEL) ? my_str : NULL;
1160 /* --------------------------------------------------------------------------------------------- */
1162 void
1163 symlink_dialog (const vfs_path_t * existing_vpath, const vfs_path_t * new_vpath,
1164 char **ret_existing, char **ret_new)
1166 quick_widget_t quick_widgets[] = {
1167 /* *INDENT-OFF* */
1168 QUICK_LABELED_INPUT (N_("Existing filename (filename symlink will point to):"),
1169 input_label_above, vfs_path_as_str (existing_vpath), "input-2",
1170 ret_existing, NULL, FALSE, FALSE, INPUT_COMPLETE_FILENAMES),
1171 QUICK_SEPARATOR (FALSE),
1172 QUICK_LABELED_INPUT (N_("Symbolic link filename:"), input_label_above,
1173 vfs_path_as_str (new_vpath), "input-1",
1174 ret_new, NULL, FALSE, FALSE, INPUT_COMPLETE_FILENAMES),
1175 QUICK_BUTTONS_OK_CANCEL,
1176 QUICK_END
1177 /* *INDENT-ON* */
1180 quick_dialog_t qdlg = {
1181 -1, -1, 64,
1182 N_("Symbolic link"), "[File Menu]",
1183 quick_widgets, NULL, NULL
1186 if (quick_dialog (&qdlg) == B_CANCEL)
1188 *ret_new = NULL;
1189 *ret_existing = NULL;
1193 /* --------------------------------------------------------------------------------------------- */
1195 #ifdef ENABLE_BACKGROUND
1196 void
1197 jobs_cmd (void)
1199 struct
1201 const char *name;
1202 int flags;
1203 int value;
1204 int len;
1205 bcback_fn callback;
1207 job_but[] =
1209 /* *INDENT-OFF* */
1210 { N_("&Stop"), NORMAL_BUTTON, B_STOP, 0, task_cb },
1211 { N_("&Resume"), NORMAL_BUTTON, B_RESUME, 0, task_cb },
1212 { N_("&Kill"), NORMAL_BUTTON, B_KILL, 0, task_cb },
1213 { N_("&OK"), DEFPUSH_BUTTON, B_CANCEL, 0, NULL }
1214 /* *INDENT-ON* */
1217 size_t i;
1218 const size_t n_but = G_N_ELEMENTS (job_but);
1220 WDialog *jobs_dlg;
1221 int cols = 60;
1222 int lines = 15;
1223 int x = 0;
1225 for (i = 0; i < n_but; i++)
1227 #ifdef ENABLE_NLS
1228 job_but[i].name = _(job_but[i].name);
1229 #endif /* ENABLE_NLS */
1231 job_but[i].len = str_term_width1 (job_but[i].name) + 3;
1232 if (job_but[i].flags == DEFPUSH_BUTTON)
1233 job_but[i].len += 2;
1234 x += job_but[i].len;
1237 x += (int) n_but - 1;
1238 cols = MAX (cols, x + 6);
1240 jobs_dlg = dlg_create (TRUE, 0, 0, lines, cols, dialog_colors, NULL, NULL,
1241 "[Background jobs]", _("Background jobs"), DLG_CENTER);
1243 bg_list = listbox_new (2, 2, lines - 6, cols - 6, FALSE, NULL);
1244 jobs_fill_listbox (bg_list);
1245 add_widget (jobs_dlg, bg_list);
1247 add_widget (jobs_dlg, hline_new (lines - 4, -1, -1));
1249 x = (cols - x) / 2;
1250 for (i = 0; i < n_but; i++)
1252 add_widget (jobs_dlg,
1253 button_new (lines - 3, x, job_but[i].value, job_but[i].flags, job_but[i].name,
1254 job_but[i].callback));
1255 x += job_but[i].len + 1;
1258 (void) dlg_run (jobs_dlg);
1259 dlg_destroy (jobs_dlg);
1261 #endif /* ENABLE_BACKGROUND */
1263 /* --------------------------------------------------------------------------------------------- */
1265 #ifdef ENABLE_VFS_SMB
1266 struct smb_authinfo *
1267 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, const char *user)
1269 char *label;
1270 struct smb_authinfo *return_value = NULL;
1272 if (domain == NULL)
1273 domain = "";
1274 if (user == NULL)
1275 user = "";
1277 label = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1280 char *ret_domain, *ret_user, *ret_password;
1282 quick_widget_t quick_widgets[] = {
1283 /* *INDENT-OFF* */
1284 QUICK_LABEL (label, NULL),
1285 QUICK_SEPARATOR (TRUE),
1286 QUICK_START_COLUMNS,
1287 QUICK_LABEL (N_("Domain:"), NULL),
1288 QUICK_SEPARATOR (FALSE),
1289 QUICK_LABEL (N_("Username:"), NULL),
1290 QUICK_SEPARATOR (FALSE),
1291 QUICK_LABEL (N_("Password:"), NULL),
1292 QUICK_NEXT_COLUMN,
1293 QUICK_INPUT (domain, "auth_domain", &ret_domain, NULL, FALSE, FALSE, INPUT_COMPLETE_HOSTNAMES),
1294 QUICK_SEPARATOR (FALSE),
1295 QUICK_INPUT (user, "auth_name", &ret_user, NULL, FALSE, FALSE, INPUT_COMPLETE_USERNAMES),
1296 QUICK_SEPARATOR (FALSE),
1297 QUICK_INPUT ("", "auth_password", &ret_password, NULL, TRUE, FALSE, INPUT_COMPLETE_NONE),
1298 QUICK_STOP_COLUMNS,
1299 QUICK_BUTTONS_OK_CANCEL,
1300 QUICK_END
1301 /* *INDENT-ON* */
1304 quick_dialog_t qdlg = {
1305 -1, -1, 40,
1306 N_("SMB authentication"), "[Smb Authinfo]",
1307 quick_widgets, NULL, NULL
1310 if (quick_dialog (&qdlg) != B_CANCEL)
1312 return_value = vfs_smb_authinfo_new (host, share, ret_domain, ret_user, ret_password);
1314 g_free (ret_domain);
1315 g_free (ret_user);
1316 g_free (ret_password);
1320 g_free (label);
1322 return return_value;
1324 #endif /* ENABLE_VFS_SMB */
1326 /* --------------------------------------------------------------------------------------------- */