4 Copyright (C) 1994-2021
5 Free Software Foundation, Inc.
7 This file is part of the Midnight Commander.
9 The Midnight Commander is free software: you can redistribute it
10 and/or modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation, either version 3 of the License,
12 or (at your option) any later version.
14 The Midnight Commander is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * \brief Source: setup loading/saving
32 #include <sys/types.h>
35 #include "lib/global.h"
37 #include "lib/tty/tty.h"
38 #include "lib/tty/key.h"
39 #include "lib/mcconfig.h" /* num_history_items_recorded */
40 #include "lib/fileloc.h"
41 #include "lib/timefmt.h"
45 #include "src/vfs/ftpfs/ftpfs.h"
47 #ifdef ENABLE_VFS_FISH
48 #include "src/vfs/fish/fish.h"
52 #include "lib/charsets.h"
55 #include "filemanager/dir.h"
56 #include "filemanager/filemanager.h"
57 #include "filemanager/tree.h" /* xtree_mode */
58 #include "filemanager/hotlist.h" /* load/save/done hotlist */
59 #include "filemanager/panelize.h" /* load/save/done panelize */
60 #include "filemanager/layout.h"
61 #include "filemanager/cmd.h"
64 #include "execute.h" /* pause_after_run */
65 #include "clipboard.h"
68 #include "selcodepage.h"
71 #ifdef USE_INTERNAL_EDIT
72 #include "src/editor/edit.h"
75 #include "src/viewer/mcviewer.h" /* For the externs */
79 /*** global variables ****************************************************************************/
81 char *global_profile_name
; /* mc.lib */
83 /* Only used at program boot */
84 gboolean boot_current_is_left
= TRUE
;
86 /* If on, default for "No" in delete operations */
87 gboolean safe_delete
= FALSE
;
88 /* If on, default for "No" in overwrite files */
89 gboolean safe_overwrite
= FALSE
;
91 /* Controls screen clearing before an exec */
92 gboolean clear_before_exec
= TRUE
;
94 /* Asks for confirmation before deleting a file */
95 gboolean confirm_delete
= TRUE
;
96 /* Asks for confirmation before deleting a hotlist entry */
97 gboolean confirm_directory_hotlist_delete
= FALSE
;
98 /* Asks for confirmation before overwriting a file */
99 gboolean confirm_overwrite
= TRUE
;
100 /* Asks for confirmation before executing a program by pressing enter */
101 gboolean confirm_execute
= FALSE
;
102 /* Asks for confirmation before leaving the program */
103 gboolean confirm_exit
= FALSE
;
105 /* If true, at startup the user-menu is invoked */
106 gboolean auto_menu
= FALSE
;
107 /* This flag indicates if the pull down menus by default drop down */
108 gboolean drop_menus
= FALSE
;
110 /* Asks for confirmation when using F3 to view a directory and there
112 gboolean confirm_view_dir
= FALSE
;
114 /* Ask file name before start the editor */
115 gboolean editor_ask_filename_before_edit
= FALSE
;
117 panel_view_mode_t startup_left_mode
;
118 panel_view_mode_t startup_right_mode
;
120 gboolean copymove_persistent_attr
= TRUE
;
123 int option_tab_spacing
= DEFAULT_TAB_SPACING
;
125 /* Ugly hack to allow panel_save_setup to work as a place holder for */
126 /* default panel values */
129 panels_options_t panels_options
= {
130 .show_mini_info
= TRUE
,
131 .kilobyte_si
= FALSE
,
132 .mix_all_files
= FALSE
,
133 .show_backups
= TRUE
,
134 .show_dot_files
= TRUE
,
135 .fast_reload
= FALSE
,
136 .fast_reload_msg_shown
= FALSE
,
137 .mark_moves_down
= TRUE
,
138 .reverse_files_only
= TRUE
,
139 .auto_save_setup
= FALSE
,
140 .navigate_with_arrows
= FALSE
,
141 .scroll_pages
= TRUE
,
142 .scroll_center
= FALSE
,
143 .mouse_move_pages
= TRUE
,
144 .filetype_mode
= TRUE
,
145 .permission_mode
= FALSE
,
146 .qsearch_mode
= QSEARCH_PANEL_CASE
,
147 .torben_fj_mode
= FALSE
,
148 .select_flags
= SELECT_MATCH_CASE
| SELECT_SHELL_PATTERNS
151 gboolean easy_patterns
= TRUE
;
153 /* It true saves the setup when quitting */
154 gboolean auto_save_setup
= TRUE
;
156 /* If true, then the +, - and \ keys have their special meaning only if the
157 * command line is empty, otherwise they behave like regular letters
159 gboolean only_leading_plus_minus
= TRUE
;
161 /* Automatically fills name with current selected item name on mkdir */
162 gboolean auto_fill_mkdir_name
= TRUE
;
164 /* If set and you don't have subshell support, then C-o will give you a shell */
165 gboolean output_starts_shell
= FALSE
;
167 /* If set, we execute the file command to check the file type */
168 gboolean use_file_to_check_type
= TRUE
;
170 gboolean verbose
= TRUE
;
173 * Whether the Midnight Commander tries to provide more
174 * information about copy/move sizes and bytes transferred
175 * at the expense of some speed
177 gboolean file_op_compute_totals
= TRUE
;
179 /* If true use the internal viewer */
180 gboolean use_internal_view
= TRUE
;
181 /* If set, use the builtin editor */
182 gboolean use_internal_edit
= TRUE
;
185 /* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
186 int default_source_codepage
= -1;
187 char *autodetect_codeset
= NULL
;
188 gboolean is_autodetect_codeset_enabled
= FALSE
;
189 #endif /* !HAVE_CHARSET */
192 char *spell_language
= NULL
;
195 /* Value of "other_dir" key in ini file */
196 char *saved_other_dir
= NULL
;
198 /* If set, then print to the given file the last directory we were at */
199 char *last_wd_string
= NULL
;
201 /* Set when main loop should be terminated */
204 /* Set to TRUE to suppress printing the last directory */
205 int print_last_revert
= FALSE
;
207 #ifdef USE_INTERNAL_EDIT
208 /* index to record_macro_buf[], -1 if not recording a macro */
209 int macro_index
= -1;
212 struct macro_action_t record_macro_buf
[MAX_MACRO_LENGTH
];
215 #endif /* USE_INTERNAL_EDIT */
217 /*** file scope macro definitions ****************************************************************/
219 /* In order to use everywhere the same setup for the locale we use defines */
220 #define FMTYEAR _("%b %e %Y")
221 #define FMTTIME _("%b %e %H:%M")
223 /*** file scope type declarations ****************************************************************/
225 /*** file scope variables ************************************************************************/
227 static char *profile_name
= NULL
; /* ${XDG_CONFIG_HOME}/mc/ini */
228 static char *panels_profile_name
= NULL
; /* ${XDG_CACHE_HOME}/mc/panels.ini */
235 } list_formats
[] = {
236 { "full", list_full
},
237 { "brief", list_brief
},
238 { "long", list_long
},
239 { "user", list_user
},
245 const char *opt_name
;
246 panel_view_mode_t opt_type
;
248 { "listing", view_listing
},
249 { "quickview", view_quick
},
250 { "info", view_info
},
251 { "tree", view_tree
},
252 { NULL
, view_listing
}
257 const char *opt_name
;
259 } layout_int_options
[] = {
260 { "output_lines", &output_lines
},
261 { "left_panel_size", &panels_layout
.left_panel_size
},
262 { "top_panel_size", &panels_layout
.top_panel_size
},
268 const char *opt_name
;
270 } layout_bool_options
[] = {
271 { "message_visible", &mc_global
.message_visible
},
272 { "keybar_visible", &mc_global
.keybar_visible
},
273 { "xterm_title", &xterm_title
},
274 { "command_prompt", &command_prompt
},
275 { "menubar_visible", &menubar_visible
},
276 { "free_space", &free_space
},
277 { "horizontal_split", &panels_layout
.horizontal_split
},
278 { "vertical_equal", &panels_layout
.vertical_equal
},
279 { "horizontal_equal", &panels_layout
.horizontal_equal
},
285 const char *opt_name
;
287 } bool_options
[] = {
288 { "verbose", &verbose
},
289 { "shell_patterns", &easy_patterns
},
290 { "auto_save_setup", &auto_save_setup
},
291 { "preallocate_space", &mc_global
.vfs
.preallocate_space
},
292 { "auto_menu", &auto_menu
},
293 { "use_internal_view", &use_internal_view
},
294 { "use_internal_edit", &use_internal_edit
},
295 { "clear_before_exec", &clear_before_exec
},
296 { "confirm_delete", &confirm_delete
},
297 { "confirm_overwrite", &confirm_overwrite
},
298 { "confirm_execute", &confirm_execute
},
299 { "confirm_history_cleanup", &mc_global
.widget
.confirm_history_cleanup
},
300 { "confirm_exit", &confirm_exit
},
301 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete
},
302 { "confirm_view_dir", &confirm_view_dir
},
303 { "safe_delete", &safe_delete
},
304 { "safe_overwrite", &safe_overwrite
},
306 { "eight_bit_clean", &mc_global
.eight_bit_clean
},
307 { "full_eight_bits", &mc_global
.full_eight_bits
},
308 #endif /* !HAVE_CHARSET */
309 { "use_8th_bit_as_meta", &use_8th_bit_as_meta
},
310 { "mouse_move_pages_viewer", &mcview_mouse_move_pages
},
311 { "mouse_close_dialog", &mouse_close_dialog
},
312 { "fast_refresh", &fast_refresh
},
313 { "drop_menus", &drop_menus
},
314 { "wrap_mode", &mcview_global_flags
.wrap
},
315 { "old_esc_mode", &old_esc_mode
},
316 { "cd_symlinks", &mc_global
.vfs
.cd_symlinks
},
317 { "show_all_if_ambiguous", &mc_global
.widget
.show_all_if_ambiguous
},
319 { "use_file_to_guess_type", &use_file_to_check_type
},
321 { "alternate_plus_minus", &mc_global
.tty
.alternate_plus_minus
},
322 { "only_leading_plus_minus", &only_leading_plus_minus
},
323 { "show_output_starts_shell", &output_starts_shell
},
324 { "xtree_mode", &xtree_mode
},
325 { "file_op_compute_totals", &file_op_compute_totals
},
326 { "classic_progressbar", &classic_progressbar
},
328 #ifdef ENABLE_VFS_FTP
329 { "use_netrc", &ftpfs_use_netrc
},
330 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy
},
331 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections
},
332 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy
},
333 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options
},
334 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls
},
335 { "ignore_ftp_chattr_errors", & ftpfs_ignore_chattr_errors
} ,
336 #endif /* ENABLE_VFS_FTP */
337 #endif /* ENABLE_VFS */
338 #ifdef USE_INTERNAL_EDIT
339 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces
},
340 { "editor_return_does_auto_indent", &option_return_does_auto_indent
},
341 { "editor_backspace_through_tabs", &option_backspace_through_tabs
},
342 { "editor_fake_half_tabs", &option_fake_half_tabs
},
343 { "editor_option_save_position", &option_save_position
},
344 { "editor_option_auto_para_formatting", &option_auto_para_formatting
},
345 { "editor_option_typewriter_wrap", &option_typewriter_wrap
},
346 { "editor_edit_confirm_save", &edit_confirm_save
},
347 { "editor_syntax_highlighting", &option_syntax_highlighting
},
348 { "editor_persistent_selections", &option_persistent_selections
},
349 { "editor_drop_selection_on_copy", &option_drop_selection_on_copy
},
350 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol
},
351 { "editor_cursor_after_inserted_block", &option_cursor_after_inserted_block
},
352 { "editor_visible_tabs", &visible_tabs
},
353 { "editor_visible_spaces", &visible_tws
},
354 { "editor_line_state", &option_line_state
},
355 { "editor_simple_statusbar", &simple_statusbar
},
356 { "editor_check_new_line", &option_check_nl_at_eof
},
357 { "editor_show_right_margin", &show_right_margin
},
358 { "editor_group_undo", &option_group_undo
},
359 { "editor_state_full_filename", &option_state_full_filename
},
360 #endif /* USE_INTERNAL_EDIT */
361 { "editor_ask_filename_before_edit", &editor_ask_filename_before_edit
},
362 { "nice_rotating_dash", &nice_rotating_dash
},
363 { "shadows", &mc_global
.tty
.shadows
},
364 { "mcview_remember_file_position", &mcview_remember_file_position
},
365 { "auto_fill_mkdir_name", &auto_fill_mkdir_name
},
366 { "copymove_persistent_attr", ©move_persistent_attr
},
372 const char *opt_name
;
375 { "pause_after_run", &pause_after_run
},
376 { "mouse_repeat_rate", &mou_auto_repeat
},
377 { "double_click_speed", &double_click_speed
},
378 { "old_esc_mode_timeout", &old_esc_mode_timeout
},
379 { "max_dirt_limit", &mcview_max_dirt_limit
},
380 { "num_history_items_recorded", &num_history_items_recorded
},
382 { "vfs_timeout", &vfs_timeout
},
383 #ifdef ENABLE_VFS_FTP
384 { "ftpfs_directory_timeout", &ftpfs_directory_timeout
},
385 { "ftpfs_retry_seconds", &ftpfs_retry_seconds
},
386 #endif /* ENABLE_VFS_FTP */
387 #ifdef ENABLE_VFS_FISH
388 { "fish_directory_timeout", &fish_directory_timeout
},
389 #endif /* ENABLE_VFS_FISH */
390 #endif /* ENABLE_VFS */
391 /* option_tab_spacing is used in internal viewer */
392 { "editor_tab_spacing", &option_tab_spacing
},
393 #ifdef USE_INTERNAL_EDIT
394 { "editor_word_wrap_line_length", &option_word_wrap_line_length
},
395 { "editor_option_save_mode", &option_save_mode
},
396 #endif /* USE_INTERNAL_EDIT */
402 const char *opt_name
;
404 const char *opt_defval
;
406 #ifdef USE_INTERNAL_EDIT
407 { "editor_backup_extension", &option_backup_ext
, "~" },
408 { "editor_filesize_threshold", &option_filesize_threshold
, "64M" },
409 { "editor_stop_format_chars", &option_stop_format_chars
, "-+*\\,.;:&>" },
411 { "mcview_eof", &mcview_show_eof
, "" },
417 const char *opt_name
;
419 } panels_ini_options
[] = {
420 { "show_mini_info", &panels_options
.show_mini_info
},
421 { "kilobyte_si", &panels_options
.kilobyte_si
},
422 { "mix_all_files", &panels_options
.mix_all_files
},
423 { "show_backups", &panels_options
.show_backups
},
424 { "show_dot_files", &panels_options
.show_dot_files
},
425 { "fast_reload", &panels_options
.fast_reload
},
426 { "fast_reload_msg_shown", &panels_options
.fast_reload_msg_shown
},
427 { "mark_moves_down", &panels_options
.mark_moves_down
},
428 { "reverse_files_only", &panels_options
.reverse_files_only
},
429 { "auto_save_setup_panels", &panels_options
.auto_save_setup
},
430 { "navigate_with_arrows", &panels_options
.navigate_with_arrows
},
431 { "panel_scroll_pages", &panels_options
.scroll_pages
},
432 { "panel_scroll_center", &panels_options
.scroll_center
},
433 { "mouse_move_pages", &panels_options
.mouse_move_pages
},
434 { "filetype_mode", &panels_options
.filetype_mode
},
435 { "permission_mode", &panels_options
.permission_mode
},
436 { "torben_fj_mode", &panels_options
.torben_fj_mode
},
441 /* --------------------------------------------------------------------------------------------- */
442 /*** file scope functions ************************************************************************/
443 /* --------------------------------------------------------------------------------------------- */
446 setup__is_cfg_group_must_panel_config (const char *grp
)
448 return (!strcasecmp ("Dirs", grp
) ||
449 !strcasecmp ("Temporal:New Right Panel", grp
) ||
450 !strcasecmp ("Temporal:New Left Panel", grp
) ||
451 !strcasecmp ("New Left Panel", grp
) || !strcasecmp ("New Right Panel", grp
))
455 /* --------------------------------------------------------------------------------------------- */
458 setup__move_panels_config_into_separate_file (const char *profile
)
460 mc_config_t
*tmp_cfg
;
461 char **groups
, **curr_grp
;
463 if (!exist_file (profile
))
466 tmp_cfg
= mc_config_init (profile
, FALSE
);
470 groups
= mc_config_get_groups (tmp_cfg
, NULL
);
474 mc_config_deinit (tmp_cfg
);
478 for (curr_grp
= groups
; *curr_grp
!= NULL
; curr_grp
++)
479 if (setup__is_cfg_group_must_panel_config (*curr_grp
) == NULL
)
480 mc_config_del_group (tmp_cfg
, *curr_grp
);
482 mc_config_save_to_file (tmp_cfg
, panels_profile_name
, NULL
);
483 mc_config_deinit (tmp_cfg
);
485 tmp_cfg
= mc_config_init (profile
, FALSE
);
492 for (curr_grp
= groups
; *curr_grp
!= NULL
; curr_grp
++)
494 const char *need_grp
;
496 need_grp
= setup__is_cfg_group_must_panel_config (*curr_grp
);
497 if (need_grp
!= NULL
)
498 mc_config_del_group (tmp_cfg
, need_grp
);
502 mc_config_save_file (tmp_cfg
, NULL
);
503 mc_config_deinit (tmp_cfg
);
506 /* --------------------------------------------------------------------------------------------- */
514 /* Load boolean options */
515 for (i
= 0; bool_options
[i
].opt_name
!= NULL
; i
++)
516 *bool_options
[i
].opt_addr
=
517 mc_config_get_bool (mc_global
.main_config
, CONFIG_APP_SECTION
, bool_options
[i
].opt_name
,
518 *bool_options
[i
].opt_addr
);
520 /* Load integer options */
521 for (i
= 0; int_options
[i
].opt_name
!= NULL
; i
++)
522 *int_options
[i
].opt_addr
=
523 mc_config_get_int (mc_global
.main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
,
524 *int_options
[i
].opt_addr
);
526 /* Load string options */
527 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
528 *str_options
[i
].opt_addr
=
529 mc_config_get_string (mc_global
.main_config
, CONFIG_APP_SECTION
,
530 str_options
[i
].opt_name
, str_options
[i
].opt_defval
);
532 /* Overwrite some options */
533 #ifdef USE_INTERNAL_EDIT
534 if (option_word_wrap_line_length
<= 0)
535 option_word_wrap_line_length
= DEFAULT_WRAP_LINE_LENGTH
;
537 /* Reset forced in case of build without internal editor */
538 use_internal_edit
= FALSE
;
539 #endif /* USE_INTERNAL_EDIT */
541 if (option_tab_spacing
<= 0)
542 option_tab_spacing
= DEFAULT_TAB_SPACING
;
544 kt
= getenv ("KEYBOARD_KEY_TIMEOUT_US");
545 if (kt
!= NULL
&& kt
[0] != '\0')
546 old_esc_mode_timeout
= atoi (kt
);
549 /* --------------------------------------------------------------------------------------------- */
551 static panel_view_mode_t
552 setup__load_panel_state (const char *section
)
556 panel_view_mode_t mode
= view_listing
;
558 /* Load the display mode */
559 buffer
= mc_config_get_string (mc_global
.panels_config
, section
, "display", "listing");
561 for (i
= 0; panel_types
[i
].opt_name
!= NULL
; i
++)
562 if (g_ascii_strcasecmp (panel_types
[i
].opt_name
, buffer
) == 0)
564 mode
= panel_types
[i
].opt_type
;
573 /* --------------------------------------------------------------------------------------------- */
580 /* actual options override legacy ones */
581 for (i
= 0; layout_int_options
[i
].opt_name
!= NULL
; i
++)
582 *layout_int_options
[i
].opt_addr
=
583 mc_config_get_int (mc_global
.main_config
, CONFIG_LAYOUT_SECTION
,
584 layout_int_options
[i
].opt_name
, *layout_int_options
[i
].opt_addr
);
586 for (i
= 0; layout_bool_options
[i
].opt_name
!= NULL
; i
++)
587 *layout_bool_options
[i
].opt_addr
=
588 mc_config_get_bool (mc_global
.main_config
, CONFIG_LAYOUT_SECTION
,
589 layout_bool_options
[i
].opt_name
, *layout_bool_options
[i
].opt_addr
);
591 startup_left_mode
= setup__load_panel_state ("New Left Panel");
592 startup_right_mode
= setup__load_panel_state ("New Right Panel");
594 /* At least one of the panels is a listing panel */
595 if (startup_left_mode
!= view_listing
&& startup_right_mode
!= view_listing
)
596 startup_left_mode
= view_listing
;
598 boot_current_is_left
=
599 mc_config_get_bool (mc_global
.panels_config
, "Dirs", "current_is_left", TRUE
);
602 /* --------------------------------------------------------------------------------------------- */
605 load_keys_from_section (const char *terminal
, mc_config_t
* cfg
)
608 gchar
**profile_keys
, **keys
;
609 char *valcopy
, *value
;
612 if (terminal
== NULL
)
615 section_name
= g_strconcat ("terminal:", terminal
, (char *) NULL
);
616 keys
= mc_config_get_keys (cfg
, section_name
, NULL
);
618 for (profile_keys
= keys
; *profile_keys
!= NULL
; profile_keys
++)
620 /* copy=other causes all keys from [terminal:other] to be loaded. */
621 if (g_ascii_strcasecmp (*profile_keys
, "copy") == 0)
623 valcopy
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
624 load_keys_from_section (valcopy
, cfg
);
629 key_code
= lookup_key (*profile_keys
, NULL
);
634 values
= mc_config_get_string_list (cfg
, section_name
, *profile_keys
, NULL
);
639 for (curr_values
= values
; *curr_values
!= NULL
; curr_values
++)
641 valcopy
= convert_controls (*curr_values
);
642 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
650 value
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
651 valcopy
= convert_controls (value
);
652 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
659 g_free (section_name
);
662 /* --------------------------------------------------------------------------------------------- */
665 panel_save_type (const char *section
, panel_view_mode_t type
)
669 for (i
= 0; panel_types
[i
].opt_name
!= NULL
; i
++)
670 if (panel_types
[i
].opt_type
== type
)
672 mc_config_set_string (mc_global
.panels_config
, section
, "display",
673 panel_types
[i
].opt_name
);
678 /* --------------------------------------------------------------------------------------------- */
681 * Load panels options from [Panels] section.
684 panels_load_options (void)
686 if (mc_config_has_group (mc_global
.main_config
, CONFIG_PANELS_SECTION
))
691 for (i
= 0; panels_ini_options
[i
].opt_name
!= NULL
; i
++)
692 *panels_ini_options
[i
].opt_addr
=
693 mc_config_get_bool (mc_global
.main_config
, CONFIG_PANELS_SECTION
,
694 panels_ini_options
[i
].opt_name
,
695 *panels_ini_options
[i
].opt_addr
);
697 qmode
= mc_config_get_int (mc_global
.main_config
, CONFIG_PANELS_SECTION
,
698 "quick_search_mode", (int) panels_options
.qsearch_mode
);
700 panels_options
.qsearch_mode
= QSEARCH_CASE_INSENSITIVE
;
701 else if (qmode
>= QSEARCH_NUM
)
702 panels_options
.qsearch_mode
= QSEARCH_PANEL_CASE
;
704 panels_options
.qsearch_mode
= (qsearch_mode_t
) qmode
;
706 panels_options
.select_flags
=
707 mc_config_get_int (mc_global
.main_config
, CONFIG_PANELS_SECTION
, "select_flags",
708 (int) panels_options
.select_flags
);
712 /* --------------------------------------------------------------------------------------------- */
715 * Save panels options in [Panels] section.
718 panels_save_options (void)
722 for (i
= 0; panels_ini_options
[i
].opt_name
!= NULL
; i
++)
723 mc_config_set_bool (mc_global
.main_config
, CONFIG_PANELS_SECTION
,
724 panels_ini_options
[i
].opt_name
, *panels_ini_options
[i
].opt_addr
);
726 mc_config_set_int (mc_global
.main_config
, CONFIG_PANELS_SECTION
,
727 "quick_search_mode", (int) panels_options
.qsearch_mode
);
728 mc_config_set_int (mc_global
.main_config
, CONFIG_PANELS_SECTION
,
729 "select_flags", (int) panels_options
.select_flags
);
732 /* --------------------------------------------------------------------------------------------- */
739 /* Save boolean options */
740 for (i
= 0; bool_options
[i
].opt_name
!= NULL
; i
++)
741 mc_config_set_bool (mc_global
.main_config
, CONFIG_APP_SECTION
, bool_options
[i
].opt_name
,
742 *bool_options
[i
].opt_addr
);
744 /* Save integer options */
745 for (i
= 0; int_options
[i
].opt_name
!= NULL
; i
++)
746 mc_config_set_int (mc_global
.main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
,
747 *int_options
[i
].opt_addr
);
749 /* Save string options */
750 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
751 mc_config_set_string (mc_global
.main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
,
752 *str_options
[i
].opt_addr
);
755 /* --------------------------------------------------------------------------------------------- */
762 /* Save integer options */
763 for (i
= 0; layout_int_options
[i
].opt_name
!= NULL
; i
++)
764 mc_config_set_int (mc_global
.main_config
, CONFIG_LAYOUT_SECTION
,
765 layout_int_options
[i
].opt_name
, *layout_int_options
[i
].opt_addr
);
767 /* Save boolean options */
768 for (i
= 0; layout_bool_options
[i
].opt_name
!= NULL
; i
++)
769 mc_config_set_bool (mc_global
.main_config
, CONFIG_LAYOUT_SECTION
,
770 layout_bool_options
[i
].opt_name
, *layout_bool_options
[i
].opt_addr
);
773 /* --------------------------------------------------------------------------------------------- */
775 /* save panels.ini */
777 save_panel_types (void)
779 panel_view_mode_t type
;
781 if (mc_global
.mc_run_mode
!= MC_RUN_FULL
)
784 type
= get_panel_type (0);
785 panel_save_type ("New Left Panel", type
);
786 if (type
== view_listing
)
787 panel_save_setup (left_panel
, left_panel
->name
);
788 type
= get_panel_type (1);
789 panel_save_type ("New Right Panel", type
);
790 if (type
== view_listing
)
791 panel_save_setup (right_panel
, right_panel
->name
);
796 dirs
= get_panel_dir_for (other_panel
);
797 mc_config_set_string (mc_global
.panels_config
, "Dirs", "other_dir", dirs
);
801 if (current_panel
!= NULL
)
802 mc_config_set_bool (mc_global
.panels_config
, "Dirs", "current_is_left",
803 get_current_index () == 0);
805 if (mc_global
.panels_config
->ini_path
== NULL
)
806 mc_global
.panels_config
->ini_path
= g_strdup (panels_profile_name
);
808 mc_config_del_group (mc_global
.panels_config
, "Temporal:New Left Panel");
809 mc_config_del_group (mc_global
.panels_config
, "Temporal:New Right Panel");
811 mc_config_save_file (mc_global
.panels_config
, NULL
);
814 /* --------------------------------------------------------------------------------------------- */
815 /*** public functions ****************************************************************************/
816 /* --------------------------------------------------------------------------------------------- */
821 if (profile_name
== NULL
)
825 profile
= mc_config_get_full_path (MC_CONFIG_FILE
);
826 if (!exist_file (profile
))
830 inifile
= mc_build_filename (mc_global
.sysconfig_dir
, "mc.ini", (char *) NULL
);
831 if (exist_file (inifile
))
839 inifile
= mc_build_filename (mc_global
.share_data_dir
, "mc.ini", (char *) NULL
);
840 if (!exist_file (inifile
))
850 profile_name
= profile
;
856 /* --------------------------------------------------------------------------------------------- */
866 load_codepages_list ();
867 #endif /* HAVE_CHARSET */
869 profile
= setup_init ();
871 /* mc.lib is common for all users, but has priority lower than
872 ${XDG_CONFIG_HOME}/mc/ini. FIXME: it's only used for keys and treestore now */
873 global_profile_name
=
874 g_build_filename (mc_global
.sysconfig_dir
, MC_GLOBAL_CONFIG_FILE
, (char *) NULL
);
875 if (!exist_file (global_profile_name
))
877 g_free (global_profile_name
);
878 global_profile_name
=
879 g_build_filename (mc_global
.share_data_dir
, MC_GLOBAL_CONFIG_FILE
, (char *) NULL
);
882 panels_profile_name
= mc_config_get_full_path (MC_PANELS_FILE
);
884 mc_global
.main_config
= mc_config_init (profile
, FALSE
);
886 if (!exist_file (panels_profile_name
))
887 setup__move_panels_config_into_separate_file (profile
);
889 mc_global
.panels_config
= mc_config_init (panels_profile_name
, FALSE
);
893 panels_load_options ();
896 /* Load time formats */
897 user_recent_timeformat
=
898 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "timeformat_recent",
900 user_old_timeformat
=
901 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "timeformat_old",
904 #ifdef ENABLE_VFS_FTP
906 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "ftp_proxy_host", "gate");
907 ftpfs_init_passwd ();
908 #endif /* ENABLE_VFS_FTP */
910 /* The default color and the terminal dependent color */
911 mc_global
.tty
.setup_color_string
=
912 mc_config_get_string (mc_global
.main_config
, "Colors", "base_color", "");
913 mc_global
.tty
.term_color_string
=
914 mc_config_get_string (mc_global
.main_config
, "Colors", getenv ("TERM"), "");
915 mc_global
.tty
.color_terminal_string
=
916 mc_config_get_string (mc_global
.main_config
, "Colors", "color_terminals", "");
918 /* Load the directory history */
919 /* directory_history_load (); */
920 /* Remove the temporal entries */
923 if (codepages
->len
> 1)
928 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "display_codepage",
930 if (buffer
[0] != '\0')
932 mc_global
.display_codepage
= get_codepage_index (buffer
);
933 cp_display
= get_codepage_id (mc_global
.display_codepage
);
937 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "source_codepage",
939 if (buffer
[0] != '\0')
941 default_source_codepage
= get_codepage_index (buffer
);
942 mc_global
.source_codepage
= default_source_codepage
; /* May be source_codepage doesn't need this */
943 cp_source
= get_codepage_id (mc_global
.source_codepage
);
949 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "autodetect_codeset", "");
950 if ((autodetect_codeset
[0] != '\0') && (strcmp (autodetect_codeset
, "off") != 0))
951 is_autodetect_codeset_enabled
= TRUE
;
953 g_free (init_translation_table (mc_global
.source_codepage
, mc_global
.display_codepage
));
954 cbuffer
= get_codepage_id (mc_global
.display_codepage
);
956 mc_global
.utf8_display
= str_isutf8 (cbuffer
);
957 #endif /* HAVE_CHARSET */
961 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "spell_language", "en");
962 #endif /* HAVE_ASPELL */
964 clipboard_store_path
=
965 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "clipboard_store", "");
966 clipboard_paste_path
=
967 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "clipboard_paste", "");
970 /* --------------------------------------------------------------------------------------------- */
973 save_setup (gboolean save_options
, gboolean save_panel_options
)
981 if (save_panel_options
)
990 panels_save_options ();
992 /* directory_history_save (); */
994 #ifdef ENABLE_VFS_FTP
995 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "ftpfs_password",
996 ftpfs_anonymous_passwd
);
997 if (ftpfs_proxy_host
)
998 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "ftp_proxy_host",
1000 #endif /* ENABLE_VFS_FTP */
1003 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "display_codepage",
1004 get_codepage_id (mc_global
.display_codepage
));
1005 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "source_codepage",
1006 get_codepage_id (default_source_codepage
));
1007 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "autodetect_codeset",
1008 autodetect_codeset
);
1009 #endif /* HAVE_CHARSET */
1012 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "spell_language",
1014 #endif /* HAVE_ASPELL */
1016 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "clipboard_store",
1017 clipboard_store_path
);
1018 mc_config_set_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "clipboard_paste",
1019 clipboard_paste_path
);
1021 tmp_profile
= mc_config_get_full_path (MC_CONFIG_FILE
);
1022 ret
= mc_config_save_to_file (mc_global
.main_config
, tmp_profile
, NULL
);
1023 g_free (tmp_profile
);
1031 /* --------------------------------------------------------------------------------------------- */
1038 g_free (clipboard_store_path
);
1039 g_free (clipboard_paste_path
);
1040 g_free (global_profile_name
);
1041 g_free (mc_global
.tty
.color_terminal_string
);
1042 g_free (mc_global
.tty
.term_color_string
);
1043 g_free (mc_global
.tty
.setup_color_string
);
1044 g_free (profile_name
);
1045 g_free (panels_profile_name
);
1046 mc_config_deinit (mc_global
.main_config
);
1047 mc_config_deinit (mc_global
.panels_config
);
1049 g_free (user_recent_timeformat
);
1050 g_free (user_old_timeformat
);
1052 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
1053 g_free (*str_options
[i
].opt_addr
);
1057 /* directory_history_free (); */
1060 g_free (autodetect_codeset
);
1061 free_codepages_list ();
1065 g_free (spell_language
);
1066 #endif /* HAVE_ASPELL */
1070 /* --------------------------------------------------------------------------------------------- */
1073 setup_save_config_show_error (const char *filename
, GError
** mcerror
)
1075 if (mcerror
!= NULL
&& *mcerror
!= NULL
)
1077 message (D_ERROR
, MSG_ERROR
, _("Cannot save file %s:\n%s"), filename
, (*mcerror
)->message
);
1078 g_error_free (*mcerror
);
1083 /* --------------------------------------------------------------------------------------------- */
1086 load_key_defs (void)
1089 * Load keys from mc.lib before ${XDG_CONFIG_HOME}/mc/ini, so that the user
1090 * definitions override global settings.
1092 mc_config_t
*mc_global_config
;
1094 mc_global_config
= mc_config_init (global_profile_name
, FALSE
);
1095 if (mc_global_config
!= NULL
)
1097 load_keys_from_section ("general", mc_global_config
);
1098 load_keys_from_section (getenv ("TERM"), mc_global_config
);
1099 mc_config_deinit (mc_global_config
);
1102 load_keys_from_section ("general", mc_global
.main_config
);
1103 load_keys_from_section (getenv ("TERM"), mc_global
.main_config
);
1106 /* --------------------------------------------------------------------------------------------- */
1108 #ifdef ENABLE_VFS_FTP
1110 load_anon_passwd (void)
1115 mc_config_get_string (mc_global
.main_config
, CONFIG_MISC_SECTION
, "ftpfs_password", "");
1117 if ((buffer
!= NULL
) && (buffer
[0] != '\0'))
1123 #endif /* ENABLE_VFS_FTP */
1125 /* --------------------------------------------------------------------------------------------- */
1128 panel_load_setup (WPanel
* panel
, const char *section
)
1131 char *buffer
, buffer2
[BUF_TINY
];
1133 panel
->sort_info
.reverse
=
1134 mc_config_get_bool (mc_global
.panels_config
, section
, "reverse", FALSE
);
1135 panel
->sort_info
.case_sensitive
=
1136 mc_config_get_bool (mc_global
.panels_config
, section
, "case_sensitive",
1137 OS_SORT_CASE_SENSITIVE_DEFAULT
);
1138 panel
->sort_info
.exec_first
=
1139 mc_config_get_bool (mc_global
.panels_config
, section
, "exec_first", FALSE
);
1141 /* Load sort order */
1142 buffer
= mc_config_get_string (mc_global
.panels_config
, section
, "sort_order", "name");
1143 panel
->sort_field
= panel_get_field_by_id (buffer
);
1144 if (panel
->sort_field
== NULL
)
1145 panel
->sort_field
= panel_get_field_by_id ("name");
1149 /* Load the listing format */
1150 buffer
= mc_config_get_string (mc_global
.panels_config
, section
, "list_format", NULL
);
1153 /* fallback to old option */
1154 buffer
= mc_config_get_string (mc_global
.panels_config
, section
, "list_mode", "full");
1156 panel
->list_format
= list_full
;
1157 for (i
= 0; list_formats
[i
].key
!= NULL
; i
++)
1158 if (g_ascii_strcasecmp (list_formats
[i
].key
, buffer
) == 0)
1160 panel
->list_format
= list_formats
[i
].list_format
;
1165 panel
->brief_cols
= mc_config_get_int (mc_global
.panels_config
, section
, "brief_cols", 2);
1168 g_free (panel
->user_format
);
1169 panel
->user_format
=
1170 mc_config_get_string (mc_global
.panels_config
, section
, "user_format", DEFAULT_USER_FORMAT
);
1172 for (i
= 0; i
< LIST_FORMATS
; i
++)
1174 g_free (panel
->user_status_format
[i
]);
1175 g_snprintf (buffer2
, sizeof (buffer2
), "user_status%lld", (long long) i
);
1176 panel
->user_status_format
[i
] =
1177 mc_config_get_string (mc_global
.panels_config
, section
, buffer2
, DEFAULT_USER_FORMAT
);
1180 panel
->user_mini_status
=
1181 mc_config_get_bool (mc_global
.panels_config
, section
, "user_mini_status", FALSE
);
1184 /* --------------------------------------------------------------------------------------------- */
1187 panel_save_setup (WPanel
* panel
, const char *section
)
1189 char buffer
[BUF_TINY
];
1192 mc_config_set_bool (mc_global
.panels_config
, section
, "reverse", panel
->sort_info
.reverse
);
1193 mc_config_set_bool (mc_global
.panels_config
, section
, "case_sensitive",
1194 panel
->sort_info
.case_sensitive
);
1195 mc_config_set_bool (mc_global
.panels_config
, section
, "exec_first",
1196 panel
->sort_info
.exec_first
);
1198 mc_config_set_string (mc_global
.panels_config
, section
, "sort_order", panel
->sort_field
->id
);
1200 for (i
= 0; list_formats
[i
].key
!= NULL
; i
++)
1201 if (list_formats
[i
].list_format
== (int) panel
->list_format
)
1203 mc_config_set_string (mc_global
.panels_config
, section
, "list_format",
1204 list_formats
[i
].key
);
1208 mc_config_set_int (mc_global
.panels_config
, section
, "brief_cols", panel
->brief_cols
);
1210 mc_config_set_string (mc_global
.panels_config
, section
, "user_format", panel
->user_format
);
1212 for (i
= 0; i
< LIST_FORMATS
; i
++)
1214 g_snprintf (buffer
, sizeof (buffer
), "user_status%lld", (long long) i
);
1215 mc_config_set_string (mc_global
.panels_config
, section
, buffer
,
1216 panel
->user_status_format
[i
]);
1219 mc_config_set_bool (mc_global
.panels_config
, section
, "user_mini_status",
1220 panel
->user_mini_status
);
1223 /* --------------------------------------------------------------------------------------------- */