(mc_global_t::shell): new member to store user's shell
[midnight-commander.git] / src / setup.c
blob3002bb85c62a64ee7289450ef36925f261151bc4
1 /*
2 Setup loading/saving.
4 Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
5 2006, 2007, 2009, 2010, 2011
6 The Free Software Foundation, Inc.
8 This file is part of the Midnight Commander.
10 The Midnight Commander is free software: you can redistribute it
11 and/or modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation, either version 3 of the License,
13 or (at your option) any later version.
15 The Midnight Commander is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /** \file setup.c
25 * \brief Source: setup loading/saving
28 #include <config.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <stdio.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
36 #include "lib/global.h"
38 #include "lib/tty/tty.h"
39 #include "lib/tty/key.h"
40 #include "lib/mcconfig.h"
41 #include "lib/fileloc.h"
42 #include "lib/timefmt.h"
43 #include "lib/util.h"
44 #include "lib/widget.h"
46 #include "lib/vfs/vfs.h"
48 #ifdef ENABLE_VFS_FTP
49 #include "src/vfs/ftpfs/ftpfs.h"
50 #endif
51 #ifdef ENABLE_VFS_FISH
52 #include "src/vfs/fish/fish.h"
53 #endif
55 #ifdef HAVE_CHARSET
56 #include "lib/charsets.h"
57 #endif
59 #include "filemanager/dir.h"
60 #include "filemanager/midnight.h"
61 #include "filemanager/tree.h" /* xtree_mode */
62 #include "filemanager/hotlist.h" /* load/save/done hotlist */
63 #include "filemanager/panelize.h" /* load/save/done panelize */
64 #include "filemanager/layout.h"
65 #include "filemanager/cmd.h"
67 #include "args.h"
68 #include "execute.h" /* pause_after_run */
69 #include "clipboard.h"
70 #include "keybind-defaults.h" /* keybind_lookup_action */
72 #ifdef HAVE_CHARSET
73 #include "selcodepage.h"
74 #endif
76 #ifdef USE_INTERNAL_EDIT
77 #include "src/editor/edit.h"
78 #endif
80 #include "src/viewer/mcviewer.h" /* For the externs */
82 #include "setup.h"
84 /*** global variables ****************************************************************************/
86 char *profile_name; /* ${XDG_CONFIG_HOME}/mc/ini */
87 char *global_profile_name; /* mc.lib */
89 /* Only used at program boot */
90 gboolean boot_current_is_left = TRUE;
92 /* If on, default for "No" in delete operations */
93 int safe_delete = 0;
95 /* Controls screen clearing before an exec */
96 int clear_before_exec = 1;
98 /* Asks for confirmation before deleting a file */
99 int confirm_delete = 1;
100 /* Asks for confirmation before deleting a hotlist entry */
101 int confirm_directory_hotlist_delete = 1;
102 /* Asks for confirmation before overwriting a file */
103 int confirm_overwrite = 1;
104 /* Asks for confirmation before executing a program by pressing enter */
105 int confirm_execute = 0;
106 /* Asks for confirmation before leaving the program */
107 int confirm_exit = 1;
109 /* If true, at startup the user-menu is invoked */
110 int auto_menu = 0;
111 /* This flag indicates if the pull down menus by default drop down */
112 int drop_menus = 0;
114 /* Asks for confirmation when using F3 to view a directory and there
115 are tagged files */
116 int confirm_view_dir = 0;
118 panel_view_mode_t startup_left_mode;
119 panel_view_mode_t startup_right_mode;
121 int setup_copymove_persistent_attr = 1;
123 /* Tab size */
124 int option_tab_spacing = DEFAULT_TAB_SPACING;
126 /* Ugly hack to allow panel_save_setup to work as a place holder for */
127 /* default panel values */
128 int saving_setup;
130 panels_options_t panels_options = {
131 .show_mini_info = TRUE,
132 .kilobyte_si = FALSE,
133 .mix_all_files = FALSE,
134 .show_backups = TRUE,
135 .show_dot_files = TRUE,
136 .fast_reload = FALSE,
137 .fast_reload_msg_shown = FALSE,
138 .mark_moves_down = TRUE,
139 .reverse_files_only = TRUE,
140 .auto_save_setup = FALSE,
141 .navigate_with_arrows = FALSE,
142 .scroll_pages = TRUE,
143 .mouse_move_pages = TRUE,
144 .filetype_mode = TRUE,
145 .permission_mode = FALSE,
146 .qsearch_mode = QSEARCH_PANEL_CASE,
147 .torben_fj_mode = FALSE
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 transfered
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 /* If set, then print to the given file the last directory we were at */
195 char *last_wd_string = NULL;
197 /* Set when main loop should be terminated */
198 int quit = 0;
200 /* Set to TRUE to suppress printing the last directory */
201 int print_last_revert = FALSE;
203 /* index to record_macro_buf[], -1 if not recording a macro */
204 int macro_index = -1;
206 /* macro stuff */
207 struct macro_action_t record_macro_buf[MAX_MACRO_LENGTH];
209 GArray *macros_list;
211 /*** file scope macro definitions ****************************************************************/
213 /* In order to use everywhere the same setup for the locale we use defines */
214 #define FMTYEAR _("%b %e %Y")
215 #define FMTTIME _("%b %e %H:%M")
217 /*** file scope type declarations ****************************************************************/
219 /*** file scope variables ************************************************************************/
221 static char *panels_profile_name = NULL; /* ${XDG_CACHE_HOME}/mc/panels.ini */
223 /* *INDENT-OFF* */
224 static const struct
226 const char *key;
227 int list_type;
228 } list_types [] = {
229 { "full", list_full },
230 { "brief", list_brief },
231 { "long", list_long },
232 { "user", list_user },
233 { NULL, 0 }
236 static const struct
238 const char *opt_name;
239 panel_view_mode_t opt_type;
240 } panel_types [] = {
241 { "listing", view_listing },
242 { "quickview", view_quick },
243 { "info", view_info },
244 { "tree", view_tree },
245 { NULL, view_listing }
248 static const struct
250 const char *opt_name;
251 int *opt_addr;
252 } layout [] = {
253 { "message_visible", &mc_global.message_visible },
254 { "keybar_visible", &mc_global.keybar_visible },
255 { "xterm_title", &xterm_title },
256 { "output_lines", &output_lines },
257 { "command_prompt", &command_prompt },
258 { "menubar_visible", &menubar_visible },
259 { "free_space", &free_space },
260 { "horizontal_split", &panels_layout.horizontal_split },
261 { "vertical_equal", &panels_layout.vertical_equal },
262 { "left_panel_size", &panels_layout.left_panel_size },
263 { "horizontal_equal", &panels_layout.horizontal_equal },
264 { "top_panel_size", &panels_layout.top_panel_size },
265 { NULL, NULL }
268 static const struct
270 const char *opt_name;
271 int *opt_addr;
272 } int_options [] = {
273 { "verbose", &verbose },
274 { "pause_after_run", &pause_after_run },
275 { "shell_patterns", &easy_patterns },
276 { "auto_save_setup", &auto_save_setup },
277 { "preallocate_space", &mc_global.vfs.preallocate_space },
278 { "auto_menu", &auto_menu },
279 { "use_internal_view", &use_internal_view },
280 { "use_internal_edit", &use_internal_edit },
281 { "clear_before_exec", &clear_before_exec },
282 { "confirm_delete", &confirm_delete },
283 { "confirm_overwrite", &confirm_overwrite },
284 { "confirm_execute", &confirm_execute },
285 { "confirm_history_cleanup", &mc_global.widget.confirm_history_cleanup },
286 { "confirm_exit", &confirm_exit },
287 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete },
288 { "safe_delete", &safe_delete },
289 { "mouse_repeat_rate", &mou_auto_repeat },
290 { "double_click_speed", &double_click_speed },
291 #ifndef HAVE_CHARSET
292 { "eight_bit_clean", &mc_global.eight_bit_clean },
293 { "full_eight_bits", &mc_global.full_eight_bits },
294 #endif /* !HAVE_CHARSET */
295 { "use_8th_bit_as_meta", &use_8th_bit_as_meta },
296 { "confirm_view_dir", &confirm_view_dir },
297 { "mouse_move_pages_viewer", &mcview_mouse_move_pages },
298 { "mouse_close_dialog", &mouse_close_dialog},
299 { "fast_refresh", &fast_refresh },
300 { "drop_menus", &drop_menus },
301 { "wrap_mode", &mcview_global_wrap_mode},
302 { "old_esc_mode", &old_esc_mode },
303 { "old_esc_mode_timeout", &old_esc_mode_timeout },
304 { "cd_symlinks", &mc_global.vfs.cd_symlinks },
305 { "show_all_if_ambiguous", &mc_global.widget.show_all_if_ambiguous },
306 { "max_dirt_limit", &mcview_max_dirt_limit },
307 { "use_file_to_guess_type", &use_file_to_check_type },
308 { "alternate_plus_minus", &mc_global.tty.alternate_plus_minus },
309 { "only_leading_plus_minus", &only_leading_plus_minus },
310 { "show_output_starts_shell", &output_starts_shell },
311 { "xtree_mode", &xtree_mode },
312 { "num_history_items_recorded", &num_history_items_recorded },
313 { "file_op_compute_totals", &file_op_compute_totals },
314 { "classic_progressbar", &classic_progressbar},
315 #ifdef ENABLE_VFS
316 { "vfs_timeout", &vfs_timeout },
317 #ifdef ENABLE_VFS_FTP
318 { "ftpfs_directory_timeout", &ftpfs_directory_timeout },
319 { "use_netrc", &ftpfs_use_netrc },
320 { "ftpfs_retry_seconds", &ftpfs_retry_seconds },
321 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy },
322 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections },
323 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy },
324 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options },
325 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls },
326 #endif /* ENABLE_VFS_FTP */
327 #ifdef ENABLE_VFS_FISH
328 { "fish_directory_timeout", &fish_directory_timeout },
329 #endif /* ENABLE_VFS_FISH */
330 #endif /* ENABLE_VFS */
331 /* option_tab_spacing is used in internal viewer */
332 { "editor_tab_spacing", &option_tab_spacing },
333 #ifdef USE_INTERNAL_EDIT
334 { "editor_word_wrap_line_length", &option_word_wrap_line_length },
335 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces },
336 { "editor_return_does_auto_indent", &option_return_does_auto_indent },
337 { "editor_backspace_through_tabs", &option_backspace_through_tabs },
338 { "editor_fake_half_tabs", &option_fake_half_tabs },
339 { "editor_option_save_mode", &option_save_mode },
340 { "editor_option_save_position", &option_save_position },
341 { "editor_option_auto_para_formatting", &option_auto_para_formatting },
342 { "editor_option_typewriter_wrap", &option_typewriter_wrap },
343 { "editor_edit_confirm_save", &edit_confirm_save },
344 { "editor_syntax_highlighting", &option_syntax_highlighting },
345 { "editor_persistent_selections", &option_persistent_selections },
346 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol },
347 { "editor_cursor_after_inserted_block", &option_cursor_after_inserted_block },
348 { "editor_visible_tabs", &visible_tabs },
349 { "editor_visible_spaces", &visible_tws },
350 { "editor_line_state", &option_line_state },
351 { "editor_simple_statusbar", &simple_statusbar },
352 { "editor_check_new_line", &option_check_nl_at_eof },
353 { "editor_show_right_margin", &show_right_margin },
354 { "editor_group_undo", &option_group_undo },
355 #endif /* USE_INTERNAL_EDIT */
356 { "nice_rotating_dash", &nice_rotating_dash },
357 { "mcview_remember_file_position", &mcview_remember_file_position },
358 { "auto_fill_mkdir_name", &auto_fill_mkdir_name },
359 { "copymove_persistent_attr", &setup_copymove_persistent_attr },
360 { "select_flags", &select_flags },
361 { NULL, NULL }
364 static const struct
366 const char *opt_name;
367 char **opt_addr;
368 const char *opt_defval;
369 } str_options[] = {
370 #ifdef USE_INTERNAL_EDIT
371 { "editor_backup_extension", &option_backup_ext, "~" },
372 #endif
373 { "mcview_eof", &mcview_show_eof, "" },
374 { NULL, NULL, NULL }
377 static const struct
379 const char *opt_name;
380 gboolean *opt_addr;
381 } panels_ini_options[] = {
382 { "show_mini_info", &panels_options.show_mini_info },
383 { "kilobyte_si", &panels_options.kilobyte_si },
384 { "mix_all_files", &panels_options.mix_all_files },
385 { "show_backups", &panels_options.show_backups },
386 { "show_dot_files", &panels_options.show_dot_files },
387 { "fast_reload", &panels_options.fast_reload },
388 { "fast_reload_msg_shown", &panels_options.fast_reload_msg_shown },
389 { "mark_moves_down", &panels_options.mark_moves_down },
390 { "reverse_files_only", &panels_options.reverse_files_only },
391 { "auto_save_setup_panels", &panels_options.auto_save_setup },
392 { "navigate_with_arrows", &panels_options.navigate_with_arrows },
393 { "panel_scroll_pages", &panels_options.scroll_pages },
394 { "mouse_move_pages", &panels_options.mouse_move_pages },
395 { "filetype_mode", &panels_options.filetype_mode },
396 { "permission_mode", &panels_options.permission_mode },
397 { "torben_fj_mode", &panels_options.torben_fj_mode },
398 { NULL, NULL }
400 /* *INDENT-ON* */
402 /*** file scope functions ************************************************************************/
403 /* --------------------------------------------------------------------------------------------- */
406 * Get name of config file.
408 * @param subdir If not NULL, config is also searched in specified subdir.
409 * @param config_file_name If relative, file if searched in standard paths.
411 * @return newly allocated string with config name or NULL if file is not found.
414 static char *
415 load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
418 TODO: IMHO, in future, this function shall be placed in mcconfig module.
420 char *lc_basename, *ret;
421 char *file_name;
423 if (config_file_name == NULL)
424 return NULL;
426 /* check for .keymap suffix */
427 if (g_str_has_suffix (config_file_name, ".keymap"))
428 file_name = g_strdup (config_file_name);
429 else
430 file_name = g_strconcat (config_file_name, ".keymap", (char *) NULL);
432 canonicalize_pathname (file_name);
434 if (g_path_is_absolute (file_name))
435 return file_name;
437 lc_basename = g_path_get_basename (file_name);
438 g_free (file_name);
440 if (lc_basename == NULL)
441 return NULL;
443 if (subdir != NULL)
444 ret = g_build_filename (mc_config_get_path (), subdir, lc_basename, NULL);
445 else
446 ret = g_build_filename (mc_config_get_path (), lc_basename, NULL);
448 if (exist_file (ret))
450 g_free (lc_basename);
451 canonicalize_pathname (ret);
452 return ret;
454 g_free (ret);
456 if (subdir != NULL)
457 ret = g_build_filename (mc_global.sysconfig_dir, subdir, lc_basename, NULL);
458 else
459 ret = g_build_filename (mc_global.sysconfig_dir, lc_basename, NULL);
461 if (exist_file (ret))
463 g_free (lc_basename);
464 canonicalize_pathname (ret);
465 return ret;
467 g_free (ret);
469 if (subdir != NULL)
470 ret = g_build_filename (mc_global.share_data_dir, subdir, lc_basename, NULL);
471 else
472 ret = g_build_filename (mc_global.share_data_dir, lc_basename, NULL);
474 g_free (lc_basename);
476 if (exist_file (ret))
478 canonicalize_pathname (ret);
479 return ret;
482 g_free (ret);
483 return NULL;
486 /* --------------------------------------------------------------------------------------------- */
488 static const char *
489 setup__is_cfg_group_must_panel_config (const char *grp)
491 return (!strcasecmp ("Dirs", grp) ||
492 !strcasecmp ("Temporal:New Right Panel", grp) ||
493 !strcasecmp ("Temporal:New Left Panel", grp) ||
494 !strcasecmp ("New Left Panel", grp) || !strcasecmp ("New Right Panel", grp))
495 ? grp : NULL;
498 /* --------------------------------------------------------------------------------------------- */
500 static void
501 setup__move_panels_config_into_separate_file (const char *profile)
503 mc_config_t *tmp_cfg;
504 char **groups, **curr_grp;
505 const char *need_grp;
507 if (!exist_file (profile))
508 return;
510 tmp_cfg = mc_config_init (profile, FALSE);
511 if (!tmp_cfg)
512 return;
514 curr_grp = groups = mc_config_get_groups (tmp_cfg, NULL);
515 if (!groups)
517 mc_config_deinit (tmp_cfg);
518 return;
521 while (*curr_grp)
523 if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL)
524 mc_config_del_group (tmp_cfg, *curr_grp);
525 curr_grp++;
528 mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
529 mc_config_deinit (tmp_cfg);
531 tmp_cfg = mc_config_init (profile, FALSE);
532 if (!tmp_cfg)
534 g_strfreev (groups);
535 return;
538 curr_grp = groups;
540 while (*curr_grp)
542 need_grp = setup__is_cfg_group_must_panel_config (*curr_grp);
543 if (need_grp != NULL)
545 mc_config_del_group (tmp_cfg, need_grp);
547 curr_grp++;
549 g_strfreev (groups);
551 mc_config_save_file (tmp_cfg, NULL);
552 mc_config_deinit (tmp_cfg);
555 /* --------------------------------------------------------------------------------------------- */
557 Create new mc_config object from specified ini-file or
558 append data to existing mc_config object from ini-file
561 static void
562 load_setup_init_config_from_file (mc_config_t ** config, const char *fname, gboolean read_only)
565 TODO: IMHO, in future, this function shall be placed in mcconfig module.
567 if (exist_file (fname))
569 if (*config != NULL)
570 mc_config_read_file (*config, fname, read_only, TRUE);
571 else
572 *config = mc_config_init (fname, read_only);
576 /* --------------------------------------------------------------------------------------------- */
578 static void
579 load_layout (void)
581 size_t i;
582 int equal_split;
583 int first_panel_size;
585 /* legacy options */
586 panels_layout.horizontal_split = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
587 "horizontal_split", 0);
588 equal_split = mc_config_get_int (mc_main_config, "Layout", "equal_split", 1);
589 first_panel_size = mc_config_get_int (mc_main_config, "Layout", "first_panel_size", 1);
590 if (panels_layout.horizontal_split)
592 panels_layout.horizontal_equal = equal_split;
593 panels_layout.left_panel_size = first_panel_size;
595 else
597 panels_layout.vertical_equal = equal_split;
598 panels_layout.top_panel_size = first_panel_size;
601 /* actual options override legacy ones */
602 for (i = 0; layout[i].opt_name != NULL; i++)
603 *layout[i].opt_addr = mc_config_get_int (mc_main_config, CONFIG_LAYOUT_SECTION,
604 layout[i].opt_name, *layout[i].opt_addr);
606 /* remove legacy options */
607 mc_config_del_key (mc_main_config, CONFIG_APP_SECTION, "horizontal_split");
608 mc_config_del_key (mc_main_config, "Layout", "equal_split");
609 mc_config_del_key (mc_main_config, "Layout", "first_panel_size");
612 /* --------------------------------------------------------------------------------------------- */
614 static void
615 load_keys_from_section (const char *terminal, mc_config_t * cfg)
617 char *section_name;
618 gchar **profile_keys, **keys;
619 gchar **values, **curr_values;
620 char *valcopy, *value;
621 long key_code;
622 gsize len, values_len;
624 if (terminal == NULL)
625 return;
627 section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
628 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
630 while (*profile_keys != NULL)
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 profile_keys++;
639 continue;
642 curr_values = values =
643 mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len);
645 key_code = lookup_key (*profile_keys, NULL);
647 if (key_code != 0)
649 if (curr_values != NULL)
651 while (*curr_values != NULL)
653 valcopy = convert_controls (*curr_values);
654 define_sequence (key_code, valcopy, MCKEY_NOACTION);
655 g_free (valcopy);
656 curr_values++;
659 else
661 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
662 valcopy = convert_controls (value);
663 define_sequence (key_code, valcopy, MCKEY_NOACTION);
664 g_free (valcopy);
665 g_free (value);
669 profile_keys++;
670 g_strfreev (values);
672 g_strfreev (keys);
673 g_free (section_name);
676 /* --------------------------------------------------------------------------------------------- */
678 static void
679 load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg)
681 gchar **profile_keys, **keys;
682 gsize len;
684 if (section_name == NULL)
685 return;
687 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
689 while (*profile_keys != NULL)
691 gchar **values, **curr_values;
693 curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &len);
695 if (curr_values != NULL)
697 int action;
699 action = keybind_lookup_action (*profile_keys);
700 if (action > 0)
701 while (*curr_values != NULL)
703 keybind_cmd_bind (keymap, *curr_values, action);
704 curr_values++;
707 g_strfreev (values);
710 profile_keys++;
713 g_strfreev (keys);
716 /* --------------------------------------------------------------------------------------------- */
718 static mc_config_t *
719 load_setup_get_keymap_profile_config (gboolean load_from_file)
722 TODO: IMHO, in future, this function shall be placed in mcconfig module.
724 mc_config_t *keymap_config;
725 char *share_keymap, *sysconfig_keymap;
726 char *fname, *fname2;
728 /* 0) Create default keymap */
729 keymap_config = create_default_keymap ();
730 if (!load_from_file)
731 return keymap_config;
733 /* load and merge global keymaps */
735 /* 1) /usr/share/mc (mc_global.share_data_dir) */
736 share_keymap = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, NULL);
737 load_setup_init_config_from_file (&keymap_config, share_keymap, TRUE);
739 /* 2) /etc/mc (mc_global.sysconfig_dir) */
740 sysconfig_keymap = g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, NULL);
741 load_setup_init_config_from_file (&keymap_config, sysconfig_keymap, TRUE);
743 /* then load and merge one of user-defined keymap */
745 /* 3) --keymap=<keymap> */
746 fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file);
747 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
749 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
750 goto done;
752 g_free (fname);
754 /* 4) getenv("MC_KEYMAP") */
755 fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
756 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
758 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
759 goto done;
761 g_free (fname);
763 /* 5) main config; [Midnight Commander] -> keymap */
764 fname2 = mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, "keymap", NULL);
765 if (fname2 != NULL && *fname2 != '\0')
766 fname = load_setup_get_full_config_name (NULL, fname2);
767 g_free (fname2);
768 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
770 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
771 goto done;
773 g_free (fname);
775 /* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */
776 fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE);
777 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
779 done:
780 g_free (fname);
781 g_free (sysconfig_keymap);
782 g_free (share_keymap);
784 return keymap_config;
787 /* --------------------------------------------------------------------------------------------- */
789 static panel_view_mode_t
790 setup__load_panel_state (const char *section)
792 char *buffer;
793 size_t i;
794 panel_view_mode_t mode = view_listing;
796 /* Load the display mode */
797 buffer = mc_config_get_string (mc_panels_config, section, "display", "listing");
799 for (i = 0; panel_types[i].opt_name != NULL; i++)
800 if (g_ascii_strcasecmp (panel_types[i].opt_name, buffer) == 0)
802 mode = panel_types[i].opt_type;
803 break;
806 g_free (buffer);
808 return mode;
811 /* --------------------------------------------------------------------------------------------- */
813 static void
814 panel_save_type (const char *section, panel_view_mode_t type)
816 size_t i;
818 for (i = 0; panel_types[i].opt_name != NULL; i++)
819 if (panel_types[i].opt_type == type)
821 mc_config_set_string (mc_panels_config, section, "display", panel_types[i].opt_name);
822 break;
826 /* --------------------------------------------------------------------------------------------- */
828 /* save panels.ini */
829 static void
830 save_panel_types (void)
832 panel_view_mode_t type;
834 if (mc_global.mc_run_mode != MC_RUN_FULL)
835 return;
837 type = get_display_type (0);
838 panel_save_type ("New Left Panel", type);
839 if (type == view_listing)
840 panel_save_setup (left_panel, left_panel->panel_name);
841 type = get_display_type (1);
842 panel_save_type ("New Right Panel", type);
843 if (type == view_listing)
844 panel_save_setup (right_panel, right_panel->panel_name);
847 char *dirs;
849 dirs = get_panel_dir_for (other_panel);
850 mc_config_set_string (mc_panels_config, "Dirs", "other_dir", dirs);
851 g_free (dirs);
854 if (current_panel != NULL)
855 mc_config_set_bool (mc_panels_config, "Dirs", "current_is_left", get_current_index () == 0);
857 if (mc_panels_config->ini_path == NULL)
858 mc_panels_config->ini_path = g_strdup (panels_profile_name);
860 mc_config_del_group (mc_panels_config, "Temporal:New Left Panel");
861 mc_config_del_group (mc_panels_config, "Temporal:New Right Panel");
863 mc_config_save_file (mc_panels_config, NULL);
866 /* --------------------------------------------------------------------------------------------- */
867 /*** public functions ****************************************************************************/
868 /* --------------------------------------------------------------------------------------------- */
870 char *
871 setup_init (void)
873 char *profile;
874 char *inifile;
876 if (profile_name != NULL)
877 return profile_name;
879 profile = mc_config_get_full_path (MC_CONFIG_FILE);
880 if (!exist_file (profile))
882 inifile = mc_build_filename (mc_global.sysconfig_dir, "mc.ini", NULL);
883 if (exist_file (inifile))
885 g_free (profile);
886 profile = inifile;
888 else
890 g_free (inifile);
891 inifile = mc_build_filename (mc_global.share_data_dir, "mc.ini", NULL);
892 if (exist_file (inifile))
894 g_free (profile);
895 profile = inifile;
897 else
898 g_free (inifile);
902 profile_name = profile;
904 return profile;
907 /* --------------------------------------------------------------------------------------------- */
909 void
910 load_setup (void)
912 char *profile;
913 size_t i;
914 char *buffer;
915 const char *kt;
917 #ifdef HAVE_CHARSET
918 load_codepages_list ();
919 #endif /* HAVE_CHARSET */
921 profile = setup_init ();
923 /* mc.lib is common for all users, but has priority lower than
924 ${XDG_CONFIG_HOME}/mc/ini. FIXME: it's only used for keys and treestore now */
925 global_profile_name =
926 g_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
927 if (!exist_file (global_profile_name))
929 g_free (global_profile_name);
930 global_profile_name =
931 g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
934 panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE);
936 mc_main_config = mc_config_init (profile, FALSE);
938 if (!exist_file (panels_profile_name))
939 setup__move_panels_config_into_separate_file (profile);
941 mc_panels_config = mc_config_init (panels_profile_name, FALSE);
943 /* Load integer boolean options */
944 for (i = 0; int_options[i].opt_name != NULL; i++)
945 *int_options[i].opt_addr =
946 mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
947 *int_options[i].opt_addr);
949 if (option_tab_spacing <= 0)
950 option_tab_spacing = DEFAULT_TAB_SPACING;
952 #ifdef USE_INTERNAL_EDIT
953 if (option_word_wrap_line_length <= 0)
954 option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
955 #endif /* USE_INTERNAL_EDIT */
957 /* overwrite old_esc_mode_timeout */
958 kt = getenv ("KEYBOARD_KEY_TIMEOUT_US");
959 if ((kt != NULL) && (kt[0] != '\0'))
960 old_esc_mode_timeout = atoi (kt);
962 /* Load string options */
963 for (i = 0; str_options[i].opt_name != NULL; i++)
964 *str_options[i].opt_addr =
965 mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
966 str_options[i].opt_defval);
968 load_layout ();
969 panels_load_options ();
970 load_panelize ();
972 startup_left_mode = setup__load_panel_state ("New Left Panel");
973 startup_right_mode = setup__load_panel_state ("New Right Panel");
975 /* At least one of the panels is a listing panel */
976 if (startup_left_mode != view_listing && startup_right_mode != view_listing)
977 startup_left_mode = view_listing;
979 if (mc_run_param1 == NULL)
981 vfs_path_t *vpath;
982 buffer = mc_config_get_string (mc_panels_config, "Dirs", "other_dir", ".");
983 vpath = vfs_path_from_str (buffer);
984 if (vfs_file_is_local (vpath))
985 mc_run_param1 = buffer;
986 else
987 g_free (buffer);
988 vfs_path_free (vpath);
991 boot_current_is_left = mc_config_get_bool (mc_panels_config, "Dirs", "current_is_left", TRUE);
993 /* Load time formats */
994 user_recent_timeformat =
995 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_recent", FMTTIME);
996 user_old_timeformat =
997 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_old", FMTYEAR);
999 #ifdef ENABLE_VFS_FTP
1000 ftpfs_proxy_host =
1001 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host", "gate");
1002 ftpfs_ignore_chattr_errors =
1003 mc_config_get_bool (mc_main_config, CONFIG_APP_SECTION, "ignore_ftp_chattr_errors", TRUE);
1004 ftpfs_init_passwd ();
1005 #endif /* ENABLE_VFS_FTP */
1007 /* The default color and the terminal dependent color */
1008 mc_global.tty.setup_color_string =
1009 mc_config_get_string (mc_main_config, "Colors", "base_color", "");
1010 mc_global.tty.term_color_string =
1011 mc_config_get_string (mc_main_config, "Colors", getenv ("TERM"), "");
1012 mc_global.tty.color_terminal_string =
1013 mc_config_get_string (mc_main_config, "Colors", "color_terminals", "");
1015 /* Load the directory history */
1016 /* directory_history_load (); */
1017 /* Remove the temporal entries */
1019 #ifdef HAVE_CHARSET
1020 if (codepages->len > 1)
1022 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage", "");
1023 if (buffer[0] != '\0')
1025 mc_global.display_codepage = get_codepage_index (buffer);
1026 cp_display = get_codepage_id (mc_global.display_codepage);
1028 g_free (buffer);
1029 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage", "");
1030 if (buffer[0] != '\0')
1032 default_source_codepage = get_codepage_index (buffer);
1033 mc_global.source_codepage = default_source_codepage; /* May be source_codepage doesn't need this */
1034 cp_source = get_codepage_id (mc_global.source_codepage);
1036 g_free (buffer);
1039 autodetect_codeset =
1040 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset", "");
1041 if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off") != 0))
1042 is_autodetect_codeset_enabled = TRUE;
1044 g_free (init_translation_table (mc_global.source_codepage, mc_global.display_codepage));
1045 buffer = (char *) get_codepage_id (mc_global.display_codepage);
1046 if (buffer != NULL)
1047 mc_global.utf8_display = str_isutf8 (buffer);
1048 #endif /* HAVE_CHARSET */
1050 #ifdef HAVE_ASPELL
1051 spell_language =
1052 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "spell_language", "en");
1053 #endif /* HAVE_ASPELL */
1055 clipboard_store_path =
1056 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store", "");
1057 clipboard_paste_path =
1058 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste", "");
1061 /* --------------------------------------------------------------------------------------------- */
1063 gboolean
1064 save_setup (gboolean save_options, gboolean save_panel_options)
1066 gboolean ret = TRUE;
1068 saving_setup = 1;
1070 save_hotlist ();
1072 if (save_panel_options)
1073 save_panel_types ();
1075 if (save_options)
1077 char *tmp_profile;
1079 save_config ();
1080 save_layout ();
1081 panels_save_options ();
1082 save_panelize ();
1083 /* directory_history_save (); */
1085 #ifdef ENABLE_VFS_FTP
1086 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "ftpfs_password",
1087 ftpfs_anonymous_passwd);
1088 if (ftpfs_proxy_host)
1089 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host",
1090 ftpfs_proxy_host);
1091 #endif /* ENABLE_VFS_FTP */
1093 #ifdef HAVE_CHARSET
1094 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage",
1095 get_codepage_id (mc_global.display_codepage));
1096 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage",
1097 get_codepage_id (default_source_codepage));
1098 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset",
1099 autodetect_codeset);
1100 #endif /* HAVE_CHARSET */
1102 #ifdef HAVE_ASPELL
1103 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "spell_language",
1104 spell_language);
1105 #endif /* HAVE_ASPELL */
1107 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store",
1108 clipboard_store_path);
1109 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste",
1110 clipboard_paste_path);
1112 tmp_profile = mc_config_get_full_path (MC_CONFIG_FILE);
1113 ret = mc_config_save_to_file (mc_main_config, tmp_profile, NULL);
1114 g_free (tmp_profile);
1117 saving_setup = 0;
1119 return ret;
1122 /* --------------------------------------------------------------------------------------------- */
1124 void
1125 done_setup (void)
1127 size_t i;
1129 g_free (clipboard_store_path);
1130 g_free (clipboard_paste_path);
1131 g_free (profile_name);
1132 g_free (global_profile_name);
1133 g_free (mc_global.tty.color_terminal_string);
1134 g_free (mc_global.tty.term_color_string);
1135 g_free (mc_global.tty.setup_color_string);
1136 g_free (panels_profile_name);
1137 mc_config_deinit (mc_main_config);
1138 mc_config_deinit (mc_panels_config);
1140 g_free (user_recent_timeformat);
1141 g_free (user_old_timeformat);
1143 for (i = 0; str_options[i].opt_name != NULL; i++)
1144 g_free (*str_options[i].opt_addr);
1146 done_hotlist ();
1147 done_panelize ();
1148 /* directory_history_free (); */
1150 #ifdef HAVE_CHARSET
1151 g_free (autodetect_codeset);
1152 free_codepages_list ();
1153 #endif
1155 #ifdef HAVE_ASPELL
1156 g_free (spell_language);
1157 #endif /* HAVE_ASPELL */
1160 /* --------------------------------------------------------------------------------------------- */
1162 void
1163 save_config (void)
1165 size_t i;
1167 /* Save integer options */
1168 for (i = 0; int_options[i].opt_name != NULL; i++)
1169 mc_config_set_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
1170 *int_options[i].opt_addr);
1172 /* Save string options */
1173 for (i = 0; str_options[i].opt_name != NULL; i++)
1174 mc_config_set_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
1175 *str_options[i].opt_addr);
1178 /* --------------------------------------------------------------------------------------------- */
1180 void
1181 setup_save_config_show_error (const char *filename, GError ** error)
1183 if (error != NULL && *error != NULL)
1185 message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*error)->message);
1186 g_error_free (*error);
1187 *error = NULL;
1191 /* --------------------------------------------------------------------------------------------- */
1193 void
1194 save_layout (void)
1196 size_t i;
1198 /* Save integer options */
1199 for (i = 0; layout[i].opt_name != NULL; i++)
1200 mc_config_set_int (mc_main_config, CONFIG_LAYOUT_SECTION, layout[i].opt_name,
1201 *layout[i].opt_addr);
1204 /* --------------------------------------------------------------------------------------------- */
1206 void
1207 load_key_defs (void)
1210 * Load keys from mc.lib before ${XDG_CONFIG_HOME}/mc/ini, so that the user
1211 * definitions override global settings.
1213 mc_config_t *mc_global_config;
1215 mc_global_config = mc_config_init (global_profile_name, FALSE);
1216 if (mc_global_config != NULL)
1218 load_keys_from_section ("general", mc_global_config);
1219 load_keys_from_section (getenv ("TERM"), mc_global_config);
1220 mc_config_deinit (mc_global_config);
1223 load_keys_from_section ("general", mc_main_config);
1224 load_keys_from_section (getenv ("TERM"), mc_main_config);
1227 /* --------------------------------------------------------------------------------------------- */
1229 #ifdef ENABLE_VFS_FTP
1230 char *
1231 load_anon_passwd (void)
1233 char *buffer;
1235 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftpfs_password", "");
1237 if ((buffer != NULL) && (buffer[0] != '\0'))
1238 return buffer;
1240 g_free (buffer);
1241 return NULL;
1243 #endif /* ENABLE_VFS_FTP */
1245 /* --------------------------------------------------------------------------------------------- */
1247 void
1248 load_keymap_defs (gboolean load_from_file)
1251 * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_CONFIG_HOME}/mc/mc.keymap, so that the user
1252 * definitions override global settings.
1254 mc_config_t *mc_global_keymap;
1256 mc_global_keymap = load_setup_get_keymap_profile_config (load_from_file);
1258 if (mc_global_keymap != NULL)
1260 main_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1261 load_keymap_from_section (KEYMAP_SECTION_MAIN, main_keymap, mc_global_keymap);
1262 main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1263 load_keymap_from_section (KEYMAP_SECTION_MAIN_EXT, main_x_keymap, mc_global_keymap);
1265 panel_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1266 load_keymap_from_section (KEYMAP_SECTION_PANEL, panel_keymap, mc_global_keymap);
1268 dialog_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1269 load_keymap_from_section (KEYMAP_SECTION_DIALOG, dialog_keymap, mc_global_keymap);
1271 input_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1272 load_keymap_from_section (KEYMAP_SECTION_INPUT, input_keymap, mc_global_keymap);
1274 listbox_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1275 load_keymap_from_section (KEYMAP_SECTION_LISTBOX, listbox_keymap, mc_global_keymap);
1277 tree_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1278 load_keymap_from_section (KEYMAP_SECTION_TREE, tree_keymap, mc_global_keymap);
1280 help_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1281 load_keymap_from_section (KEYMAP_SECTION_HELP, help_keymap, mc_global_keymap);
1283 #ifdef USE_INTERNAL_EDIT
1284 editor_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1285 load_keymap_from_section (KEYMAP_SECTION_EDITOR, editor_keymap, mc_global_keymap);
1286 editor_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1287 load_keymap_from_section (KEYMAP_SECTION_EDITOR_EXT, editor_x_keymap, mc_global_keymap);
1288 #endif
1290 viewer_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1291 load_keymap_from_section (KEYMAP_SECTION_VIEWER, viewer_keymap, mc_global_keymap);
1292 viewer_hex_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1293 load_keymap_from_section (KEYMAP_SECTION_VIEWER_HEX, viewer_hex_keymap, mc_global_keymap);
1295 #ifdef USE_DIFF_VIEW
1296 diff_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1297 load_keymap_from_section (KEYMAP_SECTION_DIFFVIEWER, diff_keymap, mc_global_keymap);
1298 #endif
1300 mc_config_deinit (mc_global_keymap);
1303 main_map = (global_keymap_t *) main_keymap->data;
1304 main_x_map = (global_keymap_t *) main_x_keymap->data;
1305 panel_map = (global_keymap_t *) panel_keymap->data;
1306 dialog_map = (global_keymap_t *) dialog_keymap->data;
1307 input_map = (global_keymap_t *) input_keymap->data;
1308 listbox_map = (global_keymap_t *) listbox_keymap->data;
1309 tree_map = (global_keymap_t *) tree_keymap->data;
1310 help_map = (global_keymap_t *) help_keymap->data;
1311 #ifdef USE_INTERNAL_EDIT
1312 editor_map = (global_keymap_t *) editor_keymap->data;
1313 editor_x_map = (global_keymap_t *) editor_x_keymap->data;
1314 #endif
1315 viewer_map = (global_keymap_t *) viewer_keymap->data;
1316 viewer_hex_map = (global_keymap_t *) viewer_hex_keymap->data;
1317 #ifdef USE_DIFF_VIEW
1318 diff_map = (global_keymap_t *) diff_keymap->data;
1319 #endif
1322 /* --------------------------------------------------------------------------------------------- */
1324 void
1325 free_keymap_defs (void)
1327 if (main_keymap != NULL)
1328 g_array_free (main_keymap, TRUE);
1329 if (main_x_keymap != NULL)
1330 g_array_free (main_x_keymap, TRUE);
1331 if (panel_keymap != NULL)
1332 g_array_free (panel_keymap, TRUE);
1333 if (dialog_keymap != NULL)
1334 g_array_free (dialog_keymap, TRUE);
1335 if (input_keymap != NULL)
1336 g_array_free (input_keymap, TRUE);
1337 if (listbox_keymap != NULL)
1338 g_array_free (listbox_keymap, TRUE);
1339 if (tree_keymap != NULL)
1340 g_array_free (tree_keymap, TRUE);
1341 if (help_keymap != NULL)
1342 g_array_free (help_keymap, TRUE);
1343 #ifdef USE_INTERNAL_EDIT
1344 if (editor_keymap != NULL)
1345 g_array_free (editor_keymap, TRUE);
1346 if (editor_x_keymap != NULL)
1347 g_array_free (editor_x_keymap, TRUE);
1348 #endif
1349 if (viewer_keymap != NULL)
1350 g_array_free (viewer_keymap, TRUE);
1351 if (viewer_hex_keymap != NULL)
1352 g_array_free (viewer_hex_keymap, TRUE);
1353 #ifdef USE_DIFF_VIEW
1354 if (diff_keymap != NULL)
1355 g_array_free (diff_keymap, TRUE);
1356 #endif
1359 /* --------------------------------------------------------------------------------------------- */
1361 void
1362 panel_load_setup (WPanel * panel, const char *section)
1364 size_t i;
1365 char *buffer, buffer2[BUF_TINY];
1367 panel->sort_info.reverse = mc_config_get_int (mc_panels_config, section, "reverse", 0);
1368 panel->sort_info.case_sensitive =
1369 mc_config_get_int (mc_panels_config, section, "case_sensitive",
1370 OS_SORT_CASE_SENSITIVE_DEFAULT);
1371 panel->sort_info.exec_first = mc_config_get_int (mc_panels_config, section, "exec_first", 0);
1373 /* Load sort order */
1374 buffer = mc_config_get_string (mc_panels_config, section, "sort_order", "name");
1375 panel->sort_info.sort_field = panel_get_field_by_id (buffer);
1376 if (panel->sort_info.sort_field == NULL)
1377 panel->sort_info.sort_field = panel_get_field_by_id ("name");
1379 g_free (buffer);
1381 /* Load the listing mode */
1382 buffer = mc_config_get_string (mc_panels_config, section, "list_mode", "full");
1383 panel->list_type = list_full;
1384 for (i = 0; list_types[i].key != NULL; i++)
1385 if (g_ascii_strcasecmp (list_types[i].key, buffer) == 0)
1387 panel->list_type = list_types[i].list_type;
1388 break;
1390 g_free (buffer);
1392 /* User formats */
1393 g_free (panel->user_format);
1394 panel->user_format =
1395 mc_config_get_string (mc_panels_config, section, "user_format", DEFAULT_USER_FORMAT);
1397 for (i = 0; i < LIST_TYPES; i++)
1399 g_free (panel->user_status_format[i]);
1400 g_snprintf (buffer2, BUF_TINY, "user_status%lld", (long long) i);
1401 panel->user_status_format[i] =
1402 mc_config_get_string (mc_panels_config, section, buffer2, DEFAULT_USER_FORMAT);
1405 panel->user_mini_status = mc_config_get_int (mc_panels_config, section, "user_mini_status", 0);
1408 /* --------------------------------------------------------------------------------------------- */
1410 void
1411 panel_save_setup (struct WPanel *panel, const char *section)
1413 char buffer[BUF_TINY];
1414 size_t i;
1416 mc_config_set_int (mc_panels_config, section, "reverse", panel->sort_info.reverse);
1417 mc_config_set_int (mc_panels_config, section, "case_sensitive",
1418 panel->sort_info.case_sensitive);
1419 mc_config_set_int (mc_panels_config, section, "exec_first", panel->sort_info.exec_first);
1421 mc_config_set_string (mc_panels_config, section, "sort_order", panel->sort_info.sort_field->id);
1423 for (i = 0; list_types[i].key != NULL; i++)
1424 if (list_types[i].list_type == panel->list_type)
1426 mc_config_set_string (mc_panels_config, section, "list_mode", list_types[i].key);
1427 break;
1430 mc_config_set_string (mc_panels_config, section, "user_format", panel->user_format);
1432 for (i = 0; i < LIST_TYPES; i++)
1434 g_snprintf (buffer, BUF_TINY, "user_status%lld", (long long) i);
1435 mc_config_set_string (mc_panels_config, section, buffer, panel->user_status_format[i]);
1438 mc_config_set_int (mc_panels_config, section, "user_mini_status", panel->user_mini_status);
1441 /* --------------------------------------------------------------------------------------------- */
1444 Load panels options from [Panels] section.
1446 void
1447 panels_load_options (void)
1449 if (mc_config_has_group (mc_main_config, CONFIG_PANELS_SECTION))
1451 size_t i;
1452 int qmode;
1454 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1455 *panels_ini_options[i].opt_addr =
1456 mc_config_get_bool (mc_main_config, CONFIG_PANELS_SECTION,
1457 panels_ini_options[i].opt_name,
1458 *panels_ini_options[i].opt_addr);
1460 qmode = mc_config_get_int (mc_main_config, CONFIG_PANELS_SECTION,
1461 "quick_search_mode", (int) panels_options.qsearch_mode);
1462 if (qmode < 0)
1463 panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE;
1464 else if (qmode >= QSEARCH_NUM)
1465 panels_options.qsearch_mode = QSEARCH_PANEL_CASE;
1466 else
1467 panels_options.qsearch_mode = (qsearch_mode_t) qmode;
1471 /* --------------------------------------------------------------------------------------------- */
1474 Save panels options in [Panels] section.
1476 void
1477 panels_save_options (void)
1479 size_t i;
1481 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1482 mc_config_set_bool (mc_main_config, CONFIG_PANELS_SECTION,
1483 panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr);
1485 mc_config_set_int (mc_main_config, CONFIG_PANELS_SECTION,
1486 "quick_search_mode", (int) panels_options.qsearch_mode);
1489 /* --------------------------------------------------------------------------------------------- */