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>
33 #include "../src/tty/tty.h"
34 #include "../src/tty/key.h"
35 #include "../src/tty/mouse.h" /* To make view.h happy */
41 #include "tree.h" /* xtree_mode */
42 #include "../src/mcconfig/mcconfig.h"
44 #include "../src/viewer/mcviewer.h" /* For the externs */
45 #include "hotlist.h" /* load/save/done hotlist */
46 #include "panelize.h" /* load/save/done panelize */
48 #include "menu.h" /* menubar_visible declaration */
50 #include "file.h" /* safe_delete */
51 #include "keybind.h" /* lookup_action */
56 #include "../vfs/gc.h"
64 # include "../vfs/ftpfs.h"
65 # include "../vfs/fish.h"
68 #ifdef USE_INTERNAL_EDIT
69 # include "../edit/edit.h"
72 #include "../src/strutil.h" /* str_isutf8 () */
75 extern char *find_ignore_dirs
;
77 extern int num_history_items_recorded
;
79 char *profile_name
; /* .mc/ini */
80 char *global_profile_name
; /* mc.lib */
82 char *setup_color_string
;
83 char *term_color_string
;
84 char *color_terminal_string
;
86 int startup_left_mode
;
87 int startup_right_mode
;
89 /* Ugly hack to allow panel_save_setup to work as a place holder for */
90 /* default panel values */
92 int setup_copymove_persistent_attr
= 1;
94 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
;
111 { "listing", view_listing
},
112 { "quickview", view_quick
},
113 { "info", view_info
},
114 { "tree", view_tree
},
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_exit", &confirm_exit
},
160 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete
},
161 { "safe_delete", &safe_delete
},
162 { "mouse_repeat_rate", &mou_auto_repeat
},
163 { "double_click_speed", &double_click_speed
},
165 { "eight_bit_clean", &eight_bit_clean
},
166 { "full_eight_bits", &full_eight_bits
},
167 #endif /* !HAVE_CHARSET */
168 { "use_8th_bit_as_meta", &use_8th_bit_as_meta
},
169 { "confirm_view_dir", &confirm_view_dir
},
170 { "mouse_move_pages", &mouse_move_pages
},
171 { "mouse_move_pages_viewer", &mcview_mouse_move_pages
},
172 { "mouse_close_dialog", &mouse_close_dialog
},
173 { "fast_refresh", &fast_refresh
},
174 { "navigate_with_arrows", &navigate_with_arrows
},
175 { "drop_menus", &drop_menus
},
176 { "wrap_mode", &mcview_global_wrap_mode
},
177 { "old_esc_mode", &old_esc_mode
},
178 { "cd_symlinks", &cd_symlinks
},
179 { "show_all_if_ambiguous", &show_all_if_ambiguous
},
180 { "max_dirt_limit", &mcview_max_dirt_limit
},
181 { "torben_fj_mode", &torben_fj_mode
},
182 { "use_file_to_guess_type", &use_file_to_check_type
},
183 { "alternate_plus_minus", &alternate_plus_minus
},
184 { "only_leading_plus_minus", &only_leading_plus_minus
},
185 { "show_output_starts_shell", &output_starts_shell
},
186 { "panel_scroll_pages", &panel_scroll_pages
},
187 { "xtree_mode", &xtree_mode
},
188 { "num_history_items_recorded", &num_history_items_recorded
},
189 { "file_op_compute_totals", &file_op_compute_totals
},
190 { "skip_check_codeset", &skip_check_codeset
},
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 */
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 #endif /* USE_INTERNAL_EDIT */
227 { "nice_rotating_dash", &nice_rotating_dash
},
228 { "horizontal_split", &horizontal_split
},
229 { "mcview_remember_file_position", &mcview_remember_file_position
},
230 { "auto_fill_mkdir_name", &auto_fill_mkdir_name
},
231 { "reverse_files_only", &reverse_files_only
},
232 { "copymove_persistent_attr", &setup_copymove_persistent_attr
},
236 static const struct {
237 const char *opt_name
;
239 const char *opt_defval
;
241 #ifdef USE_INTERNAL_EDIT
242 { "editor_backup_extension", &option_backup_ext
, "~" },
248 panel_save_setup (struct WPanel
*panel
, const char *section
)
253 mc_config_set_int(mc_panels_config
, section
, "reverse", panel
->reverse
);
254 mc_config_set_int(mc_panels_config
, section
, "case_sensitive", panel
->case_sensitive
);
255 mc_config_set_int(mc_panels_config
, section
, "exec_first", panel
->exec_first
);
258 mc_config_set_string(mc_panels_config
, section
, "sort_order", panel
->current_sort_field
->id
);
260 for (i
= 0; list_types
[i
].key
; i
++)
261 if (list_types
[i
].list_type
== panel
->list_type
){
262 mc_config_set_string(mc_panels_config
, section
, "list_mode", list_types
[i
].key
);
266 mc_config_set_string(mc_panels_config
, section
, "user_format", panel
->user_format
);
268 for (i
= 0; i
< LIST_TYPES
; i
++){
269 buffer
= g_strdup_printf("user_status%d", i
);
270 mc_config_set_string(mc_panels_config
, section
, buffer
, panel
->user_status_format
[i
]);
274 mc_config_set_int(mc_panels_config
, section
, "user_mini_status", panel
->user_mini_status
);
283 profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
285 /* Save integer options */
286 for (i
= 0; layout
[i
].opt_name
; i
++){
287 mc_config_set_int(mc_main_config
, "Layout", layout
[i
].opt_name
, *layout
[i
].opt_addr
);
289 mc_config_save_to_file (mc_main_config
, profile
, NULL
);
295 save_configure (void)
298 GError
*error
= NULL
;
301 profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
303 /* Save integer options */
304 for (i
= 0; int_options
[i
].opt_name
; i
++)
305 mc_config_set_int(mc_main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
, *int_options
[i
].opt_addr
);
307 /* Save string options */
308 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
309 mc_config_set_string(mc_main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
, *str_options
[i
].opt_addr
);
311 if (! mc_config_save_to_file (mc_main_config
, profile
, &error
))
312 setup_save_config_show_error(profile
, &error
);
318 panel_save_type (const char *section
, int type
)
322 for (i
= 0; panel_types
[i
].opt_name
; i
++)
323 if (panel_types
[i
].opt_type
== type
){
324 mc_config_set_string(mc_panels_config
, section
,
325 "display", panel_types
[i
].opt_name
);
331 save_panel_types (void)
335 type
= get_display_type (0);
336 panel_save_type ("New Left Panel", type
);
337 if (type
== view_listing
)
338 panel_save_setup (left_panel
, left_panel
->panel_name
);
339 type
= get_display_type (1);
340 panel_save_type ("New Right Panel", type
);
341 if (type
== view_listing
)
342 panel_save_setup (right_panel
, right_panel
->panel_name
);
344 mc_config_set_string (mc_panels_config
, "Dirs" , "other_dir",
345 get_panel_dir_for (other_panel
));
347 if (current_panel
!= NULL
)
348 mc_config_set_string (mc_panels_config
, "Dirs" , "current_is_left",
349 get_current_index () == 0 ? "1" : "0");
351 if (mc_panels_config
->ini_path
== NULL
)
352 mc_panels_config
->ini_path
= g_strdup(panels_profile_name
);
354 mc_config_del_group (mc_panels_config
, "Temporal:New Left Panel");
355 mc_config_del_group (mc_panels_config
, "Temporal:New Right Panel");
357 mc_config_save_file (mc_panels_config
, NULL
);
376 /* directory_history_save (); */
378 #if defined(USE_VFS) && defined (USE_NETCODE)
379 mc_config_set_string(mc_main_config
, "Misc" , "ftpfs_password",
380 ftpfs_anonymous_passwd
);
381 if (ftpfs_proxy_host
)
382 mc_config_set_string(mc_main_config
, "Misc" , "ftp_proxy_host",
384 #endif /* USE_VFS && USE_NETCODE */
387 mc_config_set_string(mc_main_config
, "Misc" , "display_codepage",
388 get_codepage_id( display_codepage
));
389 mc_config_set_string(mc_main_config
, "Misc" , "source_codepage",
390 get_codepage_id( source_codepage
));
391 #endif /* HAVE_CHARSET */
392 tmp_profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
393 ret
= mc_config_save_to_file (mc_main_config
, tmp_profile
, NULL
);
395 g_free (tmp_profile
);
401 panel_load_setup (WPanel
*panel
, const char *section
)
406 panel
->reverse
= mc_config_get_int(mc_panels_config
, section
, "reverse", 0);
407 panel
->case_sensitive
= mc_config_get_int(mc_panels_config
, section
, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT
);
408 panel
->exec_first
= mc_config_get_int(mc_panels_config
, section
, "exec_first", 0);
410 /* Load sort order */
411 buffer
= mc_config_get_string(mc_panels_config
, section
, "sort_order", "name");
412 panel
->current_sort_field
= panel_get_field_by_id(buffer
);
415 /* Load the listing mode */
416 buffer
= mc_config_get_string(mc_panels_config
, section
, "list_mode", "full");
417 panel
->list_type
= list_full
;
418 for (i
= 0; list_types
[i
].key
; i
++)
419 if ( g_strcasecmp (list_types
[i
].key
, buffer
) == 0){
420 panel
->list_type
= list_types
[i
].list_type
;
426 g_free (panel
->user_format
);
427 panel
->user_format
= mc_config_get_string(mc_panels_config
, section
, "user_format", DEFAULT_USER_FORMAT
);
429 for (i
= 0; i
< LIST_TYPES
; i
++){
430 g_free (panel
->user_status_format
[i
]);
431 buffer
= g_strdup_printf("user_status%d",i
);
432 panel
->user_status_format
[i
] =
433 mc_config_get_string(mc_panels_config
, section
, buffer
, DEFAULT_USER_FORMAT
);
437 panel
->user_mini_status
=
438 mc_config_get_int(mc_panels_config
, section
, "user_mini_status", 0);
447 for (i
= 0; layout
[i
].opt_name
; i
++)
448 *layout
[i
].opt_addr
=
449 mc_config_get_int(mc_main_config
,"Layout", layout
[i
].opt_name
, *layout
[i
].opt_addr
);
453 setup__load_panel_state (const char *section
)
458 int mode
= view_listing
;
460 /* Load the display mode */
461 buffer
= mc_config_get_string(mc_panels_config
, section
, "display", "listing");
463 for (i
= 0; panel_types
[i
].opt_name
; i
++)
464 if ( g_strcasecmp (panel_types
[i
].opt_name
, buffer
) == 0){
465 mode
= panel_types
[i
].opt_type
;
473 setup__is_cfg_group_must_panel_config(const char *grp
)
476 ! strcasecmp("Dirs",grp
) ||
477 ! strcasecmp("Temporal:New Right Panel",grp
) ||
478 ! strcasecmp("Temporal:New Left Panel",grp
) ||
479 ! strcasecmp("New Left Panel",grp
) ||
480 ! strcasecmp("New Right Panel",grp
)
487 setup__move_panels_config_into_separate_file(const char*profile
)
489 mc_config_t
*tmp_cfg
;
490 char **groups
, **curr_grp
;
491 const char *need_grp
;
494 if (!exist_file(profile
))
497 tmp_cfg
= mc_config_init(profile
);
501 curr_grp
= groups
= mc_config_get_groups (tmp_cfg
, &groups_count
);
504 mc_config_deinit(tmp_cfg
);
509 if ( setup__is_cfg_group_must_panel_config(*curr_grp
) == NULL
)
511 mc_config_del_group (tmp_cfg
, *curr_grp
);
516 mc_config_save_to_file (tmp_cfg
, panels_profile_name
, NULL
);
517 mc_config_deinit(tmp_cfg
);
519 tmp_cfg
= mc_config_init(profile
);
530 need_grp
= setup__is_cfg_group_must_panel_config(*curr_grp
);
531 if ( need_grp
!= NULL
)
533 mc_config_del_group (tmp_cfg
, need_grp
);
538 mc_config_save_file (tmp_cfg
, NULL
);
539 mc_config_deinit(tmp_cfg
);
544 Get name of config file.
547 if not NULL, then config also search into specified subdir
549 \param config_file_name
550 If specified filename is relative, then will search in standart patches.
553 Newly allocated path to config name or NULL if file not found
555 If config_file_name is a relative path, then search config in stantart pathes */
557 load_setup_get_full_config_name(const char *subdir
, const char *config_file_name
)
560 TODO: IMHO, in future this function must be placed into mc_config module.
561 Also, need to rename stupid mc_home and mc_home_alt to mc_sysconfdir and mc_datadir;
562 home_mc => mc_user_homedir
564 char *lc_basename
, *ret
;
566 if (config_file_name
== NULL
)
569 if (g_path_is_absolute (config_file_name
))
570 return g_strdup(config_file_name
);
573 lc_basename
= g_path_get_basename(config_file_name
);
574 if (lc_basename
== NULL
)
579 ret
= g_build_filename (home_dir
, MC_USERCONF_DIR
, subdir
, lc_basename
, NULL
);
581 ret
= g_build_filename (home_dir
, MC_USERCONF_DIR
, lc_basename
, NULL
);
583 if (exist_file(ret
)) {
591 ret
= g_build_filename (mc_home
, subdir
, lc_basename
, NULL
);
593 ret
= g_build_filename (mc_home
, lc_basename
, NULL
);
595 if (exist_file(ret
)) {
602 ret
= g_build_filename (mc_home_alt
, subdir
, lc_basename
, NULL
);
604 ret
= g_build_filename (mc_home_alt
, lc_basename
, NULL
);
606 if (exist_file(ret
)) {
617 Create new mc_config object from specified ini-file or
618 append data to existing mc_config object from ini-file
622 load_setup_init_config_from_file(mc_config_t
**config
, const char *fname
)
625 TODO: IMHO, in future this function must be placed into mc_config module.
627 if (exist_file(fname
)) {
629 mc_config_read_file( *config
, fname
);
631 *config
= mc_config_init(fname
);
638 load_setup_get_keymap_profile_config(void)
641 TODO: IMHO, in future this function must be placed into mc_config module.
643 mc_config_t
*keymap_config
= NULL
;
645 char *fname
, *fname2
;
647 /* 1) /usr/share/mc (mc_home_alt) */
648 fname
= g_build_filename (mc_home_alt
, GLOBAL_KEYMAP_FILE
, NULL
);
649 load_setup_init_config_from_file( &keymap_config
, fname
);
652 /* 2) /etc/mc (mc_home) */
653 fname
= g_build_filename (mc_home
, GLOBAL_KEYMAP_FILE
, NULL
);
654 load_setup_init_config_from_file( &keymap_config
, fname
);
657 /* 3) ~/.mc (home_dir?) */
658 fname
= g_build_filename (home_dir
, MC_USERCONF_DIR
, GLOBAL_KEYMAP_FILE
, NULL
);
659 load_setup_init_config_from_file( &keymap_config
, fname
);
662 /* 4) main config; [Midnight Commander] -> keymap*/
664 fname2
= mc_config_get_string(mc_main_config
, CONFIG_APP_SECTION
, "keymap" , GLOBAL_KEYMAP_FILE
);
665 fname
= load_setup_get_full_config_name(NULL
, fname2
);
668 load_setup_init_config_from_file( &keymap_config
, fname
);
673 /* 5) getenv("MC_KEYMAP") */
674 fname
= load_setup_get_full_config_name(NULL
, g_getenv ("MC_KEYMAP"));
677 load_setup_init_config_from_file( &keymap_config
, fname
);
681 /* 6) --keymap=<keymap> */
682 fname
= load_setup_get_full_config_name(NULL
, mc_args__keymap_file
);
685 load_setup_init_config_from_file( &keymap_config
, fname
);
689 return keymap_config
;
701 profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
702 if (!exist_file (profile
)){
703 inifile
= concat_dir_and_file (mc_home
, "mc.ini");
704 if (exist_file (inifile
)){
709 inifile
= concat_dir_and_file (mc_home_alt
, "mc.ini");
710 if (exist_file (inifile
)) {
718 profile_name
= profile
;
730 profile
= setup_init ();
732 /* mc.lib is common for all users, but has priority lower than
733 ~/.mc/ini. FIXME: it's only used for keys and treestore now */
734 global_profile_name
= concat_dir_and_file (mc_home
, MC_GLOBAL_CONFIG_FILE
);
735 if (!exist_file(global_profile_name
)) {
736 g_free (global_profile_name
);
737 global_profile_name
= concat_dir_and_file (mc_home_alt
, MC_GLOBAL_CONFIG_FILE
);
740 panels_profile_name
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_PANELS_FILE
, NULL
);
742 mc_main_config
= mc_config_init(profile
);
744 if (!exist_file(panels_profile_name
))
745 setup__move_panels_config_into_separate_file(profile
);
747 mc_panels_config
= mc_config_init(panels_profile_name
);
749 /* Load integer boolean options */
750 for (i
= 0; int_options
[i
].opt_name
; i
++)
751 *int_options
[i
].opt_addr
=
752 mc_config_get_int(mc_main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
, *int_options
[i
].opt_addr
);
754 /* Load string options */
755 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
756 *str_options
[i
].opt_addr
=
757 mc_config_get_string (mc_main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
, str_options
[i
].opt_defval
);
763 startup_left_mode
= setup__load_panel_state ("New Left Panel");
764 startup_right_mode
= setup__load_panel_state ("New Right Panel");
766 /* At least one of the panels is a listing panel */
767 if (startup_left_mode
!= view_listing
&& startup_right_mode
!=view_listing
)
768 startup_left_mode
= view_listing
;
771 buffer
= mc_config_get_string(mc_panels_config
, "Dirs", "other_dir", ".");
772 if (vfs_file_is_local (buffer
))
778 boot_current_is_left
=
779 mc_config_get_int(mc_panels_config
, "Dirs", "current_is_left", 1);
782 ftpfs_proxy_host
= mc_config_get_string(mc_main_config
, "Misc", "ftp_proxy_host", "gate");
784 setup_color_string
= mc_config_get_string(mc_main_config
, "Misc", "find_ignore_dirs", "");
785 if (setup_color_string
[0])
786 find_ignore_dirs
= g_strconcat (":", setup_color_string
, ":", (char *) NULL
);
787 g_free(setup_color_string
);
789 /* The default color and the terminal dependent color */
790 setup_color_string
= mc_config_get_string(mc_main_config
, "Colors", "base_color", "");
791 term_color_string
= mc_config_get_string(mc_main_config
, "Colors", getenv ("TERM"), "");
792 color_terminal_string
= mc_config_get_string(mc_main_config
, "Colors", "color_terminals", "");
794 /* Load the directory history */
795 /* directory_history_load (); */
796 /* Remove the temporal entries */
797 #if defined(USE_VFS) && defined (USE_NETCODE)
798 ftpfs_init_passwd ();
799 #endif /* USE_VFS && USE_NETCODE */
802 if ( load_codepages_list() > 0 ) {
803 buffer
= mc_config_get_string(mc_main_config
, "Misc", "display_codepage", "");
804 if ( buffer
[0] != '\0' )
806 display_codepage
= get_codepage_index( buffer
);
807 cp_display
= get_codepage_id (display_codepage
);
810 buffer
= mc_config_get_string(mc_main_config
, "Misc", "source_codepage", "");
811 if ( buffer
[0] != '\0' )
813 source_codepage
= get_codepage_index( buffer
);
814 cp_source
= get_codepage_id (source_codepage
);
818 init_translation_table( source_codepage
, display_codepage
);
819 if ( get_codepage_id( display_codepage
) )
820 utf8_display
= str_isutf8 (get_codepage_id( display_codepage
));
821 #endif /* HAVE_CHARSET */
824 #if defined(USE_VFS) && defined (USE_NETCODE)
830 buffer
= mc_config_get_string(mc_main_config
, "Misc", "ftpfs_password", "");
837 #endif /* USE_VFS && USE_NETCODE */
844 g_free (profile_name
);
845 g_free (global_profile_name
);
846 g_free (color_terminal_string
);
847 g_free (term_color_string
);
848 g_free (setup_color_string
);
849 g_free (panels_profile_name
);
850 mc_config_deinit (mc_main_config
);
851 mc_config_deinit (mc_panels_config
);
853 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
854 g_free (*str_options
[i
].opt_addr
);
858 /* directory_history_free (); */
862 load_keys_from_section (const char *terminal
, mc_config_t
*cfg
)
865 gchar
**profile_keys
, **keys
;
866 gchar
**values
, **curr_values
;
867 char *valcopy
, *value
;
869 gsize len
, values_len
;
874 section_name
= g_strconcat ("terminal:", terminal
, (char *) NULL
);
875 profile_keys
= keys
= mc_config_get_keys (cfg
, section_name
, &len
);
877 while (*profile_keys
){
879 /* copy=other causes all keys from [terminal:other] to be loaded. */
880 if (g_strcasecmp (*profile_keys
, "copy") == 0) {
881 valcopy
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
882 load_keys_from_section (valcopy
, cfg
);
887 curr_values
= values
= mc_config_get_string_list (cfg
, section_name
, *profile_keys
, &values_len
);
889 key_code
= lookup_key (*profile_keys
, NULL
);
892 while (*curr_values
){
893 valcopy
= convert_controls (*curr_values
);
894 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
899 value
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
900 valcopy
= convert_controls (value
);
901 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
911 g_free (section_name
);
914 void load_key_defs (void)
917 * Load keys from mc.lib before ~/.mc/ini, so that the user
918 * definitions override global settings.
920 mc_config_t
*mc_global_config
;
922 mc_global_config
= mc_config_init(global_profile_name
);
923 if (mc_global_config
!= NULL
)
925 load_keys_from_section ("general", mc_global_config
);
926 load_keys_from_section (getenv ("TERM"), mc_global_config
);
927 mc_config_deinit(mc_global_config
);
929 load_keys_from_section ("general", mc_main_config
);
930 load_keys_from_section (getenv ("TERM"), mc_main_config
);
935 load_keymap_from_section (const char *section_name
, GArray
*keymap
, mc_config_t
*cfg
)
937 gchar
**profile_keys
, **keys
;
938 gchar
**values
, **curr_values
;
939 char *valcopy
, *value
;
941 gsize len
, values_len
;
946 profile_keys
= keys
= mc_config_get_keys (cfg
, section_name
, &len
);
948 while (*profile_keys
) {
949 curr_values
= values
= mc_config_get_string_list (cfg
, section_name
, *profile_keys
, &values_len
);
950 action
= lookup_action (*profile_keys
);
953 while (*curr_values
){
954 valcopy
= convert_controls (*curr_values
);
955 keybind_cmd_bind (keymap
, valcopy
, action
);
960 value
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
961 valcopy
= convert_controls (value
);
962 //define_sequence (key_code, valcopy, MCKEY_NOACTION);
975 load_keymap_defs (void)
978 * Load keymap from GLOBAL_KEYMAP_FILE before ~/.mc/keymap, so that the user
979 * definitions override global settings.
981 mc_config_t
*mc_global_keymap
;
983 mc_global_keymap
= load_setup_get_keymap_profile_config();
985 if (mc_global_keymap
!= NULL
)
987 #ifdef USE_INTERNAL_EDIT
988 editor_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
989 load_keymap_from_section ("editor", editor_keymap
, mc_global_keymap
);
990 editor_x_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
991 load_keymap_from_section ("editor:xmap", editor_x_keymap
, mc_global_keymap
);
994 viewer_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
995 load_keymap_from_section ("viewer", viewer_keymap
, mc_global_keymap
);
996 viewer_hex_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
997 load_keymap_from_section ("viewer:hex", viewer_hex_keymap
, mc_global_keymap
);
999 main_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1000 load_keymap_from_section ("main", main_keymap
, mc_global_keymap
);
1001 main_x_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1002 load_keymap_from_section ("main:xmap", main_x_keymap
, mc_global_keymap
);
1004 panel_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1005 load_keymap_from_section ("panel", panel_keymap
, mc_global_keymap
);
1007 input_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1008 load_keymap_from_section ("input", input_keymap
, mc_global_keymap
);
1010 mc_config_deinit (mc_global_keymap
);
1015 free_keymap_defs (void)
1017 #ifdef USE_INTERNAL_EDIT
1018 g_array_free (editor_keymap
, TRUE
);
1019 g_array_free (editor_x_keymap
, TRUE
);
1021 g_array_free (viewer_keymap
, TRUE
);
1022 g_array_free (viewer_hex_keymap
, TRUE
);
1023 g_array_free (main_keymap
, TRUE
);
1024 g_array_free (main_x_keymap
, TRUE
);
1025 g_array_free (panel_keymap
, TRUE
);
1026 g_array_free (input_keymap
, TRUE
);
1030 setup_save_config_show_error(const char *filename
, GError
**error
)
1032 if (error
== NULL
|| *error
== NULL
)
1035 message (D_ERROR
, MSG_ERROR
, _("Cannot save file %s:\n%s"),
1036 filename
, (*error
)->message
);
1038 g_error_free(*error
);