Allow define keymap file without .keymap extension
[midnight-commander.git] / src / setup.c
blob524a4be2f654a1299f550f17a053c42b93c6b606
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 /*** file scope macro definitions ****************************************************************/
180 /* In order to use everywhere the same setup for the locale we use defines */
181 #define FMTYEAR _("%b %e %Y")
182 #define FMTTIME _("%b %e %H:%M")
184 /*** file scope type declarations ****************************************************************/
186 /*** file scope variables ************************************************************************/
188 static char *panels_profile_name = NULL; /* ${XDG_CACHE_HOME}/mc/panels.ini */
190 /* *INDENT-OFF* */
191 static const struct
193 const char *key;
194 int list_type;
195 } list_types [] = {
196 { "full", list_full },
197 { "brief", list_brief },
198 { "long", list_long },
199 { "user", list_user },
200 { NULL, 0 }
203 static const struct
205 const char *opt_name;
206 panel_view_mode_t opt_type;
207 } panel_types [] = {
208 { "listing", view_listing },
209 { "quickview", view_quick },
210 { "info", view_info },
211 { "tree", view_tree },
212 { NULL, view_listing }
215 static const struct
217 const char *opt_name;
218 int *opt_addr;
219 } layout [] = {
220 { "message_visible", &mc_global.message_visible },
221 { "keybar_visible", &mc_global.keybar_visible },
222 { "xterm_title", &xterm_title },
223 { "output_lines", &output_lines },
224 { "command_prompt", &command_prompt },
225 { "menubar_visible", &menubar_visible },
226 { "free_space", &free_space },
227 { "horizontal_split", &panels_layout.horizontal_split },
228 { "vertical_equal", &panels_layout.vertical_equal },
229 { "left_panel_size", &panels_layout.left_panel_size },
230 { "horizontal_equal", &panels_layout.horizontal_equal },
231 { "top_panel_size", &panels_layout.top_panel_size },
232 { NULL, NULL }
235 static const struct
237 const char *opt_name;
238 int *opt_addr;
239 } int_options [] = {
240 { "verbose", &verbose },
241 { "pause_after_run", &pause_after_run },
242 { "shell_patterns", &easy_patterns },
243 { "auto_save_setup", &auto_save_setup },
244 { "preallocate_space", &mc_global.vfs.preallocate_space },
245 { "auto_menu", &auto_menu },
246 { "use_internal_view", &use_internal_view },
247 { "use_internal_edit", &use_internal_edit },
248 { "clear_before_exec", &clear_before_exec },
249 { "confirm_delete", &confirm_delete },
250 { "confirm_overwrite", &confirm_overwrite },
251 { "confirm_execute", &confirm_execute },
252 { "confirm_history_cleanup", &mc_global.widget.confirm_history_cleanup },
253 { "confirm_exit", &confirm_exit },
254 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete },
255 { "safe_delete", &safe_delete },
256 { "mouse_repeat_rate", &mou_auto_repeat },
257 { "double_click_speed", &double_click_speed },
258 #ifndef HAVE_CHARSET
259 { "eight_bit_clean", &mc_global.eight_bit_clean },
260 { "full_eight_bits", &mc_global.full_eight_bits },
261 #endif /* !HAVE_CHARSET */
262 { "use_8th_bit_as_meta", &use_8th_bit_as_meta },
263 { "confirm_view_dir", &confirm_view_dir },
264 { "mouse_move_pages_viewer", &mcview_mouse_move_pages },
265 { "mouse_close_dialog", &mouse_close_dialog},
266 { "fast_refresh", &fast_refresh },
267 { "drop_menus", &drop_menus },
268 { "wrap_mode", &mcview_global_wrap_mode},
269 { "old_esc_mode", &old_esc_mode },
270 { "old_esc_mode_timeout", &old_esc_mode_timeout },
271 { "cd_symlinks", &mc_global.vfs.cd_symlinks },
272 { "show_all_if_ambiguous", &mc_global.widget.show_all_if_ambiguous },
273 { "max_dirt_limit", &mcview_max_dirt_limit },
274 { "use_file_to_guess_type", &use_file_to_check_type },
275 { "alternate_plus_minus", &mc_global.tty.alternate_plus_minus },
276 { "only_leading_plus_minus", &only_leading_plus_minus },
277 { "show_output_starts_shell", &output_starts_shell },
278 { "xtree_mode", &xtree_mode },
279 { "num_history_items_recorded", &num_history_items_recorded },
280 { "file_op_compute_totals", &file_op_compute_totals },
281 { "classic_progressbar", &classic_progressbar},
282 #ifdef ENABLE_VFS
283 { "vfs_timeout", &vfs_timeout },
284 #ifdef ENABLE_VFS_FTP
285 { "ftpfs_directory_timeout", &ftpfs_directory_timeout },
286 { "use_netrc", &ftpfs_use_netrc },
287 { "ftpfs_retry_seconds", &ftpfs_retry_seconds },
288 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy },
289 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections },
290 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy },
291 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options },
292 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls },
293 #endif /* ENABLE_VFS_FTP */
294 #ifdef ENABLE_VFS_FISH
295 { "fish_directory_timeout", &fish_directory_timeout },
296 #endif /* ENABLE_VFS_FISH */
297 #endif /* ENABLE_VFS */
298 /* option_tab_spacing is used in internal viewer */
299 { "editor_tab_spacing", &option_tab_spacing },
300 #ifdef USE_INTERNAL_EDIT
301 { "editor_word_wrap_line_length", &option_word_wrap_line_length },
302 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces },
303 { "editor_return_does_auto_indent", &option_return_does_auto_indent },
304 { "editor_backspace_through_tabs", &option_backspace_through_tabs },
305 { "editor_fake_half_tabs", &option_fake_half_tabs },
306 { "editor_option_save_mode", &option_save_mode },
307 { "editor_option_save_position", &option_save_position },
308 { "editor_option_auto_para_formatting", &option_auto_para_formatting },
309 { "editor_option_typewriter_wrap", &option_typewriter_wrap },
310 { "editor_edit_confirm_save", &edit_confirm_save },
311 { "editor_syntax_highlighting", &option_syntax_highlighting },
312 { "editor_persistent_selections", &option_persistent_selections },
313 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol },
314 { "editor_visible_tabs", &visible_tabs },
315 { "editor_visible_spaces", &visible_tws },
316 { "editor_line_state", &option_line_state },
317 { "editor_simple_statusbar", &simple_statusbar },
318 { "editor_check_new_line", &option_check_nl_at_eof },
319 { "editor_show_right_margin", &show_right_margin },
320 { "editor_group_undo", &option_group_undo },
321 #endif /* USE_INTERNAL_EDIT */
322 { "nice_rotating_dash", &nice_rotating_dash },
323 { "mcview_remember_file_position", &mcview_remember_file_position },
324 { "auto_fill_mkdir_name", &auto_fill_mkdir_name },
325 { "copymove_persistent_attr", &setup_copymove_persistent_attr },
326 { "select_flags", &select_flags },
327 { NULL, NULL }
330 static const struct
332 const char *opt_name;
333 char **opt_addr;
334 const char *opt_defval;
335 } str_options[] = {
336 #ifdef USE_INTERNAL_EDIT
337 { "editor_backup_extension", &option_backup_ext, "~" },
338 #endif
339 { "mcview_eof", &mcview_show_eof, "" },
340 { NULL, NULL, NULL }
343 static const struct
345 const char *opt_name;
346 gboolean *opt_addr;
347 } panels_ini_options[] = {
348 { "show_mini_info", &panels_options.show_mini_info },
349 { "kilobyte_si", &panels_options.kilobyte_si },
350 { "mix_all_files", &panels_options.mix_all_files },
351 { "show_backups", &panels_options.show_backups },
352 { "show_dot_files", &panels_options.show_dot_files },
353 { "fast_reload", &panels_options.fast_reload },
354 { "fast_reload_msg_shown", &panels_options.fast_reload_msg_shown },
355 { "mark_moves_down", &panels_options.mark_moves_down },
356 { "reverse_files_only", &panels_options.reverse_files_only },
357 { "auto_save_setup_panels", &panels_options.auto_save_setup },
358 { "navigate_with_arrows", &panels_options.navigate_with_arrows },
359 { "panel_scroll_pages", &panels_options.scroll_pages },
360 { "mouse_move_pages", &panels_options.mouse_move_pages },
361 { "filetype_mode", &panels_options.filetype_mode },
362 { "permission_mode", &panels_options.permission_mode },
363 { "torben_fj_mode", &panels_options.torben_fj_mode },
364 { NULL, NULL }
366 /* *INDENT-ON* */
368 /*** file scope functions ************************************************************************/
369 /* --------------------------------------------------------------------------------------------- */
372 Get name of config file.
374 @param subdir If not NULL, config is also searched in specified subdir.
375 @param config_file_name If relative, file if searched in standard paths.
376 @returns Newly allocated string with config name or NULL if file is not found.
378 static char *
379 load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
382 TODO: IMHO, in future, this function shall be placed in mcconfig module.
384 char *lc_basename, *ret;
385 char *file_name;
387 if (config_file_name == NULL)
388 return NULL;
390 /* check for .keymap suffix */
391 if (g_str_has_suffix (config_file_name, ".keymap"))
392 file_name = g_strdup (config_file_name);
393 else
394 file_name = g_strconcat (config_file_name, ".keymap", (char *) NULL);
396 canonicalize_pathname (file_name);
398 if (g_path_is_absolute (file_name))
399 return file_name;
401 lc_basename = g_path_get_basename (file_name);
402 g_free (file_name);
404 if (lc_basename == NULL)
405 return NULL;
407 if (subdir != NULL)
408 ret = g_build_filename (mc_config_get_path (), subdir, lc_basename, NULL);
409 else
410 ret = g_build_filename (mc_config_get_path (), lc_basename, NULL);
412 if (exist_file (ret))
414 g_free (lc_basename);
415 canonicalize_pathname (ret);
416 return ret;
418 g_free (ret);
420 if (subdir != NULL)
421 ret = g_build_filename (mc_global.sysconfig_dir, subdir, lc_basename, NULL);
422 else
423 ret = g_build_filename (mc_global.sysconfig_dir, lc_basename, NULL);
425 if (exist_file (ret))
427 g_free (lc_basename);
428 canonicalize_pathname (ret);
429 return ret;
431 g_free (ret);
433 if (subdir != NULL)
434 ret = g_build_filename (mc_global.share_data_dir, subdir, lc_basename, NULL);
435 else
436 ret = g_build_filename (mc_global.share_data_dir, lc_basename, NULL);
438 g_free (lc_basename);
440 if (exist_file (ret))
442 canonicalize_pathname (ret);
443 return ret;
446 g_free (ret);
447 return NULL;
450 /* --------------------------------------------------------------------------------------------- */
452 static const char *
453 setup__is_cfg_group_must_panel_config (const char *grp)
455 return (!strcasecmp ("Dirs", grp) ||
456 !strcasecmp ("Temporal:New Right Panel", grp) ||
457 !strcasecmp ("Temporal:New Left Panel", grp) ||
458 !strcasecmp ("New Left Panel", grp) || !strcasecmp ("New Right Panel", grp))
459 ? grp : NULL;
462 /* --------------------------------------------------------------------------------------------- */
464 static void
465 setup__move_panels_config_into_separate_file (const char *profile)
467 mc_config_t *tmp_cfg;
468 char **groups, **curr_grp;
469 const char *need_grp;
471 if (!exist_file (profile))
472 return;
474 tmp_cfg = mc_config_init (profile, FALSE);
475 if (!tmp_cfg)
476 return;
478 curr_grp = groups = mc_config_get_groups (tmp_cfg, NULL);
479 if (!groups)
481 mc_config_deinit (tmp_cfg);
482 return;
485 while (*curr_grp)
487 if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL)
488 mc_config_del_group (tmp_cfg, *curr_grp);
489 curr_grp++;
492 mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
493 mc_config_deinit (tmp_cfg);
495 tmp_cfg = mc_config_init (profile, FALSE);
496 if (!tmp_cfg)
498 g_strfreev (groups);
499 return;
502 curr_grp = groups;
504 while (*curr_grp)
506 need_grp = setup__is_cfg_group_must_panel_config (*curr_grp);
507 if (need_grp != NULL)
509 mc_config_del_group (tmp_cfg, need_grp);
511 curr_grp++;
513 g_strfreev (groups);
515 mc_config_save_file (tmp_cfg, NULL);
516 mc_config_deinit (tmp_cfg);
519 /* --------------------------------------------------------------------------------------------- */
521 Create new mc_config object from specified ini-file or
522 append data to existing mc_config object from ini-file
525 static void
526 load_setup_init_config_from_file (mc_config_t ** config, const char *fname, gboolean read_only)
529 TODO: IMHO, in future, this function shall be placed in mcconfig module.
531 if (exist_file (fname))
533 if (*config != NULL)
534 mc_config_read_file (*config, fname, read_only, TRUE);
535 else
536 *config = mc_config_init (fname, read_only);
540 /* --------------------------------------------------------------------------------------------- */
542 static void
543 load_layout (void)
545 size_t i;
546 int equal_split;
547 int first_panel_size;
549 /* legacy options */
550 panels_layout.horizontal_split = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
551 "horizontal_split", 0);
552 equal_split = mc_config_get_int (mc_main_config, "Layout", "equal_split", 1);
553 first_panel_size = mc_config_get_int (mc_main_config, "Layout", "first_panel_size", 1);
554 if (panels_layout.horizontal_split)
556 panels_layout.horizontal_equal = equal_split;
557 panels_layout.left_panel_size = first_panel_size;
559 else
561 panels_layout.vertical_equal = equal_split;
562 panels_layout.top_panel_size = first_panel_size;
565 /* actual options override legacy ones */
566 for (i = 0; layout[i].opt_name != NULL; i++)
567 *layout[i].opt_addr = mc_config_get_int (mc_main_config, CONFIG_LAYOUT_SECTION,
568 layout[i].opt_name, *layout[i].opt_addr);
570 /* remove legacy options */
571 mc_config_del_key (mc_main_config, CONFIG_APP_SECTION, "horizontal_split");
572 mc_config_del_key (mc_main_config, "Layout", "equal_split");
573 mc_config_del_key (mc_main_config, "Layout", "first_panel_size");
576 /* --------------------------------------------------------------------------------------------- */
578 static void
579 load_keys_from_section (const char *terminal, mc_config_t * cfg)
581 char *section_name;
582 gchar **profile_keys, **keys;
583 gchar **values, **curr_values;
584 char *valcopy, *value;
585 long key_code;
586 gsize len, values_len;
588 if (terminal == NULL)
589 return;
591 section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
592 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
594 while (*profile_keys != NULL)
596 /* copy=other causes all keys from [terminal:other] to be loaded. */
597 if (g_ascii_strcasecmp (*profile_keys, "copy") == 0)
599 valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
600 load_keys_from_section (valcopy, cfg);
601 g_free (valcopy);
602 profile_keys++;
603 continue;
606 curr_values = values =
607 mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len);
609 key_code = lookup_key (*profile_keys, NULL);
611 if (key_code != 0)
613 if (curr_values != NULL)
615 while (*curr_values != NULL)
617 valcopy = convert_controls (*curr_values);
618 define_sequence (key_code, valcopy, MCKEY_NOACTION);
619 g_free (valcopy);
620 curr_values++;
623 else
625 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
626 valcopy = convert_controls (value);
627 define_sequence (key_code, valcopy, MCKEY_NOACTION);
628 g_free (valcopy);
629 g_free (value);
633 profile_keys++;
634 g_strfreev (values);
636 g_strfreev (keys);
637 g_free (section_name);
640 /* --------------------------------------------------------------------------------------------- */
642 static void
643 load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg)
645 gchar **profile_keys, **keys;
646 gsize len;
648 if (section_name == NULL)
649 return;
651 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
653 while (*profile_keys != NULL)
655 gchar **values, **curr_values;
657 curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &len);
659 if (curr_values != NULL)
661 int action;
663 action = keybind_lookup_action (*profile_keys);
664 if (action > 0)
665 while (*curr_values != NULL)
667 keybind_cmd_bind (keymap, *curr_values, action);
668 curr_values++;
671 g_strfreev (values);
674 profile_keys++;
677 g_strfreev (keys);
680 /* --------------------------------------------------------------------------------------------- */
682 static mc_config_t *
683 load_setup_get_keymap_profile_config (gboolean load_from_file)
686 TODO: IMHO, in future, this function shall be placed in mcconfig module.
688 mc_config_t *keymap_config;
689 char *share_keymap, *sysconfig_keymap;
690 char *fname, *fname2;
692 /* 0) Create default keymap */
693 keymap_config = create_default_keymap ();
694 if (!load_from_file)
695 return keymap_config;
697 /* load and merge global keymaps */
699 /* 1) /usr/share/mc (mc_global.share_data_dir) */
700 share_keymap = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, NULL);
701 load_setup_init_config_from_file (&keymap_config, share_keymap, TRUE);
703 /* 2) /etc/mc (mc_global.sysconfig_dir) */
704 sysconfig_keymap = g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, NULL);
705 load_setup_init_config_from_file (&keymap_config, sysconfig_keymap, TRUE);
707 /* then load and merge one of user-defined keymap */
709 /* 3) --keymap=<keymap> */
710 fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file);
711 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
713 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
714 goto done;
716 g_free (fname);
718 /* 4) getenv("MC_KEYMAP") */
719 fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
720 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
722 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
723 goto done;
725 g_free (fname);
727 /* 5) main config; [Midnight Commander] -> keymap */
728 fname2 = mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, "keymap", NULL);
729 if (fname2 != NULL && *fname2 != '\0')
730 fname = load_setup_get_full_config_name (NULL, fname2);
731 g_free (fname2);
732 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
734 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
735 goto done;
737 g_free (fname);
739 /* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */
740 fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE);
741 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
743 done:
744 g_free (fname);
745 g_free (sysconfig_keymap);
746 g_free (share_keymap);
748 return keymap_config;
751 /* --------------------------------------------------------------------------------------------- */
753 static panel_view_mode_t
754 setup__load_panel_state (const char *section)
756 char *buffer;
757 size_t i;
758 panel_view_mode_t mode = view_listing;
760 /* Load the display mode */
761 buffer = mc_config_get_string (mc_panels_config, section, "display", "listing");
763 for (i = 0; panel_types[i].opt_name != NULL; i++)
764 if (g_ascii_strcasecmp (panel_types[i].opt_name, buffer) == 0)
766 mode = panel_types[i].opt_type;
767 break;
770 g_free (buffer);
772 return mode;
775 /* --------------------------------------------------------------------------------------------- */
777 static void
778 panel_save_type (const char *section, panel_view_mode_t type)
780 size_t i;
782 for (i = 0; panel_types[i].opt_name != NULL; i++)
783 if (panel_types[i].opt_type == type)
785 mc_config_set_string (mc_panels_config, section, "display", panel_types[i].opt_name);
786 break;
790 /* --------------------------------------------------------------------------------------------- */
792 /* save panels.ini */
793 static void
794 save_panel_types (void)
796 panel_view_mode_t type;
798 if (mc_global.mc_run_mode != MC_RUN_FULL)
799 return;
801 type = get_display_type (0);
802 panel_save_type ("New Left Panel", type);
803 if (type == view_listing)
804 panel_save_setup (left_panel, left_panel->panel_name);
805 type = get_display_type (1);
806 panel_save_type ("New Right Panel", type);
807 if (type == view_listing)
808 panel_save_setup (right_panel, right_panel->panel_name);
811 char *dirs;
813 dirs = get_panel_dir_for (other_panel);
814 mc_config_set_string (mc_panels_config, "Dirs", "other_dir", dirs);
815 g_free (dirs);
818 if (current_panel != NULL)
819 mc_config_set_bool (mc_panels_config, "Dirs", "current_is_left", get_current_index () == 0);
821 if (mc_panels_config->ini_path == NULL)
822 mc_panels_config->ini_path = g_strdup (panels_profile_name);
824 mc_config_del_group (mc_panels_config, "Temporal:New Left Panel");
825 mc_config_del_group (mc_panels_config, "Temporal:New Right Panel");
827 mc_config_save_file (mc_panels_config, NULL);
830 /* --------------------------------------------------------------------------------------------- */
831 /*** public functions ****************************************************************************/
832 /* --------------------------------------------------------------------------------------------- */
834 char *
835 setup_init (void)
837 char *profile;
838 char *inifile;
840 if (profile_name != NULL)
841 return profile_name;
843 profile = mc_config_get_full_path (MC_CONFIG_FILE);
844 if (!exist_file (profile))
846 inifile = mc_build_filename (mc_global.sysconfig_dir, "mc.ini", NULL);
847 if (exist_file (inifile))
849 g_free (profile);
850 profile = inifile;
852 else
854 g_free (inifile);
855 inifile = mc_build_filename (mc_global.share_data_dir, "mc.ini", NULL);
856 if (exist_file (inifile))
858 g_free (profile);
859 profile = inifile;
861 else
862 g_free (inifile);
866 profile_name = profile;
868 return profile;
871 /* --------------------------------------------------------------------------------------------- */
873 void
874 load_setup (void)
876 char *profile;
877 size_t i;
878 char *buffer;
879 const char *kt;
881 #ifdef HAVE_CHARSET
882 load_codepages_list ();
883 #endif /* HAVE_CHARSET */
885 profile = setup_init ();
887 /* mc.lib is common for all users, but has priority lower than
888 ${XDG_CONFIG_HOME}/mc/ini. FIXME: it's only used for keys and treestore now */
889 global_profile_name =
890 g_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
891 if (!exist_file (global_profile_name))
893 g_free (global_profile_name);
894 global_profile_name =
895 g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
898 panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE);
900 mc_main_config = mc_config_init (profile, FALSE);
902 if (!exist_file (panels_profile_name))
903 setup__move_panels_config_into_separate_file (profile);
905 mc_panels_config = mc_config_init (panels_profile_name, FALSE);
907 /* Load integer boolean options */
908 for (i = 0; int_options[i].opt_name != NULL; i++)
909 *int_options[i].opt_addr =
910 mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
911 *int_options[i].opt_addr);
913 if (option_tab_spacing <= 0)
914 option_tab_spacing = DEFAULT_TAB_SPACING;
916 #ifdef USE_INTERNAL_EDIT
917 if (option_word_wrap_line_length <= 0)
918 option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
919 #endif /* USE_INTERNAL_EDIT */
921 /* overwrite old_esc_mode_timeout */
922 kt = getenv ("KEYBOARD_KEY_TIMEOUT_US");
923 if ((kt != NULL) && (kt[0] != '\0'))
924 old_esc_mode_timeout = atoi (kt);
926 /* Load string options */
927 for (i = 0; str_options[i].opt_name != NULL; i++)
928 *str_options[i].opt_addr =
929 mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
930 str_options[i].opt_defval);
932 load_layout ();
933 panels_load_options ();
934 load_panelize ();
936 startup_left_mode = setup__load_panel_state ("New Left Panel");
937 startup_right_mode = setup__load_panel_state ("New Right Panel");
939 /* At least one of the panels is a listing panel */
940 if (startup_left_mode != view_listing && startup_right_mode != view_listing)
941 startup_left_mode = view_listing;
943 if (mc_run_param1 == NULL)
945 vfs_path_t *vpath;
946 buffer = mc_config_get_string (mc_panels_config, "Dirs", "other_dir", ".");
947 vpath = vfs_path_from_str (buffer);
948 if (vfs_file_is_local (vpath))
949 mc_run_param1 = buffer;
950 else
951 g_free (buffer);
952 vfs_path_free (vpath);
955 boot_current_is_left = mc_config_get_bool (mc_panels_config, "Dirs", "current_is_left", TRUE);
957 /* Load time formats */
958 user_recent_timeformat =
959 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_recent", FMTTIME);
960 user_old_timeformat =
961 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_old", FMTYEAR);
963 #ifdef ENABLE_VFS_FTP
964 ftpfs_proxy_host =
965 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host", "gate");
966 ftpfs_ignore_chattr_errors =
967 mc_config_get_bool (mc_main_config, CONFIG_APP_SECTION, "ignore_ftp_chattr_errors", TRUE);
968 ftpfs_init_passwd ();
969 #endif /* ENABLE_VFS_FTP */
971 /* The default color and the terminal dependent color */
972 mc_global.tty.setup_color_string =
973 mc_config_get_string (mc_main_config, "Colors", "base_color", "");
974 mc_global.tty.term_color_string =
975 mc_config_get_string (mc_main_config, "Colors", getenv ("TERM"), "");
976 mc_global.tty.color_terminal_string =
977 mc_config_get_string (mc_main_config, "Colors", "color_terminals", "");
979 /* Load the directory history */
980 /* directory_history_load (); */
981 /* Remove the temporal entries */
983 #ifdef HAVE_CHARSET
984 if (codepages->len > 1)
986 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage", "");
987 if (buffer[0] != '\0')
989 mc_global.display_codepage = get_codepage_index (buffer);
990 cp_display = get_codepage_id (mc_global.display_codepage);
992 g_free (buffer);
993 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage", "");
994 if (buffer[0] != '\0')
996 default_source_codepage = get_codepage_index (buffer);
997 mc_global.source_codepage = default_source_codepage; /* May be source_codepage doesn't need this */
998 cp_source = get_codepage_id (mc_global.source_codepage);
1000 g_free (buffer);
1003 autodetect_codeset =
1004 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset", "");
1005 if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off") != 0))
1006 is_autodetect_codeset_enabled = TRUE;
1008 g_free (init_translation_table (mc_global.source_codepage, mc_global.display_codepage));
1009 buffer = (char *) get_codepage_id (mc_global.display_codepage);
1010 if (buffer != NULL)
1011 mc_global.utf8_display = str_isutf8 (buffer);
1012 #endif /* HAVE_CHARSET */
1014 clipboard_store_path =
1015 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store", "");
1016 clipboard_paste_path =
1017 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste", "");
1020 /* --------------------------------------------------------------------------------------------- */
1022 gboolean
1023 save_setup (gboolean save_options, gboolean save_panel_options)
1025 gboolean ret = TRUE;
1027 saving_setup = 1;
1029 save_hotlist ();
1031 if (save_panel_options)
1032 save_panel_types ();
1034 if (save_options)
1036 char *tmp_profile;
1038 save_config ();
1039 save_layout ();
1040 panels_save_options ();
1041 save_panelize ();
1042 /* directory_history_save (); */
1044 #ifdef ENABLE_VFS_FTP
1045 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "ftpfs_password",
1046 ftpfs_anonymous_passwd);
1047 if (ftpfs_proxy_host)
1048 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host",
1049 ftpfs_proxy_host);
1050 #endif /* ENABLE_VFS_FTP */
1052 #ifdef HAVE_CHARSET
1053 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage",
1054 get_codepage_id (mc_global.display_codepage));
1055 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage",
1056 get_codepage_id (default_source_codepage));
1057 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset",
1058 autodetect_codeset);
1059 #endif /* HAVE_CHARSET */
1060 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store",
1061 clipboard_store_path);
1062 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste",
1063 clipboard_paste_path);
1065 tmp_profile = mc_config_get_full_path (MC_CONFIG_FILE);
1066 ret = mc_config_save_to_file (mc_main_config, tmp_profile, NULL);
1067 g_free (tmp_profile);
1070 saving_setup = 0;
1072 return ret;
1075 /* --------------------------------------------------------------------------------------------- */
1077 void
1078 done_setup (void)
1080 size_t i;
1082 g_free (clipboard_store_path);
1083 g_free (clipboard_paste_path);
1084 g_free (profile_name);
1085 g_free (global_profile_name);
1086 g_free (mc_global.tty.color_terminal_string);
1087 g_free (mc_global.tty.term_color_string);
1088 g_free (mc_global.tty.setup_color_string);
1089 g_free (panels_profile_name);
1090 mc_config_deinit (mc_main_config);
1091 mc_config_deinit (mc_panels_config);
1093 g_free (user_recent_timeformat);
1094 g_free (user_old_timeformat);
1096 for (i = 0; str_options[i].opt_name != NULL; i++)
1097 g_free (*str_options[i].opt_addr);
1099 done_hotlist ();
1100 done_panelize ();
1101 /* directory_history_free (); */
1103 #ifdef HAVE_CHARSET
1104 g_free (autodetect_codeset);
1105 free_codepages_list ();
1106 #endif
1109 /* --------------------------------------------------------------------------------------------- */
1111 void
1112 save_config (void)
1114 size_t i;
1116 /* Save integer options */
1117 for (i = 0; int_options[i].opt_name != NULL; i++)
1118 mc_config_set_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
1119 *int_options[i].opt_addr);
1121 /* Save string options */
1122 for (i = 0; str_options[i].opt_name != NULL; i++)
1123 mc_config_set_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
1124 *str_options[i].opt_addr);
1127 /* --------------------------------------------------------------------------------------------- */
1129 void
1130 setup_save_config_show_error (const char *filename, GError ** error)
1132 if (error != NULL && *error != NULL)
1134 message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*error)->message);
1135 g_error_free (*error);
1136 *error = NULL;
1140 /* --------------------------------------------------------------------------------------------- */
1142 void
1143 save_layout (void)
1145 size_t i;
1147 /* Save integer options */
1148 for (i = 0; layout[i].opt_name != NULL; i++)
1149 mc_config_set_int (mc_main_config, CONFIG_LAYOUT_SECTION, layout[i].opt_name,
1150 *layout[i].opt_addr);
1153 /* --------------------------------------------------------------------------------------------- */
1155 void
1156 load_key_defs (void)
1159 * Load keys from mc.lib before ${XDG_CONFIG_HOME}/mc/ini, so that the user
1160 * definitions override global settings.
1162 mc_config_t *mc_global_config;
1164 mc_global_config = mc_config_init (global_profile_name, FALSE);
1165 if (mc_global_config != NULL)
1167 load_keys_from_section ("general", mc_global_config);
1168 load_keys_from_section (getenv ("TERM"), mc_global_config);
1169 mc_config_deinit (mc_global_config);
1172 load_keys_from_section ("general", mc_main_config);
1173 load_keys_from_section (getenv ("TERM"), mc_main_config);
1176 /* --------------------------------------------------------------------------------------------- */
1178 #ifdef ENABLE_VFS_FTP
1179 char *
1180 load_anon_passwd (void)
1182 char *buffer;
1184 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftpfs_password", "");
1186 if ((buffer != NULL) && (buffer[0] != '\0'))
1187 return buffer;
1189 g_free (buffer);
1190 return NULL;
1192 #endif /* ENABLE_VFS_FTP */
1194 /* --------------------------------------------------------------------------------------------- */
1196 void
1197 load_keymap_defs (gboolean load_from_file)
1200 * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_CONFIG_HOME}/mc/mc.keymap, so that the user
1201 * definitions override global settings.
1203 mc_config_t *mc_global_keymap;
1205 mc_global_keymap = load_setup_get_keymap_profile_config (load_from_file);
1207 if (mc_global_keymap != NULL)
1209 main_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1210 load_keymap_from_section (KEYMAP_SECTION_MAIN, main_keymap, mc_global_keymap);
1211 main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1212 load_keymap_from_section (KEYMAP_SECTION_MAIN_EXT, main_x_keymap, mc_global_keymap);
1214 panel_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1215 load_keymap_from_section (KEYMAP_SECTION_PANEL, panel_keymap, mc_global_keymap);
1217 dialog_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1218 load_keymap_from_section (KEYMAP_SECTION_DIALOG, dialog_keymap, mc_global_keymap);
1220 input_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1221 load_keymap_from_section (KEYMAP_SECTION_INPUT, input_keymap, mc_global_keymap);
1223 listbox_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1224 load_keymap_from_section (KEYMAP_SECTION_LISTBOX, listbox_keymap, mc_global_keymap);
1226 tree_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1227 load_keymap_from_section (KEYMAP_SECTION_TREE, tree_keymap, mc_global_keymap);
1229 help_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1230 load_keymap_from_section (KEYMAP_SECTION_HELP, help_keymap, mc_global_keymap);
1232 #ifdef USE_INTERNAL_EDIT
1233 editor_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1234 load_keymap_from_section (KEYMAP_SECTION_EDITOR, editor_keymap, mc_global_keymap);
1235 editor_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1236 load_keymap_from_section (KEYMAP_SECTION_EDITOR_EXT, editor_x_keymap, mc_global_keymap);
1237 #endif
1239 viewer_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1240 load_keymap_from_section (KEYMAP_SECTION_VIEWER, viewer_keymap, mc_global_keymap);
1241 viewer_hex_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1242 load_keymap_from_section (KEYMAP_SECTION_VIEWER_HEX, viewer_hex_keymap, mc_global_keymap);
1244 #ifdef USE_DIFF_VIEW
1245 diff_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1246 load_keymap_from_section (KEYMAP_SECTION_DIFFVIEWER, diff_keymap, mc_global_keymap);
1247 #endif
1249 mc_config_deinit (mc_global_keymap);
1252 main_map = (global_keymap_t *) main_keymap->data;
1253 main_x_map = (global_keymap_t *) main_x_keymap->data;
1254 panel_map = (global_keymap_t *) panel_keymap->data;
1255 dialog_map = (global_keymap_t *) dialog_keymap->data;
1256 input_map = (global_keymap_t *) input_keymap->data;
1257 listbox_map = (global_keymap_t *) listbox_keymap->data;
1258 tree_map = (global_keymap_t *) tree_keymap->data;
1259 help_map = (global_keymap_t *) help_keymap->data;
1260 #ifdef USE_INTERNAL_EDIT
1261 editor_map = (global_keymap_t *) editor_keymap->data;
1262 editor_x_map = (global_keymap_t *) editor_x_keymap->data;
1263 #endif
1264 viewer_map = (global_keymap_t *) viewer_keymap->data;
1265 viewer_hex_map = (global_keymap_t *) viewer_hex_keymap->data;
1266 #ifdef USE_DIFF_VIEW
1267 diff_map = (global_keymap_t *) diff_keymap->data;
1268 #endif
1271 /* --------------------------------------------------------------------------------------------- */
1273 void
1274 free_keymap_defs (void)
1276 if (main_keymap != NULL)
1277 g_array_free (main_keymap, TRUE);
1278 if (main_x_keymap != NULL)
1279 g_array_free (main_x_keymap, TRUE);
1280 if (panel_keymap != NULL)
1281 g_array_free (panel_keymap, TRUE);
1282 if (dialog_keymap != NULL)
1283 g_array_free (dialog_keymap, TRUE);
1284 if (input_keymap != NULL)
1285 g_array_free (input_keymap, TRUE);
1286 if (listbox_keymap != NULL)
1287 g_array_free (listbox_keymap, TRUE);
1288 if (tree_keymap != NULL)
1289 g_array_free (tree_keymap, TRUE);
1290 if (help_keymap != NULL)
1291 g_array_free (help_keymap, TRUE);
1292 #ifdef USE_INTERNAL_EDIT
1293 if (editor_keymap != NULL)
1294 g_array_free (editor_keymap, TRUE);
1295 if (editor_x_keymap != NULL)
1296 g_array_free (editor_x_keymap, TRUE);
1297 #endif
1298 if (viewer_keymap != NULL)
1299 g_array_free (viewer_keymap, TRUE);
1300 if (viewer_hex_keymap != NULL)
1301 g_array_free (viewer_hex_keymap, TRUE);
1302 #ifdef USE_DIFF_VIEW
1303 if (diff_keymap != NULL)
1304 g_array_free (diff_keymap, TRUE);
1305 #endif
1308 /* --------------------------------------------------------------------------------------------- */
1310 void
1311 panel_load_setup (WPanel * panel, const char *section)
1313 size_t i;
1314 char *buffer, buffer2[BUF_TINY];
1316 panel->sort_info.reverse = mc_config_get_int (mc_panels_config, section, "reverse", 0);
1317 panel->sort_info.case_sensitive =
1318 mc_config_get_int (mc_panels_config, section, "case_sensitive",
1319 OS_SORT_CASE_SENSITIVE_DEFAULT);
1320 panel->sort_info.exec_first = mc_config_get_int (mc_panels_config, section, "exec_first", 0);
1322 /* Load sort order */
1323 buffer = mc_config_get_string (mc_panels_config, section, "sort_order", "name");
1324 panel->sort_info.sort_field = panel_get_field_by_id (buffer);
1325 if (panel->sort_info.sort_field == NULL)
1326 panel->sort_info.sort_field = panel_get_field_by_id ("name");
1328 g_free (buffer);
1330 /* Load the listing mode */
1331 buffer = mc_config_get_string (mc_panels_config, section, "list_mode", "full");
1332 panel->list_type = list_full;
1333 for (i = 0; list_types[i].key != NULL; i++)
1334 if (g_ascii_strcasecmp (list_types[i].key, buffer) == 0)
1336 panel->list_type = list_types[i].list_type;
1337 break;
1339 g_free (buffer);
1341 /* User formats */
1342 g_free (panel->user_format);
1343 panel->user_format =
1344 mc_config_get_string (mc_panels_config, section, "user_format", DEFAULT_USER_FORMAT);
1346 for (i = 0; i < LIST_TYPES; i++)
1348 g_free (panel->user_status_format[i]);
1349 g_snprintf (buffer2, BUF_TINY, "user_status%lld", (long long) i);
1350 panel->user_status_format[i] =
1351 mc_config_get_string (mc_panels_config, section, buffer2, DEFAULT_USER_FORMAT);
1354 panel->user_mini_status = mc_config_get_int (mc_panels_config, section, "user_mini_status", 0);
1357 /* --------------------------------------------------------------------------------------------- */
1359 void
1360 panel_save_setup (struct WPanel *panel, const char *section)
1362 char buffer[BUF_TINY];
1363 size_t i;
1365 mc_config_set_int (mc_panels_config, section, "reverse", panel->sort_info.reverse);
1366 mc_config_set_int (mc_panels_config, section, "case_sensitive",
1367 panel->sort_info.case_sensitive);
1368 mc_config_set_int (mc_panels_config, section, "exec_first", panel->sort_info.exec_first);
1370 mc_config_set_string (mc_panels_config, section, "sort_order", panel->sort_info.sort_field->id);
1372 for (i = 0; list_types[i].key != NULL; i++)
1373 if (list_types[i].list_type == panel->list_type)
1375 mc_config_set_string (mc_panels_config, section, "list_mode", list_types[i].key);
1376 break;
1379 mc_config_set_string (mc_panels_config, section, "user_format", panel->user_format);
1381 for (i = 0; i < LIST_TYPES; i++)
1383 g_snprintf (buffer, BUF_TINY, "user_status%lld", (long long) i);
1384 mc_config_set_string (mc_panels_config, section, buffer, panel->user_status_format[i]);
1387 mc_config_set_int (mc_panels_config, section, "user_mini_status", panel->user_mini_status);
1390 /* --------------------------------------------------------------------------------------------- */
1393 Load panels options from [Panels] section.
1395 void
1396 panels_load_options (void)
1398 if (mc_config_has_group (mc_main_config, CONFIG_PANELS_SECTION))
1400 size_t i;
1401 int qmode;
1403 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1404 *panels_ini_options[i].opt_addr =
1405 mc_config_get_bool (mc_main_config, CONFIG_PANELS_SECTION,
1406 panels_ini_options[i].opt_name,
1407 *panels_ini_options[i].opt_addr);
1409 qmode = mc_config_get_int (mc_main_config, CONFIG_PANELS_SECTION,
1410 "quick_search_mode", (int) panels_options.qsearch_mode);
1411 if (qmode < 0)
1412 panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE;
1413 else if (qmode >= QSEARCH_NUM)
1414 panels_options.qsearch_mode = QSEARCH_PANEL_CASE;
1415 else
1416 panels_options.qsearch_mode = (qsearch_mode_t) qmode;
1420 /* --------------------------------------------------------------------------------------------- */
1423 Save panels options in [Panels] section.
1425 void
1426 panels_save_options (void)
1428 size_t i;
1430 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1431 mc_config_set_bool (mc_main_config, CONFIG_PANELS_SECTION,
1432 panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr);
1434 mc_config_set_int (mc_main_config, CONFIG_PANELS_SECTION,
1435 "quick_search_mode", (int) panels_options.qsearch_mode);
1438 /* --------------------------------------------------------------------------------------------- */