Sync with gnulib 6ed53f13bc39d9a0252549e98a2a59441fb2351f.
[midnight-commander.git] / src / setup.c
blob57c9a36fb723f6256ca0d7e46c7badcaa07ce13d
1 /*
2 Setup loading/saving.
4 Copyright (C) 1994-2016
5 Free Software Foundation, Inc.
7 This file is part of the Midnight Commander.
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.
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.
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/>.
23 /** \file setup.c
24 * \brief Source: setup loading/saving
27 #include <config.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <stdio.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
35 #include "lib/global.h"
37 #include "lib/tty/tty.h"
38 #include "lib/tty/key.h"
39 #include "lib/mcconfig.h"
40 #include "lib/fileloc.h"
41 #include "lib/timefmt.h"
42 #include "lib/util.h"
43 #include "lib/widget.h"
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
52 #ifdef HAVE_CHARSET
53 #include "lib/charsets.h"
54 #endif
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"
64 #include "args.h"
65 #include "execute.h" /* pause_after_run */
66 #include "clipboard.h"
67 #include "keybind-defaults.h" /* keybind_lookup_action */
69 #ifdef HAVE_CHARSET
70 #include "selcodepage.h"
71 #endif
73 #ifdef USE_INTERNAL_EDIT
74 #include "src/editor/edit.h"
75 #endif
77 #include "src/viewer/mcviewer.h" /* For the externs */
79 #include "setup.h"
81 /*** global variables ****************************************************************************/
83 char *global_profile_name; /* mc.lib */
85 /* Only used at program boot */
86 gboolean boot_current_is_left = TRUE;
88 /* If on, default for "No" in delete operations */
89 int safe_delete = 0;
91 /* Controls screen clearing before an exec */
92 int clear_before_exec = 1;
94 /* Asks for confirmation before deleting a file */
95 int confirm_delete = 1;
96 /* Asks for confirmation before deleting a hotlist entry */
97 int confirm_directory_hotlist_delete = 1;
98 /* Asks for confirmation before overwriting a file */
99 int confirm_overwrite = 1;
100 /* Asks for confirmation before executing a program by pressing enter */
101 int confirm_execute = 0;
102 /* Asks for confirmation before leaving the program */
103 int confirm_exit = 0;
105 /* If true, at startup the user-menu is invoked */
106 int auto_menu = 0;
107 /* This flag indicates if the pull down menus by default drop down */
108 int drop_menus = 0;
110 /* Asks for confirmation when using F3 to view a directory and there
111 are tagged files */
112 int confirm_view_dir = 0;
114 /* Ask file name before start the editor */
115 int editor_ask_filename_before_edit = 0;
117 panel_view_mode_t startup_left_mode;
118 panel_view_mode_t startup_right_mode;
120 int setup_copymove_persistent_attr = 1;
122 /* Tab size */
123 int option_tab_spacing = DEFAULT_TAB_SPACING;
125 /* Ugly hack to allow panel_save_setup to work as a place holder for */
126 /* default panel values */
127 int saving_setup;
129 panels_options_t panels_options = {
130 .show_mini_info = TRUE,
131 .kilobyte_si = FALSE,
132 .mix_all_files = FALSE,
133 .show_backups = TRUE,
134 .show_dot_files = TRUE,
135 .fast_reload = FALSE,
136 .fast_reload_msg_shown = FALSE,
137 .mark_moves_down = TRUE,
138 .reverse_files_only = TRUE,
139 .auto_save_setup = FALSE,
140 .navigate_with_arrows = FALSE,
141 .scroll_pages = TRUE,
142 .mouse_move_pages = TRUE,
143 .filetype_mode = TRUE,
144 .permission_mode = FALSE,
145 .qsearch_mode = QSEARCH_PANEL_CASE,
146 .torben_fj_mode = FALSE,
147 .select_flags = SELECT_MATCH_CASE | SELECT_SHELL_PATTERNS
150 int easy_patterns = 1;
152 /* It true saves the setup when quitting */
153 int auto_save_setup = 1;
155 /* If true, then the +, - and \ keys have their special meaning only if the
156 * command line is emtpy, otherwise they behave like regular letters
158 int only_leading_plus_minus = 1;
160 /* Automatically fills name with current selected item name on mkdir */
161 int auto_fill_mkdir_name = 1;
163 /* If set and you don't have subshell support,then C-o will give you a shell */
164 int output_starts_shell = 0;
166 /* If set, we execute the file command to check the file type */
167 int use_file_to_check_type = 1;
169 int verbose = 1;
172 * Whether the Midnight Commander tries to provide more
173 * information about copy/move sizes and bytes transferred
174 * at the expense of some speed
176 int file_op_compute_totals = 1;
178 /* If true use the internal viewer */
179 int use_internal_view = 1;
180 /* If set, use the builtin editor */
181 int use_internal_edit = 1;
183 #ifdef HAVE_CHARSET
184 /* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
185 int default_source_codepage = -1;
186 char *autodetect_codeset = NULL;
187 gboolean is_autodetect_codeset_enabled = FALSE;
188 #endif /* !HAVE_CHARSET */
190 #ifdef HAVE_ASPELL
191 char *spell_language = NULL;
192 #endif
194 /* Value of "other_dir" key in ini file */
195 char *saved_other_dir = NULL;
197 /* If set, then print to the given file the last directory we were at */
198 char *last_wd_string = NULL;
200 /* Set when main loop should be terminated */
201 int quit = 0;
203 /* Set to TRUE to suppress printing the last directory */
204 int print_last_revert = FALSE;
206 #ifdef USE_INTERNAL_EDIT
207 /* index to record_macro_buf[], -1 if not recording a macro */
208 int macro_index = -1;
210 /* macro stuff */
211 struct macro_action_t record_macro_buf[MAX_MACRO_LENGTH];
213 GArray *macros_list;
214 #endif /* USE_INTERNAL_EDIT */
216 /*** file scope macro definitions ****************************************************************/
218 /* In order to use everywhere the same setup for the locale we use defines */
219 #define FMTYEAR _("%b %e %Y")
220 #define FMTTIME _("%b %e %H:%M")
222 /*** file scope type declarations ****************************************************************/
224 /*** file scope variables ************************************************************************/
226 static char *profile_name = NULL; /* ${XDG_CONFIG_HOME}/mc/ini */
227 static char *panels_profile_name = NULL; /* ${XDG_CACHE_HOME}/mc/panels.ini */
229 /* *INDENT-OFF* */
230 static const struct
232 const char *key;
233 int list_type;
234 } list_types [] = {
235 { "full", list_full },
236 { "brief", list_brief },
237 { "long", list_long },
238 { "user", list_user },
239 { NULL, 0 }
242 static const struct
244 const char *opt_name;
245 panel_view_mode_t opt_type;
246 } panel_types [] = {
247 { "listing", view_listing },
248 { "quickview", view_quick },
249 { "info", view_info },
250 { "tree", view_tree },
251 { NULL, view_listing }
254 static const struct
256 const char *opt_name;
257 int *opt_addr;
258 } layout [] = {
259 { "message_visible", &mc_global.message_visible },
260 { "keybar_visible", &mc_global.keybar_visible },
261 { "xterm_title", &xterm_title },
262 { "output_lines", &output_lines },
263 { "command_prompt", &command_prompt },
264 { "menubar_visible", &menubar_visible },
265 { "free_space", &free_space },
266 { "horizontal_split", &panels_layout.horizontal_split },
267 { "vertical_equal", &panels_layout.vertical_equal },
268 { "left_panel_size", &panels_layout.left_panel_size },
269 { "horizontal_equal", &panels_layout.horizontal_equal },
270 { "top_panel_size", &panels_layout.top_panel_size },
271 { NULL, NULL }
274 static const struct
276 const char *opt_name;
277 int *opt_addr;
278 } int_options [] = {
279 { "verbose", &verbose },
280 { "pause_after_run", &pause_after_run },
281 { "shell_patterns", &easy_patterns },
282 { "auto_save_setup", &auto_save_setup },
283 { "preallocate_space", &mc_global.vfs.preallocate_space },
284 { "auto_menu", &auto_menu },
285 { "use_internal_view", &use_internal_view },
286 { "use_internal_edit", &use_internal_edit },
287 { "clear_before_exec", &clear_before_exec },
288 { "confirm_delete", &confirm_delete },
289 { "confirm_overwrite", &confirm_overwrite },
290 { "confirm_execute", &confirm_execute },
291 { "confirm_history_cleanup", &mc_global.widget.confirm_history_cleanup },
292 { "confirm_exit", &confirm_exit },
293 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete },
294 { "safe_delete", &safe_delete },
295 { "mouse_repeat_rate", &mou_auto_repeat },
296 { "double_click_speed", &double_click_speed },
297 #ifndef HAVE_CHARSET
298 { "eight_bit_clean", &mc_global.eight_bit_clean },
299 { "full_eight_bits", &mc_global.full_eight_bits },
300 #endif /* !HAVE_CHARSET */
301 { "use_8th_bit_as_meta", &use_8th_bit_as_meta },
302 { "confirm_view_dir", &confirm_view_dir },
303 { "mouse_move_pages_viewer", &mcview_mouse_move_pages },
304 { "mouse_close_dialog", &mouse_close_dialog},
305 { "fast_refresh", &fast_refresh },
306 { "drop_menus", &drop_menus },
307 { "wrap_mode", &mcview_global_wrap_mode},
308 { "old_esc_mode", &old_esc_mode },
309 { "old_esc_mode_timeout", &old_esc_mode_timeout },
310 { "cd_symlinks", &mc_global.vfs.cd_symlinks },
311 { "show_all_if_ambiguous", &mc_global.widget.show_all_if_ambiguous },
312 { "max_dirt_limit", &mcview_max_dirt_limit },
313 { "use_file_to_guess_type", &use_file_to_check_type },
314 { "alternate_plus_minus", &mc_global.tty.alternate_plus_minus },
315 { "only_leading_plus_minus", &only_leading_plus_minus },
316 { "show_output_starts_shell", &output_starts_shell },
317 { "xtree_mode", &xtree_mode },
318 { "num_history_items_recorded", &num_history_items_recorded },
319 { "file_op_compute_totals", &file_op_compute_totals },
320 { "classic_progressbar", &classic_progressbar},
321 #ifdef ENABLE_VFS
322 { "vfs_timeout", &vfs_timeout },
323 #ifdef ENABLE_VFS_FTP
324 { "ftpfs_directory_timeout", &ftpfs_directory_timeout },
325 { "use_netrc", &ftpfs_use_netrc },
326 { "ftpfs_retry_seconds", &ftpfs_retry_seconds },
327 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy },
328 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections },
329 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy },
330 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options },
331 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls },
332 #endif /* ENABLE_VFS_FTP */
333 #ifdef ENABLE_VFS_FISH
334 { "fish_directory_timeout", &fish_directory_timeout },
335 #endif /* ENABLE_VFS_FISH */
336 #endif /* ENABLE_VFS */
337 /* option_tab_spacing is used in internal viewer */
338 { "editor_tab_spacing", &option_tab_spacing },
339 #ifdef USE_INTERNAL_EDIT
340 { "editor_word_wrap_line_length", &option_word_wrap_line_length },
341 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces },
342 { "editor_return_does_auto_indent", &option_return_does_auto_indent },
343 { "editor_backspace_through_tabs", &option_backspace_through_tabs },
344 { "editor_fake_half_tabs", &option_fake_half_tabs },
345 { "editor_option_save_mode", &option_save_mode },
346 { "editor_option_save_position", &option_save_position },
347 { "editor_option_auto_para_formatting", &option_auto_para_formatting },
348 { "editor_option_typewriter_wrap", &option_typewriter_wrap },
349 { "editor_edit_confirm_save", &edit_confirm_save },
350 { "editor_syntax_highlighting", &option_syntax_highlighting },
351 { "editor_persistent_selections", &option_persistent_selections },
352 { "editor_drop_selection_on_copy", &option_drop_selection_on_copy },
353 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol },
354 { "editor_cursor_after_inserted_block", &option_cursor_after_inserted_block },
355 { "editor_visible_tabs", &visible_tabs },
356 { "editor_visible_spaces", &visible_tws },
357 { "editor_line_state", &option_line_state },
358 { "editor_simple_statusbar", &simple_statusbar },
359 { "editor_check_new_line", &option_check_nl_at_eof },
360 { "editor_show_right_margin", &show_right_margin },
361 { "editor_group_undo", &option_group_undo },
362 { "editor_state_full_filename", &option_state_full_filename },
363 #endif /* USE_INTERNAL_EDIT */
364 { "editor_ask_filename_before_edit", &editor_ask_filename_before_edit },
365 { "nice_rotating_dash", &nice_rotating_dash },
366 { "mcview_remember_file_position", &mcview_remember_file_position },
367 { "auto_fill_mkdir_name", &auto_fill_mkdir_name },
368 { "copymove_persistent_attr", &setup_copymove_persistent_attr },
369 { NULL, NULL }
372 static const struct
374 const char *opt_name;
375 char **opt_addr;
376 const char *opt_defval;
377 } str_options[] = {
378 #ifdef USE_INTERNAL_EDIT
379 { "editor_backup_extension", &option_backup_ext, "~" },
380 { "editor_filesize_threshold", &option_filesize_threshold, "64M" },
381 { "editor_stop_format_chars", &option_stop_format_chars, "-+*\\,.;:&>" },
382 #endif
383 { "mcview_eof", &mcview_show_eof, "" },
384 { NULL, NULL, NULL }
387 static const struct
389 const char *opt_name;
390 gboolean *opt_addr;
391 } panels_ini_options[] = {
392 { "show_mini_info", &panels_options.show_mini_info },
393 { "kilobyte_si", &panels_options.kilobyte_si },
394 { "mix_all_files", &panels_options.mix_all_files },
395 { "show_backups", &panels_options.show_backups },
396 { "show_dot_files", &panels_options.show_dot_files },
397 { "fast_reload", &panels_options.fast_reload },
398 { "fast_reload_msg_shown", &panels_options.fast_reload_msg_shown },
399 { "mark_moves_down", &panels_options.mark_moves_down },
400 { "reverse_files_only", &panels_options.reverse_files_only },
401 { "auto_save_setup_panels", &panels_options.auto_save_setup },
402 { "navigate_with_arrows", &panels_options.navigate_with_arrows },
403 { "panel_scroll_pages", &panels_options.scroll_pages },
404 { "mouse_move_pages", &panels_options.mouse_move_pages },
405 { "filetype_mode", &panels_options.filetype_mode },
406 { "permission_mode", &panels_options.permission_mode },
407 { "torben_fj_mode", &panels_options.torben_fj_mode },
408 { NULL, NULL }
410 /* *INDENT-ON* */
412 /*** file scope functions ************************************************************************/
413 /* --------------------------------------------------------------------------------------------- */
416 * Get name of config file.
418 * @param subdir If not NULL, config is also searched in specified subdir.
419 * @param config_file_name If relative, file if searched in standard paths.
421 * @return newly allocated string with config name or NULL if file is not found.
424 static char *
425 load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
428 TODO: IMHO, in future, this function shall be placed in mcconfig module.
430 char *lc_basename, *ret;
431 char *file_name;
433 if (config_file_name == NULL)
434 return NULL;
436 /* check for .keymap suffix */
437 if (g_str_has_suffix (config_file_name, ".keymap"))
438 file_name = g_strdup (config_file_name);
439 else
440 file_name = g_strconcat (config_file_name, ".keymap", (char *) NULL);
442 canonicalize_pathname (file_name);
444 if (g_path_is_absolute (file_name))
445 return file_name;
447 lc_basename = g_path_get_basename (file_name);
448 g_free (file_name);
450 if (lc_basename == NULL)
451 return NULL;
453 if (subdir != NULL)
454 ret = g_build_filename (mc_config_get_path (), subdir, lc_basename, (char *) NULL);
455 else
456 ret = g_build_filename (mc_config_get_path (), lc_basename, (char *) NULL);
458 if (exist_file (ret))
460 g_free (lc_basename);
461 canonicalize_pathname (ret);
462 return ret;
464 g_free (ret);
466 if (subdir != NULL)
467 ret = g_build_filename (mc_global.sysconfig_dir, subdir, lc_basename, (char *) NULL);
468 else
469 ret = g_build_filename (mc_global.sysconfig_dir, lc_basename, (char *) NULL);
471 if (exist_file (ret))
473 g_free (lc_basename);
474 canonicalize_pathname (ret);
475 return ret;
477 g_free (ret);
479 if (subdir != NULL)
480 ret = g_build_filename (mc_global.share_data_dir, subdir, lc_basename, (char *) NULL);
481 else
482 ret = g_build_filename (mc_global.share_data_dir, lc_basename, (char *) NULL);
484 g_free (lc_basename);
486 if (exist_file (ret))
488 canonicalize_pathname (ret);
489 return ret;
492 g_free (ret);
493 return NULL;
496 /* --------------------------------------------------------------------------------------------- */
498 static const char *
499 setup__is_cfg_group_must_panel_config (const char *grp)
501 return (!strcasecmp ("Dirs", grp) ||
502 !strcasecmp ("Temporal:New Right Panel", grp) ||
503 !strcasecmp ("Temporal:New Left Panel", grp) ||
504 !strcasecmp ("New Left Panel", grp) || !strcasecmp ("New Right Panel", grp))
505 ? grp : NULL;
508 /* --------------------------------------------------------------------------------------------- */
510 static void
511 setup__move_panels_config_into_separate_file (const char *profile)
513 mc_config_t *tmp_cfg;
514 char **groups, **curr_grp;
516 if (!exist_file (profile))
517 return;
519 tmp_cfg = mc_config_init (profile, FALSE);
520 if (tmp_cfg == NULL)
521 return;
523 groups = mc_config_get_groups (tmp_cfg, NULL);
524 if (*groups == NULL)
526 g_strfreev (groups);
527 mc_config_deinit (tmp_cfg);
528 return;
531 for (curr_grp = groups; *curr_grp != NULL; curr_grp++)
532 if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL)
533 mc_config_del_group (tmp_cfg, *curr_grp);
535 mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
536 mc_config_deinit (tmp_cfg);
538 tmp_cfg = mc_config_init (profile, FALSE);
539 if (tmp_cfg == NULL)
541 g_strfreev (groups);
542 return;
545 for (curr_grp = groups; *curr_grp != NULL; curr_grp++)
547 const char *need_grp;
549 need_grp = setup__is_cfg_group_must_panel_config (*curr_grp);
550 if (need_grp != NULL)
551 mc_config_del_group (tmp_cfg, need_grp);
553 g_strfreev (groups);
555 mc_config_save_file (tmp_cfg, NULL);
556 mc_config_deinit (tmp_cfg);
559 /* --------------------------------------------------------------------------------------------- */
561 Create new mc_config object from specified ini-file or
562 append data to existing mc_config object from ini-file
565 static void
566 load_setup_init_config_from_file (mc_config_t ** config, const char *fname, gboolean read_only)
569 TODO: IMHO, in future, this function shall be placed in mcconfig module.
571 if (exist_file (fname))
573 if (*config != NULL)
574 mc_config_read_file (*config, fname, read_only, TRUE);
575 else
576 *config = mc_config_init (fname, read_only);
580 /* --------------------------------------------------------------------------------------------- */
582 static void
583 load_layout (void)
585 size_t i;
586 int equal_split;
587 int first_panel_size;
589 /* legacy options */
590 panels_layout.horizontal_split = mc_config_get_int (mc_global.main_config, CONFIG_APP_SECTION,
591 "horizontal_split", 0);
592 equal_split = mc_config_get_int (mc_global.main_config, "Layout", "equal_split", 1);
593 first_panel_size = mc_config_get_int (mc_global.main_config, "Layout", "first_panel_size", 1);
594 if (panels_layout.horizontal_split)
596 panels_layout.horizontal_equal = equal_split;
597 panels_layout.left_panel_size = first_panel_size;
599 else
601 panels_layout.vertical_equal = equal_split;
602 panels_layout.top_panel_size = first_panel_size;
605 /* actual options override legacy ones */
606 for (i = 0; layout[i].opt_name != NULL; i++)
607 *layout[i].opt_addr = mc_config_get_int (mc_global.main_config, CONFIG_LAYOUT_SECTION,
608 layout[i].opt_name, *layout[i].opt_addr);
610 /* remove legacy options */
611 mc_config_del_key (mc_global.main_config, CONFIG_APP_SECTION, "horizontal_split");
612 mc_config_del_key (mc_global.main_config, "Layout", "equal_split");
613 mc_config_del_key (mc_global.main_config, "Layout", "first_panel_size");
616 /* --------------------------------------------------------------------------------------------- */
618 static void
619 load_keys_from_section (const char *terminal, mc_config_t * cfg)
621 char *section_name;
622 gchar **profile_keys, **keys;
623 char *valcopy, *value;
624 long key_code;
626 if (terminal == NULL)
627 return;
629 section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
630 keys = mc_config_get_keys (cfg, section_name, NULL);
632 for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
634 /* copy=other causes all keys from [terminal:other] to be loaded. */
635 if (g_ascii_strcasecmp (*profile_keys, "copy") == 0)
637 valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
638 load_keys_from_section (valcopy, cfg);
639 g_free (valcopy);
640 continue;
643 key_code = lookup_key (*profile_keys, NULL);
644 if (key_code != 0)
646 gchar **values;
648 values = mc_config_get_string_list (cfg, section_name, *profile_keys, NULL);
649 if (values != NULL)
651 gchar **curr_values;
653 for (curr_values = values; *curr_values != NULL; curr_values++)
655 valcopy = convert_controls (*curr_values);
656 define_sequence (key_code, valcopy, MCKEY_NOACTION);
657 g_free (valcopy);
660 g_strfreev (values);
662 else
664 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
665 valcopy = convert_controls (value);
666 define_sequence (key_code, valcopy, MCKEY_NOACTION);
667 g_free (valcopy);
668 g_free (value);
672 g_strfreev (keys);
673 g_free (section_name);
676 /* --------------------------------------------------------------------------------------------- */
678 static void
679 load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg)
681 gchar **profile_keys, **keys;
683 if (section_name == NULL)
684 return;
686 keys = mc_config_get_keys (cfg, section_name, NULL);
688 for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
690 gchar **values;
692 values = mc_config_get_string_list (cfg, section_name, *profile_keys, NULL);
693 if (values != NULL)
695 long action;
697 action = keybind_lookup_action (*profile_keys);
698 if (action > 0)
700 gchar **curr_values;
702 for (curr_values = values; *curr_values != NULL; curr_values++)
703 keybind_cmd_bind (keymap, *curr_values, action);
706 g_strfreev (values);
710 g_strfreev (keys);
713 /* --------------------------------------------------------------------------------------------- */
715 static mc_config_t *
716 load_setup_get_keymap_profile_config (gboolean load_from_file)
719 TODO: IMHO, in future, this function shall be placed in mcconfig module.
721 mc_config_t *keymap_config;
722 char *share_keymap, *sysconfig_keymap;
723 char *fname, *fname2;
725 /* 0) Create default keymap */
726 keymap_config = create_default_keymap ();
727 if (!load_from_file)
728 return keymap_config;
730 /* load and merge global keymaps */
732 /* 1) /usr/share/mc (mc_global.share_data_dir) */
733 share_keymap = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, (char *) NULL);
734 load_setup_init_config_from_file (&keymap_config, share_keymap, TRUE);
736 /* 2) /etc/mc (mc_global.sysconfig_dir) */
737 sysconfig_keymap =
738 g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, (char *) NULL);
739 load_setup_init_config_from_file (&keymap_config, sysconfig_keymap, TRUE);
741 /* then load and merge one of user-defined keymap */
743 /* 3) --keymap=<keymap> */
744 fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file);
745 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
747 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
748 goto done;
750 g_free (fname);
752 /* 4) getenv("MC_KEYMAP") */
753 fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
754 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
756 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
757 goto done;
759 g_free (fname);
761 /* 5) main config; [Midnight Commander] -> keymap */
762 fname2 = mc_config_get_string (mc_global.main_config, CONFIG_APP_SECTION, "keymap", NULL);
763 if (fname2 != NULL && *fname2 != '\0')
764 fname = load_setup_get_full_config_name (NULL, fname2);
765 g_free (fname2);
766 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
768 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
769 goto done;
771 g_free (fname);
773 /* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */
774 fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE);
775 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
777 done:
778 g_free (fname);
779 g_free (sysconfig_keymap);
780 g_free (share_keymap);
782 return keymap_config;
785 /* --------------------------------------------------------------------------------------------- */
787 static panel_view_mode_t
788 setup__load_panel_state (const char *section)
790 char *buffer;
791 size_t i;
792 panel_view_mode_t mode = view_listing;
794 /* Load the display mode */
795 buffer = mc_config_get_string (mc_global.panels_config, section, "display", "listing");
797 for (i = 0; panel_types[i].opt_name != NULL; i++)
798 if (g_ascii_strcasecmp (panel_types[i].opt_name, buffer) == 0)
800 mode = panel_types[i].opt_type;
801 break;
804 g_free (buffer);
806 return mode;
809 /* --------------------------------------------------------------------------------------------- */
811 static void
812 panel_save_type (const char *section, panel_view_mode_t type)
814 size_t i;
816 for (i = 0; panel_types[i].opt_name != NULL; i++)
817 if (panel_types[i].opt_type == type)
819 mc_config_set_string (mc_global.panels_config, section, "display",
820 panel_types[i].opt_name);
821 break;
825 /* --------------------------------------------------------------------------------------------- */
828 * Load panels options from [Panels] section.
830 static void
831 panels_load_options (void)
833 if (mc_config_has_group (mc_global.main_config, CONFIG_PANELS_SECTION))
835 size_t i;
836 int qmode;
838 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
839 *panels_ini_options[i].opt_addr =
840 mc_config_get_bool (mc_global.main_config, CONFIG_PANELS_SECTION,
841 panels_ini_options[i].opt_name,
842 *panels_ini_options[i].opt_addr);
844 qmode = mc_config_get_int (mc_global.main_config, CONFIG_PANELS_SECTION,
845 "quick_search_mode", (int) panels_options.qsearch_mode);
846 if (qmode < 0)
847 panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE;
848 else if (qmode >= QSEARCH_NUM)
849 panels_options.qsearch_mode = QSEARCH_PANEL_CASE;
850 else
851 panels_options.qsearch_mode = (qsearch_mode_t) qmode;
853 panels_options.select_flags =
854 mc_config_get_int (mc_global.main_config, CONFIG_PANELS_SECTION, "select_flags",
855 (int) panels_options.select_flags);
859 /* --------------------------------------------------------------------------------------------- */
862 * Save panels options in [Panels] section.
864 static void
865 panels_save_options (void)
867 size_t i;
869 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
870 mc_config_set_bool (mc_global.main_config, CONFIG_PANELS_SECTION,
871 panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr);
873 mc_config_set_int (mc_global.main_config, CONFIG_PANELS_SECTION,
874 "quick_search_mode", (int) panels_options.qsearch_mode);
875 mc_config_set_int (mc_global.main_config, CONFIG_PANELS_SECTION,
876 "select_flags", (int) panels_options.select_flags);
879 /* --------------------------------------------------------------------------------------------- */
881 static void
882 save_config (void)
884 size_t i;
886 /* Save integer options */
887 for (i = 0; int_options[i].opt_name != NULL; i++)
888 mc_config_set_int (mc_global.main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
889 *int_options[i].opt_addr);
891 /* Save string options */
892 for (i = 0; str_options[i].opt_name != NULL; i++)
893 mc_config_set_string (mc_global.main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
894 *str_options[i].opt_addr);
897 /* --------------------------------------------------------------------------------------------- */
899 static void
900 save_layout (void)
902 size_t i;
904 /* Save integer options */
905 for (i = 0; layout[i].opt_name != NULL; i++)
906 mc_config_set_int (mc_global.main_config, CONFIG_LAYOUT_SECTION, layout[i].opt_name,
907 *layout[i].opt_addr);
910 /* --------------------------------------------------------------------------------------------- */
912 /* save panels.ini */
913 static void
914 save_panel_types (void)
916 panel_view_mode_t type;
918 if (mc_global.mc_run_mode != MC_RUN_FULL)
919 return;
921 type = get_display_type (0);
922 panel_save_type ("New Left Panel", type);
923 if (type == view_listing)
924 panel_save_setup (left_panel, left_panel->panel_name);
925 type = get_display_type (1);
926 panel_save_type ("New Right Panel", type);
927 if (type == view_listing)
928 panel_save_setup (right_panel, right_panel->panel_name);
931 char *dirs;
933 dirs = get_panel_dir_for (other_panel);
934 mc_config_set_string (mc_global.panels_config, "Dirs", "other_dir", dirs);
935 g_free (dirs);
938 if (current_panel != NULL)
939 mc_config_set_bool (mc_global.panels_config, "Dirs", "current_is_left",
940 get_current_index () == 0);
942 if (mc_global.panels_config->ini_path == NULL)
943 mc_global.panels_config->ini_path = g_strdup (panels_profile_name);
945 mc_config_del_group (mc_global.panels_config, "Temporal:New Left Panel");
946 mc_config_del_group (mc_global.panels_config, "Temporal:New Right Panel");
948 mc_config_save_file (mc_global.panels_config, NULL);
951 /* --------------------------------------------------------------------------------------------- */
952 /*** public functions ****************************************************************************/
953 /* --------------------------------------------------------------------------------------------- */
955 const char *
956 setup_init (void)
958 if (profile_name == NULL)
960 char *profile;
962 profile = mc_config_get_full_path (MC_CONFIG_FILE);
963 if (!exist_file (profile))
965 char *inifile;
967 inifile = mc_build_filename (mc_global.sysconfig_dir, "mc.ini", (char *) NULL);
968 if (exist_file (inifile))
970 g_free (profile);
971 profile = inifile;
973 else
975 g_free (inifile);
976 inifile = mc_build_filename (mc_global.share_data_dir, "mc.ini", (char *) NULL);
977 if (!exist_file (inifile))
978 g_free (inifile);
979 else
981 g_free (profile);
982 profile = inifile;
987 profile_name = profile;
990 return profile_name;
993 /* --------------------------------------------------------------------------------------------- */
995 void
996 load_setup (void)
998 const char *profile;
999 size_t i;
1000 const char *kt;
1002 #ifdef HAVE_CHARSET
1003 char *buffer;
1004 const char *cbuffer;
1006 load_codepages_list ();
1007 #endif /* HAVE_CHARSET */
1009 profile = setup_init ();
1011 /* mc.lib is common for all users, but has priority lower than
1012 ${XDG_CONFIG_HOME}/mc/ini. FIXME: it's only used for keys and treestore now */
1013 global_profile_name =
1014 g_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
1015 if (!exist_file (global_profile_name))
1017 g_free (global_profile_name);
1018 global_profile_name =
1019 g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
1022 panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE);
1024 mc_global.main_config = mc_config_init (profile, FALSE);
1026 if (!exist_file (panels_profile_name))
1027 setup__move_panels_config_into_separate_file (profile);
1029 mc_global.panels_config = mc_config_init (panels_profile_name, FALSE);
1031 /* Load integer boolean options */
1032 for (i = 0; int_options[i].opt_name != NULL; i++)
1033 *int_options[i].opt_addr =
1034 mc_config_get_int (mc_global.main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
1035 *int_options[i].opt_addr);
1036 #ifndef USE_INTERNAL_EDIT
1037 /* reset forced in case of build without internal editor */
1038 use_internal_edit = 0;
1039 #endif /* USE_INTERNAL_EDIT */
1041 if (option_tab_spacing <= 0)
1042 option_tab_spacing = DEFAULT_TAB_SPACING;
1044 #ifdef USE_INTERNAL_EDIT
1045 if (option_word_wrap_line_length <= 0)
1046 option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
1047 #endif /* USE_INTERNAL_EDIT */
1049 /* overwrite old_esc_mode_timeout */
1050 kt = getenv ("KEYBOARD_KEY_TIMEOUT_US");
1051 if ((kt != NULL) && (kt[0] != '\0'))
1052 old_esc_mode_timeout = atoi (kt);
1054 /* Load string options */
1055 for (i = 0; str_options[i].opt_name != NULL; i++)
1056 *str_options[i].opt_addr =
1057 mc_config_get_string (mc_global.main_config, CONFIG_APP_SECTION,
1058 str_options[i].opt_name, str_options[i].opt_defval);
1060 load_layout ();
1061 panels_load_options ();
1062 load_panelize ();
1064 startup_left_mode = setup__load_panel_state ("New Left Panel");
1065 startup_right_mode = setup__load_panel_state ("New Right Panel");
1067 /* At least one of the panels is a listing panel */
1068 if (startup_left_mode != view_listing && startup_right_mode != view_listing)
1069 startup_left_mode = view_listing;
1071 boot_current_is_left =
1072 mc_config_get_bool (mc_global.panels_config, "Dirs", "current_is_left", TRUE);
1074 /* Load time formats */
1075 user_recent_timeformat =
1076 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "timeformat_recent",
1077 FMTTIME);
1078 user_old_timeformat =
1079 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "timeformat_old",
1080 FMTYEAR);
1082 #ifdef ENABLE_VFS_FTP
1083 ftpfs_proxy_host =
1084 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftp_proxy_host", "gate");
1085 ftpfs_ignore_chattr_errors =
1086 mc_config_get_bool (mc_global.main_config, CONFIG_APP_SECTION, "ignore_ftp_chattr_errors",
1087 TRUE);
1088 ftpfs_init_passwd ();
1089 #endif /* ENABLE_VFS_FTP */
1091 /* The default color and the terminal dependent color */
1092 mc_global.tty.setup_color_string =
1093 mc_config_get_string (mc_global.main_config, "Colors", "base_color", "");
1094 mc_global.tty.term_color_string =
1095 mc_config_get_string (mc_global.main_config, "Colors", getenv ("TERM"), "");
1096 mc_global.tty.color_terminal_string =
1097 mc_config_get_string (mc_global.main_config, "Colors", "color_terminals", "");
1099 /* Load the directory history */
1100 /* directory_history_load (); */
1101 /* Remove the temporal entries */
1103 #ifdef HAVE_CHARSET
1104 if (codepages->len > 1)
1106 buffer =
1107 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "display_codepage",
1108 "");
1109 if (buffer[0] != '\0')
1111 mc_global.display_codepage = get_codepage_index (buffer);
1112 cp_display = get_codepage_id (mc_global.display_codepage);
1114 g_free (buffer);
1115 buffer =
1116 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "source_codepage",
1117 "");
1118 if (buffer[0] != '\0')
1120 default_source_codepage = get_codepage_index (buffer);
1121 mc_global.source_codepage = default_source_codepage; /* May be source_codepage doesn't need this */
1122 cp_source = get_codepage_id (mc_global.source_codepage);
1124 g_free (buffer);
1127 autodetect_codeset =
1128 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "autodetect_codeset", "");
1129 if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off") != 0))
1130 is_autodetect_codeset_enabled = TRUE;
1132 g_free (init_translation_table (mc_global.source_codepage, mc_global.display_codepage));
1133 cbuffer = get_codepage_id (mc_global.display_codepage);
1134 if (cbuffer != NULL)
1135 mc_global.utf8_display = str_isutf8 (cbuffer);
1136 #endif /* HAVE_CHARSET */
1138 #ifdef HAVE_ASPELL
1139 spell_language =
1140 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "spell_language", "en");
1141 #endif /* HAVE_ASPELL */
1143 clipboard_store_path =
1144 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_store", "");
1145 clipboard_paste_path =
1146 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_paste", "");
1149 /* --------------------------------------------------------------------------------------------- */
1151 gboolean
1152 save_setup (gboolean save_options, gboolean save_panel_options)
1154 gboolean ret = TRUE;
1156 saving_setup = 1;
1158 save_hotlist ();
1160 if (save_panel_options)
1161 save_panel_types ();
1163 if (save_options)
1165 char *tmp_profile;
1167 save_config ();
1168 save_layout ();
1169 panels_save_options ();
1170 save_panelize ();
1171 /* directory_history_save (); */
1173 #ifdef ENABLE_VFS_FTP
1174 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftpfs_password",
1175 ftpfs_anonymous_passwd);
1176 if (ftpfs_proxy_host)
1177 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftp_proxy_host",
1178 ftpfs_proxy_host);
1179 #endif /* ENABLE_VFS_FTP */
1181 #ifdef HAVE_CHARSET
1182 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "display_codepage",
1183 get_codepage_id (mc_global.display_codepage));
1184 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "source_codepage",
1185 get_codepage_id (default_source_codepage));
1186 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "autodetect_codeset",
1187 autodetect_codeset);
1188 #endif /* HAVE_CHARSET */
1190 #ifdef HAVE_ASPELL
1191 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "spell_language",
1192 spell_language);
1193 #endif /* HAVE_ASPELL */
1195 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_store",
1196 clipboard_store_path);
1197 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_paste",
1198 clipboard_paste_path);
1200 tmp_profile = mc_config_get_full_path (MC_CONFIG_FILE);
1201 ret = mc_config_save_to_file (mc_global.main_config, tmp_profile, NULL);
1202 g_free (tmp_profile);
1205 saving_setup = 0;
1207 return ret;
1210 /* --------------------------------------------------------------------------------------------- */
1212 void
1213 done_setup (void)
1215 size_t i;
1217 g_free (clipboard_store_path);
1218 g_free (clipboard_paste_path);
1219 g_free (global_profile_name);
1220 g_free (mc_global.tty.color_terminal_string);
1221 g_free (mc_global.tty.term_color_string);
1222 g_free (mc_global.tty.setup_color_string);
1223 g_free (profile_name);
1224 g_free (panels_profile_name);
1225 mc_config_deinit (mc_global.main_config);
1226 mc_config_deinit (mc_global.panels_config);
1228 g_free (user_recent_timeformat);
1229 g_free (user_old_timeformat);
1231 for (i = 0; str_options[i].opt_name != NULL; i++)
1232 g_free (*str_options[i].opt_addr);
1234 done_hotlist ();
1235 done_panelize ();
1236 /* directory_history_free (); */
1238 #ifdef HAVE_CHARSET
1239 g_free (autodetect_codeset);
1240 free_codepages_list ();
1241 #endif
1243 #ifdef HAVE_ASPELL
1244 g_free (spell_language);
1245 #endif /* HAVE_ASPELL */
1249 /* --------------------------------------------------------------------------------------------- */
1251 void
1252 setup_save_config_show_error (const char *filename, GError ** mcerror)
1254 if (mcerror != NULL && *mcerror != NULL)
1256 message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*mcerror)->message);
1257 g_error_free (*mcerror);
1258 *mcerror = NULL;
1263 /* --------------------------------------------------------------------------------------------- */
1265 void
1266 load_key_defs (void)
1269 * Load keys from mc.lib before ${XDG_CONFIG_HOME}/mc/ini, so that the user
1270 * definitions override global settings.
1272 mc_config_t *mc_global_config;
1274 mc_global_config = mc_config_init (global_profile_name, FALSE);
1275 if (mc_global_config != NULL)
1277 load_keys_from_section ("general", mc_global_config);
1278 load_keys_from_section (getenv ("TERM"), mc_global_config);
1279 mc_config_deinit (mc_global_config);
1282 load_keys_from_section ("general", mc_global.main_config);
1283 load_keys_from_section (getenv ("TERM"), mc_global.main_config);
1286 /* --------------------------------------------------------------------------------------------- */
1288 #ifdef ENABLE_VFS_FTP
1289 char *
1290 load_anon_passwd (void)
1292 char *buffer;
1294 buffer =
1295 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftpfs_password", "");
1297 if ((buffer != NULL) && (buffer[0] != '\0'))
1298 return buffer;
1300 g_free (buffer);
1301 return NULL;
1303 #endif /* ENABLE_VFS_FTP */
1305 /* --------------------------------------------------------------------------------------------- */
1307 void
1308 load_keymap_defs (gboolean load_from_file)
1311 * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_CONFIG_HOME}/mc/mc.keymap, so that the user
1312 * definitions override global settings.
1314 mc_config_t *mc_global_keymap;
1316 mc_global_keymap = load_setup_get_keymap_profile_config (load_from_file);
1318 if (mc_global_keymap != NULL)
1320 main_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1321 load_keymap_from_section (KEYMAP_SECTION_MAIN, main_keymap, mc_global_keymap);
1322 main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1323 load_keymap_from_section (KEYMAP_SECTION_MAIN_EXT, main_x_keymap, mc_global_keymap);
1325 panel_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1326 load_keymap_from_section (KEYMAP_SECTION_PANEL, panel_keymap, mc_global_keymap);
1328 dialog_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1329 load_keymap_from_section (KEYMAP_SECTION_DIALOG, dialog_keymap, mc_global_keymap);
1331 input_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1332 load_keymap_from_section (KEYMAP_SECTION_INPUT, input_keymap, mc_global_keymap);
1334 listbox_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1335 load_keymap_from_section (KEYMAP_SECTION_LISTBOX, listbox_keymap, mc_global_keymap);
1337 tree_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1338 load_keymap_from_section (KEYMAP_SECTION_TREE, tree_keymap, mc_global_keymap);
1340 help_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1341 load_keymap_from_section (KEYMAP_SECTION_HELP, help_keymap, mc_global_keymap);
1343 #ifdef USE_INTERNAL_EDIT
1344 editor_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1345 load_keymap_from_section (KEYMAP_SECTION_EDITOR, editor_keymap, mc_global_keymap);
1346 editor_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1347 load_keymap_from_section (KEYMAP_SECTION_EDITOR_EXT, editor_x_keymap, mc_global_keymap);
1348 #endif
1350 viewer_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1351 load_keymap_from_section (KEYMAP_SECTION_VIEWER, viewer_keymap, mc_global_keymap);
1352 viewer_hex_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1353 load_keymap_from_section (KEYMAP_SECTION_VIEWER_HEX, viewer_hex_keymap, mc_global_keymap);
1355 #ifdef USE_DIFF_VIEW
1356 diff_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1357 load_keymap_from_section (KEYMAP_SECTION_DIFFVIEWER, diff_keymap, mc_global_keymap);
1358 #endif
1360 mc_config_deinit (mc_global_keymap);
1363 main_map = (global_keymap_t *) main_keymap->data;
1364 main_x_map = (global_keymap_t *) main_x_keymap->data;
1365 panel_map = (global_keymap_t *) panel_keymap->data;
1366 dialog_map = (global_keymap_t *) dialog_keymap->data;
1367 input_map = (global_keymap_t *) input_keymap->data;
1368 listbox_map = (global_keymap_t *) listbox_keymap->data;
1369 tree_map = (global_keymap_t *) tree_keymap->data;
1370 help_map = (global_keymap_t *) help_keymap->data;
1371 #ifdef USE_INTERNAL_EDIT
1372 editor_map = (global_keymap_t *) editor_keymap->data;
1373 editor_x_map = (global_keymap_t *) editor_x_keymap->data;
1374 #endif
1375 viewer_map = (global_keymap_t *) viewer_keymap->data;
1376 viewer_hex_map = (global_keymap_t *) viewer_hex_keymap->data;
1377 #ifdef USE_DIFF_VIEW
1378 diff_map = (global_keymap_t *) diff_keymap->data;
1379 #endif
1382 /* --------------------------------------------------------------------------------------------- */
1384 void
1385 free_keymap_defs (void)
1387 if (main_keymap != NULL)
1388 g_array_free (main_keymap, TRUE);
1389 if (main_x_keymap != NULL)
1390 g_array_free (main_x_keymap, TRUE);
1391 if (panel_keymap != NULL)
1392 g_array_free (panel_keymap, TRUE);
1393 if (dialog_keymap != NULL)
1394 g_array_free (dialog_keymap, TRUE);
1395 if (input_keymap != NULL)
1396 g_array_free (input_keymap, TRUE);
1397 if (listbox_keymap != NULL)
1398 g_array_free (listbox_keymap, TRUE);
1399 if (tree_keymap != NULL)
1400 g_array_free (tree_keymap, TRUE);
1401 if (help_keymap != NULL)
1402 g_array_free (help_keymap, TRUE);
1403 #ifdef USE_INTERNAL_EDIT
1404 if (editor_keymap != NULL)
1405 g_array_free (editor_keymap, TRUE);
1406 if (editor_x_keymap != NULL)
1407 g_array_free (editor_x_keymap, TRUE);
1408 #endif
1409 if (viewer_keymap != NULL)
1410 g_array_free (viewer_keymap, TRUE);
1411 if (viewer_hex_keymap != NULL)
1412 g_array_free (viewer_hex_keymap, TRUE);
1413 #ifdef USE_DIFF_VIEW
1414 if (diff_keymap != NULL)
1415 g_array_free (diff_keymap, TRUE);
1416 #endif
1419 /* --------------------------------------------------------------------------------------------- */
1421 void
1422 panel_load_setup (WPanel * panel, const char *section)
1424 size_t i;
1425 char *buffer, buffer2[BUF_TINY];
1427 panel->sort_info.reverse = mc_config_get_int (mc_global.panels_config, section, "reverse", 0);
1428 panel->sort_info.case_sensitive =
1429 mc_config_get_int (mc_global.panels_config, section, "case_sensitive",
1430 OS_SORT_CASE_SENSITIVE_DEFAULT);
1431 panel->sort_info.exec_first =
1432 mc_config_get_int (mc_global.panels_config, section, "exec_first", 0);
1434 /* Load sort order */
1435 buffer = mc_config_get_string (mc_global.panels_config, section, "sort_order", "name");
1436 panel->sort_field = panel_get_field_by_id (buffer);
1437 if (panel->sort_field == NULL)
1438 panel->sort_field = panel_get_field_by_id ("name");
1440 g_free (buffer);
1442 /* Load the listing mode */
1443 buffer = mc_config_get_string (mc_global.panels_config, section, "list_mode", "full");
1444 panel->list_type = list_full;
1445 for (i = 0; list_types[i].key != NULL; i++)
1446 if (g_ascii_strcasecmp (list_types[i].key, buffer) == 0)
1448 panel->list_type = list_types[i].list_type;
1449 break;
1451 g_free (buffer);
1453 panel->brief_cols = mc_config_get_int (mc_global.panels_config, section, "brief_cols", 2);
1455 /* User formats */
1456 g_free (panel->user_format);
1457 panel->user_format =
1458 mc_config_get_string (mc_global.panels_config, section, "user_format", DEFAULT_USER_FORMAT);
1460 for (i = 0; i < LIST_TYPES; i++)
1462 g_free (panel->user_status_format[i]);
1463 g_snprintf (buffer2, sizeof (buffer2), "user_status%lld", (long long) i);
1464 panel->user_status_format[i] =
1465 mc_config_get_string (mc_global.panels_config, section, buffer2, DEFAULT_USER_FORMAT);
1468 panel->user_mini_status =
1469 mc_config_get_int (mc_global.panels_config, section, "user_mini_status", 0);
1472 /* --------------------------------------------------------------------------------------------- */
1474 void
1475 panel_save_setup (WPanel * panel, const char *section)
1477 char buffer[BUF_TINY];
1478 size_t i;
1480 mc_config_set_int (mc_global.panels_config, section, "reverse", panel->sort_info.reverse);
1481 mc_config_set_int (mc_global.panels_config, section, "case_sensitive",
1482 panel->sort_info.case_sensitive);
1483 mc_config_set_int (mc_global.panels_config, section, "exec_first", panel->sort_info.exec_first);
1485 mc_config_set_string (mc_global.panels_config, section, "sort_order", panel->sort_field->id);
1487 for (i = 0; list_types[i].key != NULL; i++)
1488 if (list_types[i].list_type == (int) panel->list_type)
1490 mc_config_set_string (mc_global.panels_config, section, "list_mode", list_types[i].key);
1491 break;
1494 mc_config_set_int (mc_global.panels_config, section, "brief_cols", panel->brief_cols);
1496 mc_config_set_string (mc_global.panels_config, section, "user_format", panel->user_format);
1498 for (i = 0; i < LIST_TYPES; i++)
1500 g_snprintf (buffer, sizeof (buffer), "user_status%lld", (long long) i);
1501 mc_config_set_string (mc_global.panels_config, section, buffer,
1502 panel->user_status_format[i]);
1505 mc_config_set_int (mc_global.panels_config, section, "user_mini_status",
1506 panel->user_mini_status);
1510 /* --------------------------------------------------------------------------------------------- */