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