1 /* Setup loading/saving.
2 Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007, 2009 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/tty/mouse.h" /* To make view.h happy */
36 #include "lib/vfs/mc-vfs/vfs.h"
37 #include "lib/mcconfig.h"
38 #include "lib/fileloc.h"
41 #include "lib/vfs/mc-vfs/gc.h"
45 # include "lib/vfs/mc-vfs/ftpfs.h"
46 # include "lib/vfs/mc-vfs/fish.h"
48 #include "lib/strutil.h" /* str_isutf8 () */
54 #include "tree.h" /* xtree_mode */
56 #include "src/viewer/mcviewer.h" /* For the externs */
57 #include "hotlist.h" /* load/save/done hotlist */
58 #include "panelize.h" /* load/save/done panelize */
60 #include "menu.h" /* menubar_visible declaration */
62 #include "file.h" /* safe_delete */
63 #include "keybind.h" /* lookup_action */
70 #ifdef USE_INTERNAL_EDIT
71 # include "src/editor/edit.h"
76 extern int num_history_items_recorded
;
78 char *profile_name
; /* .mc/ini */
79 char *global_profile_name
; /* mc.lib */
81 char *setup_color_string
;
82 char *term_color_string
;
83 char *color_terminal_string
;
85 panel_view_mode_t startup_left_mode
;
86 panel_view_mode_t startup_right_mode
;
88 /* Ugly hack to allow panel_save_setup to work as a place holder for */
89 /* default panel values */
91 int setup_copymove_persistent_attr
= 1;
93 static char *panels_profile_name
= NULL
; /* .mc/panels.ini */
100 { "full", list_full
},
101 { "brief", list_brief
},
102 { "long", list_long
},
103 { "user", list_user
},
107 static const struct {
108 const char *opt_name
;
109 panel_view_mode_t opt_type
;
111 { "listing", view_listing
},
112 { "quickview", view_quick
},
113 { "info", view_info
},
114 { "tree", view_tree
},
115 { NULL
, view_listing
}
118 static const struct {
119 const char *opt_name
;
122 { "equal_split", &equal_split
},
123 { "first_panel_size", &first_panel_size
},
124 { "message_visible", &message_visible
},
125 { "keybar_visible", &keybar_visible
},
126 { "xterm_title", &xterm_title
},
127 { "output_lines", &output_lines
},
128 { "command_prompt", &command_prompt
},
129 { "menubar_visible", &menubar_visible
},
130 { "show_mini_info", &show_mini_info
},
131 { "permission_mode", &permission_mode
},
132 { "filetype_mode", &filetype_mode
},
133 { "free_space", &free_space
},
137 static const struct {
138 const char *opt_name
;
141 { "show_backups", &show_backups
},
142 { "kilobyte_si", &kilobyte_si
},
143 { "show_dot_files", &show_dot_files
},
144 { "verbose", &verbose
},
145 { "mark_moves_down", &mark_moves_down
},
146 { "pause_after_run", &pause_after_run
},
147 { "shell_patterns", &easy_patterns
},
148 { "auto_save_setup", &auto_save_setup
},
149 { "auto_menu", &auto_menu
},
150 { "use_internal_view", &use_internal_view
},
151 { "use_internal_edit", &use_internal_edit
},
152 { "clear_before_exec", &clear_before_exec
},
153 { "mix_all_files", &mix_all_files
},
154 { "fast_reload", &fast_reload
},
155 { "fast_reload_msg_shown", &fast_reload_w
},
156 { "confirm_delete", &confirm_delete
},
157 { "confirm_overwrite", &confirm_overwrite
},
158 { "confirm_execute", &confirm_execute
},
159 { "confirm_history_cleanup", &confirm_history_cleanup
},
160 { "confirm_exit", &confirm_exit
},
161 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete
},
162 { "safe_delete", &safe_delete
},
163 { "mouse_repeat_rate", &mou_auto_repeat
},
164 { "double_click_speed", &double_click_speed
},
166 { "eight_bit_clean", &eight_bit_clean
},
167 { "full_eight_bits", &full_eight_bits
},
168 #endif /* !HAVE_CHARSET */
169 { "use_8th_bit_as_meta", &use_8th_bit_as_meta
},
170 { "confirm_view_dir", &confirm_view_dir
},
171 { "mouse_move_pages", &mouse_move_pages
},
172 { "mouse_move_pages_viewer", &mcview_mouse_move_pages
},
173 { "mouse_close_dialog", &mouse_close_dialog
},
174 { "fast_refresh", &fast_refresh
},
175 { "navigate_with_arrows", &navigate_with_arrows
},
176 { "drop_menus", &drop_menus
},
177 { "wrap_mode", &mcview_global_wrap_mode
},
178 { "old_esc_mode", &old_esc_mode
},
179 { "cd_symlinks", &cd_symlinks
},
180 { "show_all_if_ambiguous", &show_all_if_ambiguous
},
181 { "max_dirt_limit", &mcview_max_dirt_limit
},
182 { "torben_fj_mode", &torben_fj_mode
},
183 { "use_file_to_guess_type", &use_file_to_check_type
},
184 { "alternate_plus_minus", &alternate_plus_minus
},
185 { "only_leading_plus_minus", &only_leading_plus_minus
},
186 { "show_output_starts_shell", &output_starts_shell
},
187 { "panel_scroll_pages", &panel_scroll_pages
},
188 { "xtree_mode", &xtree_mode
},
189 { "num_history_items_recorded", &num_history_items_recorded
},
190 { "file_op_compute_totals", &file_op_compute_totals
},
192 { "vfs_timeout", &vfs_timeout
},
194 { "ftpfs_directory_timeout", &ftpfs_directory_timeout
},
195 { "use_netrc", &use_netrc
},
196 { "ftpfs_retry_seconds", &ftpfs_retry_seconds
},
197 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy
},
198 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections
},
199 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy
},
200 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options
},
201 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls
},
202 { "fish_directory_timeout", &fish_directory_timeout
},
203 #endif /* USE_NETCODE */
204 #endif /* ENABLE_VFS */
205 #ifdef USE_INTERNAL_EDIT
206 { "editor_word_wrap_line_length", &option_word_wrap_line_length
},
207 { "editor_tab_spacing", &option_tab_spacing
},
208 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces
},
209 { "editor_return_does_auto_indent", &option_return_does_auto_indent
},
210 { "editor_backspace_through_tabs", &option_backspace_through_tabs
},
211 { "editor_fake_half_tabs", &option_fake_half_tabs
},
212 { "editor_option_save_mode", &option_save_mode
},
213 { "editor_option_save_position", &option_save_position
},
214 { "editor_option_auto_para_formatting", &option_auto_para_formatting
},
215 { "editor_option_typewriter_wrap", &option_typewriter_wrap
},
216 { "editor_edit_confirm_save", &edit_confirm_save
},
217 { "editor_syntax_highlighting", &option_syntax_highlighting
},
218 { "editor_persistent_selections", &option_persistent_selections
},
219 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol
},
220 { "editor_visible_tabs", &visible_tabs
},
221 { "editor_visible_spaces", &visible_tws
},
222 { "editor_line_state", &option_line_state
},
223 { "editor_simple_statusbar", &simple_statusbar
},
224 { "editor_check_new_line", &option_check_nl_at_eof
},
225 { "editor_show_right_margin", &show_right_margin
},
226 #endif /* USE_INTERNAL_EDIT */
228 { "nice_rotating_dash", &nice_rotating_dash
},
229 { "horizontal_split", &horizontal_split
},
230 { "mcview_remember_file_position", &mcview_remember_file_position
},
231 { "auto_fill_mkdir_name", &auto_fill_mkdir_name
},
232 { "reverse_files_only", &reverse_files_only
},
233 { "copymove_persistent_attr", &setup_copymove_persistent_attr
},
234 { "select_flags", &select_flags
},
239 extern char *user_recent_timeformat
;
240 extern char *user_old_timeformat
;
243 In order to use everywhere the same setup
244 for the locale we use defines
246 #define FMTYEAR _("%b %e %Y")
247 #define FMTTIME _("%b %e %H:%M")
251 const char *opt_name
;
253 const char *opt_defval
;
256 #ifdef USE_INTERNAL_EDIT
258 "editor_backup_extension", &option_backup_ext
, "~"},
261 "mcview_eof", &mcview_show_eof
, ""},
267 panel_save_setup (struct WPanel
*panel
, const char *section
)
269 char buffer
[BUF_TINY
];
272 mc_config_set_int (mc_panels_config
, section
, "reverse", panel
->reverse
);
273 mc_config_set_int (mc_panels_config
, section
, "case_sensitive", panel
->case_sensitive
);
274 mc_config_set_int (mc_panels_config
, section
, "exec_first", panel
->exec_first
);
277 mc_config_set_string (mc_panels_config
, section
, "sort_order", panel
->current_sort_field
->id
);
279 for (i
= 0; list_types
[i
].key
; i
++)
280 if (list_types
[i
].list_type
== panel
->list_type
)
282 mc_config_set_string (mc_panels_config
, section
, "list_mode", list_types
[i
].key
);
286 mc_config_set_string (mc_panels_config
, section
, "user_format", panel
->user_format
);
288 for (i
= 0; i
< LIST_TYPES
; i
++)
290 g_snprintf (buffer
, BUF_TINY
, "user_status%lld", (long long) i
);
291 mc_config_set_string (mc_panels_config
, section
, buffer
, panel
->user_status_format
[i
]);
294 mc_config_set_int (mc_panels_config
, section
, "user_mini_status", panel
->user_mini_status
);
303 profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
305 /* Save integer options */
306 for (i
= 0; layout
[i
].opt_name
; i
++)
308 mc_config_set_int (mc_main_config
, "Layout", layout
[i
].opt_name
, *layout
[i
].opt_addr
);
310 mc_config_save_to_file (mc_main_config
, profile
, NULL
);
316 save_configure (void)
319 GError
*error
= NULL
;
322 profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
324 /* Save integer options */
325 for (i
= 0; int_options
[i
].opt_name
; i
++)
326 mc_config_set_int (mc_main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
,
327 *int_options
[i
].opt_addr
);
329 /* Save string options */
330 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
331 mc_config_set_string (mc_main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
,
332 *str_options
[i
].opt_addr
);
334 if (!mc_config_save_to_file (mc_main_config
, profile
, &error
))
335 setup_save_config_show_error (profile
, &error
);
341 panel_save_type (const char *section
, panel_view_mode_t type
)
345 for (i
= 0; panel_types
[i
].opt_name
!= NULL
; i
++)
346 if (panel_types
[i
].opt_type
== type
)
348 mc_config_set_string (mc_panels_config
, section
, "display", panel_types
[i
].opt_name
);
354 save_panel_types (void)
356 panel_view_mode_t type
;
358 if ((view_one_file
!= NULL
) || (edit_one_file
!= NULL
))
361 if (!mc_config_get_int (mc_main_config
, CONFIG_APP_SECTION
,
362 "auto_save_setup_panels", auto_save_setup
))
365 type
= get_display_type (0);
366 panel_save_type ("New Left Panel", type
);
367 if (type
== view_listing
)
368 panel_save_setup (left_panel
, left_panel
->panel_name
);
369 type
= get_display_type (1);
370 panel_save_type ("New Right Panel", type
);
371 if (type
== view_listing
)
372 panel_save_setup (right_panel
, right_panel
->panel_name
);
374 mc_config_set_string (mc_panels_config
, "Dirs", "other_dir", get_panel_dir_for (other_panel
));
376 if (current_panel
!= NULL
)
377 mc_config_set_string (mc_panels_config
, "Dirs", "current_is_left",
378 get_current_index () == 0 ? "1" : "0");
380 if (mc_panels_config
->ini_path
== NULL
)
381 mc_panels_config
->ini_path
= g_strdup (panels_profile_name
);
383 mc_config_del_group (mc_panels_config
, "Temporal:New Left Panel");
384 mc_config_del_group (mc_panels_config
, "Temporal:New Right Panel");
386 mc_config_save_file (mc_panels_config
, NULL
);
405 /* directory_history_save (); */
407 #if defined(ENABLE_VFS) && defined (USE_NETCODE)
408 mc_config_set_string (mc_main_config
, "Misc", "ftpfs_password", ftpfs_anonymous_passwd
);
409 if (ftpfs_proxy_host
)
410 mc_config_set_string (mc_main_config
, "Misc", "ftp_proxy_host", ftpfs_proxy_host
);
411 #endif /* ENABLE_VFS && USE_NETCODE */
414 mc_config_set_string (mc_main_config
, "Misc", "display_codepage",
415 get_codepage_id (display_codepage
));
416 mc_config_set_string (mc_main_config
, "Misc", "source_codepage",
417 get_codepage_id (default_source_codepage
));
418 mc_config_set_string (mc_main_config
, "Misc", "autodetect_codeset", autodetect_codeset
);
419 #endif /* HAVE_CHARSET */
420 tmp_profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
421 ret
= mc_config_save_to_file (mc_main_config
, tmp_profile
, NULL
);
423 g_free (tmp_profile
);
429 panel_load_setup (WPanel
* panel
, const char *section
)
432 char *buffer
, buffer2
[BUF_TINY
];
434 panel
->reverse
= mc_config_get_int (mc_panels_config
, section
, "reverse", 0);
435 panel
->case_sensitive
=
436 mc_config_get_int (mc_panels_config
, section
, "case_sensitive",
437 OS_SORT_CASE_SENSITIVE_DEFAULT
);
438 panel
->exec_first
= mc_config_get_int (mc_panels_config
, section
, "exec_first", 0);
440 /* Load sort order */
441 buffer
= mc_config_get_string (mc_panels_config
, section
, "sort_order", "name");
442 panel
->current_sort_field
= panel_get_field_by_id (buffer
);
443 if (panel
->current_sort_field
== NULL
)
444 panel
->current_sort_field
= panel_get_field_by_id ("name");
448 /* Load the listing mode */
449 buffer
= mc_config_get_string (mc_panels_config
, section
, "list_mode", "full");
450 panel
->list_type
= list_full
;
451 for (i
= 0; list_types
[i
].key
; i
++)
452 if (g_strcasecmp (list_types
[i
].key
, buffer
) == 0)
454 panel
->list_type
= list_types
[i
].list_type
;
460 g_free (panel
->user_format
);
462 mc_config_get_string (mc_panels_config
, section
, "user_format", DEFAULT_USER_FORMAT
);
464 for (i
= 0; i
< LIST_TYPES
; i
++)
466 g_free (panel
->user_status_format
[i
]);
467 g_snprintf (buffer2
, BUF_TINY
, "user_status%lld", (long long) i
);
468 panel
->user_status_format
[i
] =
469 mc_config_get_string (mc_panels_config
, section
, buffer2
, DEFAULT_USER_FORMAT
);
472 panel
->user_mini_status
= mc_config_get_int (mc_panels_config
, section
, "user_mini_status", 0);
481 for (i
= 0; layout
[i
].opt_name
; i
++)
482 *layout
[i
].opt_addr
=
483 mc_config_get_int (mc_main_config
, "Layout", layout
[i
].opt_name
, *layout
[i
].opt_addr
);
486 static panel_view_mode_t
487 setup__load_panel_state (const char *section
)
491 panel_view_mode_t mode
= view_listing
;
493 /* Load the display mode */
494 buffer
= mc_config_get_string (mc_panels_config
, section
, "display", "listing");
496 for (i
= 0; panel_types
[i
].opt_name
!= NULL
; i
++)
497 if (g_strcasecmp (panel_types
[i
].opt_name
, buffer
) == 0)
499 mode
= panel_types
[i
].opt_type
;
507 setup__is_cfg_group_must_panel_config (const char *grp
)
509 if (!strcasecmp ("Dirs", grp
) ||
510 !strcasecmp ("Temporal:New Right Panel", grp
) ||
511 !strcasecmp ("Temporal:New Left Panel", grp
) ||
512 !strcasecmp ("New Left Panel", grp
) || !strcasecmp ("New Right Panel", grp
))
518 setup__move_panels_config_into_separate_file (const char *profile
)
520 mc_config_t
*tmp_cfg
;
521 char **groups
, **curr_grp
;
522 const char *need_grp
;
524 if (!exist_file (profile
))
527 tmp_cfg
= mc_config_init (profile
);
531 curr_grp
= groups
= mc_config_get_groups (tmp_cfg
, NULL
);
534 mc_config_deinit (tmp_cfg
);
539 if (setup__is_cfg_group_must_panel_config (*curr_grp
) == NULL
)
541 mc_config_del_group (tmp_cfg
, *curr_grp
);
546 mc_config_save_to_file (tmp_cfg
, panels_profile_name
, NULL
);
547 mc_config_deinit (tmp_cfg
);
549 tmp_cfg
= mc_config_init (profile
);
560 need_grp
= setup__is_cfg_group_must_panel_config (*curr_grp
);
561 if (need_grp
!= NULL
)
563 mc_config_del_group (tmp_cfg
, need_grp
);
568 mc_config_save_file (tmp_cfg
, NULL
);
569 mc_config_deinit (tmp_cfg
);
574 Get name of config file.
577 if not NULL, then config also search into specified subdir
579 \param config_file_name
580 If specified filename is relative, then will search in standart patches.
583 Newly allocated path to config name or NULL if file not found
585 If config_file_name is a relative path, then search config in stantart pathes */
587 load_setup_get_full_config_name (const char *subdir
, const char *config_file_name
)
590 TODO: IMHO, in future this function must be placed into mc_config module.
591 Also, need to rename stupid mc_home and mc_home_alt to mc_sysconfdir and mc_datadir;
592 home_mc => mc_user_homedir
594 char *lc_basename
, *ret
;
596 if (config_file_name
== NULL
)
599 if (g_path_is_absolute (config_file_name
))
600 return g_strdup (config_file_name
);
603 lc_basename
= g_path_get_basename (config_file_name
);
604 if (lc_basename
== NULL
)
609 ret
= g_build_filename (home_dir
, MC_USERCONF_DIR
, subdir
, lc_basename
, NULL
);
611 ret
= g_build_filename (home_dir
, MC_USERCONF_DIR
, lc_basename
, NULL
);
613 if (exist_file (ret
))
615 g_free (lc_basename
);
622 ret
= g_build_filename (mc_home
, subdir
, lc_basename
, NULL
);
624 ret
= g_build_filename (mc_home
, lc_basename
, NULL
);
626 if (exist_file (ret
))
628 g_free (lc_basename
);
634 ret
= g_build_filename (mc_home_alt
, subdir
, lc_basename
, NULL
);
636 ret
= g_build_filename (mc_home_alt
, lc_basename
, NULL
);
638 if (exist_file (ret
))
640 g_free (lc_basename
);
644 g_free (lc_basename
);
650 Create new mc_config object from specified ini-file or
651 append data to existing mc_config object from ini-file
655 load_setup_init_config_from_file (mc_config_t
** config
, const char *fname
)
658 TODO: IMHO, in future this function must be placed into mc_config module.
660 if (exist_file (fname
))
663 mc_config_read_file (*config
, fname
);
665 *config
= mc_config_init (fname
);
672 load_setup_get_keymap_profile_config (void)
675 TODO: IMHO, in future this function must be placed into mc_config module.
677 mc_config_t
*keymap_config
= NULL
;
679 char *fname
, *fname2
;
681 /* 1) /usr/share/mc (mc_home_alt) */
682 fname
= g_build_filename (mc_home_alt
, GLOBAL_KEYMAP_FILE
, NULL
);
683 load_setup_init_config_from_file (&keymap_config
, fname
);
686 /* 2) /etc/mc (mc_home) */
687 fname
= g_build_filename (mc_home
, GLOBAL_KEYMAP_FILE
, NULL
);
688 load_setup_init_config_from_file (&keymap_config
, fname
);
691 /* 3) ~/.mc (home_dir?) */
692 fname
= g_build_filename (home_dir
, MC_USERCONF_DIR
, GLOBAL_KEYMAP_FILE
, NULL
);
693 load_setup_init_config_from_file (&keymap_config
, fname
);
696 /* 4) main config; [Midnight Commander] -> keymap */
699 mc_config_get_string (mc_main_config
, CONFIG_APP_SECTION
, "keymap", GLOBAL_KEYMAP_FILE
);
700 fname
= load_setup_get_full_config_name (NULL
, fname2
);
703 load_setup_init_config_from_file (&keymap_config
, fname
);
708 /* 5) getenv("MC_KEYMAP") */
709 fname
= load_setup_get_full_config_name (NULL
, g_getenv ("MC_KEYMAP"));
712 load_setup_init_config_from_file (&keymap_config
, fname
);
716 /* 6) --keymap=<keymap> */
717 fname
= load_setup_get_full_config_name (NULL
, mc_args__keymap_file
);
720 load_setup_init_config_from_file (&keymap_config
, fname
);
724 return keymap_config
;
736 profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
737 if (!exist_file (profile
))
739 inifile
= concat_dir_and_file (mc_home
, "mc.ini");
740 if (exist_file (inifile
))
748 inifile
= concat_dir_and_file (mc_home_alt
, "mc.ini");
749 if (exist_file (inifile
))
759 profile_name
= profile
;
771 profile
= setup_init ();
773 /* mc.lib is common for all users, but has priority lower than
774 ~/.mc/ini. FIXME: it's only used for keys and treestore now */
775 global_profile_name
= concat_dir_and_file (mc_home
, MC_GLOBAL_CONFIG_FILE
);
776 if (!exist_file (global_profile_name
))
778 g_free (global_profile_name
);
779 global_profile_name
= concat_dir_and_file (mc_home_alt
, MC_GLOBAL_CONFIG_FILE
);
782 panels_profile_name
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_PANELS_FILE
, NULL
);
784 mc_main_config
= mc_config_init (profile
);
786 if (!exist_file (panels_profile_name
))
787 setup__move_panels_config_into_separate_file (profile
);
789 mc_panels_config
= mc_config_init (panels_profile_name
);
791 /* Load integer boolean options */
792 for (i
= 0; int_options
[i
].opt_name
; i
++)
793 *int_options
[i
].opt_addr
=
794 mc_config_get_int (mc_main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
,
795 *int_options
[i
].opt_addr
);
797 /* Load string options */
798 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
799 *str_options
[i
].opt_addr
=
800 mc_config_get_string (mc_main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
,
801 str_options
[i
].opt_defval
);
807 startup_left_mode
= setup__load_panel_state ("New Left Panel");
808 startup_right_mode
= setup__load_panel_state ("New Right Panel");
810 /* At least one of the panels is a listing panel */
811 if (startup_left_mode
!= view_listing
&& startup_right_mode
!= view_listing
)
812 startup_left_mode
= view_listing
;
816 buffer
= mc_config_get_string (mc_panels_config
, "Dirs", "other_dir", ".");
817 if (vfs_file_is_local (buffer
))
823 boot_current_is_left
= mc_config_get_int (mc_panels_config
, "Dirs", "current_is_left", 1);
825 /* Load time formats */
826 user_recent_timeformat
=
827 mc_config_get_string (mc_main_config
, "Misc", "timeformat_recent", FMTTIME
);
828 user_old_timeformat
= mc_config_get_string (mc_main_config
, "Misc", "timeformat_old", FMTYEAR
);
831 ftpfs_proxy_host
= mc_config_get_string (mc_main_config
, "Misc", "ftp_proxy_host", "gate");
834 /* The default color and the terminal dependent color */
835 setup_color_string
= mc_config_get_string (mc_main_config
, "Colors", "base_color", "");
836 term_color_string
= mc_config_get_string (mc_main_config
, "Colors", getenv ("TERM"), "");
837 color_terminal_string
= mc_config_get_string (mc_main_config
, "Colors", "color_terminals", "");
839 /* Load the directory history */
840 /* directory_history_load (); */
841 /* Remove the temporal entries */
842 #if defined(ENABLE_VFS) && defined (USE_NETCODE)
843 ftpfs_init_passwd ();
844 #endif /* ENABLE_VFS && USE_NETCODE */
847 if (load_codepages_list () > 0)
849 buffer
= mc_config_get_string (mc_main_config
, "Misc", "display_codepage", "");
850 if (buffer
[0] != '\0')
852 display_codepage
= get_codepage_index (buffer
);
853 cp_display
= get_codepage_id (display_codepage
);
856 buffer
= mc_config_get_string (mc_main_config
, "Misc", "source_codepage", "");
857 if (buffer
[0] != '\0')
859 default_source_codepage
= get_codepage_index (buffer
);
860 source_codepage
= default_source_codepage
; /* May be source_codepage don't needed this */
861 cp_source
= get_codepage_id (source_codepage
);
866 autodetect_codeset
= mc_config_get_string (mc_main_config
, "Misc", "autodetect_codeset", "");
867 if ((autodetect_codeset
[0] != '\0') && (strcmp (autodetect_codeset
, "off")))
868 is_autodetect_codeset_enabled
= TRUE
;
870 init_translation_table (source_codepage
, display_codepage
);
871 if (get_codepage_id (display_codepage
))
872 utf8_display
= str_isutf8 (get_codepage_id (display_codepage
));
873 #endif /* HAVE_CHARSET */
876 #if defined(ENABLE_VFS) && defined (USE_NETCODE)
882 buffer
= mc_config_get_string (mc_main_config
, "Misc", "ftpfs_password", "");
889 #endif /* ENABLE_VFS && USE_NETCODE */
896 g_free (profile_name
);
897 g_free (global_profile_name
);
898 g_free (color_terminal_string
);
899 g_free (term_color_string
);
900 g_free (setup_color_string
);
901 g_free (panels_profile_name
);
902 mc_config_deinit (mc_main_config
);
903 mc_config_deinit (mc_panels_config
);
905 g_free (user_recent_timeformat
);
906 g_free (user_old_timeformat
);
908 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
909 g_free (*str_options
[i
].opt_addr
);
913 /* directory_history_free (); */
917 load_keys_from_section (const char *terminal
, mc_config_t
* cfg
)
920 gchar
**profile_keys
, **keys
;
921 gchar
**values
, **curr_values
;
922 char *valcopy
, *value
;
924 gsize len
, values_len
;
929 section_name
= g_strconcat ("terminal:", terminal
, (char *) NULL
);
930 profile_keys
= keys
= mc_config_get_keys (cfg
, section_name
, &len
);
932 while (*profile_keys
)
935 /* copy=other causes all keys from [terminal:other] to be loaded. */
936 if (g_strcasecmp (*profile_keys
, "copy") == 0)
938 valcopy
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
939 load_keys_from_section (valcopy
, cfg
);
944 curr_values
= values
=
945 mc_config_get_string_list (cfg
, section_name
, *profile_keys
, &values_len
);
947 key_code
= lookup_key (*profile_keys
, NULL
);
954 valcopy
= convert_controls (*curr_values
);
955 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
962 value
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
963 valcopy
= convert_controls (value
);
964 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
974 g_free (section_name
);
981 * Load keys from mc.lib before ~/.mc/ini, so that the user
982 * definitions override global settings.
984 mc_config_t
*mc_global_config
;
986 mc_global_config
= mc_config_init (global_profile_name
);
987 if (mc_global_config
!= NULL
)
989 load_keys_from_section ("general", mc_global_config
);
990 load_keys_from_section (getenv ("TERM"), mc_global_config
);
991 mc_config_deinit (mc_global_config
);
993 load_keys_from_section ("general", mc_main_config
);
994 load_keys_from_section (getenv ("TERM"), mc_main_config
);
999 load_keymap_from_section (const char *section_name
, GArray
* keymap
, mc_config_t
* cfg
)
1001 gchar
**profile_keys
, **keys
;
1002 gchar
**values
, **curr_values
;
1003 char *valcopy
, *value
;
1005 gsize len
, values_len
;
1010 profile_keys
= keys
= mc_config_get_keys (cfg
, section_name
, &len
);
1012 while (*profile_keys
)
1014 curr_values
= values
=
1015 mc_config_get_string_list (cfg
, section_name
, *profile_keys
, &values_len
);
1016 action
= lookup_action (*profile_keys
);
1021 while (*curr_values
)
1023 valcopy
= convert_controls (*curr_values
);
1024 keybind_cmd_bind (keymap
, valcopy
, action
);
1031 value
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
1032 valcopy
= convert_controls (value
);
1033 /* define_sequence (key_code, valcopy, MCKEY_NOACTION); */
1040 g_strfreev (values
);
1046 load_keymap_defs (void)
1049 * Load keymap from GLOBAL_KEYMAP_FILE before ~/.mc/keymap, so that the user
1050 * definitions override global settings.
1052 mc_config_t
*mc_global_keymap
;
1054 mc_global_keymap
= load_setup_get_keymap_profile_config ();
1056 if (mc_global_keymap
!= NULL
)
1058 #ifdef USE_INTERNAL_EDIT
1059 editor_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1060 load_keymap_from_section ("editor", editor_keymap
, mc_global_keymap
);
1061 editor_x_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1062 load_keymap_from_section ("editor:xmap", editor_x_keymap
, mc_global_keymap
);
1065 viewer_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1066 load_keymap_from_section ("viewer", viewer_keymap
, mc_global_keymap
);
1067 viewer_hex_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1068 load_keymap_from_section ("viewer:hex", viewer_hex_keymap
, mc_global_keymap
);
1070 main_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1071 load_keymap_from_section ("main", main_keymap
, mc_global_keymap
);
1072 main_x_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1073 load_keymap_from_section ("main:xmap", main_x_keymap
, mc_global_keymap
);
1075 panel_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1076 load_keymap_from_section ("panel", panel_keymap
, mc_global_keymap
);
1078 input_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1079 load_keymap_from_section ("input", input_keymap
, mc_global_keymap
);
1081 tree_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1082 load_keymap_from_section ("tree", tree_keymap
, mc_global_keymap
);
1084 help_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1085 load_keymap_from_section ("help", help_keymap
, mc_global_keymap
);
1087 mc_config_deinit (mc_global_keymap
);
1092 free_keymap_defs (void)
1094 #ifdef USE_INTERNAL_EDIT
1095 if (editor_keymap
!= NULL
)
1096 g_array_free (editor_keymap
, TRUE
);
1097 if (editor_x_keymap
!= NULL
)
1098 g_array_free (editor_x_keymap
, TRUE
);
1100 if (viewer_keymap
!= NULL
)
1101 g_array_free (viewer_keymap
, TRUE
);
1102 if (viewer_hex_keymap
!= NULL
)
1103 g_array_free (viewer_hex_keymap
, TRUE
);
1104 if (main_keymap
!= NULL
)
1105 g_array_free (main_keymap
, TRUE
);
1106 if (main_x_keymap
!= NULL
)
1107 g_array_free (main_x_keymap
, TRUE
);
1108 if (panel_keymap
!= NULL
)
1109 g_array_free (panel_keymap
, TRUE
);
1110 if (input_keymap
!= NULL
)
1111 g_array_free (input_keymap
, TRUE
);
1112 if (tree_keymap
!= NULL
)
1113 g_array_free (tree_keymap
, TRUE
);
1114 if (help_keymap
!= NULL
)
1115 g_array_free (help_keymap
, TRUE
);
1119 setup_save_config_show_error (const char *filename
, GError
** error
)
1121 if (error
== NULL
|| *error
== NULL
)
1124 message (D_ERROR
, MSG_ERROR
, _("Cannot save file %s:\n%s"), filename
, (*error
)->message
);
1126 g_error_free (*error
);