1 /* Setup loading/saving.
2 Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007 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. */
23 #include <sys/types.h>
31 #include "tree.h" /* xtree_mode */
34 #include "mouse.h" /* To make view.h happy */
35 #include "view.h" /* For the externs */
36 #include "key.h" /* For the externs */
37 #include "hotlist.h" /* load/save/done hotlist */
38 #include "panelize.h" /* load/save/done panelize */
40 #include "menu.h" /* menubar_visible declaration */
41 #include "win.h" /* lookup_key */
43 #include "file.h" /* safe_delete */
46 #include "../vfs/gc.h"
54 # include "../vfs/ftpfs.h"
55 # include "../vfs/fish.h"
58 #ifdef USE_INTERNAL_EDIT
59 # include "../edit/edit.h"
62 #include "../src/strutil.h" /* str_isutf8 () */
65 extern char *find_ignore_dirs
;
67 extern int num_history_items_recorded
;
69 char *profile_name
; /* .mc/ini */
70 char *global_profile_name
; /* mc.lib */
72 char setup_color_string
[4096];
73 char term_color_string
[4096];
74 char color_terminal_string
[512];
76 #define load_int(a,b,c) GetPrivateProfileInt(a,b,c,profile_name)
77 #define load_string(a,b,c,d,e) GetPrivateProfileString(a,b,c,d,e,profile_name)
78 #define save_string WritePrivateProfileString
80 int startup_left_mode
;
81 int startup_right_mode
;
83 /* Ugly hack to allow panel_save_setup to work as a place holder for */
84 /* default panel values */
91 { "name", (sortfn
*) sort_name
},
92 { "extension", (sortfn
*) sort_ext
},
93 { "time", (sortfn
*) sort_time
},
94 { "atime", (sortfn
*) sort_atime
},
95 { "ctime", (sortfn
*) sort_ctime
},
96 { "size", (sortfn
*) sort_size
},
97 { "inode", (sortfn
*) sort_inode
},
98 { "unsorted", (sortfn
*) unsorted
},
102 static const struct {
106 { "full", list_full
},
107 { "brief", list_brief
},
108 { "long", list_long
},
109 { "user", list_user
},
113 static const struct {
114 const char *opt_name
;
117 { "listing", view_listing
},
118 { "quickview", view_quick
},
119 { "info", view_info
},
120 { "tree", view_tree
},
124 static const struct {
125 const char *opt_name
;
128 { "equal_split", &equal_split
},
129 { "first_panel_size", &first_panel_size
},
130 { "message_visible", &message_visible
},
131 { "keybar_visible", &keybar_visible
},
132 { "xterm_title", &xterm_title
},
133 { "output_lines", &output_lines
},
134 { "command_prompt", &command_prompt
},
135 { "menubar_visible", &menubar_visible
},
136 { "show_mini_info", &show_mini_info
},
137 { "permission_mode", &permission_mode
},
138 { "filetype_mode", &filetype_mode
},
139 { "free_space", &free_space
},
143 static const struct {
144 const char *opt_name
;
147 { "show_backups", &show_backups
},
148 { "show_dot_files", &show_dot_files
},
149 { "verbose", &verbose
},
150 { "mark_moves_down", &mark_moves_down
},
151 { "pause_after_run", &pause_after_run
},
152 { "shell_patterns", &easy_patterns
},
153 { "auto_save_setup", &auto_save_setup
},
154 { "auto_menu", &auto_menu
},
155 { "use_internal_view", &use_internal_view
},
156 { "use_internal_edit", &use_internal_edit
},
157 { "clear_before_exec", &clear_before_exec
},
158 { "mix_all_files", &mix_all_files
},
159 { "fast_reload", &fast_reload
},
160 { "fast_reload_msg_shown", &fast_reload_w
},
161 { "confirm_delete", &confirm_delete
},
162 { "confirm_overwrite", &confirm_overwrite
},
163 { "confirm_execute", &confirm_execute
},
164 { "confirm_exit", &confirm_exit
},
165 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete
},
166 { "safe_delete", &safe_delete
},
167 { "mouse_repeat_rate", &mou_auto_repeat
},
168 { "double_click_speed", &double_click_speed
},
170 { "eight_bit_clean", &eight_bit_clean
},
171 { "full_eight_bits", &full_eight_bits
},
172 #endif /* !HAVE_CHARSET */
173 { "use_8th_bit_as_meta", &use_8th_bit_as_meta
},
174 { "confirm_view_dir", &confirm_view_dir
},
175 { "mouse_move_pages", &mouse_move_pages
},
176 { "mouse_move_pages_viewer", &mouse_move_pages_viewer
},
177 { "fast_refresh", &fast_refresh
},
178 { "navigate_with_arrows", &navigate_with_arrows
},
179 { "drop_menus", &drop_menus
},
180 { "wrap_mode", &global_wrap_mode
},
181 { "old_esc_mode", &old_esc_mode
},
182 { "cd_symlinks", &cd_symlinks
},
183 { "show_all_if_ambiguous", &show_all_if_ambiguous
},
184 { "max_dirt_limit", &max_dirt_limit
},
185 { "torben_fj_mode", &torben_fj_mode
},
186 { "use_file_to_guess_type", &use_file_to_check_type
},
187 { "alternate_plus_minus", &alternate_plus_minus
},
188 { "only_leading_plus_minus", &only_leading_plus_minus
},
189 { "show_output_starts_shell", &output_starts_shell
},
190 { "panel_scroll_pages", &panel_scroll_pages
},
191 { "xtree_mode", &xtree_mode
},
192 { "num_history_items_recorded", &num_history_items_recorded
},
193 { "file_op_compute_totals", &file_op_compute_totals
},
195 { "vfs_timeout", &vfs_timeout
},
197 { "ftpfs_directory_timeout", &ftpfs_directory_timeout
},
198 { "use_netrc", &use_netrc
},
199 { "ftpfs_retry_seconds", &ftpfs_retry_seconds
},
200 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy
},
201 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections
},
202 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options
},
203 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls
},
204 { "fish_directory_timeout", &fish_directory_timeout
},
205 #endif /* USE_NETCODE */
207 #ifdef USE_INTERNAL_EDIT
208 { "editor_word_wrap_line_length", &option_word_wrap_line_length
},
209 { "editor_key_emulation", &edit_key_emulation
},
210 { "editor_tab_spacing", &option_tab_spacing
},
211 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces
},
212 { "editor_return_does_auto_indent", &option_return_does_auto_indent
},
213 { "editor_backspace_through_tabs", &option_backspace_through_tabs
},
214 { "editor_fake_half_tabs", &option_fake_half_tabs
},
215 { "editor_option_save_mode", &option_save_mode
},
216 { "editor_option_save_position", &option_save_position
},
217 { "editor_option_auto_para_formatting", &option_auto_para_formatting
},
218 { "editor_option_typewriter_wrap", &option_typewriter_wrap
},
219 { "editor_edit_confirm_save", &edit_confirm_save
},
220 { "editor_syntax_highlighting", &option_syntax_highlighting
},
221 { "editor_persistent_selections", &option_persistent_selections
},
222 { "editor_visible_tabs", &visible_tabs
},
223 { "editor_visible_spaces", &visible_tws
},
224 #endif /* USE_INTERNAL_EDIT */
226 { "nice_rotating_dash", &nice_rotating_dash
},
227 { "horizontal_split", &horizontal_split
},
228 { "mcview_remember_file_position", &mcview_remember_file_position
},
229 { "auto_fill_mkdir_name", &auto_fill_mkdir_name
},
233 static const struct {
234 const char *opt_name
;
236 const char *opt_defval
;
238 #ifdef USE_INTERNAL_EDIT
239 { "editor_backup_extension", &option_backup_ext
, "~" },
245 panel_save_setup (struct WPanel
*panel
, const char *section
)
247 char buffer
[BUF_TINY
];
250 g_snprintf (buffer
, sizeof (buffer
), "%d", panel
->reverse
);
251 save_string (section
, "reverse", buffer
, profile_name
);
252 g_snprintf (buffer
, sizeof (buffer
), "%d", panel
->case_sensitive
);
253 save_string (section
, "case_sensitive", buffer
, profile_name
);
254 g_snprintf (buffer
, sizeof (buffer
), "%d", panel
->exec_first
);
255 save_string (section
, "exec_first", buffer
, profile_name
);
256 for (i
= 0; sort_names
[i
].key
; i
++)
257 if (sort_names
[i
].sort_type
== (sortfn
*) panel
->sort_type
){
258 save_string (section
, "sort_order",
259 sort_names
[i
].key
, profile_name
);
263 for (i
= 0; list_types
[i
].key
; i
++)
264 if (list_types
[i
].list_type
== panel
->list_type
){
265 save_string (section
, "list_mode", list_types
[i
].key
, profile_name
);
269 save_string (section
, "user_format",
270 panel
->user_format
, profile_name
);
272 for (i
= 0; i
< LIST_TYPES
; i
++){
273 g_snprintf (buffer
, sizeof (buffer
), "user_status%d", i
);
274 save_string (section
, buffer
,
275 panel
->user_status_format
[i
], profile_name
);
278 g_snprintf (buffer
, sizeof (buffer
), "%d", panel
->user_mini_status
);
279 save_string (section
, "user_mini_status", buffer
,
288 char buffer
[BUF_TINY
];
290 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
292 /* Save integer options */
293 for (i
= 0; layout
[i
].opt_name
; i
++){
294 g_snprintf (buffer
, sizeof (buffer
), "%d", *layout
[i
].opt_addr
);
295 save_string ("Layout", layout
[i
].opt_name
, buffer
, profile
);
302 save_configure (void)
307 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
309 /* Save integer options */
310 for (i
= 0; int_options
[i
].opt_name
; i
++)
311 set_int (profile
, int_options
[i
].opt_name
, *int_options
[i
].opt_addr
);
313 /* Save string options */
314 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
315 set_config_string (profile
, str_options
[i
].opt_name
,
316 *str_options
[i
].opt_addr
);
322 panel_save_type (const char *section
, int type
)
326 for (i
= 0; panel_types
[i
].opt_name
; i
++)
327 if (panel_types
[i
].opt_type
== type
){
328 save_string (section
, "display", panel_types
[i
].opt_name
,
335 save_panel_types (void)
339 type
= get_display_type (0);
340 panel_save_type ("New Left Panel", type
);
341 if (type
== view_listing
)
342 panel_save_setup (left_panel
, left_panel
->panel_name
);
343 type
= get_display_type (1);
344 panel_save_type ("New Right Panel", type
);
345 if (type
== view_listing
)
346 panel_save_setup (right_panel
, right_panel
->panel_name
);
355 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
360 save_string ("Dirs", "other_dir",
361 get_other_type () == view_listing
362 ? other_panel
->cwd
: ".", profile
);
363 if (current_panel
!= NULL
)
364 WritePrivateProfileString ("Dirs", "current_is_left",
365 get_current_index () == 0 ? "1" : "0", profile
);
370 /* directory_history_save (); */
372 #if defined(USE_VFS) && defined (USE_NETCODE)
373 WritePrivateProfileString ("Misc", "ftpfs_password",
374 ftpfs_anonymous_passwd
, profile
);
375 if (ftpfs_proxy_host
)
376 WritePrivateProfileString ("Misc", "ftp_proxy_host",
377 ftpfs_proxy_host
, profile
);
378 #endif /* USE_VFS && USE_NETCODE */
381 save_string( "Misc", "display_codepage",
382 get_codepage_id( display_codepage
), profile_name
);
383 save_string( "Misc", "source_codepage",
384 get_codepage_id( source_codepage
), profile_name
);
385 #endif /* HAVE_CHARSET */
392 panel_load_setup (WPanel
*panel
, const char *section
)
395 char buffer
[BUF_TINY
];
397 panel
->reverse
= load_int (section
, "reverse", 0);
398 panel
->case_sensitive
= load_int (section
, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT
);
399 panel
->exec_first
= load_int (section
, "exec_first", 0);
401 /* Load sort order */
402 load_string (section
, "sort_order", "name", buffer
, sizeof (buffer
));
403 panel
->sort_type
= (sortfn
*) sort_name
;
404 for (i
= 0; sort_names
[i
].key
; i
++)
405 if ( g_strcasecmp (sort_names
[i
].key
, buffer
) == 0){
406 panel
->sort_type
= sort_names
[i
].sort_type
;
410 /* Load the listing mode */
411 load_string (section
, "list_mode", "full", buffer
, sizeof (buffer
));
412 panel
->list_type
= list_full
;
413 for (i
= 0; list_types
[i
].key
; i
++)
414 if ( g_strcasecmp (list_types
[i
].key
, buffer
) == 0){
415 panel
->list_type
= list_types
[i
].list_type
;
420 g_free (panel
->user_format
);
421 panel
->user_format
= g_strdup (get_profile_string (section
, "user_format",
424 for (i
= 0; i
< LIST_TYPES
; i
++){
425 g_free (panel
->user_status_format
[i
]);
426 g_snprintf (buffer
, sizeof (buffer
), "user_status%d", i
);
427 panel
->user_status_format
[i
] =
428 g_strdup (get_profile_string (section
, buffer
,
429 DEFAULT_USER_FORMAT
, profile_name
));
432 panel
->user_mini_status
=
433 load_int (section
, "user_mini_status", 0);
438 load_layout (char *profile_name
)
442 for (i
= 0; layout
[i
].opt_name
; i
++)
443 *layout
[i
].opt_addr
=
444 load_int ("Layout", layout
[i
].opt_name
,
445 *layout
[i
].opt_addr
);
449 load_mode (const char *section
)
454 int mode
= view_listing
;
456 /* Load the display mode */
457 load_string (section
, "display", "listing", buffer
, sizeof (buffer
));
459 for (i
= 0; panel_types
[i
].opt_name
; i
++)
460 if ( g_strcasecmp (panel_types
[i
].opt_name
, buffer
) == 0){
461 mode
= panel_types
[i
].opt_type
;
470 do_load_string (const char *s
, const char *ss
, const char *def
)
472 char *buffer
= g_malloc (BUF_SMALL
);
475 load_string (s
, ss
, def
, buffer
, BUF_SMALL
);
477 p
= g_strdup (buffer
);
481 #endif /* !USE_NETCODE */
492 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
493 if (!exist_file (profile
)){
494 inifile
= concat_dir_and_file (mc_home
, "mc.ini");
495 if (exist_file (inifile
)){
502 profile_name
= profile
;
513 profile
= setup_init ();
515 /* mc.lib is common for all users, but has priority lower than
516 ~/.mc/ini. FIXME: it's only used for keys and treestore now */
517 global_profile_name
= concat_dir_and_file (mc_home
, "mc.lib");
519 /* Load integer boolean options */
520 for (i
= 0; int_options
[i
].opt_name
; i
++)
521 *int_options
[i
].opt_addr
=
522 get_int (profile
, int_options
[i
].opt_name
, *int_options
[i
].opt_addr
);
524 /* Load string options */
525 for (i
= 0; str_options
[i
].opt_name
!= NULL
; i
++)
526 *str_options
[i
].opt_addr
= get_config_string (profile
,
527 str_options
[i
].opt_name
, str_options
[i
].opt_defval
);
529 load_layout (profile
);
533 startup_left_mode
= load_mode ("New Left Panel");
534 startup_right_mode
= load_mode ("New Right Panel");
536 /* At least one of the panels is a listing panel */
537 if (startup_left_mode
!= view_listing
&& startup_right_mode
!=view_listing
)
538 startup_left_mode
= view_listing
;
543 buffer
= (char*) g_malloc (MC_MAXPATHLEN
);
544 load_string ("Dirs", "other_dir", ".", buffer
,
546 if (vfs_file_is_local (buffer
))
552 boot_current_is_left
=
553 GetPrivateProfileInt ("Dirs", "current_is_left", 1, profile
);
556 ftpfs_proxy_host
= do_load_string ("Misc", "ftp_proxy_host", "gate");
559 load_string ("Misc", "find_ignore_dirs", "", setup_color_string
,
560 sizeof (setup_color_string
));
561 if (setup_color_string
[0])
562 find_ignore_dirs
= g_strconcat (":", setup_color_string
, ":", (char *) NULL
);
564 /* The default color and the terminal dependent color */
565 load_string ("Colors", "base_color", "", setup_color_string
,
566 sizeof (setup_color_string
));
567 load_string ("Colors", getenv ("TERM"), "",
568 term_color_string
, sizeof (term_color_string
));
569 load_string ("Colors", "color_terminals", "",
570 color_terminal_string
, sizeof (color_terminal_string
));
572 /* Load the directory history */
573 /* directory_history_load (); */
574 /* Remove the temporal entries */
575 profile_clean_section ("Temporal:New Left Panel", profile_name
);
576 profile_clean_section ("Temporal:New Right Panel", profile_name
);
577 #if defined(USE_VFS) && defined (USE_NETCODE)
578 ftpfs_init_passwd ();
579 #endif /* USE_VFS && USE_NETCODE */
582 if ( load_codepages_list() > 0 ) {
584 load_string( "Misc", "display_codepage", "",
585 cpname
, sizeof(cpname
) );
586 if ( cpname
[0] != '\0' )
588 display_codepage
= get_codepage_index( cpname
);
589 cp_display
= get_codepage_id (display_codepage
);
591 load_string( "Misc", "source_codepage", "",
592 cpname
, sizeof(cpname
) );
593 if ( cpname
[0] != '\0' )
595 source_codepage
= get_codepage_index( cpname
);
596 cp_source
= get_codepage_id (source_codepage
);
599 init_translation_table( source_codepage
, display_codepage
);
600 if ( get_codepage_id( display_codepage
) )
601 utf8_display
= str_isutf8 (get_codepage_id( display_codepage
));
602 #endif /* HAVE_CHARSET */
605 #if defined(USE_VFS) && defined (USE_NETCODE)
611 load_string ("Misc", "ftpfs_password", "", buffer
, sizeof (buffer
));
613 return g_strdup (buffer
);
617 #endif /* USE_VFS && USE_NETCODE */
619 void done_setup (void)
621 g_free (profile_name
);
622 g_free (global_profile_name
);
625 /* directory_history_free (); */
629 load_keys_from_section (const char *terminal
, const char *profile_name
)
633 char *key
, *value
, *valcopy
;
639 section_name
= g_strconcat ("terminal:", terminal
, (char *) NULL
);
640 profile_keys
= profile_init_iterator (section_name
, profile_name
);
641 g_free (section_name
);
642 while (profile_keys
){
643 profile_keys
= profile_iterator_next (profile_keys
, &key
, &value
);
645 /* copy=other causes all keys from [terminal:other] to be loaded. */
646 if (g_strcasecmp (key
, "copy") == 0) {
647 load_keys_from_section (value
, profile_name
);
651 key_code
= lookup_key (key
);
653 valcopy
= convert_controls (value
);
654 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
660 void load_key_defs (void)
663 * Load keys from mc.lib before ~/.mc/ini, so that the user
664 * definitions override global settings.
666 load_keys_from_section ("general", global_profile_name
);
667 load_keys_from_section (getenv ("TERM"), global_profile_name
);
668 load_keys_from_section ("general", profile_name
);
669 load_keys_from_section (getenv ("TERM"), profile_name
);
671 /* We don't want a huge database loaded in core */
672 free_profile_name (global_profile_name
);