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 */
55 #include "../vfs/gc.h"
63 # include "../vfs/ftpfs.h"
64 # include "../vfs/fish.h"
67 #ifdef USE_INTERNAL_EDIT
68 # include "../edit/edit.h"
71 #include "../src/strutil.h" /* str_isutf8 () */
74 extern char *find_ignore_dirs
;
76 extern int num_history_items_recorded
;
78 char *profile_name
; /* .mc/ini */
79 char *global_profile_name
; /* mc.lib */
80 char *panels_profile_name
; /* .mc/panels.ini */
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 */
97 { "full", list_full
},
98 { "brief", list_brief
},
99 { "long", list_long
},
100 { "user", list_user
},
104 static const struct {
105 const char *opt_name
;
108 { "listing", view_listing
},
109 { "quickview", view_quick
},
110 { "info", view_info
},
111 { "tree", view_tree
},
115 static const struct {
116 const char *opt_name
;
119 { "equal_split", &equal_split
},
120 { "first_panel_size", &first_panel_size
},
121 { "message_visible", &message_visible
},
122 { "keybar_visible", &keybar_visible
},
123 { "xterm_title", &xterm_title
},
124 { "output_lines", &output_lines
},
125 { "command_prompt", &command_prompt
},
126 { "menubar_visible", &menubar_visible
},
127 { "show_mini_info", &show_mini_info
},
128 { "permission_mode", &permission_mode
},
129 { "filetype_mode", &filetype_mode
},
130 { "free_space", &free_space
},
134 static const struct {
135 const char *opt_name
;
138 { "show_backups", &show_backups
},
139 { "kilobyte_si", &kilobyte_si
},
140 { "show_dot_files", &show_dot_files
},
141 { "verbose", &verbose
},
142 { "mark_moves_down", &mark_moves_down
},
143 { "pause_after_run", &pause_after_run
},
144 { "shell_patterns", &easy_patterns
},
145 { "auto_save_setup", &auto_save_setup
},
146 { "auto_menu", &auto_menu
},
147 { "use_internal_view", &use_internal_view
},
148 { "use_internal_edit", &use_internal_edit
},
149 { "clear_before_exec", &clear_before_exec
},
150 { "mix_all_files", &mix_all_files
},
151 { "fast_reload", &fast_reload
},
152 { "fast_reload_msg_shown", &fast_reload_w
},
153 { "confirm_delete", &confirm_delete
},
154 { "confirm_overwrite", &confirm_overwrite
},
155 { "confirm_execute", &confirm_execute
},
156 { "confirm_exit", &confirm_exit
},
157 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete
},
158 { "safe_delete", &safe_delete
},
159 { "mouse_repeat_rate", &mou_auto_repeat
},
160 { "double_click_speed", &double_click_speed
},
162 { "eight_bit_clean", &eight_bit_clean
},
163 { "full_eight_bits", &full_eight_bits
},
164 #endif /* !HAVE_CHARSET */
165 { "use_8th_bit_as_meta", &use_8th_bit_as_meta
},
166 { "confirm_view_dir", &confirm_view_dir
},
167 { "mouse_move_pages", &mouse_move_pages
},
168 { "mouse_move_pages_viewer", &mcview_mouse_move_pages
},
169 { "mouse_close_dialog", &mouse_close_dialog
},
170 { "fast_refresh", &fast_refresh
},
171 { "navigate_with_arrows", &navigate_with_arrows
},
172 { "drop_menus", &drop_menus
},
173 { "wrap_mode", &mcview_global_wrap_mode
},
174 { "old_esc_mode", &old_esc_mode
},
175 { "cd_symlinks", &cd_symlinks
},
176 { "show_all_if_ambiguous", &show_all_if_ambiguous
},
177 { "max_dirt_limit", &mcview_max_dirt_limit
},
178 { "torben_fj_mode", &torben_fj_mode
},
179 { "use_file_to_guess_type", &use_file_to_check_type
},
180 { "alternate_plus_minus", &alternate_plus_minus
},
181 { "only_leading_plus_minus", &only_leading_plus_minus
},
182 { "show_output_starts_shell", &output_starts_shell
},
183 { "panel_scroll_pages", &panel_scroll_pages
},
184 { "xtree_mode", &xtree_mode
},
185 { "num_history_items_recorded", &num_history_items_recorded
},
186 { "file_op_compute_totals", &file_op_compute_totals
},
187 { "skip_check_codeset", &skip_check_codeset
},
189 { "vfs_timeout", &vfs_timeout
},
191 { "ftpfs_directory_timeout", &ftpfs_directory_timeout
},
192 { "use_netrc", &use_netrc
},
193 { "ftpfs_retry_seconds", &ftpfs_retry_seconds
},
194 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy
},
195 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections
},
196 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options
},
197 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls
},
198 { "fish_directory_timeout", &fish_directory_timeout
},
199 #endif /* USE_NETCODE */
201 #ifdef USE_INTERNAL_EDIT
202 { "editor_word_wrap_line_length", &option_word_wrap_line_length
},
203 { "editor_key_emulation", &edit_key_emulation
},
204 { "editor_tab_spacing", &option_tab_spacing
},
205 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces
},
206 { "editor_return_does_auto_indent", &option_return_does_auto_indent
},
207 { "editor_backspace_through_tabs", &option_backspace_through_tabs
},
208 { "editor_fake_half_tabs", &option_fake_half_tabs
},
209 { "editor_option_save_mode", &option_save_mode
},
210 { "editor_option_save_position", &option_save_position
},
211 { "editor_option_auto_para_formatting", &option_auto_para_formatting
},
212 { "editor_option_typewriter_wrap", &option_typewriter_wrap
},
213 { "editor_edit_confirm_save", &edit_confirm_save
},
214 { "editor_syntax_highlighting", &option_syntax_highlighting
},
215 { "editor_persistent_selections", &option_persistent_selections
},
216 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol
},
217 { "editor_visible_tabs", &visible_tabs
},
218 { "editor_visible_spaces", &visible_tws
},
219 { "editor_line_state", &option_line_state
},
220 { "editor_simple_statusbar", &simple_statusbar
},
221 #endif /* USE_INTERNAL_EDIT */
223 { "nice_rotating_dash", &nice_rotating_dash
},
224 { "horizontal_split", &horizontal_split
},
225 { "mcview_remember_file_position", &mcview_remember_file_position
},
226 { "auto_fill_mkdir_name", &auto_fill_mkdir_name
},
227 { "reverse_files_only", &reverse_files_only
},
231 static const struct {
232 const char *opt_name
;
234 const char *opt_defval
;
236 #ifdef USE_INTERNAL_EDIT
237 { "editor_backup_extension", &option_backup_ext
, "~" },
243 panel_save_setup (struct WPanel
*panel
, const char *section
)
248 mc_config_set_int(mc_panels_config
, section
, "reverse", panel
->reverse
);
249 mc_config_set_int(mc_panels_config
, section
, "case_sensitive", panel
->case_sensitive
);
250 mc_config_set_int(mc_panels_config
, section
, "exec_first", panel
->exec_first
);
253 mc_config_set_string(mc_panels_config
, section
, "sort_order", panel
->current_sort_field
->id
);
255 for (i
= 0; list_types
[i
].key
; i
++)
256 if (list_types
[i
].list_type
== panel
->list_type
){
257 mc_config_set_string(mc_panels_config
, section
, "list_mode", list_types
[i
].key
);
261 mc_config_set_string(mc_panels_config
, section
, "user_format", panel
->user_format
);
263 for (i
= 0; i
< LIST_TYPES
; i
++){
264 buffer
= g_strdup_printf("user_status%d", i
);
265 mc_config_set_string(mc_panels_config
, section
, buffer
, panel
->user_status_format
[i
]);
269 mc_config_set_int(mc_panels_config
, section
, "user_mini_status", panel
->user_mini_status
);
278 profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
280 /* Save integer options */
281 for (i
= 0; layout
[i
].opt_name
; i
++){
282 mc_config_set_int(mc_main_config
, "Layout", layout
[i
].opt_name
, *layout
[i
].opt_addr
);
284 mc_config_save_to_file (mc_main_config
, profile
);
290 save_configure (void)
295 profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
297 /* Save integer options */
298 for (i
= 0; int_options
[i
].opt_name
; i
++)
299 mc_config_set_int(mc_main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
, *int_options
[i
].opt_addr
);
301 /* Save string options */
302 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
303 mc_config_set_string(mc_main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
, *str_options
[i
].opt_addr
);
305 mc_config_save_to_file (mc_main_config
, profile
);
310 panel_save_type (const char *section
, int type
)
314 for (i
= 0; panel_types
[i
].opt_name
; i
++)
315 if (panel_types
[i
].opt_type
== type
){
316 mc_config_set_string(mc_panels_config
, section
,
317 "display", panel_types
[i
].opt_name
);
323 save_panel_types (void)
327 type
= get_display_type (0);
328 panel_save_type ("New Left Panel", type
);
329 if (type
== view_listing
)
330 panel_save_setup (left_panel
, left_panel
->panel_name
);
331 type
= get_display_type (1);
332 panel_save_type ("New Right Panel", type
);
333 if (type
== view_listing
)
334 panel_save_setup (right_panel
, right_panel
->panel_name
);
336 mc_config_set_string (mc_panels_config
, "Dirs" , "other_dir",
337 get_panel_dir_for (other_panel
));
339 if (current_panel
!= NULL
)
340 mc_config_set_string (mc_panels_config
, "Dirs" , "current_is_left",
341 get_current_index () == 0 ? "1" : "0");
343 if (mc_panels_config
->ini_path
== NULL
)
344 mc_panels_config
->ini_path
= g_strdup(panels_profile_name
);
346 mc_config_del_group (mc_panels_config
, "Temporal:New Left Panel");
347 mc_config_del_group (mc_panels_config
, "Temporal:New Right Panel");
349 mc_config_save_file (mc_panels_config
);
367 /* directory_history_save (); */
369 #if defined(USE_VFS) && defined (USE_NETCODE)
370 mc_config_set_string(mc_main_config
, "Misc" , "ftpfs_password",
371 ftpfs_anonymous_passwd
);
372 if (ftpfs_proxy_host
)
373 mc_config_set_string(mc_main_config
, "Misc" , "ftp_proxy_host",
375 #endif /* USE_VFS && USE_NETCODE */
378 mc_config_set_string(mc_main_config
, "Misc" , "display_codepage",
379 get_codepage_id( display_codepage
));
380 mc_config_set_string(mc_main_config
, "Misc" , "source_codepage",
381 get_codepage_id( source_codepage
));
382 #endif /* HAVE_CHARSET */
383 tmp_profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
384 mc_config_save_to_file (mc_main_config
, tmp_profile
);
385 g_free (tmp_profile
);
390 panel_load_setup (WPanel
*panel
, const char *section
)
395 panel
->reverse
= mc_config_get_int(mc_panels_config
, section
, "reverse", 0);
396 panel
->case_sensitive
= mc_config_get_int(mc_panels_config
, section
, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT
);
397 panel
->exec_first
= mc_config_get_int(mc_panels_config
, section
, "exec_first", 0);
399 /* Load sort order */
400 buffer
= mc_config_get_string(mc_panels_config
, section
, "sort_order", "name");
401 panel
->current_sort_field
= panel_get_field_by_id(buffer
);
404 /* Load the listing mode */
405 buffer
= mc_config_get_string(mc_panels_config
, section
, "list_mode", "full");
406 panel
->list_type
= list_full
;
407 for (i
= 0; list_types
[i
].key
; i
++)
408 if ( g_strcasecmp (list_types
[i
].key
, buffer
) == 0){
409 panel
->list_type
= list_types
[i
].list_type
;
415 g_free (panel
->user_format
);
416 panel
->user_format
= mc_config_get_string(mc_panels_config
, section
, "user_format", DEFAULT_USER_FORMAT
);
418 for (i
= 0; i
< LIST_TYPES
; i
++){
419 g_free (panel
->user_status_format
[i
]);
420 buffer
= g_strdup_printf("user_status%d",i
);
421 panel
->user_status_format
[i
] =
422 mc_config_get_string(mc_panels_config
, section
, buffer
, DEFAULT_USER_FORMAT
);
426 panel
->user_mini_status
=
427 mc_config_get_int(mc_panels_config
, section
, "user_mini_status", 0);
436 for (i
= 0; layout
[i
].opt_name
; i
++)
437 *layout
[i
].opt_addr
=
438 mc_config_get_int(mc_main_config
,"Layout", layout
[i
].opt_name
, *layout
[i
].opt_addr
);
442 setup__load_panel_state (const char *section
)
447 int mode
= view_listing
;
449 /* Load the display mode */
450 buffer
= mc_config_get_string(mc_panels_config
, section
, "display", "listing");
452 for (i
= 0; panel_types
[i
].opt_name
; i
++)
453 if ( g_strcasecmp (panel_types
[i
].opt_name
, buffer
) == 0){
454 mode
= panel_types
[i
].opt_type
;
462 setup__is_cfg_group_must_panel_config(const char *grp
)
465 ! strcasecmp("Dirs",grp
) ||
466 ! strcasecmp("Temporal:New Right Panel",grp
) ||
467 ! strcasecmp("Temporal:New Left Panel",grp
) ||
468 ! strcasecmp("New Left Panel",grp
) ||
469 ! strcasecmp("New Right Panel",grp
)
476 setup__move_panels_config_into_separate_file(const char*profile
)
478 mc_config_t
*tmp_cfg
;
479 char **groups
, **curr_grp
;
480 const char *need_grp
;
483 if (!exist_file(profile
))
486 tmp_cfg
= mc_config_init(profile
);
490 curr_grp
= groups
= mc_config_get_groups (tmp_cfg
, &groups_count
);
493 mc_config_deinit(tmp_cfg
);
498 if ( setup__is_cfg_group_must_panel_config(*curr_grp
) == NULL
)
500 mc_config_del_group (tmp_cfg
, *curr_grp
);
505 mc_config_save_to_file (tmp_cfg
, panels_profile_name
);
506 mc_config_deinit(tmp_cfg
);
508 tmp_cfg
= mc_config_init(profile
);
519 need_grp
= setup__is_cfg_group_must_panel_config(*curr_grp
);
520 if ( need_grp
!= NULL
)
522 mc_config_del_group (tmp_cfg
, need_grp
);
527 mc_config_save_file (tmp_cfg
);
528 mc_config_deinit(tmp_cfg
);
533 Get name of config file.
536 if not NULL, then config also search into specified subdir
538 \param config_file_name
539 If specified filename is relative, then will search in standart patches.
542 Newly allocated path to config name or NULL if file not found
544 If config_file_name is a relative path, then search config in stantart pathes */
546 load_setup_get_full_config_name(const char *subdir
, const char *config_file_name
)
549 TODO: IMHO, in future this function must be placed into mc_config module.
550 Also, need to rename stupid mc_home and mc_home_alt to mc_sysconfdir and mc_datadir;
551 home_mc => mc_user_homedir
553 char *basename
, *ret
;
555 if (config_file_name
== NULL
)
558 if (g_path_is_absolute (config_file_name
))
559 return g_strdup(config_file_name
);
562 basename
= g_path_get_basename(config_file_name
);
563 if (basename
== NULL
)
568 ret
= g_build_filename (home_dir
, MC_USERCONF_DIR
, subdir
, basename
, NULL
);
570 ret
= g_build_filename (home_dir
, MC_USERCONF_DIR
, basename
, NULL
);
572 if (exist_file(ret
)) {
580 ret
= g_build_filename (mc_home
, subdir
, basename
, NULL
);
582 ret
= g_build_filename (mc_home
, basename
, NULL
);
584 if (exist_file(ret
)) {
591 ret
= g_build_filename (mc_home_alt
, subdir
, basename
, NULL
);
593 ret
= g_build_filename (mc_home_alt
, basename
, NULL
);
595 if (exist_file(ret
)) {
606 Create new mc_config object from specified ini-file or
607 append data to existing mc_config object from ini-file
611 load_setup_init_config_from_file(mc_config_t
**config
, const char *fname
)
614 TODO: IMHO, in future this function must be placed into mc_config module.
616 if (exist_file(fname
)) {
618 mc_config_read_file( *config
, fname
);
620 *config
= mc_config_init(fname
);
627 load_setup_get_keymap_profile_config(void)
630 TODO: IMHO, in future this function must be placed into mc_config module.
632 mc_config_t
*keymap_config
= NULL
;
634 char *fname
, *fname2
;
636 /* 1) /usr/share/mc (mc_home_alt) */
637 fname
= g_build_filename (mc_home_alt
, GLOBAL_KEYMAP_FILE
, NULL
);
638 load_setup_init_config_from_file( &keymap_config
, fname
);
641 /* 2) /etc/mc (mc_home) */
642 fname
= g_build_filename (mc_home
, GLOBAL_KEYMAP_FILE
, NULL
);
643 load_setup_init_config_from_file( &keymap_config
, fname
);
646 /* 3) ~/.mc (home_dir?) */
647 fname
= g_build_filename (home_dir
, MC_USERCONF_DIR
, GLOBAL_KEYMAP_FILE
, NULL
);
648 load_setup_init_config_from_file( &keymap_config
, fname
);
651 /* 4) main config; [Midnight Commander] -> keymap*/
653 fname2
= mc_config_get_string(mc_main_config
, CONFIG_APP_SECTION
, "keymap" , GLOBAL_KEYMAP_FILE
);
654 fname
= load_setup_get_full_config_name(NULL
, fname2
);
657 load_setup_init_config_from_file( &keymap_config
, fname
);
662 /* 5) getenv("MC_KEYMAP") */
663 fname
= load_setup_get_full_config_name(NULL
, g_getenv ("MC_KEYMAP"));
666 load_setup_init_config_from_file( &keymap_config
, fname
);
670 /* 6) --keymap=<keymap> */
671 fname
= load_setup_get_full_config_name(NULL
, mc_args__keymap_file
);
674 load_setup_init_config_from_file( &keymap_config
, fname
);
678 return keymap_config
;
690 profile
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_CONFIG_FILE
, NULL
);
691 if (!exist_file (profile
)){
692 inifile
= concat_dir_and_file (mc_home
, "mc.ini");
693 if (exist_file (inifile
)){
698 inifile
= concat_dir_and_file (mc_home_alt
, "mc.ini");
699 if (exist_file (inifile
)) {
707 profile_name
= profile
;
719 profile
= setup_init ();
721 /* mc.lib is common for all users, but has priority lower than
722 ~/.mc/ini. FIXME: it's only used for keys and treestore now */
723 global_profile_name
= concat_dir_and_file (mc_home
, MC_GLOBAL_CONFIG_FILE
);
724 if (!exist_file(global_profile_name
)) {
725 g_free (global_profile_name
);
726 global_profile_name
= concat_dir_and_file (mc_home_alt
, MC_GLOBAL_CONFIG_FILE
);
729 panels_profile_name
= g_build_filename (home_dir
, MC_USERCONF_DIR
, MC_PANELS_FILE
, NULL
);
731 mc_main_config
= mc_config_init(profile
);
733 if (!exist_file(panels_profile_name
))
734 setup__move_panels_config_into_separate_file(profile
);
736 mc_panels_config
= mc_config_init(panels_profile_name
);
738 /* Load integer boolean options */
739 for (i
= 0; int_options
[i
].opt_name
; i
++)
740 *int_options
[i
].opt_addr
=
741 mc_config_get_int(mc_main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
, *int_options
[i
].opt_addr
);
743 /* Load string options */
744 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
745 *str_options
[i
].opt_addr
=
746 mc_config_get_string (mc_main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
, str_options
[i
].opt_defval
);
752 startup_left_mode
= setup__load_panel_state ("New Left Panel");
753 startup_right_mode
= setup__load_panel_state ("New Right Panel");
755 /* At least one of the panels is a listing panel */
756 if (startup_left_mode
!= view_listing
&& startup_right_mode
!=view_listing
)
757 startup_left_mode
= view_listing
;
760 buffer
= mc_config_get_string(mc_panels_config
, "Dirs", "other_dir", ".");
761 if (vfs_file_is_local (buffer
))
767 boot_current_is_left
=
768 mc_config_get_int(mc_panels_config
, "Dirs", "current_is_left", 1);
771 ftpfs_proxy_host
= mc_config_get_string(mc_main_config
, "Misc", "ftp_proxy_host", "gate");
773 setup_color_string
= mc_config_get_string(mc_main_config
, "Misc", "find_ignore_dirs", "");
774 if (setup_color_string
[0])
775 find_ignore_dirs
= g_strconcat (":", setup_color_string
, ":", (char *) NULL
);
776 g_free(setup_color_string
);
778 /* The default color and the terminal dependent color */
779 setup_color_string
= mc_config_get_string(mc_main_config
, "Colors", "base_color", "");
780 term_color_string
= mc_config_get_string(mc_main_config
, "Colors", getenv ("TERM"), "");
781 color_terminal_string
= mc_config_get_string(mc_main_config
, "Colors", "color_terminals", "");
783 /* Load the directory history */
784 /* directory_history_load (); */
785 /* Remove the temporal entries */
786 #if defined(USE_VFS) && defined (USE_NETCODE)
787 ftpfs_init_passwd ();
788 #endif /* USE_VFS && USE_NETCODE */
791 if ( load_codepages_list() > 0 ) {
792 buffer
= mc_config_get_string(mc_main_config
, "Misc", "display_codepage", "");
793 if ( buffer
[0] != '\0' )
795 display_codepage
= get_codepage_index( buffer
);
796 cp_display
= get_codepage_id (display_codepage
);
799 buffer
= mc_config_get_string(mc_main_config
, "Misc", "source_codepage", "");
800 if ( buffer
[0] != '\0' )
802 source_codepage
= get_codepage_index( buffer
);
803 cp_source
= get_codepage_id (source_codepage
);
807 init_translation_table( source_codepage
, display_codepage
);
808 if ( get_codepage_id( display_codepage
) )
809 utf8_display
= str_isutf8 (get_codepage_id( display_codepage
));
810 #endif /* HAVE_CHARSET */
813 #if defined(USE_VFS) && defined (USE_NETCODE)
819 buffer
= mc_config_get_string(mc_main_config
, "Misc", "ftpfs_password", "");
826 #endif /* USE_VFS && USE_NETCODE */
828 void done_setup (void)
830 g_free (profile_name
);
831 g_free (global_profile_name
);
832 g_free(color_terminal_string
);
833 g_free(term_color_string
);
834 g_free(setup_color_string
);
835 mc_config_deinit(mc_main_config
);
836 mc_config_deinit(mc_panels_config
);
839 /* directory_history_free (); */
843 load_keys_from_section (const char *terminal
, mc_config_t
*cfg
)
846 gchar
**profile_keys
, **keys
;
847 gchar
**values
, **curr_values
;
848 char *valcopy
, *value
;
850 gsize len
, values_len
;
855 section_name
= g_strconcat ("terminal:", terminal
, (char *) NULL
);
856 profile_keys
= keys
= mc_config_get_keys (cfg
, section_name
, &len
);
858 while (*profile_keys
){
860 /* copy=other causes all keys from [terminal:other] to be loaded. */
861 if (g_strcasecmp (*profile_keys
, "copy") == 0) {
862 valcopy
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
863 load_keys_from_section (valcopy
, cfg
);
868 curr_values
= values
= mc_config_get_string_list (cfg
, section_name
, *profile_keys
, &values_len
);
870 key_code
= lookup_key (*profile_keys
);
873 while (*curr_values
){
874 valcopy
= convert_controls (*curr_values
);
875 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
880 value
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
881 valcopy
= convert_controls (value
);
882 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
892 g_free (section_name
);
895 void load_key_defs (void)
898 * Load keys from mc.lib before ~/.mc/ini, so that the user
899 * definitions override global settings.
901 mc_config_t
*mc_global_config
;
903 mc_global_config
= mc_config_init(global_profile_name
);
904 if (mc_global_config
!= NULL
)
906 load_keys_from_section ("general", mc_global_config
);
907 load_keys_from_section (getenv ("TERM"), mc_global_config
);
908 mc_config_deinit(mc_global_config
);
910 load_keys_from_section ("general", mc_main_config
);
911 load_keys_from_section (getenv ("TERM"), mc_main_config
);
916 load_keymap_from_section (const char *section_name
, GArray
*keymap
, mc_config_t
*cfg
)
918 gchar
**profile_keys
, **keys
;
919 gchar
**values
, **curr_values
;
920 char *valcopy
, *value
;
922 gsize len
, values_len
;
927 profile_keys
= keys
= mc_config_get_keys (cfg
, section_name
, &len
);
929 while (*profile_keys
) {
930 curr_values
= values
= mc_config_get_string_list (cfg
, section_name
, *profile_keys
, &values_len
);
931 action
= lookup_action (*profile_keys
);
934 while (*curr_values
){
935 valcopy
= convert_controls (*curr_values
);
936 keybind_cmd_bind (keymap
, valcopy
, action
);
941 value
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
942 valcopy
= convert_controls (value
);
943 //define_sequence (key_code, valcopy, MCKEY_NOACTION);
956 load_keymap_defs (void)
959 * Load keymap from GLOBAL_KEYMAP_FILE before ~/.mc/keymap, so that the user
960 * definitions override global settings.
962 mc_config_t
*mc_global_keymap
;
964 mc_global_keymap
= load_setup_get_keymap_profile_config();
966 if (mc_global_keymap
!= NULL
)
968 editor_keymap
= g_array_new(TRUE
, FALSE
, sizeof(global_key_map_t
));
969 load_keymap_from_section ("editor", editor_keymap
, mc_global_keymap
);
971 viewer_keymap
= g_array_new(TRUE
, FALSE
, sizeof(global_key_map_t
));
972 load_keymap_from_section ("viewer", viewer_keymap
, mc_global_keymap
);
974 viewer_hex_keymap
= g_array_new(TRUE
, FALSE
, sizeof(global_key_map_t
));
975 load_keymap_from_section ("viewer:hex", viewer_hex_keymap
, mc_global_keymap
);
977 main_keymap
= g_array_new(TRUE
, FALSE
, sizeof(global_key_map_t
));
978 load_keymap_from_section ("main", main_keymap
, mc_global_keymap
);
980 main_x_keymap
= g_array_new(TRUE
, FALSE
, sizeof(global_key_map_t
));
981 load_keymap_from_section ("main:xmap", main_x_keymap
, mc_global_keymap
);
983 panel_keymap
= g_array_new(TRUE
, FALSE
, sizeof(global_key_map_t
));
984 load_keymap_from_section ("panel", panel_keymap
, mc_global_keymap
);
986 input_keymap
= g_array_new(TRUE
, FALSE
, sizeof(global_key_map_t
));
987 load_keymap_from_section ("input", input_keymap
, mc_global_keymap
);
989 mc_config_deinit(mc_global_keymap
);