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"
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
; /* .mc/ini */
82 char *global_profile_name
; /* mc.lib */
84 /* Only used at program boot */
85 gboolean boot_current_is_left
= TRUE
;
87 char *setup_color_string
;
88 char *term_color_string
;
89 char *color_terminal_string
;
91 /* If on, default for "No" in delete operations */
94 /* Controls screen clearing before an exec */
95 int clear_before_exec
= 1;
97 /* Asks for confirmation before deleting a file */
98 int confirm_delete
= 1;
99 /* Asks for confirmation before deleting a hotlist entry */
100 int confirm_directory_hotlist_delete
= 1;
101 /* Asks for confirmation before overwriting a file */
102 int confirm_overwrite
= 1;
103 /* Asks for confirmation before executing a program by pressing enter */
104 int confirm_execute
= 0;
105 /* Asks for confirmation before leaving the program */
106 int confirm_exit
= 1;
107 /* Asks for confirmation before clean up of history */
108 int confirm_history_cleanup
= 1;
110 /* If true, at startup the user-menu is invoked */
112 /* This flag indicates if the pull down menus by default drop down */
115 /* Asks for confirmation when using F3 to view a directory and there
117 int confirm_view_dir
= 0;
119 panel_view_mode_t startup_left_mode
;
120 panel_view_mode_t startup_right_mode
;
122 int setup_copymove_persistent_attr
= 1;
125 int option_tab_spacing
= DEFAULT_TAB_SPACING
;
127 /* Ugly hack to allow panel_save_setup to work as a place holder for */
128 /* default panel values */
131 panels_options_t panels_options
= {
132 .kilobyte_si
= FALSE
,
133 .mix_all_files
= FALSE
,
134 .show_backups
= TRUE
,
135 .show_dot_files
= TRUE
,
136 .fast_reload
= FALSE
,
137 .fast_reload_msg_shown
= FALSE
,
138 .mark_moves_down
= TRUE
,
139 .reverse_files_only
= TRUE
,
140 .auto_save_setup
= FALSE
,
141 .navigate_with_arrows
= FALSE
,
142 .scroll_pages
= TRUE
,
143 .mouse_move_pages
= TRUE
,
144 .filetype_mode
= TRUE
,
145 .permission_mode
= FALSE
,
146 .qsearch_mode
= QSEARCH_PANEL_CASE
149 int easy_patterns
= 1;
151 /* It true saves the setup when quitting */
152 int auto_save_setup
= 1;
154 /* If true, then the +, - and \ keys have their special meaning only if the
155 * command line is emtpy, otherwise they behave like regular letters
157 int only_leading_plus_minus
= 1;
159 /* Set when cd symlink following is desirable (bash mode) */
162 /* Set if you want the possible completions dialog for the first time */
163 int show_all_if_ambiguous
= 0;
165 /* Automatically fills name with current selected item name on mkdir */
166 int auto_fill_mkdir_name
= 1;
168 /* If set and you don't have subshell support,then C-o will give you a shell */
169 int output_starts_shell
= 0;
171 /* If set, we execute the file command to check the file type */
172 int use_file_to_check_type
= 1;
177 * Whether the Midnight Commander tries to provide more
178 * information about copy/move sizes and bytes transfered
179 * at the expense of some speed
181 int file_op_compute_totals
= 1;
183 /*** file scope macro definitions ****************************************************************/
185 /* In order to use everywhere the same setup for the locale we use defines */
186 #define FMTYEAR _("%b %e %Y")
187 #define FMTTIME _("%b %e %H:%M")
189 /*** file scope type declarations ****************************************************************/
191 /*** file scope variables ************************************************************************/
193 static char *panels_profile_name
= NULL
; /* .mc/panels.ini */
201 { "full", list_full
},
202 { "brief", list_brief
},
203 { "long", list_long
},
204 { "user", list_user
},
210 const char *opt_name
;
211 panel_view_mode_t opt_type
;
213 { "listing", view_listing
},
214 { "quickview", view_quick
},
215 { "info", view_info
},
216 { "tree", view_tree
},
217 { NULL
, view_listing
}
222 const char *opt_name
;
225 { "equal_split", &equal_split
},
226 { "first_panel_size", &first_panel_size
},
227 { "message_visible", &message_visible
},
228 { "keybar_visible", &keybar_visible
},
229 { "xterm_title", &xterm_title
},
230 { "output_lines", &output_lines
},
231 { "command_prompt", &command_prompt
},
232 { "menubar_visible", &menubar_visible
},
233 { "show_mini_info", &show_mini_info
},
234 { "free_space", &free_space
},
240 const char *opt_name
;
243 { "verbose", &verbose
},
244 { "pause_after_run", &pause_after_run
},
245 { "shell_patterns", &easy_patterns
},
246 { "auto_save_setup", &auto_save_setup
},
247 { "auto_menu", &auto_menu
},
248 { "use_internal_view", &use_internal_view
},
249 { "use_internal_edit", &use_internal_edit
},
250 { "clear_before_exec", &clear_before_exec
},
251 { "confirm_delete", &confirm_delete
},
252 { "confirm_overwrite", &confirm_overwrite
},
253 { "confirm_execute", &confirm_execute
},
254 { "confirm_history_cleanup", &confirm_history_cleanup
},
255 { "confirm_exit", &confirm_exit
},
256 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete
},
257 { "safe_delete", &safe_delete
},
258 { "mouse_repeat_rate", &mou_auto_repeat
},
259 { "double_click_speed", &double_click_speed
},
261 { "eight_bit_clean", &eight_bit_clean
},
262 { "full_eight_bits", &full_eight_bits
},
263 #endif /* !HAVE_CHARSET */
264 { "use_8th_bit_as_meta", &use_8th_bit_as_meta
},
265 { "confirm_view_dir", &confirm_view_dir
},
266 { "mouse_move_pages_viewer", &mcview_mouse_move_pages
},
267 { "mouse_close_dialog", &mouse_close_dialog
},
268 { "fast_refresh", &fast_refresh
},
269 { "drop_menus", &drop_menus
},
270 { "wrap_mode", &mcview_global_wrap_mode
},
271 { "old_esc_mode", &old_esc_mode
},
272 { "old_esc_mode_timeout", &old_esc_mode_timeout
},
273 { "cd_symlinks", &cd_symlinks
},
274 { "show_all_if_ambiguous", &show_all_if_ambiguous
},
275 { "max_dirt_limit", &mcview_max_dirt_limit
},
276 { "torben_fj_mode", &torben_fj_mode
},
277 { "use_file_to_guess_type", &use_file_to_check_type
},
278 { "alternate_plus_minus", &alternate_plus_minus
},
279 { "only_leading_plus_minus", &only_leading_plus_minus
},
280 { "show_output_starts_shell", &output_starts_shell
},
281 { "xtree_mode", &xtree_mode
},
282 { "num_history_items_recorded", &num_history_items_recorded
},
283 { "file_op_compute_totals", &file_op_compute_totals
},
284 { "classic_progressbar", &classic_progressbar
},
286 { "vfs_timeout", &vfs_timeout
},
287 #ifdef ENABLE_VFS_FTP
288 { "ftpfs_directory_timeout", &ftpfs_directory_timeout
},
289 { "use_netrc", &ftpfs_use_netrc
},
290 { "ftpfs_retry_seconds", &ftpfs_retry_seconds
},
291 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy
},
292 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections
},
293 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy
},
294 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options
},
295 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls
},
296 #endif /* ENABLE_VFS_FTP */
297 #ifdef ENABLE_VFS_FISH
298 { "fish_directory_timeout", &fish_directory_timeout
},
299 #endif /* ENABLE_VFS_FISH */
300 #endif /* ENABLE_VFS */
301 /* option_tab_spacing is used in internal viewer */
302 { "editor_tab_spacing", &option_tab_spacing
},
303 #ifdef USE_INTERNAL_EDIT
304 { "editor_word_wrap_line_length", &option_word_wrap_line_length
},
305 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces
},
306 { "editor_return_does_auto_indent", &option_return_does_auto_indent
},
307 { "editor_backspace_through_tabs", &option_backspace_through_tabs
},
308 { "editor_fake_half_tabs", &option_fake_half_tabs
},
309 { "editor_option_save_mode", &option_save_mode
},
310 { "editor_option_save_position", &option_save_position
},
311 { "editor_option_auto_para_formatting", &option_auto_para_formatting
},
312 { "editor_option_typewriter_wrap", &option_typewriter_wrap
},
313 { "editor_edit_confirm_save", &edit_confirm_save
},
314 { "editor_syntax_highlighting", &option_syntax_highlighting
},
315 { "editor_persistent_selections", &option_persistent_selections
},
316 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol
},
317 { "editor_visible_tabs", &visible_tabs
},
318 { "editor_visible_spaces", &visible_tws
},
319 { "editor_line_state", &option_line_state
},
320 { "editor_simple_statusbar", &simple_statusbar
},
321 { "editor_check_new_line", &option_check_nl_at_eof
},
322 { "editor_show_right_margin", &show_right_margin
},
323 { "editor_group_undo", &option_group_undo
},
324 #endif /* USE_INTERNAL_EDIT */
325 { "nice_rotating_dash", &nice_rotating_dash
},
326 { "horizontal_split", &horizontal_split
},
327 { "mcview_remember_file_position", &mcview_remember_file_position
},
328 { "auto_fill_mkdir_name", &auto_fill_mkdir_name
},
329 { "copymove_persistent_attr", &setup_copymove_persistent_attr
},
330 { "select_flags", &select_flags
},
336 const char *opt_name
;
338 const char *opt_defval
;
340 #ifdef USE_INTERNAL_EDIT
341 { "editor_backup_extension", &option_backup_ext
, "~" },
343 { "mcview_eof", &mcview_show_eof
, "" },
349 const char *opt_name
;
350 const char *opt_old_name
;
352 } panels_ini_options
[] = {
353 { "kilobyte_si", NULL
, &panels_options
.kilobyte_si
},
354 { "mix_all_files", NULL
, &panels_options
.mix_all_files
},
355 { "show_backups", NULL
, &panels_options
.show_backups
},
356 { "show_dot_files", NULL
, &panels_options
.show_dot_files
},
357 { "fast_reload", NULL
, &panels_options
.fast_reload
},
358 { "fast_reload_msg_shown", NULL
, &panels_options
.fast_reload_msg_shown
},
359 { "mark_moves_down", NULL
, &panels_options
.mark_moves_down
},
360 { "reverse_files_only", NULL
, &panels_options
.reverse_files_only
},
361 { "auto_save_setup_panels", "auto_save_setup", &panels_options
.auto_save_setup
},
362 { "navigate_with_arrows", NULL
, &panels_options
.navigate_with_arrows
},
363 { "panel_scroll_pages", "scroll_pages", &panels_options
.scroll_pages
},
364 { "mouse_move_pages", NULL
, &panels_options
.mouse_move_pages
},
365 { "filetype_mode", NULL
, &panels_options
.filetype_mode
},
366 { "permission_mode", NULL
, &panels_options
.permission_mode
},
371 static const char *panels_section
= "Panels";
373 /*** file scope functions ************************************************************************/
374 /* --------------------------------------------------------------------------------------------- */
378 Get name of config file.
381 if not NULL, then config also search into specified subdir.
383 \param config_file_name
384 If specified filename is relative, then will search in standart patches.
387 Newly allocated path to config name or NULL if file not found.
389 If config_file_name is a relative path, then search config in stantart pathes.
392 load_setup_get_full_config_name (const char *subdir
, const char *config_file_name
)
395 TODO: IMHO, in future this function must be placed into mc_config module.
396 Also, need to rename stupid mc_home and mc_home_alt to mc_sysconfdir and mc_datadir;
397 home_mc => mc_user_homedir
399 char *lc_basename
, *ret
;
401 if (config_file_name
== NULL
)
404 if (g_path_is_absolute (config_file_name
))
405 return g_strdup (config_file_name
);
408 lc_basename
= g_path_get_basename (config_file_name
);
409 if (lc_basename
== NULL
)
413 ret
= g_build_filename (home_dir
, MC_USERCONF_DIR
, subdir
, lc_basename
, NULL
);
415 ret
= g_build_filename (home_dir
, MC_USERCONF_DIR
, lc_basename
, NULL
);
417 if (exist_file (ret
))
419 g_free (lc_basename
);
425 ret
= g_build_filename (mc_home
, subdir
, lc_basename
, NULL
);
427 ret
= g_build_filename (mc_home
, lc_basename
, NULL
);
429 if (exist_file (ret
))
431 g_free (lc_basename
);
437 ret
= g_build_filename (mc_home_alt
, subdir
, lc_basename
, NULL
);
439 ret
= g_build_filename (mc_home_alt
, lc_basename
, NULL
);
441 g_free (lc_basename
);
443 if (exist_file (ret
))
451 /* --------------------------------------------------------------------------------------------- */
454 setup__is_cfg_group_must_panel_config (const char *grp
)
456 return (!strcasecmp ("Dirs", grp
) ||
457 !strcasecmp ("Temporal:New Right Panel", grp
) ||
458 !strcasecmp ("Temporal:New Left Panel", grp
) ||
459 !strcasecmp ("New Left Panel", grp
) || !strcasecmp ("New Right Panel", grp
))
463 /* --------------------------------------------------------------------------------------------- */
466 setup__move_panels_config_into_separate_file (const char *profile
)
468 mc_config_t
*tmp_cfg
;
469 char **groups
, **curr_grp
;
470 const char *need_grp
;
472 if (!exist_file (profile
))
475 tmp_cfg
= mc_config_init (profile
);
479 curr_grp
= groups
= mc_config_get_groups (tmp_cfg
, NULL
);
482 mc_config_deinit (tmp_cfg
);
488 if (setup__is_cfg_group_must_panel_config (*curr_grp
) == NULL
)
489 mc_config_del_group (tmp_cfg
, *curr_grp
);
493 mc_config_save_to_file (tmp_cfg
, panels_profile_name
, NULL
);
494 mc_config_deinit (tmp_cfg
);
496 tmp_cfg
= mc_config_init (profile
);
507 need_grp
= setup__is_cfg_group_must_panel_config (*curr_grp
);
508 if (need_grp
!= NULL
)
510 mc_config_del_group (tmp_cfg
, need_grp
);
516 mc_config_save_file (tmp_cfg
, NULL
);
517 mc_config_deinit (tmp_cfg
);
520 /* --------------------------------------------------------------------------------------------- */
522 Create new mc_config object from specified ini-file or
523 append data to existing mc_config object from ini-file
528 load_setup_init_config_from_file (mc_config_t
** config
, const char *fname
)
531 TODO: IMHO, in future this function must be placed into mc_config module.
533 if (exist_file (fname
))
536 mc_config_read_file (*config
, fname
);
538 *config
= mc_config_init (fname
);
542 /* --------------------------------------------------------------------------------------------- */
549 for (i
= 0; layout
[i
].opt_name
!= NULL
; i
++)
550 *layout
[i
].opt_addr
= mc_config_get_int (mc_main_config
, "Layout",
551 layout
[i
].opt_name
, *layout
[i
].opt_addr
);
554 /* --------------------------------------------------------------------------------------------- */
557 load_keys_from_section (const char *terminal
, mc_config_t
* cfg
)
560 gchar
**profile_keys
, **keys
;
561 gchar
**values
, **curr_values
;
562 char *valcopy
, *value
;
564 gsize len
, values_len
;
566 if (terminal
== NULL
)
569 section_name
= g_strconcat ("terminal:", terminal
, (char *) NULL
);
570 profile_keys
= keys
= mc_config_get_keys (cfg
, section_name
, &len
);
572 while (*profile_keys
!= NULL
)
574 /* copy=other causes all keys from [terminal:other] to be loaded. */
575 if (g_ascii_strcasecmp (*profile_keys
, "copy") == 0)
577 valcopy
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
578 load_keys_from_section (valcopy
, cfg
);
584 curr_values
= values
=
585 mc_config_get_string_list (cfg
, section_name
, *profile_keys
, &values_len
);
587 key_code
= lookup_key (*profile_keys
, NULL
);
591 if (curr_values
!= NULL
)
593 while (*curr_values
!= NULL
)
595 valcopy
= convert_controls (*curr_values
);
596 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
603 value
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
604 valcopy
= convert_controls (value
);
605 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
617 g_free (section_name
);
620 /* --------------------------------------------------------------------------------------------- */
623 load_keymap_from_section (const char *section_name
, GArray
* keymap
, mc_config_t
* cfg
)
625 gchar
**profile_keys
, **keys
;
626 gchar
**values
, **curr_values
;
627 char *valcopy
, *value
;
629 gsize len
, values_len
;
631 if (section_name
== NULL
)
634 profile_keys
= keys
= mc_config_get_keys (cfg
, section_name
, &len
);
636 while (*profile_keys
!= NULL
)
638 curr_values
= values
=
639 mc_config_get_string_list (cfg
, section_name
, *profile_keys
, &values_len
);
641 action
= keybind_lookup_action (*profile_keys
);
645 if (curr_values
!= NULL
)
647 while (*curr_values
!= NULL
)
649 valcopy
= convert_controls (*curr_values
);
650 keybind_cmd_bind (keymap
, valcopy
, action
);
657 value
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
658 valcopy
= convert_controls (value
);
659 /* define_sequence (key_code, valcopy, MCKEY_NOACTION); */
673 /* --------------------------------------------------------------------------------------------- */
676 load_setup_get_keymap_profile_config (void)
679 TODO: IMHO, in future this function must be placed into mc_config module.
681 mc_config_t
*keymap_config
= NULL
;
682 char *fname
, *fname2
;
684 /* 1) /usr/share/mc (mc_home_alt) */
685 fname
= g_build_filename (mc_home_alt
, GLOBAL_KEYMAP_FILE
, NULL
);
686 load_setup_init_config_from_file (&keymap_config
, fname
);
689 /* 2) /etc/mc (mc_home) */
690 fname
= g_build_filename (mc_home
, GLOBAL_KEYMAP_FILE
, NULL
);
691 load_setup_init_config_from_file (&keymap_config
, fname
);
694 /* 3) ~/.mc (home_dir?) */
695 fname
= g_build_filename (home_dir
, MC_USERCONF_DIR
, GLOBAL_KEYMAP_FILE
, NULL
);
696 load_setup_init_config_from_file (&keymap_config
, fname
);
699 /* 4) main config; [Midnight Commander] -> keymap */
702 mc_config_get_string (mc_main_config
, CONFIG_APP_SECTION
, "keymap", GLOBAL_KEYMAP_FILE
);
703 fname
= load_setup_get_full_config_name (NULL
, fname2
);
706 load_setup_init_config_from_file (&keymap_config
, fname
);
711 /* 5) getenv("MC_KEYMAP") */
712 fname
= load_setup_get_full_config_name (NULL
, g_getenv ("MC_KEYMAP"));
715 load_setup_init_config_from_file (&keymap_config
, fname
);
719 /* 6) --keymap=<keymap> */
720 fname
= load_setup_get_full_config_name (NULL
, mc_args__keymap_file
);
723 load_setup_init_config_from_file (&keymap_config
, fname
);
727 return keymap_config
;
730 /* --------------------------------------------------------------------------------------------- */
732 static panel_view_mode_t
733 setup__load_panel_state (const char *section
)
737 panel_view_mode_t mode
= view_listing
;
739 /* Load the display mode */
740 buffer
= mc_config_get_string (mc_panels_config
, section
, "display", "listing");
742 for (i
= 0; panel_types
[i
].opt_name
!= NULL
; i
++)
743 if (g_ascii_strcasecmp (panel_types
[i
].opt_name
, buffer
) == 0)
745 mode
= panel_types
[i
].opt_type
;
754 /* --------------------------------------------------------------------------------------------- */
757 panel_save_type (const char *section
, panel_view_mode_t type
)
761 for (i
= 0; panel_types
[i
].opt_name
!= NULL
; i
++)
762 if (panel_types
[i
].opt_type
== type
)
764 mc_config_set_string (mc_panels_config
, section
, "display", panel_types
[i
].opt_name
);
769 /* --------------------------------------------------------------------------------------------- */
771 /* save panels.ini */
773 save_panel_types (void)
775 panel_view_mode_t type
;
777 if (mc_run_mode
!= MC_RUN_FULL
)
780 type
= get_display_type (0);
781 panel_save_type ("New Left Panel", type
);
782 if (type
== view_listing
)
783 panel_save_setup (left_panel
, left_panel
->panel_name
);
784 type
= get_display_type (1);
785 panel_save_type ("New Right Panel", type
);
786 if (type
== view_listing
)
787 panel_save_setup (right_panel
, right_panel
->panel_name
);
789 mc_config_set_string (mc_panels_config
, "Dirs", "other_dir", get_panel_dir_for (other_panel
));
791 if (current_panel
!= NULL
)
792 mc_config_set_string (mc_panels_config
, "Dirs", "current_is_left",
793 get_current_index () == 0 ? "1" : "0");
795 if (mc_panels_config
->ini_path
== NULL
)
796 mc_panels_config
->ini_path
= g_strdup (panels_profile_name
);
798 mc_config_del_group (mc_panels_config
, "Temporal:New Left Panel");
799 mc_config_del_group (mc_panels_config
, "Temporal:New Right Panel");
801 mc_config_save_file (mc_panels_config
, NULL
);
804 /* --------------------------------------------------------------------------------------------- */
805 /*** public functions ****************************************************************************/
806 /* --------------------------------------------------------------------------------------------- */
814 if (profile_name
!= NULL
)
817 profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
818 if (!exist_file (profile
))
820 inifile
= concat_dir_and_file (mc_home
, "mc.ini");
821 if (exist_file (inifile
))
829 inifile
= concat_dir_and_file (mc_home_alt
, "mc.ini");
830 if (exist_file (inifile
))
840 profile_name
= profile
;
845 /* --------------------------------------------------------------------------------------------- */
856 load_codepages_list ();
857 #endif /* HAVE_CHARSET */
859 profile
= setup_init ();
861 /* mc.lib is common for all users, but has priority lower than
862 ~/.mc/ini. FIXME: it's only used for keys and treestore now */
863 global_profile_name
= g_build_filename (mc_home
, MC_GLOBAL_CONFIG_FILE
, (char *) NULL
);
864 if (!exist_file (global_profile_name
))
866 g_free (global_profile_name
);
867 global_profile_name
= g_build_filename (mc_home_alt
, MC_GLOBAL_CONFIG_FILE
, (char *) NULL
);
870 panels_profile_name
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_PANELS_FILE
, NULL
);
872 mc_main_config
= mc_config_init (profile
);
874 if (!exist_file (panels_profile_name
))
875 setup__move_panels_config_into_separate_file (profile
);
877 mc_panels_config
= mc_config_init (panels_profile_name
);
879 /* Load integer boolean options */
880 for (i
= 0; int_options
[i
].opt_name
!= NULL
; i
++)
881 *int_options
[i
].opt_addr
=
882 mc_config_get_int (mc_main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
,
883 *int_options
[i
].opt_addr
);
885 if (option_tab_spacing
<= 0)
886 option_tab_spacing
= DEFAULT_TAB_SPACING
;
888 #ifdef USE_INTERNAL_EDIT
889 if (option_word_wrap_line_length
<= 0)
890 option_word_wrap_line_length
= DEFAULT_WRAP_LINE_LENGTH
;
891 #endif /* USE_INTERNAL_EDIT */
893 /* overwrite old_esc_mode_timeout */
894 kt
= getenv ("KEYBOARD_KEY_TIMEOUT_US");
895 if ((kt
!= NULL
) && (kt
[0] != '\0'))
896 old_esc_mode_timeout
= atoi (kt
);
898 /* Load string options */
899 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
900 *str_options
[i
].opt_addr
=
901 mc_config_get_string (mc_main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
,
902 str_options
[i
].opt_defval
);
905 panels_load_options ();
908 startup_left_mode
= setup__load_panel_state ("New Left Panel");
909 startup_right_mode
= setup__load_panel_state ("New Right Panel");
911 /* At least one of the panels is a listing panel */
912 if (startup_left_mode
!= view_listing
&& startup_right_mode
!= view_listing
)
913 startup_left_mode
= view_listing
;
915 if (mc_run_param1
== NULL
)
917 buffer
= mc_config_get_string (mc_panels_config
, "Dirs", "other_dir", ".");
918 if (vfs_file_is_local (buffer
))
919 mc_run_param1
= buffer
;
924 boot_current_is_left
= mc_config_get_bool (mc_panels_config
, "Dirs", "current_is_left", TRUE
);
926 /* Load time formats */
927 user_recent_timeformat
=
928 mc_config_get_string (mc_main_config
, "Misc", "timeformat_recent", FMTTIME
);
929 user_old_timeformat
= mc_config_get_string (mc_main_config
, "Misc", "timeformat_old", FMTYEAR
);
931 #ifdef ENABLE_VFS_FTP
932 ftpfs_proxy_host
= mc_config_get_string (mc_main_config
, "Misc", "ftp_proxy_host", "gate");
933 ftpfs_ignore_chattr_errors
= mc_config_get_bool (mc_main_config
, CONFIG_APP_SECTION
,
934 "ignore_ftp_chattr_errors", TRUE
);
935 ftpfs_init_passwd ();
936 #endif /* ENABLE_VFS_FTP */
938 /* The default color and the terminal dependent color */
939 setup_color_string
= mc_config_get_string (mc_main_config
, "Colors", "base_color", "");
940 term_color_string
= mc_config_get_string (mc_main_config
, "Colors", getenv ("TERM"), "");
941 color_terminal_string
= mc_config_get_string (mc_main_config
, "Colors", "color_terminals", "");
943 /* Load the directory history */
944 /* directory_history_load (); */
945 /* Remove the temporal entries */
948 if (codepages
->len
> 1)
950 buffer
= mc_config_get_string (mc_main_config
, "Misc", "display_codepage", "");
951 if (buffer
[0] != '\0')
953 display_codepage
= get_codepage_index (buffer
);
954 cp_display
= get_codepage_id (display_codepage
);
957 buffer
= mc_config_get_string (mc_main_config
, "Misc", "source_codepage", "");
958 if (buffer
[0] != '\0')
960 default_source_codepage
= get_codepage_index (buffer
);
961 source_codepage
= default_source_codepage
; /* May be source_codepage doesn't need this */
962 cp_source
= get_codepage_id (source_codepage
);
967 autodetect_codeset
= mc_config_get_string (mc_main_config
, "Misc", "autodetect_codeset", "");
968 if ((autodetect_codeset
[0] != '\0') && (strcmp (autodetect_codeset
, "off") != 0))
969 is_autodetect_codeset_enabled
= TRUE
;
971 g_free (init_translation_table (source_codepage
, display_codepage
));
972 buffer
= (char *) get_codepage_id (display_codepage
);
974 utf8_display
= str_isutf8 (buffer
);
975 #endif /* HAVE_CHARSET */
977 clipboard_store_path
= mc_config_get_string (mc_main_config
, "Misc", "clipboard_store", "");
978 clipboard_paste_path
= mc_config_get_string (mc_main_config
, "Misc", "clipboard_paste", "");
981 /* --------------------------------------------------------------------------------------------- */
984 save_setup (gboolean save_options
, gboolean save_panel_options
)
992 if (save_panel_options
)
1001 panels_save_options ();
1003 /* directory_history_save (); */
1005 #ifdef ENABLE_VFS_FTP
1006 mc_config_set_string (mc_main_config
, "Misc", "ftpfs_password", ftpfs_anonymous_passwd
);
1007 if (ftpfs_proxy_host
)
1008 mc_config_set_string (mc_main_config
, "Misc", "ftp_proxy_host", ftpfs_proxy_host
);
1009 #endif /* ENABLE_VFS_FTP */
1012 mc_config_set_string (mc_main_config
, "Misc", "display_codepage",
1013 get_codepage_id (display_codepage
));
1014 mc_config_set_string (mc_main_config
, "Misc", "source_codepage",
1015 get_codepage_id (default_source_codepage
));
1016 mc_config_set_string (mc_main_config
, "Misc", "autodetect_codeset", autodetect_codeset
);
1017 #endif /* HAVE_CHARSET */
1018 mc_config_set_string (mc_main_config
, "Misc", "clipboard_store", clipboard_store_path
);
1019 mc_config_set_string (mc_main_config
, "Misc", "clipboard_paste", clipboard_paste_path
);
1021 tmp_profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
1022 ret
= mc_config_save_to_file (mc_main_config
, tmp_profile
, NULL
);
1024 g_free (tmp_profile
);
1032 /* --------------------------------------------------------------------------------------------- */
1039 g_free (clipboard_store_path
);
1040 g_free (clipboard_paste_path
);
1041 g_free (profile_name
);
1042 g_free (global_profile_name
);
1043 g_free (color_terminal_string
);
1044 g_free (term_color_string
);
1045 g_free (setup_color_string
);
1046 g_free (panels_profile_name
);
1047 mc_config_deinit (mc_main_config
);
1048 mc_config_deinit (mc_panels_config
);
1050 g_free (user_recent_timeformat
);
1051 g_free (user_old_timeformat
);
1053 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
1054 g_free (*str_options
[i
].opt_addr
);
1058 /* directory_history_free (); */
1061 g_free (autodetect_codeset
);
1062 free_codepages_list ();
1066 /* --------------------------------------------------------------------------------------------- */
1072 GError
*error
= NULL
;
1075 profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
1077 /* Save integer options */
1078 for (i
= 0; int_options
[i
].opt_name
!= NULL
; i
++)
1079 mc_config_set_int (mc_main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
,
1080 *int_options
[i
].opt_addr
);
1082 /* Save string options */
1083 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
1084 mc_config_set_string (mc_main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
,
1085 *str_options
[i
].opt_addr
);
1087 if (!mc_config_save_to_file (mc_main_config
, profile
, &error
))
1088 setup_save_config_show_error (profile
, &error
);
1093 /* --------------------------------------------------------------------------------------------- */
1096 setup_save_config_show_error (const char *filename
, GError
** error
)
1098 if (error
!= NULL
&& *error
!= NULL
)
1100 message (D_ERROR
, MSG_ERROR
, _("Cannot save file %s:\n%s"), filename
, (*error
)->message
);
1101 g_error_free (*error
);
1106 /* --------------------------------------------------------------------------------------------- */
1114 profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
1115 /* Save integer options */
1116 for (i
= 0; layout
[i
].opt_name
!= NULL
; i
++)
1117 mc_config_set_int (mc_main_config
, "Layout", layout
[i
].opt_name
, *layout
[i
].opt_addr
);
1118 mc_config_save_to_file (mc_main_config
, profile
, NULL
);
1122 /* --------------------------------------------------------------------------------------------- */
1125 load_key_defs (void)
1128 * Load keys from mc.lib before ~/.mc/ini, so that the user
1129 * definitions override global settings.
1131 mc_config_t
*mc_global_config
;
1133 mc_global_config
= mc_config_init (global_profile_name
);
1134 if (mc_global_config
!= NULL
)
1136 load_keys_from_section ("general", mc_global_config
);
1137 load_keys_from_section (getenv ("TERM"), mc_global_config
);
1138 mc_config_deinit (mc_global_config
);
1141 load_keys_from_section ("general", mc_main_config
);
1142 load_keys_from_section (getenv ("TERM"), mc_main_config
);
1145 /* --------------------------------------------------------------------------------------------- */
1147 #ifdef ENABLE_VFS_FTP
1149 load_anon_passwd (void)
1153 buffer
= mc_config_get_string (mc_main_config
, "Misc", "ftpfs_password", "");
1155 if ((buffer
!= NULL
) && (buffer
[0] != '\0'))
1161 #endif /* ENABLE_VFS_FTP */
1163 /* --------------------------------------------------------------------------------------------- */
1166 load_keymap_defs (void)
1169 * Load keymap from GLOBAL_KEYMAP_FILE before ~/.mc/keymap, so that the user
1170 * definitions override global settings.
1172 mc_config_t
*mc_global_keymap
;
1174 mc_global_keymap
= load_setup_get_keymap_profile_config ();
1176 if (mc_global_keymap
!= NULL
)
1178 #ifdef USE_INTERNAL_EDIT
1179 editor_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1180 load_keymap_from_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 ("editor:xmap", editor_x_keymap
, mc_global_keymap
);
1185 viewer_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1186 load_keymap_from_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 ("viewer:hex", viewer_hex_keymap
, mc_global_keymap
);
1190 main_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1191 load_keymap_from_section ("main", main_keymap
, mc_global_keymap
);
1192 main_x_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1193 load_keymap_from_section ("main:xmap", main_x_keymap
, mc_global_keymap
);
1195 panel_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1196 load_keymap_from_section ("panel", panel_keymap
, mc_global_keymap
);
1198 input_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1199 load_keymap_from_section ("input", input_keymap
, mc_global_keymap
);
1201 listbox_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1202 load_keymap_from_section ("listbox", listbox_keymap
, mc_global_keymap
);
1204 tree_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1205 load_keymap_from_section ("tree", tree_keymap
, mc_global_keymap
);
1207 help_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1208 load_keymap_from_section ("help", help_keymap
, mc_global_keymap
);
1210 dialog_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1211 load_keymap_from_section ("dialog", dialog_keymap
, mc_global_keymap
);
1213 #ifdef USE_DIFF_VIEW
1214 diff_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1215 load_keymap_from_section ("diffviewer", diff_keymap
, mc_global_keymap
);
1217 mc_config_deinit (mc_global_keymap
);
1220 main_map
= default_main_map
;
1221 if (main_keymap
&& main_keymap
->len
> 0)
1222 main_map
= (global_keymap_t
*) main_keymap
->data
;
1224 main_x_map
= default_main_x_map
;
1225 if (main_x_keymap
&& main_x_keymap
->len
> 0)
1226 main_x_map
= (global_keymap_t
*) main_x_keymap
->data
;
1228 panel_map
= default_panel_keymap
;
1229 if (panel_keymap
&& panel_keymap
->len
> 0)
1230 panel_map
= (global_keymap_t
*) panel_keymap
->data
;
1232 input_map
= default_input_keymap
;
1233 if (input_keymap
&& input_keymap
->len
> 0)
1234 input_map
= (global_keymap_t
*) input_keymap
->data
;
1236 listbox_map
= default_listbox_keymap
;
1237 if (listbox_keymap
&& listbox_keymap
->len
> 0)
1238 listbox_map
= (global_keymap_t
*) listbox_keymap
->data
;
1240 tree_map
= default_tree_keymap
;
1241 if (tree_keymap
&& tree_keymap
->len
> 0)
1242 tree_map
= (global_keymap_t
*) tree_keymap
->data
;
1244 help_map
= default_help_keymap
;
1245 if (help_keymap
&& help_keymap
->len
> 0)
1246 help_map
= (global_keymap_t
*) help_keymap
->data
;
1248 dialog_map
= default_dialog_keymap
;
1249 if (dialog_keymap
&& dialog_keymap
->len
> 0)
1250 dialog_map
= (global_keymap_t
*) dialog_keymap
->data
;
1252 #ifdef USE_DIFF_VIEW
1253 diff_map
= default_diff_keymap
;
1254 if (diff_keymap
&& diff_keymap
->len
> 0)
1255 diff_map
= (global_keymap_t
*) diff_keymap
->data
;
1260 /* --------------------------------------------------------------------------------------------- */
1263 free_keymap_defs (void)
1265 #ifdef USE_INTERNAL_EDIT
1266 if (editor_keymap
!= NULL
)
1267 g_array_free (editor_keymap
, TRUE
);
1268 if (editor_x_keymap
!= NULL
)
1269 g_array_free (editor_x_keymap
, TRUE
);
1271 if (viewer_keymap
!= NULL
)
1272 g_array_free (viewer_keymap
, TRUE
);
1273 if (viewer_hex_keymap
!= NULL
)
1274 g_array_free (viewer_hex_keymap
, TRUE
);
1275 if (main_keymap
!= NULL
)
1276 g_array_free (main_keymap
, TRUE
);
1277 if (main_x_keymap
!= NULL
)
1278 g_array_free (main_x_keymap
, TRUE
);
1279 if (panel_keymap
!= NULL
)
1280 g_array_free (panel_keymap
, TRUE
);
1281 if (input_keymap
!= NULL
)
1282 g_array_free (input_keymap
, TRUE
);
1283 if (listbox_keymap
!= NULL
)
1284 g_array_free (listbox_keymap
, TRUE
);
1285 if (tree_keymap
!= NULL
)
1286 g_array_free (tree_keymap
, TRUE
);
1287 if (help_keymap
!= NULL
)
1288 g_array_free (help_keymap
, TRUE
);
1289 if (dialog_keymap
!= NULL
)
1290 g_array_free (dialog_keymap
, TRUE
);
1291 #ifdef USE_DIFF_VIEW
1292 if (diff_keymap
!= NULL
)
1293 g_array_free (diff_keymap
, TRUE
);
1297 /* --------------------------------------------------------------------------------------------- */
1300 panel_load_setup (WPanel
* panel
, const char *section
)
1303 char *buffer
, buffer2
[BUF_TINY
];
1305 panel
->reverse
= mc_config_get_int (mc_panels_config
, section
, "reverse", 0);
1306 panel
->case_sensitive
=
1307 mc_config_get_int (mc_panels_config
, section
, "case_sensitive",
1308 OS_SORT_CASE_SENSITIVE_DEFAULT
);
1309 panel
->exec_first
= mc_config_get_int (mc_panels_config
, section
, "exec_first", 0);
1311 /* Load sort order */
1312 buffer
= mc_config_get_string (mc_panels_config
, section
, "sort_order", "name");
1313 panel
->current_sort_field
= panel_get_field_by_id (buffer
);
1314 if (panel
->current_sort_field
== NULL
)
1315 panel
->current_sort_field
= panel_get_field_by_id ("name");
1319 /* Load the listing mode */
1320 buffer
= mc_config_get_string (mc_panels_config
, section
, "list_mode", "full");
1321 panel
->list_type
= list_full
;
1322 for (i
= 0; list_types
[i
].key
!= NULL
; i
++)
1323 if (g_ascii_strcasecmp (list_types
[i
].key
, buffer
) == 0)
1325 panel
->list_type
= list_types
[i
].list_type
;
1331 g_free (panel
->user_format
);
1332 panel
->user_format
=
1333 mc_config_get_string (mc_panels_config
, section
, "user_format", DEFAULT_USER_FORMAT
);
1335 for (i
= 0; i
< LIST_TYPES
; i
++)
1337 g_free (panel
->user_status_format
[i
]);
1338 g_snprintf (buffer2
, BUF_TINY
, "user_status%lld", (long long) i
);
1339 panel
->user_status_format
[i
] =
1340 mc_config_get_string (mc_panels_config
, section
, buffer2
, DEFAULT_USER_FORMAT
);
1343 panel
->user_mini_status
= mc_config_get_int (mc_panels_config
, section
, "user_mini_status", 0);
1346 /* --------------------------------------------------------------------------------------------- */
1349 panel_save_setup (struct WPanel
*panel
, const char *section
)
1351 char buffer
[BUF_TINY
];
1354 mc_config_set_int (mc_panels_config
, section
, "reverse", panel
->reverse
);
1355 mc_config_set_int (mc_panels_config
, section
, "case_sensitive", panel
->case_sensitive
);
1356 mc_config_set_int (mc_panels_config
, section
, "exec_first", panel
->exec_first
);
1358 mc_config_set_string (mc_panels_config
, section
, "sort_order", panel
->current_sort_field
->id
);
1360 for (i
= 0; list_types
[i
].key
!= NULL
; i
++)
1361 if (list_types
[i
].list_type
== panel
->list_type
)
1363 mc_config_set_string (mc_panels_config
, section
, "list_mode", list_types
[i
].key
);
1367 mc_config_set_string (mc_panels_config
, section
, "user_format", panel
->user_format
);
1369 for (i
= 0; i
< LIST_TYPES
; i
++)
1371 g_snprintf (buffer
, BUF_TINY
, "user_status%lld", (long long) i
);
1372 mc_config_set_string (mc_panels_config
, section
, buffer
, panel
->user_status_format
[i
]);
1375 mc_config_set_int (mc_panels_config
, section
, "user_mini_status", panel
->user_mini_status
);
1378 /* --------------------------------------------------------------------------------------------- */
1381 Load panels options from [Panels] section.
1384 panels_load_options (void)
1389 /* Backward compatibility: load old parameters */
1390 for (i
= 0; panels_ini_options
[i
].opt_name
!= NULL
; i
++)
1391 *panels_ini_options
[i
].opt_addr
=
1392 mc_config_get_int (mc_main_config
, CONFIG_APP_SECTION
,
1393 panels_ini_options
[i
].opt_old_name
!= NULL
1394 ? panels_ini_options
[i
].opt_old_name
: panels_ini_options
[i
].
1395 opt_name
, *panels_ini_options
[i
].opt_addr
);
1397 qmode
= mc_config_get_int (mc_main_config
, CONFIG_APP_SECTION
,
1398 "quick_search_case_sensitive", (int) panels_options
.qsearch_mode
);
1400 panels_options
.qsearch_mode
= QSEARCH_CASE_INSENSITIVE
;
1401 else if (qmode
>= QSEARCH_NUM
)
1402 panels_options
.qsearch_mode
= QSEARCH_PANEL_CASE
;
1404 panels_options
.qsearch_mode
= (qsearch_mode_t
) qmode
;
1406 /* overwrite by new parameters */
1407 if (mc_config_has_group (mc_main_config
, panels_section
))
1409 for (i
= 0; panels_ini_options
[i
].opt_name
!= NULL
; i
++)
1410 *panels_ini_options
[i
].opt_addr
=
1411 mc_config_get_bool (mc_main_config
, panels_section
,
1412 panels_ini_options
[i
].opt_name
,
1413 *panels_ini_options
[i
].opt_addr
);
1415 qmode
= mc_config_get_int (mc_main_config
, panels_section
,
1416 "quick_search_mode", (int) panels_options
.qsearch_mode
);
1418 panels_options
.qsearch_mode
= QSEARCH_CASE_INSENSITIVE
;
1419 else if (qmode
>= QSEARCH_NUM
)
1420 panels_options
.qsearch_mode
= QSEARCH_PANEL_CASE
;
1422 panels_options
.qsearch_mode
= (qsearch_mode_t
) qmode
;
1426 /* --------------------------------------------------------------------------------------------- */
1429 Save panels options in [Panels] section.
1432 panels_save_options (void)
1436 for (i
= 0; panels_ini_options
[i
].opt_name
!= NULL
; i
++)
1437 mc_config_set_bool (mc_main_config
, panels_section
,
1438 panels_ini_options
[i
].opt_name
, *panels_ini_options
[i
].opt_addr
);
1440 mc_config_set_int (mc_main_config
, panels_section
,
1441 "quick_search_mode", (int) panels_options
.qsearch_mode
);
1444 /* --------------------------------------------------------------------------------------------- */