root/src/setup.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. load_setup_get_full_config_name
  2. setup__is_cfg_group_must_panel_config
  3. setup__move_panels_config_into_separate_file
  4. load_setup_init_config_from_file
  5. load_config
  6. setup__load_panel_state
  7. load_layout
  8. load_keys_from_section
  9. load_keymap_from_section
  10. load_setup_get_keymap_profile_config
  11. panel_save_type
  12. panels_load_options
  13. panels_save_options
  14. save_config
  15. save_layout
  16. save_panel_types
  17. setup_init
  18. load_setup
  19. save_setup
  20. done_setup
  21. setup_save_config_show_error
  22. load_key_defs
  23. load_anon_passwd
  24. load_keymap_defs
  25. free_keymap_defs
  26. panel_load_setup
  27. panel_save_setup

   1 /*
   2    Setup loading/saving.
   3 
   4    Copyright (C) 1994-2019
   5    Free Software Foundation, Inc.
   6 
   7    This file is part of the Midnight Commander.
   8 
   9    The Midnight Commander is free software: you can redistribute it
  10    and/or modify it under the terms of the GNU General Public License as
  11    published by the Free Software Foundation, either version 3 of the License,
  12    or (at your option) any later version.
  13 
  14    The Midnight Commander is distributed in the hope that it will be useful,
  15    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17    GNU General Public License for more details.
  18 
  19    You should have received a copy of the GNU General Public License
  20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21  */
  22 
  23 /** \file setup.c
  24  *  \brief Source: setup loading/saving
  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"       /* num_history_items_recorded */
  40 #include "lib/fileloc.h"
  41 #include "lib/timefmt.h"
  42 #include "lib/util.h"
  43 #include "lib/widget.h"
  44 
  45 #ifdef ENABLE_VFS_FTP
  46 #include "src/vfs/ftpfs/ftpfs.h"
  47 #endif
  48 #ifdef ENABLE_VFS_FISH
  49 #include "src/vfs/fish/fish.h"
  50 #endif
  51 
  52 #ifdef HAVE_CHARSET
  53 #include "lib/charsets.h"
  54 #endif
  55 
  56 #include "filemanager/dir.h"
  57 #include "filemanager/midnight.h"
  58 #include "filemanager/tree.h"   /* xtree_mode */
  59 #include "filemanager/hotlist.h"        /* load/save/done hotlist */
  60 #include "filemanager/panelize.h"       /* load/save/done panelize */
  61 #include "filemanager/layout.h"
  62 #include "filemanager/cmd.h"
  63 
  64 #include "args.h"
  65 #include "execute.h"            /* pause_after_run */
  66 #include "clipboard.h"
  67 #include "keybind-defaults.h"   /* keybind_lookup_action */
  68 
  69 #ifdef HAVE_CHARSET
  70 #include "selcodepage.h"
  71 #endif
  72 
  73 #ifdef USE_INTERNAL_EDIT
  74 #include "src/editor/edit.h"
  75 #endif
  76 
  77 #include "src/viewer/mcviewer.h"        /* For the externs */
  78 
  79 #include "setup.h"
  80 
  81 /*** global variables ****************************************************************************/
  82 
  83 char *global_profile_name;      /* mc.lib */
  84 
  85 /* Only used at program boot */
  86 gboolean boot_current_is_left = TRUE;
  87 
  88 /* If on, default for "No" in delete operations */
  89 gboolean safe_delete = FALSE;
  90 /* If on, default for "No" in overwrite files */
  91 gboolean safe_overwrite = FALSE;
  92 
  93 /* Controls screen clearing before an exec */
  94 gboolean clear_before_exec = TRUE;
  95 
  96 /* Asks for confirmation before deleting a file */
  97 gboolean confirm_delete = TRUE;
  98 /* Asks for confirmation before deleting a hotlist entry */
  99 gboolean confirm_directory_hotlist_delete = FALSE;
 100 /* Asks for confirmation before overwriting a file */
 101 gboolean confirm_overwrite = TRUE;
 102 /* Asks for confirmation before executing a program by pressing enter */
 103 gboolean confirm_execute = FALSE;
 104 /* Asks for confirmation before leaving the program */
 105 gboolean confirm_exit = FALSE;
 106 
 107 /* If true, at startup the user-menu is invoked */
 108 gboolean auto_menu = FALSE;
 109 /* This flag indicates if the pull down menus by default drop down */
 110 gboolean drop_menus = FALSE;
 111 
 112 /* Asks for confirmation when using F3 to view a directory and there
 113    are tagged files */
 114 gboolean confirm_view_dir = FALSE;
 115 
 116 /* Ask file name before start the editor */
 117 gboolean editor_ask_filename_before_edit = FALSE;
 118 
 119 panel_view_mode_t startup_left_mode;
 120 panel_view_mode_t startup_right_mode;
 121 
 122 gboolean copymove_persistent_attr = TRUE;
 123 
 124 /* Tab size */
 125 int option_tab_spacing = DEFAULT_TAB_SPACING;
 126 
 127 /* Ugly hack to allow panel_save_setup to work as a place holder for */
 128 /* default panel values */
 129 int saving_setup;
 130 
 131 panels_options_t panels_options = {
 132     .show_mini_info = TRUE,
 133     .kilobyte_si = FALSE,
 134     .mix_all_files = FALSE,
 135     .show_backups = TRUE,
 136     .show_dot_files = TRUE,
 137     .fast_reload = FALSE,
 138     .fast_reload_msg_shown = FALSE,
 139     .mark_moves_down = TRUE,
 140     .reverse_files_only = TRUE,
 141     .auto_save_setup = FALSE,
 142     .navigate_with_arrows = FALSE,
 143     .scroll_pages = TRUE,
 144     .scroll_center = FALSE,
 145     .mouse_move_pages = TRUE,
 146     .filetype_mode = TRUE,
 147     .permission_mode = FALSE,
 148     .qsearch_mode = QSEARCH_PANEL_CASE,
 149     .torben_fj_mode = FALSE,
 150     .select_flags = SELECT_MATCH_CASE | SELECT_SHELL_PATTERNS
 151 };
 152 
 153 gboolean easy_patterns = TRUE;
 154 
 155 /* It true saves the setup when quitting */
 156 gboolean auto_save_setup = TRUE;
 157 
 158 /* If true, then the +, - and \ keys have their special meaning only if the
 159  * command line is empty, otherwise they behave like regular letters
 160  */
 161 gboolean only_leading_plus_minus = TRUE;
 162 
 163 /* Automatically fills name with current selected item name on mkdir */
 164 gboolean auto_fill_mkdir_name = TRUE;
 165 
 166 /* If set and you don't have subshell support, then C-o will give you a shell */
 167 gboolean output_starts_shell = FALSE;
 168 
 169 /* If set, we execute the file command to check the file type */
 170 gboolean use_file_to_check_type = TRUE;
 171 
 172 gboolean verbose = TRUE;
 173 
 174 /*
 175  * Whether the Midnight Commander tries to provide more
 176  * information about copy/move sizes and bytes transferred
 177  * at the expense of some speed
 178  */
 179 gboolean file_op_compute_totals = TRUE;
 180 
 181 /* If true use the internal viewer */
 182 gboolean use_internal_view = TRUE;
 183 /* If set, use the builtin editor */
 184 gboolean use_internal_edit = TRUE;
 185 
 186 #ifdef HAVE_CHARSET
 187 /* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
 188 int default_source_codepage = -1;
 189 char *autodetect_codeset = NULL;
 190 gboolean is_autodetect_codeset_enabled = FALSE;
 191 #endif /* !HAVE_CHARSET */
 192 
 193 #ifdef HAVE_ASPELL
 194 char *spell_language = NULL;
 195 #endif
 196 
 197 /* Value of "other_dir" key in ini file */
 198 char *saved_other_dir = NULL;
 199 
 200 /* If set, then print to the given file the last directory we were at */
 201 char *last_wd_string = NULL;
 202 
 203 /* Set when main loop should be terminated */
 204 int quit = 0;
 205 
 206 /* Set to TRUE to suppress printing the last directory */
 207 int print_last_revert = FALSE;
 208 
 209 #ifdef USE_INTERNAL_EDIT
 210 /* index to record_macro_buf[], -1 if not recording a macro */
 211 int macro_index = -1;
 212 
 213 /* macro stuff */
 214 struct macro_action_t record_macro_buf[MAX_MACRO_LENGTH];
 215 
 216 GArray *macros_list;
 217 #endif /* USE_INTERNAL_EDIT */
 218 
 219 /*** file scope macro definitions ****************************************************************/
 220 
 221 /* In order to use everywhere the same setup for the locale we use defines */
 222 #define FMTYEAR _("%b %e  %Y")
 223 #define FMTTIME _("%b %e %H:%M")
 224 
 225 /*** file scope type declarations ****************************************************************/
 226 
 227 /*** file scope variables ************************************************************************/
 228 
 229 static char *profile_name = NULL;       /* ${XDG_CONFIG_HOME}/mc/ini */
 230 static char *panels_profile_name = NULL;        /* ${XDG_CACHE_HOME}/mc/panels.ini */
 231 
 232 /* *INDENT-OFF* */
 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 [] = {
 262     { "message_visible", &mc_global.message_visible },
 263     { "keybar_visible", &mc_global.keybar_visible },
 264     { "xterm_title", &xterm_title },
 265     { "output_lines", &output_lines },
 266     { "command_prompt", &command_prompt },
 267     { "menubar_visible", &menubar_visible },
 268     { "free_space", &free_space },
 269     { "horizontal_split", &panels_layout.horizontal_split },
 270     { "vertical_equal", &panels_layout.vertical_equal },
 271     { "left_panel_size", &panels_layout.left_panel_size },
 272     { "horizontal_equal", &panels_layout.horizontal_equal },
 273     { "top_panel_size", &panels_layout.top_panel_size },
 274     { NULL, NULL }
 275 };
 276 
 277 static const struct
 278 {
 279     const char *opt_name;
 280     gboolean *opt_addr;
 281 } bool_options [] = {
 282     { "verbose", &verbose },
 283     { "shell_patterns", &easy_patterns },
 284     { "auto_save_setup", &auto_save_setup },
 285     { "preallocate_space", &mc_global.vfs.preallocate_space },
 286     { "auto_menu", &auto_menu },
 287     { "use_internal_view", &use_internal_view },
 288     { "use_internal_edit", &use_internal_edit },
 289     { "clear_before_exec", &clear_before_exec },
 290     { "confirm_delete", &confirm_delete },
 291     { "confirm_overwrite", &confirm_overwrite },
 292     { "confirm_execute", &confirm_execute },
 293     { "confirm_history_cleanup", &mc_global.widget.confirm_history_cleanup },
 294     { "confirm_exit", &confirm_exit },
 295     { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete },
 296     { "confirm_view_dir", &confirm_view_dir },
 297     { "safe_delete", &safe_delete },
 298     { "safe_overwrite", &safe_overwrite },
 299 #ifndef HAVE_CHARSET
 300     { "eight_bit_clean", &mc_global.eight_bit_clean },
 301     { "full_eight_bits", &mc_global.full_eight_bits },
 302 #endif /* !HAVE_CHARSET */
 303     { "use_8th_bit_as_meta", &use_8th_bit_as_meta },
 304     { "mouse_move_pages_viewer", &mcview_mouse_move_pages },
 305     { "mouse_close_dialog", &mouse_close_dialog},
 306     { "fast_refresh", &fast_refresh },
 307     { "drop_menus", &drop_menus },
 308     { "wrap_mode",  &mcview_global_flags.wrap },
 309     { "old_esc_mode", &old_esc_mode },
 310     { "cd_symlinks", &mc_global.vfs.cd_symlinks },
 311     { "show_all_if_ambiguous", &mc_global.widget.show_all_if_ambiguous },
 312     { "use_file_to_guess_type", &use_file_to_check_type },
 313     { "alternate_plus_minus", &mc_global.tty.alternate_plus_minus },
 314     { "only_leading_plus_minus", &only_leading_plus_minus },
 315     { "show_output_starts_shell", &output_starts_shell },
 316     { "xtree_mode", &xtree_mode },
 317     { "file_op_compute_totals", &file_op_compute_totals },
 318     { "classic_progressbar", &classic_progressbar },
 319 #ifdef ENABLE_VFS
 320 #ifdef ENABLE_VFS_FTP
 321     { "use_netrc", &ftpfs_use_netrc },
 322     { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy },
 323     { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections },
 324     { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy },
 325     { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options },
 326     { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls },
 327     { "ignore_ftp_chattr_errors", & ftpfs_ignore_chattr_errors} ,
 328 #endif /* ENABLE_VFS_FTP */
 329 #endif /* ENABLE_VFS */
 330 #ifdef USE_INTERNAL_EDIT
 331     { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces },
 332     { "editor_return_does_auto_indent", &option_return_does_auto_indent },
 333     { "editor_backspace_through_tabs", &option_backspace_through_tabs },
 334     { "editor_fake_half_tabs", &option_fake_half_tabs },
 335     { "editor_option_save_position", &option_save_position },
 336     { "editor_option_auto_para_formatting", &option_auto_para_formatting },
 337     { "editor_option_typewriter_wrap", &option_typewriter_wrap },
 338     { "editor_edit_confirm_save", &edit_confirm_save },
 339     { "editor_syntax_highlighting", &option_syntax_highlighting },
 340     { "editor_persistent_selections", &option_persistent_selections },
 341     { "editor_drop_selection_on_copy", &option_drop_selection_on_copy },
 342     { "editor_cursor_beyond_eol", &option_cursor_beyond_eol },
 343     { "editor_cursor_after_inserted_block", &option_cursor_after_inserted_block },
 344     { "editor_visible_tabs", &visible_tabs },
 345     { "editor_visible_spaces", &visible_tws },
 346     { "editor_line_state", &option_line_state },
 347     { "editor_simple_statusbar", &simple_statusbar },
 348     { "editor_check_new_line", &option_check_nl_at_eof },
 349     { "editor_show_right_margin", &show_right_margin },
 350     { "editor_group_undo", &option_group_undo },
 351     { "editor_state_full_filename", &option_state_full_filename },
 352 #endif /* USE_INTERNAL_EDIT */
 353     { "editor_ask_filename_before_edit", &editor_ask_filename_before_edit },
 354     { "nice_rotating_dash", &nice_rotating_dash },
 355     { "mcview_remember_file_position", &mcview_remember_file_position },
 356     { "auto_fill_mkdir_name", &auto_fill_mkdir_name },
 357     { "copymove_persistent_attr", &copymove_persistent_attr },
 358     { NULL, NULL }
 359 };
 360 
 361 static const struct
 362 {
 363     const char *opt_name;
 364     int *opt_addr;
 365 } int_options [] = {
 366     { "pause_after_run", &pause_after_run },
 367     { "mouse_repeat_rate", &mou_auto_repeat },
 368     { "double_click_speed", &double_click_speed },
 369     { "old_esc_mode_timeout", &old_esc_mode_timeout },
 370     { "max_dirt_limit", &mcview_max_dirt_limit },
 371     { "num_history_items_recorded", &num_history_items_recorded },
 372 #ifdef ENABLE_VFS
 373     { "vfs_timeout", &vfs_timeout },
 374 #ifdef ENABLE_VFS_FTP
 375     { "ftpfs_directory_timeout", &ftpfs_directory_timeout },
 376     { "ftpfs_retry_seconds", &ftpfs_retry_seconds },
 377 #endif /* ENABLE_VFS_FTP */
 378 #ifdef ENABLE_VFS_FISH
 379     { "fish_directory_timeout", &fish_directory_timeout },
 380 #endif /* ENABLE_VFS_FISH */
 381 #endif /* ENABLE_VFS */
 382     /* option_tab_spacing is used in internal viewer */
 383     { "editor_tab_spacing", &option_tab_spacing },
 384 #ifdef USE_INTERNAL_EDIT
 385     { "editor_word_wrap_line_length", &option_word_wrap_line_length },
 386     { "editor_option_save_mode", &option_save_mode },
 387 #endif /* USE_INTERNAL_EDIT */
 388     { NULL, NULL }
 389 };
 390 
 391 static const struct
 392 {
 393     const char *opt_name;
 394     char **opt_addr;
 395     const char *opt_defval;
 396 } str_options[] = {
 397 #ifdef USE_INTERNAL_EDIT
 398     { "editor_backup_extension", &option_backup_ext, "~" },
 399     { "editor_filesize_threshold", &option_filesize_threshold, "64M" },
 400     { "editor_stop_format_chars", &option_stop_format_chars, "-+*\\,.;:&>" },
 401 #endif
 402     { "mcview_eof", &mcview_show_eof, "" },
 403     {  NULL, NULL, NULL }
 404 };
 405 
 406 static const struct
 407 {
 408     const char *opt_name;
 409     gboolean *opt_addr;
 410 } panels_ini_options[] = {
 411     { "show_mini_info", &panels_options.show_mini_info },
 412     { "kilobyte_si", &panels_options.kilobyte_si },
 413     { "mix_all_files", &panels_options.mix_all_files },
 414     { "show_backups", &panels_options.show_backups },
 415     { "show_dot_files", &panels_options.show_dot_files },
 416     { "fast_reload", &panels_options.fast_reload },
 417     { "fast_reload_msg_shown", &panels_options.fast_reload_msg_shown },
 418     { "mark_moves_down", &panels_options.mark_moves_down },
 419     { "reverse_files_only", &panels_options.reverse_files_only },
 420     { "auto_save_setup_panels", &panels_options.auto_save_setup },
 421     { "navigate_with_arrows", &panels_options.navigate_with_arrows },
 422     { "panel_scroll_pages", &panels_options.scroll_pages },
 423     { "panel_scroll_center", &panels_options.scroll_center },
 424     { "mouse_move_pages",  &panels_options.mouse_move_pages },
 425     { "filetype_mode", &panels_options.filetype_mode },
 426     { "permission_mode", &panels_options.permission_mode },
 427     { "torben_fj_mode", &panels_options.torben_fj_mode },
 428     { NULL, NULL }
 429 };
 430 /* *INDENT-ON* */
 431 
 432 /*** file scope functions ************************************************************************/
 433 /* --------------------------------------------------------------------------------------------- */
 434 
 435 /**
 436  * Get name of config file.
 437  *
 438  * @param subdir If not NULL, config is also searched in specified subdir.
 439  * @param config_file_name If relative, file if searched in standard paths.
 440  *
 441  * @return newly allocated string with config name or NULL if file is not found.
 442  */
 443 
 444 static char *
 445 load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
     /* [previous][next][first][last][top][bottom][index][help]  */
 446 {
 447     /*
 448        TODO: IMHO, in future, this function shall be placed in mcconfig module.
 449      */
 450     char *lc_basename, *ret;
 451     char *file_name;
 452 
 453     if (config_file_name == NULL)
 454         return NULL;
 455 
 456     /* check for .keymap suffix */
 457     if (g_str_has_suffix (config_file_name, ".keymap"))
 458         file_name = g_strdup (config_file_name);
 459     else
 460         file_name = g_strconcat (config_file_name, ".keymap", (char *) NULL);
 461 
 462     canonicalize_pathname (file_name);
 463 
 464     if (g_path_is_absolute (file_name))
 465         return file_name;
 466 
 467     lc_basename = g_path_get_basename (file_name);
 468     g_free (file_name);
 469 
 470     if (lc_basename == NULL)
 471         return NULL;
 472 
 473     if (subdir != NULL)
 474         ret = g_build_filename (mc_config_get_path (), subdir, lc_basename, (char *) NULL);
 475     else
 476         ret = g_build_filename (mc_config_get_path (), lc_basename, (char *) NULL);
 477 
 478     if (exist_file (ret))
 479     {
 480         g_free (lc_basename);
 481         canonicalize_pathname (ret);
 482         return ret;
 483     }
 484     g_free (ret);
 485 
 486     if (subdir != NULL)
 487         ret = g_build_filename (mc_global.sysconfig_dir, subdir, lc_basename, (char *) NULL);
 488     else
 489         ret = g_build_filename (mc_global.sysconfig_dir, lc_basename, (char *) NULL);
 490 
 491     if (exist_file (ret))
 492     {
 493         g_free (lc_basename);
 494         canonicalize_pathname (ret);
 495         return ret;
 496     }
 497     g_free (ret);
 498 
 499     if (subdir != NULL)
 500         ret = g_build_filename (mc_global.share_data_dir, subdir, lc_basename, (char *) NULL);
 501     else
 502         ret = g_build_filename (mc_global.share_data_dir, lc_basename, (char *) NULL);
 503 
 504     g_free (lc_basename);
 505 
 506     if (exist_file (ret))
 507     {
 508         canonicalize_pathname (ret);
 509         return ret;
 510     }
 511 
 512     g_free (ret);
 513     return NULL;
 514 }
 515 
 516 /* --------------------------------------------------------------------------------------------- */
 517 
 518 static const char *
 519 setup__is_cfg_group_must_panel_config (const char *grp)
     /* [previous][next][first][last][top][bottom][index][help]  */
 520 {
 521     return (!strcasecmp ("Dirs", grp) ||
 522             !strcasecmp ("Temporal:New Right Panel", grp) ||
 523             !strcasecmp ("Temporal:New Left Panel", grp) ||
 524             !strcasecmp ("New Left Panel", grp) || !strcasecmp ("New Right Panel", grp))
 525         ? grp : NULL;
 526 }
 527 
 528 /* --------------------------------------------------------------------------------------------- */
 529 
 530 static void
 531 setup__move_panels_config_into_separate_file (const char *profile)
     /* [previous][next][first][last][top][bottom][index][help]  */
 532 {
 533     mc_config_t *tmp_cfg;
 534     char **groups, **curr_grp;
 535 
 536     if (!exist_file (profile))
 537         return;
 538 
 539     tmp_cfg = mc_config_init (profile, FALSE);
 540     if (tmp_cfg == NULL)
 541         return;
 542 
 543     groups = mc_config_get_groups (tmp_cfg, NULL);
 544     if (*groups == NULL)
 545     {
 546         g_strfreev (groups);
 547         mc_config_deinit (tmp_cfg);
 548         return;
 549     }
 550 
 551     for (curr_grp = groups; *curr_grp != NULL; curr_grp++)
 552         if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL)
 553             mc_config_del_group (tmp_cfg, *curr_grp);
 554 
 555     mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
 556     mc_config_deinit (tmp_cfg);
 557 
 558     tmp_cfg = mc_config_init (profile, FALSE);
 559     if (tmp_cfg == NULL)
 560     {
 561         g_strfreev (groups);
 562         return;
 563     }
 564 
 565     for (curr_grp = groups; *curr_grp != NULL; curr_grp++)
 566     {
 567         const char *need_grp;
 568 
 569         need_grp = setup__is_cfg_group_must_panel_config (*curr_grp);
 570         if (need_grp != NULL)
 571             mc_config_del_group (tmp_cfg, need_grp);
 572     }
 573     g_strfreev (groups);
 574 
 575     mc_config_save_file (tmp_cfg, NULL);
 576     mc_config_deinit (tmp_cfg);
 577 }
 578 
 579 /* --------------------------------------------------------------------------------------------- */
 580 /**
 581   Create new mc_config object from specified ini-file or
 582   append data to existing mc_config object from ini-file
 583 */
 584 
 585 static void
 586 load_setup_init_config_from_file (mc_config_t ** config, const char *fname, gboolean read_only)
     /* [previous][next][first][last][top][bottom][index][help]  */
 587 {
 588     /*
 589        TODO: IMHO, in future, this function shall be placed in mcconfig module.
 590      */
 591     if (exist_file (fname))
 592     {
 593         if (*config != NULL)
 594             mc_config_read_file (*config, fname, read_only, TRUE);
 595         else
 596             *config = mc_config_init (fname, read_only);
 597     }
 598 }
 599 
 600 /* --------------------------------------------------------------------------------------------- */
 601 
 602 static void
 603 load_config (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 604 {
 605     size_t i;
 606     const char *kt;
 607 
 608     /* Load boolean options */
 609     for (i = 0; bool_options[i].opt_name != NULL; i++)
 610         *bool_options[i].opt_addr =
 611             mc_config_get_bool (mc_global.main_config, CONFIG_APP_SECTION, bool_options[i].opt_name,
 612                                 *bool_options[i].opt_addr);
 613 
 614     /* Load integer options */
 615     for (i = 0; int_options[i].opt_name != NULL; i++)
 616         *int_options[i].opt_addr =
 617             mc_config_get_int (mc_global.main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
 618                                *int_options[i].opt_addr);
 619 
 620     /* Load string options */
 621     for (i = 0; str_options[i].opt_name != NULL; i++)
 622         *str_options[i].opt_addr =
 623             mc_config_get_string (mc_global.main_config, CONFIG_APP_SECTION,
 624                                   str_options[i].opt_name, str_options[i].opt_defval);
 625 
 626     /* Overwrite some options */
 627 #ifdef USE_INTERNAL_EDIT
 628     if (option_word_wrap_line_length <= 0)
 629         option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
 630 #else
 631     /* Reset forced in case of build without internal editor */
 632     use_internal_edit = FALSE;
 633 #endif /* USE_INTERNAL_EDIT */
 634 
 635     if (option_tab_spacing <= 0)
 636         option_tab_spacing = DEFAULT_TAB_SPACING;
 637 
 638     kt = getenv ("KEYBOARD_KEY_TIMEOUT_US");
 639     if (kt != NULL && kt[0] != '\0')
 640         old_esc_mode_timeout = atoi (kt);
 641 }
 642 
 643 /* --------------------------------------------------------------------------------------------- */
 644 
 645 static panel_view_mode_t
 646 setup__load_panel_state (const char *section)
     /* [previous][next][first][last][top][bottom][index][help]  */
 647 {
 648     char *buffer;
 649     size_t i;
 650     panel_view_mode_t mode = view_listing;
 651 
 652     /* Load the display mode */
 653     buffer = mc_config_get_string (mc_global.panels_config, section, "display", "listing");
 654 
 655     for (i = 0; panel_types[i].opt_name != NULL; i++)
 656         if (g_ascii_strcasecmp (panel_types[i].opt_name, buffer) == 0)
 657         {
 658             mode = panel_types[i].opt_type;
 659             break;
 660         }
 661 
 662     g_free (buffer);
 663 
 664     return mode;
 665 }
 666 
 667 /* --------------------------------------------------------------------------------------------- */
 668 
 669 static void
 670 load_layout (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 671 {
 672     size_t i;
 673     int equal_split;
 674     int first_panel_size;
 675 
 676     /* legacy options */
 677     panels_layout.horizontal_split = mc_config_get_int (mc_global.main_config, CONFIG_APP_SECTION,
 678                                                         "horizontal_split", 0);
 679     equal_split = mc_config_get_int (mc_global.main_config, "Layout", "equal_split", 1);
 680     first_panel_size = mc_config_get_int (mc_global.main_config, "Layout", "first_panel_size", 1);
 681     if (panels_layout.horizontal_split)
 682     {
 683         panels_layout.horizontal_equal = equal_split;
 684         panels_layout.left_panel_size = first_panel_size;
 685     }
 686     else
 687     {
 688         panels_layout.vertical_equal = equal_split;
 689         panels_layout.top_panel_size = first_panel_size;
 690     }
 691 
 692     /* actual options override legacy ones */
 693     for (i = 0; layout[i].opt_name != NULL; i++)
 694         *layout[i].opt_addr = mc_config_get_int (mc_global.main_config, CONFIG_LAYOUT_SECTION,
 695                                                  layout[i].opt_name, *layout[i].opt_addr);
 696 
 697     /* remove legacy options */
 698     mc_config_del_key (mc_global.main_config, CONFIG_APP_SECTION, "horizontal_split");
 699     mc_config_del_key (mc_global.main_config, "Layout", "equal_split");
 700     mc_config_del_key (mc_global.main_config, "Layout", "first_panel_size");
 701 
 702     startup_left_mode = setup__load_panel_state ("New Left Panel");
 703     startup_right_mode = setup__load_panel_state ("New Right Panel");
 704 
 705     /* At least one of the panels is a listing panel */
 706     if (startup_left_mode != view_listing && startup_right_mode != view_listing)
 707         startup_left_mode = view_listing;
 708 
 709     boot_current_is_left =
 710         mc_config_get_bool (mc_global.panels_config, "Dirs", "current_is_left", TRUE);
 711 }
 712 
 713 /* --------------------------------------------------------------------------------------------- */
 714 
 715 static void
 716 load_keys_from_section (const char *terminal, mc_config_t * cfg)
     /* [previous][next][first][last][top][bottom][index][help]  */
 717 {
 718     char *section_name;
 719     gchar **profile_keys, **keys;
 720     char *valcopy, *value;
 721     long key_code;
 722 
 723     if (terminal == NULL)
 724         return;
 725 
 726     section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
 727     keys = mc_config_get_keys (cfg, section_name, NULL);
 728 
 729     for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
 730     {
 731         /* copy=other causes all keys from [terminal:other] to be loaded. */
 732         if (g_ascii_strcasecmp (*profile_keys, "copy") == 0)
 733         {
 734             valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
 735             load_keys_from_section (valcopy, cfg);
 736             g_free (valcopy);
 737             continue;
 738         }
 739 
 740         key_code = lookup_key (*profile_keys, NULL);
 741         if (key_code != 0)
 742         {
 743             gchar **values;
 744 
 745             values = mc_config_get_string_list (cfg, section_name, *profile_keys, NULL);
 746             if (values != NULL)
 747             {
 748                 gchar **curr_values;
 749 
 750                 for (curr_values = values; *curr_values != NULL; curr_values++)
 751                 {
 752                     valcopy = convert_controls (*curr_values);
 753                     define_sequence (key_code, valcopy, MCKEY_NOACTION);
 754                     g_free (valcopy);
 755                 }
 756 
 757                 g_strfreev (values);
 758             }
 759             else
 760             {
 761                 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
 762                 valcopy = convert_controls (value);
 763                 define_sequence (key_code, valcopy, MCKEY_NOACTION);
 764                 g_free (valcopy);
 765                 g_free (value);
 766             }
 767         }
 768     }
 769     g_strfreev (keys);
 770     g_free (section_name);
 771 }
 772 
 773 /* --------------------------------------------------------------------------------------------- */
 774 
 775 static void
 776 load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg)
     /* [previous][next][first][last][top][bottom][index][help]  */
 777 {
 778     gchar **profile_keys, **keys;
 779 
 780     if (section_name == NULL)
 781         return;
 782 
 783     keys = mc_config_get_keys (cfg, section_name, NULL);
 784 
 785     for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
 786     {
 787         gchar **values;
 788 
 789         values = mc_config_get_string_list (cfg, section_name, *profile_keys, NULL);
 790         if (values != NULL)
 791         {
 792             long action;
 793 
 794             action = keybind_lookup_action (*profile_keys);
 795             if (action > 0)
 796             {
 797                 gchar **curr_values;
 798 
 799                 for (curr_values = values; *curr_values != NULL; curr_values++)
 800                     keybind_cmd_bind (keymap, *curr_values, action);
 801             }
 802 
 803             g_strfreev (values);
 804         }
 805     }
 806 
 807     g_strfreev (keys);
 808 }
 809 
 810 /* --------------------------------------------------------------------------------------------- */
 811 
 812 static mc_config_t *
 813 load_setup_get_keymap_profile_config (gboolean load_from_file)
     /* [previous][next][first][last][top][bottom][index][help]  */
 814 {
 815     /*
 816        TODO: IMHO, in future, this function shall be placed in mcconfig module.
 817      */
 818     mc_config_t *keymap_config;
 819     char *share_keymap, *sysconfig_keymap;
 820     char *fname, *fname2;
 821 
 822     /* 0) Create default keymap */
 823     keymap_config = create_default_keymap ();
 824     if (!load_from_file)
 825         return keymap_config;
 826 
 827     /* load and merge global keymaps */
 828 
 829     /* 1) /usr/share/mc (mc_global.share_data_dir) */
 830     share_keymap = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, (char *) NULL);
 831     load_setup_init_config_from_file (&keymap_config, share_keymap, TRUE);
 832 
 833     /* 2) /etc/mc (mc_global.sysconfig_dir) */
 834     sysconfig_keymap =
 835         g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, (char *) NULL);
 836     load_setup_init_config_from_file (&keymap_config, sysconfig_keymap, TRUE);
 837 
 838     /* then load and merge one of user-defined keymap */
 839 
 840     /* 3) --keymap=<keymap> */
 841     fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file);
 842     if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
 843     {
 844         load_setup_init_config_from_file (&keymap_config, fname, TRUE);
 845         goto done;
 846     }
 847     g_free (fname);
 848 
 849     /* 4) getenv("MC_KEYMAP") */
 850     fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
 851     if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
 852     {
 853         load_setup_init_config_from_file (&keymap_config, fname, TRUE);
 854         goto done;
 855     }
 856     g_free (fname);
 857     fname = NULL;
 858 
 859     /* 5) main config; [Midnight Commander] -> keymap */
 860     fname2 = mc_config_get_string (mc_global.main_config, CONFIG_APP_SECTION, "keymap", NULL);
 861     if (fname2 != NULL && *fname2 != '\0')
 862         fname = load_setup_get_full_config_name (NULL, fname2);
 863     g_free (fname2);
 864     if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
 865     {
 866         load_setup_init_config_from_file (&keymap_config, fname, TRUE);
 867         goto done;
 868     }
 869     g_free (fname);
 870 
 871     /* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */
 872     fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE);
 873     load_setup_init_config_from_file (&keymap_config, fname, TRUE);
 874 
 875   done:
 876     g_free (fname);
 877     g_free (sysconfig_keymap);
 878     g_free (share_keymap);
 879 
 880     return keymap_config;
 881 }
 882 
 883 /* --------------------------------------------------------------------------------------------- */
 884 
 885 static void
 886 panel_save_type (const char *section, panel_view_mode_t type)
     /* [previous][next][first][last][top][bottom][index][help]  */
 887 {
 888     size_t i;
 889 
 890     for (i = 0; panel_types[i].opt_name != NULL; i++)
 891         if (panel_types[i].opt_type == type)
 892         {
 893             mc_config_set_string (mc_global.panels_config, section, "display",
 894                                   panel_types[i].opt_name);
 895             break;
 896         }
 897 }
 898 
 899 /* --------------------------------------------------------------------------------------------- */
 900 
 901 /**
 902  * Load panels options from [Panels] section.
 903  */
 904 static void
 905 panels_load_options (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 906 {
 907     if (mc_config_has_group (mc_global.main_config, CONFIG_PANELS_SECTION))
 908     {
 909         size_t i;
 910         int qmode;
 911 
 912         for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
 913             *panels_ini_options[i].opt_addr =
 914                 mc_config_get_bool (mc_global.main_config, CONFIG_PANELS_SECTION,
 915                                     panels_ini_options[i].opt_name,
 916                                     *panels_ini_options[i].opt_addr);
 917 
 918         qmode = mc_config_get_int (mc_global.main_config, CONFIG_PANELS_SECTION,
 919                                    "quick_search_mode", (int) panels_options.qsearch_mode);
 920         if (qmode < 0)
 921             panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE;
 922         else if (qmode >= QSEARCH_NUM)
 923             panels_options.qsearch_mode = QSEARCH_PANEL_CASE;
 924         else
 925             panels_options.qsearch_mode = (qsearch_mode_t) qmode;
 926 
 927         panels_options.select_flags =
 928             mc_config_get_int (mc_global.main_config, CONFIG_PANELS_SECTION, "select_flags",
 929                                (int) panels_options.select_flags);
 930     }
 931 }
 932 
 933 /* --------------------------------------------------------------------------------------------- */
 934 
 935 /**
 936  * Save panels options in [Panels] section.
 937  */
 938 static void
 939 panels_save_options (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 940 {
 941     size_t i;
 942 
 943     for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
 944         mc_config_set_bool (mc_global.main_config, CONFIG_PANELS_SECTION,
 945                             panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr);
 946 
 947     mc_config_set_int (mc_global.main_config, CONFIG_PANELS_SECTION,
 948                        "quick_search_mode", (int) panels_options.qsearch_mode);
 949     mc_config_set_int (mc_global.main_config, CONFIG_PANELS_SECTION,
 950                        "select_flags", (int) panels_options.select_flags);
 951 }
 952 
 953 /* --------------------------------------------------------------------------------------------- */
 954 
 955 static void
 956 save_config (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 957 {
 958     size_t i;
 959 
 960     /* Save boolean options */
 961     for (i = 0; bool_options[i].opt_name != NULL; i++)
 962         mc_config_set_bool (mc_global.main_config, CONFIG_APP_SECTION, bool_options[i].opt_name,
 963                             *bool_options[i].opt_addr);
 964 
 965     /* Save integer options */
 966     for (i = 0; int_options[i].opt_name != NULL; i++)
 967         mc_config_set_int (mc_global.main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
 968                            *int_options[i].opt_addr);
 969 
 970     /* Save string options */
 971     for (i = 0; str_options[i].opt_name != NULL; i++)
 972         mc_config_set_string (mc_global.main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
 973                               *str_options[i].opt_addr);
 974 }
 975 
 976 /* --------------------------------------------------------------------------------------------- */
 977 
 978 static void
 979 save_layout (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 980 {
 981     size_t i;
 982 
 983     /* Save integer options */
 984     for (i = 0; layout[i].opt_name != NULL; i++)
 985         mc_config_set_int (mc_global.main_config, CONFIG_LAYOUT_SECTION, layout[i].opt_name,
 986                            *layout[i].opt_addr);
 987 }
 988 
 989 /* --------------------------------------------------------------------------------------------- */
 990 
 991 /* save panels.ini */
 992 static void
 993 save_panel_types (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 994 {
 995     panel_view_mode_t type;
 996 
 997     if (mc_global.mc_run_mode != MC_RUN_FULL)
 998         return;
 999 
1000     type = get_panel_type (0);
1001     panel_save_type ("New Left Panel", type);
1002     if (type == view_listing)
1003         panel_save_setup (left_panel, left_panel->panel_name);
1004     type = get_panel_type (1);
1005     panel_save_type ("New Right Panel", type);
1006     if (type == view_listing)
1007         panel_save_setup (right_panel, right_panel->panel_name);
1008 
1009     {
1010         char *dirs;
1011 
1012         dirs = get_panel_dir_for (other_panel);
1013         mc_config_set_string (mc_global.panels_config, "Dirs", "other_dir", dirs);
1014         g_free (dirs);
1015     }
1016 
1017     if (current_panel != NULL)
1018         mc_config_set_bool (mc_global.panels_config, "Dirs", "current_is_left",
1019                             get_current_index () == 0);
1020 
1021     if (mc_global.panels_config->ini_path == NULL)
1022         mc_global.panels_config->ini_path = g_strdup (panels_profile_name);
1023 
1024     mc_config_del_group (mc_global.panels_config, "Temporal:New Left Panel");
1025     mc_config_del_group (mc_global.panels_config, "Temporal:New Right Panel");
1026 
1027     mc_config_save_file (mc_global.panels_config, NULL);
1028 }
1029 
1030 /* --------------------------------------------------------------------------------------------- */
1031 /*** public functions ****************************************************************************/
1032 /* --------------------------------------------------------------------------------------------- */
1033 
1034 const char *
1035 setup_init (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1036 {
1037     if (profile_name == NULL)
1038     {
1039         char *profile;
1040 
1041         profile = mc_config_get_full_path (MC_CONFIG_FILE);
1042         if (!exist_file (profile))
1043         {
1044             char *inifile;
1045 
1046             inifile = mc_build_filename (mc_global.sysconfig_dir, "mc.ini", (char *) NULL);
1047             if (exist_file (inifile))
1048             {
1049                 g_free (profile);
1050                 profile = inifile;
1051             }
1052             else
1053             {
1054                 g_free (inifile);
1055                 inifile = mc_build_filename (mc_global.share_data_dir, "mc.ini", (char *) NULL);
1056                 if (!exist_file (inifile))
1057                     g_free (inifile);
1058                 else
1059                 {
1060                     g_free (profile);
1061                     profile = inifile;
1062                 }
1063             }
1064         }
1065 
1066         profile_name = profile;
1067     }
1068 
1069     return profile_name;
1070 }
1071 
1072 /* --------------------------------------------------------------------------------------------- */
1073 
1074 void
1075 load_setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1076 {
1077     const char *profile;
1078 
1079 #ifdef HAVE_CHARSET
1080     const char *cbuffer;
1081 
1082     load_codepages_list ();
1083 #endif /* HAVE_CHARSET */
1084 
1085     profile = setup_init ();
1086 
1087     /* mc.lib is common for all users, but has priority lower than
1088        ${XDG_CONFIG_HOME}/mc/ini.  FIXME: it's only used for keys and treestore now */
1089     global_profile_name =
1090         g_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
1091     if (!exist_file (global_profile_name))
1092     {
1093         g_free (global_profile_name);
1094         global_profile_name =
1095             g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
1096     }
1097 
1098     panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE);
1099 
1100     mc_global.main_config = mc_config_init (profile, FALSE);
1101 
1102     if (!exist_file (panels_profile_name))
1103         setup__move_panels_config_into_separate_file (profile);
1104 
1105     mc_global.panels_config = mc_config_init (panels_profile_name, FALSE);
1106 
1107     load_config ();
1108     load_layout ();
1109     panels_load_options ();
1110     load_panelize ();
1111 
1112     /* Load time formats */
1113     user_recent_timeformat =
1114         mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "timeformat_recent",
1115                               FMTTIME);
1116     user_old_timeformat =
1117         mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "timeformat_old",
1118                               FMTYEAR);
1119 
1120 #ifdef ENABLE_VFS_FTP
1121     ftpfs_proxy_host =
1122         mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftp_proxy_host", "gate");
1123     ftpfs_init_passwd ();
1124 #endif /* ENABLE_VFS_FTP */
1125 
1126     /* The default color and the terminal dependent color */
1127     mc_global.tty.setup_color_string =
1128         mc_config_get_string (mc_global.main_config, "Colors", "base_color", "");
1129     mc_global.tty.term_color_string =
1130         mc_config_get_string (mc_global.main_config, "Colors", getenv ("TERM"), "");
1131     mc_global.tty.color_terminal_string =
1132         mc_config_get_string (mc_global.main_config, "Colors", "color_terminals", "");
1133 
1134     /* Load the directory history */
1135     /*    directory_history_load (); */
1136     /* Remove the temporal entries */
1137 
1138 #ifdef HAVE_CHARSET
1139     if (codepages->len > 1)
1140     {
1141         char *buffer;
1142 
1143         buffer =
1144             mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "display_codepage",
1145                                   "");
1146         if (buffer[0] != '\0')
1147         {
1148             mc_global.display_codepage = get_codepage_index (buffer);
1149             cp_display = get_codepage_id (mc_global.display_codepage);
1150         }
1151         g_free (buffer);
1152         buffer =
1153             mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "source_codepage",
1154                                   "");
1155         if (buffer[0] != '\0')
1156         {
1157             default_source_codepage = get_codepage_index (buffer);
1158             mc_global.source_codepage = default_source_codepage;        /* May be source_codepage doesn't need this */
1159             cp_source = get_codepage_id (mc_global.source_codepage);
1160         }
1161         g_free (buffer);
1162     }
1163 
1164     autodetect_codeset =
1165         mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "autodetect_codeset", "");
1166     if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off") != 0))
1167         is_autodetect_codeset_enabled = TRUE;
1168 
1169     g_free (init_translation_table (mc_global.source_codepage, mc_global.display_codepage));
1170     cbuffer = get_codepage_id (mc_global.display_codepage);
1171     if (cbuffer != NULL)
1172         mc_global.utf8_display = str_isutf8 (cbuffer);
1173 #endif /* HAVE_CHARSET */
1174 
1175 #ifdef HAVE_ASPELL
1176     spell_language =
1177         mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "spell_language", "en");
1178 #endif /* HAVE_ASPELL */
1179 
1180     clipboard_store_path =
1181         mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_store", "");
1182     clipboard_paste_path =
1183         mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_paste", "");
1184 }
1185 
1186 /* --------------------------------------------------------------------------------------------- */
1187 
1188 gboolean
1189 save_setup (gboolean save_options, gboolean save_panel_options)
     /* [previous][next][first][last][top][bottom][index][help]  */
