c11dfb7882393144ed37299140b5d46cb38a5244
[midnight-commander.git] / src / filemanager / boxes.c
blobc11dfb7882393144ed37299140b5d46cb38a5244
1 /*
2 Some misc dialog boxes for the program.
4 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 2005, 2006, 2009, 2010, 2011, 2012, 2013
6 The Free Software Foundation, Inc.
8 Written by:
9 Miguel de Icaza, 1994, 1995
10 Jakub Jelinek, 1995
11 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010, 2011, 2012, 2013
13 This file is part of the Midnight Commander.
15 The Midnight Commander is free software: you can redistribute it
16 and/or modify it under the terms of the GNU General Public License as
17 published by the Free Software Foundation, either version 3 of the License,
18 or (at your option) any later version.
20 The Midnight Commander is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 /** \file boxes.c
30 * \brief Source: Some misc dialog boxes for the program
33 #include <config.h>
35 #include <ctype.h>
36 #include <signal.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <sys/types.h>
41 #include <sys/stat.h>
43 #include "lib/global.h"
45 #include "lib/tty/tty.h"
46 #include "lib/tty/key.h" /* XCTRL and ALT macros */
47 #include "lib/skin.h" /* INPUT_COLOR */
48 #include "lib/mcconfig.h" /* Load/save user formats */
49 #include "lib/strutil.h"
51 #include "lib/vfs/vfs.h"
52 #ifdef ENABLE_VFS_FTP
53 #include "src/vfs/ftpfs/ftpfs.h"
54 #endif /* ENABLE_VFS_FTP */
55 #ifdef ENABLE_VFS_SMB
56 #include "src/vfs/smbfs/smbfs.h"
57 #endif /* ENABLE_VFS_SMB */
59 #include "lib/util.h" /* Q_() */
60 #include "lib/widget.h"
62 #include "src/setup.h" /* For profile_name */
63 #include "src/history.h" /* MC_HISTORY_ESC_TIMEOUT */
64 #include "src/execute.h" /* pause_after_run */
65 #ifdef ENABLE_BACKGROUND
66 #include "src/background.h" /* task_list */
67 #endif
69 #ifdef HAVE_CHARSET
70 #include "lib/charsets.h"
71 #include "src/selcodepage.h"
72 #endif
74 #include "command.h" /* For cmdline */
75 #include "dir.h"
76 #include "panel.h" /* LIST_TYPES */
77 #include "tree.h"
78 #include "layout.h" /* for get_nth_panel_name proto */
79 #include "midnight.h" /* current_panel */
81 #include "boxes.h"
83 /*** global variables ****************************************************************************/
85 /*** file scope macro definitions ****************************************************************/
87 #ifdef ENABLE_BACKGROUND
88 #define B_STOP (B_USER+1)
89 #define B_RESUME (B_USER+2)
90 #define B_KILL (B_USER+3)
91 #endif /* ENABLE_BACKGROUND */
93 /*** file scope type declarations ****************************************************************/
95 /*** file scope variables ************************************************************************/
97 unsigned long configure_old_esc_mode_id, configure_time_out_id;
99 /* Index in list_types[] for "user defined" */
100 static const int panel_listing_user_idx = 3;
102 static char **status_format;
103 static int listing_user_hotkey = 'u';
104 static unsigned long panel_listing_types_id, panel_user_format_id;
105 static unsigned long mini_user_status_id, mini_user_format_id;
107 #ifdef HAVE_CHARSET
108 static int new_display_codepage;
109 static unsigned long disp_bits_name_id;
110 #endif /* HAVE_CHARSET */
112 #if defined(ENABLE_VFS) && defined(ENABLE_VFS_FTP)
113 static unsigned long ftpfs_always_use_proxy_id, ftpfs_proxy_host_id;
114 #endif /* ENABLE_VFS && ENABLE_VFS_FTP */
116 #ifdef ENABLE_BACKGROUND
117 static WListbox *bg_list = NULL;
118 #endif /* ENABLE_BACKGROUND */
120 /* --------------------------------------------------------------------------------------------- */
121 /*** file scope functions ************************************************************************/
122 /* --------------------------------------------------------------------------------------------- */
124 static cb_ret_t
125 configure_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
127 switch (msg)
129 case MSG_ACTION:
130 /* message from "Single press" checkbutton */
131 if (sender != NULL && sender->id == configure_old_esc_mode_id)
133 const gboolean not_single = !(CHECK (sender)->state & C_BOOL);
134 Widget *ww;
136 /* input line */
137 ww = dlg_find_by_id (DIALOG (w), configure_time_out_id);
138 widget_disable (ww, not_single);
140 return MSG_HANDLED;
142 return MSG_NOT_HANDLED;
144 default:
145 return dlg_default_callback (w, sender, msg, parm, data);
149 /* --------------------------------------------------------------------------------------------- */
151 static cb_ret_t
152 panel_listing_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
154 WDialog *h = DIALOG (w);
156 switch (msg)
158 case MSG_KEY:
159 if (parm == '\n')
161 Widget *wi;
163 wi = dlg_find_by_id (h, panel_listing_types_id);
164 if (dlg_widget_active (wi))
166 WInput *in;
168 in = INPUT (dlg_find_by_id (h, mini_user_format_id));
169 input_assign_text (in, status_format[RADIO (wi)->sel]);
170 dlg_stop (h);
171 return MSG_HANDLED;
174 wi = dlg_find_by_id (h, panel_user_format_id);
175 if (dlg_widget_active (wi))
177 h->ret_value = B_USER + 6;
178 dlg_stop (h);
179 return MSG_HANDLED;
182 wi = dlg_find_by_id (h, mini_user_format_id);
183 if (dlg_widget_active (wi))
185 h->ret_value = B_USER + 7;
186 dlg_stop (h);
187 return MSG_HANDLED;
191 if (g_ascii_tolower (parm) == listing_user_hotkey)
193 Widget *wi;
195 wi = dlg_find_by_id (h, panel_user_format_id);
196 if (dlg_widget_active (wi))
198 wi = dlg_find_by_id (h, mini_user_format_id);
199 if (dlg_widget_active (wi))
201 WRadio *r;
203 r = RADIO (dlg_find_by_id (h, panel_listing_types_id));
204 r->pos = r->sel = panel_listing_user_idx;
205 dlg_select_widget (WIDGET (r)); /* force redraw */
206 send_message (h, r, MSG_ACTION, 0, NULL);
207 return MSG_HANDLED;
211 return MSG_NOT_HANDLED;
213 case MSG_ACTION:
214 if (sender != NULL && sender->id == panel_listing_types_id)
216 WCheck *ch;
217 WInput *in1, *in2;
219 in1 = INPUT (dlg_find_by_id (h, panel_user_format_id));
220 ch = CHECK (dlg_find_by_id (h, mini_user_status_id));
221 in2 = INPUT (dlg_find_by_id (h, mini_user_format_id));
223 if (!(ch->state & C_BOOL))
224 input_assign_text (in2, status_format[RADIO (sender)->sel]);
225 input_update (in2, FALSE);
226 input_update (in1, FALSE);
227 widget_disable (WIDGET (in1), RADIO (sender)->sel != panel_listing_user_idx);
228 return MSG_HANDLED;
231 if (sender != NULL && sender->id == mini_user_status_id)
233 WInput *in;
235 in = INPUT (dlg_find_by_id (h, mini_user_format_id));
237 if (CHECK (sender)->state & C_BOOL)
239 widget_disable (WIDGET (in), FALSE);
240 input_assign_text (in, status_format[3]);
242 else
244 WRadio *r;
246 r = RADIO (dlg_find_by_id (h, panel_listing_types_id));
247 widget_disable (WIDGET (in), TRUE);
248 input_assign_text (in, status_format[r->sel]);
250 /* input_update (in, FALSE); */
251 return MSG_HANDLED;
254 return MSG_NOT_HANDLED;
256 default:
257 return dlg_default_callback (w, sender, msg, parm, data);
261 /* --------------------------------------------------------------------------------------------- */
263 #ifdef HAVE_CHARSET
264 static int
265 sel_charset_button (WButton * button, int action)
267 int new_dcp;
269 (void) action;
271 new_dcp = select_charset (-1, -1, new_display_codepage, TRUE);
273 if (new_dcp != SELECT_CHARSET_CANCEL)
275 const char *cpname;
276 char buf[BUF_TINY];
277 Widget *w;
279 new_display_codepage = new_dcp;
280 cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
281 _("Other 8 bit") :
282 ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
283 if (cpname != NULL)
284 mc_global.utf8_display = str_isutf8 (cpname);
285 /* avoid strange bug with label repainting */
286 g_snprintf (buf, sizeof (buf), "%-27s", cpname);
287 w = dlg_find_by_id (WIDGET (button)->owner, disp_bits_name_id);
288 label_set_text (LABEL (w), buf);
291 return 0;
293 #endif /* HAVE_CHARSET */
295 /* --------------------------------------------------------------------------------------------- */
297 static cb_ret_t
298 tree_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
300 WDialog *h = DIALOG (w);
302 switch (msg)
304 case MSG_POST_KEY:
305 /* The enter key will be processed by the tree widget */
306 if (parm == '\n')
308 h->ret_value = B_ENTER;
309 dlg_stop (h);
311 return MSG_HANDLED;
313 case MSG_RESIZE:
315 Widget *bar;
317 /* simply call dlg_set_size() with new size */
318 dlg_set_size (h, LINES - 9, COLS - 20);
319 bar = WIDGET (find_buttonbar (h));
320 bar->x = 0;
321 bar->y = LINES - 1;
322 return MSG_HANDLED;
325 case MSG_ACTION:
326 return send_message (find_tree (h), NULL, MSG_ACTION, parm, NULL);
328 default:
329 return dlg_default_callback (w, sender, msg, parm, data);
333 /* --------------------------------------------------------------------------------------------- */
335 #if defined(ENABLE_VFS) && defined (ENABLE_VFS_FTP)
336 static cb_ret_t
337 confvfs_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
339 switch (msg)
341 case MSG_ACTION:
342 /* message from "Always use ftp proxy" checkbutton */
343 if (sender != NULL && sender->id == ftpfs_always_use_proxy_id)
345 const gboolean not_use = !(CHECK (sender)->state & C_BOOL);
346 Widget *wi;
348 /* input */
349 wi = dlg_find_by_id (DIALOG (w), ftpfs_proxy_host_id);
350 widget_disable (wi, not_use);
351 return MSG_HANDLED;
353 return MSG_NOT_HANDLED;
355 default:
356 return dlg_default_callback (w, sender, msg, parm, data);
359 #endif /* ENABLE_VFS && ENABLE_VFS_FTP */
361 /* --------------------------------------------------------------------------------------------- */
363 #ifdef ENABLE_BACKGROUND
364 static void
365 jobs_fill_listbox (WListbox * list)
367 static const char *state_str[2] = { "", "" };
368 TaskList *tl;
370 if (state_str[0] == '\0')
372 state_str[0] = _("Running");
373 state_str[1] = _("Stopped");
376 for (tl = task_list; tl != NULL; tl = tl->next)
378 char *s;
380 s = g_strconcat (state_str[tl->state], " ", tl->info, (char *) NULL);
381 listbox_add_item (list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
382 g_free (s);
386 /* --------------------------------------------------------------------------------------------- */
388 static int
389 task_cb (WButton * button, int action)
391 TaskList *tl;
392 int sig = 0;
394 (void) button;
396 if (bg_list->list == NULL)
397 return 0;
399 /* Get this instance information */
400 listbox_get_current (bg_list, NULL, (void **) &tl);
402 #ifdef SIGTSTP
403 if (action == B_STOP)
405 sig = SIGSTOP;
406 tl->state = Task_Stopped;
408 else if (action == B_RESUME)
410 sig = SIGCONT;
411 tl->state = Task_Running;
413 else
414 #endif
415 if (action == B_KILL)
416 sig = SIGKILL;
418 if (sig == SIGKILL)
419 unregister_task_running (tl->pid, tl->fd);
421 kill (tl->pid, sig);
422 listbox_remove_list (bg_list);
423 jobs_fill_listbox (bg_list);
425 /* This can be optimized to just redraw this widget :-) */
426 dlg_redraw (WIDGET (button)->owner);
428 return 0;
430 #endif /* ENABLE_BACKGROUND */
432 /* --------------------------------------------------------------------------------------------- */
433 /*** public functions ****************************************************************************/
434 /* --------------------------------------------------------------------------------------------- */
436 void
437 configure_box (void)
439 const char *pause_options[] = {
440 N_("&Never"),
441 N_("On dum&b terminals"),
442 N_("Alwa&ys")
445 int pause_options_num;
447 pause_options_num = G_N_ELEMENTS (pause_options);
450 char time_out[BUF_TINY] = "";
451 char *time_out_new;
453 quick_widget_t quick_widgets[] = {
454 /* *INDENT-OFF* */
455 QUICK_START_COLUMNS,
456 QUICK_START_GROUPBOX (N_("File operations")),
457 QUICK_CHECKBOX (N_("&Verbose operation"), &verbose, NULL),
458 QUICK_CHECKBOX (N_("Compute tota&ls"), &file_op_compute_totals, NULL),
459 QUICK_CHECKBOX (N_("Classic pro&gressbar"), &classic_progressbar, NULL),
460 QUICK_CHECKBOX (N_("Mkdi&r autoname"), &auto_fill_mkdir_name, NULL),
461 QUICK_CHECKBOX (N_("&Preallocate space"), &mc_global.vfs.preallocate_space,
462 NULL),
463 QUICK_STOP_GROUPBOX,
464 QUICK_START_GROUPBOX (N_("Esc key mode")),
465 QUICK_CHECKBOX (N_("S&ingle press"), &old_esc_mode, &configure_old_esc_mode_id),
466 QUICK_LABELED_INPUT (N_("Timeout:"), input_label_left,
467 (const char *) time_out, 0, MC_HISTORY_ESC_TIMEOUT,
468 &time_out_new, &configure_time_out_id),
469 QUICK_STOP_GROUPBOX,
470 QUICK_START_GROUPBOX (N_("Pause after run")),
471 QUICK_RADIO (pause_options_num, pause_options, &pause_after_run, NULL),
472 QUICK_STOP_GROUPBOX,
473 QUICK_NEXT_COLUMN,
474 QUICK_START_GROUPBOX (N_("Other options")),
475 QUICK_CHECKBOX (N_("Use internal edi&t"), &use_internal_edit, NULL),
476 QUICK_CHECKBOX (N_("Use internal vie&w"), &use_internal_view, NULL),
477 QUICK_CHECKBOX (N_("A&sk new file name"),
478 &editor_ask_filename_before_edit, NULL),
479 QUICK_CHECKBOX (N_("Auto m&enus"), &auto_menu, NULL),
480 QUICK_CHECKBOX (N_("&Drop down menus"), &drop_menus, NULL),
481 QUICK_CHECKBOX (N_("S&hell patterns"), &easy_patterns, NULL),
482 QUICK_CHECKBOX (N_("Co&mplete: show all"),
483 &mc_global.widget.show_all_if_ambiguous, NULL),
484 QUICK_CHECKBOX (N_("Rotating d&ash"), &nice_rotating_dash, NULL),
485 QUICK_CHECKBOX (N_("Cd follows lin&ks"), &mc_global.vfs.cd_symlinks, NULL),
486 QUICK_CHECKBOX (N_("Sa&fe delete"), &safe_delete, NULL),
487 QUICK_CHECKBOX (N_("A&uto save setup"), &auto_save_setup, NULL),
488 QUICK_SEPARATOR (FALSE),
489 QUICK_SEPARATOR (FALSE),
490 QUICK_SEPARATOR (FALSE),
491 QUICK_STOP_GROUPBOX,
492 QUICK_STOP_COLUMNS,
493 QUICK_BUTTONS_OK_CANCEL,
494 QUICK_END
495 /* *INDENT-ON* */
498 quick_dialog_t qdlg = {
499 -1, -1, 60,
500 N_("Configure options"), "[Configuration]",
501 quick_widgets, configure_callback, NULL
504 g_snprintf (time_out, sizeof (time_out), "%d", old_esc_mode_timeout);
506 #ifndef USE_INTERNAL_EDIT
507 quick_widgets[17].options = W_DISABLED;
508 #endif
510 if (!old_esc_mode)
511 quick_widgets[10].options = quick_widgets[11].options = W_DISABLED;
513 #ifndef HAVE_POSIX_FALLOCATE
514 mc_global.vfs.preallocate_space = FALSE;
515 quick_widgets[7].options = W_DISABLED;
516 #endif
518 if (quick_dialog (&qdlg) == B_ENTER)
519 old_esc_mode_timeout = atoi (time_out_new);
521 g_free (time_out_new);
525 /* --------------------------------------------------------------------------------------------- */
527 void
528 panel_options_box (void)
530 const char *qsearch_options[] = {
531 N_("Case &insensitive"),
532 N_("Cas&e sensitive"),
533 N_("Use panel sort mo&de")
536 int simple_swap;
538 simple_swap = mc_config_get_bool (mc_main_config, CONFIG_PANELS_SECTION,
539 "simple_swap", FALSE) ? 1 : 0;
542 quick_widget_t quick_widgets[] = {
543 /* *INDENT-OFF* */
544 QUICK_START_COLUMNS,
545 QUICK_START_GROUPBOX (N_("Main options")),
546 QUICK_CHECKBOX (N_("Show mi&ni-status"), &panels_options.show_mini_info, NULL),
547 QUICK_CHECKBOX (N_("Use SI si&ze units"), &panels_options.kilobyte_si, NULL),
548 QUICK_CHECKBOX (N_("Mi&x all files"), &panels_options.mix_all_files, NULL),
549 QUICK_CHECKBOX (N_("Show &backup files"), &panels_options.show_backups, NULL),
550 QUICK_CHECKBOX (N_("Show &hidden files"), &panels_options.show_dot_files, NULL),
551 QUICK_CHECKBOX (N_("&Fast dir reload"), &panels_options.fast_reload, NULL),
552 QUICK_CHECKBOX (N_("Ma&rk moves down"), &panels_options.mark_moves_down, NULL),
553 QUICK_CHECKBOX (N_("Re&verse files only"), &panels_options.reverse_files_only,
554 NULL),
555 QUICK_CHECKBOX (N_("Simple s&wap"), &simple_swap, NULL),
556 QUICK_CHECKBOX (N_("A&uto save panels setup"), &panels_options.auto_save_setup,
557 NULL),
558 QUICK_SEPARATOR (FALSE),
559 QUICK_SEPARATOR (FALSE),
560 QUICK_STOP_GROUPBOX,
561 QUICK_NEXT_COLUMN,
562 QUICK_START_GROUPBOX (N_("Navigation")),
563 QUICK_CHECKBOX (N_("L&ynx-like motion"), &panels_options.navigate_with_arrows,
564 NULL),
565 QUICK_CHECKBOX (N_("Pa&ge scrolling"), &panels_options.scroll_pages, NULL),
566 QUICK_CHECKBOX (N_("&Mouse page scrolling"), &panels_options.mouse_move_pages,
567 NULL),
568 QUICK_STOP_GROUPBOX,
569 QUICK_START_GROUPBOX (N_("File highlight")),
570 QUICK_CHECKBOX (N_("File &types"), &panels_options.filetype_mode, NULL),
571 QUICK_CHECKBOX (N_("&Permissions"), &panels_options.permission_mode, NULL),
572 QUICK_STOP_GROUPBOX,
573 QUICK_START_GROUPBOX (N_("Quick search")),
574 QUICK_RADIO (QSEARCH_NUM, qsearch_options, (int *) &panels_options.qsearch_mode,
575 NULL),
576 QUICK_STOP_GROUPBOX,
577 QUICK_STOP_COLUMNS,
578 QUICK_BUTTONS_OK_CANCEL,
579 QUICK_END
580 /* *INDENT-ON* */
583 quick_dialog_t qdlg = {
584 -1, -1, 60,
585 N_("Panel options"), "[Panel options]",
586 quick_widgets, NULL, NULL
589 if (quick_dialog (&qdlg) != B_ENTER)
590 return;
593 mc_config_set_bool (mc_main_config, CONFIG_PANELS_SECTION,
594 "simple_swap", (gboolean) (simple_swap & C_BOOL));
596 if (!panels_options.fast_reload_msg_shown && panels_options.fast_reload)
598 message (D_NORMAL, _("Information"),
599 _("Using the fast reload option may not reflect the exact\n"
600 "directory contents. In this case you'll need to do a\n"
601 "manual reload of the directory. See the man page for\n" "the details."));
602 panels_options.fast_reload_msg_shown = TRUE;
605 update_panels (UP_RELOAD, UP_KEEPSEL);
608 /* --------------------------------------------------------------------------------------------- */
610 /* return list type */
612 panel_listing_box (WPanel * panel, char **userp, char **minip, int *use_msformat, int num)
614 int result = -1;
615 char *section = NULL;
617 if (panel == NULL)
619 const char *p;
620 size_t i;
622 p = get_nth_panel_name (num);
623 panel = g_new (WPanel, 1);
624 panel->list_type = list_full;
625 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
626 panel->user_mini_status = 0;
627 for (i = 0; i < LIST_TYPES; i++)
628 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
629 section = g_strconcat ("Temporal:", p, (char *) NULL);
630 if (!mc_config_has_group (mc_main_config, section))
632 g_free (section);
633 section = g_strdup (p);
635 panel_load_setup (panel, section);
636 g_free (section);
640 int mini_user_status;
641 char *panel_user_format;
642 char *mini_user_format;
643 const char *cp;
645 /* Controls whether the array strings have been translated */
646 const char *list_types[LIST_TYPES] = {
647 N_("&Full file list"),
648 N_("&Brief file list"),
649 N_("&Long file list"),
650 N_("&User defined:")
653 quick_widget_t quick_widgets[] = {
654 /* *INDENT-OFF* */
655 QUICK_RADIO (LIST_TYPES, list_types, &result, &panel_listing_types_id),
656 QUICK_INPUT (panel->user_format, INPUT_COMPLETE_DEFAULT, "user-fmt-input",
657 &panel_user_format, &panel_user_format_id),
658 QUICK_SEPARATOR (TRUE),
659 QUICK_CHECKBOX (N_("User &mini status"), &mini_user_status, &mini_user_status_id),
660 QUICK_INPUT (panel->user_status_format[panel->list_type], INPUT_COMPLETE_DEFAULT,
661 "mini_input", &mini_user_format, &mini_user_format_id),
662 QUICK_BUTTONS_OK_CANCEL,
663 QUICK_END
664 /* *INDENT-ON* */
667 quick_dialog_t qdlg = {
668 -1, -1, 48,
669 N_("Listing mode"), "[Listing Mode...]",
670 quick_widgets, panel_listing_callback, NULL
673 /* get hotkey of user-defined format string */
674 cp = strchr (_(list_types[panel_listing_user_idx]), '&');
675 if (cp != NULL && *++cp != '\0')
676 listing_user_hotkey = g_ascii_tolower (*cp);
678 mini_user_status = panel->user_mini_status;
679 result = panel->list_type;
680 status_format = panel->user_status_format;
682 if (panel->list_type != panel_listing_user_idx)
683 quick_widgets[1].options = W_DISABLED;
685 if (!mini_user_status)
686 quick_widgets[4].options = W_DISABLED;
688 if (quick_dialog (&qdlg) == B_CANCEL)
689 result = -1;
690 else
692 *userp = panel_user_format;
693 *minip = mini_user_format;
694 *use_msformat = mini_user_status;
698 if (section != NULL)
700 int i;
702 g_free (panel->user_format);
703 for (i = 0; i < LIST_TYPES; i++)
704 g_free (panel->user_status_format[i]);
705 g_free (panel);
708 return result;
711 /* --------------------------------------------------------------------------------------------- */
713 const panel_field_t *
714 sort_box (panel_sort_info_t * info)
716 const char **sort_orders_names;
717 gsize sort_names_num, i;
718 int sort_idx = 0;
719 const panel_field_t *result = info->sort_field;
721 sort_orders_names = panel_get_sortable_fields (&sort_names_num);
723 for (i = 0; i < sort_names_num; i++)
724 if (strcmp (sort_orders_names[i], _(info->sort_field->title_hotkey)) == 0)
726 sort_idx = i;
727 break;
731 quick_widget_t quick_widgets[] = {
732 /* *INDENT-OFF* */
733 QUICK_START_COLUMNS,
734 QUICK_RADIO (sort_names_num, sort_orders_names, &sort_idx, NULL),
735 QUICK_NEXT_COLUMN,
736 QUICK_CHECKBOX (N_("Executable &first"), &info->exec_first, NULL),
737 QUICK_CHECKBOX (N_("Cas&e sensitive"), &info->case_sensitive, NULL),
738 QUICK_CHECKBOX (N_("&Reverse"), &info->reverse, NULL),
739 QUICK_STOP_COLUMNS,
740 QUICK_BUTTONS_OK_CANCEL,
741 QUICK_END
742 /* *INDENT-ON* */
745 quick_dialog_t qdlg = {
746 -1, -1, 40,
747 N_("Sort order"), "[Sort Order...]",
748 quick_widgets, NULL, NULL
751 if (quick_dialog (&qdlg) != B_CANCEL)
752 result = panel_get_field_by_title_hotkey (sort_orders_names[sort_idx]);
754 if (result == NULL)
755 result = info->sort_field;
758 g_strfreev ((gchar **) sort_orders_names);
760 return result;
763 /* --------------------------------------------------------------------------------------------- */
765 void
766 confirm_box (void)
768 quick_widget_t quick_widgets[] = {
769 /* *INDENT-OFF* */
770 /* TRANSLATORS: no need to translate 'Confirmation', it's just a context prefix */
771 QUICK_CHECKBOX (N_("Confirmation|&Delete"), &confirm_delete, NULL),
772 QUICK_CHECKBOX (N_("Confirmation|O&verwrite"), &confirm_overwrite, NULL),
773 QUICK_CHECKBOX (N_("Confirmation|&Execute"), &confirm_execute, NULL),
774 QUICK_CHECKBOX (N_("Confirmation|E&xit"), &confirm_exit, NULL),
775 QUICK_CHECKBOX (N_("Confirmation|Di&rectory hotlist delete"),
776 &confirm_directory_hotlist_delete, NULL),
777 QUICK_CHECKBOX (N_("Confirmation|&History cleanup"),
778 &mc_global.widget.confirm_history_cleanup, NULL),
779 QUICK_BUTTONS_OK_CANCEL,
780 QUICK_END
781 /* *INDENT-ON* */
784 quick_dialog_t qdlg = {
785 -1, -1, 46,
786 N_("Confirmation"), "[Confirmation]",
787 quick_widgets, NULL, NULL
790 (void) quick_dialog (&qdlg);
793 /* --------------------------------------------------------------------------------------------- */
795 #ifndef HAVE_CHARSET
796 void
797 display_bits_box (void)
799 int new_meta;
800 int current_mode;
802 const char *display_bits_str[] = {
803 N_("&UTF-8 output"),
804 N_("&Full 8 bits output"),
805 N_("&ISO 8859-1"),
806 N_("7 &bits")
809 quick_widget_t quick_widgets[] = {
810 /* *INDENT-OFF* */
811 QUICK_RADIO (4, display_bits_str, &current_mode, NULL),
812 QUICK_SEPARATOR (TRUE),
813 QUICK_CHECKBOX (N_("F&ull 8 bits input"), &new_meta, NULL),
814 QUICK_BUTTONS_OK_CANCEL,
815 QUICK_END
816 /* *INDENT-ON* */
819 quick_dialog_t qdlg = {
820 -1, -1, 46,
821 _("Display bits"), "[Display bits]",
822 quick_widgets, NULL, NULL
825 if (mc_global.full_eight_bits)
826 current_mode = 0;
827 else if (mc_global.eight_bit_clean)
828 current_mode = 1;
829 else
830 current_mode = 2;
832 new_meta = !use_8th_bit_as_meta;
834 if (quick_dialog (&qdlg) != B_CANCEL)
836 mc_global.eight_bit_clean = current_mode < 3;
837 mc_global.full_eight_bits = current_mode < 2;
838 #ifndef HAVE_SLANG
839 meta (stdscr, mc_global.eight_bit_clean);
840 #else
841 SLsmg_Display_Eight_Bit = mc_global.full_eight_bits ? 128 : 160;
842 #endif
843 use_8th_bit_as_meta = !new_meta;
847 /* --------------------------------------------------------------------------------------------- */
848 #else /* HAVE_CHARSET */
850 void
851 display_bits_box (void)
853 const char *cpname;
855 cpname = (new_display_codepage < 0) ? _("Other 8 bit")
856 : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
858 new_display_codepage = mc_global.display_codepage;
861 int new_meta;
863 quick_widget_t quick_widgets[] = {
864 /* *INDENT-OFF* */
865 QUICK_START_COLUMNS,
866 QUICK_LABEL (N_("Input / display codepage:"), NULL),
867 QUICK_NEXT_COLUMN,
868 QUICK_STOP_COLUMNS,
869 QUICK_START_COLUMNS,
870 QUICK_LABEL (cpname, &disp_bits_name_id),
871 QUICK_NEXT_COLUMN,
872 QUICK_BUTTON (N_("&Select"), B_USER, sel_charset_button, NULL),
873 QUICK_STOP_COLUMNS,
874 QUICK_SEPARATOR (TRUE),
875 QUICK_CHECKBOX (N_("F&ull 8 bits input"), &new_meta, NULL),
876 QUICK_BUTTONS_OK_CANCEL,
877 QUICK_END
878 /* *INDENT-ON* */
881 quick_dialog_t qdlg = {
882 -1, -1, 46,
883 N_("Display bits"), "[Display bits]",
884 quick_widgets, NULL, NULL
887 new_meta = !use_8th_bit_as_meta;
888 application_keypad_mode ();
890 if (quick_dialog (&qdlg) == B_ENTER)
892 char *errmsg;
894 mc_global.display_codepage = new_display_codepage;
896 errmsg = init_translation_table (mc_global.source_codepage, mc_global.display_codepage);
897 if (errmsg != NULL)
899 message (D_ERROR, MSG_ERROR, "%s", errmsg);
900 g_free (errmsg);
903 #ifdef HAVE_SLANG
904 tty_display_8bit (mc_global.display_codepage != 0 && mc_global.display_codepage != 1);
905 #else
906 tty_display_8bit (mc_global.display_codepage != 0);
907 #endif
908 use_8th_bit_as_meta = !new_meta;
910 repaint_screen ();
914 #endif /* HAVE_CHARSET */
916 /* --------------------------------------------------------------------------------------------- */
917 /** Show tree in a box, not on a panel */
919 char *
920 tree_box (const char *current_dir)
922 WTree *mytree;
923 WDialog *dlg;
924 Widget *wd;
925 char *val = NULL;
926 WButtonBar *bar;
928 (void) current_dir;
930 /* Create the components */
931 dlg = create_dlg (TRUE, 0, 0, LINES - 9, COLS - 20, dialog_colors, tree_callback, NULL,
932 "[Directory Tree]", _("Directory tree"), DLG_CENTER);
933 wd = WIDGET (dlg);
935 mytree = tree_new (2, 2, wd->lines - 6, wd->cols - 5, FALSE);
936 add_widget_autopos (dlg, mytree, WPOS_KEEP_ALL, NULL);
937 add_widget_autopos (dlg, hline_new (wd->lines - 4, 1, -1), WPOS_KEEP_BOTTOM, NULL);
938 bar = buttonbar_new (TRUE);
939 add_widget (dlg, bar);
940 /* restore ButtonBar coordinates after add_widget() */
941 WIDGET (bar)->x = 0;
942 WIDGET (bar)->y = LINES - 1;
944 if (run_dlg (dlg) == B_ENTER)
945 val = vfs_path_to_str (tree_selected_name (mytree));
947 destroy_dlg (dlg);
948 return val;
951 /* --------------------------------------------------------------------------------------------- */
953 #ifdef ENABLE_VFS
954 void
955 configure_vfs (void)
957 char buffer2[BUF_TINY];
958 #ifdef ENABLE_VFS_FTP
959 char buffer3[BUF_TINY];
961 g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
962 #endif
964 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
967 char *ret_timeout;
968 #ifdef ENABLE_VFS_FTP
969 char *ret_passwd;
970 char *ret_ftp_proxy;
971 char *ret_directory_timeout;
972 #endif /* ENABLE_VFS_FTP */
974 quick_widget_t quick_widgets[] = {
975 /* *INDENT-OFF* */
976 QUICK_LABELED_INPUT (N_("Timeout for freeing VFSs (sec):"), input_label_left,
977 buffer2, 0, "input-timo-vfs", &ret_timeout, NULL),
978 #ifdef ENABLE_VFS_FTP
979 QUICK_SEPARATOR (TRUE),
980 QUICK_LABELED_INPUT (N_("FTP anonymous password:"), input_label_left,
981 ftpfs_anonymous_passwd, 0, "input-passwd", &ret_passwd, NULL),
982 QUICK_LABELED_INPUT (N_("FTP directory cache timeout (sec):"), input_label_left,
983 buffer3, 0, "input-timeout", &ret_directory_timeout, NULL),
984 QUICK_CHECKBOX (N_("&Always use ftp proxy:"), &ftpfs_always_use_proxy,
985 &ftpfs_always_use_proxy_id),
986 QUICK_INPUT (ftpfs_proxy_host, 0, "input-ftp-proxy", &ret_ftp_proxy,
987 &ftpfs_proxy_host_id),
988 QUICK_CHECKBOX (N_("&Use ~/.netrc"), &ftpfs_use_netrc, NULL),
989 QUICK_CHECKBOX (N_("Use &passive mode"), &ftpfs_use_passive_connections, NULL),
990 QUICK_CHECKBOX (N_("Use passive mode over pro&xy"),
991 &ftpfs_use_passive_connections_over_proxy, NULL),
992 #endif /* ENABLE_VFS_FTP */
993 QUICK_BUTTONS_OK_CANCEL,
994 QUICK_END
995 /* *INDENT-ON* */
998 quick_dialog_t qdlg = {
999 -1, -1, 56,
1000 N_("Virtual File System Setting"), "[Virtual FS]",
1001 quick_widgets,
1002 #ifdef ENABLE_VFS_FTP
1003 confvfs_callback,
1004 #else
1005 NULL,
1006 #endif
1007 NULL,
1010 #ifdef ENABLE_VFS_FTP
1011 if (!ftpfs_always_use_proxy)
1012 quick_widgets[5].options = W_DISABLED;
1013 #endif
1015 if (quick_dialog (&qdlg) != B_CANCEL)
1017 vfs_timeout = atoi (ret_timeout);
1018 g_free (ret_timeout);
1020 if (vfs_timeout < 0 || vfs_timeout > 10000)
1021 vfs_timeout = 10;
1022 #ifdef ENABLE_VFS_FTP
1023 g_free (ftpfs_anonymous_passwd);
1024 ftpfs_anonymous_passwd = ret_passwd;
1025 g_free (ftpfs_proxy_host);
1026 ftpfs_proxy_host = ret_ftp_proxy;
1027 ftpfs_directory_timeout = atoi (ret_directory_timeout);
1028 g_free (ret_directory_timeout);
1029 #endif
1034 #endif /* ENABLE_VFS */
1036 /* --------------------------------------------------------------------------------------------- */
1038 char *
1039 cd_dialog (void)
1041 const Widget *w = WIDGET (current_panel);
1042 char *my_str;
1044 quick_widget_t quick_widgets[] = {
1045 QUICK_LABELED_INPUT (N_("cd"), input_label_left, "", 2, "input", &my_str, NULL),
1046 QUICK_END
1049 quick_dialog_t qdlg = {
1050 w->y + w->lines - 6, w->x, w->cols,
1051 N_("Quick cd"), "[Quick cd]",
1052 quick_widgets, NULL, NULL
1055 return (quick_dialog (&qdlg) != B_CANCEL) ? my_str : NULL;
1058 /* --------------------------------------------------------------------------------------------- */
1060 void
1061 symlink_dialog (const vfs_path_t * existing_vpath, const vfs_path_t * new_vpath,
1062 char **ret_existing, char **ret_new)
1064 char *existing;
1065 char *new;
1067 existing = vfs_path_to_str (existing_vpath);
1068 new = vfs_path_to_str (new_vpath);
1071 quick_widget_t quick_widgets[] = {
1072 /* *INDENT-OFF* */
1073 QUICK_LABELED_INPUT (N_("Existing filename (filename symlink will point to):"),
1074 input_label_above,
1075 existing, 0, "input-2", ret_existing, NULL),
1076 QUICK_SEPARATOR (FALSE),
1077 QUICK_LABELED_INPUT (N_("Symbolic link filename:"), input_label_above,
1078 new, 0, "input-1", ret_new, NULL),
1079 QUICK_BUTTONS_OK_CANCEL,
1080 QUICK_END
1081 /* *INDENT-ON* */
1084 quick_dialog_t qdlg = {
1085 -1, -1, 64,
1086 N_("Symbolic link"), "[File Menu]",
1087 quick_widgets, NULL, NULL
1090 if (quick_dialog (&qdlg) == B_CANCEL)
1092 *ret_new = NULL;
1093 *ret_existing = NULL;
1097 g_free (existing);
1098 g_free (new);
1101 /* --------------------------------------------------------------------------------------------- */
1103 #ifdef ENABLE_BACKGROUND
1104 void
1105 jobs_cmd (void)
1107 struct
1109 const char *name;
1110 int flags;
1111 int value;
1112 int len;
1113 bcback_fn callback;
1115 job_but[] =
1117 /* *INDENT-OFF* */
1118 { N_("&Stop"), NORMAL_BUTTON, B_STOP, 0, task_cb },
1119 { N_("&Resume"), NORMAL_BUTTON, B_RESUME, 0, task_cb },
1120 { N_("&Kill"), NORMAL_BUTTON, B_KILL, 0, task_cb },
1121 { N_("&OK"), DEFPUSH_BUTTON, B_CANCEL, 0, NULL }
1122 /* *INDENT-ON* */
1125 size_t i;
1126 const size_t n_but = G_N_ELEMENTS (job_but);
1128 WDialog *jobs_dlg;
1129 int cols = 60;
1130 int lines = 15;
1131 int x = 0;
1133 for (i = 0; i < n_but; i++)
1135 #ifdef ENABLE_NLS
1136 job_but[i].name = _(job_but[i].name);
1137 #endif /* ENABLE_NLS */
1139 job_but[i].len = str_term_width1 (job_but[i].name) + 3;
1140 if (job_but[i].flags == DEFPUSH_BUTTON)
1141 job_but[i].len += 2;
1142 x += job_but[i].len;
1145 x += (int) n_but - 1;
1146 cols = max (cols, x + 6);
1148 jobs_dlg = create_dlg (TRUE, 0, 0, lines, cols, dialog_colors, NULL, NULL,
1149 "[Background jobs]", _("Background jobs"), DLG_CENTER);
1151 bg_list = listbox_new (2, 2, lines - 6, cols - 6, FALSE, NULL);
1152 jobs_fill_listbox (bg_list);
1153 add_widget (jobs_dlg, bg_list);
1155 add_widget (jobs_dlg, hline_new (lines - 4, -1, -1));
1157 x = (cols - x) / 2;
1158 for (i = 0; i < n_but; i++)
1160 add_widget (jobs_dlg,
1161 button_new (lines - 3, x, job_but[i].value, job_but[i].flags, job_but[i].name,
1162 job_but[i].callback));
1163 x += job_but[i].len + 1;
1166 (void) run_dlg (jobs_dlg);
1167 destroy_dlg (jobs_dlg);
1169 #endif /* ENABLE_BACKGROUND */
1171 /* --------------------------------------------------------------------------------------------- */
1173 #ifdef ENABLE_VFS_SMB
1174 struct smb_authinfo *
1175 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, const char *user)
1177 char *label;
1178 struct smb_authinfo *return_value = NULL;
1180 if (domain == NULL)
1181 domain = "";
1182 if (user == NULL)
1183 user = "";
1185 label = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1188 char *ret_domain, *ret_user, *ret_password;
1190 quick_widget_t quick_widgets[] = {
1191 /* *INDENT-OFF* */
1192 QUICK_LABEL (label, NULL),
1193 QUICK_SEPARATOR (TRUE),
1194 QUICK_START_COLUMNS,
1195 QUICK_LABEL (N_("Domain:"), NULL),
1196 QUICK_SEPARATOR (FALSE),
1197 QUICK_LABEL (N_("Username:"), NULL),
1198 QUICK_SEPARATOR (FALSE),
1199 QUICK_LABEL (N_("Password:"), NULL),
1200 QUICK_NEXT_COLUMN,
1201 QUICK_INPUT (domain, 0, "auth_domain", &ret_domain, NULL),
1202 QUICK_SEPARATOR (FALSE),
1203 QUICK_INPUT (user, 0, "auth_name", &ret_user, NULL),
1204 QUICK_SEPARATOR (FALSE),
1205 QUICK_INPUT ("", 1, "auth_password", &ret_password, NULL),
1206 QUICK_STOP_COLUMNS,
1207 QUICK_BUTTONS_OK_CANCEL,
1208 QUICK_END
1209 /* *INDENT-ON* */
1212 quick_dialog_t qdlg = {
1213 -1, -1, 40,
1214 N_("SMB authentication"), "[Smb Authinfo]",
1215 quick_widgets, NULL, NULL
1218 if (quick_dialog (&qdlg) != B_CANCEL)
1220 return_value = vfs_smb_authinfo_new (host, share, ret_domain, ret_user, ret_password);
1222 g_free (ret_domain);
1223 g_free (ret_user);
1224 g_free (ret_password);
1228 g_free (label);
1230 return return_value;
1232 #endif /* ENABLE_VFS_SMB */
1234 /* --------------------------------------------------------------------------------------------- */