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_int_options [] = {
 262     { "output_lines", &output_lines },
 263     { "left_panel_size", &panels_layout.left_panel_size },
 264     { "top_panel_size", &panels_layout.top_panel_size },
 265     { NULL, NULL }
 266 };
 267 
 268 static const struct
 269 {
 270     const char *opt_name;
 271     gboolean *opt_addr;
 272 } layout_bool_options [] = {
 273     { "message_visible", &mc_global.message_visible },
 274     { "keybar_visible", &mc_global.keybar_visible },
 275     { "xterm_title", &xterm_title },
 276     { "command_prompt", &command_prompt },
 277     { "menubar_visible", &menubar_visible },
 278     { "free_space", &free_space },
 279     { "horizontal_split", &panels_layout.horizontal_split },
 280     { "vertical_equal", &panels_layout.vertical_equal },
 281     { "horizontal_equal", &panels_layout.horizontal_equal },
 282     { NULL, NULL }
 283 };
 284 
 285 static const struct
 286 {
 287     const char *opt_name;
 288     gboolean *opt_addr;
 289 } bool_options [] = {
 290     { "verbose", &verbose },
 291     { "shell_patterns", &easy_patterns },
 292     { "auto_save_setup", &auto_save_setup },
 293     { "preallocate_space", &mc_global.vfs.preallocate_space },
 294     { "auto_menu", &auto_menu },
 295     { "use_internal_view", &use_internal_view },
 296     { "use_internal_edit", &use_internal_edit },
 297     { "clear_before_exec", &clear_before_exec },
 298     { "confirm_delete", &confirm_delete },
 299     { "confirm_overwrite", &confirm_overwrite },
 300     { "confirm_execute", &confirm_execute },
 301     { "confirm_history_cleanup", &mc_global.widget.confirm_history_cleanup },
 302     { "confirm_exit", &confirm_exit },
 303     { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete },
 304     { "confirm_view_dir", &confirm_view_dir },
 305     { "safe_delete", &safe_delete },
 306     { "safe_overwrite", &safe_overwrite },
 307 #ifndef HAVE_CHARSET
 308     { "eight_bit_clean", &mc_global.eight_bit_clean },
 309     { "full_eight_bits", &mc_global.full_eight_bits },
 310 #endif /* !HAVE_CHARSET */
 311     { "use_8th_bit_as_meta", &use_8th_bit_as_meta },
 312     { "mouse_move_pages_viewer", &mcview_mouse_move_pages },
 313     { "mouse_close_dialog", &mouse_close_dialog},
 314     { "fast_refresh", &fast_refresh },
 315     { "drop_menus", &drop_menus },
 316     { "wrap_mode",  &mcview_global_flags.wrap },
 317     { "old_esc_mode", &old_esc_mode },
 318     { "cd_symlinks", &mc_global.vfs.cd_symlinks },
 319     { "show_all_if_ambiguous", &mc_global.widget.show_all_if_ambiguous },
 320     { "use_file_to_guess_type", &use_file_to_check_type },
 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 /* ENABLE_VFS_FTP */
 337 #endif /* ENABLE_VFS */
 338 #ifdef USE_INTERNAL_EDIT
 339     { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces },
 340     { "editor_return_does_auto_indent", &option_return_does_auto_indent },
 341     { "editor_backspace_through_tabs", &option_backspace_through_tabs },
 342     { "editor_fake_half_tabs", &option_fake_half_tabs },
 343     { "editor_option_save_position", &option_save_position },
 344     { "editor_option_auto_para_formatting", &option_auto_para_formatting },
 345     { "editor_option_typewriter_wrap", &option_typewriter_wrap },
 346     { "editor_edit_confirm_save", &edit_confirm_save },
 347     { "editor_syntax_highlighting", &option_syntax_highlighting },
 348     { "editor_persistent_selections", &option_persistent_selections },
 349     { "editor_drop_selection_on_copy", &option_drop_selection_on_copy },
 350     { "editor_cursor_beyond_eol", &option_cursor_beyond_eol },
 351     { "editor_cursor_after_inserted_block", &option_cursor_after_inserted_block },
 352     { "editor_visible_tabs", &visible_tabs },
 353     { "editor_visible_spaces", &visible_tws },
 354     { "editor_line_state", &option_line_state },
 355     { "editor_simple_statusbar", &simple_statusbar },
 356     { "editor_check_new_line", &option_check_nl_at_eof },
 357     { "editor_show_right_margin", &show_right_margin },
 358     { "editor_group_undo", &option_group_undo },
 359     { "editor_state_full_filename", &option_state_full_filename },
 360 #endif /* USE_INTERNAL_EDIT */
 361     { "editor_ask_filename_before_edit", &editor_ask_filename_before_edit },
 362     { "nice_rotating_dash", &nice_rotating_dash },
 363     { "mcview_remember_file_position", &mcview_remember_file_position },
 364     { "auto_fill_mkdir_name", &auto_fill_mkdir_name },
 365     { "copymove_persistent_attr", &copymove_persistent_attr },
 366     { NULL, NULL }
 367 };
 368 
 369 static const struct
 370 {
 371     const char *opt_name;
 372     int *opt_addr;
 373 } int_options [] = {
 374     { "pause_after_run", &pause_after_run },
 375     { "mouse_repeat_rate", &mou_auto_repeat },
 376     { "double_click_speed", &double_click_speed },
 377     { "old_esc_mode_timeout", &old_esc_mode_timeout },
 378     { "max_dirt_limit", &mcview_max_dirt_limit },
 379     { "num_history_items_recorded", &num_history_items_recorded },
 380 #ifdef ENABLE_VFS
 381     { "vfs_timeout", &vfs_timeout },
 382 #ifdef ENABLE_VFS_FTP
 383     { "ftpfs_directory_timeout", &ftpfs_directory_timeout },
 384     { "ftpfs_retry_seconds", &ftpfs_retry_seconds },
 385 #endif /* ENABLE_VFS_FTP */
 386 #ifdef ENABLE_VFS_FISH
 387     { "fish_directory_timeout", &fish_directory_timeout },
 388 #endif /* ENABLE_VFS_FISH */
 389 #endif /* ENABLE_VFS */
 390     /* option_tab_spacing is used in internal viewer */
 391     { "editor_tab_spacing", &option_tab_spacing },
 392 #ifdef USE_INTERNAL_EDIT
 393     { "editor_word_wrap_line_length", &option_word_wrap_line_length },
 394     { "editor_option_save_mode", &option_save_mode },
 395 #endif /* USE_INTERNAL_EDIT */
 396     { NULL, NULL }
 397 };
 398 
 399 static const struct
 400 {
 401     const char *opt_name;
 402     char **opt_addr;
 403     const char *opt_defval;
 404 } str_options[] = {
 405 #ifdef USE_INTERNAL_EDIT
 406     { "editor_backup_extension", &option_backup_ext, "~" },
 407     { "editor_filesize_threshold", &option_filesize_threshold, "64M" },
 408     { "editor_stop_format_chars", &option_stop_format_chars, "-+*\\,.;:&>" },
 409 #endif
 410     { "mcview_eof", &mcview_show_eof, "" },
 411     {  NULL, NULL, NULL }
 412 };
 413 
 414 static const struct
 415 {
 416     const char *opt_name;
 417     gboolean *opt_addr;
 418 } panels_ini_options[] = {
 419     { "show_mini_info", &panels_options.show_mini_info },
 420     { "kilobyte_si", &panels_options.kilobyte_si },
 421     { "mix_all_files", &panels_options.mix_all_files },
 422     { "show_backups", &panels_options.show_backups },
 423     { "show_dot_files", &panels_options.show_dot_files },
 424     { "fast_reload", &panels_options.fast_reload },
 425     { "fast_reload_msg_shown", &panels_options.fast_reload_msg_shown },
 426     { "mark_moves_down", &panels_options.mark_moves_down },
 427     { "reverse_files_only", &panels_options.reverse_files_only },
 428     { "auto_save_setup_panels", &panels_options.auto_save_setup },
 429     { "navigate_with_arrows", &panels_options.navigate_with_arrows },
 430     { "panel_scroll_pages", &panels_options.scroll_pages },
 431     { "panel_scroll_center", &panels_options.scroll_center },
 432     { "mouse_move_pages",  &panels_options.mouse_move_pages },
 433     { "filetype_mode", &panels_options.filetype_mode },
 434     { "permission_mode", &panels_options.permission_mode },
 435     { "torben_fj_mode", &panels_options.torben_fj_mode },
 436     { NULL, NULL }
 437 };
 438 /* *INDENT-ON* */
 439 
 440 /*** file scope functions ************************************************************************/
 441 /* --------------------------------------------------------------------------------------------- */
 442 
 443 /**
 444  * Get name of config file.
 445  *
 446  * @param subdir If not NULL, config is also searched in specified subdir.
 447  * @param config_file_name If relative, file if searched in standard paths.
 448  *
 449  * @return newly allocated string with config name or NULL if file is not found.
 450  */
 451 
 452 static char *
 453 load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
     /* [previous][next][first][last][top][bottom][index][help]  */
 454 {
 455     /*
 456        TODO: IMHO, in future, this function shall be placed in mcconfig module.
 457      */
 458     char *lc_basename, *ret;
 459     char *file_name;
 460 
 461     if (config_file_name == NULL)
 462         return NULL;
 463 
 464     /* check for .keymap suffix */
 465     if (g_str_has_suffix (config_file_name, ".keymap"))
 466         file_name = g_strdup (config_file_name);
 467     else
 468         file_name = g_strconcat (config_file_name, ".keymap", (char *) NULL);
 469 
 470     canonicalize_pathname (file_name);
 471 
 472     if (g_path_is_absolute (file_name))
 473         return file_name;
 474 
 475     lc_basename = g_path_get_basename (file_name);
 476     g_free (file_name);
 477 
 478     if (lc_basename == NULL)
 479         return NULL;
 480 
 481     if (subdir != NULL)
 482         ret = g_build_filename (mc_config_get_path (), subdir, lc_basename, (char *) NULL);
 483     else
 484         ret = g_build_filename (mc_config_get_path (), lc_basename, (char *) NULL);
 485 
 486     if (exist_file (ret))
 487     {
 488         g_free (lc_basename);
 489         canonicalize_pathname (ret);
 490         return ret;
 491     }
 492     g_free (ret);
 493 
 494     if (subdir != NULL)
 495         ret = g_build_filename (mc_global.sysconfig_dir, subdir, lc_basename, (char *) NULL);
 496     else
 497         ret = g_build_filename (mc_global.sysconfig_dir, lc_basename, (char *) NULL);
 498 
 499     if (exist_file (ret))
 500     {
 501         g_free (lc_basename);
 502         canonicalize_pathname (ret);
 503         return ret;
 504     }
 505     g_free (ret);
 506 
 507     if (subdir != NULL)
 508         ret = g_build_filename (mc_global.share_data_dir, subdir, lc_basename, (char *) NULL);
 509     else
 510         ret = g_build_filename (mc_global.share_data_dir, lc_basename, (char *) NULL);
 511 
 512     g_free (lc_basename);
 513 
 514     if (exist_file (ret))
 515     {
 516         canonicalize_pathname (ret);
 517         return ret;
 518     }
 519 
 520     g_free (ret);
 521     return NULL;
 522 }
 523 
 524 /* --------------------------------------------------------------------------------------------- */
 525 
 526 static const char *
 527 setup__is_cfg_group_must_panel_config (const char *grp)
     /* [previous][next][first][last][top][bottom][index][help]  */
 528 {
 529     return (!strcasecmp ("Dirs", grp) ||
 530             !strcasecmp ("Temporal:New Right Panel", grp) ||
 531             !strcasecmp ("Temporal:New Left Panel", grp) ||
 532             !strcasecmp ("New Left Panel", grp) || !strcasecmp ("New Right Panel", grp))
 533         ? grp : NULL;
 534 }
 535 
 536 /* --------------------------------------------------------------------------------------------- */
 537 
 538 static void
 539 setup__move_panels_config_into_separate_file (const char *profile)
     /* [previous][next][first][last][top][bottom][index][help]  */
 540 {
 541     mc_config_t *tmp_cfg;
 542     char **groups, **curr_grp;
 543 
 544     if (!exist_file (profile))
 545         return;
 546 
 547     tmp_cfg = mc_config_init (profile, FALSE);
 548     if (tmp_cfg == NULL)
 549         return;
 550 
 551     groups = mc_config_get_groups (tmp_cfg, NULL);
 552     if (*groups == NULL)
 553     {
 554         g_strfreev (groups);
 555         mc_config_deinit (tmp_cfg);
 556         return;
 557     }
 558 
 559     for (curr_grp = groups; *curr_grp != NULL; curr_grp++)
 560         if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL)
 561             mc_config_del_group (tmp_cfg, *curr_grp);
 562 
 563     mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
 564     mc_config_deinit (tmp_cfg);
 565 
 566     tmp_cfg = mc_config_init (profile, FALSE);
 567     if (tmp_cfg == NULL)
 568     {
 569         g_strfreev (groups);
 570         return;
 571     }
 572 
 573     for (curr_grp = groups; *curr_grp != NULL; curr_grp++)
 574     {
 575         const char *need_grp;
 576 
 577         need_grp = setup__is_cfg_group_must_panel_config (*curr_grp);
 578         if (need_grp != NULL)
 579             mc_config_del_group (tmp_cfg, need_grp);
 580     }
 581     g_strfreev (groups);
 582 
 583     mc_config_save_file (tmp_cfg, NULL);
 584     mc_config_deinit (tmp_cfg);
 585 }
 586 
 587 /* --------------------------------------------------------------------------------------------- */
 588 /**
 589   Create new mc_config object from specified ini-file or
 590   append data to existing mc_config object from ini-file
 591 */
 592 
 593 static void
 594 load_setup_init_config_from_file (mc_config_t ** config, const char *fname, gboolean read_only)
     /* [previous][next][first][last][top][bottom][index][help]  */
 595 {
 596     /*
 597        TODO: IMHO, in future, this function shall be placed in mcconfig module.
 598      */
 599     if (exist_file (fname))
 600     {
 601         if (*config != NULL)
 602             mc_config_read_file (*config, fname, read_only, TRUE);
 603         else
 604             *config = mc_config_init (fname, read_only);
 605     }
 606 }
 607 
 608 /* --------------------------------------------------------------------------------------------- */
 609 
 610 static void
 611 load_config (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 612 {
 613     size_t i;
 614     const char *kt;
 615 
 616     /* Load boolean options */
 617     for (i = 0; bool_options[i].opt_name != NULL; i++)
 618         *bool_options[i].opt_addr =
 619             mc_config_get_bool (mc_global.main_config, CONFIG_APP_SECTION, bool_options[i].opt_name,
 620                                 *bool_options[i].opt_addr);
 621 
 622     /* Load integer options */
 623     for (i = 0; int_options[i].opt_name != NULL; i++)
 624         *int_options[i].opt_addr =
 625             mc_config_get_int (mc_global.main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
 626                                *int_options[i].opt_addr);
 627 
 628     /* Load string options */
 629     for (i = 0; str_options[i].opt_name != NULL; i++)
 630         *str_options[i].opt_addr =
 631             mc_config_get_string (mc_global.main_config, CONFIG_APP_SECTION,
 632                                   str_options[i].opt_name, str_options[i].opt_defval);
 633 
 634     /* Overwrite some options */
 635 #ifdef USE_INTERNAL_EDIT
 636     if (option_word_wrap_line_length <= 0)
 637         option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
 638 #else
 639     /* Reset forced in case of build without internal editor */
 640     use_internal_edit = FALSE;
 641 #endif /* USE_INTERNAL_EDIT */
 642 
 643     if (option_tab_spacing <= 0)
 644         option_tab_spacing = DEFAULT_TAB_SPACING;
 645 
 646     kt = getenv ("KEYBOARD_KEY_TIMEOUT_US");
 647     if (kt != NULL && kt[0] != '\0')
 648         old_esc_mode_timeout = atoi (kt);
 649 }
 650 
 651 /* --------------------------------------------------------------------------------------------- */
 652 
 653 static panel_view_mode_t
 654 setup__load_panel_state (const char *section)
     /* [previous][next][first][last][top][bottom][index][help]  */
 655 {
 656     char *buffer;
 657     size_t i;
 658     panel_view_mode_t mode = view_listing;
 659 
 660     /* Load the display mode */
 661     buffer = mc_config_get_string (mc_global.panels_config, section, "display", "listing");
 662 
 663     for (i = 0; panel_types[i].opt_name != NULL; i++)
 664         if (g_ascii_strcasecmp (panel_types[i].opt_name, buffer) == 0)
 665         {
 666             mode = panel_types[i].opt_type;
 667             break;
 668         }
 669 
 670     g_free (buffer);
 671 
 672     return mode;
 673 }
 674 
 675 /* --------------------------------------------------------------------------------------------- */
 676 
 677 static void
 678 load_layout (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 679 {
 680     size_t i;
 681 
 682     /* actual options override legacy ones */
 683     for (i = 0; layout_int_options[i].opt_name != NULL; i++)
 684         *layout_int_options[i].opt_addr =
 685             mc_config_get_int (mc_global.main_config, CONFIG_LAYOUT_SECTION,
 686                                layout_int_options[i].opt_name, *layout_int_options[i].opt_addr);
 687 
 688     for (i = 0; layout_bool_options[i].opt_name != NULL; i++)
 689         *layout_bool_options[i].opt_addr =
 690             mc_config_get_bool (mc_global.main_config, CONFIG_LAYOUT_SECTION,
 691                                 layout_bool_options[i].opt_name, *layout_bool_options[i].opt_addr);
 692 
 693     startup_left_mode = setup__load_panel_state ("New Left Panel");
 694     startup_right_mode = setup__load_panel_state ("New Right Panel");
 695 
 696     /* At least one of the panels is a listing panel */
 697     if (startup_left_mode != view_listing && startup_right_mode != view_listing)
 698         startup_left_mode = view_listing;
 699 
 700     boot_current_is_left =
 701         mc_config_get_bool (mc_global.panels_config, "Dirs", "current_is_left", TRUE);
 702 }
 703 
 704 /* --------------------------------------------------------------------------------------------- */
 705 
 706 static void
 707 load_keys_from_section (const char *terminal, mc_config_t * cfg)
     /* [previous][next][first][last][top][bottom][index][help]  */
 708 {
 709     char *section_name;
 710     gchar **profile_keys, **keys;
 711     char *valcopy, *value;
 712     long key_code;
 713 
 714     if (terminal == NULL)
 715         return;
 716 
 717     section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
 718     keys = mc_config_get_keys (cfg, section_name, NULL);
 719 
 720     for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
 721     {
 722         /* copy=other causes all keys from [terminal:other] to be loaded. */
 723         if (g_ascii_strcasecmp (*profile_keys, "copy") == 0)
 724         {
 725             valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
 726             load_keys_from_section (valcopy, cfg);
 727             g_free (valcopy);
 728             continue;
 729         }
 730 
 731         key_code = lookup_key (*profile_keys, NULL);
 732         if (key_code != 0)
 733         {
 734             gchar **values;
 735 
 736             values = mc_config_get_string_list (cfg, section_name, *profile_keys, NULL);
 737             if (values != NULL)
 738             {
 739                 gchar **curr_values;
 740 
 741                 for (curr_values = values; *curr_values != NULL; curr_values++)
 742                 {
 743                     valcopy = convert_controls (*curr_values);
 744                     define_sequence (key_code, valcopy, MCKEY_NOACTION);
 745                     g_free (valcopy);
 746                 }
 747 
 748                 g_strfreev (values);
 749             }
 750             else
 751             {
 752                 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
 753                 valcopy = convert_controls (value);
 754                 define_sequence (key_code, valcopy, MCKEY_NOACTION);
 755                 g_free (valcopy);
 756                 g_free (value);
 757             }
 758         }
 759     }
 760     g_strfreev (keys);
 761     g_free (section_name);
 762 }
 763 
 764 /* --------------------------------------------------------------------------------------------- */
 765 
 766 static void
 767 load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg)
     /* [previous][next][first][last][top][bottom][index][help]  */
 768 {
 769     gchar **profile_keys, **keys;
 770 
 771     if (section_name == NULL)
 772         return;
 773 
 774     keys = mc_config_get_keys (cfg, section_name, NULL);
 775 
 776     for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
 777     {
 778         gchar **values;
 779 
 780         values = mc_config_get_string_list (cfg, section_name, *profile_keys, NULL);
 781         if (values != NULL)
 782         {
 783             long action;
 784 
 785             action = keybind_lookup_action (*profile_keys);
 786             if (action > 0)
 787             {
 788                 gchar **curr_values;
 789 
 790                 for (curr_values = values; *curr_values != NULL; curr_values++)
 791                     keybind_cmd_bind (keymap, *curr_values, action);
 792             }
 793 
 794             g_strfreev (values);
 795         }
 796     }
 797 
 798     g_strfreev (keys);
 799 }
 800 
 801 /* --------------------------------------------------------------------------------------------- */
 802 
 803 static mc_config_t *
 804 load_setup_get_keymap_profile_config (gboolean load_from_file)
     /* [previous][next][first][last][top][bottom][index][help]  */
 805 {
 806     /*
 807        TODO: IMHO, in future, this function shall be placed in mcconfig module.
 808      */
 809     mc_config_t *keymap_config;
 810     char *share_keymap, *sysconfig_keymap;
 811     char *fname, *fname2;
 812 
 813     /* 0) Create default keymap */
 814     keymap_config = create_default_keymap ();
 815     if (!load_from_file)
 816         return keymap_config;
 817 
 818     /* load and merge global keymaps */
 819 
 820     /* 1) /usr/share/mc (mc_global.share_data_dir) */
 821     share_keymap = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, (char *) NULL);
 822     load_setup_init_config_from_file (&keymap_config, share_keymap, TRUE);
 823 
 824     /* 2) /etc/mc (mc_global.sysconfig_dir) */
 825     sysconfig_keymap =
 826         g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, (char *) NULL);
 827     load_setup_init_config_from_file (&keymap_config, sysconfig_keymap, TRUE);
 828 
 829     /* then load and merge one of user-defined keymap */
 830 
 831     /* 3) --keymap=<keymap> */
 832     fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file);
 833     if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
 834     {
 835         load_setup_init_config_from_file (&keymap_config, fname, TRUE);
 836         goto done;
 837     }
 838     g_free (fname);
 839 
 840     /* 4) getenv("MC_KEYMAP") */
 841     fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
 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     fname = NULL;
 849 
 850     /* 5) main config; [Midnight Commander] -> keymap */
 851     fname2 = mc_config_get_string (mc_global.main_config, CONFIG_APP_SECTION, "keymap", NULL);
 852     if (fname2 != NULL && *fname2 != '\0')
 853         fname = load_setup_get_full_config_name (NULL, fname2);
 854     g_free (fname2);
 855     if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
 856     {
 857         load_setup_init_config_from_file (&keymap_config, fname, TRUE);
 858         goto done;
 859     }
 860     g_free (fname);
 861 
 862     /* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */
 863     fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE);
 864     load_setup_init_config_from_file (&keymap_config, fname, TRUE);
 865 
 866   done:
 867     g_free (fname);
 868     g_free (sysconfig_keymap);
 869     g_free (share_keymap);
 870 
 871     return keymap_config;
 872 }
 873 
 874 /* --------------------------------------------------------------------------------------------- */
 875 
 876 static void
 877 panel_save_type (const char *section, panel_view_mode_t type)
     /* [previous][next][first][last][top][bottom][index][help]  */
 878 {
 879     size_t i;
 880 
 881     for (i = 0; panel_types[i].opt_name != NULL; i++)
 882         if (panel_types[i].opt_type == type)
 883         {
 884             mc_config_set_string (mc_global.panels_config, section, "display",
 885                                   panel_types[i].opt_name);
 886             break;
 887         }
 888 }
 889 
 890 /* --------------------------------------------------------------------------------------------- */
 891 
 892 /**
 893  * Load panels options from [Panels] section.
 894  */
 895 static void
 896 panels_load_options (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 897 {
 898     if (mc_config_has_group (mc_global.main_config, CONFIG_PANELS_SECTION))
 899     {
 900         size_t i;
 901         int qmode;
 902 
 903         for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
 904             *panels_ini_options[i].opt_addr =
 905                 mc_config_get_bool (mc_global.main_config, CONFIG_PANELS_SECTION,
 906                                     panels_ini_options[i].opt_name,
 907                                     *panels_ini_options[i].opt_addr);
 908 
 909         qmode = mc_config_get_int (mc_global.main_config, CONFIG_PANELS_SECTION,
 910                                    "quick_search_mode", (int) panels_options.qsearch_mode);
 911         if (qmode < 0)
 912             panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE;
 913         else if (qmode >= QSEARCH_NUM)
 914             panels_options.qsearch_mode = QSEARCH_PANEL_CASE;
 915         else
 916             panels_options.qsearch_mode = (qsearch_mode_t) qmode;
 917 
 918         panels_options.select_flags =
 919             mc_config_get_int (mc_global.main_config, CONFIG_PANELS_SECTION, "select_flags",
 920                                (int) panels_options.select_flags);
 921     }
 922 }
 923 
 924 /* --------------------------------------------------------------------------------------------- */
 925 
 926 /**
 927  * Save panels options in [Panels] section.
 928  */
 929 static void
 930 panels_save_options (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 931 {
 932     size_t i;
 933 
 934     for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
 935         mc_config_set_bool (mc_global.main_config, CONFIG_PANELS_SECTION,
 936                             panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr);
 937 
 938     mc_config_set_int (mc_global.main_config, CONFIG_PANELS_SECTION,
 939                        "quick_search_mode", (int) panels_options.qsearch_mode);
 940     mc_config_set_int (mc_global.main_config, CONFIG_PANELS_SECTION,
 941                        "select_flags", (int) panels_options.select_flags);
 942 }
 943 
 944 /* --------------------------------------------------------------------------------------------- */
 945 
 946 static void
 947 save_config (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 948 {
 949     size_t i;
 950 
 951     /* Save boolean options */
 952     for (i = 0; bool_options[i].opt_name != NULL; i++)
 953         mc_config_set_bool (mc_global.main_config, CONFIG_APP_SECTION, bool_options[i].opt_name,
 954                             *bool_options[i].opt_addr);
 955 
 956     /* Save integer options */
 957     for (i = 0; int_options[i].opt_name != NULL; i++)
 958         mc_config_set_int (mc_global.main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
 959                            *int_options[i].opt_addr);
 960 
 961     /* Save string options */
 962     for (i = 0; str_options[i].opt_name != NULL; i++)
 963         mc_config_set_string (mc_global.main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
 964                               *str_options[i].opt_addr);
 965 }
 966 
 967 /* --------------------------------------------------------------------------------------------- */
 968 
 969 static void
 970 save_layout (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 971 {
 972     size_t i;
 973 
 974     /* Save integer options */
 975     for (i = 0; layout_int_options[i].opt_name != NULL; i++)
 976         mc_config_set_int (mc_global.main_config, CONFIG_LAYOUT_SECTION,
 977                            layout_int_options[i].opt_name, *layout_int_options[i].opt_addr);
 978 
 979     /* Save boolean options */
 980     for (i = 0; layout_bool_options[i].opt_name != NULL; i++)
 981         mc_config_set_bool (mc_global.main_config, CONFIG_LAYOUT_SECTION,
 982                             layout_bool_options[i].opt_name, *layout_bool_options[i].opt_addr);
 983 }
 984 
 985 /* --------------------------------------------------------------------------------------------- */
 986 
 987 /* save panels.ini */
 988 static void
 989 save_panel_types (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 990 {
 991     panel_view_mode_t type;
 992 
 993     if (mc_global.mc_run_mode != MC_RUN_FULL)
 994         return;
 995 
 996     type = get_panel_type (0);
 997     panel_save_type ("New Left Panel", type);
 998     if (type == view_listing)
 999         panel_save_setup (left_panel, left_panel->panel_name);
1000     type = get_panel_type (1);
1001     panel_save_type ("New Right Panel", type);
1002     if (type == view_listing)
1003         panel_save_setup (right_panel, right_panel->panel_name);
1004 
1005     {
1006         char *dirs;
1007 
1008         dirs = get_panel_dir_for (other_panel);
1009         mc_config_set_string (mc_global.panels_config, "Dirs", "other_dir", dirs);
1010         g_free (dirs);
1011     }
1012 
1013     if (current_panel != NULL)
1014         mc_config_set_bool (mc_global.panels_config, "Dirs", "current_is_left",
1015                             get_current_index () == 0);
1016 
1017     if (mc_global.panels_config->ini_path == NULL)
1018         mc_global.panels_config->ini_path = g_strdup (panels_profile_name);
1019 
1020     mc_config_del_group (mc_global.panels_config, "Temporal:New Left Panel");
1021     mc_config_del_group (mc_global.panels_config, "Temporal:New Right Panel");
1022 
1023     mc_config_save_file (mc_global.panels_config, NULL);
1024 }
1025 
1026 /* --------------------------------------------------------------------------------------------- */
1027 /*** public functions ****************************************************************************/
1028 /* --------------------------------------------------------------------------------------------- */
1029 
1030 const char *
1031 setup_init (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1032 {
1033     if (profile_name == NULL)
1034     {
1035         char *profile;
1036 
1037         profile = mc_config_get_full_path (MC_CONFIG_FILE);
1038         if (!exist_file (profile))
1039         {
1040             char *inifile;
1041 
1042             inifile = mc_build_filename (mc_global.sysconfig_dir, "mc.ini", (char *) NULL);
1043             if (exist_file (inifile))
1044             {
1045                 g_free (profile);
1046                 profile = inifile;
1047             }
1048             else
1049             {
1050                 g_free (inifile);
1051                 inifile = mc_build_filename (mc_global.share_data_dir, "mc.ini", (char *) NULL);
1052                 if (!exist_file (inifile))
1053                     g_free (inifile);
1054                 else
1055                 {
1056                     g_free (profile);
1057                     profile = inifile;
1058                 }
1059             }
1060         }
1061 
1062         profile_name = profile;
1063     }
1064 
1065     return profile_name;
1066 }
1067 
1068 /* --------------------------------------------------------------------------------------------- */
1069 
1070 void
1071 load_setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1072 {
1073     const char *profile;
1074 
1075 #ifdef HAVE_CHARSET
1076     const char *cbuffer;
1077 
1078     load_codepages_list ();
1079 #endif /* HAVE_CHARSET */
1080 
1081     profile = setup_init ();
1082 
1083     /* mc.lib is common for all users, but has priority lower than
1084        ${XDG_CONFIG_HOME}/mc/ini.  FIXME: it's only used for keys and treestore now */
1085     global_profile_name =
1086         g_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
1087     if (!exist_file (global_profile_name))
1088     {
1089         g_free (global_profile_name);
1090         global_profile_name =
1091             g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
1092     }
1093 
1094     panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE);
1095 
1096     mc_global.main_config = mc_config_init (profile, FALSE);
1097 
1098     if (!exist_file (panels_profile_name))
1099         setup__move_panels_config_into_separate_file (profile);
1100 
1101     mc_global.panels_config = mc_config_init (panels_profile_name, FALSE);
1102 
1103     load_config ();
1104     load_layout ();
1105     panels_load_options ();
1106     load_panelize ();
1107 
1108     /* Load time formats */
1109     user_recent_timeformat =
1110         mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "timeformat_recent",
1111                               FMTTIME);
1112     user_old_timeformat =
1113         mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "timeformat_old",
1114                               FMTYEAR);
1115 
1116 #ifdef ENABLE_VFS_FTP
1117     ftpfs_proxy_host =
1118         mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftp_proxy_host", "gate");
1119     ftpfs_init_passwd ();
1120 #endif /* ENABLE_VFS_FTP */
1121 
1122     /* The default color and the terminal dependent color */
1123     mc_global.tty.setup_color_string =
1124         mc_config_get_string (mc_global.main_config, "Colors", "base_color", "");
1125     mc_global.tty.term_color_string =
1126         mc_config_get_string (mc_global.main_config, "Colors", getenv ("TERM"), "");
1127     mc_global.tty.color_terminal_string =
1128         mc_config_get_string (mc_global.main_config, "Colors", "color_terminals", "");
1129 
1130     /* Load the directory history */
1131     /*    directory_history_load (); */
1132     /* Remove the temporal entries */
1133 
1134 #ifdef HAVE_CHARSET
1135     if (codepages->len > 1)
1136     {
1137         char *buffer;
1138 
1139         buffer =
1140             mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "display_codepage",
1141                                   "");
1142         if (buffer[0] != '\0')
1143         {
1144             mc_global.display_codepage = get_codepage_index (buffer);
1145             cp_display = get_codepage_id (mc_global.display_codepage);
1146         }
1147         g_free (buffer);
1148         buffer =
1149             mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "source_codepage",
1150                                   "");
1151         if (buffer[0] != '\0')
1152         {
1153             default_source_codepage = get_codepage_index (buffer);
1154             mc_global.source_codepage = default_source_codepage;        /* May be source_codepage doesn't need this */
1155             cp_source = get_codepage_id (mc_global.source_codepage);
1156         }
1157         g_free (buffer);
1158     }
1159 
1160     autodetect_codeset =
1161         mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "autodetect_codeset", "");
1162     if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off") != 0))
1163         is_autodetect_codeset_enabled = TRUE;
1164 
1165     g_free (init_translation_table (mc_global.source_codepage, mc_global.display_codepage));
1166     cbuffer = get_codepage_id (mc_global.display_codepage);
1167     if (cbuffer != NULL)
1168         mc_global.utf8_display = str_isutf8 (cbuffer);
1169 #endif /* HAVE_CHARSET */
1170 
1171 #ifdef HAVE_ASPELL
1172     spell_language =
1173         mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "spell_language", "en");
1174 #endif /* HAVE_ASPELL */
1175 
1176     clipboard_store_path =
1177         mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_store", "");
1178     clipboard_paste_path =
1179         mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_paste", "");
1180 }
1181 
1182 /* --------------------------------------------------------------------------------------------- */
1183 
1184 gboolean
1185 save_setup (gboolean save_options, gboolean save_panel_options)
     /* [previous][next][first][last][top][bottom][index][help]  */
