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 tree_panel_visible
;
69 extern int we_can_afford_the_speed
;
75 extern int vfs_timeout
;
76 extern int tar_gzipped_memlimit
;
79 extern char *find_ignore_dirs
;
81 extern int num_history_items_recorded
;
85 char setup_color_string
[4096];
86 char term_color_string
[4096];
87 char color_terminal_string
[512];
89 #define load_int(a,b,c) GetPrivateProfileInt(a,b,c,profile_name)
90 #define load_string(a,b,c,d,e) GetPrivateProfileString(a,b,c,d,e,profile_name)
91 #define save_string WritePrivateProfileString
93 int startup_left_mode
;
94 int startup_right_mode
;
96 /* Ugly hack to allow panel_save_setup to work as a place holder for */
97 /* default panel values */
104 { "name", (sortfn
*) sort_name
},
105 { "extension", (sortfn
*) sort_ext
},
106 { "time", (sortfn
*) sort_time
},
107 { "atime", (sortfn
*) sort_atime
},
108 { "ctime", (sortfn
*) sort_ctime
},
109 { "size", (sortfn
*) sort_size
},
110 { "inode", (sortfn
*) sort_inode
},
111 { "unsorted", (sortfn
*) unsorted
},
119 { "full", list_full
},
120 { "brief", list_brief
},
121 { "long", list_long
},
122 { "user", list_user
},
123 { "icons", list_icons
},
131 { "listing", view_listing
},
132 { "quickview", view_quick
},
133 { "info", view_info
},
134 { "tree", view_tree
},
143 { "equal_split", &equal_split
},
144 { "first_panel_size", &first_panel_size
},
145 { "message_visible", &message_visible
},
146 { "keybar_visible", &keybar_visible
},
147 { "xterm_hintbar", &xterm_hintbar
},
148 { "output_lines", &output_lines
},
150 { "menubar_visible", &menubar_visible
},
151 { "command_prompt", &command_prompt
},
152 { "show_mini_info", &show_mini_info
},
153 { "permission_mode", &permission_mode
},
154 { "filetype_mode", &filetype_mode
},
159 #undef SAVE_CHANGES_OUTSIDE_OPTIONS_MENU
161 #ifdef SAVE_CHANGES_OUTSIDE_OPTIONS_MENU
162 extern int preserve_uidgid
;
169 { "show_backups", &show_backups
},
171 { "gnome_show_dot_files", &show_dot_files
},
173 { "show_dot_files", &show_dot_files
},
175 { "verbose", &verbose
},
176 { "mark_moves_down", &mark_moves_down
},
177 { "pause_after_run", &pause_after_run
},
178 { "shell_patterns", &easy_patterns
},
179 { "auto_save_setup", &auto_save_setup
},
180 { "align_extensions", &align_extensions
},
181 { "auto_menu", &auto_menu
},
182 { "use_internal_view", &use_internal_view
},
183 { "use_internal_edit", &use_internal_edit
},
184 { "clear_before_exec", &clear_before_exec
},
185 { "mix_all_files", &mix_all_files
},
186 { "fast_reload", &fast_reload
},
187 { "fast_reload_msg_shown", &fast_reload_w
},
188 { "confirm_delete", &confirm_delete
},
189 { "confirm_overwrite", &confirm_overwrite
},
190 { "confirm_execute", &confirm_execute
},
191 { "confirm_exit", &confirm_exit
},
192 { "safe_delete", &know_not_what_am_i_doing
},
193 { "mouse_repeat_rate", &mou_auto_repeat
},
194 { "double_click_speed", &double_click_speed
},
195 { "eight_bit_clean", &eight_bit_clean
},
196 { "full_eight_bits", &full_eight_bits
},
197 { "use_8th_bit_as_meta", &use_8th_bit_as_meta
},
198 { "confirm_view_dir", &confirm_view_dir
},
199 { "mouse_move_pages", &mouse_move_pages
},
200 { "mouse_move_pages_viewer", &mouse_move_pages_viewer
},
201 { "fast_refresh", &fast_refresh
},
202 { "navigate_with_arrows", &navigate_with_arrows
},
203 { "advanced_chown", &advanced_chfns
},
204 { "drop_menus", &drop_menus
},
205 { "wrap_mode", &global_wrap_mode
},
206 { "old_esc_mode", &old_esc_mode
},
207 { "cd_symlinks", &cd_symlinks
},
208 { "show_all_if_ambiguous", &show_all_if_ambiguous
},
209 { "have_fast_cpu", &have_fast_cpu
},
210 { "iconify_on_exec", &iconify_on_exec
},
211 { "torben_fj_mode", &torben_fj_mode
},
212 { "use_file_to_guess_type", &use_file_to_check_type
},
213 { "alternate_plus_minus", &alternate_plus_minus
},
214 { "only_leading_plus_minus", &only_leading_plus_minus
},
215 { "show_output_starts_shell", &output_starts_shell
},
216 { "panel_scroll_pages", &panel_scroll_pages
},
217 { "xtree_mode", &xtree_mode
},
218 { "num_history_items_recorded", &num_history_items_recorded
},
219 { "file_op_compute_totals", &file_op_compute_totals
},
220 #ifdef SAVE_CHANGES_OUTSIDE_OPTIONS_MENU
221 { "dive_into_subdirs", &dive_into_subdirs
},
222 { "preserve_uidgid", &preserve_uidgid
},
223 /* What about the other two options in the copy dialog
224 (follow links, stable symlinks) -Norbert */
225 { "tree_navigation_flag", &tree_navigation_flag
},
228 { "vfs_timeout", &vfs_timeout
},
230 { "ftpfs_directory_timeout", &ftpfs_directory_timeout
},
231 { "use_netrc", &use_netrc
},
232 { "ftpfs_retry_seconds", &ftpfs_retry_seconds
},
233 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy
},
234 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections
},
235 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options
},
236 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls
},
239 #ifdef USE_INTERNAL_EDIT
240 { "editor_word_wrap_line_length", &option_word_wrap_line_length
},
241 { "editor_key_emulation", &edit_key_emulation
},
242 { "editor_tab_spacing", &option_tab_spacing
},
243 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces
},
244 { "editor_return_does_auto_indent", &option_return_does_auto_indent
},
245 { "editor_backspace_through_tabs", &option_backspace_through_tabs
},
246 { "editor_fake_half_tabs", &option_fake_half_tabs
},
247 { "editor_option_save_mode", &option_save_mode
},
248 { "editor_option_backup_ext_int", &option_backup_ext_int
},
249 { "editor_option_auto_para_formatting", &option_auto_para_formatting
},
250 { "editor_option_typewriter_wrap", &option_typewriter_wrap
},
251 { "editor_edit_confirm_save", &edit_confirm_save
},
252 { "editor_syntax_highlighting", &option_syntax_highlighting
},
256 { "tree_panel_visible", &tree_panel_visible
},
257 { "we_can_afford_the_speed", &we_can_afford_the_speed
},
259 { "nice_rotating_dash", &nice_rotating_dash
},
260 { "horizontal_split", &horizontal_split
},
266 panel_save_setup (WPanel
*panel
, char *section
)
268 char buffer
[BUF_TINY
];
271 g_snprintf (buffer
, sizeof (buffer
), "%d", panel
->reverse
);
272 save_string (section
, "reverse", buffer
, profile_name
);
273 g_snprintf (buffer
, sizeof (buffer
), "%d", panel
->case_sensitive
);
274 save_string (section
, "case_sensitive", buffer
, profile_name
);
275 for (i
= 0; sort_names
[i
].key
; i
++)
276 if (sort_names
[i
].sort_type
== (sortfn
*) panel
->sort_type
){
277 save_string (section
, "sort_order",
278 sort_names
[i
].key
, profile_name
);
282 for (i
= 0; list_types
[i
].key
; i
++)
283 if (list_types
[i
].list_type
== panel
->list_type
){
284 save_string (section
, PORT_LIST_MODE_NAME
, list_types
[i
].key
, profile_name
);
288 save_string (section
, "user_format",
289 panel
->user_format
, profile_name
);
291 for (i
= 0; i
< LIST_TYPES
; i
++){
292 g_snprintf (buffer
, sizeof (buffer
), "user_status%d", i
);
293 save_string (section
, buffer
,
294 panel
->user_status_format
[i
], profile_name
);
297 g_snprintf (buffer
, sizeof (buffer
), "%d", panel
->user_mini_status
);
298 save_string (section
, "user_mini_status", buffer
,
307 char buffer
[BUF_TINY
];
309 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
311 /* Save integer options */
312 for (i
= 0; layout
[i
].opt_name
; i
++){
313 g_snprintf (buffer
, sizeof (buffer
), "%d", *layout
[i
].opt_addr
);
314 save_string ("Layout", layout
[i
].opt_name
, buffer
, profile
);
321 save_configure (void)
326 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
328 /* Save integer options */
329 for (i
= 0; options
[i
].opt_name
; i
++)
330 set_int (profile
, options
[i
].opt_name
, *options
[i
].opt_addr
);
336 panel_save_type (char *section
, int type
)
340 for (i
= 0; panel_types
[i
].opt_name
; i
++)
341 if (panel_types
[i
].opt_type
== type
){
342 save_string (section
, "display", panel_types
[i
].opt_name
,
348 #ifndef PORT_HAS_SAVE_PANEL_TYPES
354 type
= get_display_type (0);
355 panel_save_type ("New Left Panel", type
);
356 if (type
== view_listing
)
357 panel_save_setup (left_panel
, left_panel
->panel_name
);
358 type
= get_display_type (1);
359 panel_save_type ("New Right Panel", type
);
360 if (type
== view_listing
)
361 panel_save_setup (right_panel
, right_panel
->panel_name
);
371 extern char *ftpfs_anonymous_passwd
;
372 extern char *ftpfs_proxy_host
;
376 profile
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
380 save_string ("Dirs", "other_dir",
381 get_other_type () == view_listing
382 ? opanel
->cwd
: ".", profile
);
383 WritePrivateProfileString ("Dirs", "current_is_left",
384 get_current_index () == 0 ? "1" : "0", profile
);
388 /* directory_history_save (); */
392 WritePrivateProfileString ("Misc", "ftpfs_password",
393 ftpfs_anonymous_passwd
, profile
);
394 if (ftpfs_proxy_host
)
395 WritePrivateProfileString ("Misc", "ftp_proxy_host",
396 ftpfs_proxy_host
, profile
);
404 panel_load_setup (WPanel
*panel
, char *section
)
407 char buffer
[BUF_TINY
];
409 panel
->reverse
= load_int (section
, "reverse", 0);
410 panel
->case_sensitive
= load_int (section
, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT
);
412 /* Load sort order */
413 load_string (section
, "sort_order", "name", buffer
, sizeof (buffer
));
414 panel
->sort_type
= (sortfn
*) sort_name
;
415 for (i
= 0; sort_names
[i
].key
; i
++)
416 if ( g_strcasecmp (sort_names
[i
].key
, buffer
) == 0){
417 panel
->sort_type
= sort_names
[i
].sort_type
;
421 /* Load the listing mode */
422 load_string (section
, PORT_LIST_MODE_NAME
, PORT_LIST_MODE_DEFAULT
, buffer
, sizeof (buffer
));
423 panel
->list_type
= list_full
;
424 for (i
= 0; list_types
[i
].key
; i
++)
425 if ( g_strcasecmp (list_types
[i
].key
, buffer
) == 0){
426 panel
->list_type
= list_types
[i
].list_type
;
429 #ifndef PORT_HAS_ICON_VIEW
430 if (panel
->list_type
== list_icons
)
431 panel
->list_type
= list_full
;
434 if (panel
->user_format
){
435 g_free (panel
->user_format
);
436 panel
->user_format
= 0;
438 panel
->user_format
= g_strdup (get_profile_string (section
, "user_format",
441 for (i
= 0; i
< LIST_TYPES
; i
++){
442 if (panel
->user_status_format
[i
])
443 g_free (panel
->user_status_format
[i
]);
444 g_snprintf (buffer
, sizeof (buffer
), "user_status%d", i
);
445 panel
->user_status_format
[i
] =
446 g_strdup (get_profile_string (section
, buffer
,
447 DEFAULT_USER_FORMAT
, profile_name
));
450 panel
->user_mini_status
=
451 load_int (section
, "user_mini_status", 0);
456 load_layout (char *profile_name
)
460 for (i
= 0; layout
[i
].opt_name
; i
++)
461 *layout
[i
].opt_addr
=
462 load_int ("Layout", layout
[i
].opt_name
,
463 *layout
[i
].opt_addr
);
467 load_mode (char *section
)
472 int mode
= view_listing
;
474 /* Load the display mode */
475 load_string (section
, "display", "listing", buffer
, sizeof (buffer
));
477 for (i
= 0; panel_types
[i
].opt_name
; i
++)
478 if ( g_strcasecmp (panel_types
[i
].opt_name
, buffer
) == 0){
479 mode
= panel_types
[i
].opt_type
;
487 do_load_string (char *s
, char *ss
, char *def
)
489 char *buffer
= g_malloc (128);
492 load_string (s
, ss
, def
, buffer
, 128);
494 p
= g_strdup (buffer
);
509 buffer
= concat_dir_and_file (home_dir
, PROFILE_NAME
);
510 inifile
= concat_dir_and_file (mc_home
, "mc.ini");
511 if (exist_file (buffer
)){
513 } else if (exist_file (inifile
)){
514 profile
= g_strdup (inifile
);
521 profile_name
= profile
;
533 extern char *ftpfs_proxy_host
;
536 profile
= setup_init ();
537 /* Load integer boolean options */
538 for (i
= 0; options
[i
].opt_name
; i
++)
539 *options
[i
].opt_addr
=
540 get_int (profile
, options
[i
].opt_name
, *options
[i
].opt_addr
);
542 load_layout (profile
);
546 startup_left_mode
= load_mode ("New Left Panel");
547 startup_right_mode
= load_mode ("New Right Panel");
549 /* At least one of the panels is a listing panel */
550 if (startup_left_mode
!= view_listing
&& startup_right_mode
!=view_listing
)
551 startup_left_mode
= view_listing
;
556 buffer
= (char*) g_malloc (MC_MAXPATHLEN
);
557 load_string ("Dirs", "other_dir", ".", buffer
,
559 if (vfs_file_is_local (buffer
))
565 ftpfs_proxy_host
= do_load_string ("Misc", "ftp_proxy_host", "gate");
567 boot_current_is_left
=
568 GetPrivateProfileInt ("Dirs", "current_is_left", 1, profile
);
570 load_string ("Misc", "find_ignore_dirs", "", setup_color_string
,
571 sizeof (setup_color_string
));
572 if (setup_color_string
[0])
573 find_ignore_dirs
= g_strconcat (":", setup_color_string
, ":", NULL
);
575 /* The default color and the terminal dependent color */
576 load_string ("Colors", "base_color", "", setup_color_string
,
577 sizeof (setup_color_string
));
578 load_string ("Colors", getenv ("TERM"), "",
579 term_color_string
, sizeof (term_color_string
));
580 load_string ("Colors", "color_terminals", "",
581 color_terminal_string
, sizeof (color_terminal_string
));
583 /* Load the directory history */
584 /* directory_history_load (); */
585 /* Remove the temporal entries */
586 profile_clean_section ("Temporal:New Left Panel", profile_name
);
587 profile_clean_section ("Temporal:New Right Panel", profile_name
);
590 ftpfs_init_passwd ();
602 load_string ("Misc", "ftpfs_password", "", buffer
, sizeof (buffer
));
604 return g_strdup (buffer
);
611 void done_setup (void)
613 g_free (profile_name
);
616 /* directory_history_free (); */
620 load_keys_from_section (char *terminal
, char *profile_name
)
624 char *key
, *value
, *valcopy
;
630 section_name
= g_strconcat ("terminal:", terminal
, NULL
);
631 profile_keys
= profile_init_iterator (section_name
, profile_name
);
633 g_free (section_name
);
637 while (profile_keys
){
638 profile_keys
= profile_iterator_next (profile_keys
, &key
, &value
);
639 key_code
= lookup_key (key
);
640 valcopy
= convert_controls (value
);
642 define_sequence (key_code
, valcopy
, MCKEY_NOACTION
);
645 g_free (section_name
);
649 void load_key_defs (void)
651 char *libfile
= concat_dir_and_file (mc_home
, "mc.lib");
652 load_keys_from_section (getenv ("TERM"), profile_name
);
653 load_keys_from_section ("general", profile_name
);
655 load_keys_from_section (getenv ("TERM"), libfile
);
656 load_keys_from_section ("general", libfile
);
658 /* We don't want a huge database loaded in core */
659 free_profile_name (libfile
);