Ticket #2944: code cleanup before 4.8.8 release.
[midnight-commander.git] / src / setup.c
blob3ac68af02643a1126d9592c379e8c90d2d5f415e
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 /* The user's shell */
201 char *shell = NULL;
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 *panels_profile_name = NULL; /* ${XDG_CACHE_HOME}/mc/panels.ini */
226 /* *INDENT-OFF* */
227 static const struct
229 const char *key;
230 int list_type;
231 } list_types [] = {
232 { "full", list_full },
233 { "brief", list_brief },
234 { "long", list_long },
235 { "user", list_user },
236 { NULL, 0 }
239 static const struct
241 const char *opt_name;
242 panel_view_mode_t opt_type;
243 } panel_types [] = {
244 { "listing", view_listing },
245 { "quickview", view_quick },
246 { "info", view_info },
247 { "tree", view_tree },
248 { NULL, view_listing }
251 static const struct
253 const char *opt_name;
254 int *opt_addr;
255 } layout [] = {
256 { "message_visible", &mc_global.message_visible },
257 { "keybar_visible", &mc_global.keybar_visible },
258 { "xterm_title", &xterm_title },
259 { "output_lines", &output_lines },
260 { "command_prompt", &command_prompt },
261 { "menubar_visible", &menubar_visible },
262 { "free_space", &free_space },
263 { "horizontal_split", &panels_layout.horizontal_split },
264 { "vertical_equal", &panels_layout.vertical_equal },
265 { "left_panel_size", &panels_layout.left_panel_size },
266 { "horizontal_equal", &panels_layout.horizontal_equal },
267 { "top_panel_size", &panels_layout.top_panel_size },
268 { NULL, NULL }
271 static const struct
273 const char *opt_name;
274 int *opt_addr;
275 } int_options [] = {
276 { "verbose", &verbose },
277 { "pause_after_run", &pause_after_run },
278 { "shell_patterns", &easy_patterns },
279 { "auto_save_setup", &auto_save_setup },
280 { "preallocate_space", &mc_global.vfs.preallocate_space },
281 { "auto_menu", &auto_menu },
282 { "use_internal_view", &use_internal_view },
283 { "use_internal_edit", &use_internal_edit },
284 { "clear_before_exec", &clear_before_exec },
285 { "confirm_delete", &confirm_delete },
286 { "confirm_overwrite", &confirm_overwrite },
287 { "confirm_execute", &confirm_execute },
288 { "confirm_history_cleanup", &mc_global.widget.confirm_history_cleanup },
289 { "confirm_exit", &confirm_exit },
290 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete },
291 { "safe_delete", &safe_delete },
292 { "mouse_repeat_rate", &mou_auto_repeat },
293 { "double_click_speed", &double_click_speed },
294 #ifndef HAVE_CHARSET
295 { "eight_bit_clean", &mc_global.eight_bit_clean },
296 { "full_eight_bits", &mc_global.full_eight_bits },
297 #endif /* !HAVE_CHARSET */
298 { "use_8th_bit_as_meta", &use_8th_bit_as_meta },
299 { "confirm_view_dir", &confirm_view_dir },
300 { "mouse_move_pages_viewer", &mcview_mouse_move_pages },
301 { "mouse_close_dialog", &mouse_close_dialog},
302 { "fast_refresh", &fast_refresh },
303 { "drop_menus", &drop_menus },
304 { "wrap_mode", &mcview_global_wrap_mode},
305 { "old_esc_mode", &old_esc_mode },
306 { "old_esc_mode_timeout", &old_esc_mode_timeout },
307 { "cd_symlinks", &mc_global.vfs.cd_symlinks },
308 { "show_all_if_ambiguous", &mc_global.widget.show_all_if_ambiguous },
309 { "max_dirt_limit", &mcview_max_dirt_limit },
310 { "use_file_to_guess_type", &use_file_to_check_type },
311 { "alternate_plus_minus", &mc_global.tty.alternate_plus_minus },
312 { "only_leading_plus_minus", &only_leading_plus_minus },
313 { "show_output_starts_shell", &output_starts_shell },
314 { "xtree_mode", &xtree_mode },
315 { "num_history_items_recorded", &num_history_items_recorded },
316 { "file_op_compute_totals", &file_op_compute_totals },
317 { "classic_progressbar", &classic_progressbar},
318 #ifdef ENABLE_VFS
319 { "vfs_timeout", &vfs_timeout },
320 #ifdef ENABLE_VFS_FTP
321 { "ftpfs_directory_timeout", &ftpfs_directory_timeout },
322 { "use_netrc", &ftpfs_use_netrc },
323 { "ftpfs_retry_seconds", &ftpfs_retry_seconds },
324 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy },
325 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections },
326 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy },
327 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options },
328 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls },
329 #endif /* ENABLE_VFS_FTP */
330 #ifdef ENABLE_VFS_FISH
331 { "fish_directory_timeout", &fish_directory_timeout },
332 #endif /* ENABLE_VFS_FISH */
333 #endif /* ENABLE_VFS */
334 /* option_tab_spacing is used in internal viewer */
335 { "editor_tab_spacing", &option_tab_spacing },
336 #ifdef USE_INTERNAL_EDIT
337 { "editor_word_wrap_line_length", &option_word_wrap_line_length },
338 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces },
339 { "editor_return_does_auto_indent", &option_return_does_auto_indent },
340 { "editor_backspace_through_tabs", &option_backspace_through_tabs },
341 { "editor_fake_half_tabs", &option_fake_half_tabs },
342 { "editor_option_save_mode", &option_save_mode },
343 { "editor_option_save_position", &option_save_position },
344 { "editor_option_auto_para_formatting", &option_auto_para_formatting },
345 { "editor_option_typewriter_wrap", &option_typewriter_wrap },
346 { "editor_edit_confirm_save", &edit_confirm_save },
347 { "editor_syntax_highlighting", &option_syntax_highlighting },
348 { "editor_persistent_selections", &option_persistent_selections },
349 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol },
350 { "editor_cursor_after_inserted_block", &option_cursor_after_inserted_block },
351 { "editor_visible_tabs", &visible_tabs },
352 { "editor_visible_spaces", &visible_tws },
353 { "editor_line_state", &option_line_state },
354 { "editor_simple_statusbar", &simple_statusbar },
355 { "editor_check_new_line", &option_check_nl_at_eof },
356 { "editor_show_right_margin", &show_right_margin },
357 { "editor_group_undo", &option_group_undo },
358 #endif /* USE_INTERNAL_EDIT */
359 { "nice_rotating_dash", &nice_rotating_dash },
360 { "mcview_remember_file_position", &mcview_remember_file_position },
361 { "auto_fill_mkdir_name", &auto_fill_mkdir_name },
362 { "copymove_persistent_attr", &setup_copymove_persistent_attr },
363 { "select_flags", &select_flags },
364 { NULL, NULL }
367 static const struct
369 const char *opt_name;
370 char **opt_addr;
371 const char *opt_defval;
372 } str_options[] = {
373 #ifdef USE_INTERNAL_EDIT
374 { "editor_backup_extension", &option_backup_ext, "~" },
375 #endif
376 { "mcview_eof", &mcview_show_eof, "" },
377 { NULL, NULL, NULL }
380 static const struct
382 const char *opt_name;
383 gboolean *opt_addr;
384 } panels_ini_options[] = {
385 { "show_mini_info", &panels_options.show_mini_info },
386 { "kilobyte_si", &panels_options.kilobyte_si },
387 { "mix_all_files", &panels_options.mix_all_files },
388 { "show_backups", &panels_options.show_backups },
389 { "show_dot_files", &panels_options.show_dot_files },
390 { "fast_reload", &panels_options.fast_reload },
391 { "fast_reload_msg_shown", &panels_options.fast_reload_msg_shown },
392 { "mark_moves_down", &panels_options.mark_moves_down },
393 { "reverse_files_only", &panels_options.reverse_files_only },
394 { "auto_save_setup_panels", &panels_options.auto_save_setup },
395 { "navigate_with_arrows", &panels_options.navigate_with_arrows },
396 { "panel_scroll_pages", &panels_options.scroll_pages },
397 { "mouse_move_pages", &panels_options.mouse_move_pages },
398 { "filetype_mode", &panels_options.filetype_mode },
399 { "permission_mode", &panels_options.permission_mode },
400 { "torben_fj_mode", &panels_options.torben_fj_mode },
401 { NULL, NULL }
403 /* *INDENT-ON* */
405 /*** file scope functions ************************************************************************/
406 /* --------------------------------------------------------------------------------------------- */
409 * Get name of config file.
411 * @param subdir If not NULL, config is also searched in specified subdir.
412 * @param config_file_name If relative, file if searched in standard paths.
414 * @return newly allocated string with config name or NULL if file is not found.
417 static char *
418 load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
421 TODO: IMHO, in future, this function shall be placed in mcconfig module.
423 char *lc_basename, *ret;
424 char *file_name;
426 if (config_file_name == NULL)
427 return NULL;
429 /* check for .keymap suffix */
430 if (g_str_has_suffix (config_file_name, ".keymap"))
431 file_name = g_strdup (config_file_name);
432 else
433 file_name = g_strconcat (config_file_name, ".keymap", (char *) NULL);
435 canonicalize_pathname (file_name);
437 if (g_path_is_absolute (file_name))
438 return file_name;
440 lc_basename = g_path_get_basename (file_name);
441 g_free (file_name);
443 if (lc_basename == NULL)
444 return NULL;
446 if (subdir != NULL)
447 ret = g_build_filename (mc_config_get_path (), subdir, lc_basename, NULL);
448 else
449 ret = g_build_filename (mc_config_get_path (), lc_basename, NULL);
451 if (exist_file (ret))
453 g_free (lc_basename);
454 canonicalize_pathname (ret);
455 return ret;
457 g_free (ret);
459 if (subdir != NULL)
460 ret = g_build_filename (mc_global.sysconfig_dir, subdir, lc_basename, NULL);
461 else
462 ret = g_build_filename (mc_global.sysconfig_dir, lc_basename, NULL);
464 if (exist_file (ret))
466 g_free (lc_basename);
467 canonicalize_pathname (ret);
468 return ret;
470 g_free (ret);
472 if (subdir != NULL)
473 ret = g_build_filename (mc_global.share_data_dir, subdir, lc_basename, NULL);
474 else
475 ret = g_build_filename (mc_global.share_data_dir, lc_basename, NULL);
477 g_free (lc_basename);
479 if (exist_file (ret))
481 canonicalize_pathname (ret);
482 return ret;
485 g_free (ret);
486 return NULL;
489 /* --------------------------------------------------------------------------------------------- */
491 static const char *
492 setup__is_cfg_group_must_panel_config (const char *grp)
494 return (!strcasecmp ("Dirs", grp) ||
495 !strcasecmp ("Temporal:New Right Panel", grp) ||
496 !strcasecmp ("Temporal:New Left Panel", grp) ||
497 !strcasecmp ("New Left Panel", grp) || !strcasecmp ("New Right Panel", grp))
498 ? grp : NULL;
501 /* --------------------------------------------------------------------------------------------- */
503 static void
504 setup__move_panels_config_into_separate_file (const char *profile)
506 mc_config_t *tmp_cfg;
507 char **groups, **curr_grp;
508 const char *need_grp;
510 if (!exist_file (profile))
511 return;
513 tmp_cfg = mc_config_init (profile, FALSE);
514 if (!tmp_cfg)
515 return;
517 curr_grp = groups = mc_config_get_groups (tmp_cfg, NULL);
518 if (!groups)
520 mc_config_deinit (tmp_cfg);
521 return;
524 while (*curr_grp)
526 if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL)
527 mc_config_del_group (tmp_cfg, *curr_grp);
528 curr_grp++;
531 mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
532 mc_config_deinit (tmp_cfg);
534 tmp_cfg = mc_config_init (profile, FALSE);
535 if (!tmp_cfg)
537 g_strfreev (groups);
538 return;
541 curr_grp = groups;
543 while (*curr_grp)
545 need_grp = setup__is_cfg_group_must_panel_config (*curr_grp);
546 if (need_grp != NULL)
548 mc_config_del_group (tmp_cfg, need_grp);
550 curr_grp++;
552 g_strfreev (groups);
554 mc_config_save_file (tmp_cfg, NULL);
555 mc_config_deinit (tmp_cfg);
558 /* --------------------------------------------------------------------------------------------- */
560 Create new mc_config object from specified ini-file or
561 append data to existing mc_config object from ini-file
564 static void
565 load_setup_init_config_from_file (mc_config_t ** config, const char *fname, gboolean read_only)
568 TODO: IMHO, in future, this function shall be placed in mcconfig module.
570 if (exist_file (fname))
572 if (*config != NULL)
573 mc_config_read_file (*config, fname, read_only, TRUE);
574 else
575 *config = mc_config_init (fname, read_only);
579 /* --------------------------------------------------------------------------------------------- */
581 static void
582 load_layout (void)
584 size_t i;
585 int equal_split;
586 int first_panel_size;
588 /* legacy options */
589 panels_layout.horizontal_split = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
590 "horizontal_split", 0);
591 equal_split = mc_config_get_int (mc_main_config, "Layout", "equal_split", 1);
592 first_panel_size = mc_config_get_int (mc_main_config, "Layout", "first_panel_size", 1);
593 if (panels_layout.horizontal_split)
595 panels_layout.horizontal_equal = equal_split;
596 panels_layout.left_panel_size = first_panel_size;
598 else
600 panels_layout.vertical_equal = equal_split;
601 panels_layout.top_panel_size = first_panel_size;
604 /* actual options override legacy ones */
605 for (i = 0; layout[i].opt_name != NULL; i++)
606 *layout[i].opt_addr = mc_config_get_int (mc_main_config, CONFIG_LAYOUT_SECTION,
607 layout[i].opt_name, *layout[i].opt_addr);
609 /* remove legacy options */
610 mc_config_del_key (mc_main_config, CONFIG_APP_SECTION, "horizontal_split");
611 mc_config_del_key (mc_main_config, "Layout", "equal_split");
612 mc_config_del_key (mc_main_config, "Layout", "first_panel_size");
615 /* --------------------------------------------------------------------------------------------- */
617 static void
618 load_keys_from_section (const char *terminal, mc_config_t * cfg)
620 char *section_name;
621 gchar **profile_keys, **keys;
622 gchar **values, **curr_values;
623 char *valcopy, *value;
624 long key_code;
625 gsize len, values_len;
627 if (terminal == NULL)
628 return;
630 section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
631 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
633 while (*profile_keys != NULL)
635 /* copy=other causes all keys from [terminal:other] to be loaded. */
636 if (g_ascii_strcasecmp (*profile_keys, "copy") == 0)
638 valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
639 load_keys_from_section (valcopy, cfg);
640 g_free (valcopy);
641 profile_keys++;
642 continue;
645 curr_values = values =
646 mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len);
648 key_code = lookup_key (*profile_keys, NULL);
650 if (key_code != 0)
652 if (curr_values != NULL)
654 while (*curr_values != NULL)
656 valcopy = convert_controls (*curr_values);
657 define_sequence (key_code, valcopy, MCKEY_NOACTION);
658 g_free (valcopy);
659 curr_values++;
662 else
664 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
665 valcopy = convert_controls (value);
666 define_sequence (key_code, valcopy, MCKEY_NOACTION);
667 g_free (valcopy);
668 g_free (value);
672 profile_keys++;
673 g_strfreev (values);
675 g_strfreev (keys);
676 g_free (section_name);
679 /* --------------------------------------------------------------------------------------------- */
681 static void
682 load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg)
684 gchar **profile_keys, **keys;
685 gsize len;
687 if (section_name == NULL)
688 return;
690 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
692 while (*profile_keys != NULL)
694 gchar **values, **curr_values;
696 curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &len);
698 if (curr_values != NULL)
700 int action;
702 action = keybind_lookup_action (*profile_keys);
703 if (action > 0)
704 while (*curr_values != NULL)
706 keybind_cmd_bind (keymap, *curr_values, action);
707 curr_values++;
710 g_strfreev (values);
713 profile_keys++;
716 g_strfreev (keys);
719 /* --------------------------------------------------------------------------------------------- */
721 static mc_config_t *
722 load_setup_get_keymap_profile_config (gboolean load_from_file)
725 TODO: IMHO, in future, this function shall be placed in mcconfig module.
727 mc_config_t *keymap_config;
728 char *share_keymap, *sysconfig_keymap;
729 char *fname, *fname2;
731 /* 0) Create default keymap */
732 keymap_config = create_default_keymap ();
733 if (!load_from_file)
734 return keymap_config;
736 /* load and merge global keymaps */
738 /* 1) /usr/share/mc (mc_global.share_data_dir) */
739 share_keymap = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, NULL);
740 load_setup_init_config_from_file (&keymap_config, share_keymap, TRUE);
742 /* 2) /etc/mc (mc_global.sysconfig_dir) */
743 sysconfig_keymap = g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, NULL);
744 load_setup_init_config_from_file (&keymap_config, sysconfig_keymap, TRUE);
746 /* then load and merge one of user-defined keymap */
748 /* 3) --keymap=<keymap> */
749 fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file);
750 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
752 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
753 goto done;
755 g_free (fname);
757 /* 4) getenv("MC_KEYMAP") */
758 fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
759 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
761 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
762 goto done;
764 g_free (fname);
766 /* 5) main config; [Midnight Commander] -> keymap */
767 fname2 = mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, "keymap", NULL);
768 if (fname2 != NULL && *fname2 != '\0')
769 fname = load_setup_get_full_config_name (NULL, fname2);
770 g_free (fname2);
771 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
773 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
774 goto done;
776 g_free (fname);
778 /* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */
779 fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE);
780 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
782 done:
783 g_free (fname);
784 g_free (sysconfig_keymap);
785 g_free (share_keymap);
787 return keymap_config;
790 /* --------------------------------------------------------------------------------------------- */
792 static panel_view_mode_t
793 setup__load_panel_state (const char *section)
795 char *buffer;
796 size_t i;
797 panel_view_mode_t mode = view_listing;
799 /* Load the display mode */
800 buffer = mc_config_get_string (mc_panels_config, section, "display", "listing");
802 for (i = 0; panel_types[i].opt_name != NULL; i++)
803 if (g_ascii_strcasecmp (panel_types[i].opt_name, buffer) == 0)
805 mode = panel_types[i].opt_type;
806 break;
809 g_free (buffer);
811 return mode;
814 /* --------------------------------------------------------------------------------------------- */
816 static void
817 panel_save_type (const char *section, panel_view_mode_t type)
819 size_t i;
821 for (i = 0; panel_types[i].opt_name != NULL; i++)
822 if (panel_types[i].opt_type == type)
824 mc_config_set_string (mc_panels_config, section, "display", panel_types[i].opt_name);
825 break;
829 /* --------------------------------------------------------------------------------------------- */
831 /* save panels.ini */
832 static void
833 save_panel_types (void)
835 panel_view_mode_t type;
837 if (mc_global.mc_run_mode != MC_RUN_FULL)
838 return;
840 type = get_display_type (0);
841 panel_save_type ("New Left Panel", type);
842 if (type == view_listing)
843 panel_save_setup (left_panel, left_panel->panel_name);
844 type = get_display_type (1);
845 panel_save_type ("New Right Panel", type);
846 if (type == view_listing)
847 panel_save_setup (right_panel, right_panel->panel_name);
850 char *dirs;
852 dirs = get_panel_dir_for (other_panel);
853 mc_config_set_string (mc_panels_config, "Dirs", "other_dir", dirs);
854 g_free (dirs);
857 if (current_panel != NULL)
858 mc_config_set_bool (mc_panels_config, "Dirs", "current_is_left", get_current_index () == 0);
860 if (mc_panels_config->ini_path == NULL)
861 mc_panels_config->ini_path = g_strdup (panels_profile_name);
863 mc_config_del_group (mc_panels_config, "Temporal:New Left Panel");
864 mc_config_del_group (mc_panels_config, "Temporal:New Right Panel");
866 mc_config_save_file (mc_panels_config, NULL);
869 /* --------------------------------------------------------------------------------------------- */
870 /*** public functions ****************************************************************************/
871 /* --------------------------------------------------------------------------------------------- */
873 char *
874 setup_init (void)
876 char *profile;
877 char *inifile;
879 if (profile_name != NULL)
880 return profile_name;
882 profile = mc_config_get_full_path (MC_CONFIG_FILE);
883 if (!exist_file (profile))
885 inifile = mc_build_filename (mc_global.sysconfig_dir, "mc.ini", NULL);
886 if (exist_file (inifile))
888 g_free (profile);
889 profile = inifile;
891 else
893 g_free (inifile);
894 inifile = mc_build_filename (mc_global.share_data_dir, "mc.ini", NULL);
895 if (exist_file (inifile))
897 g_free (profile);
898 profile = inifile;
900 else
901 g_free (inifile);
905 profile_name = profile;
907 return profile;
910 /* --------------------------------------------------------------------------------------------- */
912 void
913 load_setup (void)
915 char *profile;
916 size_t i;
917 char *buffer;
918 const char *kt;
920 #ifdef HAVE_CHARSET
921 load_codepages_list ();
922 #endif /* HAVE_CHARSET */
924 profile = setup_init ();
926 /* mc.lib is common for all users, but has priority lower than
927 ${XDG_CONFIG_HOME}/mc/ini. FIXME: it's only used for keys and treestore now */
928 global_profile_name =
929 g_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
930 if (!exist_file (global_profile_name))
932 g_free (global_profile_name);
933 global_profile_name =
934 g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
937 panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE);
939 mc_main_config = mc_config_init (profile, FALSE);
941 if (!exist_file (panels_profile_name))
942 setup__move_panels_config_into_separate_file (profile);
944 mc_panels_config = mc_config_init (panels_profile_name, FALSE);
946 /* Load integer boolean options */
947 for (i = 0; int_options[i].opt_name != NULL; i++)
948 *int_options[i].opt_addr =
949 mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
950 *int_options[i].opt_addr);
952 if (option_tab_spacing <= 0)
953 option_tab_spacing = DEFAULT_TAB_SPACING;
955 #ifdef USE_INTERNAL_EDIT
956 if (option_word_wrap_line_length <= 0)
957 option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
958 #endif /* USE_INTERNAL_EDIT */
960 /* overwrite old_esc_mode_timeout */
961 kt = getenv ("KEYBOARD_KEY_TIMEOUT_US");
962 if ((kt != NULL) && (kt[0] != '\0'))
963 old_esc_mode_timeout = atoi (kt);
965 /* Load string options */
966 for (i = 0; str_options[i].opt_name != NULL; i++)
967 *str_options[i].opt_addr =
968 mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
969 str_options[i].opt_defval);
971 load_layout ();
972 panels_load_options ();
973 load_panelize ();
975 startup_left_mode = setup__load_panel_state ("New Left Panel");
976 startup_right_mode = setup__load_panel_state ("New Right Panel");
978 /* At least one of the panels is a listing panel */
979 if (startup_left_mode != view_listing && startup_right_mode != view_listing)
980 startup_left_mode = view_listing;
982 if (mc_run_param1 == NULL)
984 vfs_path_t *vpath;
985 buffer = mc_config_get_string (mc_panels_config, "Dirs", "other_dir", ".");
986 vpath = vfs_path_from_str (buffer);
987 if (vfs_file_is_local (vpath))
988 mc_run_param1 = buffer;
989 else
990 g_free (buffer);
991 vfs_path_free (vpath);
994 boot_current_is_left = mc_config_get_bool (mc_panels_config, "Dirs", "current_is_left", TRUE);
996 /* Load time formats */
997 user_recent_timeformat =
998 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_recent", FMTTIME);
999 user_old_timeformat =
1000 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_old", FMTYEAR);
1002 #ifdef ENABLE_VFS_FTP
1003 ftpfs_proxy_host =
1004 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host", "gate");
1005 ftpfs_ignore_chattr_errors =
1006 mc_config_get_bool (mc_main_config, CONFIG_APP_SECTION, "ignore_ftp_chattr_errors", TRUE);
1007 ftpfs_init_passwd ();
1008 #endif /* ENABLE_VFS_FTP */
1010 /* The default color and the terminal dependent color */
1011 mc_global.tty.setup_color_string =
1012 mc_config_get_string (mc_main_config, "Colors", "base_color", "");
1013 mc_global.tty.term_color_string =
1014 mc_config_get_string (mc_main_config, "Colors", getenv ("TERM"), "");
1015 mc_global.tty.color_terminal_string =
1016 mc_config_get_string (mc_main_config, "Colors", "color_terminals", "");
1018 /* Load the directory history */
1019 /* directory_history_load (); */
1020 /* Remove the temporal entries */
1022 #ifdef HAVE_CHARSET
1023 if (codepages->len > 1)
1025 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage", "");
1026 if (buffer[0] != '\0')
1028 mc_global.display_codepage = get_codepage_index (buffer);
1029 cp_display = get_codepage_id (mc_global.display_codepage);
1031 g_free (buffer);
1032 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage", "");
1033 if (buffer[0] != '\0')
1035 default_source_codepage = get_codepage_index (buffer);
1036 mc_global.source_codepage = default_source_codepage; /* May be source_codepage doesn't need this */
1037 cp_source = get_codepage_id (mc_global.source_codepage);
1039 g_free (buffer);
1042 autodetect_codeset =
1043 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset", "");
1044 if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off") != 0))
1045 is_autodetect_codeset_enabled = TRUE;
1047 g_free (init_translation_table (mc_global.source_codepage, mc_global.display_codepage));
1048 buffer = (char *) get_codepage_id (mc_global.display_codepage);
1049 if (buffer != NULL)
1050 mc_global.utf8_display = str_isutf8 (buffer);
1051 #endif /* HAVE_CHARSET */
1053 #ifdef HAVE_ASPELL
1054 spell_language =
1055 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "spell_language", "en");
1056 #endif /* HAVE_ASPELL */
1058 clipboard_store_path =
1059 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store", "");
1060 clipboard_paste_path =
1061 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste", "");
1064 /* --------------------------------------------------------------------------------------------- */
1066 gboolean
1067 save_setup (gboolean save_options, gboolean save_panel_options)
1069 gboolean ret = TRUE;
1071 saving_setup = 1;
1073 save_hotlist ();
1075 if (save_panel_options)
1076 save_panel_types ();
1078 if (save_options)
1080 char *tmp_profile;
1082 save_config ();
1083 save_layout ();
1084 panels_save_options ();
1085 save_panelize ();
1086 /* directory_history_save (); */
1088 #ifdef ENABLE_VFS_FTP
1089 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "ftpfs_password",
1090 ftpfs_anonymous_passwd);
1091 if (ftpfs_proxy_host)
1092 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host",
1093 ftpfs_proxy_host);
1094 #endif /* ENABLE_VFS_FTP */
1096 #ifdef HAVE_CHARSET
1097 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage",
1098 get_codepage_id (mc_global.display_codepage));
1099 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage",
1100 get_codepage_id (default_source_codepage));
1101 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset",
1102 autodetect_codeset);
1103 #endif /* HAVE_CHARSET */
1105 #ifdef HAVE_ASPELL
1106 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "spell_language",
1107 spell_language);
1108 #endif /* HAVE_ASPELL */
1110 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store",
1111 clipboard_store_path);
1112 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste",
1113 clipboard_paste_path);
1115 tmp_profile = mc_config_get_full_path (MC_CONFIG_FILE);
1116 ret = mc_config_save_to_file (mc_main_config, tmp_profile, NULL);
1117 g_free (tmp_profile);
1120 saving_setup = 0;
1122 return ret;
1125 /* --------------------------------------------------------------------------------------------- */
1127 void
1128 done_setup (void)
1130 size_t i;
1132 g_free (clipboard_store_path);
1133 g_free (clipboard_paste_path);
1134 g_free (profile_name);
1135 g_free (global_profile_name);
1136 g_free (mc_global.tty.color_terminal_string);
1137 g_free (mc_global.tty.term_color_string);
1138 g_free (mc_global.tty.setup_color_string);
1139 g_free (panels_profile_name);
1140 mc_config_deinit (mc_main_config);
1141 mc_config_deinit (mc_panels_config);
1143 g_free (user_recent_timeformat);
1144 g_free (user_old_timeformat);
1146 for (i = 0; str_options[i].opt_name != NULL; i++)
1147 g_free (*str_options[i].opt_addr);
1149 done_hotlist ();
1150 done_panelize ();
1151 /* directory_history_free (); */
1153 #ifdef HAVE_CHARSET
1154 g_free (autodetect_codeset);
1155 free_codepages_list ();
1156 #endif
1158 #ifdef HAVE_ASPELL
1159 g_free (spell_language);
1160 #endif /* HAVE_ASPELL */
1163 /* --------------------------------------------------------------------------------------------- */
1165 void
1166 save_config (void)
1168 size_t i;
1170 /* Save integer options */
1171 for (i = 0; int_options[i].opt_name != NULL; i++)
1172 mc_config_set_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
1173 *int_options[i].opt_addr);
1175 /* Save string options */
1176 for (i = 0; str_options[i].opt_name != NULL; i++)
1177 mc_config_set_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
1178 *str_options[i].opt_addr);
1181 /* --------------------------------------------------------------------------------------------- */
1183 void
1184 setup_save_config_show_error (const char *filename, GError ** error)
1186 if (error != NULL && *error != NULL)
1188 message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*error)->message);
1189 g_error_free (*error);
1190 *error = NULL;
1194 /* --------------------------------------------------------------------------------------------- */
1196 void
1197 save_layout (void)
1199 size_t i;
1201 /* Save integer options */
1202 for (i = 0; layout[i].opt_name != NULL; i++)
1203 mc_config_set_int (mc_main_config, CONFIG_LAYOUT_SECTION, layout[i].opt_name,
1204 *layout[i].opt_addr);
1207 /* --------------------------------------------------------------------------------------------- */
1209 void
1210 load_key_defs (void)
1213 * Load keys from mc.lib before ${XDG_CONFIG_HOME}/mc/ini, so that the user
1214 * definitions override global settings.
1216 mc_config_t *mc_global_config;
1218 mc_global_config = mc_config_init (global_profile_name, FALSE);
1219 if (mc_global_config != NULL)
1221 load_keys_from_section ("general", mc_global_config);
1222 load_keys_from_section (getenv ("TERM"), mc_global_config);
1223 mc_config_deinit (mc_global_config);
1226 load_keys_from_section ("general", mc_main_config);
1227 load_keys_from_section (getenv ("TERM"), mc_main_config);
1230 /* --------------------------------------------------------------------------------------------- */
1232 #ifdef ENABLE_VFS_FTP
1233 char *
1234 load_anon_passwd (void)
1236 char *buffer;
1238 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftpfs_password", "");
1240 if ((buffer != NULL) && (buffer[0] != '\0'))
1241 return buffer;
1243 g_free (buffer);
1244 return NULL;
1246 #endif /* ENABLE_VFS_FTP */
1248 /* --------------------------------------------------------------------------------------------- */
1250 void
1251 load_keymap_defs (gboolean load_from_file)
1254 * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_CONFIG_HOME}/mc/mc.keymap, so that the user
1255 * definitions override global settings.
1257 mc_config_t *mc_global_keymap;
1259 mc_global_keymap = load_setup_get_keymap_profile_config (load_from_file);
1261 if (mc_global_keymap != NULL)
1263 main_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1264 load_keymap_from_section (KEYMAP_SECTION_MAIN, main_keymap, mc_global_keymap);
1265 main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1266 load_keymap_from_section (KEYMAP_SECTION_MAIN_EXT, main_x_keymap, mc_global_keymap);
1268 panel_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1269 load_keymap_from_section (KEYMAP_SECTION_PANEL, panel_keymap, mc_global_keymap);
1271 dialog_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1272 load_keymap_from_section (KEYMAP_SECTION_DIALOG, dialog_keymap, mc_global_keymap);
1274 input_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1275 load_keymap_from_section (KEYMAP_SECTION_INPUT, input_keymap, mc_global_keymap);
1277 listbox_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1278 load_keymap_from_section (KEYMAP_SECTION_LISTBOX, listbox_keymap, mc_global_keymap);
1280 tree_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1281 load_keymap_from_section (KEYMAP_SECTION_TREE, tree_keymap, mc_global_keymap);
1283 help_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1284 load_keymap_from_section (KEYMAP_SECTION_HELP, help_keymap, mc_global_keymap);
1286 #ifdef USE_INTERNAL_EDIT
1287 editor_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1288 load_keymap_from_section (KEYMAP_SECTION_EDITOR, editor_keymap, mc_global_keymap);
1289 editor_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1290 load_keymap_from_section (KEYMAP_SECTION_EDITOR_EXT, editor_x_keymap, mc_global_keymap);
1291 #endif
1293 viewer_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1294 load_keymap_from_section (KEYMAP_SECTION_VIEWER, viewer_keymap, mc_global_keymap);
1295 viewer_hex_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1296 load_keymap_from_section (KEYMAP_SECTION_VIEWER_HEX, viewer_hex_keymap, mc_global_keymap);
1298 #ifdef USE_DIFF_VIEW
1299 diff_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1300 load_keymap_from_section (KEYMAP_SECTION_DIFFVIEWER, diff_keymap, mc_global_keymap);
1301 #endif
1303 mc_config_deinit (mc_global_keymap);
1306 main_map = (global_keymap_t *) main_keymap->data;
1307 main_x_map = (global_keymap_t *) main_x_keymap->data;
1308 panel_map = (global_keymap_t *) panel_keymap->data;
1309 dialog_map = (global_keymap_t *) dialog_keymap->data;
1310 input_map = (global_keymap_t *) input_keymap->data;
1311 listbox_map = (global_keymap_t *) listbox_keymap->data;
1312 tree_map = (global_keymap_t *) tree_keymap->data;
1313 help_map = (global_keymap_t *) help_keymap->data;
1314 #ifdef USE_INTERNAL_EDIT
1315 editor_map = (global_keymap_t *) editor_keymap->data;
1316 editor_x_map = (global_keymap_t *) editor_x_keymap->data;
1317 #endif
1318 viewer_map = (global_keymap_t *) viewer_keymap->data;
1319 viewer_hex_map = (global_keymap_t *) viewer_hex_keymap->data;
1320 #ifdef USE_DIFF_VIEW
1321 diff_map = (global_keymap_t *) diff_keymap->data;
1322 #endif
1325 /* --------------------------------------------------------------------------------------------- */
1327 void
1328 free_keymap_defs (void)
1330 if (main_keymap != NULL)
1331 g_array_free (main_keymap, TRUE);
1332 if (main_x_keymap != NULL)
1333 g_array_free (main_x_keymap, TRUE);
1334 if (panel_keymap != NULL)
1335 g_array_free (panel_keymap, TRUE);
1336 if (dialog_keymap != NULL)
1337 g_array_free (dialog_keymap, TRUE);
1338 if (input_keymap != NULL)
1339 g_array_free (input_keymap, TRUE);
1340 if (listbox_keymap != NULL)
1341 g_array_free (listbox_keymap, TRUE);
1342 if (tree_keymap != NULL)
1343 g_array_free (tree_keymap, TRUE);
1344 if (help_keymap != NULL)
1345 g_array_free (help_keymap, TRUE);
1346 #ifdef USE_INTERNAL_EDIT
1347 if (editor_keymap != NULL)
1348 g_array_free (editor_keymap, TRUE);
1349 if (editor_x_keymap != NULL)
1350 g_array_free (editor_x_keymap, TRUE);
1351 #endif
1352 if (viewer_keymap != NULL)
1353 g_array_free (viewer_keymap, TRUE);
1354 if (viewer_hex_keymap != NULL)
1355 g_array_free (viewer_hex_keymap, TRUE);
1356 #ifdef USE_DIFF_VIEW
1357 if (diff_keymap != NULL)
1358 g_array_free (diff_keymap, TRUE);
1359 #endif
1362 /* --------------------------------------------------------------------------------------------- */
1364 void
1365 panel_load_setup (WPanel * panel, const char *section)
1367 size_t i;
1368 char *buffer, buffer2[BUF_TINY];
1370 panel->sort_info.reverse = mc_config_get_int (mc_panels_config, section, "reverse", 0);
1371 panel->sort_info.case_sensitive =
1372 mc_config_get_int (mc_panels_config, section, "case_sensitive",
1373 OS_SORT_CASE_SENSITIVE_DEFAULT);
1374 panel->sort_info.exec_first = mc_config_get_int (mc_panels_config, section, "exec_first", 0);
1376 /* Load sort order */
1377 buffer = mc_config_get_string (mc_panels_config, section, "sort_order", "name");
1378 panel->sort_info.sort_field = panel_get_field_by_id (buffer);
1379 if (panel->sort_info.sort_field == NULL)
1380 panel->sort_info.sort_field = panel_get_field_by_id ("name");
1382 g_free (buffer);
1384 /* Load the listing mode */
1385 buffer = mc_config_get_string (mc_panels_config, section, "list_mode", "full");
1386 panel->list_type = list_full;
1387 for (i = 0; list_types[i].key != NULL; i++)
1388 if (g_ascii_strcasecmp (list_types[i].key, buffer) == 0)
1390 panel->list_type = list_types[i].list_type;
1391 break;
1393 g_free (buffer);
1395 /* User formats */
1396 g_free (panel->user_format);
1397 panel->user_format =
1398 mc_config_get_string (mc_panels_config, section, "user_format", DEFAULT_USER_FORMAT);
1400 for (i = 0; i < LIST_TYPES; i++)
1402 g_free (panel->user_status_format[i]);
1403 g_snprintf (buffer2, BUF_TINY, "user_status%lld", (long long) i);
1404 panel->user_status_format[i] =
1405 mc_config_get_string (mc_panels_config, section, buffer2, DEFAULT_USER_FORMAT);
1408 panel->user_mini_status = mc_config_get_int (mc_panels_config, section, "user_mini_status", 0);
1411 /* --------------------------------------------------------------------------------------------- */
1413 void
1414 panel_save_setup (struct WPanel *panel, const char *section)
1416 char buffer[BUF_TINY];
1417 size_t i;
1419 mc_config_set_int (mc_panels_config, section, "reverse", panel->sort_info.reverse);
1420 mc_config_set_int (mc_panels_config, section, "case_sensitive",
1421 panel->sort_info.case_sensitive);
1422 mc_config_set_int (mc_panels_config, section, "exec_first", panel->sort_info.exec_first);
1424 mc_config_set_string (mc_panels_config, section, "sort_order", panel->sort_info.sort_field->id);
1426 for (i = 0; list_types[i].key != NULL; i++)
1427 if (list_types[i].list_type == panel->list_type)
1429 mc_config_set_string (mc_panels_config, section, "list_mode", list_types[i].key);
1430 break;
1433 mc_config_set_string (mc_panels_config, section, "user_format", panel->user_format);
1435 for (i = 0; i < LIST_TYPES; i++)
1437 g_snprintf (buffer, BUF_TINY, "user_status%lld", (long long) i);
1438 mc_config_set_string (mc_panels_config, section, buffer, panel->user_status_format[i]);
1441 mc_config_set_int (mc_panels_config, section, "user_mini_status", panel->user_mini_status);
1444 /* --------------------------------------------------------------------------------------------- */
1447 Load panels options from [Panels] section.
1449 void
1450 panels_load_options (void)
1452 if (mc_config_has_group (mc_main_config, CONFIG_PANELS_SECTION))
1454 size_t i;
1455 int qmode;
1457 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1458 *panels_ini_options[i].opt_addr =
1459 mc_config_get_bool (mc_main_config, CONFIG_PANELS_SECTION,
1460 panels_ini_options[i].opt_name,
1461 *panels_ini_options[i].opt_addr);
1463 qmode = mc_config_get_int (mc_main_config, CONFIG_PANELS_SECTION,
1464 "quick_search_mode", (int) panels_options.qsearch_mode);
1465 if (qmode < 0)
1466 panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE;
1467 else if (qmode >= QSEARCH_NUM)
1468 panels_options.qsearch_mode = QSEARCH_PANEL_CASE;
1469 else
1470 panels_options.qsearch_mode = (qsearch_mode_t) qmode;
1474 /* --------------------------------------------------------------------------------------------- */
1477 Save panels options in [Panels] section.
1479 void
1480 panels_save_options (void)
1482 size_t i;
1484 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1485 mc_config_set_bool (mc_main_config, CONFIG_PANELS_SECTION,
1486 panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr);
1488 mc_config_set_int (mc_main_config, CONFIG_PANELS_SECTION,
1489 "quick_search_mode", (int) panels_options.qsearch_mode);
1492 /* --------------------------------------------------------------------------------------------- */