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