ecaa66dec44f6df51a26f9428bdef9ec77eca5a3
[midnight-commander.git] / src / setup.c
blobecaa66dec44f6df51a26f9428bdef9ec77eca5a3
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/filehighlight.h"
39 #include "lib/tty/tty.h"
40 #include "lib/tty/key.h"
41 #include "lib/mcconfig.h"
42 #include "lib/fileloc.h"
43 #include "lib/timefmt.h"
44 #include "lib/util.h"
45 #include "lib/widget.h"
47 #include "lib/vfs/vfs.h"
49 #ifdef ENABLE_VFS_FTP
50 #include "src/vfs/ftpfs/ftpfs.h"
51 #endif
52 #ifdef ENABLE_VFS_FISH
53 #include "src/vfs/fish/fish.h"
54 #endif
56 #ifdef HAVE_CHARSET
57 #include "lib/charsets.h"
58 #endif
60 #include "filemanager/dir.h"
61 #include "filemanager/midnight.h"
62 #include "filemanager/tree.h" /* xtree_mode */
63 #include "filemanager/hotlist.h" /* load/save/done hotlist */
64 #include "filemanager/panelize.h" /* load/save/done panelize */
65 #include "filemanager/layout.h"
66 #include "filemanager/cmd.h"
68 #include "args.h"
69 #include "execute.h" /* pause_after_run */
70 #include "clipboard.h"
71 #include "keybind-defaults.h" /* keybind_lookup_action */
73 #ifdef HAVE_CHARSET
74 #include "selcodepage.h"
75 #endif
77 #ifdef USE_INTERNAL_EDIT
78 #include "src/editor/edit.h"
79 #endif
81 #include "src/viewer/mcviewer.h" /* For the externs */
83 #include "setup.h"
85 /*** global variables ****************************************************************************/
87 char *profile_name; /* ${XDG_CONFIG_HOME}/mc/ini */
88 char *global_profile_name; /* mc.lib */
90 /* Only used at program boot */
91 gboolean boot_current_is_left = TRUE;
93 /* If on, default for "No" in delete operations */
94 int safe_delete = 0;
96 /* Controls screen clearing before an exec */
97 int clear_before_exec = 1;
99 /* Asks for confirmation before deleting a file */
100 int confirm_delete = 1;
101 /* Asks for confirmation before deleting a hotlist entry */
102 int confirm_directory_hotlist_delete = 1;
103 /* Asks for confirmation before overwriting a file */
104 int confirm_overwrite = 1;
105 /* Asks for confirmation before executing a program by pressing enter */
106 int confirm_execute = 0;
107 /* Asks for confirmation before leaving the program */
108 int confirm_exit = 1;
110 /* If true, at startup the user-menu is invoked */
111 int auto_menu = 0;
112 /* This flag indicates if the pull down menus by default drop down */
113 int drop_menus = 0;
115 /* Asks for confirmation when using F3 to view a directory and there
116 are tagged files */
117 int confirm_view_dir = 0;
119 panel_view_mode_t startup_left_mode;
120 panel_view_mode_t startup_right_mode;
122 int setup_copymove_persistent_attr = 1;
124 /* Tab size */
125 int option_tab_spacing = DEFAULT_TAB_SPACING;
127 /* Ugly hack to allow panel_save_setup to work as a place holder for */
128 /* default panel values */
129 int saving_setup;
131 panels_options_t panels_options = {
132 .show_mini_info = TRUE,
133 .kilobyte_si = FALSE,
134 .mix_all_files = FALSE,
135 .show_backups = TRUE,
136 .show_dot_files = TRUE,
137 .fast_reload = FALSE,
138 .fast_reload_msg_shown = FALSE,
139 .mark_moves_down = TRUE,
140 .reverse_files_only = TRUE,
141 .auto_save_setup = FALSE,
142 .navigate_with_arrows = FALSE,
143 .scroll_pages = TRUE,
144 .mouse_move_pages = TRUE,
145 .filetype_mode = TRUE,
146 .permission_mode = FALSE,
147 .qsearch_mode = QSEARCH_PANEL_CASE,
148 .torben_fj_mode = FALSE
151 int easy_patterns = 1;
153 /* It true saves the setup when quitting */
154 int auto_save_setup = 1;
156 /* If true, then the +, - and \ keys have their special meaning only if the
157 * command line is emtpy, otherwise they behave like regular letters
159 int only_leading_plus_minus = 1;
161 /* Automatically fills name with current selected item name on mkdir */
162 int auto_fill_mkdir_name = 1;
164 /* If set and you don't have subshell support,then C-o will give you a shell */
165 int output_starts_shell = 0;
167 /* If set, we execute the file command to check the file type */
168 int use_file_to_check_type = 1;
170 int verbose = 1;
173 * Whether the Midnight Commander tries to provide more
174 * information about copy/move sizes and bytes transfered
175 * at the expense of some speed
177 int file_op_compute_totals = 1;
179 /* If true use the internal viewer */
180 int use_internal_view = 1;
181 /* If set, use the builtin editor */
182 int use_internal_edit = 1;
184 #ifdef HAVE_CHARSET
185 /* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
186 int default_source_codepage = -1;
187 char *autodetect_codeset = NULL;
188 gboolean is_autodetect_codeset_enabled = FALSE;
189 #endif /* !HAVE_CHARSET */
191 /* If set, then print to the given file the last directory we were at */
192 char *last_wd_string = NULL;
194 mc_fhl_t *mc_filehighlight;
196 /* Set when main loop should be terminated */
197 int quit = 0;
199 /* The user's shell */
200 char *shell = NULL;
202 /* The prompt */
203 const char *mc_prompt = NULL;
205 /* Set to TRUE to suppress printing the last directory */
206 int print_last_revert = FALSE;
208 /* index to record_macro_buf[], -1 if not recording a macro */
209 int macro_index = -1;
211 /* macro stuff */
212 struct macro_action_t record_macro_buf[MAX_MACRO_LENGTH];
214 GArray *macros_list;
216 /*** file scope macro definitions ****************************************************************/
218 /* In order to use everywhere the same setup for the locale we use defines */
219 #define FMTYEAR _("%b %e %Y")
220 #define FMTTIME _("%b %e %H:%M")
222 /*** file scope type declarations ****************************************************************/
224 /*** file scope variables ************************************************************************/
226 static char *panels_profile_name = NULL; /* ${XDG_CACHE_HOME}/mc/panels.ini */
228 /* *INDENT-OFF* */
229 static const struct
231 const char *key;
232 int list_type;
233 } list_types [] = {
234 { "full", list_full },
235 { "brief", list_brief },
236 { "long", list_long },
237 { "user", list_user },
238 { NULL, 0 }
241 static const struct
243 const char *opt_name;
244 panel_view_mode_t opt_type;
245 } panel_types [] = {
246 { "listing", view_listing },
247 { "quickview", view_quick },
248 { "info", view_info },
249 { "tree", view_tree },
250 { NULL, view_listing }
253 static const struct
255 const char *opt_name;
256 int *opt_addr;
257 } layout [] = {
258 { "message_visible", &mc_global.message_visible },
259 { "keybar_visible", &mc_global.keybar_visible },
260 { "xterm_title", &xterm_title },
261 { "output_lines", &output_lines },
262 { "command_prompt", &command_prompt },
263 { "menubar_visible", &menubar_visible },
264 { "free_space", &free_space },
265 { "horizontal_split", &panels_layout.horizontal_split },
266 { "vertical_equal", &panels_layout.vertical_equal },
267 { "left_panel_size", &panels_layout.left_panel_size },
268 { "horizontal_equal", &panels_layout.horizontal_equal },
269 { "top_panel_size", &panels_layout.top_panel_size },
270 { NULL, NULL }
273 static const struct
275 const char *opt_name;
276 int *opt_addr;
277 } int_options [] = {
278 { "verbose", &verbose },
279 { "pause_after_run", &pause_after_run },
280 { "shell_patterns", &easy_patterns },
281 { "auto_save_setup", &auto_save_setup },
282 { "preallocate_space", &mc_global.vfs.preallocate_space },
283 { "auto_menu", &auto_menu },
284 { "use_internal_view", &use_internal_view },
285 { "use_internal_edit", &use_internal_edit },
286 { "clear_before_exec", &clear_before_exec },
287 { "confirm_delete", &confirm_delete },
288 { "confirm_overwrite", &confirm_overwrite },
289 { "confirm_execute", &confirm_execute },
290 { "confirm_history_cleanup", &mc_global.widget.confirm_history_cleanup },
291 { "confirm_exit", &confirm_exit },
292 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete },
293 { "safe_delete", &safe_delete },
294 { "mouse_repeat_rate", &mou_auto_repeat },
295 { "double_click_speed", &double_click_speed },
296 #ifndef HAVE_CHARSET
297 { "eight_bit_clean", &mc_global.eight_bit_clean },
298 { "full_eight_bits", &mc_global.full_eight_bits },
299 #endif /* !HAVE_CHARSET */
300 { "use_8th_bit_as_meta", &use_8th_bit_as_meta },
301 { "confirm_view_dir", &confirm_view_dir },
302 { "mouse_move_pages_viewer", &mcview_mouse_move_pages },
303 { "mouse_close_dialog", &mouse_close_dialog},
304 { "fast_refresh", &fast_refresh },
305 { "drop_menus", &drop_menus },
306 { "wrap_mode", &mcview_global_wrap_mode},
307 { "old_esc_mode", &old_esc_mode },
308 { "old_esc_mode_timeout", &old_esc_mode_timeout },
309 { "cd_symlinks", &mc_global.vfs.cd_symlinks },
310 { "show_all_if_ambiguous", &mc_global.widget.show_all_if_ambiguous },
311 { "max_dirt_limit", &mcview_max_dirt_limit },
312 { "use_file_to_guess_type", &use_file_to_check_type },
313 { "alternate_plus_minus", &mc_global.tty.alternate_plus_minus },
314 { "only_leading_plus_minus", &only_leading_plus_minus },
315 { "show_output_starts_shell", &output_starts_shell },
316 { "xtree_mode", &xtree_mode },
317 { "num_history_items_recorded", &num_history_items_recorded },
318 { "file_op_compute_totals", &file_op_compute_totals },
319 { "classic_progressbar", &classic_progressbar},
320 #ifdef ENABLE_VFS
321 { "vfs_timeout", &vfs_timeout },
322 #ifdef ENABLE_VFS_FTP
323 { "ftpfs_directory_timeout", &ftpfs_directory_timeout },
324 { "use_netrc", &ftpfs_use_netrc },
325 { "ftpfs_retry_seconds", &ftpfs_retry_seconds },
326 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy },
327 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections },
328 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy },
329 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options },
330 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls },
331 #endif /* ENABLE_VFS_FTP */
332 #ifdef ENABLE_VFS_FISH
333 { "fish_directory_timeout", &fish_directory_timeout },
334 #endif /* ENABLE_VFS_FISH */
335 #endif /* ENABLE_VFS */
336 /* option_tab_spacing is used in internal viewer */
337 { "editor_tab_spacing", &option_tab_spacing },
338 #ifdef USE_INTERNAL_EDIT
339 { "editor_word_wrap_line_length", &option_word_wrap_line_length },
340 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces },
341 { "editor_return_does_auto_indent", &option_return_does_auto_indent },
342 { "editor_backspace_through_tabs", &option_backspace_through_tabs },
343 { "editor_fake_half_tabs", &option_fake_half_tabs },
344 { "editor_option_save_mode", &option_save_mode },
345 { "editor_option_save_position", &option_save_position },
346 { "editor_option_auto_para_formatting", &option_auto_para_formatting },
347 { "editor_option_typewriter_wrap", &option_typewriter_wrap },
348 { "editor_edit_confirm_save", &edit_confirm_save },
349 { "editor_syntax_highlighting", &option_syntax_highlighting },
350 { "editor_persistent_selections", &option_persistent_selections },
351 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol },
352 { "editor_visible_tabs", &visible_tabs },
353 { "editor_visible_spaces", &visible_tws },
354 { "editor_line_state", &option_line_state },
355 { "editor_simple_statusbar", &simple_statusbar },
356 { "editor_check_new_line", &option_check_nl_at_eof },
357 { "editor_show_right_margin", &show_right_margin },
358 { "editor_group_undo", &option_group_undo },
359 #endif /* USE_INTERNAL_EDIT */
360 { "nice_rotating_dash", &nice_rotating_dash },
361 { "mcview_remember_file_position", &mcview_remember_file_position },
362 { "auto_fill_mkdir_name", &auto_fill_mkdir_name },
363 { "copymove_persistent_attr", &setup_copymove_persistent_attr },
364 { "select_flags", &select_flags },
365 { NULL, NULL }
368 static const struct
370 const char *opt_name;
371 char **opt_addr;
372 const char *opt_defval;
373 } str_options[] = {
374 #ifdef USE_INTERNAL_EDIT
375 { "editor_backup_extension", &option_backup_ext, "~" },
376 #endif
377 { "mcview_eof", &mcview_show_eof, "" },
378 { NULL, NULL, NULL }
381 static const struct
383 const char *opt_name;
384 gboolean *opt_addr;
385 } panels_ini_options[] = {
386 { "show_mini_info", &panels_options.show_mini_info },
387 { "kilobyte_si", &panels_options.kilobyte_si },
388 { "mix_all_files", &panels_options.mix_all_files },
389 { "show_backups", &panels_options.show_backups },
390 { "show_dot_files", &panels_options.show_dot_files },
391 { "fast_reload", &panels_options.fast_reload },
392 { "fast_reload_msg_shown", &panels_options.fast_reload_msg_shown },
393 { "mark_moves_down", &panels_options.mark_moves_down },
394 { "reverse_files_only", &panels_options.reverse_files_only },
395 { "auto_save_setup_panels", &panels_options.auto_save_setup },
396 { "navigate_with_arrows", &panels_options.navigate_with_arrows },
397 { "panel_scroll_pages", &panels_options.scroll_pages },
398 { "mouse_move_pages", &panels_options.mouse_move_pages },
399 { "filetype_mode", &panels_options.filetype_mode },
400 { "permission_mode", &panels_options.permission_mode },
401 { "torben_fj_mode", &panels_options.torben_fj_mode },
402 { NULL, NULL }
404 /* *INDENT-ON* */
406 /*** file scope functions ************************************************************************/
407 /* --------------------------------------------------------------------------------------------- */
410 * Get name of config file.
412 * @param subdir If not NULL, config is also searched in specified subdir.
413 * @param config_file_name If relative, file if searched in standard paths.
415 * @returns Newly allocated string with config name or NULL if file is not found.
418 static char *
419 load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
422 TODO: IMHO, in future, this function shall be placed in mcconfig module.
424 char *lc_basename, *ret;
425 char *file_name;
427 if (config_file_name == NULL)
428 return NULL;
430 /* check for .keymap suffix */
431 if (g_str_has_suffix (config_file_name, ".keymap"))
432 file_name = g_strdup (config_file_name);
433 else
434 file_name = g_strconcat (config_file_name, ".keymap", (char *) NULL);
436 canonicalize_pathname (file_name);
438 if (g_path_is_absolute (file_name))
439 return file_name;
441 lc_basename = g_path_get_basename (file_name);
442 g_free (file_name);
444 if (lc_basename == NULL)
445 return NULL;
447 if (subdir != NULL)
448 ret = g_build_filename (mc_config_get_path (), subdir, lc_basename, NULL);
449 else
450 ret = g_build_filename (mc_config_get_path (), lc_basename, NULL);
452 if (exist_file (ret))
454 g_free (lc_basename);
455 canonicalize_pathname (ret);
456 return ret;
458 g_free (ret);
460 if (subdir != NULL)
461 ret = g_build_filename (mc_global.sysconfig_dir, subdir, lc_basename, NULL);
462 else
463 ret = g_build_filename (mc_global.sysconfig_dir, lc_basename, NULL);
465 if (exist_file (ret))
467 g_free (lc_basename);
468 canonicalize_pathname (ret);
469 return ret;
471 g_free (ret);
473 if (subdir != NULL)
474 ret = g_build_filename (mc_global.share_data_dir, subdir, lc_basename, NULL);
475 else
476 ret = g_build_filename (mc_global.share_data_dir, lc_basename, NULL);
478 g_free (lc_basename);
480 if (exist_file (ret))
482 canonicalize_pathname (ret);
483 return ret;
486 g_free (ret);
487 return NULL;
490 /* --------------------------------------------------------------------------------------------- */
492 static const char *
493 setup__is_cfg_group_must_panel_config (const char *grp)
495 return (!strcasecmp ("Dirs", grp) ||
496 !strcasecmp ("Temporal:New Right Panel", grp) ||
497 !strcasecmp ("Temporal:New Left Panel", grp) ||
498 !strcasecmp ("New Left Panel", grp) || !strcasecmp ("New Right Panel", grp))
499 ? grp : NULL;
502 /* --------------------------------------------------------------------------------------------- */
504 static void
505 setup__move_panels_config_into_separate_file (const char *profile)
507 mc_config_t *tmp_cfg;
508 char **groups, **curr_grp;
509 const char *need_grp;
511 if (!exist_file (profile))
512 return;
514 tmp_cfg = mc_config_init (profile, FALSE);
515 if (!tmp_cfg)
516 return;
518 curr_grp = groups = mc_config_get_groups (tmp_cfg, NULL);
519 if (!groups)
521 mc_config_deinit (tmp_cfg);
522 return;
525 while (*curr_grp)
527 if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL)
528 mc_config_del_group (tmp_cfg, *curr_grp);
529 curr_grp++;
532 mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
533 mc_config_deinit (tmp_cfg);
535 tmp_cfg = mc_config_init (profile, FALSE);
536 if (!tmp_cfg)
538 g_strfreev (groups);
539 return;
542 curr_grp = groups;
544 while (*curr_grp)
546 need_grp = setup__is_cfg_group_must_panel_config (*curr_grp);
547 if (need_grp != NULL)
549 mc_config_del_group (tmp_cfg, need_grp);
551 curr_grp++;
553 g_strfreev (groups);
555 mc_config_save_file (tmp_cfg, NULL);
556 mc_config_deinit (tmp_cfg);
559 /* --------------------------------------------------------------------------------------------- */
561 Create new mc_config object from specified ini-file or
562 append data to existing mc_config object from ini-file
565 static void
566 load_setup_init_config_from_file (mc_config_t ** config, const char *fname, gboolean read_only)
569 TODO: IMHO, in future, this function shall be placed in mcconfig module.
571 if (exist_file (fname))
573 if (*config != NULL)
574 mc_config_read_file (*config, fname, read_only, TRUE);
575 else
576 *config = mc_config_init (fname, read_only);
580 /* --------------------------------------------------------------------------------------------- */
582 static void
583 load_layout (void)
585 size_t i;
586 int equal_split;
587 int first_panel_size;
589 /* legacy options */
590 panels_layout.horizontal_split = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
591 "horizontal_split", 0);
592 equal_split = mc_config_get_int (mc_main_config, "Layout", "equal_split", 1);
593 first_panel_size = mc_config_get_int (mc_main_config, "Layout", "first_panel_size", 1);
594 if (panels_layout.horizontal_split)
596 panels_layout.horizontal_equal = equal_split;
597 panels_layout.left_panel_size = first_panel_size;
599 else
601 panels_layout.vertical_equal = equal_split;
602 panels_layout.top_panel_size = first_panel_size;
605 /* actual options override legacy ones */
606 for (i = 0; layout[i].opt_name != NULL; i++)
607 *layout[i].opt_addr = mc_config_get_int (mc_main_config, CONFIG_LAYOUT_SECTION,
608 layout[i].opt_name, *layout[i].opt_addr);
610 /* remove legacy options */
611 mc_config_del_key (mc_main_config, CONFIG_APP_SECTION, "horizontal_split");
612 mc_config_del_key (mc_main_config, "Layout", "equal_split");
613 mc_config_del_key (mc_main_config, "Layout", "first_panel_size");
616 /* --------------------------------------------------------------------------------------------- */
618 static void
619 load_keys_from_section (const char *terminal, mc_config_t * cfg)
621 char *section_name;
622 gchar **profile_keys, **keys;
623 gchar **values, **curr_values;
624 char *valcopy, *value;
625 long key_code;
626 gsize len, values_len;
628 if (terminal == NULL)
629 return;
631 section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
632 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
634 while (*profile_keys != NULL)
636 /* copy=other causes all keys from [terminal:other] to be loaded. */
637 if (g_ascii_strcasecmp (*profile_keys, "copy") == 0)
639 valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
640 load_keys_from_section (valcopy, cfg);
641 g_free (valcopy);
642 profile_keys++;
643 continue;
646 curr_values = values =
647 mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len);
649 key_code = lookup_key (*profile_keys, NULL);
651 if (key_code != 0)
653 if (curr_values != NULL)
655 while (*curr_values != NULL)
657 valcopy = convert_controls (*curr_values);
658 define_sequence (key_code, valcopy, MCKEY_NOACTION);
659 g_free (valcopy);
660 curr_values++;
663 else
665 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
666 valcopy = convert_controls (value);
667 define_sequence (key_code, valcopy, MCKEY_NOACTION);
668 g_free (valcopy);
669 g_free (value);
673 profile_keys++;
674 g_strfreev (values);
676 g_strfreev (keys);
677 g_free (section_name);
680 /* --------------------------------------------------------------------------------------------- */
682 static void
683 load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg)
685 gchar **profile_keys, **keys;
686 gsize len;
688 if (section_name == NULL)
689 return;
691 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
693 while (*profile_keys != NULL)
695 gchar **values, **curr_values;
697 curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &len);
699 if (curr_values != NULL)
701 int action;
703 action = keybind_lookup_action (*profile_keys);
704 if (action > 0)
705 while (*curr_values != NULL)
707 keybind_cmd_bind (keymap, *curr_values, action);
708 curr_values++;
711 g_strfreev (values);
714 profile_keys++;
717 g_strfreev (keys);
720 /* --------------------------------------------------------------------------------------------- */
722 static mc_config_t *
723 load_setup_get_keymap_profile_config (gboolean load_from_file)
726 TODO: IMHO, in future, this function shall be placed in mcconfig module.
728 mc_config_t *keymap_config;
729 char *share_keymap, *sysconfig_keymap;
730 char *fname, *fname2;
732 /* 0) Create default keymap */
733 keymap_config = create_default_keymap ();
734 if (!load_from_file)
735 return keymap_config;
737 /* load and merge global keymaps */
739 /* 1) /usr/share/mc (mc_global.share_data_dir) */
740 share_keymap = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, NULL);
741 load_setup_init_config_from_file (&keymap_config, share_keymap, TRUE);
743 /* 2) /etc/mc (mc_global.sysconfig_dir) */
744 sysconfig_keymap = g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, NULL);
745 load_setup_init_config_from_file (&keymap_config, sysconfig_keymap, TRUE);
747 /* then load and merge one of user-defined keymap */
749 /* 3) --keymap=<keymap> */
750 fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file);
751 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
753 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
754 goto done;
756 g_free (fname);
758 /* 4) getenv("MC_KEYMAP") */
759 fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
760 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
762 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
763 goto done;
765 g_free (fname);
767 /* 5) main config; [Midnight Commander] -> keymap */
768 fname2 = mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, "keymap", NULL);
769 if (fname2 != NULL && *fname2 != '\0')
770 fname = load_setup_get_full_config_name (NULL, fname2);
771 g_free (fname2);
772 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
774 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
775 goto done;
777 g_free (fname);
779 /* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */
780 fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE);
781 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
783 done:
784 g_free (fname);
785 g_free (sysconfig_keymap);
786 g_free (share_keymap);
788 return keymap_config;
791 /* --------------------------------------------------------------------------------------------- */
793 static panel_view_mode_t
794 setup__load_panel_state (const char *section)
796 char *buffer;
797 size_t i;
798 panel_view_mode_t mode = view_listing;
800 /* Load the display mode */
801 buffer = mc_config_get_string (mc_panels_config, section, "display", "listing");
803 for (i = 0; panel_types[i].opt_name != NULL; i++)
804 if (g_ascii_strcasecmp (panel_types[i].opt_name, buffer) == 0)
806 mode = panel_types[i].opt_type;
807 break;
810 g_free (buffer);
812 return mode;
815 /* --------------------------------------------------------------------------------------------- */
817 static void
818 panel_save_type (const char *section, panel_view_mode_t type)
820 size_t i;
822 for (i = 0; panel_types[i].opt_name != NULL; i++)
823 if (panel_types[i].opt_type == type)
825 mc_config_set_string (mc_panels_config, section, "display", panel_types[i].opt_name);
826 break;
830 /* --------------------------------------------------------------------------------------------- */
832 /* save panels.ini */
833 static void
834 save_panel_types (void)
836 panel_view_mode_t type;
838 if (mc_global.mc_run_mode != MC_RUN_FULL)
839 return;
841 type = get_display_type (0);
842 panel_save_type ("New Left Panel", type);
843 if (type == view_listing)
844 panel_save_setup (left_panel, left_panel->panel_name);
845 type = get_display_type (1);
846 panel_save_type ("New Right Panel", type);
847 if (type == view_listing)
848 panel_save_setup (right_panel, right_panel->panel_name);
851 char *dirs;
853 dirs = get_panel_dir_for (other_panel);
854 mc_config_set_string (mc_panels_config, "Dirs", "other_dir", dirs);
855 g_free (dirs);
858 if (current_panel != NULL)
859 mc_config_set_bool (mc_panels_config, "Dirs", "current_is_left", get_current_index () == 0);
861 if (mc_panels_config->ini_path == NULL)
862 mc_panels_config->ini_path = g_strdup (panels_profile_name);
864 mc_config_del_group (mc_panels_config, "Temporal:New Left Panel");
865 mc_config_del_group (mc_panels_config, "Temporal:New Right Panel");
867 mc_config_save_file (mc_panels_config, NULL);
870 /* --------------------------------------------------------------------------------------------- */
871 /*** public functions ****************************************************************************/
872 /* --------------------------------------------------------------------------------------------- */
874 char *
875 setup_init (void)
877 char *profile;
878 char *inifile;
880 if (profile_name != NULL)
881 return profile_name;
883 profile = mc_config_get_full_path (MC_CONFIG_FILE);
884 if (!exist_file (profile))
886 inifile = mc_build_filename (mc_global.sysconfig_dir, "mc.ini", NULL);
887 if (exist_file (inifile))
889 g_free (profile);
890 profile = inifile;
892 else
894 g_free (inifile);
895 inifile = mc_build_filename (mc_global.share_data_dir, "mc.ini", NULL);
896 if (exist_file (inifile))
898 g_free (profile);
899 profile = inifile;
901 else
902 g_free (inifile);
906 profile_name = profile;
908 return profile;
911 /* --------------------------------------------------------------------------------------------- */
913 void
914 load_setup (void)
916 char *profile;
917 size_t i;
918 char *buffer;
919 const char *kt;
921 #ifdef HAVE_CHARSET
922 load_codepages_list ();
923 #endif /* HAVE_CHARSET */
925 profile = setup_init ();
927 /* mc.lib is common for all users, but has priority lower than
928 ${XDG_CONFIG_HOME}/mc/ini. FIXME: it's only used for keys and treestore now */
929 global_profile_name =
930 g_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
931 if (!exist_file (global_profile_name))
933 g_free (global_profile_name);
934 global_profile_name =
935 g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
938 panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE);
940 mc_main_config = mc_config_init (profile, FALSE);
942 if (!exist_file (panels_profile_name))
943 setup__move_panels_config_into_separate_file (profile);
945 mc_panels_config = mc_config_init (panels_profile_name, FALSE);
947 /* Load integer boolean options */
948 for (i = 0; int_options[i].opt_name != NULL; i++)
949 *int_options[i].opt_addr =
950 mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
951 *int_options[i].opt_addr);
953 if (option_tab_spacing <= 0)
954 option_tab_spacing = DEFAULT_TAB_SPACING;
956 #ifdef USE_INTERNAL_EDIT
957 if (option_word_wrap_line_length <= 0)
958 option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
959 #endif /* USE_INTERNAL_EDIT */
961 /* overwrite old_esc_mode_timeout */
962 kt = getenv ("KEYBOARD_KEY_TIMEOUT_US");
963 if ((kt != NULL) && (kt[0] != '\0'))
964 old_esc_mode_timeout = atoi (kt);
966 /* Load string options */
967 for (i = 0; str_options[i].opt_name != NULL; i++)
968 *str_options[i].opt_addr =
969 mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
970 str_options[i].opt_defval);
972 load_layout ();
973 panels_load_options ();
974 load_panelize ();
976 startup_left_mode = setup__load_panel_state ("New Left Panel");
977 startup_right_mode = setup__load_panel_state ("New Right Panel");
979 /* At least one of the panels is a listing panel */
980 if (startup_left_mode != view_listing && startup_right_mode != view_listing)
981 startup_left_mode = view_listing;
983 if (mc_run_param1 == NULL)
985 vfs_path_t *vpath;
986 buffer = mc_config_get_string (mc_panels_config, "Dirs", "other_dir", ".");
987 vpath = vfs_path_from_str (buffer);
988 if (vfs_file_is_local (vpath))
989 mc_run_param1 = buffer;
990 else
991 g_free (buffer);
992 vfs_path_free (vpath);
995 boot_current_is_left = mc_config_get_bool (mc_panels_config, "Dirs", "current_is_left", TRUE);
997 /* Load time formats */
998 user_recent_timeformat =
999 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_recent", FMTTIME);
1000 user_old_timeformat =
1001 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_old", FMTYEAR);
1003 #ifdef ENABLE_VFS_FTP
1004 ftpfs_proxy_host =
1005 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host", "gate");
1006 ftpfs_ignore_chattr_errors =
1007 mc_config_get_bool (mc_main_config, CONFIG_APP_SECTION, "ignore_ftp_chattr_errors", TRUE);
1008 ftpfs_init_passwd ();
1009 #endif /* ENABLE_VFS_FTP */
1011 /* The default color and the terminal dependent color */
1012 mc_global.tty.setup_color_string =
1013 mc_config_get_string (mc_main_config, "Colors", "base_color", "");
1014 mc_global.tty.term_color_string =
1015 mc_config_get_string (mc_main_config, "Colors", getenv ("TERM"), "");
1016 mc_global.tty.color_terminal_string =
1017 mc_config_get_string (mc_main_config, "Colors", "color_terminals", "");
1019 /* Load the directory history */
1020 /* directory_history_load (); */
1021 /* Remove the temporal entries */
1023 #ifdef HAVE_CHARSET
1024 if (codepages->len > 1)
1026 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage", "");
1027 if (buffer[0] != '\0')
1029 mc_global.display_codepage = get_codepage_index (buffer);
1030 cp_display = get_codepage_id (mc_global.display_codepage);
1032 g_free (buffer);
1033 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage", "");
1034 if (buffer[0] != '\0')
1036 default_source_codepage = get_codepage_index (buffer);
1037 mc_global.source_codepage = default_source_codepage; /* May be source_codepage doesn't need this */
1038 cp_source = get_codepage_id (mc_global.source_codepage);
1040 g_free (buffer);
1043 autodetect_codeset =
1044 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset", "");
1045 if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off") != 0))
1046 is_autodetect_codeset_enabled = TRUE;
1048 g_free (init_translation_table (mc_global.source_codepage, mc_global.display_codepage));
1049 buffer = (char *) get_codepage_id (mc_global.display_codepage);
1050 if (buffer != NULL)
1051 mc_global.utf8_display = str_isutf8 (buffer);
1052 #endif /* HAVE_CHARSET */
1054 clipboard_store_path =
1055 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store", "");
1056 clipboard_paste_path =
1057 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste", "");
1060 /* --------------------------------------------------------------------------------------------- */
1062 gboolean
1063 save_setup (gboolean save_options, gboolean save_panel_options)
1065 gboolean ret = TRUE;
1067 saving_setup = 1;
1069 save_hotlist ();
1071 if (save_panel_options)
1072 save_panel_types ();
1074 if (save_options)
1076 char *tmp_profile;
1078 save_config ();
1079 save_layout ();
1080 panels_save_options ();
1081 save_panelize ();
1082 /* directory_history_save (); */
1084 #ifdef ENABLE_VFS_FTP
1085 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "ftpfs_password",
1086 ftpfs_anonymous_passwd);
1087 if (ftpfs_proxy_host)
1088 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host",
1089 ftpfs_proxy_host);
1090 #endif /* ENABLE_VFS_FTP */
1092 #ifdef HAVE_CHARSET
1093 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage",
1094 get_codepage_id (mc_global.display_codepage));
1095 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage",
1096 get_codepage_id (default_source_codepage));
1097 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset",
1098 autodetect_codeset);
1099 #endif /* HAVE_CHARSET */
1100 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store",
1101 clipboard_store_path);
1102 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste",
1103 clipboard_paste_path);
1105 tmp_profile = mc_config_get_full_path (MC_CONFIG_FILE);
1106 ret = mc_config_save_to_file (mc_main_config, tmp_profile, NULL);
1107 g_free (tmp_profile);
1110 saving_setup = 0;
1112 return ret;
1115 /* --------------------------------------------------------------------------------------------- */
1117 void
1118 done_setup (void)
1120 size_t i;
1122 g_free (clipboard_store_path);
1123 g_free (clipboard_paste_path);
1124 g_free (profile_name);
1125 g_free (global_profile_name);
1126 g_free (mc_global.tty.color_terminal_string);
1127 g_free (mc_global.tty.term_color_string);
1128 g_free (mc_global.tty.setup_color_string);
1129 g_free (panels_profile_name);
1130 mc_config_deinit (mc_main_config);
1131 mc_config_deinit (mc_panels_config);
1133 g_free (user_recent_timeformat);
1134 g_free (user_old_timeformat);
1136 for (i = 0; str_options[i].opt_name != NULL; i++)
1137 g_free (*str_options[i].opt_addr);
1139 done_hotlist ();
1140 done_panelize ();
1141 /* directory_history_free (); */
1143 #ifdef HAVE_CHARSET
1144 g_free (autodetect_codeset);
1145 free_codepages_list ();
1146 #endif
1149 /* --------------------------------------------------------------------------------------------- */
1151 void
1152 save_config (void)
1154 size_t i;
1156 /* Save integer options */
1157 for (i = 0; int_options[i].opt_name != NULL; i++)
1158 mc_config_set_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
1159 *int_options[i].opt_addr);
1161 /* Save string options */
1162 for (i = 0; str_options[i].opt_name != NULL; i++)
1163 mc_config_set_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
1164 *str_options[i].opt_addr);
1167 /* --------------------------------------------------------------------------------------------- */
1169 void
1170 setup_save_config_show_error (const char *filename, GError ** error)
1172 if (error != NULL && *error != NULL)
1174 message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*error)->message);
1175 g_error_free (*error);
1176 *error = NULL;
1180 /* --------------------------------------------------------------------------------------------- */
1182 void
1183 save_layout (void)
1185 size_t i;
1187 /* Save integer options */
1188 for (i = 0; layout[i].opt_name != NULL; i++)
1189 mc_config_set_int (mc_main_config, CONFIG_LAYOUT_SECTION, layout[i].opt_name,
1190 *layout[i].opt_addr);
1193 /* --------------------------------------------------------------------------------------------- */
1195 void
1196 load_key_defs (void)
1199 * Load keys from mc.lib before ${XDG_CONFIG_HOME}/mc/ini, so that the user
1200 * definitions override global settings.
1202 mc_config_t *mc_global_config;
1204 mc_global_config = mc_config_init (global_profile_name, FALSE);
1205 if (mc_global_config != NULL)
1207 load_keys_from_section ("general", mc_global_config);
1208 load_keys_from_section (getenv ("TERM"), mc_global_config);
1209 mc_config_deinit (mc_global_config);
1212 load_keys_from_section ("general", mc_main_config);
1213 load_keys_from_section (getenv ("TERM"), mc_main_config);
1216 /* --------------------------------------------------------------------------------------------- */
1218 #ifdef ENABLE_VFS_FTP
1219 char *
1220 load_anon_passwd (void)
1222 char *buffer;
1224 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftpfs_password", "");
1226 if ((buffer != NULL) && (buffer[0] != '\0'))
1227 return buffer;
1229 g_free (buffer);
1230 return NULL;
1232 #endif /* ENABLE_VFS_FTP */
1234 /* --------------------------------------------------------------------------------------------- */
1236 void
1237 load_keymap_defs (gboolean load_from_file)
1240 * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_CONFIG_HOME}/mc/mc.keymap, so that the user
1241 * definitions override global settings.
1243 mc_config_t *mc_global_keymap;
1245 mc_global_keymap = load_setup_get_keymap_profile_config (load_from_file);
1247 if (mc_global_keymap != NULL)
1249 main_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1250 load_keymap_from_section (KEYMAP_SECTION_MAIN, main_keymap, mc_global_keymap);
1251 main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1252 load_keymap_from_section (KEYMAP_SECTION_MAIN_EXT, main_x_keymap, mc_global_keymap);
1254 panel_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1255 load_keymap_from_section (KEYMAP_SECTION_PANEL, panel_keymap, mc_global_keymap);
1257 dialog_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1258 load_keymap_from_section (KEYMAP_SECTION_DIALOG, dialog_keymap, mc_global_keymap);
1260 input_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1261 load_keymap_from_section (KEYMAP_SECTION_INPUT, input_keymap, mc_global_keymap);
1263 listbox_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1264 load_keymap_from_section (KEYMAP_SECTION_LISTBOX, listbox_keymap, mc_global_keymap);
1266 tree_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1267 load_keymap_from_section (KEYMAP_SECTION_TREE, tree_keymap, mc_global_keymap);
1269 help_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1270 load_keymap_from_section (KEYMAP_SECTION_HELP, help_keymap, mc_global_keymap);
1272 #ifdef USE_INTERNAL_EDIT
1273 editor_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1274 load_keymap_from_section (KEYMAP_SECTION_EDITOR, editor_keymap, mc_global_keymap);
1275 editor_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1276 load_keymap_from_section (KEYMAP_SECTION_EDITOR_EXT, editor_x_keymap, mc_global_keymap);
1277 #endif
1279 viewer_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1280 load_keymap_from_section (KEYMAP_SECTION_VIEWER, viewer_keymap, mc_global_keymap);
1281 viewer_hex_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1282 load_keymap_from_section (KEYMAP_SECTION_VIEWER_HEX, viewer_hex_keymap, mc_global_keymap);
1284 #ifdef USE_DIFF_VIEW
1285 diff_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1286 load_keymap_from_section (KEYMAP_SECTION_DIFFVIEWER, diff_keymap, mc_global_keymap);
1287 #endif
1289 mc_config_deinit (mc_global_keymap);
1292 main_map = (global_keymap_t *) main_keymap->data;
1293 main_x_map = (global_keymap_t *) main_x_keymap->data;
1294 panel_map = (global_keymap_t *) panel_keymap->data;
1295 dialog_map = (global_keymap_t *) dialog_keymap->data;
1296 input_map = (global_keymap_t *) input_keymap->data;
1297 listbox_map = (global_keymap_t *) listbox_keymap->data;
1298 tree_map = (global_keymap_t *) tree_keymap->data;
1299 help_map = (global_keymap_t *) help_keymap->data;
1300 #ifdef USE_INTERNAL_EDIT
1301 editor_map = (global_keymap_t *) editor_keymap->data;
1302 editor_x_map = (global_keymap_t *) editor_x_keymap->data;
1303 #endif
1304 viewer_map = (global_keymap_t *) viewer_keymap->data;
1305 viewer_hex_map = (global_keymap_t *) viewer_hex_keymap->data;
1306 #ifdef USE_DIFF_VIEW
1307 diff_map = (global_keymap_t *) diff_keymap->data;
1308 #endif
1311 /* --------------------------------------------------------------------------------------------- */
1313 void
1314 free_keymap_defs (void)
1316 if (main_keymap != NULL)
1317 g_array_free (main_keymap, TRUE);
1318 if (main_x_keymap != NULL)
1319 g_array_free (main_x_keymap, TRUE);
1320 if (panel_keymap != NULL)
1321 g_array_free (panel_keymap, TRUE);
1322 if (dialog_keymap != NULL)
1323 g_array_free (dialog_keymap, TRUE);
1324 if (input_keymap != NULL)
1325 g_array_free (input_keymap, TRUE);
1326 if (listbox_keymap != NULL)
1327 g_array_free (listbox_keymap, TRUE);
1328 if (tree_keymap != NULL)
1329 g_array_free (tree_keymap, TRUE);
1330 if (help_keymap != NULL)
1331 g_array_free (help_keymap, TRUE);
1332 #ifdef USE_INTERNAL_EDIT
1333 if (editor_keymap != NULL)
1334 g_array_free (editor_keymap, TRUE);
1335 if (editor_x_keymap != NULL)
1336 g_array_free (editor_x_keymap, TRUE);
1337 #endif
1338 if (viewer_keymap != NULL)
1339 g_array_free (viewer_keymap, TRUE);
1340 if (viewer_hex_keymap != NULL)
1341 g_array_free (viewer_hex_keymap, TRUE);
1342 #ifdef USE_DIFF_VIEW
1343 if (diff_keymap != NULL)
1344 g_array_free (diff_keymap, TRUE);
1345 #endif
1348 /* --------------------------------------------------------------------------------------------- */
1350 void
1351 panel_load_setup (WPanel * panel, const char *section)
1353 size_t i;
1354 char *buffer, buffer2[BUF_TINY];
1356 panel->sort_info.reverse = mc_config_get_int (mc_panels_config, section, "reverse", 0);
1357 panel->sort_info.case_sensitive =
1358 mc_config_get_int (mc_panels_config, section, "case_sensitive",
1359 OS_SORT_CASE_SENSITIVE_DEFAULT);
1360 panel->sort_info.exec_first = mc_config_get_int (mc_panels_config, section, "exec_first", 0);
1362 /* Load sort order */
1363 buffer = mc_config_get_string (mc_panels_config, section, "sort_order", "name");
1364 panel->sort_info.sort_field = panel_get_field_by_id (buffer);
1365 if (panel->sort_info.sort_field == NULL)
1366 panel->sort_info.sort_field = panel_get_field_by_id ("name");
1368 g_free (buffer);
1370 /* Load the listing mode */
1371 buffer = mc_config_get_string (mc_panels_config, section, "list_mode", "full");
1372 panel->list_type = list_full;
1373 for (i = 0; list_types[i].key != NULL; i++)
1374 if (g_ascii_strcasecmp (list_types[i].key, buffer) == 0)
1376 panel->list_type = list_types[i].list_type;
1377 break;
1379 g_free (buffer);
1381 /* User formats */
1382 g_free (panel->user_format);
1383 panel->user_format =
1384 mc_config_get_string (mc_panels_config, section, "user_format", DEFAULT_USER_FORMAT);
1386 for (i = 0; i < LIST_TYPES; i++)
1388 g_free (panel->user_status_format[i]);
1389 g_snprintf (buffer2, BUF_TINY, "user_status%lld", (long long) i);
1390 panel->user_status_format[i] =
1391 mc_config_get_string (mc_panels_config, section, buffer2, DEFAULT_USER_FORMAT);
1394 panel->user_mini_status = mc_config_get_int (mc_panels_config, section, "user_mini_status", 0);
1397 /* --------------------------------------------------------------------------------------------- */
1399 void
1400 panel_save_setup (struct WPanel *panel, const char *section)
1402 char buffer[BUF_TINY];
1403 size_t i;
1405 mc_config_set_int (mc_panels_config, section, "reverse", panel->sort_info.reverse);
1406 mc_config_set_int (mc_panels_config, section, "case_sensitive",
1407 panel->sort_info.case_sensitive);
1408 mc_config_set_int (mc_panels_config, section, "exec_first", panel->sort_info.exec_first);
1410 mc_config_set_string (mc_panels_config, section, "sort_order", panel->sort_info.sort_field->id);
1412 for (i = 0; list_types[i].key != NULL; i++)
1413 if (list_types[i].list_type == panel->list_type)
1415 mc_config_set_string (mc_panels_config, section, "list_mode", list_types[i].key);
1416 break;
1419 mc_config_set_string (mc_panels_config, section, "user_format", panel->user_format);
1421 for (i = 0; i < LIST_TYPES; i++)
1423 g_snprintf (buffer, BUF_TINY, "user_status%lld", (long long) i);
1424 mc_config_set_string (mc_panels_config, section, buffer, panel->user_status_format[i]);
1427 mc_config_set_int (mc_panels_config, section, "user_mini_status", panel->user_mini_status);
1430 /* --------------------------------------------------------------------------------------------- */
1433 Load panels options from [Panels] section.
1435 void
1436 panels_load_options (void)
1438 if (mc_config_has_group (mc_main_config, CONFIG_PANELS_SECTION))
1440 size_t i;
1441 int qmode;
1443 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1444 *panels_ini_options[i].opt_addr =
1445 mc_config_get_bool (mc_main_config, CONFIG_PANELS_SECTION,
1446 panels_ini_options[i].opt_name,
1447 *panels_ini_options[i].opt_addr);
1449 qmode = mc_config_get_int (mc_main_config, CONFIG_PANELS_SECTION,
1450 "quick_search_mode", (int) panels_options.qsearch_mode);
1451 if (qmode < 0)
1452 panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE;
1453 else if (qmode >= QSEARCH_NUM)
1454 panels_options.qsearch_mode = QSEARCH_PANEL_CASE;
1455 else
1456 panels_options.qsearch_mode = (qsearch_mode_t) qmode;
1460 /* --------------------------------------------------------------------------------------------- */
1463 Save panels options in [Panels] section.
1465 void
1466 panels_save_options (void)
1468 size_t i;
1470 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1471 mc_config_set_bool (mc_main_config, CONFIG_PANELS_SECTION,
1472 panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr);
1474 mc_config_set_int (mc_main_config, CONFIG_PANELS_SECTION,
1475 "quick_search_mode", (int) panels_options.qsearch_mode);
1478 /* --------------------------------------------------------------------------------------------- */