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 */
48 #include "../vfs/vfs.h"
50 # include "../vfs/ftpfs.h"
56 extern int vfs_timeout
;
57 extern int tar_gzipped_memlimit
;
60 extern char *find_ignore_dirs
;
62 extern int num_history_items_recorded
;
66 char setup_color_string
[4096];
67 char term_color_string
[4096];
68 char color_terminal_string
[512];
70 #define load_int(a,b,c) GetPrivateProfileInt(a,b,c,profile_name)
71 #define load_string(a,b,c,d,e) GetPrivateProfileString(a,b,c,d,e,profile_name)
72 #define save_string WritePrivateProfileString
74 int startup_left_mode
;
75 int startup_right_mode
;
77 /* Ugly hack to allow panel_save_setup to work as a place holder for */
78 /* default panel values */
85 { "name", (sortfn
*) sort_name
},
86 { "extension", (sortfn
*) sort_ext
},
87 { "time", (sortfn
*) sort_time
},
88 { "atime", (sortfn
*) sort_atime
},
89 { "ctime", (sortfn
*) sort_ctime
},
90 { "size", (sortfn
*) sort_size
},
91 { "inode", (sortfn
*) sort_inode
},
92 { "unsorted", (sortfn
*) unsorted
},
100 { "full", list_full
},
101 { "brief", list_brief
},
102 { "long", list_long
},
103 { "user", list_user
},
104 { "icons", list_icons
},
108 static const struct {
112 { "listing", view_listing
},
113 { "quickview", view_quick
},
114 { "info", view_info
},
115 { "tree", view_tree
},
119 static const struct {
123 { "equal_split", &equal_split
},
124 { "first_panel_size", &first_panel_size
},
125 { "message_visible", &message_visible
},
126 { "keybar_visible", &keybar_visible
},
127 { "xterm_hintbar", &xterm_hintbar
},
128 { "output_lines", &output_lines
},
129 { "command_prompt", &command_prompt
},
130 { "menubar_visible", &menubar_visible
},
131 { "show_mini_info", &show_mini_info
},
132 { "permission_mode", &permission_mode
},
133 { "filetype_mode", &filetype_mode
},
138 #undef SAVE_CHANGES_OUTSIDE_OPTIONS_MENU
140 #ifdef SAVE_CHANGES_OUTSIDE_OPTIONS_MENU
141 extern int preserve_uidgid
;
144 static const struct {
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 { "safe_delete", &know_not_what_am_i_doing
},
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 { "advanced_chown", &advanced_chfns
},
180 { "drop_menus", &drop_menus
},
181 { "wrap_mode", &global_wrap_mode
},
182 { "old_esc_mode", &old_esc_mode
},
183 { "cd_symlinks", &cd_symlinks
},
184 { "show_all_if_ambiguous", &show_all_if_ambiguous
},
185 { "have_fast_cpu", &have_fast_cpu
},
186 { "torben_fj_mode", &torben_fj_mode
},
187 { "use_file_to_guess_type", &use_file_to_check_type
},
188 { "alternate_plus_minus", &alternate_plus_minus
},
189 { "only_leading_plus_minus", &only_leading_plus_minus
},
190 { "show_output_starts_shell", &output_starts_shell
},
191 { "panel_scroll_pages", &panel_scroll_pages
},
192 { "xtree_mode", &xtree_mode
},
193 { "num_history_items_recorded", &num_history_items_recorded
},
194 { "file_op_compute_totals", &file_op_compute_totals
},
195 #ifdef SAVE_CHANGES_OUTSIDE_OPTIONS_MENU
196 { "dive_into_subdirs", &dive_into_subdirs
},
197 { "preserve_uidgid", &preserve_uidgid
},
198 /* What about the other two options in the copy dialog
199 (follow links, stable symlinks) -Norbert */
200 { "tree_navigation_flag", &tree_navigation_flag
},
201 #endif /* SAVE_CHANGES_OUTSIDE_OPTIONS_MENU */
203 { "vfs_timeout", &vfs_timeout
},
205 { "ftpfs_directory_timeout", &ftpfs_directory_timeout
},
206 { "use_netrc", &use_netrc
},
207 { "ftpfs_retry_seconds", &ftpfs_retry_seconds
},
208 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy
},
209 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections
},
210 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options
},
211 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls
},
212 #endif /* USE_NETCODE */
214 #ifdef USE_INTERNAL_EDIT
215 { "editor_word_wrap_line_length", &option_word_wrap_line_length
},
216 { "editor_key_emulation", &edit_key_emulation
},
217 { "editor_tab_spacing", &option_tab_spacing
},
218 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces
},
219 { "editor_return_does_auto_indent", &option_return_does_auto_indent
},
220 { "editor_backspace_through_tabs", &option_backspace_through_tabs
},
221 { "editor_fake_half_tabs", &option_fake_half_tabs
},
222 { "editor_option_save_mode", &option_save_mode
},
223 { "editor_option_backup_ext_int", &option_backup_ext_int
},
224 { "editor_option_auto_para_formatting", &option_auto_para_formatting
},
225 { "editor_option_typewriter_wrap", &option_typewriter_wrap
},
226 { "editor_edit_confirm_save", &edit_confirm_save
},
227 { "editor_syntax_highlighting", &option_syntax_highlighting
},
228 #endif /* USE_INTERNAL_EDIT */
230 { "nice_rotating_dash", &nice_rotating_dash
},
231 { "horizontal_split", &horizontal_split
},
236 panel_save_setup (WPanel
*panel
, char *section
)
238 char buffer
[BUF_TINY
];
241 g_snprintf (buffer
, sizeof (buffer
), "%d", panel
->reverse
);
242 save_string (section
, "reverse", buffer
, profile_name
);
243 g_snprintf (buffer
, sizeof (buffer
), "%d", panel
->case_sensitive
);
244 save_string (section
, "case_sensitive", buffer
, profile_name
);
245 for (i
= 0; sort_names
[i
].key
; i
++)
246 if (sort_names
[i
].sort_type
== (sortfn
*) panel
->sort_type
){
247 save_string (section
, "sort_order",
248 sort_names
[i
].key
, profile_name
);
252 for (i
= 0; list_types
[i
].key
; i
++)
253 if (list_types
[i
].list_type
== panel
->list_type
){
254 save_string (section
, "list_mode", list_types
[i
].key
, profile_name
);
258 save_string (section
, "user_format",
259 panel
->user_format
, profile_name
);
261 for (i
= 0; i
< LIST_TYPES
; i
++){
262 g_snprintf (buffer
, sizeof (buffer
), "user_status%d", i
);
263 save_string (section
, buffer
,
264 panel
->user_status_format
[i
], profile_name
);
267 g_snprintf (buffer
, sizeof (buffer
), "%d", panel
->user_mini_status
);
268 save_string (section
, "user_mini_status", buffer
,
277 char buffer
[BUF_TINY
];
279 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
281 /* Save integer options */
282 for (i
= 0; layout
[i
].opt_name
; i
++){
283 g_snprintf (buffer
, sizeof (buffer
), "%d", *layout
[i
].opt_addr
);
284 save_string ("Layout", layout
[i
].opt_name
, buffer
, profile
);
291 save_configure (void)
296 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
298 /* Save integer options */
299 for (i
= 0; options
[i
].opt_name
; i
++)
300 set_int (profile
, options
[i
].opt_name
, *options
[i
].opt_addr
);
306 panel_save_type (char *section
, int type
)
310 for (i
= 0; panel_types
[i
].opt_name
; i
++)
311 if (panel_types
[i
].opt_type
== type
){
312 save_string (section
, "display", panel_types
[i
].opt_name
,
323 type
= get_display_type (0);
324 panel_save_type ("New Left Panel", type
);
325 if (type
== view_listing
)
326 panel_save_setup (left_panel
, left_panel
->panel_name
);
327 type
= get_display_type (1);
328 panel_save_type ("New Right Panel", type
);
329 if (type
== view_listing
)
330 panel_save_setup (right_panel
, right_panel
->panel_name
);
339 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
344 save_string ("Dirs", "other_dir",
345 get_other_type () == view_listing
346 ? opanel
->cwd
: ".", profile
);
347 if (get_current_panel () != NULL
)
348 WritePrivateProfileString ("Dirs", "current_is_left",
349 get_current_index () == 0 ? "1" : "0", profile
);
354 /* directory_history_save (); */
356 #if defined(USE_VFS) && defined (USE_NETCODE)
357 WritePrivateProfileString ("Misc", "ftpfs_password",
358 ftpfs_anonymous_passwd
, profile
);
359 if (ftpfs_proxy_host
)
360 WritePrivateProfileString ("Misc", "ftp_proxy_host",
361 ftpfs_proxy_host
, profile
);
362 #endif /* USE_VFS && USE_NETCODE */
365 save_string( "Misc", "display_codepage",
366 get_codepage_id( display_codepage
), profile_name
);
367 #endif /* HAVE_CHARSET */
374 panel_load_setup (WPanel
*panel
, char *section
)
377 char buffer
[BUF_TINY
];
379 panel
->reverse
= load_int (section
, "reverse", 0);
380 panel
->case_sensitive
= load_int (section
, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT
);
382 /* Load sort order */
383 load_string (section
, "sort_order", "name", buffer
, sizeof (buffer
));
384 panel
->sort_type
= (sortfn
*) sort_name
;
385 for (i
= 0; sort_names
[i
].key
; i
++)
386 if ( g_strcasecmp (sort_names
[i
].key
, buffer
) == 0){
387 panel
->sort_type
= sort_names
[i
].sort_type
;
391 /* Load the listing mode */
392 load_string (section
, "list_mode", "full", buffer
, sizeof (buffer
));
393 panel
->list_type
= list_full
;
394 for (i
= 0; list_types
[i
].key
; i
++)
395 if ( g_strcasecmp (list_types
[i
].key
, buffer
) == 0){
396 panel
->list_type
= list_types
[i
].list_type
;
400 if (panel
->list_type
== list_icons
)
401 panel
->list_type
= list_full
;
404 if (panel
->user_format
){
405 g_free (panel
->user_format
);
406 panel
->user_format
= 0;
408 panel
->user_format
= g_strdup (get_profile_string (section
, "user_format",
411 for (i
= 0; i
< LIST_TYPES
; i
++){
412 if (panel
->user_status_format
[i
])
413 g_free (panel
->user_status_format
[i
]);
414 g_snprintf (buffer
, sizeof (buffer
), "user_status%d", i
);
415 panel
->user_status_format
[i
] =
416 g_strdup (get_profile_string (section
, buffer
,
417 DEFAULT_USER_FORMAT
, profile_name
));
420 panel
->user_mini_status
=
421 load_int (section
, "user_mini_status", 0);
426 load_layout (char *profile_name
)
430 for (i
= 0; layout
[i
].opt_name
; i
++)
431 *layout
[i
].opt_addr
=
432 load_int ("Layout", layout
[i
].opt_name
,
433 *layout
[i
].opt_addr
);
437 load_mode (char *section
)
442 int mode
= view_listing
;
444 /* Load the display mode */
445 load_string (section
, "display", "listing", buffer
, sizeof (buffer
));
447 for (i
= 0; panel_types
[i
].opt_name
; i
++)
448 if ( g_strcasecmp (panel_types
[i
].opt_name
, buffer
) == 0){
449 mode
= panel_types
[i
].opt_type
;
458 do_load_string (char *s
, char *ss
, char *def
)
460 char *buffer
= g_malloc (BUF_SMALL
);
463 load_string (s
, ss
, def
, buffer
, BUF_SMALL
);
465 p
= g_strdup (buffer
);
469 #endif /* !USE_NETCODE */
480 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
481 if (!exist_file (profile
)){
482 inifile
= concat_dir_and_file (mc_home
, "mc.ini");
483 if (exist_file (inifile
)){
490 profile_name
= profile
;
501 profile
= setup_init ();
502 /* Load integer boolean options */
503 for (i
= 0; options
[i
].opt_name
; i
++)
504 *options
[i
].opt_addr
=
505 get_int (profile
, options
[i
].opt_name
, *options
[i
].opt_addr
);
507 load_layout (profile
);
511 startup_left_mode
= load_mode ("New Left Panel");
512 startup_right_mode
= load_mode ("New Right Panel");
514 /* At least one of the panels is a listing panel */
515 if (startup_left_mode
!= view_listing
&& startup_right_mode
!=view_listing
)
516 startup_left_mode
= view_listing
;
521 buffer
= (char*) g_malloc (MC_MAXPATHLEN
);
522 load_string ("Dirs", "other_dir", ".", buffer
,
524 if (vfs_file_is_local (buffer
))
530 boot_current_is_left
=
531 GetPrivateProfileInt ("Dirs", "current_is_left", 1, profile
);
534 ftpfs_proxy_host
= do_load_string ("Misc", "ftp_proxy_host", "gate");
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
= g_strconcat (":", setup_color_string
, ":", NULL
);
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
);
555 #if defined(USE_VFS) && defined (USE_NETCODE)
556 ftpfs_init_passwd ();
557 #endif /* USE_VFS && USE_NETCODE */
560 if ( load_codepages_list() > 0 ) {
562 load_string( "Misc", "display_codepage", "",
563 cpname
, sizeof(cpname
) );
564 if ( cpname
[0] != '\0' )
565 display_codepage
= get_codepage_index( cpname
);
568 init_translation_table( source_codepage
, display_codepage
);
569 #endif /* HAVE_CHARSET */
572 #if defined(USE_VFS) && defined (USE_NETCODE)
578 load_string ("Misc", "ftpfs_password", "", buffer
, sizeof (buffer
));
580 return g_strdup (buffer
);
584 #endif /* USE_VFS && USE_NETCODE */
586 void done_setup (void)
588 g_free (profile_name
);
591 /* directory_history_free (); */
595 load_keys_from_section (char *terminal
, char *profile_name
)
599 char *key
, *value
, *valcopy
;
605 section_name
= g_strconcat ("terminal:", terminal
, NULL
);
606 profile_keys
= profile_init_iterator (section_name
, profile_name
);
608 g_free (section_name
);
612 while (profile_keys
){
613 profile_keys
= profile_iterator_next (profile_keys
, &key
, &value
);
614 key_code
= lookup_key (key
);
616 valcopy
= convert_controls (value
);
617 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
621 g_free (section_name
);
625 void load_key_defs (void)
627 char *libfile
= concat_dir_and_file (mc_home
, "mc.lib");
630 * Load keys from mc.lib before ~/.mc/ini, so that the user
631 * definitions override global settings.
633 load_keys_from_section ("general", libfile
);
634 load_keys_from_section (getenv ("TERM"), libfile
);
635 load_keys_from_section ("general", profile_name
);
636 load_keys_from_section (getenv ("TERM"), profile_name
);
638 /* We don't want a huge database loaded in core */
639 free_profile_name (libfile
);