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/vfs/mc-vfs/vfs.h"
42 #include "lib/vfs/mc-vfs/ftpfs.h"
44 #ifdef ENABLE_VFS_FISH
45 #include "lib/vfs/mc-vfs/fish.h"
49 #include "lib/widget.h"
51 #include "lib/charsets.h"
57 #include "tree.h" /* xtree_mode */
58 #include "hotlist.h" /* load/save/done hotlist */
59 #include "panelize.h" /* load/save/done panelize */
62 #include "execute.h" /* pause_after_run */
63 #include "clipboard.h"
64 #include "keybind-defaults.h" /* keybind_lookup_action */
67 #include "selcodepage.h"
70 #ifdef USE_INTERNAL_EDIT
71 #include "src/editor/edit.h"
74 #include "src/viewer/mcviewer.h" /* For the externs */
78 /*** global variables ****************************************************************************/
80 char *profile_name
; /* .mc/ini */
81 char *global_profile_name
; /* mc.lib */
83 /* Only used at program boot */
84 gboolean boot_current_is_left
= TRUE
;
86 char *setup_color_string
;
87 char *term_color_string
;
88 char *color_terminal_string
;
90 /* If on, default for "No" in delete operations */
93 /* Controls screen clearing before an exec */
94 int clear_before_exec
= 1;
96 /* Asks for confirmation before deleting a file */
97 int confirm_delete
= 1;
98 /* Asks for confirmation before deleting a hotlist entry */
99 int confirm_directory_hotlist_delete
= 1;
100 /* Asks for confirmation before overwriting a file */
101 int confirm_overwrite
= 1;
102 /* Asks for confirmation before executing a program by pressing enter */
103 int confirm_execute
= 0;
104 /* Asks for confirmation before leaving the program */
105 int confirm_exit
= 1;
106 /* Asks for confirmation before clean up of history */
107 int confirm_history_cleanup
= 1;
109 /* If true, at startup the user-menu is invoked */
111 /* This flag indicates if the pull down menus by default drop down */
114 /* Asks for confirmation when using F3 to view a directory and there
116 int confirm_view_dir
= 0;
118 panel_view_mode_t startup_left_mode
;
119 panel_view_mode_t startup_right_mode
;
121 int setup_copymove_persistent_attr
= 1;
124 int option_tab_spacing
= DEFAULT_TAB_SPACING
;
126 /* Ugly hack to allow panel_save_setup to work as a place holder for */
127 /* default panel values */
130 panels_options_t panels_options
= {
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 .mouse_move_pages
= TRUE
,
143 .filetype_mode
= TRUE
,
144 .permission_mode
= FALSE
,
145 .qsearch_mode
= QSEARCH_PANEL_CASE
148 int easy_patterns
= 1;
150 /* It true saves the setup when quitting */
151 int auto_save_setup
= 1;
153 /* If true, then the +, - and \ keys have their special meaning only if the
154 * command line is emtpy, otherwise they behave like regular letters
156 int only_leading_plus_minus
= 1;
158 /* Set when cd symlink following is desirable (bash mode) */
161 /* Set if you want the possible completions dialog for the first time */
162 int show_all_if_ambiguous
= 0;
164 /* Automatically fills name with current selected item name on mkdir */
165 int auto_fill_mkdir_name
= 1;
167 /* If set and you don't have subshell support,then C-o will give you a shell */
168 int output_starts_shell
= 0;
170 /* If set, we execute the file command to check the file type */
171 int use_file_to_check_type
= 1;
176 * Whether the Midnight Commander tries to provide more
177 * information about copy/move sizes and bytes transfered
178 * at the expense of some speed
180 int file_op_compute_totals
= 1;
182 /*** file scope macro definitions ****************************************************************/
184 /* In order to use everywhere the same setup for the locale we use defines */
185 #define FMTYEAR _("%b %e %Y")
186 #define FMTTIME _("%b %e %H:%M")
188 /*** file scope type declarations ****************************************************************/
190 /*** file scope variables ************************************************************************/
192 static char *panels_profile_name
= NULL
; /* .mc/panels.ini */
200 { "full", list_full
},
201 { "brief", list_brief
},
202 { "long", list_long
},
203 { "user", list_user
},
209 const char *opt_name
;
210 panel_view_mode_t opt_type
;
212 { "listing", view_listing
},
213 { "quickview", view_quick
},
214 { "info", view_info
},
215 { "tree", view_tree
},
216 { NULL
, view_listing
}
221 const char *opt_name
;
224 { "equal_split", &equal_split
},
225 { "first_panel_size", &first_panel_size
},
226 { "message_visible", &message_visible
},
227 { "keybar_visible", &keybar_visible
},
228 { "xterm_title", &xterm_title
},
229 { "output_lines", &output_lines
},
230 { "command_prompt", &command_prompt
},
231 { "menubar_visible", &menubar_visible
},
232 { "show_mini_info", &show_mini_info
},
233 { "free_space", &free_space
},
239 const char *opt_name
;
242 { "verbose", &verbose
},
243 { "pause_after_run", &pause_after_run
},
244 { "shell_patterns", &easy_patterns
},
245 { "auto_save_setup", &auto_save_setup
},
246 { "auto_menu", &auto_menu
},
247 { "use_internal_view", &use_internal_view
},
248 { "use_internal_edit", &use_internal_edit
},
249 { "clear_before_exec", &clear_before_exec
},
250 { "confirm_delete", &confirm_delete
},
251 { "confirm_overwrite", &confirm_overwrite
},
252 { "confirm_execute", &confirm_execute
},
253 { "confirm_history_cleanup", &confirm_history_cleanup
},
254 { "confirm_exit", &confirm_exit
},
255 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete
},
256 { "safe_delete", &safe_delete
},
257 { "mouse_repeat_rate", &mou_auto_repeat
},
258 { "double_click_speed", &double_click_speed
},
260 { "eight_bit_clean", &eight_bit_clean
},
261 { "full_eight_bits", &full_eight_bits
},
262 #endif /* !HAVE_CHARSET */
263 { "use_8th_bit_as_meta", &use_8th_bit_as_meta
},
264 { "confirm_view_dir", &confirm_view_dir
},
265 { "mouse_move_pages_viewer", &mcview_mouse_move_pages
},
266 { "mouse_close_dialog", &mouse_close_dialog
},
267 { "fast_refresh", &fast_refresh
},
268 { "drop_menus", &drop_menus
},
269 { "wrap_mode", &mcview_global_wrap_mode
},
270 { "old_esc_mode", &old_esc_mode
},
271 { "old_esc_mode_timeout", &old_esc_mode_timeout
},
272 { "cd_symlinks", &cd_symlinks
},
273 { "show_all_if_ambiguous", &show_all_if_ambiguous
},
274 { "max_dirt_limit", &mcview_max_dirt_limit
},
275 { "torben_fj_mode", &torben_fj_mode
},
276 { "use_file_to_guess_type", &use_file_to_check_type
},
277 { "alternate_plus_minus", &alternate_plus_minus
},
278 { "only_leading_plus_minus", &only_leading_plus_minus
},
279 { "show_output_starts_shell", &output_starts_shell
},
280 { "xtree_mode", &xtree_mode
},
281 { "num_history_items_recorded", &num_history_items_recorded
},
282 { "file_op_compute_totals", &file_op_compute_totals
},
283 { "classic_progressbar", &classic_progressbar
},
285 { "vfs_timeout", &vfs_timeout
},
286 #ifdef ENABLE_VFS_FTP
287 { "ftpfs_directory_timeout", &ftpfs_directory_timeout
},
288 { "use_netrc", &ftpfs_use_netrc
},
289 { "ftpfs_retry_seconds", &ftpfs_retry_seconds
},
290 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy
},
291 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections
},
292 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy
},
293 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options
},
294 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls
},
295 #endif /* ENABLE_VFS_FTP */
296 #ifdef ENABLE_VFS_FISH
297 { "fish_directory_timeout", &fish_directory_timeout
},
298 #endif /* ENABLE_VFS_FISH */
299 #endif /* ENABLE_VFS */
300 /* option_tab_spacing is used in internal viewer */
301 { "editor_tab_spacing", &option_tab_spacing
},
302 #ifdef USE_INTERNAL_EDIT
303 { "editor_word_wrap_line_length", &option_word_wrap_line_length
},
304 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces
},
305 { "editor_return_does_auto_indent", &option_return_does_auto_indent
},
306 { "editor_backspace_through_tabs", &option_backspace_through_tabs
},
307 { "editor_fake_half_tabs", &option_fake_half_tabs
},
308 { "editor_option_save_mode", &option_save_mode
},
309 { "editor_option_save_position", &option_save_position
},
310 { "editor_option_auto_para_formatting", &option_auto_para_formatting
},
311 { "editor_option_typewriter_wrap", &option_typewriter_wrap
},
312 { "editor_edit_confirm_save", &edit_confirm_save
},
313 { "editor_syntax_highlighting", &option_syntax_highlighting
},
314 { "editor_persistent_selections", &option_persistent_selections
},
315 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol
},
316 { "editor_visible_tabs", &visible_tabs
},
317 { "editor_visible_spaces", &visible_tws
},
318 { "editor_line_state", &option_line_state
},
319 { "editor_simple_statusbar", &simple_statusbar
},
320 { "editor_check_new_line", &option_check_nl_at_eof
},
321 { "editor_show_right_margin", &show_right_margin
},
322 #endif /* USE_INTERNAL_EDIT */
323 { "nice_rotating_dash", &nice_rotating_dash
},
324 { "horizontal_split", &horizontal_split
},
325 { "mcview_remember_file_position", &mcview_remember_file_position
},
326 { "auto_fill_mkdir_name", &auto_fill_mkdir_name
},
327 { "copymove_persistent_attr", &setup_copymove_persistent_attr
},
328 { "select_flags", &select_flags
},
334 const char *opt_name
;
336 const char *opt_defval
;
338 #ifdef USE_INTERNAL_EDIT
339 { "editor_backup_extension", &option_backup_ext
, "~" },
341 { "mcview_eof", &mcview_show_eof
, "" },
347 const char *opt_name
;
348 const char *opt_old_name
;
350 } panels_ini_options
[] = {
351 { "kilobyte_si", NULL
, &panels_options
.kilobyte_si
},
352 { "mix_all_files", NULL
, &panels_options
.mix_all_files
},
353 { "show_backups", NULL
, &panels_options
.show_backups
},
354 { "show_dot_files", NULL
, &panels_options
.show_dot_files
},
355 { "fast_reload", NULL
, &panels_options
.fast_reload
},
356 { "fast_reload_msg_shown", NULL
, &panels_options
.fast_reload_msg_shown
},
357 { "mark_moves_down", NULL
, &panels_options
.mark_moves_down
},
358 { "reverse_files_only", NULL
, &panels_options
.reverse_files_only
},
359 { "auto_save_setup_panels", "auto_save_setup", &panels_options
.auto_save_setup
},
360 { "navigate_with_arrows", NULL
, &panels_options
.navigate_with_arrows
},
361 { "panel_scroll_pages", "scroll_pages", &panels_options
.scroll_pages
},
362 { "mouse_move_pages", NULL
, &panels_options
.mouse_move_pages
},
363 { "filetype_mode", NULL
, &panels_options
.filetype_mode
},
364 { "permission_mode", NULL
, &panels_options
.permission_mode
},
369 static const char *panels_section
= "Panels";
371 /*** file scope functions ************************************************************************/
372 /* --------------------------------------------------------------------------------------------- */
376 Get name of config file.
379 if not NULL, then config also search into specified subdir.
381 \param config_file_name
382 If specified filename is relative, then will search in standart patches.
385 Newly allocated path to config name or NULL if file not found.
387 If config_file_name is a relative path, then search config in stantart pathes.
390 load_setup_get_full_config_name (const char *subdir
, const char *config_file_name
)
393 TODO: IMHO, in future this function must be placed into mc_config module.
394 Also, need to rename stupid mc_home and mc_home_alt to mc_sysconfdir and mc_datadir;
395 home_mc => mc_user_homedir
397 char *lc_basename
, *ret
;
399 if (config_file_name
== NULL
)
402 if (g_path_is_absolute (config_file_name
))
403 return g_strdup (config_file_name
);
406 lc_basename
= g_path_get_basename (config_file_name
);
407 if (lc_basename
== NULL
)
411 ret
= g_build_filename (home_dir
, MC_USERCONF_DIR
, subdir
, lc_basename
, NULL
);
413 ret
= g_build_filename (home_dir
, MC_USERCONF_DIR
, lc_basename
, NULL
);
415 if (exist_file (ret
))
417 g_free (lc_basename
);
423 ret
= g_build_filename (mc_home
, subdir
, lc_basename
, NULL
);
425 ret
= g_build_filename (mc_home
, lc_basename
, NULL
);
427 if (exist_file (ret
))
429 g_free (lc_basename
);
435 ret
= g_build_filename (mc_home_alt
, subdir
, lc_basename
, NULL
);
437 ret
= g_build_filename (mc_home_alt
, lc_basename
, NULL
);
439 g_free (lc_basename
);
441 if (exist_file (ret
))
449 /* --------------------------------------------------------------------------------------------- */
452 setup__is_cfg_group_must_panel_config (const char *grp
)
454 return (!strcasecmp ("Dirs", grp
) ||
455 !strcasecmp ("Temporal:New Right Panel", grp
) ||
456 !strcasecmp ("Temporal:New Left Panel", grp
) ||
457 !strcasecmp ("New Left Panel", grp
) || !strcasecmp ("New Right Panel", grp
))
461 /* --------------------------------------------------------------------------------------------- */
464 setup__move_panels_config_into_separate_file (const char *profile
)
466 mc_config_t
*tmp_cfg
;
467 char **groups
, **curr_grp
;
468 const char *need_grp
;
470 if (!exist_file (profile
))
473 tmp_cfg
= mc_config_init (profile
);
477 curr_grp
= groups
= mc_config_get_groups (tmp_cfg
, NULL
);
480 mc_config_deinit (tmp_cfg
);
486 if (setup__is_cfg_group_must_panel_config (*curr_grp
) == NULL
)
487 mc_config_del_group (tmp_cfg
, *curr_grp
);
491 mc_config_save_to_file (tmp_cfg
, panels_profile_name
, NULL
);
492 mc_config_deinit (tmp_cfg
);
494 tmp_cfg
= mc_config_init (profile
);
505 need_grp
= setup__is_cfg_group_must_panel_config (*curr_grp
);
506 if (need_grp
!= NULL
)
508 mc_config_del_group (tmp_cfg
, need_grp
);
514 mc_config_save_file (tmp_cfg
, NULL
);
515 mc_config_deinit (tmp_cfg
);
518 /* --------------------------------------------------------------------------------------------- */
520 Create new mc_config object from specified ini-file or
521 append data to existing mc_config object from ini-file
526 load_setup_init_config_from_file (mc_config_t
** config
, const char *fname
)
529 TODO: IMHO, in future this function must be placed into mc_config module.
531 if (exist_file (fname
))
534 mc_config_read_file (*config
, fname
);
536 *config
= mc_config_init (fname
);
540 /* --------------------------------------------------------------------------------------------- */
547 for (i
= 0; layout
[i
].opt_name
!= NULL
; i
++)
548 *layout
[i
].opt_addr
= mc_config_get_int (mc_main_config
, "Layout",
549 layout
[i
].opt_name
, *layout
[i
].opt_addr
);
552 /* --------------------------------------------------------------------------------------------- */
555 load_keys_from_section (const char *terminal
, mc_config_t
* cfg
)
558 gchar
**profile_keys
, **keys
;
559 gchar
**values
, **curr_values
;
560 char *valcopy
, *value
;
562 gsize len
, values_len
;
564 if (terminal
== NULL
)
567 section_name
= g_strconcat ("terminal:", terminal
, (char *) NULL
);
568 profile_keys
= keys
= mc_config_get_keys (cfg
, section_name
, &len
);
570 while (*profile_keys
!= NULL
)
572 /* copy=other causes all keys from [terminal:other] to be loaded. */
573 if (g_ascii_strcasecmp (*profile_keys
, "copy") == 0)
575 valcopy
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
576 load_keys_from_section (valcopy
, cfg
);
582 curr_values
= values
=
583 mc_config_get_string_list (cfg
, section_name
, *profile_keys
, &values_len
);
585 key_code
= lookup_key (*profile_keys
, NULL
);
589 if (curr_values
!= NULL
)
591 while (*curr_values
!= NULL
)
593 valcopy
= convert_controls (*curr_values
);
594 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
601 value
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
602 valcopy
= convert_controls (value
);
603 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
615 g_free (section_name
);
618 /* --------------------------------------------------------------------------------------------- */
621 load_keymap_from_section (const char *section_name
, GArray
* keymap
, mc_config_t
* cfg
)
623 gchar
**profile_keys
, **keys
;
624 gchar
**values
, **curr_values
;
625 char *valcopy
, *value
;
627 gsize len
, values_len
;
629 if (section_name
== NULL
)
632 profile_keys
= keys
= mc_config_get_keys (cfg
, section_name
, &len
);
634 while (*profile_keys
!= NULL
)
636 curr_values
= values
=
637 mc_config_get_string_list (cfg
, section_name
, *profile_keys
, &values_len
);
639 action
= keybind_lookup_action (*profile_keys
);
643 if (curr_values
!= NULL
)
645 while (*curr_values
!= NULL
)
647 valcopy
= convert_controls (*curr_values
);
648 keybind_cmd_bind (keymap
, valcopy
, action
);
655 value
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
656 valcopy
= convert_controls (value
);
657 /* define_sequence (key_code, valcopy, MCKEY_NOACTION); */
671 /* --------------------------------------------------------------------------------------------- */
674 load_setup_get_keymap_profile_config (void)
677 TODO: IMHO, in future this function must be placed into mc_config module.
679 mc_config_t
*keymap_config
= NULL
;
680 char *fname
, *fname2
;
682 /* 1) /usr/share/mc (mc_home_alt) */
683 fname
= g_build_filename (mc_home_alt
, GLOBAL_KEYMAP_FILE
, NULL
);
684 load_setup_init_config_from_file (&keymap_config
, fname
);
687 /* 2) /etc/mc (mc_home) */
688 fname
= g_build_filename (mc_home
, GLOBAL_KEYMAP_FILE
, NULL
);
689 load_setup_init_config_from_file (&keymap_config
, fname
);
692 /* 3) ~/.mc (home_dir?) */
693 fname
= g_build_filename (home_dir
, MC_USERCONF_DIR
, GLOBAL_KEYMAP_FILE
, NULL
);
694 load_setup_init_config_from_file (&keymap_config
, fname
);
697 /* 4) main config; [Midnight Commander] -> keymap */
700 mc_config_get_string (mc_main_config
, CONFIG_APP_SECTION
, "keymap", GLOBAL_KEYMAP_FILE
);
701 fname
= load_setup_get_full_config_name (NULL
, fname2
);
704 load_setup_init_config_from_file (&keymap_config
, fname
);
709 /* 5) getenv("MC_KEYMAP") */
710 fname
= load_setup_get_full_config_name (NULL
, g_getenv ("MC_KEYMAP"));
713 load_setup_init_config_from_file (&keymap_config
, fname
);
717 /* 6) --keymap=<keymap> */
718 fname
= load_setup_get_full_config_name (NULL
, mc_args__keymap_file
);
721 load_setup_init_config_from_file (&keymap_config
, fname
);
725 return keymap_config
;
728 /* --------------------------------------------------------------------------------------------- */
730 static panel_view_mode_t
731 setup__load_panel_state (const char *section
)
735 panel_view_mode_t mode
= view_listing
;
737 /* Load the display mode */
738 buffer
= mc_config_get_string (mc_panels_config
, section
, "display", "listing");
740 for (i
= 0; panel_types
[i
].opt_name
!= NULL
; i
++)
741 if (g_ascii_strcasecmp (panel_types
[i
].opt_name
, buffer
) == 0)
743 mode
= panel_types
[i
].opt_type
;
752 /* --------------------------------------------------------------------------------------------- */
755 panel_save_type (const char *section
, panel_view_mode_t type
)
759 for (i
= 0; panel_types
[i
].opt_name
!= NULL
; i
++)
760 if (panel_types
[i
].opt_type
== type
)
762 mc_config_set_string (mc_panels_config
, section
, "display", panel_types
[i
].opt_name
);
767 /* --------------------------------------------------------------------------------------------- */
768 /*** public functions ****************************************************************************/
769 /* --------------------------------------------------------------------------------------------- */
777 if (profile_name
!= NULL
)
780 profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
781 if (!exist_file (profile
))
783 inifile
= concat_dir_and_file (mc_home
, "mc.ini");
784 if (exist_file (inifile
))
792 inifile
= concat_dir_and_file (mc_home_alt
, "mc.ini");
793 if (exist_file (inifile
))
803 profile_name
= profile
;
808 /* --------------------------------------------------------------------------------------------- */
819 load_codepages_list ();
820 #endif /* HAVE_CHARSET */
822 profile
= setup_init ();
824 /* mc.lib is common for all users, but has priority lower than
825 ~/.mc/ini. FIXME: it's only used for keys and treestore now */
826 global_profile_name
= g_build_filename (mc_home
, MC_GLOBAL_CONFIG_FILE
, (char *) NULL
);
827 if (!exist_file (global_profile_name
))
829 g_free (global_profile_name
);
830 global_profile_name
= g_build_filename (mc_home_alt
, MC_GLOBAL_CONFIG_FILE
, (char *) NULL
);
833 panels_profile_name
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_PANELS_FILE
, NULL
);
835 mc_main_config
= mc_config_init (profile
);
837 if (!exist_file (panels_profile_name
))
838 setup__move_panels_config_into_separate_file (profile
);
840 mc_panels_config
= mc_config_init (panels_profile_name
);
842 /* Load integer boolean options */
843 for (i
= 0; int_options
[i
].opt_name
!= NULL
; i
++)
844 *int_options
[i
].opt_addr
=
845 mc_config_get_int (mc_main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
,
846 *int_options
[i
].opt_addr
);
848 if (option_tab_spacing
<= 0)
849 option_tab_spacing
= DEFAULT_TAB_SPACING
;
851 #ifdef USE_INTERNAL_EDIT
852 if (option_word_wrap_line_length
<= 0)
853 option_word_wrap_line_length
= DEFAULT_WRAP_LINE_LENGTH
;
854 #endif /* USE_INTERNAL_EDIT */
856 /* overwrite old_esc_mode_timeout */
857 kt
= getenv ("KEYBOARD_KEY_TIMEOUT_US");
858 if ((kt
!= NULL
) && (kt
[0] != '\0'))
859 old_esc_mode_timeout
= atoi (kt
);
861 /* Load string options */
862 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
863 *str_options
[i
].opt_addr
=
864 mc_config_get_string (mc_main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
,
865 str_options
[i
].opt_defval
);
868 panels_load_options ();
871 startup_left_mode
= setup__load_panel_state ("New Left Panel");
872 startup_right_mode
= setup__load_panel_state ("New Right Panel");
874 /* At least one of the panels is a listing panel */
875 if (startup_left_mode
!= view_listing
&& startup_right_mode
!= view_listing
)
876 startup_left_mode
= view_listing
;
878 if (mc_run_param1
== NULL
)
880 buffer
= mc_config_get_string (mc_panels_config
, "Dirs", "other_dir", ".");
881 if (vfs_file_is_local (buffer
))
882 mc_run_param1
= buffer
;
887 boot_current_is_left
= mc_config_get_bool (mc_panels_config
, "Dirs", "current_is_left", TRUE
);
889 /* Load time formats */
890 user_recent_timeformat
=
891 mc_config_get_string (mc_main_config
, "Misc", "timeformat_recent", FMTTIME
);
892 user_old_timeformat
= mc_config_get_string (mc_main_config
, "Misc", "timeformat_old", FMTYEAR
);
894 #ifdef ENABLE_VFS_FTP
895 ftpfs_proxy_host
= mc_config_get_string (mc_main_config
, "Misc", "ftp_proxy_host", "gate");
896 ftpfs_ignore_chattr_errors
= mc_config_get_bool (mc_main_config
, CONFIG_APP_SECTION
,
897 "ignore_ftp_chattr_errors", TRUE
);
898 ftpfs_init_passwd ();
899 #endif /* ENABLE_VFS_FTP */
901 /* The default color and the terminal dependent color */
902 setup_color_string
= mc_config_get_string (mc_main_config
, "Colors", "base_color", "");
903 term_color_string
= mc_config_get_string (mc_main_config
, "Colors", getenv ("TERM"), "");
904 color_terminal_string
= mc_config_get_string (mc_main_config
, "Colors", "color_terminals", "");
906 /* Load the directory history */
907 /* directory_history_load (); */
908 /* Remove the temporal entries */
911 if (codepages
->len
> 1)
913 buffer
= mc_config_get_string (mc_main_config
, "Misc", "display_codepage", "");
914 if (buffer
[0] != '\0')
916 display_codepage
= get_codepage_index (buffer
);
917 cp_display
= get_codepage_id (display_codepage
);
920 buffer
= mc_config_get_string (mc_main_config
, "Misc", "source_codepage", "");
921 if (buffer
[0] != '\0')
923 default_source_codepage
= get_codepage_index (buffer
);
924 source_codepage
= default_source_codepage
; /* May be source_codepage doesn't need this */
925 cp_source
= get_codepage_id (source_codepage
);
930 autodetect_codeset
= mc_config_get_string (mc_main_config
, "Misc", "autodetect_codeset", "");
931 if ((autodetect_codeset
[0] != '\0') && (strcmp (autodetect_codeset
, "off") != 0))
932 is_autodetect_codeset_enabled
= TRUE
;
934 g_free (init_translation_table (source_codepage
, display_codepage
));
935 buffer
= (char *) get_codepage_id (display_codepage
);
937 utf8_display
= str_isutf8 (buffer
);
938 #endif /* HAVE_CHARSET */
940 clipboard_store_path
= mc_config_get_string (mc_main_config
, "Misc", "clipboard_store", "");
941 clipboard_paste_path
= mc_config_get_string (mc_main_config
, "Misc", "clipboard_paste", "");
944 /* --------------------------------------------------------------------------------------------- */
956 panels_save_options ();
960 /* directory_history_save (); */
962 #ifdef ENABLE_VFS_FTP
963 mc_config_set_string (mc_main_config
, "Misc", "ftpfs_password", ftpfs_anonymous_passwd
);
964 if (ftpfs_proxy_host
)
965 mc_config_set_string (mc_main_config
, "Misc", "ftp_proxy_host", ftpfs_proxy_host
);
966 #endif /* ENABLE_VFS_FTP */
969 mc_config_set_string (mc_main_config
, "Misc", "display_codepage",
970 get_codepage_id (display_codepage
));
971 mc_config_set_string (mc_main_config
, "Misc", "source_codepage",
972 get_codepage_id (default_source_codepage
));
973 mc_config_set_string (mc_main_config
, "Misc", "autodetect_codeset", autodetect_codeset
);
974 #endif /* HAVE_CHARSET */
975 mc_config_set_string (mc_main_config
, "Misc", "clipboard_store", clipboard_store_path
);
976 mc_config_set_string (mc_main_config
, "Misc", "clipboard_paste", clipboard_paste_path
);
978 tmp_profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
979 ret
= mc_config_save_to_file (mc_main_config
, tmp_profile
, NULL
);
981 g_free (tmp_profile
);
986 /* --------------------------------------------------------------------------------------------- */
993 g_free (clipboard_store_path
);
994 g_free (clipboard_paste_path
);
995 g_free (profile_name
);
996 g_free (global_profile_name
);
997 g_free (color_terminal_string
);
998 g_free (term_color_string
);
999 g_free (setup_color_string
);
1000 g_free (panels_profile_name
);
1001 mc_config_deinit (mc_main_config
);
1002 mc_config_deinit (mc_panels_config
);
1004 g_free (user_recent_timeformat
);
1005 g_free (user_old_timeformat
);
1007 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
1008 g_free (*str_options
[i
].opt_addr
);
1012 /* directory_history_free (); */
1015 g_free (autodetect_codeset
);
1016 free_codepages_list ();
1020 /* --------------------------------------------------------------------------------------------- */
1026 GError
*error
= NULL
;
1029 profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
1031 /* Save integer options */
1032 for (i
= 0; int_options
[i
].opt_name
!= NULL
; i
++)
1033 mc_config_set_int (mc_main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
,
1034 *int_options
[i
].opt_addr
);
1036 /* Save string options */
1037 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
1038 mc_config_set_string (mc_main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
,
1039 *str_options
[i
].opt_addr
);
1041 if (!mc_config_save_to_file (mc_main_config
, profile
, &error
))
1042 setup_save_config_show_error (profile
, &error
);
1047 /* --------------------------------------------------------------------------------------------- */
1050 setup_save_config_show_error (const char *filename
, GError
** error
)
1052 if (error
!= NULL
&& *error
!= NULL
)
1054 message (D_ERROR
, MSG_ERROR
, _("Cannot save file %s:\n%s"), filename
, (*error
)->message
);
1055 g_error_free (*error
);
1060 /* --------------------------------------------------------------------------------------------- */
1068 profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
1069 /* Save integer options */
1070 for (i
= 0; layout
[i
].opt_name
!= NULL
; i
++)
1071 mc_config_set_int (mc_main_config
, "Layout", layout
[i
].opt_name
, *layout
[i
].opt_addr
);
1072 mc_config_save_to_file (mc_main_config
, profile
, NULL
);
1076 /* --------------------------------------------------------------------------------------------- */
1079 load_key_defs (void)
1082 * Load keys from mc.lib before ~/.mc/ini, so that the user
1083 * definitions override global settings.
1085 mc_config_t
*mc_global_config
;
1087 mc_global_config
= mc_config_init (global_profile_name
);
1088 if (mc_global_config
!= NULL
)
1090 load_keys_from_section ("general", mc_global_config
);
1091 load_keys_from_section (getenv ("TERM"), mc_global_config
);
1092 mc_config_deinit (mc_global_config
);
1095 load_keys_from_section ("general", mc_main_config
);
1096 load_keys_from_section (getenv ("TERM"), mc_main_config
);
1099 /* --------------------------------------------------------------------------------------------- */
1101 #ifdef ENABLE_VFS_FTP
1103 load_anon_passwd (void)
1107 buffer
= mc_config_get_string (mc_main_config
, "Misc", "ftpfs_password", "");
1109 if ((buffer
!= NULL
) && (buffer
[0] != '\0'))
1115 #endif /* ENABLE_VFS_FTP */
1117 /* --------------------------------------------------------------------------------------------- */
1120 load_keymap_defs (void)
1123 * Load keymap from GLOBAL_KEYMAP_FILE before ~/.mc/keymap, so that the user
1124 * definitions override global settings.
1126 mc_config_t
*mc_global_keymap
;
1128 mc_global_keymap
= load_setup_get_keymap_profile_config ();
1130 if (mc_global_keymap
!= NULL
)
1132 #ifdef USE_INTERNAL_EDIT
1133 editor_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1134 load_keymap_from_section ("editor", editor_keymap
, mc_global_keymap
);
1135 editor_x_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1136 load_keymap_from_section ("editor:xmap", editor_x_keymap
, mc_global_keymap
);
1139 viewer_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1140 load_keymap_from_section ("viewer", viewer_keymap
, mc_global_keymap
);
1141 viewer_hex_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1142 load_keymap_from_section ("viewer:hex", viewer_hex_keymap
, mc_global_keymap
);
1144 main_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1145 load_keymap_from_section ("main", main_keymap
, mc_global_keymap
);
1146 main_x_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1147 load_keymap_from_section ("main:xmap", main_x_keymap
, mc_global_keymap
);
1149 panel_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1150 load_keymap_from_section ("panel", panel_keymap
, mc_global_keymap
);
1152 input_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1153 load_keymap_from_section ("input", input_keymap
, mc_global_keymap
);
1155 listbox_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1156 load_keymap_from_section ("listbox", listbox_keymap
, mc_global_keymap
);
1158 tree_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1159 load_keymap_from_section ("tree", tree_keymap
, mc_global_keymap
);
1161 help_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1162 load_keymap_from_section ("help", help_keymap
, mc_global_keymap
);
1164 dialog_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1165 load_keymap_from_section ("dialog", dialog_keymap
, mc_global_keymap
);
1167 #ifdef USE_DIFF_VIEW
1168 diff_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1169 load_keymap_from_section ("diffviewer", diff_keymap
, mc_global_keymap
);
1171 mc_config_deinit (mc_global_keymap
);
1174 main_map
= default_main_map
;
1175 if (main_keymap
&& main_keymap
->len
> 0)
1176 main_map
= (global_keymap_t
*) main_keymap
->data
;
1178 main_x_map
= default_main_x_map
;
1179 if (main_x_keymap
&& main_x_keymap
->len
> 0)
1180 main_x_map
= (global_keymap_t
*) main_x_keymap
->data
;
1182 panel_map
= default_panel_keymap
;
1183 if (panel_keymap
&& panel_keymap
->len
> 0)
1184 panel_map
= (global_keymap_t
*) panel_keymap
->data
;
1186 input_map
= default_input_keymap
;
1187 if (input_keymap
&& input_keymap
->len
> 0)
1188 input_map
= (global_keymap_t
*) input_keymap
->data
;
1190 listbox_map
= default_listbox_keymap
;
1191 if (listbox_keymap
&& listbox_keymap
->len
> 0)
1192 listbox_map
= (global_keymap_t
*) listbox_keymap
->data
;
1194 tree_map
= default_tree_keymap
;
1195 if (tree_keymap
&& tree_keymap
->len
> 0)
1196 tree_map
= (global_keymap_t
*) tree_keymap
->data
;
1198 help_map
= default_help_keymap
;
1199 if (help_keymap
&& help_keymap
->len
> 0)
1200 help_map
= (global_keymap_t
*) help_keymap
->data
;
1202 dialog_map
= default_dialog_keymap
;
1203 if (dialog_keymap
&& dialog_keymap
->len
> 0)
1204 dialog_map
= (global_keymap_t
*) dialog_keymap
->data
;
1206 #ifdef USE_DIFF_VIEW
1207 diff_map
= default_diff_keymap
;
1208 if (diff_keymap
&& diff_keymap
->len
> 0)
1209 diff_map
= (global_keymap_t
*) diff_keymap
->data
;
1214 /* --------------------------------------------------------------------------------------------- */
1217 free_keymap_defs (void)
1219 #ifdef USE_INTERNAL_EDIT
1220 if (editor_keymap
!= NULL
)
1221 g_array_free (editor_keymap
, TRUE
);
1222 if (editor_x_keymap
!= NULL
)
1223 g_array_free (editor_x_keymap
, TRUE
);
1225 if (viewer_keymap
!= NULL
)
1226 g_array_free (viewer_keymap
, TRUE
);
1227 if (viewer_hex_keymap
!= NULL
)
1228 g_array_free (viewer_hex_keymap
, TRUE
);
1229 if (main_keymap
!= NULL
)
1230 g_array_free (main_keymap
, TRUE
);
1231 if (main_x_keymap
!= NULL
)
1232 g_array_free (main_x_keymap
, TRUE
);
1233 if (panel_keymap
!= NULL
)
1234 g_array_free (panel_keymap
, TRUE
);
1235 if (input_keymap
!= NULL
)
1236 g_array_free (input_keymap
, TRUE
);
1237 if (listbox_keymap
!= NULL
)
1238 g_array_free (listbox_keymap
, TRUE
);
1239 if (tree_keymap
!= NULL
)
1240 g_array_free (tree_keymap
, TRUE
);
1241 if (help_keymap
!= NULL
)
1242 g_array_free (help_keymap
, TRUE
);
1243 if (dialog_keymap
!= NULL
)
1244 g_array_free (dialog_keymap
, TRUE
);
1245 #ifdef USE_DIFF_VIEW
1246 if (diff_keymap
!= NULL
)
1247 g_array_free (diff_keymap
, TRUE
);
1251 /* --------------------------------------------------------------------------------------------- */
1254 panel_load_setup (WPanel
* panel
, const char *section
)
1257 char *buffer
, buffer2
[BUF_TINY
];
1259 panel
->reverse
= mc_config_get_int (mc_panels_config
, section
, "reverse", 0);
1260 panel
->case_sensitive
=
1261 mc_config_get_int (mc_panels_config
, section
, "case_sensitive",
1262 OS_SORT_CASE_SENSITIVE_DEFAULT
);
1263 panel
->exec_first
= mc_config_get_int (mc_panels_config
, section
, "exec_first", 0);
1265 /* Load sort order */
1266 buffer
= mc_config_get_string (mc_panels_config
, section
, "sort_order", "name");
1267 panel
->current_sort_field
= panel_get_field_by_id (buffer
);
1268 if (panel
->current_sort_field
== NULL
)
1269 panel
->current_sort_field
= panel_get_field_by_id ("name");
1273 /* Load the listing mode */
1274 buffer
= mc_config_get_string (mc_panels_config
, section
, "list_mode", "full");
1275 panel
->list_type
= list_full
;
1276 for (i
= 0; list_types
[i
].key
!= NULL
; i
++)
1277 if (g_ascii_strcasecmp (list_types
[i
].key
, buffer
) == 0)
1279 panel
->list_type
= list_types
[i
].list_type
;
1285 g_free (panel
->user_format
);
1286 panel
->user_format
=
1287 mc_config_get_string (mc_panels_config
, section
, "user_format", DEFAULT_USER_FORMAT
);
1289 for (i
= 0; i
< LIST_TYPES
; i
++)
1291 g_free (panel
->user_status_format
[i
]);
1292 g_snprintf (buffer2
, BUF_TINY
, "user_status%lld", (long long) i
);
1293 panel
->user_status_format
[i
] =
1294 mc_config_get_string (mc_panels_config
, section
, buffer2
, DEFAULT_USER_FORMAT
);
1297 panel
->user_mini_status
= mc_config_get_int (mc_panels_config
, section
, "user_mini_status", 0);
1300 /* --------------------------------------------------------------------------------------------- */
1303 panel_save_setup (struct WPanel
*panel
, const char *section
)
1305 char buffer
[BUF_TINY
];
1308 mc_config_set_int (mc_panels_config
, section
, "reverse", panel
->reverse
);
1309 mc_config_set_int (mc_panels_config
, section
, "case_sensitive", panel
->case_sensitive
);
1310 mc_config_set_int (mc_panels_config
, section
, "exec_first", panel
->exec_first
);
1312 mc_config_set_string (mc_panels_config
, section
, "sort_order", panel
->current_sort_field
->id
);
1314 for (i
= 0; list_types
[i
].key
!= NULL
; i
++)
1315 if (list_types
[i
].list_type
== panel
->list_type
)
1317 mc_config_set_string (mc_panels_config
, section
, "list_mode", list_types
[i
].key
);
1321 mc_config_set_string (mc_panels_config
, section
, "user_format", panel
->user_format
);
1323 for (i
= 0; i
< LIST_TYPES
; i
++)
1325 g_snprintf (buffer
, BUF_TINY
, "user_status%lld", (long long) i
);
1326 mc_config_set_string (mc_panels_config
, section
, buffer
, panel
->user_status_format
[i
]);
1329 mc_config_set_int (mc_panels_config
, section
, "user_mini_status", panel
->user_mini_status
);
1332 /* --------------------------------------------------------------------------------------------- */
1335 save_panel_types (void)
1337 panel_view_mode_t type
;
1339 if (mc_run_mode
!= MC_RUN_FULL
)
1342 if (!panels_options
.auto_save_setup
)
1345 type
= get_display_type (0);
1346 panel_save_type ("New Left Panel", type
);
1347 if (type
== view_listing
)
1348 panel_save_setup (left_panel
, left_panel
->panel_name
);
1349 type
= get_display_type (1);
1350 panel_save_type ("New Right Panel", type
);
1351 if (type
== view_listing
)
1352 panel_save_setup (right_panel
, right_panel
->panel_name
);
1354 mc_config_set_string (mc_panels_config
, "Dirs", "other_dir", get_panel_dir_for (other_panel
));
1356 if (current_panel
!= NULL
)
1357 mc_config_set_string (mc_panels_config
, "Dirs", "current_is_left",
1358 get_current_index () == 0 ? "1" : "0");
1360 if (mc_panels_config
->ini_path
== NULL
)
1361 mc_panels_config
->ini_path
= g_strdup (panels_profile_name
);
1363 mc_config_del_group (mc_panels_config
, "Temporal:New Left Panel");
1364 mc_config_del_group (mc_panels_config
, "Temporal:New Right Panel");
1366 mc_config_save_file (mc_panels_config
, NULL
);
1369 /* --------------------------------------------------------------------------------------------- */
1372 Load panels options from [Panels] section.
1375 panels_load_options (void)
1380 /* Backward compatibility: load old parameters */
1381 for (i
= 0; panels_ini_options
[i
].opt_name
!= NULL
; i
++)
1382 *panels_ini_options
[i
].opt_addr
=
1383 mc_config_get_int (mc_main_config
, CONFIG_APP_SECTION
,
1384 panels_ini_options
[i
].opt_old_name
!= NULL
1385 ? panels_ini_options
[i
].
1386 opt_old_name
: panels_ini_options
[i
].opt_name
,
1387 *panels_ini_options
[i
].opt_addr
);
1389 qmode
= mc_config_get_int (mc_main_config
, CONFIG_APP_SECTION
,
1390 "quick_search_case_sensitive", (int) panels_options
.qsearch_mode
);
1392 panels_options
.qsearch_mode
= QSEARCH_CASE_INSENSITIVE
;
1393 else if (qmode
>= QSEARCH_NUM
)
1394 panels_options
.qsearch_mode
= QSEARCH_PANEL_CASE
;
1396 panels_options
.qsearch_mode
= (qsearch_mode_t
) qmode
;
1398 /* overwrite by new parameters */
1399 if (mc_config_has_group (mc_main_config
, panels_section
))
1401 for (i
= 0; panels_ini_options
[i
].opt_name
!= NULL
; i
++)
1402 *panels_ini_options
[i
].opt_addr
=
1403 mc_config_get_bool (mc_main_config
, panels_section
,
1404 panels_ini_options
[i
].opt_name
,
1405 *panels_ini_options
[i
].opt_addr
);
1407 qmode
= mc_config_get_int (mc_main_config
, panels_section
,
1408 "quick_search_mode", (int) panels_options
.qsearch_mode
);
1410 panels_options
.qsearch_mode
= QSEARCH_CASE_INSENSITIVE
;
1411 else if (qmode
>= QSEARCH_NUM
)
1412 panels_options
.qsearch_mode
= QSEARCH_PANEL_CASE
;
1414 panels_options
.qsearch_mode
= (qsearch_mode_t
) qmode
;
1418 /* --------------------------------------------------------------------------------------------- */
1421 Save panels options in [Panels] section.
1424 panels_save_options (void)
1428 for (i
= 0; panels_ini_options
[i
].opt_name
!= NULL
; i
++)
1429 mc_config_set_bool (mc_main_config
, panels_section
,
1430 panels_ini_options
[i
].opt_name
, *panels_ini_options
[i
].opt_addr
);
1432 mc_config_set_int (mc_main_config
, panels_section
,
1433 "quick_search_mode", (int) panels_options
.qsearch_mode
);
1436 /* --------------------------------------------------------------------------------------------- */