This source file includes following definitions.
- setup__is_cfg_group_must_panel_config
- setup__move_panels_config_into_separate_file
- load_config
- setup__load_panel_state
- load_layout
- load_keys_from_section
- panel_save_type
- panels_load_options
- panels_save_options
- save_config
- save_layout
- save_panel_types
- setup_init
- load_setup
- save_setup
- done_setup
- setup_save_config_show_error
- load_key_defs
- load_anon_passwd
- panel_load_setup
- panel_save_setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 #include <config.h>
28
29 #include <stdlib.h>
30 #include <string.h>
31 #include <stdio.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34
35 #include "lib/global.h"
36
37 #include "lib/tty/tty.h"
38 #include "lib/tty/key.h"
39 #include "lib/mcconfig.h"
40 #include "lib/fileloc.h"
41 #include "lib/timefmt.h"
42 #include "lib/util.h"
43
44 #ifdef ENABLE_VFS_FTP
45 #include "src/vfs/ftpfs/ftpfs.h"
46 #endif
47 #ifdef ENABLE_VFS_SHELL
48 #include "src/vfs/shell/shell.h"
49 #endif
50
51 #ifdef HAVE_CHARSET
52 #include "lib/charsets.h"
53 #endif
54
55 #include "filemanager/dir.h"
56 #include "filemanager/filemanager.h"
57 #include "filemanager/tree.h"
58 #include "filemanager/hotlist.h"
59 #include "filemanager/panelize.h"
60 #include "filemanager/layout.h"
61 #include "filemanager/cmd.h"
62
63 #include "args.h"
64 #include "execute.h"
65 #include "clipboard.h"
66
67 #ifdef HAVE_CHARSET
68 #include "selcodepage.h"
69 #endif
70
71 #ifdef USE_INTERNAL_EDIT
72 #include "src/editor/edit.h"
73 #endif
74
75 #include "src/viewer/mcviewer.h"
76
77 #include "setup.h"
78
79
80
81
82 gboolean boot_current_is_left = TRUE;
83
84
85 gboolean safe_delete = FALSE;
86
87 gboolean safe_overwrite = FALSE;
88
89
90 gboolean clear_before_exec = TRUE;
91
92
93 gboolean confirm_delete = TRUE;
94
95 gboolean confirm_directory_hotlist_delete = FALSE;
96
97 gboolean confirm_overwrite = TRUE;
98
99 gboolean confirm_execute = FALSE;
100
101 gboolean confirm_exit = FALSE;
102
103
104 gboolean auto_menu = FALSE;
105
106 gboolean drop_menus = FALSE;
107
108
109
110 gboolean confirm_view_dir = FALSE;
111
112
113 gboolean editor_ask_filename_before_edit = FALSE;
114
115 panel_view_mode_t startup_left_mode;
116 panel_view_mode_t startup_right_mode;
117
118 gboolean copymove_persistent_attr = TRUE;
119
120
121 int option_tab_spacing = DEFAULT_TAB_SPACING;
122
123
124
125 int saving_setup;
126
127 panels_options_t panels_options = {
128 .show_mini_info = TRUE,
129 .kilobyte_si = FALSE,
130 .mix_all_files = FALSE,
131 .show_backups = TRUE,
132 .show_dot_files = TRUE,
133 .fast_reload = FALSE,
134 .fast_reload_msg_shown = FALSE,
135 .mark_moves_down = TRUE,
136 .reverse_files_only = TRUE,
137 .auto_save_setup = FALSE,
138 .navigate_with_arrows = FALSE,
139 .scroll_pages = TRUE,
140 .scroll_center = FALSE,
141 .mouse_move_pages = TRUE,
142 .filetype_mode = TRUE,
143 .permission_mode = FALSE,
144 .qsearch_mode = QSEARCH_PANEL_CASE,
145 .torben_fj_mode = FALSE,
146 .select_flags = SELECT_MATCH_CASE | SELECT_SHELL_PATTERNS
147 };
148
149 gboolean easy_patterns = TRUE;
150
151
152 gboolean auto_save_setup = TRUE;
153
154
155
156
157 gboolean only_leading_plus_minus = TRUE;
158
159
160 gboolean auto_fill_mkdir_name = TRUE;
161
162
163 gboolean output_starts_shell = FALSE;
164
165 #ifdef USE_FILE_CMD
166
167 gboolean use_file_to_check_type = TRUE;
168 #endif
169
170 gboolean verbose = TRUE;
171
172
173
174
175
176
177 gboolean file_op_compute_totals = TRUE;
178
179
180 gboolean use_internal_view = TRUE;
181
182 gboolean use_internal_edit = TRUE;
183
184 #ifdef HAVE_CHARSET
185
186 int default_source_codepage = -1;
187 char *autodetect_codeset = NULL;
188 gboolean is_autodetect_codeset_enabled = FALSE;
189 #endif
190
191 #ifdef HAVE_ASPELL
192 char *spell_language = NULL;
193 #endif
194
195
196 char *saved_other_dir = NULL;
197
198
199 char *last_wd_string = NULL;
200
201
202 int quit = 0;
203
204
205 int print_last_revert = FALSE;
206
207 #ifdef USE_INTERNAL_EDIT
208
209 int macro_index = -1;
210
211
212 struct macro_action_t record_macro_buf[MAX_MACRO_LENGTH];
213
214 GArray *macros_list;
215 #endif
216
217
218
219
220 #define FMTYEAR _("%b %e %Y")
221 #define FMTTIME _("%b %e %H:%M")
222
223
224
225
226
227
228
229 static char *profile_name = NULL;
230 static char *panels_profile_name = NULL;
231
232
233 static const struct
234 {
235 const char *key;
236 int list_format;
237 } list_formats [] = {
238 { "full", list_full },
239 { "brief", list_brief },
240 { "long", list_long },
241 { "user", list_user },
242 { NULL, 0 }
243 };
244
245 static const struct
246 {
247 const char *opt_name;
248 panel_view_mode_t opt_type;
249 } panel_types [] = {
250 { "listing", view_listing },
251 { "quickview", view_quick },
252 { "info", view_info },
253 { "tree", view_tree },
254 { NULL, view_listing }
255 };
256
257 static const struct
258 {
259 const char *opt_name;
260 int *opt_addr;
261 } layout_int_options [] = {
262 { "output_lines", &output_lines },
263 { "left_panel_size", &panels_layout.left_panel_size },
264 { "top_panel_size", &panels_layout.top_panel_size },
265 { NULL, NULL }
266 };
267
268 static const struct
269 {
270 const char *opt_name;
271 gboolean *opt_addr;
272 } layout_bool_options [] = {
273 { "message_visible", &mc_global.message_visible },
274 { "keybar_visible", &mc_global.keybar_visible },
275 { "xterm_title", &xterm_title },
276 { "command_prompt", &command_prompt },
277 { "menubar_visible", &menubar_visible },
278 { "free_space", &free_space },
279 { "horizontal_split", &panels_layout.horizontal_split },
280 { "vertical_equal", &panels_layout.vertical_equal },
281 { "horizontal_equal", &panels_layout.horizontal_equal },
282 { NULL, NULL }
283 };
284
285 static const struct
286 {
287 const char *opt_name;
288 gboolean *opt_addr;
289 } bool_options [] = {
290 { "verbose", &verbose },
291 { "shell_patterns", &easy_patterns },
292 { "auto_save_setup", &auto_save_setup },
293 { "preallocate_space", &mc_global.vfs.preallocate_space },
294 { "auto_menu", &auto_menu },
295 { "use_internal_view", &use_internal_view },
296 { "use_internal_edit", &use_internal_edit },
297 { "clear_before_exec", &clear_before_exec },
298 { "confirm_delete", &confirm_delete },
299 { "confirm_overwrite", &confirm_overwrite },
300 { "confirm_execute", &confirm_execute },
301 { "confirm_history_cleanup", &mc_global.widget.confirm_history_cleanup },
302 { "confirm_exit", &confirm_exit },
303 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete },
304 { "confirm_view_dir", &confirm_view_dir },
305 { "safe_delete", &safe_delete },
306 { "safe_overwrite", &safe_overwrite },
307 #ifndef HAVE_CHARSET
308 { "eight_bit_clean", &mc_global.eight_bit_clean },
309 { "full_eight_bits", &mc_global.full_eight_bits },
310 #endif
311 { "use_8th_bit_as_meta", &use_8th_bit_as_meta },
312 { "mouse_move_pages_viewer", &mcview_mouse_move_pages },
313 { "mouse_close_dialog", &mouse_close_dialog},
314 { "fast_refresh", &fast_refresh },
315 { "drop_menus", &drop_menus },
316 { "wrap_mode", &mcview_global_flags.wrap },
317 { "old_esc_mode", &old_esc_mode },
318 { "cd_symlinks", &mc_global.vfs.cd_symlinks },
319 { "show_all_if_ambiguous", &mc_global.widget.show_all_if_ambiguous },
320 #ifdef USE_FILE_CMD
321 { "use_file_to_guess_type", &use_file_to_check_type },
322 #endif
323 { "alternate_plus_minus", &mc_global.tty.alternate_plus_minus },
324 { "only_leading_plus_minus", &only_leading_plus_minus },
325 { "show_output_starts_shell", &output_starts_shell },
326 { "xtree_mode", &xtree_mode },
327 { "file_op_compute_totals", &file_op_compute_totals },
328 { "classic_progressbar", &classic_progressbar },
329 #ifdef ENABLE_VFS
330 #ifdef ENABLE_VFS_FTP
331 { "use_netrc", &ftpfs_use_netrc },
332 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy },
333 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections },
334 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy },
335 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options },
336 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls },
337 { "ignore_ftp_chattr_errors", & ftpfs_ignore_chattr_errors} ,
338 #endif
339 #endif
340 #ifdef USE_INTERNAL_EDIT
341 { "editor_fill_tabs_with_spaces", &edit_options.fill_tabs_with_spaces },
342 { "editor_return_does_auto_indent", &edit_options.return_does_auto_indent },
343 { "editor_backspace_through_tabs", &edit_options.backspace_through_tabs },
344 { "editor_fake_half_tabs", &edit_options.fake_half_tabs },
345 { "editor_option_save_position", &edit_options.save_position },
346 { "editor_option_auto_para_formatting", &edit_options.auto_para_formatting },
347 { "editor_option_typewriter_wrap", &edit_options.typewriter_wrap },
348 { "editor_edit_confirm_save", &edit_options.confirm_save },
349 { "editor_syntax_highlighting", &edit_options.syntax_highlighting },
350 { "editor_persistent_selections", &edit_options.persistent_selections },
351 { "editor_drop_selection_on_copy", &edit_options.drop_selection_on_copy },
352 { "editor_cursor_beyond_eol", &edit_options.cursor_beyond_eol },
353 { "editor_cursor_after_inserted_block", &edit_options.cursor_after_inserted_block },
354 { "editor_visible_tabs", &edit_options.visible_tabs },
355 { "editor_visible_spaces", &edit_options.visible_tws },
356 { "editor_line_state", &edit_options.line_state },
357 { "editor_simple_statusbar", &edit_options.simple_statusbar },
358 { "editor_check_new_line", &edit_options.check_nl_at_eof },
359 { "editor_show_right_margin", &edit_options.show_right_margin },
360 { "editor_group_undo", &edit_options.group_undo },
361 { "editor_state_full_filename", &edit_options.state_full_filename },
362 #endif
363 { "editor_ask_filename_before_edit", &editor_ask_filename_before_edit },
364 { "nice_rotating_dash", &nice_rotating_dash },
365 { "shadows", &mc_global.tty.shadows },
366 { "mcview_remember_file_position", &mcview_remember_file_position },
367 { "auto_fill_mkdir_name", &auto_fill_mkdir_name },
368 { "copymove_persistent_attr", ©move_persistent_attr },
369 { NULL, NULL }
370 };
371
372 static const struct
373 {
374 const char *opt_name;
375 int *opt_addr;
376 } int_options [] = {
377 { "pause_after_run", &pause_after_run },
378 { "mouse_repeat_rate", &mou_auto_repeat },
379 { "double_click_speed", &double_click_speed },
380 { "old_esc_mode_timeout", &old_esc_mode_timeout },
381 { "max_dirt_limit", &mcview_max_dirt_limit },
382 { "num_history_items_recorded", &num_history_items_recorded },
383 #ifdef ENABLE_VFS
384 { "vfs_timeout", &vfs_timeout },
385 #ifdef ENABLE_VFS_FTP
386 { "ftpfs_directory_timeout", &ftpfs_directory_timeout },
387 { "ftpfs_retry_seconds", &ftpfs_retry_seconds },
388 #endif
389 #ifdef ENABLE_VFS_SHELL
390 { "shell_directory_timeout", &shell_directory_timeout },
391 #endif
392 #endif
393
394 { "editor_tab_spacing", &option_tab_spacing },
395 #ifdef USE_INTERNAL_EDIT
396 { "editor_word_wrap_line_length", &edit_options.word_wrap_line_length },
397 { "editor_option_save_mode", &edit_options.save_mode },
398 #endif
399 { NULL, NULL }
400 };
401
402 static const struct
403 {
404 const char *opt_name;
405 char **opt_addr;
406 const char *opt_defval;
407 } str_options[] = {
408 #ifdef USE_INTERNAL_EDIT
409 { "editor_backup_extension", &edit_options.backup_ext, "~" },
410 { "editor_filesize_threshold", &edit_options.filesize_threshold, "64M" },
411 { "editor_stop_format_chars", &edit_options.stop_format_chars, "-+*\\,.;:&>" },
412 #endif
413 { "mcview_eof", &mcview_show_eof, "" },
414 { NULL, NULL, NULL }
415 };
416
417 static const struct
418 {
419 const char *opt_name;
420 gboolean *opt_addr;
421 } panels_ini_options[] = {
422 { "show_mini_info", &panels_options.show_mini_info },
423 { "kilobyte_si", &panels_options.kilobyte_si },
424 { "mix_all_files", &panels_options.mix_all_files },
425 { "show_backups", &panels_options.show_backups },
426 { "show_dot_files", &panels_options.show_dot_files },
427 { "fast_reload", &panels_options.fast_reload },
428 { "fast_reload_msg_shown", &panels_options.fast_reload_msg_shown },
429 { "mark_moves_down", &panels_options.mark_moves_down },
430 { "reverse_files_only", &panels_options.reverse_files_only },
431 { "auto_save_setup_panels", &panels_options.auto_save_setup },
432 { "navigate_with_arrows", &panels_options.navigate_with_arrows },
433 { "panel_scroll_pages", &panels_options.scroll_pages },
434 { "panel_scroll_center", &panels_options.scroll_center },
435 { "mouse_move_pages", &panels_options.mouse_move_pages },
436 { "filetype_mode", &panels_options.filetype_mode },
437 { "permission_mode", &panels_options.permission_mode },
438 { "torben_fj_mode", &panels_options.torben_fj_mode },
439 { NULL, NULL }
440 };
441
442
443
444
445
446
447 static const char *
448 setup__is_cfg_group_must_panel_config (const char *grp)
449 {
450 return (strcasecmp ("Dirs", grp) == 0||
451 strcasecmp ("Temporal:New Right Panel", grp) == 0||
452 strcasecmp ("Temporal:New Left Panel", grp) == 0 ||
453 strcasecmp ("New Left Panel", grp) == 0 || strcasecmp ("New Right Panel", grp) == 0)
454 ? grp : NULL;
455 }
456
457
458
459 static void
460 setup__move_panels_config_into_separate_file (const char *profile)
461 {
462 mc_config_t *tmp_cfg;
463 char **groups, **curr_grp;
464
465 if (!exist_file (profile))
466 return;
467
468 tmp_cfg = mc_config_init (profile, FALSE);
469 if (tmp_cfg == NULL)
470 return;
471
472 groups = mc_config_get_groups (tmp_cfg, NULL);
473 if (*groups == NULL)
474 {
475 g_strfreev (groups);
476 mc_config_deinit (tmp_cfg);
477 return;
478 }
479
480 for (curr_grp = groups; *curr_grp != NULL; curr_grp++)
481 if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL)
482 mc_config_del_group (tmp_cfg, *curr_grp);
483
484 mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
485 mc_config_deinit (tmp_cfg);
486
487 tmp_cfg = mc_config_init (profile, FALSE);
488 if (tmp_cfg == NULL)
489 {
490 g_strfreev (groups);
491 return;
492 }
493
494 for (curr_grp = groups; *curr_grp != NULL; curr_grp++)
495 {
496 const char *need_grp;
497
498 need_grp = setup__is_cfg_group_must_panel_config (*curr_grp);
499 if (need_grp != NULL)
500 mc_config_del_group (tmp_cfg, need_grp);
501 }
502 g_strfreev (groups);
503
504 mc_config_save_file (tmp_cfg, NULL);
505 mc_config_deinit (tmp_cfg);
506 }
507
508
509
510 static void
511 load_config (void)
512 {
513 size_t i;
514 const char *kt;
515
516
517 for (i = 0; bool_options[i].opt_name != NULL; i++)
518 *bool_options[i].opt_addr =
519 mc_config_get_bool (mc_global.main_config, CONFIG_APP_SECTION, bool_options[i].opt_name,
520 *bool_options[i].opt_addr);
521
522
523 for (i = 0; int_options[i].opt_name != NULL; i++)
524 *int_options[i].opt_addr =
525 mc_config_get_int (mc_global.main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
526 *int_options[i].opt_addr);
527
528
529 for (i = 0; str_options[i].opt_name != NULL; i++)
530 *str_options[i].opt_addr =
531 mc_config_get_string (mc_global.main_config, CONFIG_APP_SECTION,
532 str_options[i].opt_name, str_options[i].opt_defval);
533
534
535 #ifdef USE_INTERNAL_EDIT
536 if (edit_options.word_wrap_line_length <= 0)
537 edit_options.word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
538 #else
539
540 use_internal_edit = FALSE;
541 #endif
542
543 if (option_tab_spacing <= 0)
544 option_tab_spacing = DEFAULT_TAB_SPACING;
545
546 kt = getenv ("KEYBOARD_KEY_TIMEOUT_US");
547 if (kt != NULL && kt[0] != '\0')
548 old_esc_mode_timeout = atoi (kt);
549 }
550
551
552
553 static panel_view_mode_t
554 setup__load_panel_state (const char *section)
555 {
556 char *buffer;
557 size_t i;
558 panel_view_mode_t mode = view_listing;
559
560
561 buffer = mc_config_get_string (mc_global.panels_config, section, "display", "listing");
562
563 for (i = 0; panel_types[i].opt_name != NULL; i++)
564 if (g_ascii_strcasecmp (panel_types[i].opt_name, buffer) == 0)
565 {
566 mode = panel_types[i].opt_type;
567 break;
568 }
569
570 g_free (buffer);
571
572 return mode;
573 }
574
575
576
577 static void
578 load_layout (void)
579 {
580 size_t i;
581
582
583 for (i = 0; layout_int_options[i].opt_name != NULL; i++)
584 *layout_int_options[i].opt_addr =
585 mc_config_get_int (mc_global.main_config, CONFIG_LAYOUT_SECTION,
586 layout_int_options[i].opt_name, *layout_int_options[i].opt_addr);
587
588 for (i = 0; layout_bool_options[i].opt_name != NULL; i++)
589 *layout_bool_options[i].opt_addr =
590 mc_config_get_bool (mc_global.main_config, CONFIG_LAYOUT_SECTION,
591 layout_bool_options[i].opt_name, *layout_bool_options[i].opt_addr);
592
593 startup_left_mode = setup__load_panel_state ("New Left Panel");
594 startup_right_mode = setup__load_panel_state ("New Right Panel");
595
596
597 if (startup_left_mode != view_listing && startup_right_mode != view_listing)
598 startup_left_mode = view_listing;
599
600 boot_current_is_left =
601 mc_config_get_bool (mc_global.panels_config, "Dirs", "current_is_left", TRUE);
602 }
603
604
605
606 static void
607 load_keys_from_section (const char *terminal, mc_config_t *cfg)
608 {
609 char *section_name;
610 gchar **profile_keys, **keys;
611 char *valcopy, *value;
612 long key_code;
613
614 if (terminal == NULL)
615 return;
616
617 section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
618 keys = mc_config_get_keys (cfg, section_name, NULL);
619
620 for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
621 {
622
623 if (g_ascii_strcasecmp (*profile_keys, "copy") == 0)
624 {
625 valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
626 load_keys_from_section (valcopy, cfg);
627 g_free (valcopy);
628 continue;
629 }
630
631 key_code = tty_keyname_to_keycode (*profile_keys, NULL);
632 if (key_code != 0)
633 {
634 gchar **values;
635
636 values = mc_config_get_string_list (cfg, section_name, *profile_keys, NULL);
637 if (values != NULL)
638 {
639 gchar **curr_values;
640
641 for (curr_values = values; *curr_values != NULL; curr_values++)
642 {
643 valcopy = convert_controls (*curr_values);
644 define_sequence (key_code, valcopy, MCKEY_NOACTION);
645 g_free (valcopy);
646 }
647
648 g_strfreev (values);
649 }
650 else
651 {
652 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
653 valcopy = convert_controls (value);
654 define_sequence (key_code, valcopy, MCKEY_NOACTION);
655 g_free (valcopy);
656 g_free (value);
657 }
658 }
659 }
660 g_strfreev (keys);
661 g_free (section_name);
662 }
663
664
665
666 static void
667 panel_save_type (const char *section, panel_view_mode_t type)
668 {
669 size_t i;
670
671 for (i = 0; panel_types[i].opt_name != NULL; i++)
672 if (panel_types[i].opt_type == type)
673 {
674 mc_config_set_string (mc_global.panels_config, section, "display",
675 panel_types[i].opt_name);
676 break;
677 }
678 }
679
680
681
682
683
684
685 static void
686 panels_load_options (void)
687 {
688 if (mc_config_has_group (mc_global.main_config, CONFIG_PANELS_SECTION))
689 {
690 size_t i;
691 int qmode;
692
693 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
694 *panels_ini_options[i].opt_addr =
695 mc_config_get_bool (mc_global.main_config, CONFIG_PANELS_SECTION,
696 panels_ini_options[i].opt_name,
697 *panels_ini_options[i].opt_addr);
698
699 qmode = mc_config_get_int (mc_global.main_config, CONFIG_PANELS_SECTION,
700 "quick_search_mode", (int) panels_options.qsearch_mode);
701 if (qmode < 0)
702 panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE;
703 else if (qmode >= QSEARCH_NUM)
704 panels_options.qsearch_mode = QSEARCH_PANEL_CASE;
705 else
706 panels_options.qsearch_mode = (qsearch_mode_t) qmode;
707
708 panels_options.select_flags =
709 mc_config_get_int (mc_global.main_config, CONFIG_PANELS_SECTION, "select_flags",
710 (int) panels_options.select_flags);
711 }
712 }
713
714
715
716
717
718
719 static void
720 panels_save_options (void)
721 {
722 size_t i;
723
724 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
725 mc_config_set_bool (mc_global.main_config, CONFIG_PANELS_SECTION,
726 panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr);
727
728 mc_config_set_int (mc_global.main_config, CONFIG_PANELS_SECTION,
729 "quick_search_mode", (int) panels_options.qsearch_mode);
730 mc_config_set_int (mc_global.main_config, CONFIG_PANELS_SECTION,
731 "select_flags", (int) panels_options.select_flags);
732 }
733
734
735
736 static void
737 save_config (void)
738 {
739 size_t i;
740
741
742 for (i = 0; bool_options[i].opt_name != NULL; i++)
743 mc_config_set_bool (mc_global.main_config, CONFIG_APP_SECTION, bool_options[i].opt_name,
744 *bool_options[i].opt_addr);
745
746
747 for (i = 0; int_options[i].opt_name != NULL; i++)
748 mc_config_set_int (mc_global.main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
749 *int_options[i].opt_addr);
750
751
752 for (i = 0; str_options[i].opt_name != NULL; i++)
753 mc_config_set_string (mc_global.main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
754 *str_options[i].opt_addr);
755 }
756
757
758
759 static void
760 save_layout (void)
761 {
762 size_t i;
763
764
765 for (i = 0; layout_int_options[i].opt_name != NULL; i++)
766 mc_config_set_int (mc_global.main_config, CONFIG_LAYOUT_SECTION,
767 layout_int_options[i].opt_name, *layout_int_options[i].opt_addr);
768
769
770 for (i = 0; layout_bool_options[i].opt_name != NULL; i++)
771 mc_config_set_bool (mc_global.main_config, CONFIG_LAYOUT_SECTION,
772 layout_bool_options[i].opt_name, *layout_bool_options[i].opt_addr);
773 }
774
775
776
777
778 static void
779 save_panel_types (void)
780 {
781 panel_view_mode_t type;
782
783 if (mc_global.mc_run_mode != MC_RUN_FULL)
784 return;
785
786 type = get_panel_type (0);
787 panel_save_type ("New Left Panel", type);
788 if (type == view_listing)
789 panel_save_setup (left_panel, left_panel->name);
790 type = get_panel_type (1);
791 panel_save_type ("New Right Panel", type);
792 if (type == view_listing)
793 panel_save_setup (right_panel, right_panel->name);
794
795 {
796 char *dirs;
797
798 dirs = get_panel_dir_for (other_panel);
799 mc_config_set_string (mc_global.panels_config, "Dirs", "other_dir", dirs);
800 g_free (dirs);
801 }
802
803 if (current_panel != NULL)
804 mc_config_set_bool (mc_global.panels_config, "Dirs", "current_is_left",
805 get_current_index () == 0);
806
807 if (mc_global.panels_config->ini_path == NULL)
808 mc_global.panels_config->ini_path = g_strdup (panels_profile_name);
809
810 mc_config_del_group (mc_global.panels_config, "Temporal:New Left Panel");
811 mc_config_del_group (mc_global.panels_config, "Temporal:New Right Panel");
812
813 mc_config_save_file (mc_global.panels_config, NULL);
814 }
815
816
817
818
819
820 const char *
821 setup_init (void)
822 {
823 if (profile_name == NULL)
824 {
825 char *profile;
826
827 profile = mc_config_get_full_path (MC_CONFIG_FILE);
828 if (!exist_file (profile))
829 {
830 char *inifile;
831
832 inifile = mc_build_filename (mc_global.sysconfig_dir, "mc.ini", (char *) NULL);
833 if (exist_file (inifile))
834 {
835 g_free (profile);
836 profile = inifile;
837 }
838 else
839 {
840 g_free (inifile);
841 inifile = mc_build_filename (mc_global.share_data_dir, "mc.ini", (char *) NULL);
842 if (!exist_file (inifile))
843 g_free (inifile);
844 else
845 {
846 g_free (profile);
847 profile = inifile;
848 }
849 }
850 }
851
852 profile_name = profile;
853 }
854
855 return profile_name;
856 }
857
858
859
860 void
861 load_setup (void)
862 {
863 const char *profile;
864
865 #ifdef HAVE_CHARSET
866 const char *cbuffer;
867
868 load_codepages_list ();
869 #endif
870
871 profile = setup_init ();
872
873
874
875 mc_global.profile_name =
876 g_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
877 if (!exist_file (mc_global.profile_name))
878 {
879 g_free (mc_global.profile_name);
880 mc_global.profile_name =
881 g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
882 }
883
884 panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE);
885
886 mc_global.main_config = mc_config_init (profile, FALSE);
887
888 if (!exist_file (panels_profile_name))
889 setup__move_panels_config_into_separate_file (profile);
890
891 mc_global.panels_config = mc_config_init (panels_profile_name, FALSE);
892
893 load_config ();
894 load_layout ();
895 panels_load_options ();
896 external_panelize_load ();
897
898
899 user_recent_timeformat =
900 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "timeformat_recent",
901 FMTTIME);
902 user_old_timeformat =
903 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "timeformat_old",
904 FMTYEAR);
905
906 #ifdef ENABLE_VFS_FTP
907 ftpfs_proxy_host =
908 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftp_proxy_host", "gate");
909 ftpfs_init_passwd ();
910 #endif
911
912
913 mc_global.tty.setup_color_string =
914 mc_config_get_string (mc_global.main_config, "Colors", "base_color", "");
915 mc_global.tty.term_color_string =
916 mc_config_get_string (mc_global.main_config, "Colors", getenv ("TERM"), "");
917 mc_global.tty.color_terminal_string =
918 mc_config_get_string (mc_global.main_config, "Colors", "color_terminals", "");
919
920
921
922
923
924 #ifdef HAVE_CHARSET
925 if (codepages->len > 1)
926 {
927 char *buffer;
928
929 buffer =
930 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "display_codepage",
931 "");
932 if (buffer[0] != '\0')
933 {
934 mc_global.display_codepage = get_codepage_index (buffer);
935 cp_display = get_codepage_id (mc_global.display_codepage);
936 }
937 g_free (buffer);
938 buffer =
939 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "source_codepage",
940 "");
941 if (buffer[0] != '\0')
942 {
943 default_source_codepage = get_codepage_index (buffer);
944 mc_global.source_codepage = default_source_codepage;
945 cp_source = get_codepage_id (mc_global.source_codepage);
946 }
947 g_free (buffer);
948 }
949
950 autodetect_codeset =
951 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "autodetect_codeset", "");
952 if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off") != 0))
953 is_autodetect_codeset_enabled = TRUE;
954
955 g_free (init_translation_table (mc_global.source_codepage, mc_global.display_codepage));
956 cbuffer = get_codepage_id (mc_global.display_codepage);
957 if (cbuffer != NULL)
958 mc_global.utf8_display = str_isutf8 (cbuffer);
959 #endif
960
961 #ifdef HAVE_ASPELL
962 spell_language =
963 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "spell_language", "en");
964 #endif
965
966 clipboard_store_path =
967 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_store", "");
968 clipboard_paste_path =
969 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_paste", "");
970 }
971
972
973
974 gboolean
975 save_setup (gboolean save_options, gboolean save_panel_options)
976 {
977 gboolean ret = TRUE;
978
979 saving_setup = 1;
980
981 save_hotlist ();
982
983 if (save_panel_options)
984 save_panel_types ();
985
986 if (save_options)
987 {
988 char *tmp_profile;
989
990 save_config ();
991 save_layout ();
992 panels_save_options ();
993 external_panelize_save ();
994
995
996 #ifdef ENABLE_VFS_FTP
997 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftpfs_password",
998 ftpfs_anonymous_passwd);
999 if (ftpfs_proxy_host)
1000 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftp_proxy_host",
1001 ftpfs_proxy_host);
1002 #endif
1003
1004 #ifdef HAVE_CHARSET
1005 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "display_codepage",
1006 get_codepage_id (mc_global.display_codepage));
1007 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "source_codepage",
1008 get_codepage_id (default_source_codepage));
1009 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "autodetect_codeset",
1010 autodetect_codeset);
1011 #endif
1012
1013 #ifdef HAVE_ASPELL
1014 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "spell_language",
1015 spell_language);
1016 #endif
1017
1018 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_store",
1019 clipboard_store_path);
1020 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_paste",
1021 clipboard_paste_path);
1022
1023 tmp_profile = mc_config_get_full_path (MC_CONFIG_FILE);
1024 ret = mc_config_save_to_file (mc_global.main_config, tmp_profile, NULL);
1025 g_free (tmp_profile);
1026 }
1027
1028 saving_setup = 0;
1029
1030 return ret;
1031 }
1032
1033
1034
1035 void
1036 done_setup (void)
1037 {
1038 size_t i;
1039
1040 g_free (clipboard_store_path);
1041 g_free (clipboard_paste_path);
1042 g_free (mc_global.profile_name);
1043 g_free (mc_global.tty.color_terminal_string);
1044 g_free (mc_global.tty.term_color_string);
1045 g_free (mc_global.tty.setup_color_string);
1046 g_free (profile_name);
1047 g_free (panels_profile_name);
1048 mc_config_deinit (mc_global.main_config);
1049 mc_config_deinit (mc_global.panels_config);
1050
1051 g_free (user_recent_timeformat);
1052 g_free (user_old_timeformat);
1053
1054 for (i = 0; str_options[i].opt_name != NULL; i++)
1055 g_free (*str_options[i].opt_addr);
1056
1057 done_hotlist ();
1058 external_panelize_free ();
1059
1060
1061 #ifdef HAVE_CHARSET
1062 g_free (autodetect_codeset);
1063 free_codepages_list ();
1064 #endif
1065
1066 #ifdef HAVE_ASPELL
1067 g_free (spell_language);
1068 #endif
1069 }
1070
1071
1072
1073
1074 void
1075 setup_save_config_show_error (const char *filename, GError **mcerror)
1076 {
1077 if (mcerror != NULL && *mcerror != NULL)
1078 {
1079 message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*mcerror)->message);
1080 g_error_free (*mcerror);
1081 *mcerror = NULL;
1082 }
1083 }
1084
1085
1086
1087 void
1088 load_key_defs (void)
1089 {
1090
1091
1092
1093
1094 mc_config_t *mc_global_config;
1095
1096 mc_global_config = mc_config_init (mc_global.profile_name, FALSE);
1097 if (mc_global_config != NULL)
1098 {
1099 load_keys_from_section ("general", mc_global_config);
1100 load_keys_from_section (getenv ("TERM"), mc_global_config);
1101 mc_config_deinit (mc_global_config);
1102 }
1103
1104 load_keys_from_section ("general", mc_global.main_config);
1105 load_keys_from_section (getenv ("TERM"), mc_global.main_config);
1106 }
1107
1108
1109
1110 #ifdef ENABLE_VFS_FTP
1111 char *
1112 load_anon_passwd (void)
1113 {
1114 char *buffer;
1115
1116 buffer =
1117 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftpfs_password", "");
1118
1119 if ((buffer != NULL) && (buffer[0] != '\0'))
1120 return buffer;
1121
1122 g_free (buffer);
1123 return NULL;
1124 }
1125 #endif
1126
1127
1128
1129 void
1130 panel_load_setup (WPanel *panel, const char *section)
1131 {
1132 size_t i;
1133 char *buffer;
1134
1135 panel->sort_info.reverse =
1136 mc_config_get_bool (mc_global.panels_config, section, "reverse", FALSE);
1137 panel->sort_info.case_sensitive =
1138 mc_config_get_bool (mc_global.panels_config, section, "case_sensitive",
1139 OS_SORT_CASE_SENSITIVE_DEFAULT);
1140 panel->sort_info.exec_first =
1141 mc_config_get_bool (mc_global.panels_config, section, "exec_first", FALSE);
1142
1143
1144 buffer = mc_config_get_string (mc_global.panels_config, section, "sort_order", "name");
1145 panel->sort_field = panel_get_field_by_id (buffer);
1146 if (panel->sort_field == NULL)
1147 panel->sort_field = panel_get_field_by_id ("name");
1148
1149 g_free (buffer);
1150
1151
1152 buffer = mc_config_get_string (mc_global.panels_config, section, "list_format", NULL);
1153 if (buffer == NULL)
1154 {
1155
1156 buffer = mc_config_get_string (mc_global.panels_config, section, "list_mode", "full");
1157 }
1158 panel->list_format = list_full;
1159 for (i = 0; list_formats[i].key != NULL; i++)
1160 if (g_ascii_strcasecmp (list_formats[i].key, buffer) == 0)
1161 {
1162 panel->list_format = list_formats[i].list_format;
1163 break;
1164 }
1165 g_free (buffer);
1166
1167 panel->brief_cols = mc_config_get_int (mc_global.panels_config, section, "brief_cols", 2);
1168
1169
1170 g_free (panel->user_format);
1171 panel->user_format =
1172 mc_config_get_string (mc_global.panels_config, section, "user_format", NULL);
1173
1174 for (i = 0; i < LIST_FORMATS; i++)
1175 {
1176 char buffer2[BUF_TINY];
1177
1178 g_free (panel->user_status_format[i]);
1179 g_snprintf (buffer2, sizeof (buffer2), "user_status%lld", (long long) i);
1180 panel->user_status_format[i] =
1181 mc_config_get_string (mc_global.panels_config, section, buffer2, NULL);
1182 }
1183
1184 panel->user_mini_status =
1185 mc_config_get_bool (mc_global.panels_config, section, "user_mini_status", FALSE);
1186
1187 panel->filter.value =
1188 mc_config_get_string (mc_global.panels_config, section, "filter_value", NULL);
1189 panel->filter.flags =
1190 mc_config_get_int (mc_global.panels_config, section, "filter_flags",
1191 (int) FILE_FILTER_DEFAULT_FLAGS);
1192 }
1193
1194
1195
1196 void
1197 panel_save_setup (WPanel *panel, const char *section)
1198 {
1199 char buffer[BUF_TINY];
1200 size_t i;
1201
1202 mc_config_set_bool (mc_global.panels_config, section, "reverse", panel->sort_info.reverse);
1203 mc_config_set_bool (mc_global.panels_config, section, "case_sensitive",
1204 panel->sort_info.case_sensitive);
1205 mc_config_set_bool (mc_global.panels_config, section, "exec_first",
1206 panel->sort_info.exec_first);
1207
1208 mc_config_set_string (mc_global.panels_config, section, "sort_order", panel->sort_field->id);
1209
1210 for (i = 0; list_formats[i].key != NULL; i++)
1211 if (list_formats[i].list_format == (int) panel->list_format)
1212 {
1213 mc_config_set_string (mc_global.panels_config, section, "list_format",
1214 list_formats[i].key);
1215 break;
1216 }
1217
1218 mc_config_set_int (mc_global.panels_config, section, "brief_cols", panel->brief_cols);
1219
1220 mc_config_set_string (mc_global.panels_config, section, "user_format", panel->user_format);
1221
1222 for (i = 0; i < LIST_FORMATS; i++)
1223 {
1224 g_snprintf (buffer, sizeof (buffer), "user_status%lld", (long long) i);
1225 mc_config_set_string (mc_global.panels_config, section, buffer,
1226 panel->user_status_format[i]);
1227 }
1228
1229 mc_config_set_bool (mc_global.panels_config, section, "user_mini_status",
1230 panel->user_mini_status);
1231
1232
1233 if (panel->filter.handler != NULL)
1234 mc_config_set_string (mc_global.panels_config, section, "filter_value",
1235 panel->filter.value);
1236 else
1237 mc_config_del_key (mc_global.panels_config, section, "filter_value");
1238 mc_config_set_int (mc_global.panels_config, section, "filter_flags", (int) panel->filter.flags);
1239 }
1240
1241