Internal menu structures are opaque now.
[midnight-commander.git] / src / setup.c
blobbeb29d76178b7a62f13b9587f38ee013423dbbef
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 /* If set, then print to the given file the last directory we were at */
191 char *last_wd_string = NULL;
193 /* Set when main loop should be terminated */
194 int quit = 0;
196 /* The user's shell */
197 char *shell = NULL;
199 /* The prompt */
200 const char *mc_prompt = NULL;
202 /* Set to TRUE to suppress printing the last directory */
203 int print_last_revert = FALSE;
205 /* index to record_macro_buf[], -1 if not recording a macro */
206 int macro_index = -1;
208 /* macro stuff */
209 struct macro_action_t record_macro_buf[MAX_MACRO_LENGTH];
211 GArray *macros_list;
213 /*** file scope macro definitions ****************************************************************/
215 /* In order to use everywhere the same setup for the locale we use defines */
216 #define FMTYEAR _("%b %e %Y")
217 #define FMTTIME _("%b %e %H:%M")
219 /*** file scope type declarations ****************************************************************/
221 /*** file scope variables ************************************************************************/
223 static char *panels_profile_name = NULL; /* ${XDG_CACHE_HOME}/mc/panels.ini */
225 /* *INDENT-OFF* */
226 static const struct
228 const char *key;
229 int list_type;
230 } list_types [] = {
231 { "full", list_full },
232 { "brief", list_brief },
233 { "long", list_long },
234 { "user", list_user },
235 { NULL, 0 }
238 static const struct
240 const char *opt_name;
241 panel_view_mode_t opt_type;
242 } panel_types [] = {
243 { "listing", view_listing },
244 { "quickview", view_quick },
245 { "info", view_info },
246 { "tree", view_tree },
247 { NULL, view_listing }
250 static const struct
252 const char *opt_name;
253 int *opt_addr;
254 } layout [] = {
255 { "message_visible", &mc_global.message_visible },
256 { "keybar_visible", &mc_global.keybar_visible },
257 { "xterm_title", &xterm_title },
258 { "output_lines", &output_lines },
259 { "command_prompt", &command_prompt },
260 { "menubar_visible", &menubar_visible },
261 { "free_space", &free_space },
262 { "horizontal_split", &panels_layout.horizontal_split },
263 { "vertical_equal", &panels_layout.vertical_equal },
264 { "left_panel_size", &panels_layout.left_panel_size },
265 { "horizontal_equal", &panels_layout.horizontal_equal },
266 { "top_panel_size", &panels_layout.top_panel_size },
267 { NULL, NULL }
270 static const struct
272 const char *opt_name;
273 int *opt_addr;
274 } int_options [] = {
275 { "verbose", &verbose },
276 { "pause_after_run", &pause_after_run },
277 { "shell_patterns", &easy_patterns },
278 { "auto_save_setup", &auto_save_setup },
279 { "preallocate_space", &mc_global.vfs.preallocate_space },
280 { "auto_menu", &auto_menu },
281 { "use_internal_view", &use_internal_view },
282 { "use_internal_edit", &use_internal_edit },
283 { "clear_before_exec", &clear_before_exec },
284 { "confirm_delete", &confirm_delete },
285 { "confirm_overwrite", &confirm_overwrite },
286 { "confirm_execute", &confirm_execute },
287 { "confirm_history_cleanup", &mc_global.widget.confirm_history_cleanup },
288 { "confirm_exit", &confirm_exit },
289 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete },
290 { "safe_delete", &safe_delete },
291 { "mouse_repeat_rate", &mou_auto_repeat },
292 { "double_click_speed", &double_click_speed },
293 #ifndef HAVE_CHARSET
294 { "eight_bit_clean", &mc_global.eight_bit_clean },
295 { "full_eight_bits", &mc_global.full_eight_bits },
296 #endif /* !HAVE_CHARSET */
297 { "use_8th_bit_as_meta", &use_8th_bit_as_meta },
298 { "confirm_view_dir", &confirm_view_dir },
299 { "mouse_move_pages_viewer", &mcview_mouse_move_pages },
300 { "mouse_close_dialog", &mouse_close_dialog},
301 { "fast_refresh", &fast_refresh },
302 { "drop_menus", &drop_menus },
303 { "wrap_mode", &mcview_global_wrap_mode},
304 { "old_esc_mode", &old_esc_mode },
305 { "old_esc_mode_timeout", &old_esc_mode_timeout },
306 { "cd_symlinks", &mc_global.vfs.cd_symlinks },
307 { "show_all_if_ambiguous", &mc_global.widget.show_all_if_ambiguous },
308 { "max_dirt_limit", &mcview_max_dirt_limit },
309 { "use_file_to_guess_type", &use_file_to_check_type },
310 { "alternate_plus_minus", &mc_global.tty.alternate_plus_minus },
311 { "only_leading_plus_minus", &only_leading_plus_minus },
312 { "show_output_starts_shell", &output_starts_shell },
313 { "xtree_mode", &xtree_mode },
314 { "num_history_items_recorded", &num_history_items_recorded },
315 { "file_op_compute_totals", &file_op_compute_totals },
316 { "classic_progressbar", &classic_progressbar},
317 #ifdef ENABLE_VFS
318 { "vfs_timeout", &vfs_timeout },
319 #ifdef ENABLE_VFS_FTP
320 { "ftpfs_directory_timeout", &ftpfs_directory_timeout },
321 { "use_netrc", &ftpfs_use_netrc },
322 { "ftpfs_retry_seconds", &ftpfs_retry_seconds },
323 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy },
324 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections },
325 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy },
326 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options },
327 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls },
328 #endif /* ENABLE_VFS_FTP */
329 #ifdef ENABLE_VFS_FISH
330 { "fish_directory_timeout", &fish_directory_timeout },
331 #endif /* ENABLE_VFS_FISH */
332 #endif /* ENABLE_VFS */
333 /* option_tab_spacing is used in internal viewer */
334 { "editor_tab_spacing", &option_tab_spacing },
335 #ifdef USE_INTERNAL_EDIT
336 { "editor_word_wrap_line_length", &option_word_wrap_line_length },
337 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces },
338 { "editor_return_does_auto_indent", &option_return_does_auto_indent },
339 { "editor_backspace_through_tabs", &option_backspace_through_tabs },
340 { "editor_fake_half_tabs", &option_fake_half_tabs },
341 { "editor_option_save_mode", &option_save_mode },
342 { "editor_option_save_position", &option_save_position },
343 { "editor_option_auto_para_formatting", &option_auto_para_formatting },
344 { "editor_option_typewriter_wrap", &option_typewriter_wrap },
345 { "editor_edit_confirm_save", &edit_confirm_save },
346 { "editor_syntax_highlighting", &option_syntax_highlighting },
347 { "editor_persistent_selections", &option_persistent_selections },
348 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol },
349 { "editor_visible_tabs", &visible_tabs },
350 { "editor_visible_spaces", &visible_tws },
351 { "editor_line_state", &option_line_state },
352 { "editor_simple_statusbar", &simple_statusbar },
353 { "editor_check_new_line", &option_check_nl_at_eof },
354 { "editor_show_right_margin", &show_right_margin },
355 { "editor_group_undo", &option_group_undo },
356 #endif /* USE_INTERNAL_EDIT */
357 { "nice_rotating_dash", &nice_rotating_dash },
358 { "mcview_remember_file_position", &mcview_remember_file_position },
359 { "auto_fill_mkdir_name", &auto_fill_mkdir_name },
360 { "copymove_persistent_attr", &setup_copymove_persistent_attr },
361 { "select_flags", &select_flags },
362 { NULL, NULL }
365 static const struct
367 const char *opt_name;
368 char **opt_addr;
369 const char *opt_defval;
370 } str_options[] = {
371 #ifdef USE_INTERNAL_EDIT
372 { "editor_backup_extension", &option_backup_ext, "~" },
373 #endif
374 { "mcview_eof", &mcview_show_eof, "" },
375 { NULL, NULL, NULL }
378 static const struct
380 const char *opt_name;
381 gboolean *opt_addr;
382 } panels_ini_options[] = {
383 { "show_mini_info", &panels_options.show_mini_info },
384 { "kilobyte_si", &panels_options.kilobyte_si },
385 { "mix_all_files", &panels_options.mix_all_files },
386 { "show_backups", &panels_options.show_backups },
387 { "show_dot_files", &panels_options.show_dot_files },
388 { "fast_reload", &panels_options.fast_reload },
389 { "fast_reload_msg_shown", &panels_options.fast_reload_msg_shown },
390 { "mark_moves_down", &panels_options.mark_moves_down },
391 { "reverse_files_only", &panels_options.reverse_files_only },
392 { "auto_save_setup_panels", &panels_options.auto_save_setup },
393 { "navigate_with_arrows", &panels_options.navigate_with_arrows },
394 { "panel_scroll_pages", &panels_options.scroll_pages },
395 { "mouse_move_pages", &panels_options.mouse_move_pages },
396 { "filetype_mode", &panels_options.filetype_mode },
397 { "permission_mode", &panels_options.permission_mode },
398 { "torben_fj_mode", &panels_options.torben_fj_mode },
399 { NULL, NULL }
401 /* *INDENT-ON* */
403 /*** file scope functions ************************************************************************/
404 /* --------------------------------------------------------------------------------------------- */
407 * Get name of config file.
409 * @param subdir If not NULL, config is also searched in specified subdir.
410 * @param config_file_name If relative, file if searched in standard paths.
412 * @return newly allocated string with config name or NULL if file is not found.
415 static char *
416 load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
419 TODO: IMHO, in future, this function shall be placed in mcconfig module.
421 char *lc_basename, *ret;
422 char *file_name;
424 if (config_file_name == NULL)
425 return NULL;
427 /* check for .keymap suffix */
428 if (g_str_has_suffix (config_file_name, ".keymap"))
429 file_name = g_strdup (config_file_name);
430 else
431 file_name = g_strconcat (config_file_name, ".keymap", (char *) NULL);
433 canonicalize_pathname (file_name);
435 if (g_path_is_absolute (file_name))
436 return file_name;
438 lc_basename = g_path_get_basename (file_name);
439 g_free (file_name);
441 if (lc_basename == NULL)
442 return NULL;
444 if (subdir != NULL)
445 ret = g_build_filename (mc_config_get_path (), subdir, lc_basename, NULL);
446 else
447 ret = g_build_filename (mc_config_get_path (), lc_basename, NULL);
449 if (exist_file (ret))
451 g_free (lc_basename);
452 canonicalize_pathname (ret);
453 return ret;
455 g_free (ret);
457 if (subdir != NULL)
458 ret = g_build_filename (mc_global.sysconfig_dir, subdir, lc_basename, NULL);
459 else
460 ret = g_build_filename (mc_global.sysconfig_dir, lc_basename, NULL);
462 if (exist_file (ret))
464 g_free (lc_basename);
465 canonicalize_pathname (ret);
466 return ret;
468 g_free (ret);
470 if (subdir != NULL)
471 ret = g_build_filename (mc_global.share_data_dir, subdir, lc_basename, NULL);
472 else
473 ret = g_build_filename (mc_global.share_data_dir, lc_basename, NULL);
475 g_free (lc_basename);
477 if (exist_file (ret))
479 canonicalize_pathname (ret);
480 return ret;
483 g_free (ret);
484 return NULL;
487 /* --------------------------------------------------------------------------------------------- */
489 static const char *
490 setup__is_cfg_group_must_panel_config (const char *grp)
492 return (!strcasecmp ("Dirs", grp) ||
493 !strcasecmp ("Temporal:New Right Panel", grp) ||
494 !strcasecmp ("Temporal:New Left Panel", grp) ||
495 !strcasecmp ("New Left Panel", grp) || !strcasecmp ("New Right Panel", grp))
496 ? grp : NULL;
499 /* --------------------------------------------------------------------------------------------- */
501 static void
502 setup__move_panels_config_into_separate_file (const char *profile)
504 mc_config_t *tmp_cfg;
505 char **groups, **curr_grp;
506 const char *need_grp;
508 if (!exist_file (profile))
509 return;
511 tmp_cfg = mc_config_init (profile, FALSE);
512 if (!tmp_cfg)
513 return;
515 curr_grp = groups = mc_config_get_groups (tmp_cfg, NULL);
516 if (!groups)
518 mc_config_deinit (tmp_cfg);
519 return;
522 while (*curr_grp)
524 if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL)
525 mc_config_del_group (tmp_cfg, *curr_grp);
526 curr_grp++;
529 mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
530 mc_config_deinit (tmp_cfg);
532 tmp_cfg = mc_config_init (profile, FALSE);
533 if (!tmp_cfg)
535 g_strfreev (groups);
536 return;
539 curr_grp = groups;
541 while (*curr_grp)
543 need_grp = setup__is_cfg_group_must_panel_config (*curr_grp);
544 if (need_grp != NULL)
546 mc_config_del_group (tmp_cfg, need_grp);
548 curr_grp++;
550 g_strfreev (groups);
552 mc_config_save_file (tmp_cfg, NULL);
553 mc_config_deinit (tmp_cfg);
556 /* --------------------------------------------------------------------------------------------- */
558 Create new mc_config object from specified ini-file or
559 append data to existing mc_config object from ini-file
562 static void
563 load_setup_init_config_from_file (mc_config_t ** config, const char *fname, gboolean read_only)
566 TODO: IMHO, in future, this function shall be placed in mcconfig module.
568 if (exist_file (fname))
570 if (*config != NULL)
571 mc_config_read_file (*config, fname, read_only, TRUE);
572 else
573 *config = mc_config_init (fname, read_only);
577 /* --------------------------------------------------------------------------------------------- */
579 static void
580 load_layout (void)
582 size_t i;
583 int equal_split;
584 int first_panel_size;
586 /* legacy options */
587 panels_layout.horizontal_split = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
588 "horizontal_split", 0);
589 equal_split = mc_config_get_int (mc_main_config, "Layout", "equal_split", 1);
590 first_panel_size = mc_config_get_int (mc_main_config, "Layout", "first_panel_size", 1);
591 if (panels_layout.horizontal_split)
593 panels_layout.horizontal_equal = equal_split;
594 panels_layout.left_panel_size = first_panel_size;
596 else
598 panels_layout.vertical_equal = equal_split;
599 panels_layout.top_panel_size = first_panel_size;
602 /* actual options override legacy ones */
603 for (i = 0; layout[i].opt_name != NULL; i++)
604 *layout[i].opt_addr = mc_config_get_int (mc_main_config, CONFIG_LAYOUT_SECTION,
605 layout[i].opt_name, *layout[i].opt_addr);
607 /* remove legacy options */
608 mc_config_del_key (mc_main_config, CONFIG_APP_SECTION, "horizontal_split");
609 mc_config_del_key (mc_main_config, "Layout", "equal_split");
610 mc_config_del_key (mc_main_config, "Layout", "first_panel_size");
613 /* --------------------------------------------------------------------------------------------- */
615 static void
616 load_keys_from_section (const char *terminal, mc_config_t * cfg)
618 char *section_name;
619 gchar **profile_keys, **keys;
620 gchar **values, **curr_values;
621 char *valcopy, *value;
622 long key_code;
623 gsize len, values_len;
625 if (terminal == NULL)
626 return;
628 section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
629 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
631 while (*profile_keys != NULL)
633 /* copy=other causes all keys from [terminal:other] to be loaded. */
634 if (g_ascii_strcasecmp (*profile_keys, "copy") == 0)
636 valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
637 load_keys_from_section (valcopy, cfg);
638 g_free (valcopy);
639 profile_keys++;
640 continue;
643 curr_values = values =
644 mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len);
646 key_code = lookup_key (*profile_keys, NULL);
648 if (key_code != 0)
650 if (curr_values != NULL)
652 while (*curr_values != NULL)
654 valcopy = convert_controls (*curr_values);
655 define_sequence (key_code, valcopy, MCKEY_NOACTION);
656 g_free (valcopy);
657 curr_values++;
660 else
662 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
663 valcopy = convert_controls (value);
664 define_sequence (key_code, valcopy, MCKEY_NOACTION);
665 g_free (valcopy);
666 g_free (value);
670 profile_keys++;
671 g_strfreev (values);
673 g_strfreev (keys);
674 g_free (section_name);
677 /* --------------------------------------------------------------------------------------------- */
679 static void
680 load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg)
682 gchar **profile_keys, **keys;
683 gsize len;
685 if (section_name == NULL)
686 return;
688 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
690 while (*profile_keys != NULL)
692 gchar **values, **curr_values;
694 curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &len);
696 if (curr_values != NULL)
698 int action;
700 action = keybind_lookup_action (*profile_keys);
701 if (action > 0)
702 while (*curr_values != NULL)
704 keybind_cmd_bind (keymap, *curr_values, action);
705 curr_values++;
708 g_strfreev (values);
711 profile_keys++;
714 g_strfreev (keys);
717 /* --------------------------------------------------------------------------------------------- */
719 static mc_config_t *
720 load_setup_get_keymap_profile_config (gboolean load_from_file)
723 TODO: IMHO, in future, this function shall be placed in mcconfig module.
725 mc_config_t *keymap_config;
726 char *share_keymap, *sysconfig_keymap;
727 char *fname, *fname2;
729 /* 0) Create default keymap */
730 keymap_config = create_default_keymap ();
731 if (!load_from_file)
732 return keymap_config;
734 /* load and merge global keymaps */
736 /* 1) /usr/share/mc (mc_global.share_data_dir) */
737 share_keymap = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, NULL);
738 load_setup_init_config_from_file (&keymap_config, share_keymap, TRUE);
740 /* 2) /etc/mc (mc_global.sysconfig_dir) */
741 sysconfig_keymap = g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, NULL);
742 load_setup_init_config_from_file (&keymap_config, sysconfig_keymap, TRUE);
744 /* then load and merge one of user-defined keymap */
746 /* 3) --keymap=<keymap> */
747 fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file);
748 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
750 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
751 goto done;
753 g_free (fname);
755 /* 4) getenv("MC_KEYMAP") */
756 fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
757 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
759 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
760 goto done;
762 g_free (fname);
764 /* 5) main config; [Midnight Commander] -> keymap */
765 fname2 = mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, "keymap", NULL);
766 if (fname2 != NULL && *fname2 != '\0')
767 fname = load_setup_get_full_config_name (NULL, fname2);
768 g_free (fname2);
769 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
771 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
772 goto done;
774 g_free (fname);
776 /* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */
777 fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE);
778 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
780 done:
781 g_free (fname);
782 g_free (sysconfig_keymap);
783 g_free (share_keymap);
785 return keymap_config;
788 /* --------------------------------------------------------------------------------------------- */
790 static panel_view_mode_t
791 setup__load_panel_state (const char *section)
793 char *buffer;
794 size_t i;
795 panel_view_mode_t mode = view_listing;
797 /* Load the display mode */
798 buffer = mc_config_get_string (mc_panels_config, section, "display", "listing");
800 for (i = 0; panel_types[i].opt_name != NULL; i++)
801 if (g_ascii_strcasecmp (panel_types[i].opt_name, buffer) == 0)
803 mode = panel_types[i].opt_type;
804 break;
807 g_free (buffer);
809 return mode;
812 /* --------------------------------------------------------------------------------------------- */
814 static void
815 panel_save_type (const char *section, panel_view_mode_t type)
817 size_t i;
819 for (i = 0; panel_types[i].opt_name != NULL; i++)
820 if (panel_types[i].opt_type == type)
822 mc_config_set_string (mc_panels_config, section, "display", panel_types[i].opt_name);
823 break;
827 /* --------------------------------------------------------------------------------------------- */
829 /* save panels.ini */
830 static void
831 save_panel_types (void)
833 panel_view_mode_t type;
835 if (mc_global.mc_run_mode != MC_RUN_FULL)
836 return;
838 type = get_display_type (0);
839 panel_save_type ("New Left Panel", type);
840 if (type == view_listing)
841 panel_save_setup (left_panel, left_panel->panel_name);
842 type = get_display_type (1);
843 panel_save_type ("New Right Panel", type);
844 if (type == view_listing)
845 panel_save_setup (right_panel, right_panel->panel_name);
848 char *dirs;
850 dirs = get_panel_dir_for (other_panel);
851 mc_config_set_string (mc_panels_config, "Dirs", "other_dir", dirs);
852 g_free (dirs);
855 if (current_panel != NULL)
856 mc_config_set_bool (mc_panels_config, "Dirs", "current_is_left", get_current_index () == 0);
858 if (mc_panels_config->ini_path == NULL)
859 mc_panels_config->ini_path = g_strdup (panels_profile_name);
861 mc_config_del_group (mc_panels_config, "Temporal:New Left Panel");
862 mc_config_del_group (mc_panels_config, "Temporal:New Right Panel");
864 mc_config_save_file (mc_panels_config, NULL);
867 /* --------------------------------------------------------------------------------------------- */
868 /*** public functions ****************************************************************************/
869 /* --------------------------------------------------------------------------------------------- */
871 char *
872 setup_init (void)
874 char *profile;
875 char *inifile;
877 if (profile_name != NULL)
878 return profile_name;
880 profile = mc_config_get_full_path (MC_CONFIG_FILE);
881 if (!exist_file (profile))
883 inifile = mc_build_filename (mc_global.sysconfig_dir, "mc.ini", NULL);
884 if (exist_file (inifile))
886 g_free (profile);
887 profile = inifile;
889 else
891 g_free (inifile);
892 inifile = mc_build_filename (mc_global.share_data_dir, "mc.ini", NULL);
893 if (exist_file (inifile))
895 g_free (profile);
896 profile = inifile;
898 else
899 g_free (inifile);
903 profile_name = profile;
905 return profile;
908 /* --------------------------------------------------------------------------------------------- */
910 void
911 load_setup (void)
913 char *profile;
914 size_t i;
915 char *buffer;
916 const char *kt;
918 #ifdef HAVE_CHARSET
919 load_codepages_list ();
920 #endif /* HAVE_CHARSET */
922 profile = setup_init ();
924 /* mc.lib is common for all users, but has priority lower than
925 ${XDG_CONFIG_HOME}/mc/ini. FIXME: it's only used for keys and treestore now */
926 global_profile_name =
927 g_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
928 if (!exist_file (global_profile_name))
930 g_free (global_profile_name);
931 global_profile_name =
932 g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
935 panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE);
937 mc_main_config = mc_config_init (profile, FALSE);
939 if (!exist_file (panels_profile_name))
940 setup__move_panels_config_into_separate_file (profile);
942 mc_panels_config = mc_config_init (panels_profile_name, FALSE);
944 /* Load integer boolean options */
945 for (i = 0; int_options[i].opt_name != NULL; i++)
946 *int_options[i].opt_addr =
947 mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
948 *int_options[i].opt_addr);
950 if (option_tab_spacing <= 0)
951 option_tab_spacing = DEFAULT_TAB_SPACING;
953 #ifdef USE_INTERNAL_EDIT
954 if (option_word_wrap_line_length <= 0)
955 option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
956 #endif /* USE_INTERNAL_EDIT */
958 /* overwrite old_esc_mode_timeout */
959 kt = getenv ("KEYBOARD_KEY_TIMEOUT_US");
960 if ((kt != NULL) && (kt[0] != '\0'))
961 old_esc_mode_timeout = atoi (kt);
963 /* Load string options */
964 for (i = 0; str_options[i].opt_name != NULL; i++)
965 *str_options[i].opt_addr =
966 mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
967 str_options[i].opt_defval);
969 load_layout ();
970 panels_load_options ();
971 load_panelize ();
973 startup_left_mode = setup__load_panel_state ("New Left Panel");
974 startup_right_mode = setup__load_panel_state ("New Right Panel");
976 /* At least one of the panels is a listing panel */
977 if (startup_left_mode != view_listing && startup_right_mode != view_listing)
978 startup_left_mode = view_listing;
980 if (mc_run_param1 == NULL)
982 vfs_path_t *vpath;
983 buffer = mc_config_get_string (mc_panels_config, "Dirs", "other_dir", ".");
984 vpath = vfs_path_from_str (buffer);
985 if (vfs_file_is_local (vpath))
986 mc_run_param1 = buffer;
987 else
988 g_free (buffer);
989 vfs_path_free (vpath);
992 boot_current_is_left = mc_config_get_bool (mc_panels_config, "Dirs", "current_is_left", TRUE);
994 /* Load time formats */
995 user_recent_timeformat =
996 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_recent", FMTTIME);
997 user_old_timeformat =
998 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_old", FMTYEAR);
1000 #ifdef ENABLE_VFS_FTP
1001 ftpfs_proxy_host =
1002 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host", "gate");
1003 ftpfs_ignore_chattr_errors =
1004 mc_config_get_bool (mc_main_config, CONFIG_APP_SECTION, "ignore_ftp_chattr_errors", TRUE);
1005 ftpfs_init_passwd ();
1006 #endif /* ENABLE_VFS_FTP */
1008 /* The default color and the terminal dependent color */
1009 mc_global.tty.setup_color_string =
1010 mc_config_get_string (mc_main_config, "Colors", "base_color", "");
1011 mc_global.tty.term_color_string =
1012 mc_config_get_string (mc_main_config, "Colors", getenv ("TERM"), "");
1013 mc_global.tty.color_terminal_string =
1014 mc_config_get_string (mc_main_config, "Colors", "color_terminals", "");
1016 /* Load the directory history */
1017 /* directory_history_load (); */
1018 /* Remove the temporal entries */
1020 #ifdef HAVE_CHARSET
1021 if (codepages->len > 1)
1023 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage", "");
1024 if (buffer[0] != '\0')
1026 mc_global.display_codepage = get_codepage_index (buffer);
1027 cp_display = get_codepage_id (mc_global.display_codepage);
1029 g_free (buffer);
1030 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage", "");
1031 if (buffer[0] != '\0')
1033 default_source_codepage = get_codepage_index (buffer);
1034 mc_global.source_codepage = default_source_codepage; /* May be source_codepage doesn't need this */
1035 cp_source = get_codepage_id (mc_global.source_codepage);
1037 g_free (buffer);
1040 autodetect_codeset =
1041 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset", "");
1042 if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off") != 0))
1043 is_autodetect_codeset_enabled = TRUE;
1045 g_free (init_translation_table (mc_global.source_codepage, mc_global.display_codepage));
1046 buffer = (char *) get_codepage_id (mc_global.display_codepage);
1047 if (buffer != NULL)
1048 mc_global.utf8_display = str_isutf8 (buffer);
1049 #endif /* HAVE_CHARSET */
1051 clipboard_store_path =
1052 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store", "");
1053 clipboard_paste_path =
1054 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste", "");
1057 /* --------------------------------------------------------------------------------------------- */
1059 gboolean
1060 save_setup (gboolean save_options, gboolean save_panel_options)
1062 gboolean ret = TRUE;
1064 saving_setup = 1;
1066 save_hotlist ();
1068 if (save_panel_options)
1069 save_panel_types ();
1071 if (save_options)
1073 char *tmp_profile;
1075 save_config ();
1076 save_layout ();
1077 panels_save_options ();
1078 save_panelize ();
1079 /* directory_history_save (); */
1081 #ifdef ENABLE_VFS_FTP
1082 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "ftpfs_password",
1083 ftpfs_anonymous_passwd);
1084 if (ftpfs_proxy_host)
1085 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host",
1086 ftpfs_proxy_host);
1087 #endif /* ENABLE_VFS_FTP */
1089 #ifdef HAVE_CHARSET
1090 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage",
1091 get_codepage_id (mc_global.display_codepage));
1092 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage",
1093 get_codepage_id (default_source_codepage));
1094 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset",
1095 autodetect_codeset);
1096 #endif /* HAVE_CHARSET */
1097 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store",
1098 clipboard_store_path);
1099 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste",
1100 clipboard_paste_path);
1102 tmp_profile = mc_config_get_full_path (MC_CONFIG_FILE);
1103 ret = mc_config_save_to_file (mc_main_config, tmp_profile, NULL);
1104 g_free (tmp_profile);
1107 saving_setup = 0;
1109 return ret;
1112 /* --------------------------------------------------------------------------------------------- */
1114 void
1115 done_setup (void)
1117 size_t i;
1119 g_free (clipboard_store_path);
1120 g_free (clipboard_paste_path);
1121 g_free (profile_name);
1122 g_free (global_profile_name);
1123 g_free (mc_global.tty.color_terminal_string);
1124 g_free (mc_global.tty.term_color_string);
1125 g_free (mc_global.tty.setup_color_string);
1126 g_free (panels_profile_name);
1127 mc_config_deinit (mc_main_config);
1128 mc_config_deinit (mc_panels_config);
1130 g_free (user_recent_timeformat);
1131 g_free (user_old_timeformat);
1133 for (i = 0; str_options[i].opt_name != NULL; i++)
1134 g_free (*str_options[i].opt_addr);
1136 done_hotlist ();
1137 done_panelize ();
1138 /* directory_history_free (); */
1140 #ifdef HAVE_CHARSET
1141 g_free (autodetect_codeset);
1142 free_codepages_list ();
1143 #endif
1146 /* --------------------------------------------------------------------------------------------- */
1148 void
1149 save_config (void)
1151 size_t i;
1153 /* Save integer options */
1154 for (i = 0; int_options[i].opt_name != NULL; i++)
1155 mc_config_set_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
1156 *int_options[i].opt_addr);
1158 /* Save string options */
1159 for (i = 0; str_options[i].opt_name != NULL; i++)
1160 mc_config_set_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
1161 *str_options[i].opt_addr);
1164 /* --------------------------------------------------------------------------------------------- */
1166 void
1167 setup_save_config_show_error (const char *filename, GError ** error)
1169 if (error != NULL && *error != NULL)
1171 message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*error)->message);
1172 g_error_free (*error);
1173 *error = NULL;
1177 /* --------------------------------------------------------------------------------------------- */
1179 void
1180 save_layout (void)
1182 size_t i;
1184 /* Save integer options */
1185 for (i = 0; layout[i].opt_name != NULL; i++)
1186 mc_config_set_int (mc_main_config, CONFIG_LAYOUT_SECTION, layout[i].opt_name,
1187 *layout[i].opt_addr);
1190 /* --------------------------------------------------------------------------------------------- */
1192 void
1193 load_key_defs (void)
1196 * Load keys from mc.lib before ${XDG_CONFIG_HOME}/mc/ini, so that the user
1197 * definitions override global settings.
1199 mc_config_t *mc_global_config;
1201 mc_global_config = mc_config_init (global_profile_name, FALSE);
1202 if (mc_global_config != NULL)
1204 load_keys_from_section ("general", mc_global_config);
1205 load_keys_from_section (getenv ("TERM"), mc_global_config);
1206 mc_config_deinit (mc_global_config);
1209 load_keys_from_section ("general", mc_main_config);
1210 load_keys_from_section (getenv ("TERM"), mc_main_config);
1213 /* --------------------------------------------------------------------------------------------- */
1215 #ifdef ENABLE_VFS_FTP
1216 char *
1217 load_anon_passwd (void)
1219 char *buffer;
1221 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftpfs_password", "");
1223 if ((buffer != NULL) && (buffer[0] != '\0'))
1224 return buffer;
1226 g_free (buffer);
1227 return NULL;
1229 #endif /* ENABLE_VFS_FTP */
1231 /* --------------------------------------------------------------------------------------------- */
1233 void
1234 load_keymap_defs (gboolean load_from_file)
1237 * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_CONFIG_HOME}/mc/mc.keymap, so that the user
1238 * definitions override global settings.
1240 mc_config_t *mc_global_keymap;
1242 mc_global_keymap = load_setup_get_keymap_profile_config (load_from_file);
1244 if (mc_global_keymap != NULL)
1246 main_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1247 load_keymap_from_section (KEYMAP_SECTION_MAIN, main_keymap, mc_global_keymap);
1248 main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1249 load_keymap_from_section (KEYMAP_SECTION_MAIN_EXT, main_x_keymap, mc_global_keymap);
1251 panel_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1252 load_keymap_from_section (KEYMAP_SECTION_PANEL, panel_keymap, mc_global_keymap);
1254 dialog_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1255 load_keymap_from_section (KEYMAP_SECTION_DIALOG, dialog_keymap, mc_global_keymap);
1257 input_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1258 load_keymap_from_section (KEYMAP_SECTION_INPUT, input_keymap, mc_global_keymap);
1260 listbox_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1261 load_keymap_from_section (KEYMAP_SECTION_LISTBOX, listbox_keymap, mc_global_keymap);
1263 tree_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1264 load_keymap_from_section (KEYMAP_SECTION_TREE, tree_keymap, mc_global_keymap);
1266 help_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1267 load_keymap_from_section (KEYMAP_SECTION_HELP, help_keymap, mc_global_keymap);
1269 #ifdef USE_INTERNAL_EDIT
1270 editor_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1271 load_keymap_from_section (KEYMAP_SECTION_EDITOR, editor_keymap, mc_global_keymap);
1272 editor_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1273 load_keymap_from_section (KEYMAP_SECTION_EDITOR_EXT, editor_x_keymap, mc_global_keymap);
1274 #endif
1276 viewer_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1277 load_keymap_from_section (KEYMAP_SECTION_VIEWER, viewer_keymap, mc_global_keymap);
1278 viewer_hex_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1279 load_keymap_from_section (KEYMAP_SECTION_VIEWER_HEX, viewer_hex_keymap, mc_global_keymap);
1281 #ifdef USE_DIFF_VIEW
1282 diff_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1283 load_keymap_from_section (KEYMAP_SECTION_DIFFVIEWER, diff_keymap, mc_global_keymap);
1284 #endif
1286 mc_config_deinit (mc_global_keymap);
1289 main_map = (global_keymap_t *) main_keymap->data;
1290 main_x_map = (global_keymap_t *) main_x_keymap->data;
1291 panel_map = (global_keymap_t *) panel_keymap->data;
1292 dialog_map = (global_keymap_t *) dialog_keymap->data;
1293 input_map = (global_keymap_t *) input_keymap->data;
1294 listbox_map = (global_keymap_t *) listbox_keymap->data;
1295 tree_map = (global_keymap_t *) tree_keymap->data;
1296 help_map = (global_keymap_t *) help_keymap->data;
1297 #ifdef USE_INTERNAL_EDIT
1298 editor_map = (global_keymap_t *) editor_keymap->data;
1299 editor_x_map = (global_keymap_t *) editor_x_keymap->data;
1300 #endif
1301 viewer_map = (global_keymap_t *) viewer_keymap->data;
1302 viewer_hex_map = (global_keymap_t *) viewer_hex_keymap->data;
1303 #ifdef USE_DIFF_VIEW
1304 diff_map = (global_keymap_t *) diff_keymap->data;
1305 #endif
1308 /* --------------------------------------------------------------------------------------------- */
1310 void
1311 free_keymap_defs (void)
1313 if (main_keymap != NULL)
1314 g_array_free (main_keymap, TRUE);
1315 if (main_x_keymap != NULL)
1316 g_array_free (main_x_keymap, TRUE);
1317 if (panel_keymap != NULL)
1318 g_array_free (panel_keymap, TRUE);
1319 if (dialog_keymap != NULL)
1320 g_array_free (dialog_keymap, TRUE);
1321 if (input_keymap != NULL)
1322 g_array_free (input_keymap, TRUE);
1323 if (listbox_keymap != NULL)
1324 g_array_free (listbox_keymap, TRUE);
1325 if (tree_keymap != NULL)
1326 g_array_free (tree_keymap, TRUE);
1327 if (help_keymap != NULL)
1328 g_array_free (help_keymap, TRUE);
1329 #ifdef USE_INTERNAL_EDIT
1330 if (editor_keymap != NULL)
1331 g_array_free (editor_keymap, TRUE);
1332 if (editor_x_keymap != NULL)
1333 g_array_free (editor_x_keymap, TRUE);
1334 #endif
1335 if (viewer_keymap != NULL)
1336 g_array_free (viewer_keymap, TRUE);
1337 if (viewer_hex_keymap != NULL)
1338 g_array_free (viewer_hex_keymap, TRUE);
1339 #ifdef USE_DIFF_VIEW
1340 if (diff_keymap != NULL)
1341 g_array_free (diff_keymap, TRUE);
1342 #endif
1345 /* --------------------------------------------------------------------------------------------- */
1347 void
1348 panel_load_setup (WPanel * panel, const char *section)
1350 size_t i;
1351 char *buffer, buffer2[BUF_TINY];
1353 panel->sort_info.reverse = mc_config_get_int (mc_panels_config, section, "reverse", 0);
1354 panel->sort_info.case_sensitive =
1355 mc_config_get_int (mc_panels_config, section, "case_sensitive",
1356 OS_SORT_CASE_SENSITIVE_DEFAULT);
1357 panel->sort_info.exec_first = mc_config_get_int (mc_panels_config, section, "exec_first", 0);
1359 /* Load sort order */
1360 buffer = mc_config_get_string (mc_panels_config, section, "sort_order", "name");
1361 panel->sort_info.sort_field = panel_get_field_by_id (buffer);
1362 if (panel->sort_info.sort_field == NULL)
1363 panel->sort_info.sort_field = panel_get_field_by_id ("name");
1365 g_free (buffer);
1367 /* Load the listing mode */
1368 buffer = mc_config_get_string (mc_panels_config, section, "list_mode", "full");
1369 panel->list_type = list_full;
1370 for (i = 0; list_types[i].key != NULL; i++)
1371 if (g_ascii_strcasecmp (list_types[i].key, buffer) == 0)
1373 panel->list_type = list_types[i].list_type;
1374 break;
1376 g_free (buffer);
1378 /* User formats */
1379 g_free (panel->user_format);
1380 panel->user_format =
1381 mc_config_get_string (mc_panels_config, section, "user_format", DEFAULT_USER_FORMAT);
1383 for (i = 0; i < LIST_TYPES; i++)
1385 g_free (panel->user_status_format[i]);
1386 g_snprintf (buffer2, BUF_TINY, "user_status%lld", (long long) i);
1387 panel->user_status_format[i] =
1388 mc_config_get_string (mc_panels_config, section, buffer2, DEFAULT_USER_FORMAT);
1391 panel->user_mini_status = mc_config_get_int (mc_panels_config, section, "user_mini_status", 0);
1394 /* --------------------------------------------------------------------------------------------- */
1396 void
1397 panel_save_setup (struct WPanel *panel, const char *section)
1399 char buffer[BUF_TINY];
1400 size_t i;
1402 mc_config_set_int (mc_panels_config, section, "reverse", panel->sort_info.reverse);
1403 mc_config_set_int (mc_panels_config, section, "case_sensitive",
1404 panel->sort_info.case_sensitive);
1405 mc_config_set_int (mc_panels_config, section, "exec_first", panel->sort_info.exec_first);
1407 mc_config_set_string (mc_panels_config, section, "sort_order", panel->sort_info.sort_field->id);
1409 for (i = 0; list_types[i].key != NULL; i++)
1410 if (list_types[i].list_type == panel->list_type)
1412 mc_config_set_string (mc_panels_config, section, "list_mode", list_types[i].key);
1413 break;
1416 mc_config_set_string (mc_panels_config, section, "user_format", panel->user_format);
1418 for (i = 0; i < LIST_TYPES; i++)
1420 g_snprintf (buffer, BUF_TINY, "user_status%lld", (long long) i);
1421 mc_config_set_string (mc_panels_config, section, buffer, panel->user_status_format[i]);
1424 mc_config_set_int (mc_panels_config, section, "user_mini_status", panel->user_mini_status);
1427 /* --------------------------------------------------------------------------------------------- */
1430 Load panels options from [Panels] section.
1432 void
1433 panels_load_options (void)
1435 if (mc_config_has_group (mc_main_config, CONFIG_PANELS_SECTION))
1437 size_t i;
1438 int qmode;
1440 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1441 *panels_ini_options[i].opt_addr =
1442 mc_config_get_bool (mc_main_config, CONFIG_PANELS_SECTION,
1443 panels_ini_options[i].opt_name,
1444 *panels_ini_options[i].opt_addr);
1446 qmode = mc_config_get_int (mc_main_config, CONFIG_PANELS_SECTION,
1447 "quick_search_mode", (int) panels_options.qsearch_mode);
1448 if (qmode < 0)
1449 panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE;
1450 else if (qmode >= QSEARCH_NUM)
1451 panels_options.qsearch_mode = QSEARCH_PANEL_CASE;
1452 else
1453 panels_options.qsearch_mode = (qsearch_mode_t) qmode;
1457 /* --------------------------------------------------------------------------------------------- */
1460 Save panels options in [Panels] section.
1462 void
1463 panels_save_options (void)
1465 size_t i;
1467 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1468 mc_config_set_bool (mc_main_config, CONFIG_PANELS_SECTION,
1469 panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr);
1471 mc_config_set_int (mc_main_config, CONFIG_PANELS_SECTION,
1472 "quick_search_mode", (int) panels_options.qsearch_mode);
1475 /* --------------------------------------------------------------------------------------------- */