1 /* Setup loading/saving.
2 Copyright (C) 1994 Miguel de Icaza
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19 #include <sys/types.h> /* Needed to include local .h files */
33 #include "mouse.h" /* To make view.h happy */
34 #include "view.h" /* For the externs */
35 #include "key.h" /* For the externs */
36 #include "hotlist.h" /* load/save/done hotlist */
37 #include "panelize.h" /* load/save/done panelize */
39 #include "menu.h" /* menubar_visible declaration */
40 #include "win.h" /* lookup_key */
44 #ifndef PORT_LIST_MODE_NAME
45 # define PORT_LIST_MODE_NAME "list_mode"
48 #ifndef PORT_LIST_MODE_DEFAULT
49 # define PORT_LIST_MODE_DEFAULT "full"
56 #include "../vfs/vfs.h"
58 # include "../vfs/ftpfs.h"
64 extern int vfs_timeout
;
65 extern int tar_gzipped_memlimit
;
68 extern char *find_ignore_dirs
;
70 extern int num_history_items_recorded
;
74 char setup_color_string
[4096];
75 char term_color_string
[4096];
76 char color_terminal_string
[512];
78 #define load_int(a,b,c) GetPrivateProfileInt(a,b,c,profile_name)
79 #define load_string(a,b,c,d,e) GetPrivateProfileString(a,b,c,d,e,profile_name)
80 #define save_string WritePrivateProfileString
82 int startup_left_mode
;
83 int startup_right_mode
;
85 /* Ugly hack to allow panel_save_setup to work as a place holder for */
86 /* default panel values */
93 { "name", (sortfn
*) sort_name
},
94 { "extension", (sortfn
*) sort_ext
},
95 { "time", (sortfn
*) sort_time
},
96 { "atime", (sortfn
*) sort_atime
},
97 { "ctime", (sortfn
*) sort_ctime
},
98 { "size", (sortfn
*) sort_size
},
99 { "inode", (sortfn
*) sort_inode
},
100 { "unsorted", (sortfn
*) unsorted
},
104 static const struct {
108 { "full", list_full
},
109 { "brief", list_brief
},
110 { "long", list_long
},
111 { "user", list_user
},
112 { "icons", list_icons
},
116 static const struct {
120 { "listing", view_listing
},
121 { "quickview", view_quick
},
122 { "info", view_info
},
123 { "tree", view_tree
},
127 static const struct {
131 { "equal_split", &equal_split
},
132 { "first_panel_size", &first_panel_size
},
133 { "message_visible", &message_visible
},
134 { "keybar_visible", &keybar_visible
},
135 { "xterm_hintbar", &xterm_hintbar
},
136 { "output_lines", &output_lines
},
137 { "command_prompt", &command_prompt
},
138 { "menubar_visible", &menubar_visible
},
139 { "show_mini_info", &show_mini_info
},
140 { "permission_mode", &permission_mode
},
141 { "filetype_mode", &filetype_mode
},
146 #undef SAVE_CHANGES_OUTSIDE_OPTIONS_MENU
148 #ifdef SAVE_CHANGES_OUTSIDE_OPTIONS_MENU
149 extern int preserve_uidgid
;
152 static const struct {
156 { "show_backups", &show_backups
},
157 { "show_dot_files", &show_dot_files
},
158 { "verbose", &verbose
},
159 { "mark_moves_down", &mark_moves_down
},
160 { "pause_after_run", &pause_after_run
},
161 { "shell_patterns", &easy_patterns
},
162 { "auto_save_setup", &auto_save_setup
},
163 { "auto_menu", &auto_menu
},
164 { "use_internal_view", &use_internal_view
},
165 { "use_internal_edit", &use_internal_edit
},
166 { "clear_before_exec", &clear_before_exec
},
167 { "mix_all_files", &mix_all_files
},
168 { "fast_reload", &fast_reload
},
169 { "fast_reload_msg_shown", &fast_reload_w
},
170 { "confirm_delete", &confirm_delete
},
171 { "confirm_overwrite", &confirm_overwrite
},
172 { "confirm_execute", &confirm_execute
},
173 { "confirm_exit", &confirm_exit
},
174 { "safe_delete", &know_not_what_am_i_doing
},
175 { "mouse_repeat_rate", &mou_auto_repeat
},
176 { "double_click_speed", &double_click_speed
},
178 { "eight_bit_clean", &eight_bit_clean
},
179 { "full_eight_bits", &full_eight_bits
},
180 #endif /* !HAVE_CHARSET */
181 { "use_8th_bit_as_meta", &use_8th_bit_as_meta
},
182 { "confirm_view_dir", &confirm_view_dir
},
183 { "mouse_move_pages", &mouse_move_pages
},
184 { "mouse_move_pages_viewer", &mouse_move_pages_viewer
},
185 { "fast_refresh", &fast_refresh
},
186 { "navigate_with_arrows", &navigate_with_arrows
},
187 { "advanced_chown", &advanced_chfns
},
188 { "drop_menus", &drop_menus
},
189 { "wrap_mode", &global_wrap_mode
},
190 { "old_esc_mode", &old_esc_mode
},
191 { "cd_symlinks", &cd_symlinks
},
192 { "show_all_if_ambiguous", &show_all_if_ambiguous
},
193 { "have_fast_cpu", &have_fast_cpu
},
194 { "torben_fj_mode", &torben_fj_mode
},
195 { "use_file_to_guess_type", &use_file_to_check_type
},
196 { "alternate_plus_minus", &alternate_plus_minus
},
197 { "only_leading_plus_minus", &only_leading_plus_minus
},
198 { "show_output_starts_shell", &output_starts_shell
},
199 { "panel_scroll_pages", &panel_scroll_pages
},
200 { "xtree_mode", &xtree_mode
},
201 { "num_history_items_recorded", &num_history_items_recorded
},
202 { "file_op_compute_totals", &file_op_compute_totals
},
203 #ifdef SAVE_CHANGES_OUTSIDE_OPTIONS_MENU
204 { "dive_into_subdirs", &dive_into_subdirs
},
205 { "preserve_uidgid", &preserve_uidgid
},
206 /* What about the other two options in the copy dialog
207 (follow links, stable symlinks) -Norbert */
208 { "tree_navigation_flag", &tree_navigation_flag
},
209 #endif /* SAVE_CHANGES_OUTSIDE_OPTIONS_MENU */
211 { "vfs_timeout", &vfs_timeout
},
213 { "ftpfs_directory_timeout", &ftpfs_directory_timeout
},
214 { "use_netrc", &use_netrc
},
215 { "ftpfs_retry_seconds", &ftpfs_retry_seconds
},
216 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy
},
217 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections
},
218 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options
},
219 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls
},
220 #endif /* USE_NETCODE */
222 #ifdef USE_INTERNAL_EDIT
223 { "editor_word_wrap_line_length", &option_word_wrap_line_length
},
224 { "editor_key_emulation", &edit_key_emulation
},
225 { "editor_tab_spacing", &option_tab_spacing
},
226 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces
},
227 { "editor_return_does_auto_indent", &option_return_does_auto_indent
},
228 { "editor_backspace_through_tabs", &option_backspace_through_tabs
},
229 { "editor_fake_half_tabs", &option_fake_half_tabs
},
230 { "editor_option_save_mode", &option_save_mode
},
231 { "editor_option_backup_ext_int", &option_backup_ext_int
},
232 { "editor_option_auto_para_formatting", &option_auto_para_formatting
},
233 { "editor_option_typewriter_wrap", &option_typewriter_wrap
},
234 { "editor_edit_confirm_save", &edit_confirm_save
},
235 { "editor_syntax_highlighting", &option_syntax_highlighting
},
236 #endif /* USE_INTERNAL_EDIT */
238 { "nice_rotating_dash", &nice_rotating_dash
},
239 { "horizontal_split", &horizontal_split
},
244 panel_save_setup (WPanel
*panel
, char *section
)
246 char buffer
[BUF_TINY
];
249 g_snprintf (buffer
, sizeof (buffer
), "%d", panel
->reverse
);
250 save_string (section
, "reverse", buffer
, profile_name
);
251 g_snprintf (buffer
, sizeof (buffer
), "%d", panel
->case_sensitive
);
252 save_string (section
, "case_sensitive", buffer
, profile_name
);
253 for (i
= 0; sort_names
[i
].key
; i
++)
254 if (sort_names
[i
].sort_type
== (sortfn
*) panel
->sort_type
){
255 save_string (section
, "sort_order",
256 sort_names
[i
].key
, profile_name
);
260 for (i
= 0; list_types
[i
].key
; i
++)
261 if (list_types
[i
].list_type
== panel
->list_type
){
262 save_string (section
, PORT_LIST_MODE_NAME
, list_types
[i
].key
, profile_name
);
266 save_string (section
, "user_format",
267 panel
->user_format
, profile_name
);
269 for (i
= 0; i
< LIST_TYPES
; i
++){
270 g_snprintf (buffer
, sizeof (buffer
), "user_status%d", i
);
271 save_string (section
, buffer
,
272 panel
->user_status_format
[i
], profile_name
);
275 g_snprintf (buffer
, sizeof (buffer
), "%d", panel
->user_mini_status
);
276 save_string (section
, "user_mini_status", buffer
,
285 char buffer
[BUF_TINY
];
287 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
289 /* Save integer options */
290 for (i
= 0; layout
[i
].opt_name
; i
++){
291 g_snprintf (buffer
, sizeof (buffer
), "%d", *layout
[i
].opt_addr
);
292 save_string ("Layout", layout
[i
].opt_name
, buffer
, profile
);
299 save_configure (void)
304 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
306 /* Save integer options */
307 for (i
= 0; options
[i
].opt_name
; i
++)
308 set_int (profile
, options
[i
].opt_name
, *options
[i
].opt_addr
);
314 panel_save_type (char *section
, int type
)
318 for (i
= 0; panel_types
[i
].opt_name
; i
++)
319 if (panel_types
[i
].opt_type
== type
){
320 save_string (section
, "display", panel_types
[i
].opt_name
,
331 type
= get_display_type (0);
332 panel_save_type ("New Left Panel", type
);
333 if (type
== view_listing
)
334 panel_save_setup (left_panel
, left_panel
->panel_name
);
335 type
= get_display_type (1);
336 panel_save_type ("New Right Panel", type
);
337 if (type
== view_listing
)
338 panel_save_setup (right_panel
, right_panel
->panel_name
);
347 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
352 save_string ("Dirs", "other_dir",
353 get_other_type () == view_listing
354 ? opanel
->cwd
: ".", profile
);
355 if (get_current_panel () != NULL
)
356 WritePrivateProfileString ("Dirs", "current_is_left",
357 get_current_index () == 0 ? "1" : "0", profile
);
362 /* directory_history_save (); */
364 #if defined(USE_VFS) && defined (USE_NETCODE)
365 WritePrivateProfileString ("Misc", "ftpfs_password",
366 ftpfs_anonymous_passwd
, profile
);
367 if (ftpfs_proxy_host
)
368 WritePrivateProfileString ("Misc", "ftp_proxy_host",
369 ftpfs_proxy_host
, profile
);
370 #endif /* USE_VFS && USE_NETCODE */
373 save_string( "Misc", "display_codepage",
374 get_codepage_id( display_codepage
), profile_name
);
375 #endif /* HAVE_CHARSET */
382 panel_load_setup (WPanel
*panel
, char *section
)
385 char buffer
[BUF_TINY
];
387 panel
->reverse
= load_int (section
, "reverse", 0);
388 panel
->case_sensitive
= load_int (section
, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT
);
390 /* Load sort order */
391 load_string (section
, "sort_order", "name", buffer
, sizeof (buffer
));
392 panel
->sort_type
= (sortfn
*) sort_name
;
393 for (i
= 0; sort_names
[i
].key
; i
++)
394 if ( g_strcasecmp (sort_names
[i
].key
, buffer
) == 0){
395 panel
->sort_type
= sort_names
[i
].sort_type
;
399 /* Load the listing mode */
400 load_string (section
, PORT_LIST_MODE_NAME
, PORT_LIST_MODE_DEFAULT
, buffer
, sizeof (buffer
));
401 panel
->list_type
= list_full
;
402 for (i
= 0; list_types
[i
].key
; i
++)
403 if ( g_strcasecmp (list_types
[i
].key
, buffer
) == 0){
404 panel
->list_type
= list_types
[i
].list_type
;
408 if (panel
->list_type
== list_icons
)
409 panel
->list_type
= list_full
;
412 if (panel
->user_format
){
413 g_free (panel
->user_format
);
414 panel
->user_format
= 0;
416 panel
->user_format
= g_strdup (get_profile_string (section
, "user_format",
419 for (i
= 0; i
< LIST_TYPES
; i
++){
420 if (panel
->user_status_format
[i
])
421 g_free (panel
->user_status_format
[i
]);
422 g_snprintf (buffer
, sizeof (buffer
), "user_status%d", i
);
423 panel
->user_status_format
[i
] =
424 g_strdup (get_profile_string (section
, buffer
,
425 DEFAULT_USER_FORMAT
, profile_name
));
428 panel
->user_mini_status
=
429 load_int (section
, "user_mini_status", 0);
434 load_layout (char *profile_name
)
438 for (i
= 0; layout
[i
].opt_name
; i
++)
439 *layout
[i
].opt_addr
=
440 load_int ("Layout", layout
[i
].opt_name
,
441 *layout
[i
].opt_addr
);
445 load_mode (char *section
)
450 int mode
= view_listing
;
452 /* Load the display mode */
453 load_string (section
, "display", "listing", buffer
, sizeof (buffer
));
455 for (i
= 0; panel_types
[i
].opt_name
; i
++)
456 if ( g_strcasecmp (panel_types
[i
].opt_name
, buffer
) == 0){
457 mode
= panel_types
[i
].opt_type
;
466 do_load_string (char *s
, char *ss
, char *def
)
468 char *buffer
= g_malloc (BUF_SMALL
);
471 load_string (s
, ss
, def
, buffer
, BUF_SMALL
);
473 p
= g_strdup (buffer
);
477 #endif /* !USE_NETCODE */
488 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
489 if (!exist_file (profile
)){
490 inifile
= concat_dir_and_file (mc_home
, "mc.ini");
491 if (exist_file (inifile
)){
498 profile_name
= profile
;
509 profile
= setup_init ();
510 /* Load integer boolean options */
511 for (i
= 0; options
[i
].opt_name
; i
++)
512 *options
[i
].opt_addr
=
513 get_int (profile
, options
[i
].opt_name
, *options
[i
].opt_addr
);
515 load_layout (profile
);
519 startup_left_mode
= load_mode ("New Left Panel");
520 startup_right_mode
= load_mode ("New Right Panel");
522 /* At least one of the panels is a listing panel */
523 if (startup_left_mode
!= view_listing
&& startup_right_mode
!=view_listing
)
524 startup_left_mode
= view_listing
;
529 buffer
= (char*) g_malloc (MC_MAXPATHLEN
);
530 load_string ("Dirs", "other_dir", ".", buffer
,
532 if (vfs_file_is_local (buffer
))
538 boot_current_is_left
=
539 GetPrivateProfileInt ("Dirs", "current_is_left", 1, profile
);
542 ftpfs_proxy_host
= do_load_string ("Misc", "ftp_proxy_host", "gate");
545 load_string ("Misc", "find_ignore_dirs", "", setup_color_string
,
546 sizeof (setup_color_string
));
547 if (setup_color_string
[0])
548 find_ignore_dirs
= g_strconcat (":", setup_color_string
, ":", NULL
);
550 /* The default color and the terminal dependent color */
551 load_string ("Colors", "base_color", "", setup_color_string
,
552 sizeof (setup_color_string
));
553 load_string ("Colors", getenv ("TERM"), "",
554 term_color_string
, sizeof (term_color_string
));
555 load_string ("Colors", "color_terminals", "",
556 color_terminal_string
, sizeof (color_terminal_string
));
558 /* Load the directory history */
559 /* directory_history_load (); */
560 /* Remove the temporal entries */
561 profile_clean_section ("Temporal:New Left Panel", profile_name
);
562 profile_clean_section ("Temporal:New Right Panel", profile_name
);
563 #if defined(USE_VFS) && defined (USE_NETCODE)
564 ftpfs_init_passwd ();
565 #endif /* USE_VFS && USE_NETCODE */
568 if ( load_codepages_list() > 0 ) {
570 load_string( "Misc", "display_codepage", "",
571 cpname
, sizeof(cpname
) );
572 if ( cpname
[0] != '\0' )
573 display_codepage
= get_codepage_index( cpname
);
576 init_translation_table( source_codepage
, display_codepage
);
577 #endif /* HAVE_CHARSET */
580 #if defined(USE_VFS) && defined (USE_NETCODE)
586 load_string ("Misc", "ftpfs_password", "", buffer
, sizeof (buffer
));
588 return g_strdup (buffer
);
592 #endif /* USE_VFS && USE_NETCODE */
594 void done_setup (void)
596 g_free (profile_name
);
599 /* directory_history_free (); */
603 load_keys_from_section (char *terminal
, char *profile_name
)
607 char *key
, *value
, *valcopy
;
613 section_name
= g_strconcat ("terminal:", terminal
, NULL
);
614 profile_keys
= profile_init_iterator (section_name
, profile_name
);
616 g_free (section_name
);
620 while (profile_keys
){
621 profile_keys
= profile_iterator_next (profile_keys
, &key
, &value
);
622 key_code
= lookup_key (key
);
624 valcopy
= convert_controls (value
);
625 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
629 g_free (section_name
);
633 void load_key_defs (void)
635 char *libfile
= concat_dir_and_file (mc_home
, "mc.lib");
638 * Load keys from mc.lib before ~/.mc/ini, so that the user
639 * definitions override global settings.
641 load_keys_from_section ("general", libfile
);
642 load_keys_from_section (getenv ("TERM"), libfile
);
643 load_keys_from_section ("general", profile_name
);
644 load_keys_from_section (getenv ("TERM"), profile_name
);
646 /* We don't want a huge database loaded in core */
647 free_profile_name (libfile
);