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
},
233 { "select_flags", &select_flags
},
237 static const struct {
238 const char *opt_name
;
240 const char *opt_defval
;
242 #ifdef USE_INTERNAL_EDIT
243 { "editor_backup_extension", &option_backup_ext
, "~" },
249 panel_save_setup (struct WPanel
*panel
, const char *section
)
254 mc_config_set_int(mc_panels_config
, section
, "reverse", panel
->reverse
);
255 mc_config_set_int(mc_panels_config
, section
, "case_sensitive", panel
->case_sensitive
);
256 mc_config_set_int(mc_panels_config
, section
, "exec_first", panel
->exec_first
);
259 mc_config_set_string(mc_panels_config
, section
, "sort_order", panel
->current_sort_field
->id
);
261 for (i
= 0; list_types
[i
].key
; i
++)
262 if (list_types
[i
].list_type
== panel
->list_type
){
263 mc_config_set_string(mc_panels_config
, section
, "list_mode", list_types
[i
].key
);
267 mc_config_set_string(mc_panels_config
, section
, "user_format", panel
->user_format
);
269 for (i
= 0; i
< LIST_TYPES
; i
++){
270 buffer
= g_strdup_printf("user_status%d", i
);
271 mc_config_set_string(mc_panels_config
, section
, buffer
, panel
->user_status_format
[i
]);
275 mc_config_set_int(mc_panels_config
, section
, "user_mini_status", panel
->user_mini_status
);
284 profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
286 /* Save integer options */
287 for (i
= 0; layout
[i
].opt_name
; i
++){
288 mc_config_set_int(mc_main_config
, "Layout", layout
[i
].opt_name
, *layout
[i
].opt_addr
);
290 mc_config_save_to_file (mc_main_config
, profile
, NULL
);
296 save_configure (void)
299 GError
*error
= NULL
;
302 profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
304 /* Save integer options */
305 for (i
= 0; int_options
[i
].opt_name
; i
++)
306 mc_config_set_int(mc_main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
, *int_options
[i
].opt_addr
);
308 /* Save string options */
309 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
310 mc_config_set_string(mc_main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
, *str_options
[i
].opt_addr
);
312 if (! mc_config_save_to_file (mc_main_config
, profile
, &error
))
313 setup_save_config_show_error(profile
, &error
);
319 panel_save_type (const char *section
, int type
)
323 for (i
= 0; panel_types
[i
].opt_name
; i
++)
324 if (panel_types
[i
].opt_type
== type
){
325 mc_config_set_string(mc_panels_config
, section
,
326 "display", panel_types
[i
].opt_name
);
332 save_panel_types (void)
336 type
= get_display_type (0);
337 panel_save_type ("New Left Panel", type
);
338 if (type
== view_listing
)
339 panel_save_setup (left_panel
, left_panel
->panel_name
);
340 type
= get_display_type (1);
341 panel_save_type ("New Right Panel", type
);
342 if (type
== view_listing
)
343 panel_save_setup (right_panel
, right_panel
->panel_name
);
345 mc_config_set_string (mc_panels_config
, "Dirs" , "other_dir",
346 get_panel_dir_for (other_panel
));
348 if (current_panel
!= NULL
)
349 mc_config_set_string (mc_panels_config
, "Dirs" , "current_is_left",
350 get_current_index () == 0 ? "1" : "0");
352 if (mc_panels_config
->ini_path
== NULL
)
353 mc_panels_config
->ini_path
= g_strdup(panels_profile_name
);
355 mc_config_del_group (mc_panels_config
, "Temporal:New Left Panel");
356 mc_config_del_group (mc_panels_config
, "Temporal:New Right Panel");
358 mc_config_save_file (mc_panels_config
, NULL
);
377 /* directory_history_save (); */
379 #if defined(USE_VFS) && defined (USE_NETCODE)
380 mc_config_set_string(mc_main_config
, "Misc" , "ftpfs_password",
381 ftpfs_anonymous_passwd
);
382 if (ftpfs_proxy_host
)
383 mc_config_set_string(mc_main_config
, "Misc" , "ftp_proxy_host",
385 #endif /* USE_VFS && USE_NETCODE */
388 mc_config_set_string(mc_main_config
, "Misc" , "display_codepage",
389 get_codepage_id( display_codepage
));
390 mc_config_set_string(mc_main_config
, "Misc" , "source_codepage",
391 get_codepage_id( source_codepage
));
392 #endif /* HAVE_CHARSET */
393 tmp_profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
394 ret
= mc_config_save_to_file (mc_main_config
, tmp_profile
, NULL
);
396 g_free (tmp_profile
);
402 panel_load_setup (WPanel
*panel
, const char *section
)
407 panel
->reverse
= mc_config_get_int(mc_panels_config
, section
, "reverse", 0);
408 panel
->case_sensitive
= mc_config_get_int(mc_panels_config
, section
, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT
);
409 panel
->exec_first
= mc_config_get_int(mc_panels_config
, section
, "exec_first", 0);
411 /* Load sort order */
412 buffer
= mc_config_get_string(mc_panels_config
, section
, "sort_order", "name");
413 panel
->current_sort_field
= panel_get_field_by_id(buffer
);
414 if (panel
->current_sort_field
== NULL
)
415 panel
->current_sort_field
= panel_get_field_by_id("name");
419 /* Load the listing mode */
420 buffer
= mc_config_get_string(mc_panels_config
, section
, "list_mode", "full");
421 panel
->list_type
= list_full
;
422 for (i
= 0; list_types
[i
].key
; i
++)
423 if ( g_strcasecmp (list_types
[i
].key
, buffer
) == 0){
424 panel
->list_type
= list_types
[i
].list_type
;
430 g_free (panel
->user_format
);
431 panel
->user_format
= mc_config_get_string(mc_panels_config
, section
, "user_format", DEFAULT_USER_FORMAT
);
433 for (i
= 0; i
< LIST_TYPES
; i
++){
434 g_free (panel
->user_status_format
[i
]);
435 buffer
= g_strdup_printf("user_status%d",i
);
436 panel
->user_status_format
[i
] =
437 mc_config_get_string(mc_panels_config
, section
, buffer
, DEFAULT_USER_FORMAT
);
441 panel
->user_mini_status
=
442 mc_config_get_int(mc_panels_config
, section
, "user_mini_status", 0);
451 for (i
= 0; layout
[i
].opt_name
; i
++)
452 *layout
[i
].opt_addr
=
453 mc_config_get_int(mc_main_config
,"Layout", layout
[i
].opt_name
, *layout
[i
].opt_addr
);
457 setup__load_panel_state (const char *section
)
462 int mode
= view_listing
;
464 /* Load the display mode */
465 buffer
= mc_config_get_string(mc_panels_config
, section
, "display", "listing");
467 for (i
= 0; panel_types
[i
].opt_name
; i
++)
468 if ( g_strcasecmp (panel_types
[i
].opt_name
, buffer
) == 0){
469 mode
= panel_types
[i
].opt_type
;
477 setup__is_cfg_group_must_panel_config(const char *grp
)
480 ! strcasecmp("Dirs",grp
) ||
481 ! strcasecmp("Temporal:New Right Panel",grp
) ||
482 ! strcasecmp("Temporal:New Left Panel",grp
) ||
483 ! strcasecmp("New Left Panel",grp
) ||
484 ! strcasecmp("New Right Panel",grp
)
491 setup__move_panels_config_into_separate_file(const char*profile
)
493 mc_config_t
*tmp_cfg
;
494 char **groups
, **curr_grp
;
495 const char *need_grp
;
498 if (!exist_file(profile
))
501 tmp_cfg
= mc_config_init(profile
);
505 curr_grp
= groups
= mc_config_get_groups (tmp_cfg
, &groups_count
);
508 mc_config_deinit(tmp_cfg
);
513 if ( setup__is_cfg_group_must_panel_config(*curr_grp
) == NULL
)
515 mc_config_del_group (tmp_cfg
, *curr_grp
);
520 mc_config_save_to_file (tmp_cfg
, panels_profile_name
, NULL
);
521 mc_config_deinit(tmp_cfg
);
523 tmp_cfg
= mc_config_init(profile
);
534 need_grp
= setup__is_cfg_group_must_panel_config(*curr_grp
);
535 if ( need_grp
!= NULL
)
537 mc_config_del_group (tmp_cfg
, need_grp
);
542 mc_config_save_file (tmp_cfg
, NULL
);
543 mc_config_deinit(tmp_cfg
);
548 Get name of config file.
551 if not NULL, then config also search into specified subdir
553 \param config_file_name
554 If specified filename is relative, then will search in standart patches.
557 Newly allocated path to config name or NULL if file not found
559 If config_file_name is a relative path, then search config in stantart pathes */
561 load_setup_get_full_config_name(const char *subdir
, const char *config_file_name
)
564 TODO: IMHO, in future this function must be placed into mc_config module.
565 Also, need to rename stupid mc_home and mc_home_alt to mc_sysconfdir and mc_datadir;
566 home_mc => mc_user_homedir
568 char *lc_basename
, *ret
;
570 if (config_file_name
== NULL
)
573 if (g_path_is_absolute (config_file_name
))
574 return g_strdup(config_file_name
);
577 lc_basename
= g_path_get_basename(config_file_name
);
578 if (lc_basename
== NULL
)
583 ret
= g_build_filename (home_dir
, MC_USERCONF_DIR
, subdir
, lc_basename
, NULL
);
585 ret
= g_build_filename (home_dir
, MC_USERCONF_DIR
, lc_basename
, NULL
);
587 if (exist_file(ret
)) {
595 ret
= g_build_filename (mc_home
, subdir
, lc_basename
, NULL
);
597 ret
= g_build_filename (mc_home
, lc_basename
, NULL
);
599 if (exist_file(ret
)) {
606 ret
= g_build_filename (mc_home_alt
, subdir
, lc_basename
, NULL
);
608 ret
= g_build_filename (mc_home_alt
, lc_basename
, NULL
);
610 if (exist_file(ret
)) {
621 Create new mc_config object from specified ini-file or
622 append data to existing mc_config object from ini-file
626 load_setup_init_config_from_file(mc_config_t
**config
, const char *fname
)
629 TODO: IMHO, in future this function must be placed into mc_config module.
631 if (exist_file(fname
)) {
633 mc_config_read_file( *config
, fname
);
635 *config
= mc_config_init(fname
);
642 load_setup_get_keymap_profile_config(void)
645 TODO: IMHO, in future this function must be placed into mc_config module.
647 mc_config_t
*keymap_config
= NULL
;
649 char *fname
, *fname2
;
651 /* 1) /usr/share/mc (mc_home_alt) */
652 fname
= g_build_filename (mc_home_alt
, GLOBAL_KEYMAP_FILE
, NULL
);
653 load_setup_init_config_from_file( &keymap_config
, fname
);
656 /* 2) /etc/mc (mc_home) */
657 fname
= g_build_filename (mc_home
, GLOBAL_KEYMAP_FILE
, NULL
);
658 load_setup_init_config_from_file( &keymap_config
, fname
);
661 /* 3) ~/.mc (home_dir?) */
662 fname
= g_build_filename (home_dir
, MC_USERCONF_DIR
, GLOBAL_KEYMAP_FILE
, NULL
);
663 load_setup_init_config_from_file( &keymap_config
, fname
);
666 /* 4) main config; [Midnight Commander] -> keymap*/
668 fname2
= mc_config_get_string(mc_main_config
, CONFIG_APP_SECTION
, "keymap" , GLOBAL_KEYMAP_FILE
);
669 fname
= load_setup_get_full_config_name(NULL
, fname2
);
672 load_setup_init_config_from_file( &keymap_config
, fname
);
677 /* 5) getenv("MC_KEYMAP") */
678 fname
= load_setup_get_full_config_name(NULL
, g_getenv ("MC_KEYMAP"));
681 load_setup_init_config_from_file( &keymap_config
, fname
);
685 /* 6) --keymap=<keymap> */
686 fname
= load_setup_get_full_config_name(NULL
, mc_args__keymap_file
);
689 load_setup_init_config_from_file( &keymap_config
, fname
);
693 return keymap_config
;
705 profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
706 if (!exist_file (profile
)){
707 inifile
= concat_dir_and_file (mc_home
, "mc.ini");
708 if (exist_file (inifile
)){
713 inifile
= concat_dir_and_file (mc_home_alt
, "mc.ini");
714 if (exist_file (inifile
)) {
722 profile_name
= profile
;
734 profile
= setup_init ();
736 /* mc.lib is common for all users, but has priority lower than
737 ~/.mc/ini. FIXME: it's only used for keys and treestore now */
738 global_profile_name
= concat_dir_and_file (mc_home
, MC_GLOBAL_CONFIG_FILE
);
739 if (!exist_file(global_profile_name
)) {
740 g_free (global_profile_name
);
741 global_profile_name
= concat_dir_and_file (mc_home_alt
, MC_GLOBAL_CONFIG_FILE
);
744 panels_profile_name
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_PANELS_FILE
, NULL
);
746 mc_main_config
= mc_config_init(profile
);
748 if (!exist_file(panels_profile_name
))
749 setup__move_panels_config_into_separate_file(profile
);
751 mc_panels_config
= mc_config_init(panels_profile_name
);
753 /* Load integer boolean options */
754 for (i
= 0; int_options
[i
].opt_name
; i
++)
755 *int_options
[i
].opt_addr
=
756 mc_config_get_int(mc_main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
, *int_options
[i
].opt_addr
);
758 /* Load string options */
759 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
760 *str_options
[i
].opt_addr
=
761 mc_config_get_string (mc_main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
, str_options
[i
].opt_defval
);
767 startup_left_mode
= setup__load_panel_state ("New Left Panel");
768 startup_right_mode
= setup__load_panel_state ("New Right Panel");
770 /* At least one of the panels is a listing panel */
771 if (startup_left_mode
!= view_listing
&& startup_right_mode
!=view_listing
)
772 startup_left_mode
= view_listing
;
775 buffer
= mc_config_get_string(mc_panels_config
, "Dirs", "other_dir", ".");
776 if (vfs_file_is_local (buffer
))
782 boot_current_is_left
=
783 mc_config_get_int(mc_panels_config
, "Dirs", "current_is_left", 1);
786 ftpfs_proxy_host
= mc_config_get_string(mc_main_config
, "Misc", "ftp_proxy_host", "gate");
788 setup_color_string
= mc_config_get_string(mc_main_config
, "Misc", "find_ignore_dirs", "");
789 if (setup_color_string
[0])
790 find_ignore_dirs
= g_strconcat (":", setup_color_string
, ":", (char *) NULL
);
791 g_free(setup_color_string
);
793 /* The default color and the terminal dependent color */
794 setup_color_string
= mc_config_get_string(mc_main_config
, "Colors", "base_color", "");
795 term_color_string
= mc_config_get_string(mc_main_config
, "Colors", getenv ("TERM"), "");
796 color_terminal_string
= mc_config_get_string(mc_main_config
, "Colors", "color_terminals", "");
798 /* Load the directory history */
799 /* directory_history_load (); */
800 /* Remove the temporal entries */
801 #if defined(USE_VFS) && defined (USE_NETCODE)
802 ftpfs_init_passwd ();
803 #endif /* USE_VFS && USE_NETCODE */
806 if ( load_codepages_list() > 0 ) {
807 buffer
= mc_config_get_string(mc_main_config
, "Misc", "display_codepage", "");
808 if ( buffer
[0] != '\0' )
810 display_codepage
= get_codepage_index( buffer
);
811 cp_display
= get_codepage_id (display_codepage
);
814 buffer
= mc_config_get_string(mc_main_config
, "Misc", "source_codepage", "");
815 if ( buffer
[0] != '\0' )
817 source_codepage
= get_codepage_index( buffer
);
818 cp_source
= get_codepage_id (source_codepage
);
822 init_translation_table( source_codepage
, display_codepage
);
823 if ( get_codepage_id( display_codepage
) )
824 utf8_display
= str_isutf8 (get_codepage_id( display_codepage
));
825 #endif /* HAVE_CHARSET */
828 #if defined(USE_VFS) && defined (USE_NETCODE)
834 buffer
= mc_config_get_string(mc_main_config
, "Misc", "ftpfs_password", "");
841 #endif /* USE_VFS && USE_NETCODE */
848 g_free (profile_name
);
849 g_free (global_profile_name
);
850 g_free (color_terminal_string
);
851 g_free (term_color_string
);
852 g_free (setup_color_string
);
853 g_free (panels_profile_name
);
854 mc_config_deinit (mc_main_config
);
855 mc_config_deinit (mc_panels_config
);
857 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
858 g_free (*str_options
[i
].opt_addr
);
862 /* directory_history_free (); */
866 load_keys_from_section (const char *terminal
, mc_config_t
*cfg
)
869 gchar
**profile_keys
, **keys
;
870 gchar
**values
, **curr_values
;
871 char *valcopy
, *value
;
873 gsize len
, values_len
;
878 section_name
= g_strconcat ("terminal:", terminal
, (char *) NULL
);
879 profile_keys
= keys
= mc_config_get_keys (cfg
, section_name
, &len
);
881 while (*profile_keys
){
883 /* copy=other causes all keys from [terminal:other] to be loaded. */
884 if (g_strcasecmp (*profile_keys
, "copy") == 0) {
885 valcopy
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
886 load_keys_from_section (valcopy
, cfg
);
891 curr_values
= values
= mc_config_get_string_list (cfg
, section_name
, *profile_keys
, &values_len
);
893 key_code
= lookup_key (*profile_keys
, NULL
);
896 while (*curr_values
){
897 valcopy
= convert_controls (*curr_values
);
898 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
903 value
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
904 valcopy
= convert_controls (value
);
905 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
915 g_free (section_name
);
918 void load_key_defs (void)
921 * Load keys from mc.lib before ~/.mc/ini, so that the user
922 * definitions override global settings.
924 mc_config_t
*mc_global_config
;
926 mc_global_config
= mc_config_init(global_profile_name
);
927 if (mc_global_config
!= NULL
)
929 load_keys_from_section ("general", mc_global_config
);
930 load_keys_from_section (getenv ("TERM"), mc_global_config
);
931 mc_config_deinit(mc_global_config
);
933 load_keys_from_section ("general", mc_main_config
);
934 load_keys_from_section (getenv ("TERM"), mc_main_config
);
939 load_keymap_from_section (const char *section_name
, GArray
*keymap
, mc_config_t
*cfg
)
941 gchar
**profile_keys
, **keys
;
942 gchar
**values
, **curr_values
;
943 char *valcopy
, *value
;
945 gsize len
, values_len
;
950 profile_keys
= keys
= mc_config_get_keys (cfg
, section_name
, &len
);
952 while (*profile_keys
) {
953 curr_values
= values
= mc_config_get_string_list (cfg
, section_name
, *profile_keys
, &values_len
);
954 action
= lookup_action (*profile_keys
);
957 while (*curr_values
){
958 valcopy
= convert_controls (*curr_values
);
959 keybind_cmd_bind (keymap
, valcopy
, action
);
964 value
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
965 valcopy
= convert_controls (value
);
966 //define_sequence (key_code, valcopy, MCKEY_NOACTION);
979 load_keymap_defs (void)
982 * Load keymap from GLOBAL_KEYMAP_FILE before ~/.mc/keymap, so that the user
983 * definitions override global settings.
985 mc_config_t
*mc_global_keymap
;
987 mc_global_keymap
= load_setup_get_keymap_profile_config();
989 if (mc_global_keymap
!= NULL
)
991 #ifdef USE_INTERNAL_EDIT
992 editor_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
993 load_keymap_from_section ("editor", editor_keymap
, mc_global_keymap
);
994 editor_x_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
995 load_keymap_from_section ("editor:xmap", editor_x_keymap
, mc_global_keymap
);
998 viewer_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
999 load_keymap_from_section ("viewer", viewer_keymap
, mc_global_keymap
);
1000 viewer_hex_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1001 load_keymap_from_section ("viewer:hex", viewer_hex_keymap
, mc_global_keymap
);
1003 main_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1004 load_keymap_from_section ("main", main_keymap
, mc_global_keymap
);
1005 main_x_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1006 load_keymap_from_section ("main:xmap", main_x_keymap
, mc_global_keymap
);
1008 panel_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1009 load_keymap_from_section ("panel", panel_keymap
, mc_global_keymap
);
1011 input_keymap
= g_array_new (TRUE
, FALSE
, sizeof (global_keymap_t
));
1012 load_keymap_from_section ("input", input_keymap
, mc_global_keymap
);
1014 mc_config_deinit (mc_global_keymap
);
1019 free_keymap_defs (void)
1021 #ifdef USE_INTERNAL_EDIT
1022 g_array_free (editor_keymap
, TRUE
);
1023 g_array_free (editor_x_keymap
, TRUE
);
1025 g_array_free (viewer_keymap
, TRUE
);
1026 g_array_free (viewer_hex_keymap
, TRUE
);
1027 g_array_free (main_keymap
, TRUE
);
1028 g_array_free (main_x_keymap
, TRUE
);
1029 g_array_free (panel_keymap
, TRUE
);
1030 g_array_free (input_keymap
, TRUE
);
1034 setup_save_config_show_error(const char *filename
, GError
**error
)
1036 if (error
== NULL
|| *error
== NULL
)
1039 message (D_ERROR
, MSG_ERROR
, _("Cannot save file %s:\n%s"),
1040 filename
, (*error
)->message
);
1042 g_error_free(*error
);