1190 {
1191     gboolean ret = TRUE;
1192 
1193     saving_setup = 1;
1194 
1195     save_hotlist ();
1196 
1197     if (save_panel_options)
1198         save_panel_types ();
1199 
1200     if (save_options)
1201     {
1202         char *tmp_profile;
1203 
1204         save_config ();
1205         save_layout ();
1206         panels_save_options ();
1207         save_panelize ();
1208         /* directory_history_save (); */
1209 
1210 #ifdef ENABLE_VFS_FTP
1211         mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftpfs_password",
1212                               ftpfs_anonymous_passwd);
1213         if (ftpfs_proxy_host)
1214             mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftp_proxy_host",
1215                                   ftpfs_proxy_host);
1216 #endif /* ENABLE_VFS_FTP */
1217 
1218 #ifdef HAVE_CHARSET
1219         mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "display_codepage",
1220                               get_codepage_id (mc_global.display_codepage));
1221         mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "source_codepage",
1222                               get_codepage_id (default_source_codepage));
1223         mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "autodetect_codeset",
1224                               autodetect_codeset);
1225 #endif /* HAVE_CHARSET */
1226 
1227 #ifdef HAVE_ASPELL
1228         mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "spell_language",
1229                               spell_language);
1230 #endif /* HAVE_ASPELL */
1231 
1232         mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_store",
1233                               clipboard_store_path);
1234         mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_paste",
1235                               clipboard_paste_path);
1236 
1237         tmp_profile = mc_config_get_full_path (MC_CONFIG_FILE);
1238         ret = mc_config_save_to_file (mc_global.main_config, tmp_profile, NULL);
1239         g_free (tmp_profile);
1240     }
1241 
1242     saving_setup = 0;
1243 
1244     return ret;
1245 }
1246 
1247 /* --------------------------------------------------------------------------------------------- */
1248 
1249 void
1250 done_setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1251 {
1252     size_t i;
1253 
1254     g_free (clipboard_store_path);
1255     g_free (clipboard_paste_path);
1256     g_free (global_profile_name);
1257     g_free (mc_global.tty.color_terminal_string);
1258     g_free (mc_global.tty.term_color_string);
1259     g_free (mc_global.tty.setup_color_string);
1260     g_free (profile_name);
1261     g_free (panels_profile_name);
1262     mc_config_deinit (mc_global.main_config);
1263     mc_config_deinit (mc_global.panels_config);
1264 
1265     g_free (user_recent_timeformat);
1266     g_free (user_old_timeformat);
1267 
1268     for (i = 0; str_options[i].opt_name != NULL; i++)
1269         g_free (*str_options[i].opt_addr);
1270 
1271     done_hotlist ();
1272     done_panelize ();
1273     /*    directory_history_free (); */
1274 
1275 #ifdef HAVE_CHARSET
1276     g_free (autodetect_codeset);
1277     free_codepages_list ();
1278 #endif
1279 
1280 #ifdef HAVE_ASPELL
1281     g_free (spell_language);
1282 #endif /* HAVE_ASPELL */
1283 }
1284 
1285 
1286 /* --------------------------------------------------------------------------------------------- */
1287 
1288 void
1289 setup_save_config_show_error (const char *filename, GError ** mcerror)
     /* [previous][next][first][last][top][bottom][index][help]  */