1186 {
1187     gboolean ret = TRUE;
1188 
1189     saving_setup = 1;
1190 
1191     save_hotlist ();
1192 
1193     if (save_panel_options)
1194         save_panel_types ();
1195 
1196     if (save_options)
1197     {
1198         char *tmp_profile;
1199 
1200         save_config ();
1201         save_layout ();
1202         panels_save_options ();
1203         save_panelize ();
1204         /* directory_history_save (); */
1205 
1206 #ifdef ENABLE_VFS_FTP
1207         mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftpfs_password",
1208                               ftpfs_anonymous_passwd);
1209         if (ftpfs_proxy_host)
1210             mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftp_proxy_host",
1211                                   ftpfs_proxy_host);
1212 #endif /* ENABLE_VFS_FTP */
1213 
1214 #ifdef HAVE_CHARSET
1215         mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "display_codepage",
1216                               get_codepage_id (mc_global.display_codepage));
1217         mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "source_codepage",
1218                               get_codepage_id (default_source_codepage));
1219         mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "autodetect_codeset",
1220                               autodetect_codeset);
1221 #endif /* HAVE_CHARSET */
1222 
1223 #ifdef HAVE_ASPELL
1224         mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "spell_language",
1225                               spell_language);
1226 #endif /* HAVE_ASPELL */
1227 
1228         mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_store",
1229                               clipboard_store_path);
1230         mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_paste",
1231                               clipboard_paste_path);
1232 
1233         tmp_profile = mc_config_get_full_path (MC_CONFIG_FILE);
1234         ret = mc_config_save_to_file (mc_global.main_config, tmp_profile, NULL);
1235         g_free (tmp_profile);
1236     }
1237 
1238     saving_setup = 0;
1239 
1240     return ret;
1241 }
1242 
1243 /* --------------------------------------------------------------------------------------------- */
1244 
1245 void
1246 done_setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1247 {
1248     size_t i;
1249 
1250     g_free (clipboard_store_path);
1251     g_free (clipboard_paste_path);
1252     g_free (global_profile_name);
1253     g_free (mc_global.tty.color_terminal_string);
1254     g_free (mc_global.tty.term_color_string);
1255     g_free (mc_global.tty.setup_color_string);
1256     g_free (profile_name);
1257     g_free (panels_profile_name);
1258     mc_config_deinit (mc_global.main_config);
1259     mc_config_deinit (mc_global.panels_config);
1260 
1261     g_free (user_recent_timeformat);
1262     g_free (user_old_timeformat);
1263 
1264     for (i = 0; str_options[i].opt_name != NULL; i++)
1265         g_free (*str_options[i].opt_addr);
1266 
1267     done_hotlist ();
1268     done_panelize ();
1269     /*    directory_history_free (); */
1270 
1271 #ifdef HAVE_CHARSET
1272     g_free (autodetect_codeset);
1273     free_codepages_list ();
1274 #endif
1275 
1276 #ifdef HAVE_ASPELL
1277     g_free (spell_language);
1278 #endif /* HAVE_ASPELL */
1279 }
1280 
1281 
1282 /* --------------------------------------------------------------------------------------------- */
1283 
1284 void
1285 setup_save_config_show_error (const char *filename, GError ** mcerror)
     /* [previous][next][first][last][top][bottom][index][help]  */
