(skin_dlg_callback): add forgotten return.
[midnight-commander.git] / src / filemanager / boxes.c
blob4b451cf07949f8ab9eaf22c4c214d905368ba245
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 && parm == (int) MSG_FOCUS)
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 cb_ret_t
186 skin_dlg_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
188 switch (msg)
190 case MSG_RESIZE:
192 WDialog *d = DIALOG (w);
193 Widget *wd = WIDGET (d->data);
194 int y, x;
196 y = wd->y + (wd->lines - w->lines) / 2;
197 x = wd->x + wd->cols / 2;
198 dlg_set_position (d, y, x, w->lines, w->cols);
200 return MSG_HANDLED;
203 default:
204 return dlg_default_callback (w, sender, msg, parm, data);
208 /* --------------------------------------------------------------------------------------------- */
210 static int
211 sel_skin_button (WButton * button, int action)
213 int result;
214 WListbox *skin_list;
215 WDialog *skin_dlg;
216 const gchar *skin_name;
217 unsigned int i;
218 unsigned int pos = 1;
220 (void) action;
222 skin_dlg =
223 dlg_create (TRUE, 0, 0, 13, 24, WPOS_KEEP_DEFAULT, TRUE, dialog_colors, skin_dlg_callback,
224 NULL, "[Appearance]", _("Skins"));
225 /* use Appearance dialog for positioning */
226 skin_dlg->data = WIDGET (button)->owner;
228 /* set dialog location before all */
229 send_message (skin_dlg, NULL, MSG_RESIZE, 0, NULL);
231 skin_list = listbox_new (1, 1, 11, 22, FALSE, NULL);
232 skin_name = "default";
233 listbox_add_item (skin_list, LISTBOX_APPEND_AT_END, 0, skin_name_to_label (skin_name),
234 (void *) skin_name, FALSE);
236 if (strcmp (skin_name, current_skin_name) == 0)
237 listbox_select_entry (skin_list, 0);
239 for (i = 0; i < skin_names->len; i++)
241 skin_name = g_ptr_array_index (skin_names, i);
242 if (strcmp (skin_name, "default") != 0)
244 listbox_add_item (skin_list, LISTBOX_APPEND_AT_END, 0, skin_name_to_label (skin_name),
245 (void *) skin_name, FALSE);
246 if (strcmp (skin_name, current_skin_name) == 0)
247 listbox_select_entry (skin_list, pos);
248 pos++;
252 /* make list stick to all sides of dialog, effectively make it be resized with dialog */
253 add_widget_autopos (skin_dlg, skin_list, WPOS_KEEP_ALL, NULL);
255 result = dlg_run (skin_dlg);
256 if (result == B_ENTER)
258 gchar *skin_label;
260 listbox_get_current (skin_list, &skin_label, (void **) &skin_name);
261 g_free (current_skin_name);
262 current_skin_name = g_strdup (skin_name);
263 skin_apply (skin_name);
265 button_set_text (button, str_fit_to_term (skin_label, 20, J_LEFT_FIT));
267 dlg_destroy (skin_dlg);
269 return 0;
272 /* --------------------------------------------------------------------------------------------- */
274 static cb_ret_t
275 panel_listing_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
277 WDialog *h = DIALOG (w);
279 switch (msg)
281 case MSG_NOTIFY:
282 if (sender != NULL && sender->id == panel_listing_types_id && parm == (int) MSG_FOCUS)
284 WCheck *ch;
285 WInput *in1, *in2, *in3;
287 in1 = INPUT (dlg_find_by_id (h, panel_user_format_id));
288 in2 = INPUT (dlg_find_by_id (h, panel_brief_cols_id));
289 ch = CHECK (dlg_find_by_id (h, mini_user_status_id));
290 in3 = INPUT (dlg_find_by_id (h, mini_user_format_id));
292 if (!(ch->state & C_BOOL))
293 input_assign_text (in3, status_format[RADIO (sender)->sel]);
294 input_update (in1, FALSE);
295 input_update (in2, FALSE);
296 input_update (in3, FALSE);
297 widget_disable (WIDGET (in1), RADIO (sender)->sel != panel_listing_user_idx);
298 widget_disable (WIDGET (in2), RADIO (sender)->sel != panel_listing_brief_idx);
299 return MSG_HANDLED;
302 if (sender != NULL && sender->id == mini_user_status_id && parm == (int) MSG_FOCUS)
304 WInput *in;
306 in = INPUT (dlg_find_by_id (h, mini_user_format_id));
308 if (CHECK (sender)->state & C_BOOL)
310 widget_disable (WIDGET (in), FALSE);
311 input_assign_text (in, status_format[3]);
313 else
315 WRadio *r;
317 r = RADIO (dlg_find_by_id (h, panel_listing_types_id));
318 widget_disable (WIDGET (in), TRUE);
319 input_assign_text (in, status_format[r->sel]);
321 /* input_update (in, FALSE); */
322 return MSG_HANDLED;
325 return MSG_NOT_HANDLED;
327 default:
328 return dlg_default_callback (w, sender, msg, parm, data);
332 /* --------------------------------------------------------------------------------------------- */
334 #ifdef HAVE_CHARSET
335 static int
336 sel_charset_button (WButton * button, int action)
338 int new_dcp;
340 (void) action;
342 new_dcp = select_charset (-1, -1, new_display_codepage, TRUE);
344 if (new_dcp != SELECT_CHARSET_CANCEL)
346 const char *cpname;
348 new_display_codepage = new_dcp;
349 cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
350 _("Other 8 bit") :
351 ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
352 if (cpname != NULL)
353 mc_global.utf8_display = str_isutf8 (cpname);
354 else
355 cpname = _("7-bit ASCII"); /* FIXME */
357 button_set_text (button, cpname);
358 dlg_redraw (WIDGET (button)->owner);
361 return 0;
363 #endif /* HAVE_CHARSET */
365 /* --------------------------------------------------------------------------------------------- */
367 static cb_ret_t
368 tree_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
370 WDialog *h = DIALOG (w);
372 switch (msg)
374 case MSG_RESIZE:
376 Widget *bar;
378 /* simply call dlg_set_size() with new size */
379 dlg_set_size (h, LINES - 9, COLS - 20);
380 bar = WIDGET (find_buttonbar (h));
381 bar->x = 0;
382 bar->y = LINES - 1;
383 return MSG_HANDLED;
386 case MSG_ACTION:
387 return send_message (find_tree (h), NULL, MSG_ACTION, parm, NULL);
389 default:
390 return dlg_default_callback (w, sender, msg, parm, data);
394 /* --------------------------------------------------------------------------------------------- */
396 #if defined(ENABLE_VFS) && defined (ENABLE_VFS_FTP)
397 static cb_ret_t
398 confvfs_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
400 switch (msg)
402 case MSG_NOTIFY:
403 /* message from "Always use ftp proxy" checkbutton */
404 if (sender != NULL && sender->id == ftpfs_always_use_proxy_id && parm == (int) MSG_FOCUS)
406 const gboolean not_use = !(CHECK (sender)->state & C_BOOL);
407 Widget *wi;
409 /* input */
410 wi = dlg_find_by_id (DIALOG (w), ftpfs_proxy_host_id);
411 widget_disable (wi, not_use);
412 return MSG_HANDLED;
414 return MSG_NOT_HANDLED;
416 default:
417 return dlg_default_callback (w, sender, msg, parm, data);
420 #endif /* ENABLE_VFS && ENABLE_VFS_FTP */
422 /* --------------------------------------------------------------------------------------------- */
424 #ifdef ENABLE_BACKGROUND
425 static void
426 jobs_fill_listbox (WListbox * list)
428 static const char *state_str[2] = { "", "" };
429 TaskList *tl;
431 if (state_str[0] == '\0')
433 state_str[0] = _("Running");
434 state_str[1] = _("Stopped");
437 for (tl = task_list; tl != NULL; tl = tl->next)
439 char *s;
441 s = g_strconcat (state_str[tl->state], " ", tl->info, (char *) NULL);
442 listbox_add_item (list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl, FALSE);
443 g_free (s);
447 /* --------------------------------------------------------------------------------------------- */
449 static int
450 task_cb (WButton * button, int action)
452 TaskList *tl;
453 int sig = 0;
455 (void) button;
457 if (bg_list->list == NULL)
458 return 0;
460 /* Get this instance information */
461 listbox_get_current (bg_list, NULL, (void **) &tl);
463 #ifdef SIGTSTP
464 if (action == B_STOP)
466 sig = SIGSTOP;
467 tl->state = Task_Stopped;
469 else if (action == B_RESUME)
471 sig = SIGCONT;
472 tl->state = Task_Running;
474 else
475 #endif
476 if (action == B_KILL)
477 sig = SIGKILL;
479 if (sig == SIGKILL)
480 unregister_task_running (tl->pid, tl->fd);
482 kill (tl->pid, sig);
483 listbox_remove_list (bg_list);
484 jobs_fill_listbox (bg_list);
486 /* This can be optimized to just redraw this widget :-) */
487 dlg_redraw (WIDGET (button)->owner);
489 return 0;
491 #endif /* ENABLE_BACKGROUND */
493 /* --------------------------------------------------------------------------------------------- */
494 /*** public functions ****************************************************************************/
495 /* --------------------------------------------------------------------------------------------- */
497 void
498 configure_box (void)
500 const char *pause_options[] = {
501 N_("&Never"),
502 N_("On dum&b terminals"),
503 N_("Alwa&ys")
506 int pause_options_num;
508 pause_options_num = G_N_ELEMENTS (pause_options);
511 char time_out[BUF_TINY] = "";
512 char *time_out_new;
514 quick_widget_t quick_widgets[] = {
515 /* *INDENT-OFF* */
516 QUICK_START_COLUMNS,
517 QUICK_START_GROUPBOX (N_("File operations")),
518 QUICK_CHECKBOX (N_("&Verbose operation"), &verbose, NULL),
519 QUICK_CHECKBOX (N_("Compute tota&ls"), &file_op_compute_totals, NULL),
520 QUICK_CHECKBOX (N_("Classic pro&gressbar"), &classic_progressbar, NULL),
521 QUICK_CHECKBOX (N_("Mkdi&r autoname"), &auto_fill_mkdir_name, NULL),
522 QUICK_CHECKBOX (N_("&Preallocate space"), &mc_global.vfs.preallocate_space,
523 NULL),
524 QUICK_STOP_GROUPBOX,
525 QUICK_START_GROUPBOX (N_("Esc key mode")),
526 QUICK_CHECKBOX (N_("S&ingle press"), &old_esc_mode, &configure_old_esc_mode_id),
527 QUICK_LABELED_INPUT (N_("Timeout:"), input_label_left,
528 (const char *) time_out, MC_HISTORY_ESC_TIMEOUT,
529 &time_out_new, &configure_time_out_id, FALSE, FALSE,
530 INPUT_COMPLETE_NONE),
531 QUICK_STOP_GROUPBOX,
532 QUICK_START_GROUPBOX (N_("Pause after run")),
533 QUICK_RADIO (pause_options_num, pause_options, &pause_after_run, NULL),
534 QUICK_STOP_GROUPBOX,
535 QUICK_NEXT_COLUMN,
536 QUICK_START_GROUPBOX (N_("Other options")),
537 QUICK_CHECKBOX (N_("Use internal edi&t"), &use_internal_edit, NULL),
538 QUICK_CHECKBOX (N_("Use internal vie&w"), &use_internal_view, NULL),
539 QUICK_CHECKBOX (N_("A&sk new file name"),
540 &editor_ask_filename_before_edit, NULL),
541 QUICK_CHECKBOX (N_("Auto m&enus"), &auto_menu, NULL),
542 QUICK_CHECKBOX (N_("&Drop down menus"), &drop_menus, NULL),
543 QUICK_CHECKBOX (N_("S&hell patterns"), &easy_patterns, NULL),
544 QUICK_CHECKBOX (N_("Co&mplete: show all"),
545 &mc_global.widget.show_all_if_ambiguous, NULL),
546 QUICK_CHECKBOX (N_("Rotating d&ash"), &nice_rotating_dash, NULL),
547 QUICK_CHECKBOX (N_("Cd follows lin&ks"), &mc_global.vfs.cd_symlinks, NULL),
548 QUICK_CHECKBOX (N_("Sa&fe delete"), &safe_delete, NULL),
549 QUICK_CHECKBOX (N_("A&uto save setup"), &auto_save_setup, NULL),
550 QUICK_SEPARATOR (FALSE),
551 QUICK_SEPARATOR (FALSE),
552 QUICK_SEPARATOR (FALSE),
553 QUICK_STOP_GROUPBOX,
554 QUICK_STOP_COLUMNS,
555 QUICK_BUTTONS_OK_CANCEL,
556 QUICK_END
557 /* *INDENT-ON* */
560 quick_dialog_t qdlg = {
561 -1, -1, 60,
562 N_("Configure options"), "[Configuration]",
563 quick_widgets, configure_callback, NULL
566 g_snprintf (time_out, sizeof (time_out), "%d", old_esc_mode_timeout);
568 #ifndef USE_INTERNAL_EDIT
569 quick_widgets[17].state = WST_DISABLED;
570 #endif
572 if (!old_esc_mode)
573 quick_widgets[10].state = quick_widgets[11].state = WST_DISABLED;
575 #ifndef HAVE_POSIX_FALLOCATE
576 mc_global.vfs.preallocate_space = FALSE;
577 quick_widgets[7].state = WST_DISABLED;
578 #endif
580 if (quick_dialog (&qdlg) == B_ENTER)
581 old_esc_mode_timeout = atoi (time_out_new);
583 g_free (time_out_new);
587 /* --------------------------------------------------------------------------------------------- */
589 void
590 appearance_box (void)
592 current_skin_name = g_strdup (mc_skin__default.name);
593 skin_names = mc_skin_list ();
596 quick_widget_t quick_widgets[] = {
597 /* *INDENT-OFF* */
598 QUICK_START_COLUMNS,
599 QUICK_LABEL (N_("Skin:"), NULL),
600 QUICK_NEXT_COLUMN,
601 QUICK_BUTTON (str_fit_to_term (skin_name_to_label (current_skin_name), 20, J_LEFT_FIT),
602 B_USER, sel_skin_button, NULL),
603 QUICK_STOP_COLUMNS,
604 QUICK_BUTTONS_OK_CANCEL,
605 QUICK_END
606 /* *INDENT-ON* */
609 quick_dialog_t qdlg = {
610 -1, -1, 54,
611 N_("Appearance"), "[Appearance]",
612 quick_widgets, dlg_default_callback, NULL
615 if (quick_dialog (&qdlg) == B_ENTER)
616 mc_config_set_string (mc_global.main_config, CONFIG_APP_SECTION, "skin",
617 current_skin_name);
618 else
619 skin_apply (NULL);
622 g_free (current_skin_name);
623 g_ptr_array_foreach (skin_names, (GFunc) g_free, NULL);
624 g_ptr_array_free (skin_names, TRUE);
627 /* --------------------------------------------------------------------------------------------- */
629 void
630 panel_options_box (void)
632 int simple_swap;
634 simple_swap = mc_config_get_bool (mc_global.main_config, CONFIG_PANELS_SECTION,
635 "simple_swap", FALSE) ? 1 : 0;
637 const char *qsearch_options[] = {
638 N_("Case &insensitive"),
639 N_("Cas&e sensitive"),
640 N_("Use panel sort mo&de")
643 quick_widget_t quick_widgets[] = {
644 /* *INDENT-OFF* */
645 QUICK_START_COLUMNS,
646 QUICK_START_GROUPBOX (N_("Main options")),
647 QUICK_CHECKBOX (N_("Show mi&ni-status"), &panels_options.show_mini_info, NULL),
648 QUICK_CHECKBOX (N_("Use SI si&ze units"), &panels_options.kilobyte_si, NULL),
649 QUICK_CHECKBOX (N_("Mi&x all files"), &panels_options.mix_all_files, NULL),
650 QUICK_CHECKBOX (N_("Show &backup files"), &panels_options.show_backups, NULL),
651 QUICK_CHECKBOX (N_("Show &hidden files"), &panels_options.show_dot_files, NULL),
652 QUICK_CHECKBOX (N_("&Fast dir reload"), &panels_options.fast_reload, NULL),
653 QUICK_CHECKBOX (N_("Ma&rk moves down"), &panels_options.mark_moves_down, NULL),
654 QUICK_CHECKBOX (N_("Re&verse files only"), &panels_options.reverse_files_only,
655 NULL),
656 QUICK_CHECKBOX (N_("Simple s&wap"), &simple_swap, NULL),
657 QUICK_CHECKBOX (N_("A&uto save panels setup"), &panels_options.auto_save_setup,
658 NULL),
659 QUICK_SEPARATOR (FALSE),
660 QUICK_SEPARATOR (FALSE),
661 QUICK_SEPARATOR (FALSE),
662 QUICK_STOP_GROUPBOX,
663 QUICK_NEXT_COLUMN,
664 QUICK_START_GROUPBOX (N_("Navigation")),
665 QUICK_CHECKBOX (N_("L&ynx-like motion"), &panels_options.navigate_with_arrows,
666 NULL),
667 QUICK_CHECKBOX (N_("Pa&ge scrolling"), &panels_options.scroll_pages, NULL),
668 QUICK_CHECKBOX (N_("Center &scrolling"), &panels_options.scroll_center, NULL),
669 QUICK_CHECKBOX (N_("&Mouse page scrolling"), &panels_options.mouse_move_pages,
670 NULL),
671 QUICK_STOP_GROUPBOX,
672 QUICK_START_GROUPBOX (N_("File highlight")),
673 QUICK_CHECKBOX (N_("File &types"), &panels_options.filetype_mode, NULL),
674 QUICK_CHECKBOX (N_("&Permissions"), &panels_options.permission_mode, NULL),
675 QUICK_STOP_GROUPBOX,
676 QUICK_START_GROUPBOX (N_("Quick search")),
677 QUICK_RADIO (QSEARCH_NUM, qsearch_options, (int *) &panels_options.qsearch_mode,
678 NULL),
679 QUICK_STOP_GROUPBOX,
680 QUICK_STOP_COLUMNS,
681 QUICK_BUTTONS_OK_CANCEL,
682 QUICK_END
683 /* *INDENT-ON* */
686 quick_dialog_t qdlg = {
687 -1, -1, 60,
688 N_("Panel options"), "[Panel options]",
689 quick_widgets, NULL, NULL
692 if (quick_dialog (&qdlg) != B_ENTER)
693 return;
696 mc_config_set_bool (mc_global.main_config, CONFIG_PANELS_SECTION,
697 "simple_swap", (gboolean) (simple_swap & C_BOOL));
699 if (!panels_options.fast_reload_msg_shown && panels_options.fast_reload)
701 message (D_NORMAL, _("Information"),
702 _("Using the fast reload option may not reflect the exact\n"
703 "directory contents. In this case you'll need to do a\n"
704 "manual reload of the directory. See the man page for\n" "the details."));
705 panels_options.fast_reload_msg_shown = TRUE;
708 update_panels (UP_RELOAD, UP_KEEPSEL);
711 /* --------------------------------------------------------------------------------------------- */
713 /* return list type */
715 panel_listing_box (WPanel * panel, int num, char **userp, char **minip, int *use_msformat,
716 int *brief_cols)
718 int result = -1;
719 char *section = NULL;
721 if (panel == NULL)
723 const char *p;
724 size_t i;
726 p = get_nth_panel_name (num);
727 panel = g_new (WPanel, 1);
728 panel->list_type = list_full;
729 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
730 panel->user_mini_status = 0;
731 for (i = 0; i < LIST_TYPES; i++)
732 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
733 section = g_strconcat ("Temporal:", p, (char *) NULL);
734 if (!mc_config_has_group (mc_global.main_config, section))
736 g_free (section);
737 section = g_strdup (p);
739 panel_load_setup (panel, section);
740 g_free (section);
744 int mini_user_status;
745 char panel_brief_cols_in[BUF_TINY];
746 char *panel_brief_cols_out = NULL;
747 char *panel_user_format = NULL;
748 char *mini_user_format = NULL;
750 /* Controls whether the array strings have been translated */
751 const char *list_types[LIST_TYPES] = {
752 N_("&Full file list"),
753 N_("&Brief file list:"),
754 N_("&Long file list"),
755 N_("&User defined:")
758 quick_widget_t quick_widgets[] = {
759 /* *INDENT-OFF* */
760 QUICK_START_COLUMNS,
761 QUICK_RADIO (LIST_TYPES, list_types, &result, &panel_listing_types_id),
762 QUICK_NEXT_COLUMN,
763 QUICK_SEPARATOR (FALSE),
764 QUICK_LABELED_INPUT (_ ("columns"), input_label_right, panel_brief_cols_in,
765 "panel-brief-cols-input", &panel_brief_cols_out,
766 &panel_brief_cols_id, FALSE, FALSE, INPUT_COMPLETE_NONE),
767 QUICK_STOP_COLUMNS,
768 QUICK_INPUT (panel->user_format, "user-fmt-input", &panel_user_format,
769 &panel_user_format_id, FALSE, FALSE, INPUT_COMPLETE_NONE),
770 QUICK_SEPARATOR (TRUE),
771 QUICK_CHECKBOX (N_("User &mini status"), &mini_user_status, &mini_user_status_id),
772 QUICK_INPUT (panel->user_status_format[panel->list_type], "mini_input",
773 &mini_user_format, &mini_user_format_id, FALSE, FALSE, INPUT_COMPLETE_NONE),
774 QUICK_BUTTONS_OK_CANCEL,
775 QUICK_END
776 /* *INDENT-ON* */
779 quick_dialog_t qdlg = {
780 -1, -1, 48,
781 N_("Listing mode"), "[Listing Mode...]",
782 quick_widgets, panel_listing_callback, NULL
785 mini_user_status = panel->user_mini_status;
786 result = panel->list_type;
787 status_format = panel->user_status_format;
789 g_snprintf (panel_brief_cols_in, sizeof (panel_brief_cols_in), "%d", panel->brief_cols);
791 if ((int) panel->list_type != panel_listing_brief_idx)
792 quick_widgets[4].state = WST_DISABLED;
794 if ((int) panel->list_type != panel_listing_user_idx)
795 quick_widgets[6].state = WST_DISABLED;
797 if (!mini_user_status)
798 quick_widgets[9].state = WST_DISABLED;
800 if (quick_dialog (&qdlg) == B_CANCEL)
801 result = -1;
802 else
804 int cols;
805 char *error = NULL;
807 *userp = panel_user_format;
808 *minip = mini_user_format;
809 *use_msformat = mini_user_status;
811 cols = strtol (panel_brief_cols_out, &error, 10);
812 if (*error == '\0')
813 *brief_cols = cols;
814 else
815 *brief_cols = panel->brief_cols;
817 g_free (panel_brief_cols_out);
821 if (section != NULL)
823 int i;
825 g_free (panel->user_format);
826 for (i = 0; i < LIST_TYPES; i++)
827 g_free (panel->user_status_format[i]);
828 g_free (panel);
831 return result;
834 /* --------------------------------------------------------------------------------------------- */
836 const panel_field_t *
837 sort_box (dir_sort_options_t * op, const panel_field_t * sort_field)
839 char **sort_orders_names;
840 gsize i;
841 gsize sort_names_num = 0;
842 int sort_idx = 0;
843 const panel_field_t *result = NULL;
845 sort_orders_names = panel_get_sortable_fields (&sort_names_num);
847 for (i = 0; i < sort_names_num; i++)
848 if (strcmp (sort_orders_names[i], _(sort_field->title_hotkey)) == 0)
850 sort_idx = i;
851 break;
855 quick_widget_t quick_widgets[] = {
856 /* *INDENT-OFF* */
857 QUICK_START_COLUMNS,
858 QUICK_RADIO (sort_names_num, (const char **) sort_orders_names, &sort_idx, NULL),
859 QUICK_NEXT_COLUMN,
860 QUICK_CHECKBOX (N_("Executable &first"), &op->exec_first, NULL),
861 QUICK_CHECKBOX (N_("Cas&e sensitive"), &op->case_sensitive, NULL),
862 QUICK_CHECKBOX (N_("&Reverse"), &op->reverse, NULL),
863 QUICK_STOP_COLUMNS,
864 QUICK_BUTTONS_OK_CANCEL,
865 QUICK_END
866 /* *INDENT-ON* */
869 quick_dialog_t qdlg = {
870 -1, -1, 40,
871 N_("Sort order"), "[Sort Order...]",
872 quick_widgets, NULL, NULL
875 if (quick_dialog (&qdlg) != B_CANCEL)
876 result = panel_get_field_by_title_hotkey (sort_orders_names[sort_idx]);
878 if (result == NULL)
879 result = sort_field;
882 g_strfreev (sort_orders_names);
884 return result;
887 /* --------------------------------------------------------------------------------------------- */
889 void
890 confirm_box (void)
892 quick_widget_t quick_widgets[] = {
893 /* *INDENT-OFF* */
894 /* TRANSLATORS: no need to translate 'Confirmation', it's just a context prefix */
895 QUICK_CHECKBOX (Q_("Confirmation|&Delete"), &confirm_delete, NULL),
896 QUICK_CHECKBOX (Q_("Confirmation|O&verwrite"), &confirm_overwrite, NULL),
897 QUICK_CHECKBOX (Q_("Confirmation|&Execute"), &confirm_execute, NULL),
898 QUICK_CHECKBOX (Q_("Confirmation|E&xit"), &confirm_exit, NULL),
899 QUICK_CHECKBOX (Q_("Confirmation|Di&rectory hotlist delete"),
900 &confirm_directory_hotlist_delete, NULL),
901 QUICK_CHECKBOX (Q_("Confirmation|&History cleanup"),
902 &mc_global.widget.confirm_history_cleanup, NULL),
903 QUICK_BUTTONS_OK_CANCEL,
904 QUICK_END
905 /* *INDENT-ON* */
908 quick_dialog_t qdlg = {
909 -1, -1, 46,
910 N_("Confirmation"), "[Confirmation]",
911 quick_widgets, NULL, NULL
914 (void) quick_dialog (&qdlg);
917 /* --------------------------------------------------------------------------------------------- */
919 #ifndef HAVE_CHARSET
920 void
921 display_bits_box (void)
923 int new_meta;
924 int current_mode;
926 const char *display_bits_str[] = {
927 N_("&UTF-8 output"),
928 N_("&Full 8 bits output"),
929 N_("&ISO 8859-1"),
930 N_("7 &bits")
933 quick_widget_t quick_widgets[] = {
934 /* *INDENT-OFF* */
935 QUICK_RADIO (4, display_bits_str, &current_mode, NULL),
936 QUICK_SEPARATOR (TRUE),
937 QUICK_CHECKBOX (N_("F&ull 8 bits input"), &new_meta, NULL),
938 QUICK_BUTTONS_OK_CANCEL,
939 QUICK_END
940 /* *INDENT-ON* */
943 quick_dialog_t qdlg = {
944 -1, -1, 46,
945 _("Display bits"), "[Display bits]",
946 quick_widgets, NULL, NULL
949 if (mc_global.full_eight_bits)
950 current_mode = 0;
951 else if (mc_global.eight_bit_clean)
952 current_mode = 1;
953 else
954 current_mode = 2;
956 new_meta = !use_8th_bit_as_meta;
958 if (quick_dialog (&qdlg) != B_CANCEL)
960 mc_global.eight_bit_clean = current_mode < 3;
961 mc_global.full_eight_bits = current_mode < 2;
962 #ifndef HAVE_SLANG
963 meta (stdscr, mc_global.eight_bit_clean);
964 #else
965 SLsmg_Display_Eight_Bit = mc_global.full_eight_bits ? 128 : 160;
966 #endif
967 use_8th_bit_as_meta = !new_meta;
971 /* --------------------------------------------------------------------------------------------- */
972 #else /* HAVE_CHARSET */
974 void
975 display_bits_box (void)
977 const char *cpname;
979 new_display_codepage = mc_global.display_codepage;
981 cpname = (new_display_codepage < 0) ? _("Other 8 bit")
982 : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
985 int new_meta;
987 quick_widget_t quick_widgets[] = {
988 /* *INDENT-OFF* */
989 QUICK_START_COLUMNS,
990 QUICK_LABEL (N_("Input / display codepage:"), NULL),
991 QUICK_NEXT_COLUMN,
992 QUICK_BUTTON (cpname, B_USER, sel_charset_button, NULL),
993 QUICK_STOP_COLUMNS,
994 QUICK_SEPARATOR (TRUE),
995 QUICK_CHECKBOX (N_("F&ull 8 bits input"), &new_meta, NULL),
996 QUICK_BUTTONS_OK_CANCEL,
997 QUICK_END
998 /* *INDENT-ON* */
1001 quick_dialog_t qdlg = {
1002 -1, -1, 46,
1003 N_("Display bits"), "[Display bits]",
1004 quick_widgets, NULL, NULL
1007 new_meta = !use_8th_bit_as_meta;
1008 application_keypad_mode ();
1010 if (quick_dialog (&qdlg) == B_ENTER)
1012 char *errmsg;
1014 mc_global.display_codepage = new_display_codepage;
1016 errmsg = init_translation_table (mc_global.source_codepage, mc_global.display_codepage);
1017 if (errmsg != NULL)
1019 message (D_ERROR, MSG_ERROR, "%s", errmsg);
1020 g_free (errmsg);
1023 #ifdef HAVE_SLANG
1024 tty_display_8bit (mc_global.display_codepage != 0 && mc_global.display_codepage != 1);
1025 #else
1026 tty_display_8bit (mc_global.display_codepage != 0);
1027 #endif
1028 use_8th_bit_as_meta = !new_meta;
1030 repaint_screen ();
1034 #endif /* HAVE_CHARSET */
1036 /* --------------------------------------------------------------------------------------------- */
1037 /** Show tree in a box, not on a panel */
1039 char *
1040 tree_box (const char *current_dir)
1042 WTree *mytree;
1043 WDialog *dlg;
1044 Widget *wd;
1045 char *val = NULL;
1046 WButtonBar *bar;
1048 (void) current_dir;
1050 /* Create the components */
1051 dlg = dlg_create (TRUE, 0, 0, LINES - 9, COLS - 20, WPOS_CENTER, FALSE, dialog_colors,
1052 tree_callback, NULL, "[Directory Tree]", _("Directory tree"));
1053 wd = WIDGET (dlg);
1055 mytree = tree_new (2, 2, wd->lines - 6, wd->cols - 5, FALSE);
1056 add_widget_autopos (dlg, mytree, WPOS_KEEP_ALL, NULL);
1057 add_widget_autopos (dlg, hline_new (wd->lines - 4, 1, -1), WPOS_KEEP_BOTTOM, NULL);
1058 bar = buttonbar_new (TRUE);
1059 add_widget (dlg, bar);
1060 /* restore ButtonBar coordinates after add_widget() */
1061 WIDGET (bar)->x = 0;
1062 WIDGET (bar)->y = LINES - 1;
1064 if (dlg_run (dlg) == B_ENTER)
1066 const vfs_path_t *selected_name;
1068 selected_name = tree_selected_name (mytree);
1069 val = g_strdup (vfs_path_as_str (selected_name));
1072 dlg_destroy (dlg);
1073 return val;
1076 /* --------------------------------------------------------------------------------------------- */
1078 #ifdef ENABLE_VFS
1079 void
1080 configure_vfs (void)
1082 char buffer2[BUF_TINY];
1083 #ifdef ENABLE_VFS_FTP
1084 char buffer3[BUF_TINY];
1086 g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
1087 #endif
1089 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
1092 char *ret_timeout;
1093 #ifdef ENABLE_VFS_FTP
1094 char *ret_passwd;
1095 char *ret_ftp_proxy;
1096 char *ret_directory_timeout;
1097 #endif /* ENABLE_VFS_FTP */
1099 quick_widget_t quick_widgets[] = {
1100 /* *INDENT-OFF* */
1101 QUICK_LABELED_INPUT (N_("Timeout for freeing VFSs (sec):"), input_label_left,
1102 buffer2, "input-timo-vfs", &ret_timeout, NULL, FALSE, FALSE,
1103 INPUT_COMPLETE_NONE),
1104 #ifdef ENABLE_VFS_FTP
1105 QUICK_SEPARATOR (TRUE),
1106 QUICK_LABELED_INPUT (N_("FTP anonymous password:"), input_label_left,
1107 ftpfs_anonymous_passwd, "input-passwd", &ret_passwd, NULL,
1108 FALSE, FALSE, INPUT_COMPLETE_NONE),
1109 QUICK_LABELED_INPUT (N_("FTP directory cache timeout (sec):"), input_label_left,
1110 buffer3, "input-timeout", &ret_directory_timeout, NULL,
1111 FALSE, FALSE, INPUT_COMPLETE_NONE),
1112 QUICK_CHECKBOX (N_("&Always use ftp proxy:"), &ftpfs_always_use_proxy,
1113 &ftpfs_always_use_proxy_id),
1114 QUICK_INPUT (ftpfs_proxy_host, "input-ftp-proxy", &ret_ftp_proxy,
1115 &ftpfs_proxy_host_id, FALSE, FALSE, INPUT_COMPLETE_HOSTNAMES),
1116 QUICK_CHECKBOX (N_("&Use ~/.netrc"), &ftpfs_use_netrc, NULL),
1117 QUICK_CHECKBOX (N_("Use &passive mode"), &ftpfs_use_passive_connections, NULL),
1118 QUICK_CHECKBOX (N_("Use passive mode over pro&xy"),
1119 &ftpfs_use_passive_connections_over_proxy, NULL),
1120 #endif /* ENABLE_VFS_FTP */
1121 QUICK_BUTTONS_OK_CANCEL,
1122 QUICK_END
1123 /* *INDENT-ON* */
1126 quick_dialog_t qdlg = {
1127 -1, -1, 56,
1128 N_("Virtual File System Setting"), "[Virtual FS]",
1129 quick_widgets,
1130 #ifdef ENABLE_VFS_FTP
1131 confvfs_callback,
1132 #else
1133 NULL,
1134 #endif
1135 NULL,
1138 #ifdef ENABLE_VFS_FTP
1139 if (!ftpfs_always_use_proxy)
1140 quick_widgets[5].state = WST_DISABLED;
1141 #endif
1143 if (quick_dialog (&qdlg) != B_CANCEL)
1145 /* cppcheck-suppress uninitvar */
1146 vfs_timeout = atoi (ret_timeout);
1147 g_free (ret_timeout);
1149 if (vfs_timeout < 0 || vfs_timeout > 10000)
1150 vfs_timeout = 10;
1151 #ifdef ENABLE_VFS_FTP
1152 g_free (ftpfs_anonymous_passwd);
1153 /* cppcheck-suppress uninitvar */
1154 ftpfs_anonymous_passwd = ret_passwd;
1155 g_free (ftpfs_proxy_host);
1156 /* cppcheck-suppress uninitvar */
1157 ftpfs_proxy_host = ret_ftp_proxy;
1158 /* cppcheck-suppress uninitvar */
1159 ftpfs_directory_timeout = atoi (ret_directory_timeout);
1160 g_free (ret_directory_timeout);
1161 #endif
1166 #endif /* ENABLE_VFS */
1168 /* --------------------------------------------------------------------------------------------- */
1170 char *
1171 cd_dialog (void)
1173 const Widget *w = CONST_WIDGET (current_panel);
1174 char *my_str;
1176 quick_widget_t quick_widgets[] = {
1177 QUICK_LABELED_INPUT (N_("cd"), input_label_left, "", "input", &my_str, NULL, FALSE, TRUE,
1178 INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_CD),
1179 QUICK_END
1182 quick_dialog_t qdlg = {
1183 w->y + w->lines - 6, w->x, w->cols,
1184 N_("Quick cd"), "[Quick cd]",
1185 quick_widgets, NULL, NULL
1188 return (quick_dialog (&qdlg) != B_CANCEL) ? my_str : NULL;
1191 /* --------------------------------------------------------------------------------------------- */
1193 void
1194 symlink_dialog (const vfs_path_t * existing_vpath, const vfs_path_t * new_vpath,
1195 char **ret_existing, char **ret_new)
1197 quick_widget_t quick_widgets[] = {
1198 /* *INDENT-OFF* */
1199 QUICK_LABELED_INPUT (N_("Existing filename (filename symlink will point to):"),
1200 input_label_above, vfs_path_as_str (existing_vpath), "input-2",
1201 ret_existing, NULL, FALSE, FALSE, INPUT_COMPLETE_FILENAMES),
1202 QUICK_SEPARATOR (FALSE),
1203 QUICK_LABELED_INPUT (N_("Symbolic link filename:"), input_label_above,
1204 vfs_path_as_str (new_vpath), "input-1",
1205 ret_new, NULL, FALSE, FALSE, INPUT_COMPLETE_FILENAMES),
1206 QUICK_BUTTONS_OK_CANCEL,
1207 QUICK_END
1208 /* *INDENT-ON* */
1211 quick_dialog_t qdlg = {
1212 -1, -1, 64,
1213 N_("Symbolic link"), "[File Menu]",
1214 quick_widgets, NULL, NULL
1217 if (quick_dialog (&qdlg) == B_CANCEL)
1219 *ret_new = NULL;
1220 *ret_existing = NULL;
1224 /* --------------------------------------------------------------------------------------------- */
1226 #ifdef ENABLE_BACKGROUND
1227 void
1228 jobs_cmd (void)
1230 struct
1232 const char *name;
1233 int flags;
1234 int value;
1235 int len;
1236 bcback_fn callback;
1238 job_but[] =
1240 /* *INDENT-OFF* */
1241 { N_("&Stop"), NORMAL_BUTTON, B_STOP, 0, task_cb },
1242 { N_("&Resume"), NORMAL_BUTTON, B_RESUME, 0, task_cb },
1243 { N_("&Kill"), NORMAL_BUTTON, B_KILL, 0, task_cb },
1244 { N_("&OK"), DEFPUSH_BUTTON, B_CANCEL, 0, NULL }
1245 /* *INDENT-ON* */
1248 size_t i;
1249 const size_t n_but = G_N_ELEMENTS (job_but);
1251 WDialog *jobs_dlg;
1252 int cols = 60;
1253 int lines = 15;
1254 int x = 0;
1256 for (i = 0; i < n_but; i++)
1258 #ifdef ENABLE_NLS
1259 job_but[i].name = _(job_but[i].name);
1260 #endif /* ENABLE_NLS */
1262 job_but[i].len = str_term_width1 (job_but[i].name) + 3;
1263 if (job_but[i].flags == DEFPUSH_BUTTON)
1264 job_but[i].len += 2;
1265 x += job_but[i].len;
1268 x += (int) n_but - 1;
1269 cols = MAX (cols, x + 6);
1271 jobs_dlg = dlg_create (TRUE, 0, 0, lines, cols, WPOS_CENTER, FALSE, dialog_colors, NULL, NULL,
1272 "[Background jobs]", _("Background jobs"));
1274 bg_list = listbox_new (2, 2, lines - 6, cols - 6, FALSE, NULL);
1275 jobs_fill_listbox (bg_list);
1276 add_widget (jobs_dlg, bg_list);
1278 add_widget (jobs_dlg, hline_new (lines - 4, -1, -1));
1280 x = (cols - x) / 2;
1281 for (i = 0; i < n_but; i++)
1283 add_widget (jobs_dlg,
1284 button_new (lines - 3, x, job_but[i].value, job_but[i].flags, job_but[i].name,
1285 job_but[i].callback));
1286 x += job_but[i].len + 1;
1289 (void) dlg_run (jobs_dlg);
1290 dlg_destroy (jobs_dlg);
1292 #endif /* ENABLE_BACKGROUND */
1294 /* --------------------------------------------------------------------------------------------- */
1296 #ifdef ENABLE_VFS_SMB
1297 struct smb_authinfo *
1298 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, const char *user)
1300 char *label;
1301 struct smb_authinfo *return_value = NULL;
1303 if (domain == NULL)
1304 domain = "";
1305 if (user == NULL)
1306 user = "";
1308 label = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1311 char *ret_domain, *ret_user, *ret_password;
1313 quick_widget_t quick_widgets[] = {
1314 /* *INDENT-OFF* */
1315 QUICK_LABEL (label, NULL),
1316 QUICK_SEPARATOR (TRUE),
1317 QUICK_START_COLUMNS,
1318 QUICK_LABEL (N_("Domain:"), NULL),
1319 QUICK_SEPARATOR (FALSE),
1320 QUICK_LABEL (N_("Username:"), NULL),
1321 QUICK_SEPARATOR (FALSE),
1322 QUICK_LABEL (N_("Password:"), NULL),
1323 QUICK_NEXT_COLUMN,
1324 QUICK_INPUT (domain, "auth_domain", &ret_domain, NULL, FALSE, FALSE, INPUT_COMPLETE_HOSTNAMES),
1325 QUICK_SEPARATOR (FALSE),
1326 QUICK_INPUT (user, "auth_name", &ret_user, NULL, FALSE, FALSE, INPUT_COMPLETE_USERNAMES),
1327 QUICK_SEPARATOR (FALSE),
1328 QUICK_INPUT ("", "auth_password", &ret_password, NULL, TRUE, FALSE, INPUT_COMPLETE_NONE),
1329 QUICK_STOP_COLUMNS,
1330 QUICK_BUTTONS_OK_CANCEL,
1331 QUICK_END
1332 /* *INDENT-ON* */
1335 quick_dialog_t qdlg = {
1336 -1, -1, 40,
1337 N_("SMB authentication"), "[Smb Authinfo]",
1338 quick_widgets, NULL, NULL
1341 if (quick_dialog (&qdlg) != B_CANCEL)
1343 return_value = vfs_smb_authinfo_new (host, share, ret_domain, ret_user, ret_password);
1345 g_free (ret_domain);
1346 g_free (ret_user);
1347 g_free (ret_password);
1351 g_free (label);
1353 return return_value;
1355 #endif /* ENABLE_VFS_SMB */
1357 /* --------------------------------------------------------------------------------------------- */