Indentation.
[midnight-commander.git] / src / setup.c
blob542d16c75b9045a88a467ee23086d2200c5476f9
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 /* index to record_macro_buf[], -1 if not recording a macro */
207 int macro_index = -1;
209 /* macro stuff */
210 struct macro_action_t record_macro_buf[MAX_MACRO_LENGTH];
212 GArray *macros_list;
214 /*** file scope macro definitions ****************************************************************/
216 /* In order to use everywhere the same setup for the locale we use defines */
217 #define FMTYEAR _("%b %e %Y")
218 #define FMTTIME _("%b %e %H:%M")
220 /*** file scope type declarations ****************************************************************/
222 /*** file scope variables ************************************************************************/
224 static char *profile_name = NULL; /* ${XDG_CONFIG_HOME}/mc/ini */
225 static char *panels_profile_name = NULL; /* ${XDG_CACHE_HOME}/mc/panels.ini */
227 /* *INDENT-OFF* */
228 static const struct
230 const char *key;
231 int list_type;
232 } list_types [] = {
233 { "full", list_full },
234 { "brief", list_brief },
235 { "long", list_long },
236 { "user", list_user },
237 { NULL, 0 }
240 static const struct
242 const char *opt_name;
243 panel_view_mode_t opt_type;
244 } panel_types [] = {
245 { "listing", view_listing },
246 { "quickview", view_quick },
247 { "info", view_info },
248 { "tree", view_tree },
249 { NULL, view_listing }
252 static const struct
254 const char *opt_name;
255 int *opt_addr;
256 } layout [] = {
257 { "message_visible", &mc_global.message_visible },
258 { "keybar_visible", &mc_global.keybar_visible },
259 { "xterm_title", &xterm_title },
260 { "output_lines", &output_lines },
261 { "command_prompt", &command_prompt },
262 { "menubar_visible", &menubar_visible },
263 { "free_space", &free_space },
264 { "horizontal_split", &panels_layout.horizontal_split },
265 { "vertical_equal", &panels_layout.vertical_equal },
266 { "left_panel_size", &panels_layout.left_panel_size },
267 { "horizontal_equal", &panels_layout.horizontal_equal },
268 { "top_panel_size", &panels_layout.top_panel_size },
269 { NULL, NULL }
272 static const struct
274 const char *opt_name;
275 int *opt_addr;
276 } int_options [] = {
277 { "verbose", &verbose },
278 { "pause_after_run", &pause_after_run },
279 { "shell_patterns", &easy_patterns },
280 { "auto_save_setup", &auto_save_setup },
281 { "preallocate_space", &mc_global.vfs.preallocate_space },
282 { "auto_menu", &auto_menu },
283 { "use_internal_view", &use_internal_view },
284 { "use_internal_edit", &use_internal_edit },
285 { "clear_before_exec", &clear_before_exec },
286 { "confirm_delete", &confirm_delete },
287 { "confirm_overwrite", &confirm_overwrite },
288 { "confirm_execute", &confirm_execute },
289 { "confirm_history_cleanup", &mc_global.widget.confirm_history_cleanup },
290 { "confirm_exit", &confirm_exit },
291 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete },
292 { "safe_delete", &safe_delete },
293 { "mouse_repeat_rate", &mou_auto_repeat },
294 { "double_click_speed", &double_click_speed },
295 #ifndef HAVE_CHARSET
296 { "eight_bit_clean", &mc_global.eight_bit_clean },
297 { "full_eight_bits", &mc_global.full_eight_bits },
298 #endif /* !HAVE_CHARSET */
299 { "use_8th_bit_as_meta", &use_8th_bit_as_meta },
300 { "confirm_view_dir", &confirm_view_dir },
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 { "old_esc_mode_timeout", &old_esc_mode_timeout },
308 { "cd_symlinks", &mc_global.vfs.cd_symlinks },
309 { "show_all_if_ambiguous", &mc_global.widget.show_all_if_ambiguous },
310 { "max_dirt_limit", &mcview_max_dirt_limit },
311 { "use_file_to_guess_type", &use_file_to_check_type },
312 { "alternate_plus_minus", &mc_global.tty.alternate_plus_minus },
313 { "only_leading_plus_minus", &only_leading_plus_minus },
314 { "show_output_starts_shell", &output_starts_shell },
315 { "xtree_mode", &xtree_mode },
316 { "num_history_items_recorded", &num_history_items_recorded },
317 { "file_op_compute_totals", &file_op_compute_totals },
318 { "classic_progressbar", &classic_progressbar},
319 #ifdef ENABLE_VFS
320 { "vfs_timeout", &vfs_timeout },
321 #ifdef ENABLE_VFS_FTP
322 { "ftpfs_directory_timeout", &ftpfs_directory_timeout },
323 { "use_netrc", &ftpfs_use_netrc },
324 { "ftpfs_retry_seconds", &ftpfs_retry_seconds },
325 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy },
326 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections },
327 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy },
328 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options },
329 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls },
330 #endif /* ENABLE_VFS_FTP */
331 #ifdef ENABLE_VFS_FISH
332 { "fish_directory_timeout", &fish_directory_timeout },
333 #endif /* ENABLE_VFS_FISH */
334 #endif /* ENABLE_VFS */
335 /* option_tab_spacing is used in internal viewer */
336 { "editor_tab_spacing", &option_tab_spacing },
337 #ifdef USE_INTERNAL_EDIT
338 { "editor_word_wrap_line_length", &option_word_wrap_line_length },
339 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces },
340 { "editor_return_does_auto_indent", &option_return_does_auto_indent },
341 { "editor_backspace_through_tabs", &option_backspace_through_tabs },
342 { "editor_fake_half_tabs", &option_fake_half_tabs },
343 { "editor_option_save_mode", &option_save_mode },
344 { "editor_option_save_position", &option_save_position },
345 { "editor_option_auto_para_formatting", &option_auto_para_formatting },
346 { "editor_option_typewriter_wrap", &option_typewriter_wrap },
347 { "editor_edit_confirm_save", &edit_confirm_save },
348 { "editor_syntax_highlighting", &option_syntax_highlighting },
349 { "editor_persistent_selections", &option_persistent_selections },
350 { "editor_drop_selection_on_copy", &option_drop_selection_on_copy },
351 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol },
352 { "editor_cursor_after_inserted_block", &option_cursor_after_inserted_block },
353 { "editor_visible_tabs", &visible_tabs },
354 { "editor_visible_spaces", &visible_tws },
355 { "editor_line_state", &option_line_state },
356 { "editor_simple_statusbar", &simple_statusbar },
357 { "editor_check_new_line", &option_check_nl_at_eof },
358 { "editor_show_right_margin", &show_right_margin },
359 { "editor_group_undo", &option_group_undo },
360 { "editor_state_full_filename", &option_state_full_filename },
361 #endif /* USE_INTERNAL_EDIT */
362 { "editor_ask_filename_before_edit", &editor_ask_filename_before_edit },
363 { "nice_rotating_dash", &nice_rotating_dash },
364 { "mcview_remember_file_position", &mcview_remember_file_position },
365 { "auto_fill_mkdir_name", &auto_fill_mkdir_name },
366 { "copymove_persistent_attr", &setup_copymove_persistent_attr },
367 { NULL, NULL }
370 static const struct
372 const char *opt_name;
373 char **opt_addr;
374 const char *opt_defval;
375 } str_options[] = {
376 #ifdef USE_INTERNAL_EDIT
377 { "editor_backup_extension", &option_backup_ext, "~" },
378 { "editor_filesize_threshold", &option_filesize_threshold, "64M" },
379 { "editor_stop_format_chars", &option_stop_format_chars, "-+*\\,.;:&>" },
380 #endif
381 { "mcview_eof", &mcview_show_eof, "" },
382 { NULL, NULL, NULL }
385 static const struct
387 const char *opt_name;
388 gboolean *opt_addr;
389 } panels_ini_options[] = {
390 { "show_mini_info", &panels_options.show_mini_info },
391 { "kilobyte_si", &panels_options.kilobyte_si },
392 { "mix_all_files", &panels_options.mix_all_files },
393 { "show_backups", &panels_options.show_backups },
394 { "show_dot_files", &panels_options.show_dot_files },
395 { "fast_reload", &panels_options.fast_reload },
396 { "fast_reload_msg_shown", &panels_options.fast_reload_msg_shown },
397 { "mark_moves_down", &panels_options.mark_moves_down },
398 { "reverse_files_only", &panels_options.reverse_files_only },
399 { "auto_save_setup_panels", &panels_options.auto_save_setup },
400 { "navigate_with_arrows", &panels_options.navigate_with_arrows },
401 { "panel_scroll_pages", &panels_options.scroll_pages },
402 { "mouse_move_pages", &panels_options.mouse_move_pages },
403 { "filetype_mode", &panels_options.filetype_mode },
404 { "permission_mode", &panels_options.permission_mode },
405 { "torben_fj_mode", &panels_options.torben_fj_mode },
406 { NULL, NULL }
408 /* *INDENT-ON* */
410 /*** file scope functions ************************************************************************/
411 /* --------------------------------------------------------------------------------------------- */
414 * Get name of config file.
416 * @param subdir If not NULL, config is also searched in specified subdir.
417 * @param config_file_name If relative, file if searched in standard paths.
419 * @return newly allocated string with config name or NULL if file is not found.
422 static char *
423 load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
426 TODO: IMHO, in future, this function shall be placed in mcconfig module.
428 char *lc_basename, *ret;
429 char *file_name;
431 if (config_file_name == NULL)
432 return NULL;
434 /* check for .keymap suffix */
435 if (g_str_has_suffix (config_file_name, ".keymap"))
436 file_name = g_strdup (config_file_name);
437 else
438 file_name = g_strconcat (config_file_name, ".keymap", (char *) NULL);
440 canonicalize_pathname (file_name);
442 if (g_path_is_absolute (file_name))
443 return file_name;
445 lc_basename = g_path_get_basename (file_name);
446 g_free (file_name);
448 if (lc_basename == NULL)
449 return NULL;
451 if (subdir != NULL)
452 ret = g_build_filename (mc_config_get_path (), subdir, lc_basename, NULL);
453 else
454 ret = g_build_filename (mc_config_get_path (), lc_basename, NULL);
456 if (exist_file (ret))
458 g_free (lc_basename);
459 canonicalize_pathname (ret);
460 return ret;
462 g_free (ret);
464 if (subdir != NULL)
465 ret = g_build_filename (mc_global.sysconfig_dir, subdir, lc_basename, NULL);
466 else
467 ret = g_build_filename (mc_global.sysconfig_dir, lc_basename, NULL);
469 if (exist_file (ret))
471 g_free (lc_basename);
472 canonicalize_pathname (ret);
473 return ret;
475 g_free (ret);
477 if (subdir != NULL)
478 ret = g_build_filename (mc_global.share_data_dir, subdir, lc_basename, NULL);
479 else
480 ret = g_build_filename (mc_global.share_data_dir, lc_basename, NULL);
482 g_free (lc_basename);
484 if (exist_file (ret))
486 canonicalize_pathname (ret);
487 return ret;
490 g_free (ret);
491 return NULL;
494 /* --------------------------------------------------------------------------------------------- */
496 static const char *
497 setup__is_cfg_group_must_panel_config (const char *grp)
499 return (!strcasecmp ("Dirs", grp) ||
500 !strcasecmp ("Temporal:New Right Panel", grp) ||
501 !strcasecmp ("Temporal:New Left Panel", grp) ||
502 !strcasecmp ("New Left Panel", grp) || !strcasecmp ("New Right Panel", grp))
503 ? grp : NULL;
506 /* --------------------------------------------------------------------------------------------- */
508 static void
509 setup__move_panels_config_into_separate_file (const char *profile)
511 mc_config_t *tmp_cfg;
512 char **groups, **curr_grp;
514 if (!exist_file (profile))
515 return;
517 tmp_cfg = mc_config_init (profile, FALSE);
518 if (tmp_cfg == NULL)
519 return;
521 groups = mc_config_get_groups (tmp_cfg, NULL);
522 if (*groups == NULL)
524 g_strfreev (groups);
525 mc_config_deinit (tmp_cfg);
526 return;
529 for (curr_grp = groups; *curr_grp != NULL; curr_grp++)
530 if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL)
531 mc_config_del_group (tmp_cfg, *curr_grp);
533 mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
534 mc_config_deinit (tmp_cfg);
536 tmp_cfg = mc_config_init (profile, FALSE);
537 if (tmp_cfg == NULL)
539 g_strfreev (groups);
540 return;
543 for (curr_grp = groups; *curr_grp != NULL; curr_grp++)
545 const char *need_grp;
547 need_grp = setup__is_cfg_group_must_panel_config (*curr_grp);
548 if (need_grp != NULL)
549 mc_config_del_group (tmp_cfg, need_grp);
551 g_strfreev (groups);
553 mc_config_save_file (tmp_cfg, NULL);
554 mc_config_deinit (tmp_cfg);
557 /* --------------------------------------------------------------------------------------------- */
559 Create new mc_config object from specified ini-file or
560 append data to existing mc_config object from ini-file
563 static void
564 load_setup_init_config_from_file (mc_config_t ** config, const char *fname, gboolean read_only)
567 TODO: IMHO, in future, this function shall be placed in mcconfig module.
569 if (exist_file (fname))
571 if (*config != NULL)
572 mc_config_read_file (*config, fname, read_only, TRUE);
573 else
574 *config = mc_config_init (fname, read_only);
578 /* --------------------------------------------------------------------------------------------- */
580 static void
581 load_layout (void)
583 size_t i;
584 int equal_split;
585 int first_panel_size;
587 /* legacy options */
588 panels_layout.horizontal_split = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
589 "horizontal_split", 0);
590 equal_split = mc_config_get_int (mc_main_config, "Layout", "equal_split", 1);
591 first_panel_size = mc_config_get_int (mc_main_config, "Layout", "first_panel_size", 1);
592 if (panels_layout.horizontal_split)
594 panels_layout.horizontal_equal = equal_split;
595 panels_layout.left_panel_size = first_panel_size;
597 else
599 panels_layout.vertical_equal = equal_split;
600 panels_layout.top_panel_size = first_panel_size;
603 /* actual options override legacy ones */
604 for (i = 0; layout[i].opt_name != NULL; i++)
605 *layout[i].opt_addr = mc_config_get_int (mc_main_config, CONFIG_LAYOUT_SECTION,
606 layout[i].opt_name, *layout[i].opt_addr);
608 /* remove legacy options */
609 mc_config_del_key (mc_main_config, CONFIG_APP_SECTION, "horizontal_split");
610 mc_config_del_key (mc_main_config, "Layout", "equal_split");
611 mc_config_del_key (mc_main_config, "Layout", "first_panel_size");
614 /* --------------------------------------------------------------------------------------------- */
616 static void
617 load_keys_from_section (const char *terminal, mc_config_t * cfg)
619 char *section_name;
620 gchar **profile_keys, **keys;
621 char *valcopy, *value;
622 long key_code;
624 if (terminal == NULL)
625 return;
627 section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
628 keys = mc_config_get_keys (cfg, section_name, NULL);
630 for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
632 /* copy=other causes all keys from [terminal:other] to be loaded. */
633 if (g_ascii_strcasecmp (*profile_keys, "copy") == 0)
635 valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
636 load_keys_from_section (valcopy, cfg);
637 g_free (valcopy);
638 continue;
641 key_code = lookup_key (*profile_keys, NULL);
642 if (key_code != 0)
644 gchar **values;
646 values = mc_config_get_string_list (cfg, section_name, *profile_keys, NULL);
647 if (values != NULL)
649 gchar **curr_values;
651 for (curr_values = values; *curr_values != NULL; curr_values++)
653 valcopy = convert_controls (*curr_values);
654 define_sequence (key_code, valcopy, MCKEY_NOACTION);
655 g_free (valcopy);
658 g_strfreev (values);
660 else
662 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
663 valcopy = convert_controls (value);
664 define_sequence (key_code, valcopy, MCKEY_NOACTION);
665 g_free (valcopy);
666 g_free (value);
670 g_strfreev (keys);
671 g_free (section_name);
674 /* --------------------------------------------------------------------------------------------- */
676 static void
677 load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg)
679 gchar **profile_keys, **keys;
681 if (section_name == NULL)
682 return;
684 keys = mc_config_get_keys (cfg, section_name, NULL);
686 for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
688 gchar **values;
690 values = mc_config_get_string_list (cfg, section_name, *profile_keys, NULL);
691 if (values != NULL)
693 long action;
695 action = keybind_lookup_action (*profile_keys);
696 if (action > 0)
698 gchar **curr_values;
700 for (curr_values = values; *curr_values != NULL; curr_values++)
701 keybind_cmd_bind (keymap, *curr_values, action);
704 g_strfreev (values);
708 g_strfreev (keys);
711 /* --------------------------------------------------------------------------------------------- */
713 static mc_config_t *
714 load_setup_get_keymap_profile_config (gboolean load_from_file)
717 TODO: IMHO, in future, this function shall be placed in mcconfig module.
719 mc_config_t *keymap_config;
720 char *share_keymap, *sysconfig_keymap;
721 char *fname, *fname2;
723 /* 0) Create default keymap */
724 keymap_config = create_default_keymap ();
725 if (!load_from_file)
726 return keymap_config;
728 /* load and merge global keymaps */
730 /* 1) /usr/share/mc (mc_global.share_data_dir) */
731 share_keymap = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, NULL);
732 load_setup_init_config_from_file (&keymap_config, share_keymap, TRUE);
734 /* 2) /etc/mc (mc_global.sysconfig_dir) */
735 sysconfig_keymap = g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, NULL);
736 load_setup_init_config_from_file (&keymap_config, sysconfig_keymap, TRUE);
738 /* then load and merge one of user-defined keymap */
740 /* 3) --keymap=<keymap> */
741 fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file);
742 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
744 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
745 goto done;
747 g_free (fname);
749 /* 4) getenv("MC_KEYMAP") */
750 fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
751 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
753 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
754 goto done;
756 g_free (fname);
758 /* 5) main config; [Midnight Commander] -> keymap */
759 fname2 = mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, "keymap", NULL);
760 if (fname2 != NULL && *fname2 != '\0')
761 fname = load_setup_get_full_config_name (NULL, fname2);
762 g_free (fname2);
763 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
765 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
766 goto done;
768 g_free (fname);
770 /* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */
771 fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE);
772 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
774 done:
775 g_free (fname);
776 g_free (sysconfig_keymap);
777 g_free (share_keymap);
779 return keymap_config;
782 /* --------------------------------------------------------------------------------------------- */
784 static panel_view_mode_t
785 setup__load_panel_state (const char *section)
787 char *buffer;
788 size_t i;
789 panel_view_mode_t mode = view_listing;
791 /* Load the display mode */
792 buffer = mc_config_get_string (mc_panels_config, section, "display", "listing");
794 for (i = 0; panel_types[i].opt_name != NULL; i++)
795 if (g_ascii_strcasecmp (panel_types[i].opt_name, buffer) == 0)
797 mode = panel_types[i].opt_type;
798 break;
801 g_free (buffer);
803 return mode;
806 /* --------------------------------------------------------------------------------------------- */
808 static void
809 panel_save_type (const char *section, panel_view_mode_t type)
811 size_t i;
813 for (i = 0; panel_types[i].opt_name != NULL; i++)
814 if (panel_types[i].opt_type == type)
816 mc_config_set_string (mc_panels_config, section, "display", panel_types[i].opt_name);
817 break;
821 /* --------------------------------------------------------------------------------------------- */
823 /* save panels.ini */
824 static void
825 save_panel_types (void)
827 panel_view_mode_t type;
829 if (mc_global.mc_run_mode != MC_RUN_FULL)
830 return;
832 type = get_display_type (0);
833 panel_save_type ("New Left Panel", type);
834 if (type == view_listing)
835 panel_save_setup (left_panel, left_panel->panel_name);
836 type = get_display_type (1);
837 panel_save_type ("New Right Panel", type);
838 if (type == view_listing)
839 panel_save_setup (right_panel, right_panel->panel_name);
842 char *dirs;
844 dirs = get_panel_dir_for (other_panel);
845 mc_config_set_string (mc_panels_config, "Dirs", "other_dir", dirs);
846 g_free (dirs);
849 if (current_panel != NULL)
850 mc_config_set_bool (mc_panels_config, "Dirs", "current_is_left", get_current_index () == 0);
852 if (mc_panels_config->ini_path == NULL)
853 mc_panels_config->ini_path = g_strdup (panels_profile_name);
855 mc_config_del_group (mc_panels_config, "Temporal:New Left Panel");
856 mc_config_del_group (mc_panels_config, "Temporal:New Right Panel");
858 mc_config_save_file (mc_panels_config, NULL);
861 /* --------------------------------------------------------------------------------------------- */
862 /*** public functions ****************************************************************************/
863 /* --------------------------------------------------------------------------------------------- */
865 const char *
866 setup_init (void)
868 if (profile_name == NULL)
870 char *profile;
872 profile = mc_config_get_full_path (MC_CONFIG_FILE);
873 if (!exist_file (profile))
875 char *inifile;
877 inifile = mc_build_filename (mc_global.sysconfig_dir, "mc.ini", NULL);
878 if (exist_file (inifile))
880 g_free (profile);
881 profile = inifile;
883 else
885 g_free (inifile);
886 inifile = mc_build_filename (mc_global.share_data_dir, "mc.ini", NULL);
887 if (!exist_file (inifile))
888 g_free (inifile);
889 else
891 g_free (profile);
892 profile = inifile;
897 profile_name = profile;
900 return profile_name;
903 /* --------------------------------------------------------------------------------------------- */
905 void
906 load_setup (void)
908 const char *profile;
909 size_t i;
910 const char *kt;
912 #ifdef HAVE_CHARSET
913 char *buffer;
915 load_codepages_list ();
916 #endif /* HAVE_CHARSET */
918 profile = setup_init ();
920 /* mc.lib is common for all users, but has priority lower than
921 ${XDG_CONFIG_HOME}/mc/ini. FIXME: it's only used for keys and treestore now */
922 global_profile_name =
923 g_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
924 if (!exist_file (global_profile_name))
926 g_free (global_profile_name);
927 global_profile_name =
928 g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
931 panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE);
933 mc_main_config = mc_config_init (profile, FALSE);
935 if (!exist_file (panels_profile_name))
936 setup__move_panels_config_into_separate_file (profile);
938 mc_panels_config = mc_config_init (panels_profile_name, FALSE);
940 /* Load integer boolean options */
941 for (i = 0; int_options[i].opt_name != NULL; i++)
942 *int_options[i].opt_addr =
943 mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
944 *int_options[i].opt_addr);
945 #ifndef USE_INTERNAL_EDIT
946 /* reset forced in case of build without internal editor */
947 use_internal_edit = 0;
948 #endif /* USE_INTERNAL_EDIT */
950 if (option_tab_spacing <= 0)
951 option_tab_spacing = DEFAULT_TAB_SPACING;
953 #ifdef USE_INTERNAL_EDIT
954 if (option_word_wrap_line_length <= 0)
955 option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
956 #endif /* USE_INTERNAL_EDIT */
958 /* overwrite old_esc_mode_timeout */
959 kt = getenv ("KEYBOARD_KEY_TIMEOUT_US");
960 if ((kt != NULL) && (kt[0] != '\0'))
961 old_esc_mode_timeout = atoi (kt);
963 /* Load string options */
964 for (i = 0; str_options[i].opt_name != NULL; i++)
965 *str_options[i].opt_addr =
966 mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
967 str_options[i].opt_defval);
969 load_layout ();
970 panels_load_options ();
971 load_panelize ();
973 startup_left_mode = setup__load_panel_state ("New Left Panel");
974 startup_right_mode = setup__load_panel_state ("New Right Panel");
976 /* At least one of the panels is a listing panel */
977 if (startup_left_mode != view_listing && startup_right_mode != view_listing)
978 startup_left_mode = view_listing;
980 boot_current_is_left = mc_config_get_bool (mc_panels_config, "Dirs", "current_is_left", TRUE);
982 /* Load time formats */
983 user_recent_timeformat =
984 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_recent", FMTTIME);
985 user_old_timeformat =
986 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_old", FMTYEAR);
988 #ifdef ENABLE_VFS_FTP
989 ftpfs_proxy_host =
990 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host", "gate");
991 ftpfs_ignore_chattr_errors =
992 mc_config_get_bool (mc_main_config, CONFIG_APP_SECTION, "ignore_ftp_chattr_errors", TRUE);
993 ftpfs_init_passwd ();
994 #endif /* ENABLE_VFS_FTP */
996 /* The default color and the terminal dependent color */
997 mc_global.tty.setup_color_string =
998 mc_config_get_string (mc_main_config, "Colors", "base_color", "");
999 mc_global.tty.term_color_string =
1000 mc_config_get_string (mc_main_config, "Colors", getenv ("TERM"), "");
1001 mc_global.tty.color_terminal_string =
1002 mc_config_get_string (mc_main_config, "Colors", "color_terminals", "");
1004 /* Load the directory history */
1005 /* directory_history_load (); */
1006 /* Remove the temporal entries */
1008 #ifdef HAVE_CHARSET
1009 if (codepages->len > 1)
1011 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage", "");
1012 if (buffer[0] != '\0')
1014 mc_global.display_codepage = get_codepage_index (buffer);
1015 cp_display = get_codepage_id (mc_global.display_codepage);
1017 g_free (buffer);
1018 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage", "");
1019 if (buffer[0] != '\0')
1021 default_source_codepage = get_codepage_index (buffer);
1022 mc_global.source_codepage = default_source_codepage; /* May be source_codepage doesn't need this */
1023 cp_source = get_codepage_id (mc_global.source_codepage);
1025 g_free (buffer);
1028 autodetect_codeset =
1029 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset", "");
1030 if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off") != 0))
1031 is_autodetect_codeset_enabled = TRUE;
1033 g_free (init_translation_table (mc_global.source_codepage, mc_global.display_codepage));
1034 buffer = (char *) get_codepage_id (mc_global.display_codepage);
1035 if (buffer != NULL)
1036 mc_global.utf8_display = str_isutf8 (buffer);
1037 #endif /* HAVE_CHARSET */
1039 #ifdef HAVE_ASPELL
1040 spell_language =
1041 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "spell_language", "en");
1042 #endif /* HAVE_ASPELL */
1044 clipboard_store_path =
1045 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store", "");
1046 clipboard_paste_path =
1047 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste", "");
1050 /* --------------------------------------------------------------------------------------------- */
1052 gboolean
1053 save_setup (gboolean save_options, gboolean save_panel_options)
1055 gboolean ret = TRUE;
1057 saving_setup = 1;
1059 save_hotlist ();
1061 if (save_panel_options)
1062 save_panel_types ();
1064 if (save_options)
1066 char *tmp_profile;
1068 save_config ();
1069 save_layout ();
1070 panels_save_options ();
1071 save_panelize ();
1072 /* directory_history_save (); */
1074 #ifdef ENABLE_VFS_FTP
1075 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "ftpfs_password",
1076 ftpfs_anonymous_passwd);
1077 if (ftpfs_proxy_host)
1078 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host",
1079 ftpfs_proxy_host);
1080 #endif /* ENABLE_VFS_FTP */
1082 #ifdef HAVE_CHARSET
1083 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage",
1084 get_codepage_id (mc_global.display_codepage));
1085 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage",
1086 get_codepage_id (default_source_codepage));
1087 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset",
1088 autodetect_codeset);
1089 #endif /* HAVE_CHARSET */
1091 #ifdef HAVE_ASPELL
1092 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "spell_language",
1093 spell_language);
1094 #endif /* HAVE_ASPELL */
1096 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store",
1097 clipboard_store_path);
1098 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste",
1099 clipboard_paste_path);
1101 tmp_profile = mc_config_get_full_path (MC_CONFIG_FILE);
1102 ret = mc_config_save_to_file (mc_main_config, tmp_profile, NULL);
1103 g_free (tmp_profile);
1106 saving_setup = 0;
1108 return ret;
1111 /* --------------------------------------------------------------------------------------------- */
1113 void
1114 done_setup (void)
1116 size_t i;
1118 g_free (clipboard_store_path);
1119 g_free (clipboard_paste_path);
1120 g_free (global_profile_name);
1121 g_free (mc_global.tty.color_terminal_string);
1122 g_free (mc_global.tty.term_color_string);
1123 g_free (mc_global.tty.setup_color_string);
1124 g_free (profile_name);
1125 g_free (panels_profile_name);
1126 mc_config_deinit (mc_main_config);
1127 mc_config_deinit (mc_panels_config);
1129 g_free (user_recent_timeformat);
1130 g_free (user_old_timeformat);
1132 for (i = 0; str_options[i].opt_name != NULL; i++)
1133 g_free (*str_options[i].opt_addr);
1135 done_hotlist ();
1136 done_panelize ();
1137 /* directory_history_free (); */
1139 #ifdef HAVE_CHARSET
1140 g_free (autodetect_codeset);
1141 free_codepages_list ();
1142 #endif
1144 #ifdef HAVE_ASPELL
1145 g_free (spell_language);
1146 #endif /* HAVE_ASPELL */
1149 /* --------------------------------------------------------------------------------------------- */
1151 void
1152 save_config (void)
1154 size_t i;
1156 /* Save integer options */
1157 for (i = 0; int_options[i].opt_name != NULL; i++)
1158 mc_config_set_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
1159 *int_options[i].opt_addr);
1161 /* Save string options */
1162 for (i = 0; str_options[i].opt_name != NULL; i++)
1163 mc_config_set_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
1164 *str_options[i].opt_addr);
1167 /* --------------------------------------------------------------------------------------------- */
1169 void
1170 setup_save_config_show_error (const char *filename, GError ** mcerror)
1172 if (mcerror != NULL && *mcerror != NULL)
1174 message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*mcerror)->message);
1175 g_error_free (*mcerror);
1176 *mcerror = NULL;
1180 /* --------------------------------------------------------------------------------------------- */
1182 void
1183 save_layout (void)
1185 size_t i;
1187 /* Save integer options */
1188 for (i = 0; layout[i].opt_name != NULL; i++)
1189 mc_config_set_int (mc_main_config, CONFIG_LAYOUT_SECTION, layout[i].opt_name,
1190 *layout[i].opt_addr);
1193 /* --------------------------------------------------------------------------------------------- */
1195 void
1196 load_key_defs (void)
1199 * Load keys from mc.lib before ${XDG_CONFIG_HOME}/mc/ini, so that the user
1200 * definitions override global settings.
1202 mc_config_t *mc_global_config;
1204 mc_global_config = mc_config_init (global_profile_name, FALSE);
1205 if (mc_global_config != NULL)
1207 load_keys_from_section ("general", mc_global_config);
1208 load_keys_from_section (getenv ("TERM"), mc_global_config);
1209 mc_config_deinit (mc_global_config);
1212 load_keys_from_section ("general", mc_main_config);
1213 load_keys_from_section (getenv ("TERM"), mc_main_config);
1216 /* --------------------------------------------------------------------------------------------- */
1218 #ifdef ENABLE_VFS_FTP
1219 char *
1220 load_anon_passwd (void)
1222 char *buffer;
1224 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftpfs_password", "");
1226 if ((buffer != NULL) && (buffer[0] != '\0'))
1227 return buffer;
1229 g_free (buffer);
1230 return NULL;
1232 #endif /* ENABLE_VFS_FTP */
1234 /* --------------------------------------------------------------------------------------------- */
1236 void
1237 load_keymap_defs (gboolean load_from_file)
1240 * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_CONFIG_HOME}/mc/mc.keymap, so that the user
1241 * definitions override global settings.
1243 mc_config_t *mc_global_keymap;
1245 mc_global_keymap = load_setup_get_keymap_profile_config (load_from_file);
1247 if (mc_global_keymap != NULL)
1249 main_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1250 load_keymap_from_section (KEYMAP_SECTION_MAIN, main_keymap, mc_global_keymap);
1251 main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1252 load_keymap_from_section (KEYMAP_SECTION_MAIN_EXT, main_x_keymap, mc_global_keymap);
1254 panel_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1255 load_keymap_from_section (KEYMAP_SECTION_PANEL, panel_keymap, mc_global_keymap);
1257 dialog_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1258 load_keymap_from_section (KEYMAP_SECTION_DIALOG, dialog_keymap, mc_global_keymap);
1260 input_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1261 load_keymap_from_section (KEYMAP_SECTION_INPUT, input_keymap, mc_global_keymap);
1263 listbox_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1264 load_keymap_from_section (KEYMAP_SECTION_LISTBOX, listbox_keymap, mc_global_keymap);
1266 tree_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1267 load_keymap_from_section (KEYMAP_SECTION_TREE, tree_keymap, mc_global_keymap);
1269 help_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1270 load_keymap_from_section (KEYMAP_SECTION_HELP, help_keymap, mc_global_keymap);
1272 #ifdef USE_INTERNAL_EDIT
1273 editor_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1274 load_keymap_from_section (KEYMAP_SECTION_EDITOR, editor_keymap, mc_global_keymap);
1275 editor_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1276 load_keymap_from_section (KEYMAP_SECTION_EDITOR_EXT, editor_x_keymap, mc_global_keymap);
1277 #endif
1279 viewer_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1280 load_keymap_from_section (KEYMAP_SECTION_VIEWER, viewer_keymap, mc_global_keymap);
1281 viewer_hex_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1282 load_keymap_from_section (KEYMAP_SECTION_VIEWER_HEX, viewer_hex_keymap, mc_global_keymap);
1284 #ifdef USE_DIFF_VIEW
1285 diff_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1286 load_keymap_from_section (KEYMAP_SECTION_DIFFVIEWER, diff_keymap, mc_global_keymap);
1287 #endif
1289 mc_config_deinit (mc_global_keymap);
1292 main_map = (global_keymap_t *) main_keymap->data;
1293 main_x_map = (global_keymap_t *) main_x_keymap->data;
1294 panel_map = (global_keymap_t *) panel_keymap->data;
1295 dialog_map = (global_keymap_t *) dialog_keymap->data;
1296 input_map = (global_keymap_t *) input_keymap->data;
1297 listbox_map = (global_keymap_t *) listbox_keymap->data;
1298 tree_map = (global_keymap_t *) tree_keymap->data;
1299 help_map = (global_keymap_t *) help_keymap->data;
1300 #ifdef USE_INTERNAL_EDIT
1301 editor_map = (global_keymap_t *) editor_keymap->data;
1302 editor_x_map = (global_keymap_t *) editor_x_keymap->data;
1303 #endif
1304 viewer_map = (global_keymap_t *) viewer_keymap->data;
1305 viewer_hex_map = (global_keymap_t *) viewer_hex_keymap->data;
1306 #ifdef USE_DIFF_VIEW
1307 diff_map = (global_keymap_t *) diff_keymap->data;
1308 #endif
1311 /* --------------------------------------------------------------------------------------------- */
1313 void
1314 free_keymap_defs (void)
1316 if (main_keymap != NULL)
1317 g_array_free (main_keymap, TRUE);
1318 if (main_x_keymap != NULL)
1319 g_array_free (main_x_keymap, TRUE);
1320 if (panel_keymap != NULL)
1321 g_array_free (panel_keymap, TRUE);
1322 if (dialog_keymap != NULL)
1323 g_array_free (dialog_keymap, TRUE);
1324 if (input_keymap != NULL)
1325 g_array_free (input_keymap, TRUE);
1326 if (listbox_keymap != NULL)
1327 g_array_free (listbox_keymap, TRUE);
1328 if (tree_keymap != NULL)
1329 g_array_free (tree_keymap, TRUE);
1330 if (help_keymap != NULL)
1331 g_array_free (help_keymap, TRUE);
1332 #ifdef USE_INTERNAL_EDIT
1333 if (editor_keymap != NULL)
1334 g_array_free (editor_keymap, TRUE);
1335 if (editor_x_keymap != NULL)
1336 g_array_free (editor_x_keymap, TRUE);
1337 #endif
1338 if (viewer_keymap != NULL)
1339 g_array_free (viewer_keymap, TRUE);
1340 if (viewer_hex_keymap != NULL)
1341 g_array_free (viewer_hex_keymap, TRUE);
1342 #ifdef USE_DIFF_VIEW
1343 if (diff_keymap != NULL)
1344 g_array_free (diff_keymap, TRUE);
1345 #endif
1348 /* --------------------------------------------------------------------------------------------- */
1350 void
1351 panel_load_setup (WPanel * panel, const char *section)
1353 size_t i;
1354 char *buffer, buffer2[BUF_TINY];
1356 panel->sort_info.reverse = mc_config_get_int (mc_panels_config, section, "reverse", 0);
1357 panel->sort_info.case_sensitive =
1358 mc_config_get_int (mc_panels_config, section, "case_sensitive",
1359 OS_SORT_CASE_SENSITIVE_DEFAULT);
1360 panel->sort_info.exec_first = mc_config_get_int (mc_panels_config, section, "exec_first", 0);
1362 /* Load sort order */
1363 buffer = mc_config_get_string (mc_panels_config, section, "sort_order", "name");
1364 panel->sort_field = panel_get_field_by_id (buffer);
1365 if (panel->sort_field == NULL)
1366 panel->sort_field = panel_get_field_by_id ("name");
1368 g_free (buffer);
1370 /* Load the listing mode */
1371 buffer = mc_config_get_string (mc_panels_config, section, "list_mode", "full");
1372 panel->list_type = list_full;
1373 for (i = 0; list_types[i].key != NULL; i++)
1374 if (g_ascii_strcasecmp (list_types[i].key, buffer) == 0)
1376 panel->list_type = list_types[i].list_type;
1377 break;
1379 g_free (buffer);
1381 panel->brief_cols = mc_config_get_int (mc_panels_config, section, "brief_cols", 2);
1383 /* User formats */
1384 g_free (panel->user_format);
1385 panel->user_format =
1386 mc_config_get_string (mc_panels_config, section, "user_format", DEFAULT_USER_FORMAT);
1388 for (i = 0; i < LIST_TYPES; i++)
1390 g_free (panel->user_status_format[i]);
1391 g_snprintf (buffer2, sizeof (buffer2), "user_status%lld", (long long) i);
1392 panel->user_status_format[i] =
1393 mc_config_get_string (mc_panels_config, section, buffer2, DEFAULT_USER_FORMAT);
1396 panel->user_mini_status = mc_config_get_int (mc_panels_config, section, "user_mini_status", 0);
1399 /* --------------------------------------------------------------------------------------------- */
1401 void
1402 panel_save_setup (WPanel * panel, const char *section)
1404 char buffer[BUF_TINY];
1405 size_t i;
1407 mc_config_set_int (mc_panels_config, section, "reverse", panel->sort_info.reverse);
1408 mc_config_set_int (mc_panels_config, section, "case_sensitive",
1409 panel->sort_info.case_sensitive);
1410 mc_config_set_int (mc_panels_config, section, "exec_first", panel->sort_info.exec_first);
1412 mc_config_set_string (mc_panels_config, section, "sort_order", panel->sort_field->id);
1414 for (i = 0; list_types[i].key != NULL; i++)
1415 if (list_types[i].list_type == (int) panel->list_type)
1417 mc_config_set_string (mc_panels_config, section, "list_mode", list_types[i].key);
1418 break;
1421 mc_config_set_int (mc_panels_config, section, "brief_cols", panel->brief_cols);
1423 mc_config_set_string (mc_panels_config, section, "user_format", panel->user_format);
1425 for (i = 0; i < LIST_TYPES; i++)
1427 g_snprintf (buffer, sizeof (buffer), "user_status%lld", (long long) i);
1428 mc_config_set_string (mc_panels_config, section, buffer, panel->user_status_format[i]);
1431 mc_config_set_int (mc_panels_config, section, "user_mini_status", panel->user_mini_status);
1434 /* --------------------------------------------------------------------------------------------- */
1437 Load panels options from [Panels] section.
1439 void
1440 panels_load_options (void)
1442 if (mc_config_has_group (mc_main_config, CONFIG_PANELS_SECTION))
1444 size_t i;
1445 int qmode;
1447 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1448 *panels_ini_options[i].opt_addr =
1449 mc_config_get_bool (mc_main_config, CONFIG_PANELS_SECTION,
1450 panels_ini_options[i].opt_name,
1451 *panels_ini_options[i].opt_addr);
1453 qmode = mc_config_get_int (mc_main_config, CONFIG_PANELS_SECTION,
1454 "quick_search_mode", (int) panels_options.qsearch_mode);
1455 if (qmode < 0)
1456 panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE;
1457 else if (qmode >= QSEARCH_NUM)
1458 panels_options.qsearch_mode = QSEARCH_PANEL_CASE;
1459 else
1460 panels_options.qsearch_mode = (qsearch_mode_t) qmode;
1462 panels_options.select_flags =
1463 mc_config_get_int (mc_main_config, CONFIG_PANELS_SECTION, "select_flags",
1464 (int) panels_options.select_flags);
1468 /* --------------------------------------------------------------------------------------------- */
1471 Save panels options in [Panels] section.
1473 void
1474 panels_save_options (void)
1476 size_t i;
1478 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1479 mc_config_set_bool (mc_main_config, CONFIG_PANELS_SECTION,
1480 panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr);
1482 mc_config_set_int (mc_main_config, CONFIG_PANELS_SECTION,
1483 "quick_search_mode", (int) panels_options.qsearch_mode);
1484 mc_config_set_int (mc_main_config, CONFIG_PANELS_SECTION,
1485 "select_flags", (int) panels_options.select_flags);
1488 /* --------------------------------------------------------------------------------------------- */