1286 {
1287     if (mcerror != NULL && *mcerror != NULL)
1288     {
1289         message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*mcerror)->message);
1290         g_error_free (*mcerror);
1291         *mcerror = NULL;
1292     }
1293 }
1294 
1295 
1296 /* --------------------------------------------------------------------------------------------- */
1297 
1298 void
1299 load_key_defs (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1300 {
1301     /*
1302      * Load keys from mc.lib before ${XDG_CONFIG_HOME}/mc/ini, so that the user
1303      * definitions override global settings.
1304      */
1305     mc_config_t *mc_global_config;
1306 
1307     mc_global_config = mc_config_init (global_profile_name, FALSE);
1308     if (mc_global_config != NULL)
1309     {
1310         load_keys_from_section ("general", mc_global_config);
1311         load_keys_from_section (getenv ("TERM"), mc_global_config);
1312         mc_config_deinit (mc_global_config);
1313     }
1314 
1315     load_keys_from_section ("general", mc_global.main_config);
1316     load_keys_from_section (getenv ("TERM"), mc_global.main_config);
1317 }
1318 
1319 /* --------------------------------------------------------------------------------------------- */
1320 
1321 #ifdef ENABLE_VFS_FTP
1322 char *
1323 load_anon_passwd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1324 {
1325     char *buffer;
1326 
1327     buffer =
1328         mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftpfs_password", "");
1329 
1330     if ((buffer != NULL) && (buffer[0] != '\0'))
1331         return buffer;
1332 
1333     g_free (buffer);
1334     return NULL;
1335 }
1336 #endif /* ENABLE_VFS_FTP */
1337 
1338 /* --------------------------------------------------------------------------------------------- */
1339 
1340 void
1341 load_keymap_defs (gboolean load_from_file)
     /* [previous][next][first][last][top][bottom][index][help]  */
1342 {
1343     /*
1344      * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_CONFIG_HOME}/mc/mc.keymap, so that the user
1345      * definitions override global settings.
1346      */
1347     mc_config_t *mc_global_keymap;
1348 
1349     mc_global_keymap = load_setup_get_keymap_profile_config (load_from_file);
1350 
1351     if (mc_global_keymap != NULL)
1352     {
1353         main_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1354         load_keymap_from_section (KEYMAP_SECTION_MAIN, main_keymap, mc_global_keymap);
1355         main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1356         load_keymap_from_section (KEYMAP_SECTION_MAIN_EXT, main_x_keymap, mc_global_keymap);
1357 
1358         panel_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1359         load_keymap_from_section (KEYMAP_SECTION_PANEL, panel_keymap, mc_global_keymap);
1360 
1361         dialog_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1362         load_keymap_from_section (KEYMAP_SECTION_DIALOG, dialog_keymap, mc_global_keymap);
1363 
1364         menu_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1365         load_keymap_from_section (KEYMAP_SECTION_MENU, menu_keymap, mc_global_keymap);
1366 
1367         input_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1368         load_keymap_from_section (KEYMAP_SECTION_INPUT, input_keymap, mc_global_keymap);
1369 
1370         listbox_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1371         load_keymap_from_section (KEYMAP_SECTION_LISTBOX, listbox_keymap, mc_global_keymap);
1372 
1373         tree_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1374         load_keymap_from_section (KEYMAP_SECTION_TREE, tree_keymap, mc_global_keymap);
1375 
1376         help_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1377         load_keymap_from_section (KEYMAP_SECTION_HELP, help_keymap, mc_global_keymap);
1378 
1379 #ifdef USE_INTERNAL_EDIT
1380         editor_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1381         load_keymap_from_section (KEYMAP_SECTION_EDITOR, editor_keymap, mc_global_keymap);
1382         editor_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1383         load_keymap_from_section (KEYMAP_SECTION_EDITOR_EXT, editor_x_keymap, mc_global_keymap);
1384 #endif
1385 
1386         viewer_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1387         load_keymap_from_section (KEYMAP_SECTION_VIEWER, viewer_keymap, mc_global_keymap);
1388         viewer_hex_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1389         load_keymap_from_section (KEYMAP_SECTION_VIEWER_HEX, viewer_hex_keymap, mc_global_keymap);
1390 
1391 #ifdef USE_DIFF_VIEW
1392         diff_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1393         load_keymap_from_section (KEYMAP_SECTION_DIFFVIEWER, diff_keymap, mc_global_keymap);
1394 #endif
1395 
1396         mc_config_deinit (mc_global_keymap);
1397     }
1398 
1399     main_map = (global_keymap_t *) main_keymap->data;
1400     main_x_map = (global_keymap_t *) main_x_keymap->data;
1401     panel_map = (global_keymap_t *) panel_keymap->data;
1402     dialog_map = (global_keymap_t *) dialog_keymap->data;
1403     menu_map = (global_keymap_t *) menu_keymap->data;
1404     input_map = (global_keymap_t *) input_keymap->data;
1405     listbox_map = (global_keymap_t *) listbox_keymap->data;
1406     tree_map = (global_keymap_t *) tree_keymap->data;
1407     help_map = (global_keymap_t *) help_keymap->data;
1408 #ifdef USE_INTERNAL_EDIT
1409     editor_map = (global_keymap_t *) editor_keymap->data;
1410     editor_x_map = (global_keymap_t *) editor_x_keymap->data;
1411 #endif
1412     viewer_map = (global_keymap_t *) viewer_keymap->data;
1413     viewer_hex_map = (global_keymap_t *) viewer_hex_keymap->data;
1414 #ifdef USE_DIFF_VIEW
1415     diff_map = (global_keymap_t *) diff_keymap->data;
1416 #endif
1417 }
1418 
1419 /* --------------------------------------------------------------------------------------------- */
1420 
1421 void
1422 free_keymap_defs (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1423 {
1424     if (main_keymap != NULL)
1425         g_array_free (main_keymap, TRUE);
1426     if (main_x_keymap != NULL)
1427         g_array_free (main_x_keymap, TRUE);
1428     if (panel_keymap != NULL)
1429         g_array_free (panel_keymap, TRUE);
1430     if (dialog_keymap != NULL)
1431         g_array_free (dialog_keymap, TRUE);
1432     if (input_keymap != NULL)
1433         g_array_free (input_keymap, TRUE);
1434     if (listbox_keymap != NULL)
1435         g_array_free (listbox_keymap, TRUE);
1436     if (tree_keymap != NULL)
1437         g_array_free (tree_keymap, TRUE);
1438     if (help_keymap != NULL)
1439         g_array_free (help_keymap, TRUE);
1440 #ifdef USE_INTERNAL_EDIT
1441     if (editor_keymap != NULL)
1442         g_array_free (editor_keymap, TRUE);
1443     if (editor_x_keymap != NULL)
1444         g_array_free (editor_x_keymap, TRUE);
1445 #endif
1446     if (viewer_keymap != NULL)
1447         g_array_free (viewer_keymap, TRUE);
1448     if (viewer_hex_keymap != NULL)
1449         g_array_free (viewer_hex_keymap, TRUE);
1450 #ifdef USE_DIFF_VIEW
1451     if (diff_keymap != NULL)
1452         g_array_free (diff_keymap, TRUE);
1453 #endif
1454 }
1455 
1456 /* --------------------------------------------------------------------------------------------- */
1457 
1458 void
1459 panel_load_setup (WPanel * panel, const char *section)
     /* [previous][next][first][last][top][bottom][index][help]  */
1460 {
1461     size_t i;
1462     char *buffer, buffer2[BUF_TINY];
1463 
1464     panel->sort_info.reverse =
1465         mc_config_get_bool (mc_global.panels_config, section, "reverse", FALSE);
1466     panel->sort_info.case_sensitive =
1467         mc_config_get_bool (mc_global.panels_config, section, "case_sensitive",
1468                             OS_SORT_CASE_SENSITIVE_DEFAULT);
1469     panel->sort_info.exec_first =
1470         mc_config_get_bool (mc_global.panels_config, section, "exec_first", FALSE);
1471 
1472     /* Load sort order */
1473     buffer = mc_config_get_string (mc_global.panels_config, section, "sort_order", "name");
1474     panel->sort_field = panel_get_field_by_id (buffer);
1475     if (panel->sort_field == NULL)
1476         panel->sort_field = panel_get_field_by_id ("name");
1477 
1478     g_free (buffer);
1479 
1480     /* Load the listing format */
1481     buffer = mc_config_get_string (mc_global.panels_config, section, "list_format", NULL);
1482     if (buffer == NULL)
1483     {
1484         /* fallback to old option */
1485         buffer = mc_config_get_string (mc_global.panels_config, section, "list_mode", "full");
1486     }
1487     panel->list_format = list_full;
1488     for (i = 0; list_formats[i].key != NULL; i++)
1489         if (g_ascii_strcasecmp (list_formats[i].key, buffer) == 0)
1490         {
1491             panel->list_format = list_formats[i].list_format;
1492             break;
1493         }
1494     g_free (buffer);
1495 
1496     panel->brief_cols = mc_config_get_int (mc_global.panels_config, section, "brief_cols", 2);
1497 
1498     /* User formats */
1499     g_free (panel->user_format);
1500     panel->user_format =
1501         mc_config_get_string (mc_global.panels_config, section, "user_format", DEFAULT_USER_FORMAT);
1502 
1503     for (i = 0; i < LIST_FORMATS; i++)
1504     {
1505         g_free (panel->user_status_format[i]);
1506         g_snprintf (buffer2, sizeof (buffer2), "user_status%lld", (long long) i);
1507         panel->user_status_format[i] =
1508             mc_config_get_string (mc_global.panels_config, section, buffer2, DEFAULT_USER_FORMAT);
1509     }
1510 
1511     panel->user_mini_status =
1512         mc_config_get_bool (mc_global.panels_config, section, "user_mini_status", FALSE);
1513 }
1514 
1515 /* --------------------------------------------------------------------------------------------- */
1516 
1517 void
1518 panel_save_setup (WPanel * panel, const char *section)
     /* [previous][next][first][last][top][bottom][index][help]  */
1519 {
1520     char buffer[BUF_TINY];
1521     size_t i;
1522 
1523     mc_config_set_bool (mc_global.panels_config, section, "reverse", panel->sort_info.reverse);
1524     mc_config_set_bool (mc_global.panels_config, section, "case_sensitive",
1525                         panel->sort_info.case_sensitive);
1526     mc_config_set_bool (mc_global.panels_config, section, "exec_first",
1527                         panel->sort_info.exec_first);
1528 
1529     mc_config_set_string (mc_global.panels_config, section, "sort_order", panel->sort_field->id);
1530 
1531     for (i = 0; list_formats[i].key != NULL; i++)
1532         if (list_formats[i].list_format == (int) panel->list_format)
1533         {
1534             mc_config_set_string (mc_global.panels_config, section, "list_format",
1535                                   list_formats[i].key);
1536             break;
1537         }
1538 
1539     mc_config_set_int (mc_global.panels_config, section, "brief_cols", panel->brief_cols);
1540 
1541     mc_config_set_string (mc_global.panels_config, section, "user_format", panel->user_format);
1542 
1543     for (i = 0; i < LIST_FORMATS; i++)
1544     {
1545         g_snprintf (buffer, sizeof (buffer), "user_status%lld", (long long) i);
1546         mc_config_set_string (mc_global.panels_config, section, buffer,
1547                               panel->user_status_format[i]);
1548     }
1549 
1550     mc_config_set_bool (mc_global.panels_config, section, "user_mini_status",
1551                         panel->user_mini_status);
1552 }
1553 
1554 /* --------------------------------------------------------------------------------------------- */

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