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
27 #include <sys/types.h>
35 #include "tree.h" /* xtree_mode */
36 #include "../src/mcconfig/mcconfig.h"
38 #include "mouse.h" /* To make view.h happy */
39 #include "view.h" /* For the externs */
40 #include "key.h" /* For the externs */
41 #include "hotlist.h" /* load/save/done hotlist */
42 #include "panelize.h" /* load/save/done panelize */
44 #include "menu.h" /* menubar_visible declaration */
45 #include "win.h" /* lookup_key */
47 #include "file.h" /* safe_delete */
50 #include "../vfs/gc.h"
58 # include "../vfs/ftpfs.h"
59 # include "../vfs/fish.h"
62 #ifdef USE_INTERNAL_EDIT
63 # include "../edit/edit.h"
66 #include "../src/strutil.h" /* str_isutf8 () */
69 extern char *find_ignore_dirs
;
71 extern int num_history_items_recorded
;
73 char *profile_name
; /* .mc/ini */
74 char *global_profile_name
; /* mc.lib */
75 char *panels_profile_name
; /* .mc/panels.ini */
77 char *setup_color_string
;
78 char *term_color_string
;
79 char *color_terminal_string
;
81 int startup_left_mode
;
82 int startup_right_mode
;
84 /* Ugly hack to allow panel_save_setup to work as a place holder for */
85 /* default panel values */
92 { "name", (sortfn
*) sort_name
},
93 { "extension", (sortfn
*) sort_ext
},
94 { "time", (sortfn
*) sort_time
},
95 { "atime", (sortfn
*) sort_atime
},
96 { "ctime", (sortfn
*) sort_ctime
},
97 { "size", (sortfn
*) sort_size
},
98 { "inode", (sortfn
*) sort_inode
},
99 { "unsorted", (sortfn
*) unsorted
},
103 static const struct {
107 { "full", list_full
},
108 { "brief", list_brief
},
109 { "long", list_long
},
110 { "user", list_user
},
114 static const struct {
115 const char *opt_name
;
118 { "listing", view_listing
},
119 { "quickview", view_quick
},
120 { "info", view_info
},
121 { "tree", view_tree
},
125 static const struct {
126 const char *opt_name
;
129 { "equal_split", &equal_split
},
130 { "first_panel_size", &first_panel_size
},
131 { "message_visible", &message_visible
},
132 { "keybar_visible", &keybar_visible
},
133 { "xterm_title", &xterm_title
},
134 { "output_lines", &output_lines
},
135 { "command_prompt", &command_prompt
},
136 { "menubar_visible", &menubar_visible
},
137 { "show_mini_info", &show_mini_info
},
138 { "permission_mode", &permission_mode
},
139 { "filetype_mode", &filetype_mode
},
140 { "free_space", &free_space
},
144 static const struct {
145 const char *opt_name
;
148 { "show_backups", &show_backups
},
149 { "show_dot_files", &show_dot_files
},
150 { "verbose", &verbose
},
151 { "mark_moves_down", &mark_moves_down
},
152 { "pause_after_run", &pause_after_run
},
153 { "shell_patterns", &easy_patterns
},
154 { "auto_save_setup", &auto_save_setup
},
155 { "auto_menu", &auto_menu
},
156 { "use_internal_view", &use_internal_view
},
157 { "use_internal_edit", &use_internal_edit
},
158 { "clear_before_exec", &clear_before_exec
},
159 { "mix_all_files", &mix_all_files
},
160 { "fast_reload", &fast_reload
},
161 { "fast_reload_msg_shown", &fast_reload_w
},
162 { "confirm_delete", &confirm_delete
},
163 { "confirm_overwrite", &confirm_overwrite
},
164 { "confirm_execute", &confirm_execute
},
165 { "confirm_exit", &confirm_exit
},
166 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete
},
167 { "safe_delete", &safe_delete
},
168 { "mouse_repeat_rate", &mou_auto_repeat
},
169 { "double_click_speed", &double_click_speed
},
171 { "eight_bit_clean", &eight_bit_clean
},
172 { "full_eight_bits", &full_eight_bits
},
173 #endif /* !HAVE_CHARSET */
174 { "use_8th_bit_as_meta", &use_8th_bit_as_meta
},
175 { "confirm_view_dir", &confirm_view_dir
},
176 { "mouse_move_pages", &mouse_move_pages
},
177 { "mouse_move_pages_viewer", &mouse_move_pages_viewer
},
178 { "mouse_close_dialog", &mouse_close_dialog
},
179 { "fast_refresh", &fast_refresh
},
180 { "navigate_with_arrows", &navigate_with_arrows
},
181 { "drop_menus", &drop_menus
},
182 { "wrap_mode", &global_wrap_mode
},
183 { "old_esc_mode", &old_esc_mode
},
184 { "cd_symlinks", &cd_symlinks
},
185 { "show_all_if_ambiguous", &show_all_if_ambiguous
},
186 { "max_dirt_limit", &max_dirt_limit
},
187 { "torben_fj_mode", &torben_fj_mode
},
188 { "use_file_to_guess_type", &use_file_to_check_type
},
189 { "alternate_plus_minus", &alternate_plus_minus
},
190 { "only_leading_plus_minus", &only_leading_plus_minus
},
191 { "show_output_starts_shell", &output_starts_shell
},
192 { "panel_scroll_pages", &panel_scroll_pages
},
193 { "xtree_mode", &xtree_mode
},
194 { "num_history_items_recorded", &num_history_items_recorded
},
195 { "file_op_compute_totals", &file_op_compute_totals
},
197 { "vfs_timeout", &vfs_timeout
},
199 { "ftpfs_directory_timeout", &ftpfs_directory_timeout
},
200 { "use_netrc", &use_netrc
},
201 { "ftpfs_retry_seconds", &ftpfs_retry_seconds
},
202 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy
},
203 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections
},
204 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options
},
205 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls
},
206 { "fish_directory_timeout", &fish_directory_timeout
},
207 #endif /* USE_NETCODE */
209 #ifdef USE_INTERNAL_EDIT
210 { "editor_word_wrap_line_length", &option_word_wrap_line_length
},
211 { "editor_key_emulation", &edit_key_emulation
},
212 { "editor_tab_spacing", &option_tab_spacing
},
213 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces
},
214 { "editor_return_does_auto_indent", &option_return_does_auto_indent
},
215 { "editor_backspace_through_tabs", &option_backspace_through_tabs
},
216 { "editor_fake_half_tabs", &option_fake_half_tabs
},
217 { "editor_option_save_mode", &option_save_mode
},
218 { "editor_option_save_position", &option_save_position
},
219 { "editor_option_auto_para_formatting", &option_auto_para_formatting
},
220 { "editor_option_typewriter_wrap", &option_typewriter_wrap
},
221 { "editor_edit_confirm_save", &edit_confirm_save
},
222 { "editor_syntax_highlighting", &option_syntax_highlighting
},
223 { "editor_persistent_selections", &option_persistent_selections
},
224 { "editor_visible_tabs", &visible_tabs
},
225 { "editor_visible_spaces", &visible_tws
},
226 { "editor_line_state", &option_line_state
},
227 #endif /* USE_INTERNAL_EDIT */
229 { "nice_rotating_dash", &nice_rotating_dash
},
230 { "horizontal_split", &horizontal_split
},
231 { "mcview_remember_file_position", &mcview_remember_file_position
},
232 { "auto_fill_mkdir_name", &auto_fill_mkdir_name
},
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 for (i
= 0; sort_names
[i
].key
; i
++)
259 if (sort_names
[i
].sort_type
== (sortfn
*) panel
->sort_type
){
260 mc_config_set_string(mc_panels_config
, section
, "sort_order", sort_names
[i
].key
);
264 for (i
= 0; list_types
[i
].key
; i
++)
265 if (list_types
[i
].list_type
== panel
->list_type
){
266 mc_config_set_string(mc_panels_config
, section
, "list_mode", list_types
[i
].key
);
270 mc_config_set_string(mc_panels_config
, section
, "user_format", panel
->user_format
);
272 for (i
= 0; i
< LIST_TYPES
; i
++){
273 buffer
= g_strdup_printf("user_status%d", i
);
274 mc_config_set_string(mc_panels_config
, section
, buffer
, panel
->user_status_format
[i
]);
278 mc_config_set_int(mc_panels_config
, section
, "user_mini_status", panel
->user_mini_status
);
287 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
289 /* Save integer options */
290 for (i
= 0; layout
[i
].opt_name
; i
++){
291 mc_config_set_int(mc_main_config
, "Layout", layout
[i
].opt_name
, *layout
[i
].opt_addr
);
293 mc_config_save_to_file (mc_main_config
, profile
);
299 save_configure (void)
304 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
306 /* Save integer options */
307 for (i
= 0; int_options
[i
].opt_name
; i
++)
308 mc_config_set_int(mc_main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
, *int_options
[i
].opt_addr
);
310 /* Save string options */
311 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
312 mc_config_set_string(mc_main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
, *str_options
[i
].opt_addr
);
314 mc_config_save_to_file (mc_main_config
, profile
);
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_other_type () == view_listing
347 ? other_panel
->cwd
: ".");
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
);
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
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
393 mc_config_save_to_file (mc_main_config
, tmp_profile
);
394 g_free (tmp_profile
);
399 panel_load_setup (WPanel
*panel
, const char *section
)
404 panel
->reverse
= mc_config_get_int(mc_panels_config
, section
, "reverse", 0);
405 panel
->case_sensitive
= mc_config_get_int(mc_panels_config
, section
, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT
);
406 panel
->exec_first
= mc_config_get_int(mc_panels_config
, section
, "exec_first", 0);
408 /* Load sort order */
409 buffer
= mc_config_get_string(mc_panels_config
, section
, "sort_order", "name");
411 panel
->sort_type
= (sortfn
*) sort_name
;
412 for (i
= 0; sort_names
[i
].key
; i
++)
413 if ( g_strcasecmp (sort_names
[i
].key
, buffer
) == 0){
414 panel
->sort_type
= sort_names
[i
].sort_type
;
418 /* Load the listing mode */
419 buffer
= mc_config_get_string(mc_panels_config
, section
, "list_mode", "full");
420 panel
->list_type
= list_full
;
421 for (i
= 0; list_types
[i
].key
; i
++)
422 if ( g_strcasecmp (list_types
[i
].key
, buffer
) == 0){
423 panel
->list_type
= list_types
[i
].list_type
;
429 g_free (panel
->user_format
);
430 panel
->user_format
= mc_config_get_string(mc_panels_config
, section
, "user_format", DEFAULT_USER_FORMAT
);
432 for (i
= 0; i
< LIST_TYPES
; i
++){
433 g_free (panel
->user_status_format
[i
]);
434 buffer
= g_strdup_printf("user_status%d",i
);
435 panel
->user_status_format
[i
] =
436 mc_config_get_string(mc_panels_config
, section
, buffer
, DEFAULT_USER_FORMAT
);
440 panel
->user_mini_status
=
441 mc_config_get_int(mc_panels_config
, section
, "user_mini_status", 0);
450 for (i
= 0; layout
[i
].opt_name
; i
++)
451 *layout
[i
].opt_addr
=
452 mc_config_get_int(mc_main_config
,"Layout", layout
[i
].opt_name
, *layout
[i
].opt_addr
);
456 setup__load_panel_state (const char *section
)
461 int mode
= view_listing
;
463 /* Load the display mode */
464 buffer
= mc_config_get_string(mc_panels_config
, section
, "display", "listing");
466 for (i
= 0; panel_types
[i
].opt_name
; i
++)
467 if ( g_strcasecmp (panel_types
[i
].opt_name
, buffer
) == 0){
468 mode
= panel_types
[i
].opt_type
;
476 setup__is_cfg_group_must_panel_config(const char *grp
)
479 ! strcasecmp("Dirs",grp
) ||
480 ! strcasecmp("Temporal:New Right Panel",grp
) ||
481 ! strcasecmp("Temporal:New Left Panel",grp
) ||
482 ! strcasecmp("New Left Panel",grp
) ||
483 ! strcasecmp("New Right Panel",grp
)
490 setup__move_panels_config_into_separate_file(const char*profile
)
492 mc_config_t
*tmp_cfg
;
493 char **groups
, **curr_grp
;
497 if (!exist_file(profile
))
500 tmp_cfg
= mc_config_init(profile
);
504 curr_grp
= groups
= mc_config_get_groups (tmp_cfg
, &groups_count
);
507 mc_config_deinit(tmp_cfg
);
512 if ( setup__is_cfg_group_must_panel_config(*curr_grp
) == NULL
)
514 mc_config_del_group (tmp_cfg
, *curr_grp
);
519 mc_config_save_to_file (tmp_cfg
, panels_profile_name
);
520 mc_config_deinit(tmp_cfg
);
522 tmp_cfg
= mc_config_init(profile
);
533 need_grp
= setup__is_cfg_group_must_panel_config(*curr_grp
);
534 if ( need_grp
!= NULL
)
536 mc_config_del_group (tmp_cfg
, need_grp
);
541 mc_config_save_file (tmp_cfg
);
542 mc_config_deinit(tmp_cfg
);
555 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
556 if (!exist_file (profile
)){
557 inifile
= concat_dir_and_file (mc_home
, "mc.ini");
558 if (exist_file (inifile
)){
563 inifile
= concat_dir_and_file (mc_home_alt
, "mc.ini");
564 if (exist_file (inifile
)) {
572 profile_name
= profile
;
584 profile
= setup_init ();
586 /* mc.lib is common for all users, but has priority lower than
587 ~/.mc/ini. FIXME: it's only used for keys and treestore now */
588 global_profile_name
= concat_dir_and_file (mc_home
, "mc.lib");
590 if (!exist_file(global_profile_name
)) {
591 g_free (global_profile_name
);
592 global_profile_name
= concat_dir_and_file (mc_home_alt
, "mc.lib");
594 panels_profile_name
= concat_dir_and_file (home_dir
, PANELS_PROFILE_NAME
);
596 mc_main_config
= mc_config_init(profile
);
598 if (!exist_file(panels_profile_name
))
599 setup__move_panels_config_into_separate_file(profile
);
601 mc_panels_config
= mc_config_init(panels_profile_name
);
603 /* Load integer boolean options */
604 for (i
= 0; int_options
[i
].opt_name
; i
++)
605 *int_options
[i
].opt_addr
=
606 mc_config_get_int(mc_main_config
, CONFIG_APP_SECTION
, int_options
[i
].opt_name
, *int_options
[i
].opt_addr
);
608 /* Load string options */
609 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
610 *str_options
[i
].opt_addr
=
611 mc_config_get_string (mc_main_config
, CONFIG_APP_SECTION
, str_options
[i
].opt_name
, str_options
[i
].opt_defval
);
617 startup_left_mode
= setup__load_panel_state ("New Left Panel");
618 startup_right_mode
= setup__load_panel_state ("New Right Panel");
620 /* At least one of the panels is a listing panel */
621 if (startup_left_mode
!= view_listing
&& startup_right_mode
!=view_listing
)
622 startup_left_mode
= view_listing
;
625 buffer
= mc_config_get_string(mc_panels_config
, "Dirs", "other_dir", ".");
626 if (vfs_file_is_local (buffer
))
632 boot_current_is_left
=
633 mc_config_get_int(mc_panels_config
, "Dirs", "current_is_left", 1);
636 ftpfs_proxy_host
= mc_config_get_string(mc_main_config
, "Misc", "ftp_proxy_host", "gate");
638 setup_color_string
= mc_config_get_string(mc_main_config
, "Misc", "find_ignore_dirs", "");
639 if (setup_color_string
[0])
640 find_ignore_dirs
= g_strconcat (":", setup_color_string
, ":", (char *) NULL
);
641 g_free(setup_color_string
);
643 /* The default color and the terminal dependent color */
644 setup_color_string
= mc_config_get_string(mc_main_config
, "Colors", "base_color", "");
645 term_color_string
= mc_config_get_string(mc_main_config
, "Colors", getenv ("TERM"), "");
646 color_terminal_string
= mc_config_get_string(mc_main_config
, "Colors", "color_terminals", "");
648 /* Load the directory history */
649 /* directory_history_load (); */
650 /* Remove the temporal entries */
651 #if defined(USE_VFS) && defined (USE_NETCODE)
652 ftpfs_init_passwd ();
653 #endif /* USE_VFS && USE_NETCODE */
656 if ( load_codepages_list() > 0 ) {
657 buffer
= mc_config_get_string(mc_main_config
, "Misc", "display_codepage", "");
658 if ( buffer
[0] != '\0' )
660 display_codepage
= get_codepage_index( buffer
);
661 cp_display
= get_codepage_id (display_codepage
);
664 buffer
= mc_config_get_string(mc_main_config
, "Misc", "source_codepage", "");
665 if ( buffer
[0] != '\0' )
667 source_codepage
= get_codepage_index( buffer
);
668 cp_source
= get_codepage_id (source_codepage
);
672 init_translation_table( source_codepage
, display_codepage
);
673 if ( get_codepage_id( display_codepage
) )
674 utf8_display
= str_isutf8 (get_codepage_id( display_codepage
));
675 #endif /* HAVE_CHARSET */
678 #if defined(USE_VFS) && defined (USE_NETCODE)
684 buffer
= mc_config_get_string(mc_main_config
, "Misc", "ftpfs_password", "");
691 #endif /* USE_VFS && USE_NETCODE */
693 void done_setup (void)
695 g_free (profile_name
);
696 g_free (global_profile_name
);
697 g_free(color_terminal_string
);
698 g_free(term_color_string
);
699 g_free(setup_color_string
);
700 mc_config_deinit(mc_main_config
);
701 mc_config_deinit(mc_panels_config
);
704 /* directory_history_free (); */
708 load_keys_from_section (const char *terminal
, mc_config_t
*cfg
)
711 gchar
**profile_keys
, **keys
;
712 gchar
**values
, **curr_values
;
713 char *valcopy
, *value
;
715 gsize len
, values_len
;
720 section_name
= g_strconcat ("terminal:", terminal
, (char *) NULL
);
721 profile_keys
= keys
= mc_config_get_keys (cfg
, section_name
, &len
);
723 while (*profile_keys
){
725 /* copy=other causes all keys from [terminal:other] to be loaded. */
726 if (g_strcasecmp (*profile_keys
, "copy") == 0) {
727 valcopy
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
728 load_keys_from_section (valcopy
, cfg
);
733 curr_values
= values
= mc_config_get_string_list (cfg
, section_name
, *profile_keys
, &values_len
);
735 key_code
= lookup_key (*profile_keys
);
738 while (*curr_values
){
739 valcopy
= convert_controls (*curr_values
);
740 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
745 value
= mc_config_get_string (cfg
, section_name
, *profile_keys
, "");
746 valcopy
= convert_controls (value
);
747 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
757 g_free (section_name
);
760 void load_key_defs (void)
763 * Load keys from mc.lib before ~/.mc/ini, so that the user
764 * definitions override global settings.
766 mc_config_t
*mc_global_config
;
768 mc_global_config
= mc_config_init(global_profile_name
);
769 if (mc_global_config
!= NULL
)
771 load_keys_from_section ("general", mc_global_config
);
772 load_keys_from_section (getenv ("TERM"), mc_global_config
);
773 mc_config_deinit(mc_global_config
);
775 load_keys_from_section ("general", mc_main_config
);
776 load_keys_from_section (getenv ("TERM"), mc_main_config
);