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>
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 */
46 # include "gdesktop.h"
49 #ifndef PORT_LIST_MODE_NAME
50 # define PORT_LIST_MODE_NAME "list_mode"
53 #ifndef PORT_LIST_MODE_DEFAULT
54 # define PORT_LIST_MODE_DEFAULT "full"
57 #include "../vfs/vfs.h"
59 # include "../vfs/ftpfs.h"
61 extern int ftpfs_retry_seconds
;
62 extern int ftpfs_use_passive_connections
;
63 extern int ftpfs_use_unix_list_options
;
64 extern int ftpfs_first_cd_then_ls
;
68 extern int we_can_afford_the_speed
;
74 extern int vfs_timeout
;
75 extern int tar_gzipped_memlimit
;
78 extern char *find_ignore_dirs
;
80 extern int num_history_items_recorded
;
84 char setup_color_string
[4096];
85 char term_color_string
[4096];
86 char color_terminal_string
[512];
88 #define load_int(a,b,c) GetPrivateProfileInt(a,b,c,profile_name)
89 #define load_string(a,b,c,d,e) GetPrivateProfileString(a,b,c,d,e,profile_name)
90 #define save_string WritePrivateProfileString
92 int startup_left_mode
;
93 int startup_right_mode
;
95 /* Ugly hack to allow panel_save_setup to work as a place holder for */
96 /* default panel values */
103 { "name", (sortfn
*) sort_name
},
104 { "extension", (sortfn
*) sort_ext
},
105 { "time", (sortfn
*) sort_time
},
106 { "atime", (sortfn
*) sort_atime
},
107 { "ctime", (sortfn
*) sort_ctime
},
108 { "size", (sortfn
*) sort_size
},
109 { "inode", (sortfn
*) sort_inode
},
110 { "unsorted", (sortfn
*) unsorted
},
118 { "full", list_full
},
119 { "brief", list_brief
},
120 { "long", list_long
},
121 { "user", list_user
},
122 { "icons", list_icons
},
130 { "listing", view_listing
},
131 { "quickview", view_quick
},
132 { "info", view_info
},
133 { "tree", view_tree
},
142 { "equal_split", &equal_split
},
143 { "first_panel_size", &first_panel_size
},
144 { "message_visible", &message_visible
},
145 { "keybar_visible", &keybar_visible
},
146 { "xterm_hintbar", &xterm_hintbar
},
147 { "output_lines", &output_lines
},
149 { "menubar_visible", &menubar_visible
},
150 { "command_prompt", &command_prompt
},
151 { "show_mini_info", &show_mini_info
},
152 { "permission_mode", &permission_mode
},
153 { "filetype_mode", &filetype_mode
},
158 #undef SAVE_CHANGES_OUTSIDE_OPTIONS_MENU
160 #ifdef SAVE_CHANGES_OUTSIDE_OPTIONS_MENU
161 extern int preserve_uidgid
;
168 { "show_backups", &show_backups
},
169 { "show_dot_files", &show_dot_files
},
170 { "verbose", &verbose
},
171 { "mark_moves_down", &mark_moves_down
},
172 { "pause_after_run", &pause_after_run
},
173 { "shell_patterns", &easy_patterns
},
174 { "auto_save_setup", &auto_save_setup
},
175 { "align_extensions", &align_extensions
},
176 { "auto_menu", &auto_menu
},
177 { "use_internal_view", &use_internal_view
},
178 { "use_internal_edit", &use_internal_edit
},
179 { "clear_before_exec", &clear_before_exec
},
180 { "mix_all_files", &mix_all_files
},
181 { "fast_reload", &fast_reload
},
182 { "fast_reload_msg_shown", &fast_reload_w
},
183 { "confirm_delete", &confirm_delete
},
184 { "confirm_overwrite", &confirm_overwrite
},
185 { "confirm_execute", &confirm_execute
},
186 { "confirm_exit", &confirm_exit
},
187 { "safe_delete", &know_not_what_am_i_doing
},
188 { "mouse_repeat_rate", &mou_auto_repeat
},
189 { "double_click_speed", &double_click_speed
},
190 { "eight_bit_clean", &eight_bit_clean
},
191 { "full_eight_bits", &full_eight_bits
},
192 { "use_8th_bit_as_meta", &use_8th_bit_as_meta
},
193 { "confirm_view_dir", &confirm_view_dir
},
194 { "mouse_move_pages", &mouse_move_pages
},
195 { "mouse_move_pages_viewer", &mouse_move_pages_viewer
},
196 { "fast_refresh", &fast_refresh
},
197 { "navigate_with_arrows", &navigate_with_arrows
},
198 { "advanced_chown", &advanced_chfns
},
199 { "drop_menus", &drop_menus
},
200 { "wrap_mode", &global_wrap_mode
},
201 { "old_esc_mode", &old_esc_mode
},
202 { "cd_symlinks", &cd_symlinks
},
203 { "show_all_if_ambiguous", &show_all_if_ambiguous
},
204 { "have_fast_cpu", &have_fast_cpu
},
205 { "iconify_on_exec", &iconify_on_exec
},
206 { "torben_fj_mode", &torben_fj_mode
},
207 { "use_file_to_guess_type", &use_file_to_check_type
},
208 { "alternate_plus_minus", &alternate_plus_minus
},
209 { "only_leading_plus_minus", &only_leading_plus_minus
},
210 { "show_output_starts_shell", &output_starts_shell
},
211 { "panel_scroll_pages", &panel_scroll_pages
},
212 { "xtree_mode", &xtree_mode
},
213 { "num_history_items_recorded", &num_history_items_recorded
},
214 { "file_op_compute_totals", &file_op_compute_totals
},
215 #ifdef SAVE_CHANGES_OUTSIDE_OPTIONS_MENU
216 { "dive_into_subdirs", &dive_into_subdirs
},
217 { "preserve_uidgid", &preserve_uidgid
},
218 /* What about the other two options in the copy dialog
219 (follow links, stable symlinks) -Norbert */
220 { "tree_navigation_flag", &tree_navigation_flag
},
223 { "vfs_timeout", &vfs_timeout
},
225 { "ftpfs_directory_timeout", &ftpfs_directory_timeout
},
226 { "use_netrc", &use_netrc
},
227 { "ftpfs_retry_seconds", &ftpfs_retry_seconds
},
228 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy
},
229 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections
},
230 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options
},
231 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls
},
234 #ifdef USE_INTERNAL_EDIT
235 { "editor_word_wrap_line_length", &option_word_wrap_line_length
},
236 { "editor_key_emulation", &edit_key_emulation
},
237 { "editor_tab_spacing", &option_tab_spacing
},
238 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces
},
239 { "editor_return_does_auto_indent", &option_return_does_auto_indent
},
240 { "editor_backspace_through_tabs", &option_backspace_through_tabs
},
241 { "editor_fake_half_tabs", &option_fake_half_tabs
},
242 { "editor_option_save_mode", &option_save_mode
},
243 { "editor_option_backup_ext_int", &option_backup_ext_int
},
244 { "editor_option_auto_para_formatting", &option_auto_para_formatting
},
245 { "editor_option_typewriter_wrap", &option_typewriter_wrap
},
246 { "editor_edit_confirm_save", &edit_confirm_save
},
247 { "editor_syntax_highlighting", &option_syntax_highlighting
},
251 { "tree_panel_visible", &tree_panel_visible
},
252 { "we_can_afford_the_speed", &we_can_afford_the_speed
},
254 { "nice_rotating_dash", &nice_rotating_dash
},
255 { "horizontal_split", &horizontal_split
},
261 panel_save_setup (WPanel
*panel
, char *section
)
263 char buffer
[BUF_TINY
];
266 g_snprintf (buffer
, sizeof (buffer
), "%d", panel
->reverse
);
267 save_string (section
, "reverse", buffer
, profile_name
);
268 g_snprintf (buffer
, sizeof (buffer
), "%d", panel
->case_sensitive
);
269 save_string (section
, "case_sensitive", buffer
, profile_name
);
270 for (i
= 0; sort_names
[i
].key
; i
++)
271 if (sort_names
[i
].sort_type
== (sortfn
*) panel
->sort_type
){
272 save_string (section
, "sort_order",
273 sort_names
[i
].key
, profile_name
);
277 for (i
= 0; list_types
[i
].key
; i
++)
278 if (list_types
[i
].list_type
== panel
->list_type
){
279 save_string (section
, PORT_LIST_MODE_NAME
, list_types
[i
].key
, profile_name
);
283 save_string (section
, "user_format",
284 panel
->user_format
, profile_name
);
286 for (i
= 0; i
< LIST_TYPES
; i
++){
287 g_snprintf (buffer
, sizeof (buffer
), "user_status%d", i
);
288 save_string (section
, buffer
,
289 panel
->user_status_format
[i
], profile_name
);
292 g_snprintf (buffer
, sizeof (buffer
), "%d", panel
->user_mini_status
);
293 save_string (section
, "user_mini_status", buffer
,
302 char buffer
[BUF_TINY
];
304 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
306 /* Save integer options */
307 for (i
= 0; layout
[i
].opt_name
; i
++){
308 g_snprintf (buffer
, sizeof (buffer
), "%d", *layout
[i
].opt_addr
);
309 save_string ("Layout", layout
[i
].opt_name
, buffer
, profile
);
316 save_configure (void)
321 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
323 /* Save integer options */
324 for (i
= 0; options
[i
].opt_name
; i
++)
325 set_int (profile
, options
[i
].opt_name
, *options
[i
].opt_addr
);
331 panel_save_type (char *section
, int type
)
335 for (i
= 0; panel_types
[i
].opt_name
; i
++)
336 if (panel_types
[i
].opt_type
== type
){
337 save_string (section
, "display", panel_types
[i
].opt_name
,
343 #ifndef PORT_HAS_SAVE_PANEL_TYPES
349 type
= get_display_type (0);
350 panel_save_type ("New Left Panel", type
);
351 if (type
== view_listing
)
352 panel_save_setup (left_panel
, left_panel
->panel_name
);
353 type
= get_display_type (1);
354 panel_save_type ("New Right Panel", type
);
355 if (type
== view_listing
)
356 panel_save_setup (right_panel
, right_panel
->panel_name
);
366 extern char *ftpfs_anonymous_passwd
;
367 extern char *ftpfs_proxy_host
;
371 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
375 save_string ("Dirs", "other_dir",
376 get_other_type () == view_listing
377 ? opanel
->cwd
: ".", profile
);
378 WritePrivateProfileString ("Dirs", "current_is_left",
379 get_current_index () == 0 ? "1" : "0", profile
);
383 /* directory_history_save (); */
387 WritePrivateProfileString ("Misc", "ftpfs_password",
388 ftpfs_anonymous_passwd
, profile
);
389 if (ftpfs_proxy_host
)
390 WritePrivateProfileString ("Misc", "ftp_proxy_host",
391 ftpfs_proxy_host
, profile
);
399 panel_load_setup (WPanel
*panel
, char *section
)
402 char buffer
[BUF_TINY
];
404 panel
->reverse
= load_int (section
, "reverse", 0);
405 panel
->case_sensitive
= load_int (section
, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT
);
407 /* Load sort order */
408 load_string (section
, "sort_order", "name", buffer
, sizeof (buffer
));
409 panel
->sort_type
= (sortfn
*) sort_name
;
410 for (i
= 0; sort_names
[i
].key
; i
++)
411 if ( g_strcasecmp (sort_names
[i
].key
, buffer
) == 0){
412 panel
->sort_type
= sort_names
[i
].sort_type
;
416 /* Load the listing mode */
417 load_string (section
, PORT_LIST_MODE_NAME
, PORT_LIST_MODE_DEFAULT
, buffer
, sizeof (buffer
));
418 panel
->list_type
= list_full
;
419 for (i
= 0; list_types
[i
].key
; i
++)
420 if ( g_strcasecmp (list_types
[i
].key
, buffer
) == 0){
421 panel
->list_type
= list_types
[i
].list_type
;
424 #ifndef PORT_HAS_ICON_VIEW
425 if (panel
->list_type
== list_icons
)
426 panel
->list_type
= list_full
;
429 if (panel
->user_format
){
430 g_free (panel
->user_format
);
431 panel
->user_format
= 0;
433 panel
->user_format
= g_strdup (get_profile_string (section
, "user_format",
436 for (i
= 0; i
< LIST_TYPES
; i
++){
437 if (panel
->user_status_format
[i
])
438 g_free (panel
->user_status_format
[i
]);
439 g_snprintf (buffer
, sizeof (buffer
), "user_status%d", i
);
440 panel
->user_status_format
[i
] =
441 g_strdup (get_profile_string (section
, buffer
,
442 DEFAULT_USER_FORMAT
, profile_name
));
445 panel
->user_mini_status
=
446 load_int (section
, "user_mini_status", 0);
451 load_layout (char *profile_name
)
455 for (i
= 0; layout
[i
].opt_name
; i
++)
456 *layout
[i
].opt_addr
=
457 load_int ("Layout", layout
[i
].opt_name
,
458 *layout
[i
].opt_addr
);
462 load_mode (char *section
)
467 int mode
= view_listing
;
469 /* Load the display mode */
470 load_string (section
, "display", "listing", buffer
, sizeof (buffer
));
472 for (i
= 0; panel_types
[i
].opt_name
; i
++)
473 if ( g_strcasecmp (panel_types
[i
].opt_name
, buffer
) == 0){
474 mode
= panel_types
[i
].opt_type
;
482 do_load_string (char *s
, char *ss
, char *def
)
484 char *buffer
= g_malloc (128);
487 load_string (s
, ss
, def
, buffer
, 128);
489 p
= g_strdup (buffer
);
502 extern char *ftpfs_proxy_host
;
504 buffer
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
505 inifile
= concat_dir_and_file (mc_home
, "mc.ini");
506 if (exist_file (buffer
)){
508 } else if (exist_file (inifile
)){
509 profile
= g_strdup (inifile
);
516 profile_name
= profile
;
518 /* Load integer boolean options */
519 for (i
= 0; options
[i
].opt_name
; i
++)
520 *options
[i
].opt_addr
=
521 get_int (profile
, options
[i
].opt_name
, *options
[i
].opt_addr
);
523 load_layout (profile
);
527 startup_left_mode
= load_mode ("New Left Panel");
528 startup_right_mode
= load_mode ("New Right Panel");
530 /* At least one of the panels is a listing panel */
531 if (startup_left_mode
!= view_listing
&& startup_right_mode
!=view_listing
)
532 startup_left_mode
= view_listing
;
535 buffer
= (char*) g_malloc (MC_MAXPATHLEN
);
536 load_string ("Dirs", "other_dir", ".", buffer
,
538 if (vfs_file_is_local (buffer
))
544 ftpfs_proxy_host
= do_load_string ("Misc", "ftp_proxy_host", "gate");
546 boot_current_is_left
=
547 GetPrivateProfileInt ("Dirs", "current_is_left", 1, profile
);
549 load_string ("Misc", "find_ignore_dirs", "", setup_color_string
,
550 sizeof (setup_color_string
));
551 if (setup_color_string
[0])
552 find_ignore_dirs
= g_strconcat (":", setup_color_string
, ":", NULL
);
554 /* The default color and the terminal dependent color */
555 load_string ("Colors", "base_color", "", setup_color_string
,
556 sizeof (setup_color_string
));
557 load_string ("Colors", getenv ("TERM"), "",
558 term_color_string
, sizeof (term_color_string
));
559 load_string ("Colors", "color_terminals", "",
560 color_terminal_string
, sizeof (color_terminal_string
));
562 /* Load the directory history */
563 /* directory_history_load (); */
564 /* Remove the temporal entries */
565 profile_clean_section ("Temporal:New Left Panel", profile_name
);
566 profile_clean_section ("Temporal:New Right Panel", profile_name
);
569 ftpfs_init_passwd ();
581 load_string ("Misc", "ftpfs_password", "", buffer
, sizeof (buffer
));
583 return g_strdup (buffer
);
590 void done_setup (void)
592 g_free (profile_name
);
595 /* directory_history_free (); */
599 load_keys_from_section (char *terminal
, char *profile_name
)
603 char *key
, *value
, *valcopy
;
609 section_name
= g_strconcat ("terminal:", terminal
, NULL
);
610 profile_keys
= profile_init_iterator (section_name
, profile_name
);
612 g_free (section_name
);
616 while (profile_keys
){
617 profile_keys
= profile_iterator_next (profile_keys
, &key
, &value
);
618 key_code
= lookup_key (key
);
619 valcopy
= convert_controls (value
);
621 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
624 g_free (section_name
);
628 void load_key_defs (void)
630 char *libfile
= concat_dir_and_file (mc_home
, "mc.lib");
631 load_keys_from_section (getenv ("TERM"), profile_name
);
632 load_keys_from_section ("general", profile_name
);
634 load_keys_from_section (getenv ("TERM"), libfile
);
635 load_keys_from_section ("general", libfile
);
637 /* We don't want a huge database loaded in core */
638 free_profile_name (libfile
);