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., 675 Mass Ave, Cambridge, MA 02139, USA. */
19 #include <sys/types.h> /* Needed to include local .h files */
21 #include <sys/param.h>
30 #include "util.h" /* Functions and externs */
37 #include "mouse.h" /* To make view.h happy */
38 #include "view.h" /* For the externs */
39 #include "key.h" /* For the externs */
40 #include "hotlist.h" /* load/save/done hotlist */
41 #include "panelize.h" /* load/save/done panelize */
43 #include "menu.h" /* menubar_visible declaration */
44 #include "win.h" /* lookup_key */
49 # include "gdesktop.h"
52 #ifndef PORT_LIST_MODE_NAME
53 # define PORT_LIST_MODE_NAME "list_mode"
56 #ifndef PORT_LIST_MODE_DEFAULT
57 # define PORT_LIST_MODE_DEFAULT "full"
60 #include "../vfs/vfs.h"
62 # include "../vfs/ftpfs.h"
64 extern int ftpfs_retry_seconds
;
65 extern int ftpfs_use_passive_connections
;
66 extern int ftpfs_use_unix_list_options
;
72 extern int vfs_timeout
;
73 extern int tar_gzipped_memlimit
;
76 extern char *find_ignore_dirs
;
78 extern int num_history_items_recorded
;
82 char setup_color_string
[4096];
83 char term_color_string
[4096];
84 char color_terminal_string
[512];
86 #define load_int(a,b,c) GetPrivateProfileInt(a,b,c,profile_name)
87 #define load_string(a,b,c,d,e) GetPrivateProfileString(a,b,c,d,e,profile_name)
88 #define save_string WritePrivateProfileString
90 int startup_left_mode
;
91 int startup_right_mode
;
93 /* Ugly hack to allow panel_save_setup to work as a place holder for */
94 /* default panel values */
101 { "name", (sortfn
*) sort_name
},
102 { "extension", (sortfn
*) sort_ext
},
103 { "time", (sortfn
*) sort_time
},
104 { "atime", (sortfn
*) sort_atime
},
105 { "ctime", (sortfn
*) sort_ctime
},
106 { "size", (sortfn
*) sort_size
},
107 { "inode", (sortfn
*) sort_inode
},
108 { "unsorted", (sortfn
*) unsorted
},
116 { "full", list_full
},
117 { "brief", list_brief
},
118 { "long", list_long
},
119 { "user", list_user
},
120 { "icons", list_icons
},
128 { "listing", view_listing
},
129 { "quickview", view_quick
},
130 { "info", view_info
},
131 { "tree", view_tree
},
140 { "equal_split", &equal_split
},
141 { "first_panel_size", &first_panel_size
},
142 { "message_visible", &message_visible
},
143 { "keybar_visible", &keybar_visible
},
144 { "xterm_hintbar", &xterm_hintbar
},
145 { "output_lines", &output_lines
},
147 { "menubar_visible", &menubar_visible
},
148 { "command_prompt", &command_prompt
},
149 { "show_mini_info", &show_mini_info
},
150 { "permission_mode", &permission_mode
},
151 { "filetype_mode", &filetype_mode
},
156 #undef SAVE_CHANGES_OUTSIDE_OPTIONS_MENU
158 #ifdef SAVE_CHANGES_OUTSIDE_OPTIONS_MENU
159 extern int preserve_uidgid
;
166 { "show_backups", &show_backups
},
167 { "show_dot_files", &show_dot_files
},
168 { "verbose", &verbose
},
169 { "mark_moves_down", &mark_moves_down
},
170 { "pause_after_run", &pause_after_run
},
171 { "shell_patterns", &easy_patterns
},
172 { "auto_save_setup", &auto_save_setup
},
173 { "align_extensions", &align_extensions
},
174 { "auto_menu", &auto_menu
},
175 { "use_internal_view", &use_internal_view
},
176 { "use_internal_edit", &use_internal_edit
},
177 { "clear_before_exec", &clear_before_exec
},
178 { "mix_all_files", &mix_all_files
},
179 { "fast_reload", &fast_reload
},
180 { "fast_reload_msg_shown", &fast_reload_w
},
181 { "confirm_delete", &confirm_delete
},
182 { "confirm_overwrite", &confirm_overwrite
},
183 { "confirm_execute", &confirm_execute
},
184 { "confirm_exit", &confirm_exit
},
185 { "safe_delete", &know_not_what_am_i_doing
},
186 { "mouse_repeat_rate", &mou_auto_repeat
},
187 { "double_click_speed", &double_click_speed
},
188 { "eight_bit_clean", &eight_bit_clean
},
189 { "full_eight_bits", &full_eight_bits
},
190 { "use_8th_bit_as_meta", &use_8th_bit_as_meta
},
191 { "confirm_view_dir", &confirm_view_dir
},
192 { "mouse_move_pages", &mouse_move_pages
},
193 { "mouse_move_pages_viewer", &mouse_move_pages_viewer
},
194 { "fast_refresh", &fast_refresh
},
195 { "navigate_with_arrows", &navigate_with_arrows
},
196 { "advanced_chown", &advanced_chfns
},
197 { "drop_menus", &drop_menus
},
198 { "wrap_mode", &global_wrap_mode
},
199 { "old_esc_mode", &old_esc_mode
},
200 { "cd_symlinks", &cd_symlinks
},
201 { "show_all_if_ambiguous", &show_all_if_ambiguous
},
202 { "have_fast_cpu", &have_fast_cpu
},
203 { "iconify_on_exec", &iconify_on_exec
},
204 { "torben_fj_mode", &torben_fj_mode
},
205 { "use_file_to_guess_type", &use_file_to_check_type
},
206 { "alternate_plus_minus", &alternate_plus_minus
},
207 { "only_leading_plus_minus", &only_leading_plus_minus
},
208 { "show_output_starts_shell", &output_starts_shell
},
209 { "panel_scroll_pages", &panel_scroll_pages
},
210 { "xtree_mode", &xtree_mode
},
211 { "num_history_items_recorded", &num_history_items_recorded
},
212 #ifdef SAVE_CHANGES_OUTSIDE_OPTIONS_MENU
213 { "dive_into_subdirs", &dive_into_subdirs
},
214 { "preserve_uidgid", &preserve_uidgid
},
215 /* What about the other two options in the copy dialog
216 (follow links, stable symlinks) -Norbert */
217 { "tree_navigation_flag", &tree_navigation_flag
},
220 { "tar_gzipped_memlimit", &tar_gzipped_memlimit
},
221 { "vfs_timeout", &vfs_timeout
},
222 { "vfs_use_targz_memlimit", &vfs_use_limit
},
224 { "ftpfs_directory_timeout", &ftpfs_directory_timeout
},
225 { "use_netrc", &use_netrc
},
226 { "ftpfs_retry_seconds", &ftpfs_retry_seconds
},
227 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy
},
228 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections
},
229 { "ftpfs_use_unix_list_options", &ftpfs_use_passive_connections
},
232 #ifdef USE_INTERNAL_EDIT
233 { "editor_word_wrap_line_length", &option_word_wrap_line_length
},
234 { "editor_key_emulation", &edit_key_emulation
},
235 { "editor_tab_spacing", &option_tab_spacing
},
236 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces
},
237 { "editor_return_does_auto_indent", &option_return_does_auto_indent
},
238 { "editor_backspace_through_tabs", &option_backspace_through_tabs
},
239 { "editor_fake_half_tabs", &option_fake_half_tabs
},
240 { "editor_option_save_mode", &option_save_mode
},
241 { "editor_option_backup_ext_int", &option_backup_ext_int
},
242 { "editor_option_auto_para_formatting", &option_auto_para_formatting
},
243 { "editor_option_typewriter_wrap", &option_typewriter_wrap
},
244 { "editor_edit_confirm_save", &edit_confirm_save
},
245 { "editor_syntax_highlighting", &option_syntax_highlighting
},
249 { "want_transparent_text", &want_transparent_text
},
250 { "want_transparent_icons", &want_transparent_icons
},
251 { "icons_snap_to_grid", &icons_snap_to_grid
},
253 { "nice_rotating_dash", &nice_rotating_dash
},
254 { "horizontal_split", &horizontal_split
},
259 void panel_save_setup (WPanel
*panel
, char *section
)
264 sprintf (buffer
, "%d", panel
->reverse
);
265 save_string (section
, "reverse", buffer
, profile_name
);
266 sprintf (buffer
, "%d", panel
->case_sensitive
);
267 save_string (section
, "case_sensitive", buffer
, profile_name
);
268 for (i
= 0; sort_names
[i
].key
; i
++)
269 if (sort_names
[i
].sort_type
== (sortfn
*) panel
->sort_type
){
270 save_string (section
, "sort_order",
271 sort_names
[i
].key
, profile_name
);
275 for (i
= 0; list_types
[i
].key
; i
++)
276 if (list_types
[i
].list_type
== panel
->list_type
){
277 save_string (section
, PORT_LIST_MODE_NAME
, list_types
[i
].key
, profile_name
);
281 save_string (section
, "user_format",
282 panel
->user_format
, profile_name
);
284 for (i
= 0; i
< LIST_TYPES
; i
++){
285 sprintf (buffer
, "user_status%d", i
);
286 save_string (section
, buffer
,
287 panel
->user_status_format
[i
], profile_name
);
290 sprintf (buffer
, "%d", panel
->user_mini_status
);
291 save_string (section
, "user_mini_status", buffer
,
295 void save_layout (void)
301 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
303 /* Save integer options */
304 for (i
= 0; layout
[i
].opt_name
; i
++){
305 sprintf (buffer
, "%d", *layout
[i
].opt_addr
);
306 save_string ("Layout", layout
[i
].opt_name
, buffer
, profile
);
312 void save_configure (void)
317 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
319 /* Save integer options */
320 for (i
= 0; options
[i
].opt_name
; i
++)
321 set_int (profile
, options
[i
].opt_name
, *options
[i
].opt_addr
);
326 static void panel_save_type (char *section
, int type
)
330 for (i
= 0; panel_types
[i
].opt_name
; i
++)
331 if (panel_types
[i
].opt_type
== type
){
332 save_string (section
, "display", panel_types
[i
].opt_name
,
338 #ifndef PORT_HAS_SAVE_PANEL_TYPES
339 void save_panel_types ()
343 type
= get_display_type (0);
344 panel_save_type ("New Left Panel", type
);
345 if (type
== view_listing
)
346 panel_save_setup (left_panel
, left_panel
->panel_name
);
347 type
= get_display_type (1);
348 panel_save_type ("New Right Panel", type
);
349 if (type
== view_listing
)
350 panel_save_setup (right_panel
, right_panel
->panel_name
);
354 void save_setup (void)
359 extern char *ftpfs_anonymous_passwd
;
360 extern char *ftpfs_proxy_host
;
364 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
368 save_string ("Dirs", "other_dir",
369 get_other_type () == view_listing
370 ? opanel
->cwd
: ".", profile
);
371 WritePrivateProfileString ("Dirs", "current_is_left",
372 get_current_index () == 0 ? "1" : "0", profile
);
376 /* directory_history_save (); */
380 WritePrivateProfileString ("Misc", "ftpfs_password",
381 ftpfs_anonymous_passwd
, profile
);
382 if (ftpfs_proxy_host
)
383 WritePrivateProfileString ("Misc", "ftp_proxy_host",
384 ftpfs_proxy_host
, profile
);
391 void panel_load_setup (WPanel
*panel
, char *section
)
396 panel
->reverse
= load_int (section
, "reverse", 0);
397 panel
->case_sensitive
= load_int (section
, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT
);
399 /* Load sort order */
400 load_string (section
, "sort_order", "name", buffer
, sizeof (buffer
));
401 panel
->sort_type
= (sortfn
*) sort_name
;
402 for (i
= 0; sort_names
[i
].key
; i
++)
403 if (strcasecmp (sort_names
[i
].key
, buffer
) == 0){
404 panel
->sort_type
= sort_names
[i
].sort_type
;
408 /* Load the listing mode */
409 load_string (section
, PORT_LIST_MODE_NAME
, PORT_LIST_MODE_DEFAULT
, buffer
, sizeof (buffer
));
410 panel
->list_type
= list_full
;
411 for (i
= 0; list_types
[i
].key
; i
++)
412 if (strcasecmp (list_types
[i
].key
, buffer
) == 0){
413 panel
->list_type
= list_types
[i
].list_type
;
416 #ifndef PORT_HAS_ICON_VIEW
417 if (panel
->list_type
== list_icons
)
418 panel
->list_type
= list_full
;
421 if (panel
->user_format
){
422 free (panel
->user_format
);
423 panel
->user_format
= 0;
425 panel
->user_format
= strdup (get_profile_string (section
, "user_format",
428 for (i
= 0; i
< LIST_TYPES
; i
++){
429 if (panel
->user_status_format
[i
])
430 free (panel
->user_status_format
[i
]);
431 sprintf (buffer
, "user_status%d", i
);
432 panel
->user_status_format
[i
] =
433 strdup (get_profile_string (section
, buffer
,
434 DEFAULT_USER_FORMAT
, profile_name
));
437 panel
->user_mini_status
=
438 load_int (section
, "user_mini_status", 0);
442 static void load_layout (char *profile_name
)
446 for (i
= 0; layout
[i
].opt_name
; i
++)
447 *layout
[i
].opt_addr
=
448 load_int ("Layout", layout
[i
].opt_name
,
449 *layout
[i
].opt_addr
);
452 static int load_mode (char *section
)
457 int mode
= view_listing
;
459 /* Load the display mode */
460 load_string (section
, "display", "listing", buffer
, sizeof (buffer
));
462 for (i
= 0; panel_types
[i
].opt_name
; i
++)
463 if (strcasecmp (panel_types
[i
].opt_name
, buffer
) == 0){
464 mode
= panel_types
[i
].opt_type
;
471 char *do_load_string (char *s
, char *ss
, char *def
)
473 char *buffer
= xmalloc (128, "dls");
476 load_string (s
, ss
, def
, buffer
, 128);
483 void load_setup (void)
490 extern char *ftpfs_proxy_host
;
492 buffer
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
493 inifile
= concat_dir_and_file (mc_home
, "mc.ini");
494 if (exist_file (buffer
)){
496 } else if (exist_file (inifile
)){
497 profile
= strdup (inifile
);
504 profile_name
= profile
;
506 /* Load integer boolean options */
507 for (i
= 0; options
[i
].opt_name
; i
++)
508 *options
[i
].opt_addr
=
509 get_int (profile
, options
[i
].opt_name
, *options
[i
].opt_addr
);
511 load_layout (profile
);
515 startup_left_mode
= load_mode ("New Left Panel");
516 startup_right_mode
= load_mode ("New Right Panel");
518 /* At least one of the panels is a listing panel */
519 if (startup_left_mode
!= view_listing
&& startup_right_mode
!=view_listing
)
520 startup_left_mode
= view_listing
;
523 buffer
= (char*) malloc (MC_MAXPATHLEN
);
524 load_string ("Dirs", "other_dir", ".", buffer
,
526 if (vfs_file_is_local (buffer
))
532 ftpfs_proxy_host
= do_load_string ("Misc", "ftp_proxy_host", "gate");
534 boot_current_is_left
=
535 GetPrivateProfileInt ("Dirs", "current_is_left", 1, profile
);
537 load_string ("Misc", "find_ignore_dirs", "", setup_color_string
,
538 sizeof (setup_color_string
));
539 if (setup_color_string
[0])
540 find_ignore_dirs
= copy_strings (":", setup_color_string
, ":", 0);
542 /* The default color and the terminal dependent color */
543 load_string ("Colors", "base_color", "", setup_color_string
,
544 sizeof (setup_color_string
));
545 load_string ("Colors", getenv ("TERM"), "",
546 term_color_string
, sizeof (term_color_string
));
547 load_string ("Colors", "color_terminals", "",
548 color_terminal_string
, sizeof (color_terminal_string
));
550 /* Load the directory history */
551 /* directory_history_load (); */
552 /* Remove the temporal entries */
553 profile_clean_section ("Temporal:New Left Panel", profile_name
);
554 profile_clean_section ("Temporal:New Right Panel", profile_name
);
557 ftpfs_init_passwd ();
564 char *load_anon_passwd ()
568 load_string ("Misc", "ftpfs_password", "", buffer
, sizeof (buffer
));
570 return strdup (buffer
);
577 void done_setup (void)
582 /* directory_history_free (); */
585 void load_keys_from_section (char *terminal
, char *profile_name
)
589 char *key
, *value
, *valcopy
;
595 section_name
= copy_strings ("terminal:", terminal
, 0);
596 profile_keys
= profile_init_iterator (section_name
, profile_name
);
602 while (profile_keys
){
603 profile_keys
= profile_iterator_next (profile_keys
, &key
, &value
);
604 key_code
= lookup_key (key
);
605 valcopy
= convert_controls (value
);
607 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
614 void load_key_defs (void)
616 char *libfile
= concat_dir_and_file (mc_home
, "mc.lib");
617 load_keys_from_section (getenv ("TERM"), profile_name
);
618 load_keys_from_section ("general", profile_name
);
620 load_keys_from_section (getenv ("TERM"), libfile
);
621 load_keys_from_section ("general", libfile
);
623 /* We don't want a huge database loaded in core */
624 free_profile_name (libfile
);