Ticket #3804: syntax: update Ada 95 keywords (ALT Linux #33330)
[midnight-commander.git] / src / setup.c
blobc033590ac7e2a71a7b2f3229ec1f23bdd4741afb
1 /*
2 Setup loading/saving.
4 Copyright (C) 1994-2017
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 gboolean safe_delete = FALSE;
91 /* Controls screen clearing before an exec */
92 gboolean clear_before_exec = TRUE;
94 /* Asks for confirmation before deleting a file */
95 gboolean confirm_delete = TRUE;
96 /* Asks for confirmation before deleting a hotlist entry */
97 gboolean confirm_directory_hotlist_delete = FALSE;
98 /* Asks for confirmation before overwriting a file */
99 gboolean confirm_overwrite = TRUE;
100 /* Asks for confirmation before executing a program by pressing enter */
101 gboolean confirm_execute = FALSE;
102 /* Asks for confirmation before leaving the program */
103 gboolean confirm_exit = FALSE;
105 /* If true, at startup the user-menu is invoked */
106 gboolean auto_menu = FALSE;
107 /* This flag indicates if the pull down menus by default drop down */
108 gboolean drop_menus = FALSE;
110 /* Asks for confirmation when using F3 to view a directory and there
111 are tagged files */
112 gboolean confirm_view_dir = FALSE;
114 /* Ask file name before start the editor */
115 gboolean editor_ask_filename_before_edit = FALSE;
117 panel_view_mode_t startup_left_mode;
118 panel_view_mode_t startup_right_mode;
120 gboolean copymove_persistent_attr = TRUE;
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 .scroll_center = FALSE,
143 .mouse_move_pages = TRUE,
144 .filetype_mode = TRUE,
145 .permission_mode = FALSE,
146 .qsearch_mode = QSEARCH_PANEL_CASE,
147 .torben_fj_mode = FALSE,
148 .select_flags = SELECT_MATCH_CASE | SELECT_SHELL_PATTERNS
151 gboolean easy_patterns = TRUE;
153 /* It true saves the setup when quitting */
154 gboolean auto_save_setup = TRUE;
156 /* If true, then the +, - and \ keys have their special meaning only if the
157 * command line is emtpy, otherwise they behave like regular letters
159 gboolean only_leading_plus_minus = TRUE;
161 /* Automatically fills name with current selected item name on mkdir */
162 gboolean auto_fill_mkdir_name = TRUE;
164 /* If set and you don't have subshell support,then C-o will give you a shell */
165 gboolean output_starts_shell = FALSE;
167 /* If set, we execute the file command to check the file type */
168 gboolean use_file_to_check_type = TRUE;
170 gboolean verbose = TRUE;
173 * Whether the Midnight Commander tries to provide more
174 * information about copy/move sizes and bytes transferred
175 * at the expense of some speed
177 gboolean file_op_compute_totals = TRUE;
179 /* If true use the internal viewer */
180 gboolean use_internal_view = TRUE;
181 /* If set, use the builtin editor */
182 gboolean use_internal_edit = TRUE;
184 #ifdef HAVE_CHARSET
185 /* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
186 int default_source_codepage = -1;
187 char *autodetect_codeset = NULL;
188 gboolean is_autodetect_codeset_enabled = FALSE;
189 #endif /* !HAVE_CHARSET */
191 #ifdef HAVE_ASPELL
192 char *spell_language = NULL;
193 #endif
195 /* Value of "other_dir" key in ini file */
196 char *saved_other_dir = NULL;
198 /* If set, then print to the given file the last directory we were at */
199 char *last_wd_string = NULL;
201 /* Set when main loop should be terminated */
202 int quit = 0;
204 /* Set to TRUE to suppress printing the last directory */
205 int print_last_revert = FALSE;
207 #ifdef USE_INTERNAL_EDIT
208 /* index to record_macro_buf[], -1 if not recording a macro */
209 int macro_index = -1;
211 /* macro stuff */
212 struct macro_action_t record_macro_buf[MAX_MACRO_LENGTH];
214 GArray *macros_list;
215 #endif /* USE_INTERNAL_EDIT */
217 /*** file scope macro definitions ****************************************************************/
219 /* In order to use everywhere the same setup for the locale we use defines */
220 #define FMTYEAR _("%b %e %Y")
221 #define FMTTIME _("%b %e %H:%M")
223 /*** file scope type declarations ****************************************************************/
225 /*** file scope variables ************************************************************************/
227 static char *profile_name = NULL; /* ${XDG_CONFIG_HOME}/mc/ini */
228 static char *panels_profile_name = NULL; /* ${XDG_CACHE_HOME}/mc/panels.ini */
230 /* *INDENT-OFF* */
231 static const struct
233 const char *key;
234 int list_type;
235 } list_types [] = {
236 { "full", list_full },
237 { "brief", list_brief },
238 { "long", list_long },
239 { "user", list_user },
240 { NULL, 0 }
243 static const struct
245 const char *opt_name;
246 panel_view_mode_t opt_type;
247 } panel_types [] = {
248 { "listing", view_listing },
249 { "quickview", view_quick },
250 { "info", view_info },
251 { "tree", view_tree },
252 { NULL, view_listing }
255 static const struct
257 const char *opt_name;
258 int *opt_addr;
259 } layout [] = {
260 { "message_visible", &mc_global.message_visible },
261 { "keybar_visible", &mc_global.keybar_visible },
262 { "xterm_title", &xterm_title },
263 { "output_lines", &output_lines },
264 { "command_prompt", &command_prompt },
265 { "menubar_visible", &menubar_visible },
266 { "free_space", &free_space },
267 { "horizontal_split", &panels_layout.horizontal_split },
268 { "vertical_equal", &panels_layout.vertical_equal },
269 { "left_panel_size", &panels_layout.left_panel_size },
270 { "horizontal_equal", &panels_layout.horizontal_equal },
271 { "top_panel_size", &panels_layout.top_panel_size },
272 { NULL, NULL }
275 static const struct
277 const char *opt_name;
278 gboolean *opt_addr;
279 } bool_options [] = {
280 { "verbose", &verbose },
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 { "confirm_view_dir", &confirm_view_dir },
295 { "safe_delete", &safe_delete },
296 #ifndef HAVE_CHARSET
297 { "eight_bit_clean", &mc_global.eight_bit_clean },
298 { "full_eight_bits", &mc_global.full_eight_bits },
299 #endif /* !HAVE_CHARSET */
300 { "use_8th_bit_as_meta", &use_8th_bit_as_meta },
301 { "mouse_move_pages_viewer", &mcview_mouse_move_pages },
302 { "mouse_close_dialog", &mouse_close_dialog},
303 { "fast_refresh", &fast_refresh },
304 { "drop_menus", &drop_menus },
305 { "wrap_mode", &mcview_global_wrap_mode },
306 { "old_esc_mode", &old_esc_mode },
307 { "cd_symlinks", &mc_global.vfs.cd_symlinks },
308 { "show_all_if_ambiguous", &mc_global.widget.show_all_if_ambiguous },
309 { "use_file_to_guess_type", &use_file_to_check_type },
310 { "alternate_plus_minus", &mc_global.tty.alternate_plus_minus },
311 { "only_leading_plus_minus", &only_leading_plus_minus },
312 { "show_output_starts_shell", &output_starts_shell },
313 { "xtree_mode", &xtree_mode },
314 { "file_op_compute_totals", &file_op_compute_totals },
315 { "classic_progressbar", &classic_progressbar },
316 #ifdef ENABLE_VFS
317 #ifdef ENABLE_VFS_FTP
318 { "use_netrc", &ftpfs_use_netrc },
319 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy },
320 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections },
321 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy },
322 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options },
323 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls },
324 { "ignore_ftp_chattr_errors", & ftpfs_ignore_chattr_errors} ,
325 #endif /* ENABLE_VFS_FTP */
326 #endif /* ENABLE_VFS */
327 #ifdef USE_INTERNAL_EDIT
328 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces },
329 { "editor_return_does_auto_indent", &option_return_does_auto_indent },
330 { "editor_backspace_through_tabs", &option_backspace_through_tabs },
331 { "editor_fake_half_tabs", &option_fake_half_tabs },
332 { "editor_option_save_position", &option_save_position },
333 { "editor_option_auto_para_formatting", &option_auto_para_formatting },
334 { "editor_option_typewriter_wrap", &option_typewriter_wrap },
335 { "editor_edit_confirm_save", &edit_confirm_save },
336 { "editor_syntax_highlighting", &option_syntax_highlighting },
337 { "editor_persistent_selections", &option_persistent_selections },
338 { "editor_drop_selection_on_copy", &option_drop_selection_on_copy },
339 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol },
340 { "editor_cursor_after_inserted_block", &option_cursor_after_inserted_block },
341 { "editor_visible_tabs", &visible_tabs },
342 { "editor_visible_spaces", &visible_tws },
343 { "editor_line_state", &option_line_state },
344 { "editor_simple_statusbar", &simple_statusbar },
345 { "editor_check_new_line", &option_check_nl_at_eof },
346 { "editor_show_right_margin", &show_right_margin },
347 { "editor_group_undo", &option_group_undo },
348 { "editor_state_full_filename", &option_state_full_filename },
349 #endif /* USE_INTERNAL_EDIT */
350 { "editor_ask_filename_before_edit", &editor_ask_filename_before_edit },
351 { "nice_rotating_dash", &nice_rotating_dash },
352 { "mcview_remember_file_position", &mcview_remember_file_position },
353 { "auto_fill_mkdir_name", &auto_fill_mkdir_name },
354 { "copymove_persistent_attr", &copymove_persistent_attr },
355 { NULL, NULL }
358 static const struct
360 const char *opt_name;
361 int *opt_addr;
362 } int_options [] = {
363 { "pause_after_run", &pause_after_run },
364 { "mouse_repeat_rate", &mou_auto_repeat },
365 { "double_click_speed", &double_click_speed },
366 { "old_esc_mode_timeout", &old_esc_mode_timeout },
367 { "max_dirt_limit", &mcview_max_dirt_limit },
368 { "num_history_items_recorded", &num_history_items_recorded },
369 #ifdef ENABLE_VFS
370 { "vfs_timeout", &vfs_timeout },
371 #ifdef ENABLE_VFS_FTP
372 { "ftpfs_directory_timeout", &ftpfs_directory_timeout },
373 { "ftpfs_retry_seconds", &ftpfs_retry_seconds },
374 #endif /* ENABLE_VFS_FTP */
375 #ifdef ENABLE_VFS_FISH
376 { "fish_directory_timeout", &fish_directory_timeout },
377 #endif /* ENABLE_VFS_FISH */
378 #endif /* ENABLE_VFS */
379 /* option_tab_spacing is used in internal viewer */
380 { "editor_tab_spacing", &option_tab_spacing },
381 #ifdef USE_INTERNAL_EDIT
382 { "editor_word_wrap_line_length", &option_word_wrap_line_length },
383 { "editor_option_save_mode", &option_save_mode },
384 #endif /* USE_INTERNAL_EDIT */
385 { NULL, NULL }
388 static const struct
390 const char *opt_name;
391 char **opt_addr;
392 const char *opt_defval;
393 } str_options[] = {
394 #ifdef USE_INTERNAL_EDIT
395 { "editor_backup_extension", &option_backup_ext, "~" },
396 { "editor_filesize_threshold", &option_filesize_threshold, "64M" },
397 { "editor_stop_format_chars", &option_stop_format_chars, "-+*\\,.;:&>" },
398 #endif
399 { "mcview_eof", &mcview_show_eof, "" },
400 { NULL, NULL, NULL }
403 static const struct
405 const char *opt_name;
406 gboolean *opt_addr;
407 } panels_ini_options[] = {
408 { "show_mini_info", &panels_options.show_mini_info },
409 { "kilobyte_si", &panels_options.kilobyte_si },
410 { "mix_all_files", &panels_options.mix_all_files },
411 { "show_backups", &panels_options.show_backups },
412 { "show_dot_files", &panels_options.show_dot_files },
413 { "fast_reload", &panels_options.fast_reload },
414 { "fast_reload_msg_shown", &panels_options.fast_reload_msg_shown },
415 { "mark_moves_down", &panels_options.mark_moves_down },
416 { "reverse_files_only", &panels_options.reverse_files_only },
417 { "auto_save_setup_panels", &panels_options.auto_save_setup },
418 { "navigate_with_arrows", &panels_options.navigate_with_arrows },
419 { "panel_scroll_pages", &panels_options.scroll_pages },
420 { "panel_scroll_center", &panels_options.scroll_center },
421 { "mouse_move_pages", &panels_options.mouse_move_pages },
422 { "filetype_mode", &panels_options.filetype_mode },
423 { "permission_mode", &panels_options.permission_mode },
424 { "torben_fj_mode", &panels_options.torben_fj_mode },
425 { NULL, NULL }
427 /* *INDENT-ON* */
429 /*** file scope functions ************************************************************************/
430 /* --------------------------------------------------------------------------------------------- */
433 * Get name of config file.
435 * @param subdir If not NULL, config is also searched in specified subdir.
436 * @param config_file_name If relative, file if searched in standard paths.
438 * @return newly allocated string with config name or NULL if file is not found.
441 static char *
442 load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
445 TODO: IMHO, in future, this function shall be placed in mcconfig module.
447 char *lc_basename, *ret;
448 char *file_name;
450 if (config_file_name == NULL)
451 return NULL;
453 /* check for .keymap suffix */
454 if (g_str_has_suffix (config_file_name, ".keymap"))
455 file_name = g_strdup (config_file_name);
456 else
457 file_name = g_strconcat (config_file_name, ".keymap", (char *) NULL);
459 canonicalize_pathname (file_name);
461 if (g_path_is_absolute (file_name))
462 return file_name;
464 lc_basename = g_path_get_basename (file_name);
465 g_free (file_name);
467 if (lc_basename == NULL)
468 return NULL;
470 if (subdir != NULL)
471 ret = g_build_filename (mc_config_get_path (), subdir, lc_basename, (char *) NULL);
472 else
473 ret = g_build_filename (mc_config_get_path (), lc_basename, (char *) NULL);
475 if (exist_file (ret))
477 g_free (lc_basename);
478 canonicalize_pathname (ret);
479 return ret;
481 g_free (ret);
483 if (subdir != NULL)
484 ret = g_build_filename (mc_global.sysconfig_dir, subdir, lc_basename, (char *) NULL);
485 else
486 ret = g_build_filename (mc_global.sysconfig_dir, lc_basename, (char *) NULL);
488 if (exist_file (ret))
490 g_free (lc_basename);
491 canonicalize_pathname (ret);
492 return ret;
494 g_free (ret);
496 if (subdir != NULL)
497 ret = g_build_filename (mc_global.share_data_dir, subdir, lc_basename, (char *) NULL);
498 else
499 ret = g_build_filename (mc_global.share_data_dir, lc_basename, (char *) NULL);
501 g_free (lc_basename);
503 if (exist_file (ret))
505 canonicalize_pathname (ret);
506 return ret;
509 g_free (ret);
510 return NULL;
513 /* --------------------------------------------------------------------------------------------- */
515 static const char *
516 setup__is_cfg_group_must_panel_config (const char *grp)
518 return (!strcasecmp ("Dirs", grp) ||
519 !strcasecmp ("Temporal:New Right Panel", grp) ||
520 !strcasecmp ("Temporal:New Left Panel", grp) ||
521 !strcasecmp ("New Left Panel", grp) || !strcasecmp ("New Right Panel", grp))
522 ? grp : NULL;
525 /* --------------------------------------------------------------------------------------------- */
527 static void
528 setup__move_panels_config_into_separate_file (const char *profile)
530 mc_config_t *tmp_cfg;
531 char **groups, **curr_grp;
533 if (!exist_file (profile))
534 return;
536 tmp_cfg = mc_config_init (profile, FALSE);
537 if (tmp_cfg == NULL)
538 return;
540 groups = mc_config_get_groups (tmp_cfg, NULL);
541 if (*groups == NULL)
543 g_strfreev (groups);
544 mc_config_deinit (tmp_cfg);
545 return;
548 for (curr_grp = groups; *curr_grp != NULL; curr_grp++)
549 if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL)
550 mc_config_del_group (tmp_cfg, *curr_grp);
552 mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
553 mc_config_deinit (tmp_cfg);
555 tmp_cfg = mc_config_init (profile, FALSE);
556 if (tmp_cfg == NULL)
558 g_strfreev (groups);
559 return;
562 for (curr_grp = groups; *curr_grp != NULL; curr_grp++)
564 const char *need_grp;
566 need_grp = setup__is_cfg_group_must_panel_config (*curr_grp);
567 if (need_grp != NULL)
568 mc_config_del_group (tmp_cfg, need_grp);
570 g_strfreev (groups);
572 mc_config_save_file (tmp_cfg, NULL);
573 mc_config_deinit (tmp_cfg);
576 /* --------------------------------------------------------------------------------------------- */
578 Create new mc_config object from specified ini-file or
579 append data to existing mc_config object from ini-file
582 static void
583 load_setup_init_config_from_file (mc_config_t ** config, const char *fname, gboolean read_only)
586 TODO: IMHO, in future, this function shall be placed in mcconfig module.
588 if (exist_file (fname))
590 if (*config != NULL)
591 mc_config_read_file (*config, fname, read_only, TRUE);
592 else
593 *config = mc_config_init (fname, read_only);
597 /* --------------------------------------------------------------------------------------------- */
599 static void
600 load_config (void)
602 size_t i;
603 const char *kt;
605 /* Load boolean options */
606 for (i = 0; bool_options[i].opt_name != NULL; i++)
607 *bool_options[i].opt_addr =
608 mc_config_get_bool (mc_global.main_config, CONFIG_APP_SECTION, bool_options[i].opt_name,
609 *bool_options[i].opt_addr);
611 /* Load integer options */
612 for (i = 0; int_options[i].opt_name != NULL; i++)
613 *int_options[i].opt_addr =
614 mc_config_get_int (mc_global.main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
615 *int_options[i].opt_addr);
617 /* Load string options */
618 for (i = 0; str_options[i].opt_name != NULL; i++)
619 *str_options[i].opt_addr =
620 mc_config_get_string (mc_global.main_config, CONFIG_APP_SECTION,
621 str_options[i].opt_name, str_options[i].opt_defval);
623 /* Overwrite some options */
624 #ifdef USE_INTERNAL_EDIT
625 if (option_word_wrap_line_length <= 0)
626 option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
627 #else
628 /* Reset forced in case of build without internal editor */
629 use_internal_edit = FALSE;
630 #endif /* USE_INTERNAL_EDIT */
632 if (option_tab_spacing <= 0)
633 option_tab_spacing = DEFAULT_TAB_SPACING;
635 kt = getenv ("KEYBOARD_KEY_TIMEOUT_US");
636 if (kt != NULL && kt[0] != '\0')
637 old_esc_mode_timeout = atoi (kt);
640 /* --------------------------------------------------------------------------------------------- */
642 static panel_view_mode_t
643 setup__load_panel_state (const char *section)
645 char *buffer;
646 size_t i;
647 panel_view_mode_t mode = view_listing;
649 /* Load the display mode */
650 buffer = mc_config_get_string (mc_global.panels_config, section, "display", "listing");
652 for (i = 0; panel_types[i].opt_name != NULL; i++)
653 if (g_ascii_strcasecmp (panel_types[i].opt_name, buffer) == 0)
655 mode = panel_types[i].opt_type;
656 break;
659 g_free (buffer);
661 return mode;
664 /* --------------------------------------------------------------------------------------------- */
666 static void
667 load_layout (void)
669 size_t i;
670 int equal_split;
671 int first_panel_size;
673 /* legacy options */
674 panels_layout.horizontal_split = mc_config_get_int (mc_global.main_config, CONFIG_APP_SECTION,
675 "horizontal_split", 0);
676 equal_split = mc_config_get_int (mc_global.main_config, "Layout", "equal_split", 1);
677 first_panel_size = mc_config_get_int (mc_global.main_config, "Layout", "first_panel_size", 1);
678 if (panels_layout.horizontal_split)
680 panels_layout.horizontal_equal = equal_split;
681 panels_layout.left_panel_size = first_panel_size;
683 else
685 panels_layout.vertical_equal = equal_split;
686 panels_layout.top_panel_size = first_panel_size;
689 /* actual options override legacy ones */
690 for (i = 0; layout[i].opt_name != NULL; i++)
691 *layout[i].opt_addr = mc_config_get_int (mc_global.main_config, CONFIG_LAYOUT_SECTION,
692 layout[i].opt_name, *layout[i].opt_addr);
694 /* remove legacy options */
695 mc_config_del_key (mc_global.main_config, CONFIG_APP_SECTION, "horizontal_split");
696 mc_config_del_key (mc_global.main_config, "Layout", "equal_split");
697 mc_config_del_key (mc_global.main_config, "Layout", "first_panel_size");
699 startup_left_mode = setup__load_panel_state ("New Left Panel");
700 startup_right_mode = setup__load_panel_state ("New Right Panel");
702 /* At least one of the panels is a listing panel */
703 if (startup_left_mode != view_listing && startup_right_mode != view_listing)
704 startup_left_mode = view_listing;
706 boot_current_is_left =
707 mc_config_get_bool (mc_global.panels_config, "Dirs", "current_is_left", TRUE);
710 /* --------------------------------------------------------------------------------------------- */
712 static void
713 load_keys_from_section (const char *terminal, mc_config_t * cfg)
715 char *section_name;
716 gchar **profile_keys, **keys;
717 char *valcopy, *value;
718 long key_code;
720 if (terminal == NULL)
721 return;
723 section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
724 keys = mc_config_get_keys (cfg, section_name, NULL);
726 for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
728 /* copy=other causes all keys from [terminal:other] to be loaded. */
729 if (g_ascii_strcasecmp (*profile_keys, "copy") == 0)
731 valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
732 load_keys_from_section (valcopy, cfg);
733 g_free (valcopy);
734 continue;
737 key_code = lookup_key (*profile_keys, NULL);
738 if (key_code != 0)
740 gchar **values;
742 values = mc_config_get_string_list (cfg, section_name, *profile_keys, NULL);
743 if (values != NULL)
745 gchar **curr_values;
747 for (curr_values = values; *curr_values != NULL; curr_values++)
749 valcopy = convert_controls (*curr_values);
750 define_sequence (key_code, valcopy, MCKEY_NOACTION);
751 g_free (valcopy);
754 g_strfreev (values);
756 else
758 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
759 valcopy = convert_controls (value);
760 define_sequence (key_code, valcopy, MCKEY_NOACTION);
761 g_free (valcopy);
762 g_free (value);
766 g_strfreev (keys);
767 g_free (section_name);
770 /* --------------------------------------------------------------------------------------------- */
772 static void
773 load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg)
775 gchar **profile_keys, **keys;
777 if (section_name == NULL)
778 return;
780 keys = mc_config_get_keys (cfg, section_name, NULL);
782 for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
784 gchar **values;
786 values = mc_config_get_string_list (cfg, section_name, *profile_keys, NULL);
787 if (values != NULL)
789 long action;
791 action = keybind_lookup_action (*profile_keys);
792 if (action > 0)
794 gchar **curr_values;
796 for (curr_values = values; *curr_values != NULL; curr_values++)
797 keybind_cmd_bind (keymap, *curr_values, action);
800 g_strfreev (values);
804 g_strfreev (keys);
807 /* --------------------------------------------------------------------------------------------- */
809 static mc_config_t *
810 load_setup_get_keymap_profile_config (gboolean load_from_file)
813 TODO: IMHO, in future, this function shall be placed in mcconfig module.
815 mc_config_t *keymap_config;
816 char *share_keymap, *sysconfig_keymap;
817 char *fname, *fname2;
819 /* 0) Create default keymap */
820 keymap_config = create_default_keymap ();
821 if (!load_from_file)
822 return keymap_config;
824 /* load and merge global keymaps */
826 /* 1) /usr/share/mc (mc_global.share_data_dir) */
827 share_keymap = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, (char *) NULL);
828 load_setup_init_config_from_file (&keymap_config, share_keymap, TRUE);
830 /* 2) /etc/mc (mc_global.sysconfig_dir) */
831 sysconfig_keymap =
832 g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, (char *) NULL);
833 load_setup_init_config_from_file (&keymap_config, sysconfig_keymap, TRUE);
835 /* then load and merge one of user-defined keymap */
837 /* 3) --keymap=<keymap> */
838 fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file);
839 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
841 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
842 goto done;
844 g_free (fname);
846 /* 4) getenv("MC_KEYMAP") */
847 fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
848 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
850 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
851 goto done;
853 g_free (fname);
855 /* 5) main config; [Midnight Commander] -> keymap */
856 fname2 = mc_config_get_string (mc_global.main_config, CONFIG_APP_SECTION, "keymap", NULL);
857 if (fname2 != NULL && *fname2 != '\0')
858 fname = load_setup_get_full_config_name (NULL, fname2);
859 g_free (fname2);
860 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
862 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
863 goto done;
865 g_free (fname);
867 /* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */
868 fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE);
869 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
871 done:
872 g_free (fname);
873 g_free (sysconfig_keymap);
874 g_free (share_keymap);
876 return keymap_config;
879 /* --------------------------------------------------------------------------------------------- */
881 static void
882 panel_save_type (const char *section, panel_view_mode_t type)
884 size_t i;
886 for (i = 0; panel_types[i].opt_name != NULL; i++)
887 if (panel_types[i].opt_type == type)
889 mc_config_set_string (mc_global.panels_config, section, "display",
890 panel_types[i].opt_name);
891 break;
895 /* --------------------------------------------------------------------------------------------- */
898 * Load panels options from [Panels] section.
900 static void
901 panels_load_options (void)
903 if (mc_config_has_group (mc_global.main_config, CONFIG_PANELS_SECTION))
905 size_t i;
906 int qmode;
908 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
909 *panels_ini_options[i].opt_addr =
910 mc_config_get_bool (mc_global.main_config, CONFIG_PANELS_SECTION,
911 panels_ini_options[i].opt_name,
912 *panels_ini_options[i].opt_addr);
914 qmode = mc_config_get_int (mc_global.main_config, CONFIG_PANELS_SECTION,
915 "quick_search_mode", (int) panels_options.qsearch_mode);
916 if (qmode < 0)
917 panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE;
918 else if (qmode >= QSEARCH_NUM)
919 panels_options.qsearch_mode = QSEARCH_PANEL_CASE;
920 else
921 panels_options.qsearch_mode = (qsearch_mode_t) qmode;
923 panels_options.select_flags =
924 mc_config_get_int (mc_global.main_config, CONFIG_PANELS_SECTION, "select_flags",
925 (int) panels_options.select_flags);
929 /* --------------------------------------------------------------------------------------------- */
932 * Save panels options in [Panels] section.
934 static void
935 panels_save_options (void)
937 size_t i;
939 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
940 mc_config_set_bool (mc_global.main_config, CONFIG_PANELS_SECTION,
941 panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr);
943 mc_config_set_int (mc_global.main_config, CONFIG_PANELS_SECTION,
944 "quick_search_mode", (int) panels_options.qsearch_mode);
945 mc_config_set_int (mc_global.main_config, CONFIG_PANELS_SECTION,
946 "select_flags", (int) panels_options.select_flags);
949 /* --------------------------------------------------------------------------------------------- */
951 static void
952 save_config (void)
954 size_t i;
956 /* Save boolean options */
957 for (i = 0; bool_options[i].opt_name != NULL; i++)
958 mc_config_set_bool (mc_global.main_config, CONFIG_APP_SECTION, bool_options[i].opt_name,
959 *bool_options[i].opt_addr);
961 /* Save integer options */
962 for (i = 0; int_options[i].opt_name != NULL; i++)
963 mc_config_set_int (mc_global.main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
964 *int_options[i].opt_addr);
966 /* Save string options */
967 for (i = 0; str_options[i].opt_name != NULL; i++)
968 mc_config_set_string (mc_global.main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
969 *str_options[i].opt_addr);
972 /* --------------------------------------------------------------------------------------------- */
974 static void
975 save_layout (void)
977 size_t i;
979 /* Save integer options */
980 for (i = 0; layout[i].opt_name != NULL; i++)
981 mc_config_set_int (mc_global.main_config, CONFIG_LAYOUT_SECTION, layout[i].opt_name,
982 *layout[i].opt_addr);
985 /* --------------------------------------------------------------------------------------------- */
987 /* save panels.ini */
988 static void
989 save_panel_types (void)
991 panel_view_mode_t type;
993 if (mc_global.mc_run_mode != MC_RUN_FULL)
994 return;
996 type = get_display_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_display_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);
1006 char *dirs;
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);
1013 if (current_panel != NULL)
1014 mc_config_set_bool (mc_global.panels_config, "Dirs", "current_is_left",
1015 get_current_index () == 0);
1017 if (mc_global.panels_config->ini_path == NULL)
1018 mc_global.panels_config->ini_path = g_strdup (panels_profile_name);
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");
1023 mc_config_save_file (mc_global.panels_config, NULL);
1026 /* --------------------------------------------------------------------------------------------- */
1027 /*** public functions ****************************************************************************/
1028 /* --------------------------------------------------------------------------------------------- */
1030 const char *
1031 setup_init (void)
1033 if (profile_name == NULL)
1035 char *profile;
1037 profile = mc_config_get_full_path (MC_CONFIG_FILE);
1038 if (!exist_file (profile))
1040 char *inifile;
1042 inifile = mc_build_filename (mc_global.sysconfig_dir, "mc.ini", (char *) NULL);
1043 if (exist_file (inifile))
1045 g_free (profile);
1046 profile = inifile;
1048 else
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
1056 g_free (profile);
1057 profile = inifile;
1062 profile_name = profile;
1065 return profile_name;
1068 /* --------------------------------------------------------------------------------------------- */
1070 void
1071 load_setup (void)
1073 const char *profile;
1075 #ifdef HAVE_CHARSET
1076 char *buffer;
1077 const char *cbuffer;
1079 load_codepages_list ();
1080 #endif /* HAVE_CHARSET */
1082 profile = setup_init ();
1084 /* mc.lib is common for all users, but has priority lower than
1085 ${XDG_CONFIG_HOME}/mc/ini. FIXME: it's only used for keys and treestore now */
1086 global_profile_name =
1087 g_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
1088 if (!exist_file (global_profile_name))
1090 g_free (global_profile_name);
1091 global_profile_name =
1092 g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
1095 panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE);
1097 mc_global.main_config = mc_config_init (profile, FALSE);
1099 if (!exist_file (panels_profile_name))
1100 setup__move_panels_config_into_separate_file (profile);
1102 mc_global.panels_config = mc_config_init (panels_profile_name, FALSE);
1104 load_config ();
1105 load_layout ();
1106 panels_load_options ();
1107 load_panelize ();
1109 /* Load time formats */
1110 user_recent_timeformat =
1111 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "timeformat_recent",
1112 FMTTIME);
1113 user_old_timeformat =
1114 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "timeformat_old",
1115 FMTYEAR);
1117 #ifdef ENABLE_VFS_FTP
1118 ftpfs_proxy_host =
1119 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftp_proxy_host", "gate");
1120 ftpfs_init_passwd ();
1121 #endif /* ENABLE_VFS_FTP */
1123 /* The default color and the terminal dependent color */
1124 mc_global.tty.setup_color_string =
1125 mc_config_get_string (mc_global.main_config, "Colors", "base_color", "");
1126 mc_global.tty.term_color_string =
1127 mc_config_get_string (mc_global.main_config, "Colors", getenv ("TERM"), "");
1128 mc_global.tty.color_terminal_string =
1129 mc_config_get_string (mc_global.main_config, "Colors", "color_terminals", "");
1131 /* Load the directory history */
1132 /* directory_history_load (); */
1133 /* Remove the temporal entries */
1135 #ifdef HAVE_CHARSET
1136 if (codepages->len > 1)
1138 buffer =
1139 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "display_codepage",
1140 "");
1141 if (buffer[0] != '\0')
1143 mc_global.display_codepage = get_codepage_index (buffer);
1144 cp_display = get_codepage_id (mc_global.display_codepage);
1146 g_free (buffer);
1147 buffer =
1148 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "source_codepage",
1149 "");
1150 if (buffer[0] != '\0')
1152 default_source_codepage = get_codepage_index (buffer);
1153 mc_global.source_codepage = default_source_codepage; /* May be source_codepage doesn't need this */
1154 cp_source = get_codepage_id (mc_global.source_codepage);
1156 g_free (buffer);
1159 autodetect_codeset =
1160 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "autodetect_codeset", "");
1161 if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off") != 0))
1162 is_autodetect_codeset_enabled = TRUE;
1164 g_free (init_translation_table (mc_global.source_codepage, mc_global.display_codepage));
1165 cbuffer = get_codepage_id (mc_global.display_codepage);
1166 if (cbuffer != NULL)
1167 mc_global.utf8_display = str_isutf8 (cbuffer);
1168 #endif /* HAVE_CHARSET */
1170 #ifdef HAVE_ASPELL
1171 spell_language =
1172 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "spell_language", "en");
1173 #endif /* HAVE_ASPELL */
1175 clipboard_store_path =
1176 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_store", "");
1177 clipboard_paste_path =
1178 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_paste", "");
1181 /* --------------------------------------------------------------------------------------------- */
1183 gboolean
1184 save_setup (gboolean save_options, gboolean save_panel_options)
1186 gboolean ret = TRUE;
1188 saving_setup = 1;
1190 save_hotlist ();
1192 if (save_panel_options)
1193 save_panel_types ();
1195 if (save_options)
1197 char *tmp_profile;
1199 save_config ();
1200 save_layout ();
1201 panels_save_options ();
1202 save_panelize ();
1203 /* directory_history_save (); */
1205 #ifdef ENABLE_VFS_FTP
1206 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftpfs_password",
1207 ftpfs_anonymous_passwd);
1208 if (ftpfs_proxy_host)
1209 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftp_proxy_host",
1210 ftpfs_proxy_host);
1211 #endif /* ENABLE_VFS_FTP */
1213 #ifdef HAVE_CHARSET
1214 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "display_codepage",
1215 get_codepage_id (mc_global.display_codepage));
1216 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "source_codepage",
1217 get_codepage_id (default_source_codepage));
1218 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "autodetect_codeset",
1219 autodetect_codeset);
1220 #endif /* HAVE_CHARSET */
1222 #ifdef HAVE_ASPELL
1223 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "spell_language",
1224 spell_language);
1225 #endif /* HAVE_ASPELL */
1227 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_store",
1228 clipboard_store_path);
1229 mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_paste",
1230 clipboard_paste_path);
1232 tmp_profile = mc_config_get_full_path (MC_CONFIG_FILE);
1233 ret = mc_config_save_to_file (mc_global.main_config, tmp_profile, NULL);
1234 g_free (tmp_profile);
1237 saving_setup = 0;
1239 return ret;
1242 /* --------------------------------------------------------------------------------------------- */
1244 void
1245 done_setup (void)
1247 size_t i;
1249 g_free (clipboard_store_path);
1250 g_free (clipboard_paste_path);
1251 g_free (global_profile_name);
1252 g_free (mc_global.tty.color_terminal_string);
1253 g_free (mc_global.tty.term_color_string);
1254 g_free (mc_global.tty.setup_color_string);
1255 g_free (profile_name);
1256 g_free (panels_profile_name);
1257 mc_config_deinit (mc_global.main_config);
1258 mc_config_deinit (mc_global.panels_config);
1260 g_free (user_recent_timeformat);
1261 g_free (user_old_timeformat);
1263 for (i = 0; str_options[i].opt_name != NULL; i++)
1264 g_free (*str_options[i].opt_addr);
1266 done_hotlist ();
1267 done_panelize ();
1268 /* directory_history_free (); */
1270 #ifdef HAVE_CHARSET
1271 g_free (autodetect_codeset);
1272 free_codepages_list ();
1273 #endif
1275 #ifdef HAVE_ASPELL
1276 g_free (spell_language);
1277 #endif /* HAVE_ASPELL */
1281 /* --------------------------------------------------------------------------------------------- */
1283 void
1284 setup_save_config_show_error (const char *filename, GError ** mcerror)
1286 if (mcerror != NULL && *mcerror != NULL)
1288 message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*mcerror)->message);
1289 g_error_free (*mcerror);
1290 *mcerror = NULL;
1295 /* --------------------------------------------------------------------------------------------- */
1297 void
1298 load_key_defs (void)
1301 * Load keys from mc.lib before ${XDG_CONFIG_HOME}/mc/ini, so that the user
1302 * definitions override global settings.
1304 mc_config_t *mc_global_config;
1306 mc_global_config = mc_config_init (global_profile_name, FALSE);
1307 if (mc_global_config != NULL)
1309 load_keys_from_section ("general", mc_global_config);
1310 load_keys_from_section (getenv ("TERM"), mc_global_config);
1311 mc_config_deinit (mc_global_config);
1314 load_keys_from_section ("general", mc_global.main_config);
1315 load_keys_from_section (getenv ("TERM"), mc_global.main_config);
1318 /* --------------------------------------------------------------------------------------------- */
1320 #ifdef ENABLE_VFS_FTP
1321 char *
1322 load_anon_passwd (void)
1324 char *buffer;
1326 buffer =
1327 mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "ftpfs_password", "");
1329 if ((buffer != NULL) && (buffer[0] != '\0'))
1330 return buffer;
1332 g_free (buffer);
1333 return NULL;
1335 #endif /* ENABLE_VFS_FTP */
1337 /* --------------------------------------------------------------------------------------------- */
1339 void
1340 load_keymap_defs (gboolean load_from_file)
1343 * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_CONFIG_HOME}/mc/mc.keymap, so that the user
1344 * definitions override global settings.
1346 mc_config_t *mc_global_keymap;
1348 mc_global_keymap = load_setup_get_keymap_profile_config (load_from_file);
1350 if (mc_global_keymap != NULL)
1352 main_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1353 load_keymap_from_section (KEYMAP_SECTION_MAIN, main_keymap, mc_global_keymap);
1354 main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1355 load_keymap_from_section (KEYMAP_SECTION_MAIN_EXT, main_x_keymap, mc_global_keymap);
1357 panel_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1358 load_keymap_from_section (KEYMAP_SECTION_PANEL, panel_keymap, mc_global_keymap);
1360 dialog_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1361 load_keymap_from_section (KEYMAP_SECTION_DIALOG, dialog_keymap, mc_global_keymap);
1363 input_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1364 load_keymap_from_section (KEYMAP_SECTION_INPUT, input_keymap, mc_global_keymap);
1366 listbox_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1367 load_keymap_from_section (KEYMAP_SECTION_LISTBOX, listbox_keymap, mc_global_keymap);
1369 tree_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1370 load_keymap_from_section (KEYMAP_SECTION_TREE, tree_keymap, mc_global_keymap);
1372 help_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1373 load_keymap_from_section (KEYMAP_SECTION_HELP, help_keymap, mc_global_keymap);
1375 #ifdef USE_INTERNAL_EDIT
1376 editor_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1377 load_keymap_from_section (KEYMAP_SECTION_EDITOR, editor_keymap, mc_global_keymap);
1378 editor_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1379 load_keymap_from_section (KEYMAP_SECTION_EDITOR_EXT, editor_x_keymap, mc_global_keymap);
1380 #endif
1382 viewer_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1383 load_keymap_from_section (KEYMAP_SECTION_VIEWER, viewer_keymap, mc_global_keymap);
1384 viewer_hex_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1385 load_keymap_from_section (KEYMAP_SECTION_VIEWER_HEX, viewer_hex_keymap, mc_global_keymap);
1387 #ifdef USE_DIFF_VIEW
1388 diff_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1389 load_keymap_from_section (KEYMAP_SECTION_DIFFVIEWER, diff_keymap, mc_global_keymap);
1390 #endif
1392 mc_config_deinit (mc_global_keymap);
1395 main_map = (global_keymap_t *) main_keymap->data;
1396 main_x_map = (global_keymap_t *) main_x_keymap->data;
1397 panel_map = (global_keymap_t *) panel_keymap->data;
1398 dialog_map = (global_keymap_t *) dialog_keymap->data;
1399 input_map = (global_keymap_t *) input_keymap->data;
1400 listbox_map = (global_keymap_t *) listbox_keymap->data;
1401 tree_map = (global_keymap_t *) tree_keymap->data;
1402 help_map = (global_keymap_t *) help_keymap->data;
1403 #ifdef USE_INTERNAL_EDIT
1404 editor_map = (global_keymap_t *) editor_keymap->data;
1405 editor_x_map = (global_keymap_t *) editor_x_keymap->data;
1406 #endif
1407 viewer_map = (global_keymap_t *) viewer_keymap->data;
1408 viewer_hex_map = (global_keymap_t *) viewer_hex_keymap->data;
1409 #ifdef USE_DIFF_VIEW
1410 diff_map = (global_keymap_t *) diff_keymap->data;
1411 #endif
1414 /* --------------------------------------------------------------------------------------------- */
1416 void
1417 free_keymap_defs (void)
1419 if (main_keymap != NULL)
1420 g_array_free (main_keymap, TRUE);
1421 if (main_x_keymap != NULL)
1422 g_array_free (main_x_keymap, TRUE);
1423 if (panel_keymap != NULL)
1424 g_array_free (panel_keymap, TRUE);
1425 if (dialog_keymap != NULL)
1426 g_array_free (dialog_keymap, TRUE);
1427 if (input_keymap != NULL)
1428 g_array_free (input_keymap, TRUE);
1429 if (listbox_keymap != NULL)
1430 g_array_free (listbox_keymap, TRUE);
1431 if (tree_keymap != NULL)
1432 g_array_free (tree_keymap, TRUE);
1433 if (help_keymap != NULL)
1434 g_array_free (help_keymap, TRUE);
1435 #ifdef USE_INTERNAL_EDIT
1436 if (editor_keymap != NULL)
1437 g_array_free (editor_keymap, TRUE);
1438 if (editor_x_keymap != NULL)
1439 g_array_free (editor_x_keymap, TRUE);
1440 #endif
1441 if (viewer_keymap != NULL)
1442 g_array_free (viewer_keymap, TRUE);
1443 if (viewer_hex_keymap != NULL)
1444 g_array_free (viewer_hex_keymap, TRUE);
1445 #ifdef USE_DIFF_VIEW
1446 if (diff_keymap != NULL)
1447 g_array_free (diff_keymap, TRUE);
1448 #endif
1451 /* --------------------------------------------------------------------------------------------- */
1453 void
1454 panel_load_setup (WPanel * panel, const char *section)
1456 size_t i;
1457 char *buffer, buffer2[BUF_TINY];
1459 panel->sort_info.reverse = mc_config_get_int (mc_global.panels_config, section, "reverse", 0);
1460 panel->sort_info.case_sensitive =
1461 mc_config_get_int (mc_global.panels_config, section, "case_sensitive",
1462 OS_SORT_CASE_SENSITIVE_DEFAULT);
1463 panel->sort_info.exec_first =
1464 mc_config_get_int (mc_global.panels_config, section, "exec_first", 0);
1466 /* Load sort order */
1467 buffer = mc_config_get_string (mc_global.panels_config, section, "sort_order", "name");
1468 panel->sort_field = panel_get_field_by_id (buffer);
1469 if (panel->sort_field == NULL)
1470 panel->sort_field = panel_get_field_by_id ("name");
1472 g_free (buffer);
1474 /* Load the listing mode */
1475 buffer = mc_config_get_string (mc_global.panels_config, section, "list_mode", "full");
1476 panel->list_type = list_full;
1477 for (i = 0; list_types[i].key != NULL; i++)
1478 if (g_ascii_strcasecmp (list_types[i].key, buffer) == 0)
1480 panel->list_type = list_types[i].list_type;
1481 break;
1483 g_free (buffer);
1485 panel->brief_cols = mc_config_get_int (mc_global.panels_config, section, "brief_cols", 2);
1487 /* User formats */
1488 g_free (panel->user_format);
1489 panel->user_format =
1490 mc_config_get_string (mc_global.panels_config, section, "user_format", DEFAULT_USER_FORMAT);
1492 for (i = 0; i < LIST_TYPES; i++)
1494 g_free (panel->user_status_format[i]);
1495 g_snprintf (buffer2, sizeof (buffer2), "user_status%lld", (long long) i);
1496 panel->user_status_format[i] =
1497 mc_config_get_string (mc_global.panels_config, section, buffer2, DEFAULT_USER_FORMAT);
1500 panel->user_mini_status =
1501 mc_config_get_bool (mc_global.panels_config, section, "user_mini_status", FALSE);
1504 /* --------------------------------------------------------------------------------------------- */
1506 void
1507 panel_save_setup (WPanel * panel, const char *section)
1509 char buffer[BUF_TINY];
1510 size_t i;
1512 mc_config_set_int (mc_global.panels_config, section, "reverse", panel->sort_info.reverse);
1513 mc_config_set_int (mc_global.panels_config, section, "case_sensitive",
1514 panel->sort_info.case_sensitive);
1515 mc_config_set_int (mc_global.panels_config, section, "exec_first", panel->sort_info.exec_first);
1517 mc_config_set_string (mc_global.panels_config, section, "sort_order", panel->sort_field->id);
1519 for (i = 0; list_types[i].key != NULL; i++)
1520 if (list_types[i].list_type == (int) panel->list_type)
1522 mc_config_set_string (mc_global.panels_config, section, "list_mode", list_types[i].key);
1523 break;
1526 mc_config_set_int (mc_global.panels_config, section, "brief_cols", panel->brief_cols);
1528 mc_config_set_string (mc_global.panels_config, section, "user_format", panel->user_format);
1530 for (i = 0; i < LIST_TYPES; i++)
1532 g_snprintf (buffer, sizeof (buffer), "user_status%lld", (long long) i);
1533 mc_config_set_string (mc_global.panels_config, section, buffer,
1534 panel->user_status_format[i]);
1537 mc_config_set_bool (mc_global.panels_config, section, "user_mini_status",
1538 panel->user_mini_status);
1541 /* --------------------------------------------------------------------------------------------- */