cppcheck: reduce variable scope.
[midnight-commander.git] / src / setup.c
blobb1ff58d1f117068970c5ba0d6859627f84d2fe52
1 /*
2 Setup loading/saving.
4 Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
5 2006, 2007, 2009, 2010, 2011, 2013
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 *global_profile_name; /* mc.lib */
88 /* Only used at program boot */
89 gboolean boot_current_is_left = TRUE;
91 /* If on, default for "No" in delete operations */
92 int safe_delete = 0;
94 /* Controls screen clearing before an exec */
95 int clear_before_exec = 1;
97 /* Asks for confirmation before deleting a file */
98 int confirm_delete = 1;
99 /* Asks for confirmation before deleting a hotlist entry */
100 int confirm_directory_hotlist_delete = 1;
101 /* Asks for confirmation before overwriting a file */
102 int confirm_overwrite = 1;
103 /* Asks for confirmation before executing a program by pressing enter */
104 int confirm_execute = 0;
105 /* Asks for confirmation before leaving the program */
106 int confirm_exit = 1;
108 /* If true, at startup the user-menu is invoked */
109 int auto_menu = 0;
110 /* This flag indicates if the pull down menus by default drop down */
111 int drop_menus = 0;
113 /* Asks for confirmation when using F3 to view a directory and there
114 are tagged files */
115 int confirm_view_dir = 0;
117 /* Ask file name before start the editor */
118 int editor_ask_filename_before_edit = 0;
120 panel_view_mode_t startup_left_mode;
121 panel_view_mode_t startup_right_mode;
123 int setup_copymove_persistent_attr = 1;
125 /* Tab size */
126 int option_tab_spacing = DEFAULT_TAB_SPACING;
128 /* Ugly hack to allow panel_save_setup to work as a place holder for */
129 /* default panel values */
130 int saving_setup;
132 panels_options_t panels_options = {
133 .show_mini_info = TRUE,
134 .kilobyte_si = FALSE,
135 .mix_all_files = FALSE,
136 .show_backups = TRUE,
137 .show_dot_files = TRUE,
138 .fast_reload = FALSE,
139 .fast_reload_msg_shown = FALSE,
140 .mark_moves_down = TRUE,
141 .reverse_files_only = TRUE,
142 .auto_save_setup = FALSE,
143 .navigate_with_arrows = FALSE,
144 .scroll_pages = TRUE,
145 .mouse_move_pages = TRUE,
146 .filetype_mode = TRUE,
147 .permission_mode = FALSE,
148 .qsearch_mode = QSEARCH_PANEL_CASE,
149 .torben_fj_mode = FALSE
152 int easy_patterns = 1;
154 /* It true saves the setup when quitting */
155 int auto_save_setup = 1;
157 /* If true, then the +, - and \ keys have their special meaning only if the
158 * command line is emtpy, otherwise they behave like regular letters
160 int only_leading_plus_minus = 1;
162 /* Automatically fills name with current selected item name on mkdir */
163 int auto_fill_mkdir_name = 1;
165 /* If set and you don't have subshell support,then C-o will give you a shell */
166 int output_starts_shell = 0;
168 /* If set, we execute the file command to check the file type */
169 int use_file_to_check_type = 1;
171 int verbose = 1;
174 * Whether the Midnight Commander tries to provide more
175 * information about copy/move sizes and bytes transfered
176 * at the expense of some speed
178 int file_op_compute_totals = 1;
180 /* If true use the internal viewer */
181 int use_internal_view = 1;
182 /* If set, use the builtin editor */
183 int use_internal_edit = 1;
185 #ifdef HAVE_CHARSET
186 /* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
187 int default_source_codepage = -1;
188 char *autodetect_codeset = NULL;
189 gboolean is_autodetect_codeset_enabled = FALSE;
190 #endif /* !HAVE_CHARSET */
192 #ifdef HAVE_ASPELL
193 char *spell_language = NULL;
194 #endif
196 /* Value of "other_dir" key in ini file */
197 char *saved_other_dir = NULL;
199 /* If set, then print to the given file the last directory we were at */
200 char *last_wd_string = NULL;
202 /* Set when main loop should be terminated */
203 int quit = 0;
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 *profile_name = NULL; /* ${XDG_CONFIG_HOME}/mc/ini */
227 static char *panels_profile_name = NULL; /* ${XDG_CACHE_HOME}/mc/panels.ini */
229 /* *INDENT-OFF* */
230 static const struct
232 const char *key;
233 int list_type;
234 } list_types [] = {
235 { "full", list_full },
236 { "brief", list_brief },
237 { "long", list_long },
238 { "user", list_user },
239 { NULL, 0 }
242 static const struct
244 const char *opt_name;
245 panel_view_mode_t opt_type;
246 } panel_types [] = {
247 { "listing", view_listing },
248 { "quickview", view_quick },
249 { "info", view_info },
250 { "tree", view_tree },
251 { NULL, view_listing }
254 static const struct
256 const char *opt_name;
257 int *opt_addr;
258 } layout [] = {
259 { "message_visible", &mc_global.message_visible },
260 { "keybar_visible", &mc_global.keybar_visible },
261 { "xterm_title", &xterm_title },
262 { "output_lines", &output_lines },
263 { "command_prompt", &command_prompt },
264 { "menubar_visible", &menubar_visible },
265 { "free_space", &free_space },
266 { "horizontal_split", &panels_layout.horizontal_split },
267 { "vertical_equal", &panels_layout.vertical_equal },
268 { "left_panel_size", &panels_layout.left_panel_size },
269 { "horizontal_equal", &panels_layout.horizontal_equal },
270 { "top_panel_size", &panels_layout.top_panel_size },
271 { NULL, NULL }
274 static const struct
276 const char *opt_name;
277 int *opt_addr;
278 } int_options [] = {
279 { "verbose", &verbose },
280 { "pause_after_run", &pause_after_run },
281 { "shell_patterns", &easy_patterns },
282 { "auto_save_setup", &auto_save_setup },
283 { "preallocate_space", &mc_global.vfs.preallocate_space },
284 { "auto_menu", &auto_menu },
285 { "use_internal_view", &use_internal_view },
286 { "use_internal_edit", &use_internal_edit },
287 { "clear_before_exec", &clear_before_exec },
288 { "confirm_delete", &confirm_delete },
289 { "confirm_overwrite", &confirm_overwrite },
290 { "confirm_execute", &confirm_execute },
291 { "confirm_history_cleanup", &mc_global.widget.confirm_history_cleanup },
292 { "confirm_exit", &confirm_exit },
293 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete },
294 { "safe_delete", &safe_delete },
295 { "mouse_repeat_rate", &mou_auto_repeat },
296 { "double_click_speed", &double_click_speed },
297 #ifndef HAVE_CHARSET
298 { "eight_bit_clean", &mc_global.eight_bit_clean },
299 { "full_eight_bits", &mc_global.full_eight_bits },
300 #endif /* !HAVE_CHARSET */
301 { "use_8th_bit_as_meta", &use_8th_bit_as_meta },
302 { "confirm_view_dir", &confirm_view_dir },
303 { "mouse_move_pages_viewer", &mcview_mouse_move_pages },
304 { "mouse_close_dialog", &mouse_close_dialog},
305 { "fast_refresh", &fast_refresh },
306 { "drop_menus", &drop_menus },
307 { "wrap_mode", &mcview_global_wrap_mode},
308 { "old_esc_mode", &old_esc_mode },
309 { "old_esc_mode_timeout", &old_esc_mode_timeout },
310 { "cd_symlinks", &mc_global.vfs.cd_symlinks },
311 { "show_all_if_ambiguous", &mc_global.widget.show_all_if_ambiguous },
312 { "max_dirt_limit", &mcview_max_dirt_limit },
313 { "use_file_to_guess_type", &use_file_to_check_type },
314 { "alternate_plus_minus", &mc_global.tty.alternate_plus_minus },
315 { "only_leading_plus_minus", &only_leading_plus_minus },
316 { "show_output_starts_shell", &output_starts_shell },
317 { "xtree_mode", &xtree_mode },
318 { "num_history_items_recorded", &num_history_items_recorded },
319 { "file_op_compute_totals", &file_op_compute_totals },
320 { "classic_progressbar", &classic_progressbar},
321 #ifdef ENABLE_VFS
322 { "vfs_timeout", &vfs_timeout },
323 #ifdef ENABLE_VFS_FTP
324 { "ftpfs_directory_timeout", &ftpfs_directory_timeout },
325 { "use_netrc", &ftpfs_use_netrc },
326 { "ftpfs_retry_seconds", &ftpfs_retry_seconds },
327 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy },
328 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections },
329 { "ftpfs_use_passive_connections_over_proxy", &ftpfs_use_passive_connections_over_proxy },
330 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options },
331 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls },
332 #endif /* ENABLE_VFS_FTP */
333 #ifdef ENABLE_VFS_FISH
334 { "fish_directory_timeout", &fish_directory_timeout },
335 #endif /* ENABLE_VFS_FISH */
336 #endif /* ENABLE_VFS */
337 /* option_tab_spacing is used in internal viewer */
338 { "editor_tab_spacing", &option_tab_spacing },
339 #ifdef USE_INTERNAL_EDIT
340 { "editor_word_wrap_line_length", &option_word_wrap_line_length },
341 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces },
342 { "editor_return_does_auto_indent", &option_return_does_auto_indent },
343 { "editor_backspace_through_tabs", &option_backspace_through_tabs },
344 { "editor_fake_half_tabs", &option_fake_half_tabs },
345 { "editor_option_save_mode", &option_save_mode },
346 { "editor_option_save_position", &option_save_position },
347 { "editor_option_auto_para_formatting", &option_auto_para_formatting },
348 { "editor_option_typewriter_wrap", &option_typewriter_wrap },
349 { "editor_edit_confirm_save", &edit_confirm_save },
350 { "editor_syntax_highlighting", &option_syntax_highlighting },
351 { "editor_persistent_selections", &option_persistent_selections },
352 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol },
353 { "editor_cursor_after_inserted_block", &option_cursor_after_inserted_block },
354 { "editor_visible_tabs", &visible_tabs },
355 { "editor_visible_spaces", &visible_tws },
356 { "editor_line_state", &option_line_state },
357 { "editor_simple_statusbar", &simple_statusbar },
358 { "editor_check_new_line", &option_check_nl_at_eof },
359 { "editor_show_right_margin", &show_right_margin },
360 { "editor_group_undo", &option_group_undo },
361 #endif /* USE_INTERNAL_EDIT */
362 { "editor_ask_filename_before_edit", &editor_ask_filename_before_edit },
363 { "nice_rotating_dash", &nice_rotating_dash },
364 { "mcview_remember_file_position", &mcview_remember_file_position },
365 { "auto_fill_mkdir_name", &auto_fill_mkdir_name },
366 { "copymove_persistent_attr", &setup_copymove_persistent_attr },
367 { "select_flags", &select_flags },
368 { NULL, NULL }
371 static const struct
373 const char *opt_name;
374 char **opt_addr;
375 const char *opt_defval;
376 } str_options[] = {
377 #ifdef USE_INTERNAL_EDIT
378 { "editor_backup_extension", &option_backup_ext, "~" },
379 { "editor_filesize_threshold", &option_filesize_threshold, "64M" },
380 #endif
381 { "mcview_eof", &mcview_show_eof, "" },
382 { NULL, NULL, NULL }
385 static const struct
387 const char *opt_name;
388 gboolean *opt_addr;
389 } panels_ini_options[] = {
390 { "show_mini_info", &panels_options.show_mini_info },
391 { "kilobyte_si", &panels_options.kilobyte_si },
392 { "mix_all_files", &panels_options.mix_all_files },
393 { "show_backups", &panels_options.show_backups },
394 { "show_dot_files", &panels_options.show_dot_files },
395 { "fast_reload", &panels_options.fast_reload },
396 { "fast_reload_msg_shown", &panels_options.fast_reload_msg_shown },
397 { "mark_moves_down", &panels_options.mark_moves_down },
398 { "reverse_files_only", &panels_options.reverse_files_only },
399 { "auto_save_setup_panels", &panels_options.auto_save_setup },
400 { "navigate_with_arrows", &panels_options.navigate_with_arrows },
401 { "panel_scroll_pages", &panels_options.scroll_pages },
402 { "mouse_move_pages", &panels_options.mouse_move_pages },
403 { "filetype_mode", &panels_options.filetype_mode },
404 { "permission_mode", &panels_options.permission_mode },
405 { "torben_fj_mode", &panels_options.torben_fj_mode },
406 { NULL, NULL }
408 /* *INDENT-ON* */
410 /*** file scope functions ************************************************************************/
411 /* --------------------------------------------------------------------------------------------- */
414 * Get name of config file.
416 * @param subdir If not NULL, config is also searched in specified subdir.
417 * @param config_file_name If relative, file if searched in standard paths.
419 * @return newly allocated string with config name or NULL if file is not found.
422 static char *
423 load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
426 TODO: IMHO, in future, this function shall be placed in mcconfig module.
428 char *lc_basename, *ret;
429 char *file_name;
431 if (config_file_name == NULL)
432 return NULL;
434 /* check for .keymap suffix */
435 if (g_str_has_suffix (config_file_name, ".keymap"))
436 file_name = g_strdup (config_file_name);
437 else
438 file_name = g_strconcat (config_file_name, ".keymap", (char *) NULL);
440 canonicalize_pathname (file_name);
442 if (g_path_is_absolute (file_name))
443 return file_name;
445 lc_basename = g_path_get_basename (file_name);
446 g_free (file_name);
448 if (lc_basename == NULL)
449 return NULL;
451 if (subdir != NULL)
452 ret = g_build_filename (mc_config_get_path (), subdir, lc_basename, NULL);
453 else
454 ret = g_build_filename (mc_config_get_path (), lc_basename, NULL);
456 if (exist_file (ret))
458 g_free (lc_basename);
459 canonicalize_pathname (ret);
460 return ret;
462 g_free (ret);
464 if (subdir != NULL)
465 ret = g_build_filename (mc_global.sysconfig_dir, subdir, lc_basename, NULL);
466 else
467 ret = g_build_filename (mc_global.sysconfig_dir, lc_basename, NULL);
469 if (exist_file (ret))
471 g_free (lc_basename);
472 canonicalize_pathname (ret);
473 return ret;
475 g_free (ret);
477 if (subdir != NULL)
478 ret = g_build_filename (mc_global.share_data_dir, subdir, lc_basename, NULL);
479 else
480 ret = g_build_filename (mc_global.share_data_dir, lc_basename, NULL);
482 g_free (lc_basename);
484 if (exist_file (ret))
486 canonicalize_pathname (ret);
487 return ret;
490 g_free (ret);
491 return NULL;
494 /* --------------------------------------------------------------------------------------------- */
496 static const char *
497 setup__is_cfg_group_must_panel_config (const char *grp)
499 return (!strcasecmp ("Dirs", grp) ||
500 !strcasecmp ("Temporal:New Right Panel", grp) ||
501 !strcasecmp ("Temporal:New Left Panel", grp) ||
502 !strcasecmp ("New Left Panel", grp) || !strcasecmp ("New Right Panel", grp))
503 ? grp : NULL;
506 /* --------------------------------------------------------------------------------------------- */
508 static void
509 setup__move_panels_config_into_separate_file (const char *profile)
511 mc_config_t *tmp_cfg;
512 char **groups, **curr_grp;
514 if (!exist_file (profile))
515 return;
517 tmp_cfg = mc_config_init (profile, FALSE);
518 if (!tmp_cfg)
519 return;
521 curr_grp = groups = mc_config_get_groups (tmp_cfg, NULL);
522 if (!groups)
524 mc_config_deinit (tmp_cfg);
525 return;
528 while (*curr_grp)
530 if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL)
531 mc_config_del_group (tmp_cfg, *curr_grp);
532 curr_grp++;
535 mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
536 mc_config_deinit (tmp_cfg);
538 tmp_cfg = mc_config_init (profile, FALSE);
539 if (!tmp_cfg)
541 g_strfreev (groups);
542 return;
545 curr_grp = groups;
547 while (*curr_grp)
549 const char *need_grp;
551 need_grp = setup__is_cfg_group_must_panel_config (*curr_grp);
552 if (need_grp != NULL)
554 mc_config_del_group (tmp_cfg, need_grp);
556 curr_grp++;
558 g_strfreev (groups);
560 mc_config_save_file (tmp_cfg, NULL);
561 mc_config_deinit (tmp_cfg);
564 /* --------------------------------------------------------------------------------------------- */
566 Create new mc_config object from specified ini-file or
567 append data to existing mc_config object from ini-file
570 static void
571 load_setup_init_config_from_file (mc_config_t ** config, const char *fname, gboolean read_only)
574 TODO: IMHO, in future, this function shall be placed in mcconfig module.
576 if (exist_file (fname))
578 if (*config != NULL)
579 mc_config_read_file (*config, fname, read_only, TRUE);
580 else
581 *config = mc_config_init (fname, read_only);
585 /* --------------------------------------------------------------------------------------------- */
587 static void
588 load_layout (void)
590 size_t i;
591 int equal_split;
592 int first_panel_size;
594 /* legacy options */
595 panels_layout.horizontal_split = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
596 "horizontal_split", 0);
597 equal_split = mc_config_get_int (mc_main_config, "Layout", "equal_split", 1);
598 first_panel_size = mc_config_get_int (mc_main_config, "Layout", "first_panel_size", 1);
599 if (panels_layout.horizontal_split)
601 panels_layout.horizontal_equal = equal_split;
602 panels_layout.left_panel_size = first_panel_size;
604 else
606 panels_layout.vertical_equal = equal_split;
607 panels_layout.top_panel_size = first_panel_size;
610 /* actual options override legacy ones */
611 for (i = 0; layout[i].opt_name != NULL; i++)
612 *layout[i].opt_addr = mc_config_get_int (mc_main_config, CONFIG_LAYOUT_SECTION,
613 layout[i].opt_name, *layout[i].opt_addr);
615 /* remove legacy options */
616 mc_config_del_key (mc_main_config, CONFIG_APP_SECTION, "horizontal_split");
617 mc_config_del_key (mc_main_config, "Layout", "equal_split");
618 mc_config_del_key (mc_main_config, "Layout", "first_panel_size");
621 /* --------------------------------------------------------------------------------------------- */
623 static void
624 load_keys_from_section (const char *terminal, mc_config_t * cfg)
626 char *section_name;
627 gchar **profile_keys, **keys;
628 gchar **values, **curr_values;
629 char *valcopy, *value;
630 long key_code;
631 gsize len, values_len;
633 if (terminal == NULL)
634 return;
636 section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
637 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
639 while (*profile_keys != NULL)
641 /* copy=other causes all keys from [terminal:other] to be loaded. */
642 if (g_ascii_strcasecmp (*profile_keys, "copy") == 0)
644 valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
645 load_keys_from_section (valcopy, cfg);
646 g_free (valcopy);
647 profile_keys++;
648 continue;
651 curr_values = values =
652 mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len);
654 key_code = lookup_key (*profile_keys, NULL);
656 if (key_code != 0)
658 if (curr_values != NULL)
660 while (*curr_values != NULL)
662 valcopy = convert_controls (*curr_values);
663 define_sequence (key_code, valcopy, MCKEY_NOACTION);
664 g_free (valcopy);
665 curr_values++;
668 else
670 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
671 valcopy = convert_controls (value);
672 define_sequence (key_code, valcopy, MCKEY_NOACTION);
673 g_free (valcopy);
674 g_free (value);
678 profile_keys++;
679 g_strfreev (values);
681 g_strfreev (keys);
682 g_free (section_name);
685 /* --------------------------------------------------------------------------------------------- */
687 static void
688 load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg)
690 gchar **profile_keys, **keys;
691 gsize len;
693 if (section_name == NULL)
694 return;
696 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
698 while (*profile_keys != NULL)
700 gchar **values, **curr_values;
702 curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &len);
704 if (curr_values != NULL)
706 int action;
708 action = keybind_lookup_action (*profile_keys);
709 if (action > 0)
710 while (*curr_values != NULL)
712 keybind_cmd_bind (keymap, *curr_values, action);
713 curr_values++;
716 g_strfreev (values);
719 profile_keys++;
722 g_strfreev (keys);
725 /* --------------------------------------------------------------------------------------------- */
727 static mc_config_t *
728 load_setup_get_keymap_profile_config (gboolean load_from_file)
731 TODO: IMHO, in future, this function shall be placed in mcconfig module.
733 mc_config_t *keymap_config;
734 char *share_keymap, *sysconfig_keymap;
735 char *fname, *fname2;
737 /* 0) Create default keymap */
738 keymap_config = create_default_keymap ();
739 if (!load_from_file)
740 return keymap_config;
742 /* load and merge global keymaps */
744 /* 1) /usr/share/mc (mc_global.share_data_dir) */
745 share_keymap = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, NULL);
746 load_setup_init_config_from_file (&keymap_config, share_keymap, TRUE);
748 /* 2) /etc/mc (mc_global.sysconfig_dir) */
749 sysconfig_keymap = g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, NULL);
750 load_setup_init_config_from_file (&keymap_config, sysconfig_keymap, TRUE);
752 /* then load and merge one of user-defined keymap */
754 /* 3) --keymap=<keymap> */
755 fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file);
756 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
758 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
759 goto done;
761 g_free (fname);
763 /* 4) getenv("MC_KEYMAP") */
764 fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
765 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
767 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
768 goto done;
770 g_free (fname);
772 /* 5) main config; [Midnight Commander] -> keymap */
773 fname2 = mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, "keymap", NULL);
774 if (fname2 != NULL && *fname2 != '\0')
775 fname = load_setup_get_full_config_name (NULL, fname2);
776 g_free (fname2);
777 if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
779 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
780 goto done;
782 g_free (fname);
784 /* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */
785 fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE);
786 load_setup_init_config_from_file (&keymap_config, fname, TRUE);
788 done:
789 g_free (fname);
790 g_free (sysconfig_keymap);
791 g_free (share_keymap);
793 return keymap_config;
796 /* --------------------------------------------------------------------------------------------- */
798 static panel_view_mode_t
799 setup__load_panel_state (const char *section)
801 char *buffer;
802 size_t i;
803 panel_view_mode_t mode = view_listing;
805 /* Load the display mode */
806 buffer = mc_config_get_string (mc_panels_config, section, "display", "listing");
808 for (i = 0; panel_types[i].opt_name != NULL; i++)
809 if (g_ascii_strcasecmp (panel_types[i].opt_name, buffer) == 0)
811 mode = panel_types[i].opt_type;
812 break;
815 g_free (buffer);
817 return mode;
820 /* --------------------------------------------------------------------------------------------- */
822 static void
823 panel_save_type (const char *section, panel_view_mode_t type)
825 size_t i;
827 for (i = 0; panel_types[i].opt_name != NULL; i++)
828 if (panel_types[i].opt_type == type)
830 mc_config_set_string (mc_panels_config, section, "display", panel_types[i].opt_name);
831 break;
835 /* --------------------------------------------------------------------------------------------- */
837 /* save panels.ini */
838 static void
839 save_panel_types (void)
841 panel_view_mode_t type;
843 if (mc_global.mc_run_mode != MC_RUN_FULL)
844 return;
846 type = get_display_type (0);
847 panel_save_type ("New Left Panel", type);
848 if (type == view_listing)
849 panel_save_setup (left_panel, left_panel->panel_name);
850 type = get_display_type (1);
851 panel_save_type ("New Right Panel", type);
852 if (type == view_listing)
853 panel_save_setup (right_panel, right_panel->panel_name);
856 char *dirs;
858 dirs = get_panel_dir_for (other_panel);
859 mc_config_set_string (mc_panels_config, "Dirs", "other_dir", dirs);
860 g_free (dirs);
863 if (current_panel != NULL)
864 mc_config_set_bool (mc_panels_config, "Dirs", "current_is_left", get_current_index () == 0);
866 if (mc_panels_config->ini_path == NULL)
867 mc_panels_config->ini_path = g_strdup (panels_profile_name);
869 mc_config_del_group (mc_panels_config, "Temporal:New Left Panel");
870 mc_config_del_group (mc_panels_config, "Temporal:New Right Panel");
872 mc_config_save_file (mc_panels_config, NULL);
875 /* --------------------------------------------------------------------------------------------- */
876 /*** public functions ****************************************************************************/
877 /* --------------------------------------------------------------------------------------------- */
879 const char *
880 setup_init (void)
882 if (profile_name == NULL)
884 char *profile;
886 profile = mc_config_get_full_path (MC_CONFIG_FILE);
887 if (!exist_file (profile))
889 char *inifile;
891 inifile = mc_build_filename (mc_global.sysconfig_dir, "mc.ini", NULL);
892 if (exist_file (inifile))
894 g_free (profile);
895 profile = inifile;
897 else
899 g_free (inifile);
900 inifile = mc_build_filename (mc_global.share_data_dir, "mc.ini", NULL);
901 if (!exist_file (inifile))
902 g_free (inifile);
903 else
905 g_free (profile);
906 profile = inifile;
911 profile_name = profile;
914 return profile_name;
917 /* --------------------------------------------------------------------------------------------- */
919 void
920 load_setup (void)
922 const char *profile;
923 size_t i;
924 char *buffer;
925 const char *kt;
927 #ifdef HAVE_CHARSET
928 load_codepages_list ();
929 #endif /* HAVE_CHARSET */
931 profile = setup_init ();
933 /* mc.lib is common for all users, but has priority lower than
934 ${XDG_CONFIG_HOME}/mc/ini. FIXME: it's only used for keys and treestore now */
935 global_profile_name =
936 g_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
937 if (!exist_file (global_profile_name))
939 g_free (global_profile_name);
940 global_profile_name =
941 g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
944 panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE);
946 mc_main_config = mc_config_init (profile, FALSE);
948 if (!exist_file (panels_profile_name))
949 setup__move_panels_config_into_separate_file (profile);
951 mc_panels_config = mc_config_init (panels_profile_name, FALSE);
953 /* Load integer boolean options */
954 for (i = 0; int_options[i].opt_name != NULL; i++)
955 *int_options[i].opt_addr =
956 mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
957 *int_options[i].opt_addr);
958 #ifndef USE_INTERNAL_EDIT
959 /* reset forced in case of build without internal editor */
960 use_internal_edit = 0;
961 #endif /* USE_INTERNAL_EDIT */
963 if (option_tab_spacing <= 0)
964 option_tab_spacing = DEFAULT_TAB_SPACING;
966 #ifdef USE_INTERNAL_EDIT
967 if (option_word_wrap_line_length <= 0)
968 option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
969 #endif /* USE_INTERNAL_EDIT */
971 /* overwrite old_esc_mode_timeout */
972 kt = getenv ("KEYBOARD_KEY_TIMEOUT_US");
973 if ((kt != NULL) && (kt[0] != '\0'))
974 old_esc_mode_timeout = atoi (kt);
976 /* Load string options */
977 for (i = 0; str_options[i].opt_name != NULL; i++)
978 *str_options[i].opt_addr =
979 mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
980 str_options[i].opt_defval);
982 load_layout ();
983 panels_load_options ();
984 load_panelize ();
986 startup_left_mode = setup__load_panel_state ("New Left Panel");
987 startup_right_mode = setup__load_panel_state ("New Right Panel");
989 /* At least one of the panels is a listing panel */
990 if (startup_left_mode != view_listing && startup_right_mode != view_listing)
991 startup_left_mode = view_listing;
994 vfs_path_t *vpath;
996 buffer = mc_config_get_string (mc_panels_config, "Dirs", "other_dir", ".");
997 vpath = vfs_path_from_str (buffer);
998 if (vfs_file_is_local (vpath))
999 saved_other_dir = buffer;
1000 else
1001 g_free (buffer);
1002 vfs_path_free (vpath);
1005 boot_current_is_left = mc_config_get_bool (mc_panels_config, "Dirs", "current_is_left", TRUE);
1007 /* Load time formats */
1008 user_recent_timeformat =
1009 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_recent", FMTTIME);
1010 user_old_timeformat =
1011 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_old", FMTYEAR);
1013 #ifdef ENABLE_VFS_FTP
1014 ftpfs_proxy_host =
1015 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host", "gate");
1016 ftpfs_ignore_chattr_errors =
1017 mc_config_get_bool (mc_main_config, CONFIG_APP_SECTION, "ignore_ftp_chattr_errors", TRUE);
1018 ftpfs_init_passwd ();
1019 #endif /* ENABLE_VFS_FTP */
1021 /* The default color and the terminal dependent color */
1022 mc_global.tty.setup_color_string =
1023 mc_config_get_string (mc_main_config, "Colors", "base_color", "");
1024 mc_global.tty.term_color_string =
1025 mc_config_get_string (mc_main_config, "Colors", getenv ("TERM"), "");
1026 mc_global.tty.color_terminal_string =
1027 mc_config_get_string (mc_main_config, "Colors", "color_terminals", "");
1029 /* Load the directory history */
1030 /* directory_history_load (); */
1031 /* Remove the temporal entries */
1033 #ifdef HAVE_CHARSET
1034 if (codepages->len > 1)
1036 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage", "");
1037 if (buffer[0] != '\0')
1039 mc_global.display_codepage = get_codepage_index (buffer);
1040 cp_display = get_codepage_id (mc_global.display_codepage);
1042 g_free (buffer);
1043 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage", "");
1044 if (buffer[0] != '\0')
1046 default_source_codepage = get_codepage_index (buffer);
1047 mc_global.source_codepage = default_source_codepage; /* May be source_codepage doesn't need this */
1048 cp_source = get_codepage_id (mc_global.source_codepage);
1050 g_free (buffer);
1053 autodetect_codeset =
1054 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset", "");
1055 if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off") != 0))
1056 is_autodetect_codeset_enabled = TRUE;
1058 g_free (init_translation_table (mc_global.source_codepage, mc_global.display_codepage));
1059 buffer = (char *) get_codepage_id (mc_global.display_codepage);
1060 if (buffer != NULL)
1061 mc_global.utf8_display = str_isutf8 (buffer);
1062 #endif /* HAVE_CHARSET */
1064 #ifdef HAVE_ASPELL
1065 spell_language =
1066 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "spell_language", "en");
1067 #endif /* HAVE_ASPELL */
1069 clipboard_store_path =
1070 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store", "");
1071 clipboard_paste_path =
1072 mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste", "");
1075 /* --------------------------------------------------------------------------------------------- */
1077 gboolean
1078 save_setup (gboolean save_options, gboolean save_panel_options)
1080 gboolean ret = TRUE;
1082 saving_setup = 1;
1084 save_hotlist ();
1086 if (save_panel_options)
1087 save_panel_types ();
1089 if (save_options)
1091 char *tmp_profile;
1093 save_config ();
1094 save_layout ();
1095 panels_save_options ();
1096 save_panelize ();
1097 /* directory_history_save (); */
1099 #ifdef ENABLE_VFS_FTP
1100 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "ftpfs_password",
1101 ftpfs_anonymous_passwd);
1102 if (ftpfs_proxy_host)
1103 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host",
1104 ftpfs_proxy_host);
1105 #endif /* ENABLE_VFS_FTP */
1107 #ifdef HAVE_CHARSET
1108 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage",
1109 get_codepage_id (mc_global.display_codepage));
1110 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage",
1111 get_codepage_id (default_source_codepage));
1112 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset",
1113 autodetect_codeset);
1114 #endif /* HAVE_CHARSET */
1116 #ifdef HAVE_ASPELL
1117 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "spell_language",
1118 spell_language);
1119 #endif /* HAVE_ASPELL */
1121 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store",
1122 clipboard_store_path);
1123 mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste",
1124 clipboard_paste_path);
1126 tmp_profile = mc_config_get_full_path (MC_CONFIG_FILE);
1127 ret = mc_config_save_to_file (mc_main_config, tmp_profile, NULL);
1128 g_free (tmp_profile);
1131 saving_setup = 0;
1133 return ret;
1136 /* --------------------------------------------------------------------------------------------- */
1138 void
1139 done_setup (void)
1141 size_t i;
1143 g_free (clipboard_store_path);
1144 g_free (clipboard_paste_path);
1145 g_free (global_profile_name);
1146 g_free (mc_global.tty.color_terminal_string);
1147 g_free (mc_global.tty.term_color_string);
1148 g_free (mc_global.tty.setup_color_string);
1149 g_free (profile_name);
1150 g_free (panels_profile_name);
1151 mc_config_deinit (mc_main_config);
1152 mc_config_deinit (mc_panels_config);
1154 g_free (user_recent_timeformat);
1155 g_free (user_old_timeformat);
1157 for (i = 0; str_options[i].opt_name != NULL; i++)
1158 g_free (*str_options[i].opt_addr);
1160 done_hotlist ();
1161 done_panelize ();
1162 /* directory_history_free (); */
1164 #ifdef HAVE_CHARSET
1165 g_free (autodetect_codeset);
1166 free_codepages_list ();
1167 #endif
1169 #ifdef HAVE_ASPELL
1170 g_free (spell_language);
1171 #endif /* HAVE_ASPELL */
1174 /* --------------------------------------------------------------------------------------------- */
1176 void
1177 save_config (void)
1179 size_t i;
1181 /* Save integer options */
1182 for (i = 0; int_options[i].opt_name != NULL; i++)
1183 mc_config_set_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
1184 *int_options[i].opt_addr);
1186 /* Save string options */
1187 for (i = 0; str_options[i].opt_name != NULL; i++)
1188 mc_config_set_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
1189 *str_options[i].opt_addr);
1192 /* --------------------------------------------------------------------------------------------- */
1194 void
1195 setup_save_config_show_error (const char *filename, GError ** error)
1197 if (error != NULL && *error != NULL)
1199 message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*error)->message);
1200 g_error_free (*error);
1201 *error = NULL;
1205 /* --------------------------------------------------------------------------------------------- */
1207 void
1208 save_layout (void)
1210 size_t i;
1212 /* Save integer options */
1213 for (i = 0; layout[i].opt_name != NULL; i++)
1214 mc_config_set_int (mc_main_config, CONFIG_LAYOUT_SECTION, layout[i].opt_name,
1215 *layout[i].opt_addr);
1218 /* --------------------------------------------------------------------------------------------- */
1220 void
1221 load_key_defs (void)
1224 * Load keys from mc.lib before ${XDG_CONFIG_HOME}/mc/ini, so that the user
1225 * definitions override global settings.
1227 mc_config_t *mc_global_config;
1229 mc_global_config = mc_config_init (global_profile_name, FALSE);
1230 if (mc_global_config != NULL)
1232 load_keys_from_section ("general", mc_global_config);
1233 load_keys_from_section (getenv ("TERM"), mc_global_config);
1234 mc_config_deinit (mc_global_config);
1237 load_keys_from_section ("general", mc_main_config);
1238 load_keys_from_section (getenv ("TERM"), mc_main_config);
1241 /* --------------------------------------------------------------------------------------------- */
1243 #ifdef ENABLE_VFS_FTP
1244 char *
1245 load_anon_passwd (void)
1247 char *buffer;
1249 buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftpfs_password", "");
1251 if ((buffer != NULL) && (buffer[0] != '\0'))
1252 return buffer;
1254 g_free (buffer);
1255 return NULL;
1257 #endif /* ENABLE_VFS_FTP */
1259 /* --------------------------------------------------------------------------------------------- */
1261 void
1262 load_keymap_defs (gboolean load_from_file)
1265 * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_CONFIG_HOME}/mc/mc.keymap, so that the user
1266 * definitions override global settings.
1268 mc_config_t *mc_global_keymap;
1270 mc_global_keymap = load_setup_get_keymap_profile_config (load_from_file);
1272 if (mc_global_keymap != NULL)
1274 main_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1275 load_keymap_from_section (KEYMAP_SECTION_MAIN, main_keymap, mc_global_keymap);
1276 main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1277 load_keymap_from_section (KEYMAP_SECTION_MAIN_EXT, main_x_keymap, mc_global_keymap);
1279 panel_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1280 load_keymap_from_section (KEYMAP_SECTION_PANEL, panel_keymap, mc_global_keymap);
1282 dialog_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1283 load_keymap_from_section (KEYMAP_SECTION_DIALOG, dialog_keymap, mc_global_keymap);
1285 input_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1286 load_keymap_from_section (KEYMAP_SECTION_INPUT, input_keymap, mc_global_keymap);
1288 listbox_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1289 load_keymap_from_section (KEYMAP_SECTION_LISTBOX, listbox_keymap, mc_global_keymap);
1291 tree_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1292 load_keymap_from_section (KEYMAP_SECTION_TREE, tree_keymap, mc_global_keymap);
1294 help_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1295 load_keymap_from_section (KEYMAP_SECTION_HELP, help_keymap, mc_global_keymap);
1297 #ifdef USE_INTERNAL_EDIT
1298 editor_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1299 load_keymap_from_section (KEYMAP_SECTION_EDITOR, editor_keymap, mc_global_keymap);
1300 editor_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1301 load_keymap_from_section (KEYMAP_SECTION_EDITOR_EXT, editor_x_keymap, mc_global_keymap);
1302 #endif
1304 viewer_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1305 load_keymap_from_section (KEYMAP_SECTION_VIEWER, viewer_keymap, mc_global_keymap);
1306 viewer_hex_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1307 load_keymap_from_section (KEYMAP_SECTION_VIEWER_HEX, viewer_hex_keymap, mc_global_keymap);
1309 #ifdef USE_DIFF_VIEW
1310 diff_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
1311 load_keymap_from_section (KEYMAP_SECTION_DIFFVIEWER, diff_keymap, mc_global_keymap);
1312 #endif
1314 mc_config_deinit (mc_global_keymap);
1317 main_map = (global_keymap_t *) main_keymap->data;
1318 main_x_map = (global_keymap_t *) main_x_keymap->data;
1319 panel_map = (global_keymap_t *) panel_keymap->data;
1320 dialog_map = (global_keymap_t *) dialog_keymap->data;
1321 input_map = (global_keymap_t *) input_keymap->data;
1322 listbox_map = (global_keymap_t *) listbox_keymap->data;
1323 tree_map = (global_keymap_t *) tree_keymap->data;
1324 help_map = (global_keymap_t *) help_keymap->data;
1325 #ifdef USE_INTERNAL_EDIT
1326 editor_map = (global_keymap_t *) editor_keymap->data;
1327 editor_x_map = (global_keymap_t *) editor_x_keymap->data;
1328 #endif
1329 viewer_map = (global_keymap_t *) viewer_keymap->data;
1330 viewer_hex_map = (global_keymap_t *) viewer_hex_keymap->data;
1331 #ifdef USE_DIFF_VIEW
1332 diff_map = (global_keymap_t *) diff_keymap->data;
1333 #endif
1336 /* --------------------------------------------------------------------------------------------- */
1338 void
1339 free_keymap_defs (void)
1341 if (main_keymap != NULL)
1342 g_array_free (main_keymap, TRUE);
1343 if (main_x_keymap != NULL)
1344 g_array_free (main_x_keymap, TRUE);
1345 if (panel_keymap != NULL)
1346 g_array_free (panel_keymap, TRUE);
1347 if (dialog_keymap != NULL)
1348 g_array_free (dialog_keymap, TRUE);
1349 if (input_keymap != NULL)
1350 g_array_free (input_keymap, TRUE);
1351 if (listbox_keymap != NULL)
1352 g_array_free (listbox_keymap, TRUE);
1353 if (tree_keymap != NULL)
1354 g_array_free (tree_keymap, TRUE);
1355 if (help_keymap != NULL)
1356 g_array_free (help_keymap, TRUE);
1357 #ifdef USE_INTERNAL_EDIT
1358 if (editor_keymap != NULL)
1359 g_array_free (editor_keymap, TRUE);
1360 if (editor_x_keymap != NULL)
1361 g_array_free (editor_x_keymap, TRUE);
1362 #endif
1363 if (viewer_keymap != NULL)
1364 g_array_free (viewer_keymap, TRUE);
1365 if (viewer_hex_keymap != NULL)
1366 g_array_free (viewer_hex_keymap, TRUE);
1367 #ifdef USE_DIFF_VIEW
1368 if (diff_keymap != NULL)
1369 g_array_free (diff_keymap, TRUE);
1370 #endif
1373 /* --------------------------------------------------------------------------------------------- */
1375 void
1376 panel_load_setup (WPanel * panel, const char *section)
1378 size_t i;
1379 char *buffer, buffer2[BUF_TINY];
1381 panel->sort_info.reverse = mc_config_get_int (mc_panels_config, section, "reverse", 0);
1382 panel->sort_info.case_sensitive =
1383 mc_config_get_int (mc_panels_config, section, "case_sensitive",
1384 OS_SORT_CASE_SENSITIVE_DEFAULT);
1385 panel->sort_info.exec_first = mc_config_get_int (mc_panels_config, section, "exec_first", 0);
1387 /* Load sort order */
1388 buffer = mc_config_get_string (mc_panels_config, section, "sort_order", "name");
1389 panel->sort_field = panel_get_field_by_id (buffer);
1390 if (panel->sort_field == NULL)
1391 panel->sort_field = panel_get_field_by_id ("name");
1393 g_free (buffer);
1395 /* Load the listing mode */
1396 buffer = mc_config_get_string (mc_panels_config, section, "list_mode", "full");
1397 panel->list_type = list_full;
1398 for (i = 0; list_types[i].key != NULL; i++)
1399 if (g_ascii_strcasecmp (list_types[i].key, buffer) == 0)
1401 panel->list_type = list_types[i].list_type;
1402 break;
1404 g_free (buffer);
1406 /* User formats */
1407 g_free (panel->user_format);
1408 panel->user_format =
1409 mc_config_get_string (mc_panels_config, section, "user_format", DEFAULT_USER_FORMAT);
1411 for (i = 0; i < LIST_TYPES; i++)
1413 g_free (panel->user_status_format[i]);
1414 g_snprintf (buffer2, BUF_TINY, "user_status%lld", (long long) i);
1415 panel->user_status_format[i] =
1416 mc_config_get_string (mc_panels_config, section, buffer2, DEFAULT_USER_FORMAT);
1419 panel->user_mini_status = mc_config_get_int (mc_panels_config, section, "user_mini_status", 0);
1422 /* --------------------------------------------------------------------------------------------- */
1424 void
1425 panel_save_setup (struct WPanel *panel, const char *section)
1427 char buffer[BUF_TINY];
1428 size_t i;
1430 mc_config_set_int (mc_panels_config, section, "reverse", panel->sort_info.reverse);
1431 mc_config_set_int (mc_panels_config, section, "case_sensitive",
1432 panel->sort_info.case_sensitive);
1433 mc_config_set_int (mc_panels_config, section, "exec_first", panel->sort_info.exec_first);
1435 mc_config_set_string (mc_panels_config, section, "sort_order", panel->sort_field->id);
1437 for (i = 0; list_types[i].key != NULL; i++)
1438 if (list_types[i].list_type == panel->list_type)
1440 mc_config_set_string (mc_panels_config, section, "list_mode", list_types[i].key);
1441 break;
1444 mc_config_set_string (mc_panels_config, section, "user_format", panel->user_format);
1446 for (i = 0; i < LIST_TYPES; i++)
1448 g_snprintf (buffer, BUF_TINY, "user_status%lld", (long long) i);
1449 mc_config_set_string (mc_panels_config, section, buffer, panel->user_status_format[i]);
1452 mc_config_set_int (mc_panels_config, section, "user_mini_status", panel->user_mini_status);
1455 /* --------------------------------------------------------------------------------------------- */
1458 Load panels options from [Panels] section.
1460 void
1461 panels_load_options (void)
1463 if (mc_config_has_group (mc_main_config, CONFIG_PANELS_SECTION))
1465 size_t i;
1466 int qmode;
1468 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1469 *panels_ini_options[i].opt_addr =
1470 mc_config_get_bool (mc_main_config, CONFIG_PANELS_SECTION,
1471 panels_ini_options[i].opt_name,
1472 *panels_ini_options[i].opt_addr);
1474 qmode = mc_config_get_int (mc_main_config, CONFIG_PANELS_SECTION,
1475 "quick_search_mode", (int) panels_options.qsearch_mode);
1476 if (qmode < 0)
1477 panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE;
1478 else if (qmode >= QSEARCH_NUM)
1479 panels_options.qsearch_mode = QSEARCH_PANEL_CASE;
1480 else
1481 panels_options.qsearch_mode = (qsearch_mode_t) qmode;
1485 /* --------------------------------------------------------------------------------------------- */
1488 Save panels options in [Panels] section.
1490 void
1491 panels_save_options (void)
1493 size_t i;
1495 for (i = 0; panels_ini_options[i].opt_name != NULL; i++)
1496 mc_config_set_bool (mc_main_config, CONFIG_PANELS_SECTION,
1497 panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr);
1499 mc_config_set_int (mc_main_config, CONFIG_PANELS_SECTION,
1500 "quick_search_mode", (int) panels_options.qsearch_mode);
1503 /* --------------------------------------------------------------------------------------------- */