1 /* Setup loading/saving.
2 Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
20 * \brief Source: setup loading/saving
28 #include <sys/types.h>
31 #include "lib/global.h"
33 #include "lib/tty/tty.h"
34 #include "lib/tty/key.h"
35 #include "lib/mcconfig.h"
36 #include "lib/fileloc.h"
37 #include "lib/timefmt.h"
39 #include "lib/widget.h"
41 #include "lib/vfs/vfs.h"
44 #include "src/vfs/ftpfs/ftpfs.h"
46 #ifdef ENABLE_VFS_FISH
47 #include "src/vfs/fish/fish.h"
51 #include "lib/charsets.h"
54 #include "filemanager/dir.h"
55 #include "filemanager/midnight.h"
56 #include "filemanager/tree.h" /* xtree_mode */
57 #include "filemanager/hotlist.h" /* load/save/done hotlist */
58 #include "filemanager/panelize.h" /* load/save/done panelize */
59 #include "filemanager/layout.h"
60 #include "filemanager/cmd.h"
63 #include "execute.h" /* pause_after_run */
64 #include "clipboard.h"
65 #include "keybind-defaults.h" /* keybind_lookup_action */
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 *profile_name
; /* ${XDG_CONFIG_HOME}/mc/ini */
82 char *global_profile_name
; /* mc.lib */
84 /* Only used at program boot */
85 gboolean boot_current_is_left
= TRUE
;
87 /* If on, default for "No" in delete operations */
90 /* Controls screen clearing before an exec */
91 int clear_before_exec
= 1;
93 /* Asks for confirmation before deleting a file */
94 int confirm_delete
= 1;
95 /* Asks for confirmation before deleting a hotlist entry */
96 int confirm_directory_hotlist_delete
= 1;
97 /* Asks for confirmation before overwriting a file */
98 int confirm_overwrite
= 1;
99 /* Asks for confirmation before executing a program by pressing enter */
100 int confirm_execute
= 0;
101 /* Asks for confirmation before leaving the program */
102 int confirm_exit
= 1;
104 /* If true, at startup the user-menu is invoked */
106 /* This flag indicates if the pull down menus by default drop down */
109 /* Asks for confirmation when using F3 to view a directory and there
111 int confirm_view_dir
= 0;
113 panel_view_mode_t startup_left_mode
;
114 panel_view_mode_t startup_right_mode
;
116 int setup_copymove_persistent_attr
= 1;
119 int option_tab_spacing
= DEFAULT_TAB_SPACING
;
121 /* Ugly hack to allow panel_save_setup to work as a place holder for */
122 /* default panel values */
125 panels_options_t panels_options
= {
126 .show_mini_info
= TRUE
,
127 .kilobyte_si
= FALSE
,
128 .mix_all_files
= FALSE
,
129 .show_backups
= TRUE
,
130 .show_dot_files
= TRUE
,
131 .fast_reload
= FALSE
,
132 .fast_reload_msg_shown
= FALSE
,
133 .mark_moves_down
= TRUE
,
134 .reverse_files_only
= TRUE
,
135 .auto_save_setup
= FALSE
,
136 .navigate_with_arrows
= FALSE
,
137 .scroll_pages
= TRUE
,
138 .mouse_move_pages
= TRUE
,
139 .filetype_mode
= TRUE
,
140 .permission_mode
= FALSE
,
141 .qsearch_mode
= QSEARCH_PANEL_CASE
,
142 .torben_fj_mode
= FALSE
145 int easy_patterns
= 1;
147 /* It true saves the setup when quitting */
148 int auto_save_setup
= 1;
150 /* If true, then the +, - and \ keys have their special meaning only if the
151 * command line is emtpy, otherwise they behave like regular letters
153 int only_leading_plus_minus
= 1;
155 /* Automatically fills name with current selected item name on mkdir */
156 int auto_fill_mkdir_name
= 1;
158 /* If set and you don't have subshell support,then C-o will give you a shell */
159 int output_starts_shell
= 0;
161 /* If set, we execute the file command to check the file type */
162 int use_file_to_check_type
= 1;
167 * Whether the Midnight Commander tries to provide more
168 * information about copy/move sizes and bytes transfered
169 * at the expense of some speed
171 int file_op_compute_totals
= 1;
173 /*** file scope macro definitions ****************************************************************/
175 /* In order to use everywhere the same setup for the locale we use defines */
176 #define FMTYEAR _("%b %e %Y")
177 #define FMTTIME _("%b %e %H:%M")
179 /*** file scope type declarations ****************************************************************/
181 /*** file scope variables ************************************************************************/
183 static char *panels_profile_name
= NULL
; /* ${XDG_CACHE_HOME}/mc/panels.ini */
191 { "full", list_full
},
192 { "brief", list_brief
},
193 { "long", list_long
},
194 { "user", list_user
},
200 const char *opt_name
;
201 panel_view_mode_t opt_type
;
203 { "listing", view_listing
},
204 { "quickview", view_quick
},
205 { "info", view_info
},
206 { "tree", view_tree
},
207 { NULL
, view_listing
}
212 const char *opt_name
;
215 { "equal_split", &equal_split
},
216 { "first_panel_size", &first_panel_size
},
217 { "message_visible", &mc_global
.message_visible
},
218 { "keybar_visible", &mc_global
.keybar_visible
},
219 { "xterm_title", &xterm_title
},
220 { "output_lines", &output_lines
},
221 { "command_prompt", &command_prompt
},
222 { "menubar_visible", &menubar_visible
},
223 { "free_space", &free_space
},
229 const char *opt_name
;
232 { "verbose", &verbose
},
233 { "pause_after_run", &pause_after_run
},
234 { "shell_patterns", &easy_patterns
},
235 { "auto_save_setup", &auto_save_setup
},
236 { "auto_menu", &auto_menu
},
237 { "use_internal_view", &use_internal_view
},
238 { "use_internal_edit", &use_internal_edit
},
239 { "clear_before_exec", &clear_before_exec
},
240 { "confirm_delete", &confirm_delete
},
241 { "confirm_overwrite", &confirm_overwrite
},
242 { "confirm_execute", &confirm_execute
},
243 { "confirm_history_cleanup", &mc_global
.widget
.confirm_history_cleanup
},
244 { "confirm_exit", &confirm_exit
},
245 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete
},
246 { "safe_delete", &safe_delete
},
247 { "mouse_repeat_rate", &mou_auto_repeat
},
248 { "double_click_speed", &double_click_speed
},
250 { "eight_bit_clean", &mc_global
.eight_bit_clean
},
251 { "full_eight_bits", &mc_global
.full_eight_bits
},
252 #endif /* !HAVE_CHARSET */
253 { "use_8th_bit_as_meta", &use_8th_bit_as_meta
},
254 { "confirm_view_dir", &confirm_view_dir
},
255 { "mouse_move_pages_viewer", &mcview_mouse_move_pages
},
256 { "mouse_close_dialog", &mouse_close_dialog
},
257 { "fast_refresh", &fast_refresh
},
258 { "drop_menus", &drop_menus
},
259 { "wrap_mode", &mcview_global_wrap_mode
},
260 { "old_esc_mode", &old_esc_mode
},
261 { "old_esc_mode_timeout", &old_esc_mode_timeout
},
262 { "cd_symlinks", &mc_global
.vfs
.cd_symlinks
},
263 { "show_all_if_ambiguous", &mc_global
.widget
.show_all_if_ambiguous
},
264 { "max_dirt_limit", &mcview_max_dirt_limit
},
265 { "use_file_to_guess_type", &use_file_to_check_type
},
266 { "alternate_plus_minus", &mc_global
.tty
.alternate_plus_minus
},
267 { "only_leading_plus_minus", &only_leading_plus_minus
},
268 { "show_output_starts_shell", &output_starts_shell
},
269 { "xtree_mode", &xtree_mode
},
270 { "num_history_items_recorded", &num_history_items_recorded
},
271 { "file_op_compute_totals", &file_op_compute_totals
},
272 { "classic_progressbar", &classic_progressbar
},
274 { "vfs_timeout", &vfs_timeout
},
275 #ifdef ENABLE_VFS_FTP
276 { "ftpfs_directory_timeout", &ftpfs_directory_timeout
},
277 { "use_netrc", &ftpfs_use_netrc
},
278 { "ftpfs_retry_seconds", &ftpfs_retry_seconds
},
279 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy
},
280 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections
},
281 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy
},
282 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options
},
283 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls
},
284 #endif /* ENABLE_VFS_FTP */
285 #ifdef ENABLE_VFS_FISH
286 { "fish_directory_timeout", &fish_directory_timeout
},
287 #endif /* ENABLE_VFS_FISH */
288 #endif /* ENABLE_VFS */
289 /* option_tab_spacing is used in internal viewer */
290 { "editor_tab_spacing", &option_tab_spacing
},
291 #ifdef USE_INTERNAL_EDIT
292 { "editor_word_wrap_line_length", &option_word_wrap_line_length
},
293 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces
},
294 { "editor_return_does_auto_indent", &option_return_does_auto_indent
},
295 { "editor_backspace_through_tabs", &option_backspace_through_tabs
},
296 { "editor_fake_half_tabs", &option_fake_half_tabs
},
297 { "editor_option_save_mode", &option_save_mode
},
298 { "editor_option_save_position", &option_save_position
},
299 { "editor_option_auto_para_formatting", &option_auto_para_formatting
},
300 { "editor_option_typewriter_wrap", &option_typewriter_wrap
},
301 { "editor_edit_confirm_save", &edit_confirm_save
},
302 { "editor_syntax_highlighting", &option_syntax_highlighting
},
303 { "editor_persistent_selections", &option_persistent_selections
},
304 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol
},
305 { "editor_visible_tabs", &visible_tabs
},
306 { "editor_visible_spaces", &visible_tws
},
307 { "editor_line_state", &option_line_state
},
308 { "editor_simple_statusbar", &simple_statusbar
},
309 { "editor_check_new_line", &option_check_nl_at_eof
},
310 { "editor_show_right_margin", &show_right_margin
},
311 { "editor_group_undo", &option_group_undo
},
312 #endif /* USE_INTERNAL_EDIT */
313 { "nice_rotating_dash", &nice_rotating_dash
},
314 { "horizontal_split", &horizontal_split
},
315 { "mcview_remember_file_position", &mcview_remember_file_position
},
316 { "auto_fill_mkdir_name", &auto_fill_mkdir_name
},
317 { "copymove_persistent_attr", &setup_copymove_persistent_attr
},
318 { "select_flags", &select_flags
},
324 const char *opt_name
;
326 const char *opt_defval
;
328 #ifdef USE_INTERNAL_EDIT
329 { "editor_backup_extension", &option_backup_ext
, "~" },
331 { "mcview_eof", &mcview_show_eof
, "" },
337 const char *opt_name
;
339 } panels_ini_options
[] = {
340 { "show_mini_info", &panels_options
.show_mini_info
},
341 { "kilobyte_si", &panels_options
.kilobyte_si
},
342 { "mix_all_files", &panels_options
.mix_all_files
},
343 { "show_backups", &panels_options
.show_backups
},
344 { "show_dot_files", &panels_options
.show_dot_files
},
345 { "fast_reload", &panels_options
.fast_reload
},
346 { "fast_reload_msg_shown", &panels_options
.fast_reload_msg_shown
},
347 { "mark_moves_down", &panels_options
.mark_moves_down
},
348 { "reverse_files_only", &panels_options
.reverse_files_only
},
349 { "auto_save_setup_panels", &panels_options
.auto_save_setup
},
350 { "navigate_with_arrows", &panels_options
.navigate_with_arrows
},
351 { "panel_scroll_pages", &panels_options
.scroll_pages
},
352 { "mouse_move_pages", &panels_options
.mouse_move_pages
},
353 { "filetype_mode", &panels_options
.filetype_mode
},
354 { "permission_mode", &panels_options
.permission_mode
},
355 { "torben_fj_mode", &panels_options
.torben_fj_mode
},
360 /*** file scope functions ************************************************************************/
361 /* --------------------------------------------------------------------------------------------- */
364 Get name of config file.
367 if not NULL, then config also search into specified subdir.
369 \param config_file_name
370 If specified filename is relative, then will search in standart patches.
373 Newly allocated path to config name or NULL if file not found.
375 If config_file_name is a relative path, then search config in stantart paths.
378 load_setup_get_full_config_name (const char *subdir
, const char *config_file_name
)
381 TODO: IMHO, in future this function must be placed into mc_config module.
383 char *lc_basename
, *ret
;
385 if (config_file_name
== NULL
)
388 if (g_path_is_absolute (config_file_name
))
389 return g_strdup (config_file_name
);
392 lc_basename
= g_path_get_basename (config_file_name
);
393 if (lc_basename
== NULL
)
397 ret
= g_build_filename (mc_config_get_path (), subdir
, lc_basename
, NULL
);
399 ret
= g_build_filename (mc_config_get_path (), lc_basename
, NULL
);
401 if (exist_file (ret
))
403 g_free (lc_basename
);
409 ret
= g_build_filename (mc_global
.sysconfig_dir
, subdir
, lc_basename
, NULL
);
411 ret
= g_build_filename (mc_global
.sysconfig_dir
, lc_basename
, NULL
);
413 if (exist_file (ret
))
415 g_free (lc_basename
);
421 ret
= g_build_filename (mc_global
.share_data_dir
, subdir
, lc_basename
, NULL
);
423 ret
= g_build_filename (mc_global
.share_data_dir
, lc_basename
, NULL
);
425 g_free (lc_basename
);
427 if (exist_file (ret
))
435 /* --------------------------------------------------------------------------------------------- */
438 setup__is_cfg_group_must_panel_config (const char *grp
)
440 return (!strcasecmp ("Dirs", grp
) ||
441 !strcasecmp ("Temporal:New Right Panel", grp
) ||
442 !strcasecmp ("Temporal:New Left Panel", grp
) ||
443 !strcasecmp ("New Left Panel", grp
) || !strcasecmp ("New Right Panel", grp
))
447 /* --------------------------------------------------------------------------------------------- */
450 setup__move_panels_config_into_separate_file (const char *profile
)
452 mc_config_t
*tmp_cfg
;
453 char **groups
, **curr_grp
;
454 const char *need_grp
;
456 if (!exist_file (profile
))
459 tmp_cfg
= mc_config_init (profile
);
463 curr_grp
= groups
= mc_config_get_groups (tmp_cfg
, NULL
);
466 mc_config_deinit (tmp_cfg
);
472 if (setup__is_cfg_group_must_panel_config (*curr_grp
) == NULL
)
473 mc_config_del_group (tmp_cfg
, *curr_grp
);
477 mc_config_save_to_file (tmp_cfg
, panels_profile_name
, NULL
);
478 mc_config_deinit (tmp_cfg
);
480 tmp_cfg
= mc_config_init (profile
);
491 need_grp
= setup__is_cfg_group_must_panel_config (*curr_grp
);
492 if (need_grp
!= NULL
)
494 mc_config_del_group (tmp_cfg
, need_grp
);
500 mc_config_save_file (tmp_cfg
, NULL
);
501 mc_config_deinit (tmp_cfg
);
504 /* --------------------------------------------------------------------------------------------- */
506 Create new mc_config object from specified ini-file or
507 append data to existing mc_config object from ini-file
511 load_setup_init_config_from_file (mc_config_t
** config
, const char *fname
)
514 TODO: IMHO, in future this function must be placed into mc_config module.
516 if (exist_file (fname
))
519 mc_config_read_file (*config
, fname
, TRUE
);
521 *config
= mc_config_init (fname
);
525 /* --------------------------------------------------------------------------------------------- */
532 for (i
= 0; layout
[i
].opt_name
!= NULL
; i
++)
533 *layout
[i
].opt_addr
= mc_config_get_int (mc_main_config
, "Layout",
534 layout
[i
].opt_name
, *layout
[i
].opt_addr
);
537 /* --------------------------------------------------------------------------------------------- */
540 load_keys_from_section (const char *terminal
, mc_config_t
* cfg
)
543 gchar
**profile_keys
, **keys
;
544 gchar
**values
, **curr_values
;
545 char *valcopy
, *value
;
547 gsize len
, values_len
;
549 if (terminal
== NULL
)
552 section_name
= g_strconcat ("terminal:", terminal
, (char *) NULL
);
553 profile_keys
= keys
= mc_config_get_keys (cfg
, section_name
, &len
);
555 while (*profile_keys
!= NULL
)
557 /* copy=other causes all keys from [terminal:other] to be loaded. */
558 if (g_ascii_strcasecmp (*profile_keys
, "copy") == 0)
560 valcopy
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
561 load_keys_from_section (valcopy
, cfg
);
567 curr_values
= values
=
568 mc_config_get_string_list (cfg
, section_name
, *profile_keys
, &values_len
);
570 key_code
= lookup_key (*profile_keys
, NULL
);
574 if (curr_values
!= NULL
)
576 while (*curr_values
!= NULL
)
578 valcopy
= convert_controls (*curr_values
);
579 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
586 value
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
587 valcopy
= convert_controls (value
);
588 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
598 g_free (section_name
);
601 /* --------------------------------------------------------------------------------------------- */
604 load_keymap_from_section (const char *section_name
, GArray
* keymap
, mc_config_t
* cfg
)
606 gchar
**profile_keys
, **keys
;
607 gchar
**values
, **curr_values
;
608 char *valcopy
, *value
;
610 gsize len
, values_len
;
612 if (section_name
== NULL
)
615 profile_keys
= keys
= mc_config_get_keys (cfg
, section_name
, &len
);
617 while (*profile_keys
!= NULL
)
619 curr_values
= values
=
620 mc_config_get_string_list (cfg
, section_name
, *profile_keys
, &values_len
);
622 action
= keybind_lookup_action (*profile_keys
);
626 if (curr_values
!= NULL
)
628 while (*curr_values
!= NULL
)
630 valcopy
= convert_controls (*curr_values
);
631 keybind_cmd_bind (keymap
, valcopy
, action
);
638 value
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
639 valcopy
= convert_controls (value
);
640 /* define_sequence (key_code, valcopy, MCKEY_NOACTION); */
652 /* --------------------------------------------------------------------------------------------- */
655 load_setup_get_keymap_profile_config (gboolean load_from_file
)
658 TODO: IMHO, in future this function must be placed into mc_config module.
660 mc_config_t
*keymap_config
;
661 char *fname
, *fname2
;
663 /* 0) Create default keymap */
664 keymap_config
= create_default_keymap ();
666 return keymap_config
;
668 /* 1) /usr/share/mc (mc_global.share_data_dir) */
669 fname
= g_build_filename (mc_global
.share_data_dir
, GLOBAL_KEYMAP_FILE
, NULL
);
670 load_setup_init_config_from_file (&keymap_config
, fname
);
673 /* 2) /etc/mc (mc_global.sysconfig_dir) */
674 fname
= g_build_filename (mc_global
.sysconfig_dir
, GLOBAL_KEYMAP_FILE
, NULL
);
675 load_setup_init_config_from_file (&keymap_config
, fname
);
678 /* 3) ${XDG_CONFIG_HOME}/mc */
679 fname
= g_build_filename (mc_config_get_path (), GLOBAL_KEYMAP_FILE
, NULL
);
680 load_setup_init_config_from_file (&keymap_config
, fname
);
683 /* 4) main config; [Midnight Commander] -> keymap */
685 mc_config_get_string (mc_main_config
, CONFIG_APP_SECTION
, "keymap", GLOBAL_KEYMAP_FILE
);
686 fname
= load_setup_get_full_config_name (NULL
, fname2
);
689 load_setup_init_config_from_file (&keymap_config
, fname
);
694 /* 5) getenv("MC_KEYMAP") */
695 fname
= load_setup_get_full_config_name (NULL
, g_getenv ("MC_KEYMAP"));
698 load_setup_init_config_from_file (&keymap_config
, fname
);
702 /* 6) --keymap=<keymap> */
703 fname
= load_setup_get_full_config_name (NULL
, mc_args__keymap_file
);
706 load_setup_init_config_from_file (&keymap_config
, fname
);
710 return keymap_config
;
713 /* --------------------------------------------------------------------------------------------- */
715 static panel_view_mode_t
716 setup__load_panel_state (const char *section
)
720 panel_view_mode_t mode
= view_listing
;
722 /* Load the display mode */
723 buffer
= mc_config_get_string (mc_panels_config
, section
, "display", "listing");
725 for (i
= 0; panel_types
[i
].opt_name
!= NULL
; i
++)
726 if (g_ascii_strcasecmp (panel_types
[i
].opt_name
, buffer
) == 0)
728 mode
= panel_types
[i
].opt_type
;
737 /* --------------------------------------------------------------------------------------------- */
740 panel_save_type (const char *section
, panel_view_mode_t type
)
744 for (i
= 0; panel_types
[i
].opt_name
!= NULL
; i
++)
745 if (panel_types
[i
].opt_type
== type
)
747 mc_config_set_string (mc_panels_config
, section
, "display", panel_types
[i
].opt_name
);
752 /* --------------------------------------------------------------------------------------------- */
754 /* save panels.ini */
756 save_panel_types (void)
758 panel_view_mode_t type
;
760 if (mc_global
.mc_run_mode
!= MC_RUN_FULL
)
763 type
= get_display_type (0);
764 panel_save_type ("New Left Panel", type
);
765 if (type
== view_listing
)
766 panel_save_setup (left_panel
, left_panel
->panel_name
);
767 type
= get_display_type (1);
768 panel_save_type ("New Right Panel", type
);
769 if (type
== view_listing
)
770 panel_save_setup (right_panel
, right_panel
->panel_name
);
772 mc_config_set_string (mc_panels_config
, "Dirs", "other_dir", get_panel_dir_for (other_panel
));
774 if (current_panel
!= NULL
)
775 mc_config_set_string (mc_panels_config
, "Dirs", "current_is_left",
776 get_current_index () == 0 ? "1" : "0");
778 if (mc_panels_config
->ini_path
== NULL
)
779 mc_panels_config
->ini_path
= g_strdup (panels_profile_name
);
781 mc_config_del_group (mc_panels_config
, "Temporal:New Left Panel");
782 mc_config_del_group (mc_panels_config
, "Temporal:New Right Panel");
784 mc_config_save_file (mc_panels_config
, NULL
);
787 /* --------------------------------------------------------------------------------------------- */
788 /*** public functions ****************************************************************************/
789 /* --------------------------------------------------------------------------------------------- */
797 if (profile_name
!= NULL
)
800 profile
= g_build_filename (mc_config_get_path (), MC_CONFIG_FILE
, NULL
);
801 if (!exist_file (profile
))
803 inifile
= concat_dir_and_file (mc_global
.sysconfig_dir
, "mc.ini");
804 if (exist_file (inifile
))
812 inifile
= concat_dir_and_file (mc_global
.share_data_dir
, "mc.ini");
813 if (exist_file (inifile
))
823 profile_name
= profile
;
828 /* --------------------------------------------------------------------------------------------- */
839 load_codepages_list ();
840 #endif /* HAVE_CHARSET */
842 profile
= setup_init ();
844 /* mc.lib is common for all users, but has priority lower than
845 ${XDG_CONFIG_HOME}/mc/ini. FIXME: it's only used for keys and treestore now */
846 global_profile_name
=
847 g_build_filename (mc_global
.sysconfig_dir
, MC_GLOBAL_CONFIG_FILE
, (char *) NULL
);
848 if (!exist_file (global_profile_name
))
850 g_free (global_profile_name
);
851 global_profile_name
=
852 g_build_filename (mc_global
.share_data_dir
, MC_GLOBAL_CONFIG_FILE
, (char *) NULL
);
855 panels_profile_name
= g_build_filename (mc_config_get_cache_path (), MC_PANELS_FILE
, NULL
);
857 mc_main_config
= mc_config_init (profile
);
859 if (!exist_file (panels_profile_name
))
860 setup__move_panels_config_into_separate_file (profile
);
862 mc_panels_config
= mc_config_init (panels_profile_name
);
864 /* Load integer boolean options */
865 for (i
= 0; int_options
[i
].opt_name
!= NULL
; i
++)
866 *int_options
[i
].opt_addr
=
867 mc_config_get_int (mc_main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
,
868 *int_options
[i
].opt_addr
);
870 if (option_tab_spacing
<= 0)
871 option_tab_spacing
= DEFAULT_TAB_SPACING
;
873 #ifdef USE_INTERNAL_EDIT
874 if (option_word_wrap_line_length
<= 0)
875 option_word_wrap_line_length
= DEFAULT_WRAP_LINE_LENGTH
;
876 #endif /* USE_INTERNAL_EDIT */
878 /* overwrite old_esc_mode_timeout */
879 kt
= getenv ("KEYBOARD_KEY_TIMEOUT_US");
880 if ((kt
!= NULL
) && (kt
[0] != '\0'))
881 old_esc_mode_timeout
= atoi (kt
);
883 /* Load string options */
884 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
885 *str_options
[i
].opt_addr
=
886 mc_config_get_string (mc_main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
,
887 str_options
[i
].opt_defval
);
890 panels_load_options ();
893 startup_left_mode
= setup__load_panel_state ("New Left Panel");
894 startup_right_mode
= setup__load_panel_state ("New Right Panel");
896 /* At least one of the panels is a listing panel */
897 if (startup_left_mode
!= view_listing
&& startup_right_mode
!= view_listing
)
898 startup_left_mode
= view_listing
;
900 if (mc_run_param1
== NULL
)
903 buffer
= mc_config_get_string (mc_panels_config
, "Dirs", "other_dir", ".");
904 vpath
= vfs_path_from_str (buffer
);
905 if (vfs_file_is_local (vpath
))
906 mc_run_param1
= buffer
;
909 vfs_path_free (vpath
);
912 boot_current_is_left
= mc_config_get_bool (mc_panels_config
, "Dirs", "current_is_left", TRUE
);
914 /* Load time formats */
915 user_recent_timeformat
=
916 mc_config_get_string (mc_main_config
, "Misc", "timeformat_recent", FMTTIME
);
917 user_old_timeformat
= mc_config_get_string (mc_main_config
, "Misc", "timeformat_old", FMTYEAR
);
919 #ifdef ENABLE_VFS_FTP
920 ftpfs_proxy_host
= mc_config_get_string (mc_main_config
, "Misc", "ftp_proxy_host", "gate");
921 ftpfs_ignore_chattr_errors
= mc_config_get_bool (mc_main_config
, CONFIG_APP_SECTION
,
922 "ignore_ftp_chattr_errors", TRUE
);
923 ftpfs_init_passwd ();
924 #endif /* ENABLE_VFS_FTP */
926 /* The default color and the terminal dependent color */
927 mc_global
.tty
.setup_color_string
=
928 mc_config_get_string (mc_main_config
, "Colors", "base_color", "");
929 mc_global
.tty
.term_color_string
=
930 mc_config_get_string (mc_main_config
, "Colors", getenv ("TERM"), "");
931 mc_global
.tty
.color_terminal_string
=
932 mc_config_get_string (mc_main_config
, "Colors", "color_terminals", "");
934 /* Load the directory history */
935 /* directory_history_load (); */
936 /* Remove the temporal entries */
939 if (codepages
->len
> 1)
941 buffer
= mc_config_get_string (mc_main_config
, "Misc", "display_codepage", "");
942 if (buffer
[0] != '\0')
944 mc_global
.display_codepage
= get_codepage_index (buffer
);
945 cp_display
= get_codepage_id (mc_global
.display_codepage
);
948 buffer
= mc_config_get_string (mc_main_config
, "Misc", "source_codepage", "");
949 if (buffer
[0] != '\0')
951 default_source_codepage
= get_codepage_index (buffer
);
952 mc_global
.source_codepage
= default_source_codepage
; /* May be source_codepage doesn't need this */
953 cp_source
= get_codepage_id (mc_global
.source_codepage
);
958 autodetect_codeset
= mc_config_get_string (mc_main_config
, "Misc", "autodetect_codeset", "");
959 if ((autodetect_codeset
[0] != '\0') && (strcmp (autodetect_codeset
, "off") != 0))
960 is_autodetect_codeset_enabled
= TRUE
;
962 g_free (init_translation_table (mc_global
.source_codepage
, mc_global
.display_codepage
));
963 buffer
= (char *) get_codepage_id (mc_global
.display_codepage
);
965 mc_global
.utf8_display
= str_isutf8 (buffer
);
966 #endif /* HAVE_CHARSET */
968 clipboard_store_path
= mc_config_get_string (mc_main_config
, "Misc", "clipboard_store", "");
969 clipboard_paste_path
= mc_config_get_string (mc_main_config
, "Misc", "clipboard_paste", "");
972 /* --------------------------------------------------------------------------------------------- */
975 save_setup (gboolean save_options
, gboolean save_panel_options
)
983 if (save_panel_options
)
992 panels_save_options ();
994 /* directory_history_save (); */
996 #ifdef ENABLE_VFS_FTP
997 mc_config_set_string (mc_main_config
, "Misc", "ftpfs_password", ftpfs_anonymous_passwd
);
998 if (ftpfs_proxy_host
)
999 mc_config_set_string (mc_main_config
, "Misc", "ftp_proxy_host", ftpfs_proxy_host
);
1000 #endif /* ENABLE_VFS_FTP */
1003 mc_config_set_string (mc_main_config
, "Misc", "display_codepage",
1004 get_codepage_id (mc_global
.display_codepage
));
1005 mc_config_set_string (mc_main_config
, "Misc", "source_codepage",
1006 get_codepage_id (default_source_codepage
));
1007 mc_config_set_string (mc_main_config
, "Misc", "autodetect_codeset", autodetect_codeset
);
1008 #endif /* HAVE_CHARSET */
1009 mc_config_set_string (mc_main_config
, "Misc", "clipboard_store", clipboard_store_path
);
1010 mc_config_set_string (mc_main_config
, "Misc", "clipboard_paste", clipboard_paste_path
);
1012 tmp_profile
= g_build_filename (mc_config_get_path (), MC_CONFIG_FILE
, NULL
);
1013 ret
= mc_config_save_to_file (mc_main_config
, tmp_profile
, NULL
);
1014 g_free (tmp_profile
);
1022 /* --------------------------------------------------------------------------------------------- */
1029 g_free (clipboard_store_path
);
1030 g_free (clipboard_paste_path
);
1031 g_free (profile_name
);
1032 g_free (global_profile_name
);
1033 g_free (mc_global
.tty
.color_terminal_string
);
1034 g_free (mc_global
.tty
.term_color_string
);
1035 g_free (mc_global
.tty
.setup_color_string
);
1036 g_free (panels_profile_name
);
1037 mc_config_deinit (mc_main_config
);
1038 mc_config_deinit (mc_panels_config
);
1040 g_free (user_recent_timeformat
);
1041 g_free (user_old_timeformat
);
1043 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
1044 g_free (*str_options
[i
].opt_addr
);
1048 /* directory_history_free (); */
1051 g_free (autodetect_codeset
);
1052 free_codepages_list ();
1056 /* --------------------------------------------------------------------------------------------- */
1063 /* Save integer options */
1064 for (i
= 0; int_options
[i
].opt_name
!= NULL
; i
++)
1065 mc_config_set_int (mc_main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
,
1066 *int_options
[i
].opt_addr
);
1068 /* Save string options */
1069 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
1070 mc_config_set_string (mc_main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
,
1071 *str_options
[i
].opt_addr
);
1074 /* --------------------------------------------------------------------------------------------- */
1077 setup_save_config_show_error (const char *filename
, GError
** error
)
1079 if (error
!= NULL
&& *error
!= NULL
)
1081 message (D_ERROR
, MSG_ERROR
, _("Cannot save file %s:\n%s"), filename
, (*error
)->message
);
1082 g_error_free (*error
);
1087 /* --------------------------------------------------------------------------------------------- */
1094 /* Save integer options */
1095 for (i
= 0; layout
[i
].opt_name
!= NULL
; i
++)
1096 mc_config_set_int (mc_main_config
, "Layout", layout
[i
].opt_name
, *layout
[i
].opt_addr
);
1099 /* --------------------------------------------------------------------------------------------- */
1102 load_key_defs (void)
1105 * Load keys from mc.lib before ${XDG_CONFIG_HOME}/mc/ini, so that the user
1106 * definitions override global settings.
1108 mc_config_t
*mc_global_config
;
1110 mc_global_config
= mc_config_init (global_profile_name
);
1111 if (mc_global_config
!= NULL
)
1113 load_keys_from_section ("general", mc_global_config
);
1114 load_keys_from_section (getenv ("TERM"), mc_global_config
);
1115 mc_config_deinit (mc_global_config
);
1118 load_keys_from_section ("general", mc_main_config
);
1119 load_keys_from_section (getenv ("TERM"), mc_main_config
);
1122 /* --------------------------------------------------------------------------------------------- */
1124 #ifdef ENABLE_VFS_FTP
1126 load_anon_passwd (void)
1130 buffer
= mc_config_get_string (mc_main_config
, "Misc", "ftpfs_password", "");
1132 if ((buffer
!= NULL
) && (buffer
[0] != '\0'))
1138 #endif /* ENABLE_VFS_FTP */
1140 /* --------------------------------------------------------------------------------------------- */
1143 load_keymap_defs (gboolean load_from_file
)
1146 * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_DATA_HOME}/mc/keymap, so that the user
1147 * definitions override global settings.
1149 mc_config_t
*mc_global_keymap
;
1151 mc_global_keymap
= load_setup_get_keymap_profile_config (load_from_file
);
1153 if (mc_global_keymap
!= NULL
)
1155 main_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1156 load_keymap_from_section (KEYMAP_SECTION_MAIN
, main_keymap
, mc_global_keymap
);
1157 main_x_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1158 load_keymap_from_section (KEYMAP_SECTION_MAIN_EXT
, main_x_keymap
, mc_global_keymap
);
1160 panel_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1161 load_keymap_from_section (KEYMAP_SECTION_PANEL
, panel_keymap
, mc_global_keymap
);
1163 dialog_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1164 load_keymap_from_section (KEYMAP_SECTION_DIALOG
, dialog_keymap
, mc_global_keymap
);
1166 input_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1167 load_keymap_from_section (KEYMAP_SECTION_INPUT
, input_keymap
, mc_global_keymap
);
1169 listbox_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1170 load_keymap_from_section (KEYMAP_SECTION_LISTBOX
, listbox_keymap
, mc_global_keymap
);
1172 tree_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1173 load_keymap_from_section (KEYMAP_SECTION_TREE
, tree_keymap
, mc_global_keymap
);
1175 help_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1176 load_keymap_from_section (KEYMAP_SECTION_HELP
, help_keymap
, mc_global_keymap
);
1178 #ifdef USE_INTERNAL_EDIT
1179 editor_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1180 load_keymap_from_section (KEYMAP_SECTION_EDITOR
, editor_keymap
, mc_global_keymap
);
1181 editor_x_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1182 load_keymap_from_section (KEYMAP_SECTION_EDITOR_EXT
, editor_x_keymap
, mc_global_keymap
);
1185 viewer_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1186 load_keymap_from_section (KEYMAP_SECTION_VIEWER
, viewer_keymap
, mc_global_keymap
);
1187 viewer_hex_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1188 load_keymap_from_section (KEYMAP_SECTION_VIEWER_HEX
, viewer_hex_keymap
, mc_global_keymap
);
1190 #ifdef USE_DIFF_VIEW
1191 diff_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1192 load_keymap_from_section (KEYMAP_SECTION_DIFFVIEWER
, diff_keymap
, mc_global_keymap
);
1195 mc_config_deinit (mc_global_keymap
);
1198 main_map
= (global_keymap_t
*) main_keymap
->data
;
1199 main_x_map
= (global_keymap_t
*) main_x_keymap
->data
;
1200 panel_map
= (global_keymap_t
*) panel_keymap
->data
;
1201 dialog_map
= (global_keymap_t
*) dialog_keymap
->data
;
1202 input_map
= (global_keymap_t
*) input_keymap
->data
;
1203 listbox_map
= (global_keymap_t
*) listbox_keymap
->data
;
1204 tree_map
= (global_keymap_t
*) tree_keymap
->data
;
1205 help_map
= (global_keymap_t
*) help_keymap
->data
;
1206 #ifdef USE_INTERNAL_EDIT
1207 editor_map
= (global_keymap_t
*) editor_keymap
->data
;
1208 editor_x_map
= (global_keymap_t
*) editor_x_keymap
->data
;
1210 viewer_map
= (global_keymap_t
*) viewer_keymap
->data
;
1211 viewer_hex_map
= (global_keymap_t
*) viewer_hex_keymap
->data
;
1212 #ifdef USE_DIFF_VIEW
1213 diff_map
= (global_keymap_t
*) diff_keymap
->data
;
1217 /* --------------------------------------------------------------------------------------------- */
1220 free_keymap_defs (void)
1222 if (main_keymap
!= NULL
)
1223 g_array_free (main_keymap
, TRUE
);
1224 if (main_x_keymap
!= NULL
)
1225 g_array_free (main_x_keymap
, TRUE
);
1226 if (panel_keymap
!= NULL
)
1227 g_array_free (panel_keymap
, TRUE
);
1228 if (dialog_keymap
!= NULL
)
1229 g_array_free (dialog_keymap
, TRUE
);
1230 if (input_keymap
!= NULL
)
1231 g_array_free (input_keymap
, TRUE
);
1232 if (listbox_keymap
!= NULL
)
1233 g_array_free (listbox_keymap
, TRUE
);
1234 if (tree_keymap
!= NULL
)
1235 g_array_free (tree_keymap
, TRUE
);
1236 if (help_keymap
!= NULL
)
1237 g_array_free (help_keymap
, TRUE
);
1238 #ifdef USE_INTERNAL_EDIT
1239 if (editor_keymap
!= NULL
)
1240 g_array_free (editor_keymap
, TRUE
);
1241 if (editor_x_keymap
!= NULL
)
1242 g_array_free (editor_x_keymap
, TRUE
);
1244 if (viewer_keymap
!= NULL
)
1245 g_array_free (viewer_keymap
, TRUE
);
1246 if (viewer_hex_keymap
!= NULL
)
1247 g_array_free (viewer_hex_keymap
, TRUE
);
1248 #ifdef USE_DIFF_VIEW
1249 if (diff_keymap
!= NULL
)
1250 g_array_free (diff_keymap
, TRUE
);
1254 /* --------------------------------------------------------------------------------------------- */
1257 panel_load_setup (WPanel
* panel
, const char *section
)
1260 char *buffer
, buffer2
[BUF_TINY
];
1262 panel
->sort_info
.reverse
= mc_config_get_int (mc_panels_config
, section
, "reverse", 0);
1263 panel
->sort_info
.case_sensitive
=
1264 mc_config_get_int (mc_panels_config
, section
, "case_sensitive",
1265 OS_SORT_CASE_SENSITIVE_DEFAULT
);
1266 panel
->sort_info
.exec_first
= mc_config_get_int (mc_panels_config
, section
, "exec_first", 0);
1268 /* Load sort order */
1269 buffer
= mc_config_get_string (mc_panels_config
, section
, "sort_order", "name");
1270 panel
->sort_info
.sort_field
= panel_get_field_by_id (buffer
);
1271 if (panel
->sort_info
.sort_field
== NULL
)
1272 panel
->sort_info
.sort_field
= panel_get_field_by_id ("name");
1276 /* Load the listing mode */
1277 buffer
= mc_config_get_string (mc_panels_config
, section
, "list_mode", "full");
1278 panel
->list_type
= list_full
;
1279 for (i
= 0; list_types
[i
].key
!= NULL
; i
++)
1280 if (g_ascii_strcasecmp (list_types
[i
].key
, buffer
) == 0)
1282 panel
->list_type
= list_types
[i
].list_type
;
1288 g_free (panel
->user_format
);
1289 panel
->user_format
=
1290 mc_config_get_string (mc_panels_config
, section
, "user_format", DEFAULT_USER_FORMAT
);
1292 for (i
= 0; i
< LIST_TYPES
; i
++)
1294 g_free (panel
->user_status_format
[i
]);
1295 g_snprintf (buffer2
, BUF_TINY
, "user_status%lld", (long long) i
);
1296 panel
->user_status_format
[i
] =
1297 mc_config_get_string (mc_panels_config
, section
, buffer2
, DEFAULT_USER_FORMAT
);
1300 panel
->user_mini_status
= mc_config_get_int (mc_panels_config
, section
, "user_mini_status", 0);
1303 /* --------------------------------------------------------------------------------------------- */
1306 panel_save_setup (struct WPanel
*panel
, const char *section
)
1308 char buffer
[BUF_TINY
];
1311 mc_config_set_int (mc_panels_config
, section
, "reverse", panel
->sort_info
.reverse
);
1312 mc_config_set_int (mc_panels_config
, section
, "case_sensitive",
1313 panel
->sort_info
.case_sensitive
);
1314 mc_config_set_int (mc_panels_config
, section
, "exec_first", panel
->sort_info
.exec_first
);
1316 mc_config_set_string (mc_panels_config
, section
, "sort_order", panel
->sort_info
.sort_field
->id
);
1318 for (i
= 0; list_types
[i
].key
!= NULL
; i
++)
1319 if (list_types
[i
].list_type
== panel
->list_type
)
1321 mc_config_set_string (mc_panels_config
, section
, "list_mode", list_types
[i
].key
);
1325 mc_config_set_string (mc_panels_config
, section
, "user_format", panel
->user_format
);
1327 for (i
= 0; i
< LIST_TYPES
; i
++)
1329 g_snprintf (buffer
, BUF_TINY
, "user_status%lld", (long long) i
);
1330 mc_config_set_string (mc_panels_config
, section
, buffer
, panel
->user_status_format
[i
]);
1333 mc_config_set_int (mc_panels_config
, section
, "user_mini_status", panel
->user_mini_status
);
1336 /* --------------------------------------------------------------------------------------------- */
1339 Load panels options from [Panels] section.
1342 panels_load_options (void)
1344 if (mc_config_has_group (mc_main_config
, CONFIG_PANELS_SECTION
))
1349 for (i
= 0; panels_ini_options
[i
].opt_name
!= NULL
; i
++)
1350 *panels_ini_options
[i
].opt_addr
=
1351 mc_config_get_bool (mc_main_config
, CONFIG_PANELS_SECTION
,
1352 panels_ini_options
[i
].opt_name
,
1353 *panels_ini_options
[i
].opt_addr
);
1355 qmode
= mc_config_get_int (mc_main_config
, CONFIG_PANELS_SECTION
,
1356 "quick_search_mode", (int) panels_options
.qsearch_mode
);
1358 panels_options
.qsearch_mode
= QSEARCH_CASE_INSENSITIVE
;
1359 else if (qmode
>= QSEARCH_NUM
)
1360 panels_options
.qsearch_mode
= QSEARCH_PANEL_CASE
;
1362 panels_options
.qsearch_mode
= (qsearch_mode_t
) qmode
;
1366 /* --------------------------------------------------------------------------------------------- */
1369 Save panels options in [Panels] section.
1372 panels_save_options (void)
1376 for (i
= 0; panels_ini_options
[i
].opt_name
!= NULL
; i
++)
1377 mc_config_set_bool (mc_main_config
, CONFIG_PANELS_SECTION
,
1378 panels_ini_options
[i
].opt_name
, *panels_ini_options
[i
].opt_addr
);
1380 mc_config_set_int (mc_main_config
, CONFIG_PANELS_SECTION
,
1381 "quick_search_mode", (int) panels_options
.qsearch_mode
);
1384 /* --------------------------------------------------------------------------------------------- */