1290 {
1291     if (mcerror != NULL && *mcerror != NULL)
1292     {
1293         message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*mcerror)->message);
1294         g_error_free (*mcerror);
1295         *mcerror = NULL;
1296     }
1297 }
1298 
1299 
1300 /* --------------------------------------------------------------------------------------------- */
1301 
1302 void
1303 load_key_defs (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1304 {
1305     /*
1306      * Load keys from mc.lib before ${XDG_CONFIG_HOME}/mc/ini, so that the user
1307      * definitions override global settings.
1308      */
1309     mc_config_t *mc_global_config;
1310 
1311     mc_global_config = mc_config_init (global_profile_name, FALSE);
1312     if (mc_global_config != NULL)
1313     {
1314         load_keys_from_section ("general", mc_global_config);
1315         load_keys_from_section (getenv ("TERM"), mc_global_config);
1316         mc_config_deinit (mc_global_config);
1317     }
1318 
1319     load_keys_from_section ("general", mc_global.main_config);
1320     load_keys_from_section (getenv ("TERM"), mc_global.main_config);
1321 }
1322 
1323 /* --------------------------------------------------------------------------------------------- */
1324 
1325 #ifdef ENABLE_VFS_FTP
1326 char *
1327 load_anon_passwd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1328 {
1329     char *buffer;
1330 
1331     buffer =
1332         mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftpfs_password", "");
1333 
1334     if ((buffer != NULL) && (buffer[0] != '\0'))
1335         return buffer;
1336 
1337     g_free (buffer);
1338     return NULL;
1339 }
1340 #endif /* ENABLE_VFS_FTP */
1341 
1342 /* --------------------------------------------------------------------------------------------- */
1343 
1344 void
1345 load_keymap_defs (gboolean load_from_file)
     /* [previous][next][first][last][top][bottom][index][help]  */
1346 {
1347     /*
1348      * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_CONFIG_HOME}/mc/mc.keymap, so that the user
1349      * definitions override global settings.
1350      */
1351     mc_config_t *mc_global_keymap;
1352 
1353     mc_global_keymap = load_setup_get_keymap_profile_config (load_from_file);
1354 
1355     if (mc_global_keymap != NULL)
1356     {
1357         main_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1358         load_keymap_from_section (KEYMAP_SECTION_MAIN, main_keymap, mc_global_keymap);
1359         main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1360         load_keymap_from_section (KEYMAP_SECTION_MAIN_EXT, main_x_keymap, mc_global_keymap);
1361 
1362         panel_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1363         load_keymap_from_section (KEYMAP_SECTION_PANEL, panel_keymap, mc_global_keymap);
1364 
1365         dialog_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1366         load_keymap_from_section (KEYMAP_SECTION_DIALOG, dialog_keymap, mc_global_keymap);
1367 
1368         menu_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1369         load_keymap_from_section (KEYMAP_SECTION_MENU, menu_keymap, mc_global_keymap);
1370 
1371         input_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1372         load_keymap_from_section (KEYMAP_SECTION_INPUT, input_keymap, mc_global_keymap);
1373 
1374         listbox_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1375         load_keymap_from_section (KEYMAP_SECTION_LISTBOX, listbox_keymap, mc_global_keymap);
1376 
1377         tree_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1378         load_keymap_from_section (KEYMAP_SECTION_TREE, tree_keymap, mc_global_keymap);
1379 
1380         help_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1381         load_keymap_from_section (KEYMAP_SECTION_HELP, help_keymap, mc_global_keymap);
1382 
1383 #ifdef USE_INTERNAL_EDIT
1384         editor_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1385         load_keymap_from_section (KEYMAP_SECTION_EDITOR, editor_keymap, mc_global_keymap);
1386         editor_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1387         load_keymap_from_section (KEYMAP_SECTION_EDITOR_EXT, editor_x_keymap, mc_global_keymap);
1388 #endif
1389 
1390         viewer_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1391         load_keymap_from_section (KEYMAP_SECTION_VIEWER, viewer_keymap, mc_global_keymap);
1392         viewer_hex_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1393         load_keymap_from_section (KEYMAP_SECTION_VIEWER_HEX, viewer_hex_keymap, mc_global_keymap);
1394 
1395 #ifdef USE_DIFF_VIEW
1396         diff_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1397         load_keymap_from_section (KEYMAP_SECTION_DIFFVIEWER, diff_keymap, mc_global_keymap);
1398 #endif
1399 
1400         mc_config_deinit (mc_global_keymap);
1401     }
1402 
1403     main_map = (global_keymap_t *) main_keymap->data;
1404     main_x_map = (global_keymap_t *) main_x_keymap->data;
1405     panel_map = (global_keymap_t *) panel_keymap->data;
1406     dialog_map = (global_keymap_t *) dialog_keymap->data;
1407     menu_map = (global_keymap_t *) menu_keymap->data;
1408     input_map = (global_keymap_t *) input_keymap->data;
1409     listbox_map = (global_keymap_t *) listbox_keymap->data;
1410     tree_map = (global_keymap_t *) tree_keymap->data;
1411     help_map = (global_keymap_t *) help_keymap->data;
1412 #ifdef USE_INTERNAL_EDIT
1413     editor_map = (global_keymap_t *) editor_keymap->data;
1414     editor_x_map = (global_keymap_t *) editor_x_keymap->data;
1415 #endif
1416     viewer_map = (global_keymap_t *) viewer_keymap->data;
1417     viewer_hex_map = (global_keymap_t *) viewer_hex_keymap->data;
1418 #ifdef USE_DIFF_VIEW
1419     diff_map = (global_keymap_t *) diff_keymap->data;
1420 #endif
1421 }
1422 
1423 /* --------------------------------------------------------------------------------------------- */
1424 
1425 void
1426 free_keymap_defs (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1427 {
1428     if (main_keymap != NULL)
1429         g_array_free (main_keymap, TRUE);
1430     if (main_x_keymap != NULL)
1431         g_array_free (main_x_keymap, TRUE);
1432     if (panel_keymap != NULL)
1433         g_array_free (panel_keymap, TRUE);
1434     if (dialog_keymap != NULL)
1435         g_array_free (dialog_keymap, TRUE);
1436     if (input_keymap != NULL)
1437         g_array_free (input_keymap, TRUE);
1438     if (listbox_keymap != NULL)
1439         g_array_free (listbox_keymap, TRUE);
1440     if (tree_keymap != NULL)
1441         g_array_free (tree_keymap, TRUE);
1442     if (help_keymap != NULL)
1443         g_array_free (help_keymap, TRUE);
1444 #ifdef USE_INTERNAL_EDIT
1445     if (editor_keymap != NULL)
1446         g_array_free (editor_keymap, TRUE);
1447     if (editor_x_keymap != NULL)
1448         g_array_free (editor_x_keymap, TRUE);
1449 #endif
1450     if (viewer_keymap != NULL)
1451         g_array_free (viewer_keymap, TRUE);
1452     if (viewer_hex_keymap != NULL)
1453         g_array_free (viewer_hex_keymap, TRUE);
1454 #ifdef USE_DIFF_VIEW
1455     if (diff_keymap != NULL)
1456         g_array_free (diff_keymap, TRUE);
1457 #endif
1458 }
1459 
1460 /* --------------------------------------------------------------------------------------------- */
1461 
1462 void
1463 panel_load_setup (WPanel * panel, const char *section)
     /* [previous][next][first][last][top][bottom][index][help]  */
1464 {
1465     size_t i;
1466     char *buffer, buffer2[BUF_TINY];
1467 
1468     panel->sort_info.reverse =
1469         mc_config_get_bool (mc_global.panels_config, section, "reverse", FALSE);
1470     panel->sort_info.case_sensitive =
1471         mc_config_get_bool (mc_global.panels_config, section, "case_sensitive",
1472                             OS_SORT_CASE_SENSITIVE_DEFAULT);
1473     panel->sort_info.exec_first =
1474         mc_config_get_bool (mc_global.panels_config, section, "exec_first", FALSE);
1475 
1476     /* Load sort order */
1477     buffer = mc_config_get_string (mc_global.panels_config, section, "sort_order", "name");
1478     panel->sort_field = panel_get_field_by_id (buffer);
1479     if (panel->sort_field == NULL)
1480         panel->sort_field = panel_get_field_by_id ("name");
1481 
1482     g_free (buffer);
1483 
1484     /* Load the listing format */
1485     buffer = mc_config_get_string (mc_global.panels_config, section, "list_format", NULL);
1486     if (buffer == NULL)
1487     {
1488         /* fallback to old option */
1489         buffer = mc_config_get_string (mc_global.panels_config, section, "list_mode", "full");
1490     }
1491     panel->list_format = list_full;
1492     for (i = 0; list_formats[i].key != NULL; i++)
1493         if (g_ascii_strcasecmp (list_formats[i].key, buffer) == 0)
1494         {
1495             panel->list_format = list_formats[i].list_format;
1496             break;
1497         }
1498     g_free (buffer);
1499 
1500     panel->brief_cols = mc_config_get_int (mc_global.panels_config, section, "brief_cols", 2);
1501 
1502     /* User formats */
1503     g_free (panel->user_format);
1504     panel->user_format =
1505         mc_config_get_string (mc_global.panels_config, section, "user_format", DEFAULT_USER_FORMAT);
1506 
1507     for (i = 0; i < LIST_FORMATS; i++)
1508     {
1509         g_free (panel->user_status_format[i]);
1510         g_snprintf (buffer2, sizeof (buffer2), "user_status%lld", (long long) i);
1511         panel->user_status_format[i] =
1512             mc_config_get_string (mc_global.panels_config, section, buffer2, DEFAULT_USER_FORMAT);
1513     }
1514 
1515     panel->user_mini_status =
1516         mc_config_get_bool (mc_global.panels_config, section, "user_mini_status", FALSE);
1517 }
1518 
1519 /* --------------------------------------------------------------------------------------------- */
1520 
1521 void
1522 panel_save_setup (WPanel * panel, const char *section)
     /* [previous][next][first][last][top][bottom][index][help]  */
1523 {
1524     char buffer[BUF_TINY];
1525     size_t i;
1526 
1527     mc_config_set_bool (mc_global.panels_config, section, "reverse", panel->sort_info.reverse);
1528     mc_config_set_bool (mc_global.panels_config, section, "case_sensitive",
1529                         panel->sort_info.case_sensitive);
1530     mc_config_set_bool (mc_global.panels_config, section, "exec_first",
1531                         panel->sort_info.exec_first);
1532 
1533     mc_config_set_string (mc_global.panels_config, section, "sort_order", panel->sort_field->id);
1534 
1535     for (i = 0; list_formats[i].key != NULL; i++)
1536         if (list_formats[i].list_format == (int) panel->list_format)
1537         {
1538             mc_config_set_string (mc_global.panels_config, section, "list_format",
1539                                   list_formats[i].key);
1540             break;
1541         }
1542 
1543     mc_config_set_int (mc_global.panels_config, section, "brief_cols", panel->brief_cols);
1544 
1545     mc_config_set_string (mc_global.panels_config, section, "user_format", panel->user_format);
1546 
1547     for (i = 0; i < LIST_FORMATS; i++)
1548     {
1549         g_snprintf (buffer, sizeof (buffer), "user_status%lld", (long long) i);
1550         mc_config_set_string (mc_global.panels_config, section, buffer,
1551                               panel->user_status_format[i]);
1552     }
1553 
1554     mc_config_set_bool (mc_global.panels_config, section, "user_mini_status",
1555                         panel->user_mini_status);
1556 }
1557 
1558 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */